/**
 * TechOwl Partners Portal — application shell & component styling.
 * Layers on top of Bootstrap 5. Loaded by layouts/app.blade.php.
 */

:root {
    /* Brand */
    --tp-primary: #1d4ed8;
    --tp-primary-dark: #1e3a8a;
    --tp-primary-light: #eff4ff;
    --tp-accent: #0ea5e9;

    /* Surfaces */
    --tp-bg: #f5f7fa;
    --tp-surface: #ffffff;
    --tp-sidebar-bg: #0f172a;
    --tp-sidebar-fg: #cbd5e1;
    --tp-sidebar-fg-muted: #64748b;
    --tp-sidebar-active: #1e293b;

    /* Text */
    --tp-text: #0f172a;
    --tp-text-muted: #64748b;

    /* Lines */
    --tp-border: #e2e8f0;

    /* Status */
    --tp-success: #16a34a;
    --tp-warning: #d97706;
    --tp-danger: #dc2626;
    --tp-info: #0891b2;

    /* Shape */
    --tp-radius: 10px;
    --tp-radius-sm: 6px;
    --tp-shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --tp-shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --tp-shadow-lg: 0 10px 25px rgba(15, 23, 42, .10);

    --tp-sidebar-w: 250px;
    --tp-topbar-h: 58px;
}

/* ---------------------------------------------------------------- base */

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    background: var(--tp-bg);
    color: var(--tp-text);
    font-size: .9375rem;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { font-weight: 600; letter-spacing: -.01em; color: var(--tp-text); }
h2 { font-size: 1.5rem; }

a { color: var(--tp-primary); text-decoration: none; }
a:hover { color: var(--tp-primary-dark); text-decoration: underline; }

/* Visible keyboard focus everywhere (accessibility) */
a:focus-visible,
button:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.nav-link:focus-visible {
    outline: 2px solid var(--tp-accent);
    outline-offset: 2px;
    border-radius: var(--tp-radius-sm);
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 2000;
    background: var(--tp-primary);
    color: #fff;
    padding: .6rem 1rem;
    border-radius: 0 0 var(--tp-radius-sm) 0;
}
.skip-link:focus { left: 0; color: #fff; }

/* ------------------------------------------------------------- topbar */

.tp-topbar {
    height: var(--tp-topbar-h);
    background: var(--tp-surface);
    border-bottom: 1px solid var(--tp-border);
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: .75rem;
}

.tp-brand {
    font-weight: 700;
    font-size: 1.0625rem;
    color: var(--tp-text);
    letter-spacing: -.02em;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.tp-brand:hover { color: var(--tp-text); text-decoration: none; }

.tp-brand-mark {
    width: 28px; height: 28px;
    border-radius: 7px;
    background: linear-gradient(135deg, var(--tp-primary), var(--tp-accent));
    color: #fff;
    display: grid; place-items: center;
    font-size: .8125rem; font-weight: 700;
    flex: 0 0 auto;
}

.tp-user {
    display: flex; align-items: center; gap: .5rem;
    font-size: .875rem;
}
.tp-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--tp-primary-light);
    color: var(--tp-primary);
    display: grid; place-items: center;
    font-weight: 600; font-size: .8125rem;
    flex: 0 0 auto;
}
.tp-role-chip {
    font-size: .6875rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em;
    background: var(--tp-primary-light); color: var(--tp-primary);
    padding: .15rem .5rem; border-radius: var(--tp-radius-full, 999px);
}

/* ------------------------------------------------------------ sidebar */

.tp-shell { display: flex; min-height: calc(100vh - var(--tp-topbar-h)); }

.tp-sidebar {
    width: var(--tp-sidebar-w);
    flex: 0 0 var(--tp-sidebar-w);
    background: var(--tp-sidebar-bg);
    color: var(--tp-sidebar-fg);
    padding: 1rem .75rem 2rem;
    overflow-y: auto;
    position: sticky;
    top: var(--tp-topbar-h);
    height: calc(100vh - var(--tp-topbar-h));
}

.tp-nav-section {
    font-size: .6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--tp-sidebar-fg-muted);
    padding: 0 .75rem;
    margin: 1.25rem 0 .375rem;
}
.tp-nav-section:first-of-type { margin-top: .25rem; }

.tp-nav { list-style: none; padding: 0; margin: 0; }

.tp-nav a {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem .75rem;
    border-radius: var(--tp-radius-sm);
    color: var(--tp-sidebar-fg);
    font-size: .875rem;
    line-height: 1.3;
    transition: background .12s ease, color .12s ease;
}
.tp-nav a:hover {
    background: var(--tp-sidebar-active);
    color: #fff;
    text-decoration: none;
}
.tp-nav a.active {
    background: var(--tp-primary);
    color: #fff;
    font-weight: 500;
}
.tp-nav a.active:hover { background: var(--tp-primary); }

/* --------------------------------------------------------------- main */

.tp-main {
    flex: 1 1 auto;
    min-width: 0;              /* lets tables scroll instead of stretching */
    padding: 1.75rem;
}

.tp-page-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.5rem;
}
.tp-page-head h2 { margin: 0; }
.tp-page-head .tp-subtitle {
    color: var(--tp-text-muted);
    font-size: .875rem;
    margin: .125rem 0 0;
}

/* --------------------------------------------------------- components */

.card {
    border: 1px solid var(--tp-border);
    border-radius: var(--tp-radius);
    box-shadow: var(--tp-shadow-sm);
    background: var(--tp-surface);
}
.card-header {
    background: var(--tp-surface);
    border-bottom: 1px solid var(--tp-border);
    font-weight: 600;
    padding: .875rem 1.125rem;
}
.card-body { padding: 1.125rem; }
.card-footer { background: var(--tp-surface); border-top: 1px solid var(--tp-border); }

/* Stat cards */
.tp-stat { text-align: center; }
.tp-stat .tp-stat-label {
    font-size: .75rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em;
    color: var(--tp-text-muted);
}
.tp-stat .tp-stat-value {
    font-size: 1.875rem; font-weight: 700;
    line-height: 1.2; margin-top: .25rem;
    letter-spacing: -.02em;
    white-space: nowrap;        /* never split a figure across lines */
}

.tp-stat .tp-stat-hint {
    font-size: .75rem;
    color: var(--tp-text-muted);
    margin-top: .25rem;
    line-height: 1.3;
}

/* Long currency figures shrink rather than wrap on narrow screens */
@media (max-width: 575.98px) {
    .tp-stat .tp-stat-value { font-size: 1.375rem; }
}

/* Tables */
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > thead > tr > th {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--tp-text-muted);
    background: #f8fafc;
    border-bottom: 1px solid var(--tp-border);
    white-space: nowrap;
    padding: .75rem .875rem;
}
.table > tbody > tr > td {
    padding: .8125rem .875rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--tp-border);
}
.table-hover > tbody > tr:hover > * { background: #f8fafc; }

/* A table inside a card sits flush to the card edges */
.card > .table-responsive { border-radius: 0 0 var(--tp-radius) var(--tp-radius); }

/* Dates and short figures should not wrap mid-value */
td[data-label="Created"],
td[data-label="Date"],
td[data-label="Start"],
td[data-label="End"],
td[data-label="Invoice Date"],
td[data-label="Due Date"] {
    white-space: nowrap;
}

/* Badges */
.badge {
    font-weight: 600;
    font-size: .6875rem;
    letter-spacing: .02em;
    padding: .3rem .55rem;
    border-radius: var(--tp-radius-sm);
}

/* Buttons */
.btn {
    border-radius: var(--tp-radius-sm);
    font-weight: 500;
    font-size: .875rem;
    padding: .4375rem .875rem;
}
.btn-primary {
    background: var(--tp-primary);
    border-color: var(--tp-primary);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--tp-primary-dark);
    border-color: var(--tp-primary-dark);
}
.btn-sm { font-size: .8125rem; padding: .25rem .625rem; }

/* Forms */
.form-label { font-weight: 500; font-size: .875rem; margin-bottom: .375rem; }
.form-control, .form-select {
    border-radius: var(--tp-radius-sm);
    border-color: var(--tp-border);
    font-size: .875rem;
    padding: .4375rem .75rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--tp-primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, .12);
}
.form-text { font-size: .8125rem; color: var(--tp-text-muted); }

/* Alerts */
.alert {
    border: 1px solid transparent;
    border-radius: var(--tp-radius);
    font-size: .875rem;
    padding: .75rem 1rem;
}
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #b45309; }
.alert-info    { background: #f0f9ff; border-color: #bae6fd; color: #0369a1; }

/* Accordion — Bootstrap's default chevron renders oversized at our type scale */
.accordion {
    --bs-accordion-border-color: var(--tp-border);
    --bs-accordion-border-radius: var(--tp-radius);
    --bs-accordion-btn-padding-y: .875rem;
    --bs-accordion-btn-padding-x: 1.125rem;
    --bs-accordion-active-bg: var(--tp-primary-light);
    --bs-accordion-active-color: var(--tp-primary-dark);
    --bs-accordion-btn-focus-box-shadow: 0 0 0 3px rgba(29, 78, 216, .12);
}

.accordion-button {
    font-size: .9375rem;
    background: var(--tp-surface);
}

.accordion-button::after {
    width: .875rem;
    height: .875rem;
    background-size: .875rem;
    opacity: .55;
}

.accordion-button:not(.collapsed)::after {
    opacity: .9;
}

.accordion-body {
    padding: 1.125rem;
    background: #fbfcfe;
}

/* Progress */
.progress {
    background: #e2e8f0;
    border-radius: var(--tp-radius-full, 999px);
    overflow: hidden;
}
.progress-bar { font-size: .75rem; font-weight: 600; }

/* Timeline — vertical event list with a connecting rail */
.tp-timeline {
    list-style: none;
    margin: 0;
    padding: 0 0 0 1.25rem;
    position: relative;
}
.tp-timeline::before {
    content: '';
    position: absolute;
    left: .3125rem;
    top: .35rem;
    bottom: .35rem;
    width: 2px;
    background: var(--tp-border);
}
.tp-timeline-item {
    position: relative;
    padding-bottom: 1rem;
}
.tp-timeline-item:last-child { padding-bottom: 0; }

.tp-timeline-dot {
    position: absolute;
    left: -1.25rem;
    top: .3rem;
    width: .75rem;
    height: .75rem;
    border-radius: 50%;
    border: 2px solid var(--tp-surface);
    box-shadow: 0 0 0 1px var(--tp-border);
}
.tp-timeline-body { padding-left: .25rem; }

/* Empty state */
.tp-empty {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--tp-text-muted);
}
.tp-empty-icon { font-size: 2.5rem; opacity: .35; margin-bottom: .75rem; }
.tp-empty h5 { color: var(--tp-text); margin-bottom: .375rem; }
.tp-empty p { font-size: .875rem; margin-bottom: 1rem; }

/* Pagination */
.pagination { --bs-pagination-font-size: .875rem; margin-bottom: 0; }
.page-link { border-color: var(--tp-border); color: var(--tp-text); }
.page-item.active .page-link { background: var(--tp-primary); border-color: var(--tp-primary); }

/* ------------------------------------------------------- auth screens */

.tp-auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background: linear-gradient(150deg, #0f172a 0%, #1e293b 55%, #1d4ed8 100%);
}

.tp-auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--tp-surface);
    border-radius: var(--tp-radius);
    box-shadow: var(--tp-shadow-lg);
    padding: 2rem;
}

.tp-auth-card-wide { max-width: 720px; }

.tp-brand-mark-lg {
    width: 48px; height: 48px;
    border-radius: 12px;
    font-size: 1.125rem;
    display: inline-grid;      /* so mx-auto / text-center works */
}

/* ------------------------------------------------------- mobile shell */

.tp-sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
    .tp-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1045;
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: var(--tp-shadow-lg);
        padding-top: 1rem;
    }
    body.tp-nav-open .tp-sidebar { transform: translateX(0); }

    body.tp-nav-open .tp-sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .45);
        z-index: 1040;
    }

    .tp-main { padding: 1.125rem; }
}

@media (min-width: 992px) {
    .tp-nav-toggle { display: none; }
}

/* Tables become readable cards on small screens */
@media (max-width: 767.98px) {
    .tp-page-head { align-items: flex-start; }

    .table-stack thead { display: none; }
    .table-stack tbody tr {
        display: block;
        border: 1px solid var(--tp-border);
        border-radius: var(--tp-radius);
        margin-bottom: .75rem;
        padding: .25rem .75rem;
        background: var(--tp-surface);
    }
    .table-stack tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        border: 0;
        border-bottom: 1px solid var(--tp-border-light, #f1f5f9);
        padding: .5rem 0;
        text-align: right;
    }
    .table-stack tbody tr td:last-child { border-bottom: 0; }
    .table-stack tbody td::before {
        content: attr(data-label);
        font-size: .75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--tp-text-muted);
        text-align: left;
        flex: 0 0 auto;
    }
    /* Cells with no label render full width */
    .table-stack tbody td:not([data-label]) { justify-content: flex-end; }
}

/* ---------------------------------------------------- touch ergonomics */

@media (max-width: 991.98px) {
    /* Comfortable thumb targets: 44px is the usual accessibility floor. */
    .btn,
    .btn-sm,
    .page-link,
    .form-control,
    .form-select {
        min-height: 44px;
    }

    .btn-sm {
        padding-inline: .875rem;
    }

    /* Buttons in a stacked table row sit full width and spaced apart. */
    .table-stack td .btn {
        min-width: 5.5rem;
    }

    .tp-nav a {
        padding-block: .6875rem;   /* taller sidebar rows on touch */
    }
}

/* A stacked row is a card: lead with the title, mute the labels. */
@media (max-width: 767.98px) {
    .table-stack tbody tr {
        padding: .5rem .875rem;
    }

    .table-stack tbody td {
        padding: .375rem 0;
        font-size: .875rem;
    }

    .table-stack tbody td::before {
        font-size: .6875rem;
        opacity: .75;
    }

    /* First cell reads as the card heading, not a labelled field. */
    .table-stack tbody tr td:first-child {
        display: block;
        text-align: left;
        font-size: .9375rem;
        padding-top: .5rem;
    }
    .table-stack tbody tr td:first-child::before {
        display: block;
        margin-bottom: .125rem;
    }

    /* Action buttons get their own full-width row. */
    .table-stack tbody tr td:last-child:not([data-label]) {
        display: flex;
        gap: .5rem;
        padding-top: .625rem;
    }
    .table-stack tbody tr td:last-child:not([data-label]) .btn,
    .table-stack tbody tr td:last-child:not([data-label]) form {
        flex: 1 1 0;
    }
    .table-stack tbody tr td:last-child:not([data-label]) form .btn {
        width: 100%;
    }
}

/* ------------------------------------------------------------- print */

@media print {
    .tp-topbar, .tp-sidebar, .tp-nav-toggle, .btn { display: none !important; }
    .tp-main { padding: 0; }
    .card { box-shadow: none; border-color: #ccc; }
}

/* Notification bell -------------------------------------------------------- */
.tp-bell-menu {
    width: min(22rem, calc(100vw - 2rem));
    max-height: 26rem;
    overflow-y: auto;
    padding: 0;
}

.tp-bell-menu .dropdown-item:last-child {
    border-bottom: 0;
}

/* The badge sits over the bell glyph, so keep it from clipping the button. */
.tp-bell .btn {
    overflow: visible;
}
