/*
 * NCSS CRM design tokens, adapted from the approved dashboard-mockup.html.
 * Semantic custom properties only -- nothing in app CSS/markup should
 * hardcode a hex color going forward; reference these instead.
 * Dark values apply via Bootstrap 5.3's native color-mode attribute.
 */

:root {
    --page: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f8f9fa;
    --text: #23262a;
    --text-muted: #6c7075;
    --border: #e5e7ea;

    --brand: #CF372E;
    --brand-strong: #B22E25;

    --nav-bg: #2b2d31;
    --nav-text: #c9cbcf;
    --nav-text-dim: #8b8e93;
    --nav-active: #EF4136;

    --warning: #E0912B;
    --warning-bg: #fbf0dc;
    --warning-text: #7a4e08;

    --success: #2e9e5b;
    --success-bg: #e6f4ec;
    --success-text: #1c6b3c;

    --info: #3574c0;
    --info-bg: #e8f0fa;
    --info-text: #1d4e86;

    --radius: 8px;
    --radius-lg: 12px;
}

[data-bs-theme="dark"] {
    --page: #131518;
    --surface: #1c1f23;
    --surface-2: #23272c;
    --text: #e7e8ea;
    --text-muted: #9a9da2;
    --border: #2e3339;

    --brand: #EF4136;
    --brand-strong: #F0574C;

    --nav-bg: #141619;
    --nav-text: #c2c4c8;
    --nav-text-dim: #7c8085;
    --nav-active: #EF4136;

    --warning: #E0912B;
    --warning-bg: #3a2c12;
    --warning-text: #f0b559;

    --success: #3bb56d;
    --success-bg: #14301f;
    --success-text: #66c98d;

    --info: #4f8fd6;
    --info-bg: #152738;
    --info-text: #7cb0e6;
}

/*
 * Phase 2: map Bootstrap's primary/link/focus-ring colors to the NCSS brand,
 * light and dark. --bs-primary/--bs-primary-rgb, --bs-link-*, and
 * --bs-focus-ring-color are plain custom properties Bootstrap declares on
 * :root with literal values (confirmed by inspecting the vendored 5.3.3
 * bootstrap.css) -- re-declaring them here after bootstrap.min.css wins the
 * cascade and correctly retints every utility class that reads them at use
 * time (.bg-primary, .text-primary, .border-primary, links, focus rings).
 *
 * .btn-primary does NOT read var(--bs-primary) -- Bootstrap bakes literal
 * hex directly into its own --bs-btn-* properties, so it needs its own
 * explicit override below (not a Sass rebuild, so this is the correct way
 * to retint it without recompiling Bootstrap).
 */
:root {
    --bs-primary: var(--brand);
    --bs-primary-rgb: 207, 55, 46;
    --bs-link-color: var(--brand);
    --bs-link-color-rgb: 207, 55, 46;
    --bs-link-hover-color: var(--brand-strong);
    --bs-link-hover-color-rgb: 178, 46, 37;
    --bs-focus-ring-color: rgba(207, 55, 46, .25);
    --bs-body-bg: var(--page);
    --bs-body-color: var(--text);
}

[data-bs-theme="dark"] {
    --bs-primary: var(--brand);
    --bs-primary-rgb: 239, 65, 54;
    --bs-link-color: var(--brand);
    --bs-link-color-rgb: 239, 65, 54;
    --bs-link-hover-color: var(--brand-strong);
    --bs-link-hover-color-rgb: 240, 87, 76;
    --bs-focus-ring-color: rgba(239, 65, 54, .25);
    --bs-body-bg: var(--page);
    --bs-body-color: var(--text);
}

.btn-primary {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--brand-strong);
    --bs-btn-hover-border-color: var(--brand-strong);
    --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--brand-strong);
    --bs-btn-active-border-color: var(--brand-strong);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
}

/*
 * Phase 3: app shell -- left side-nav + thin topbar, adapted from the
 * mockup's .app/.nav/.topbar structure. Classes are prefixed app- to avoid
 * colliding with Bootstrap's own .nav/.navbar-nav (used throughout the app
 * for tabs) and with .main.
 *
 * The side-nav's mobile collapse is a small custom class toggle (below),
 * NOT Bootstrap's offcanvas component: offcanvas's base CSS sets
 * visibility:hidden and transform:translateX(-100%) UNCONDITIONALLY (not
 * gated by any breakpoint media query -- confirmed by reading the vendored
 * 5.3.3 CSS), and its "responsive" (offcanvas-lg etc.) variant only resets
 * display on the *.offcanvas-header/.offcanvas-body children*, not the
 * container's own visibility/transform -- so it never actually becomes a
 * normal static block at wide viewports the way the docs' framing suggests.
 * Rather than fight that, this is a few lines of plain CSS + JS instead.
 */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidenav {
    width: 224px;
    background: var(--nav-bg);
    color: var(--nav-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    padding: 0;
}

@media (min-width: 992px) {
    .app-sidenav {
        position: sticky;
        top: 0;
        height: 100vh;
        border: none;
    }
}

@media (max-width: 991.98px) {
    .app-sidenav {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        z-index: 1045;
        box-shadow: var(--bs-box-shadow-lg);
    }

    .app-sidenav.app-sidenav-open {
        display: flex;
    }

    .app-sidenav-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .4);
        z-index: 1044;
    }

    .app-sidenav-backdrop.app-sidenav-open {
        display: block;
    }
}

@media (min-width: 992px) {
    .app-sidenav-backdrop {
        display: none !important;
    }
}

.app-sidenav-brand {
    padding: 20px 20px 18px;
    display: flex;
    align-items: baseline;
    gap: 2px;
    letter-spacing: .5px;
}

    .app-sidenav-brand .mark {
        font-size: 22px;
        font-weight: 800;
        color: var(--brand);
    }

    .app-sidenav-brand .sub {
        font-size: 12px;
        font-weight: 600;
        color: var(--nav-text-dim);
        margin-left: 6px;
        letter-spacing: 2px;
    }

.app-sidenav-group {
    padding: 8px 12px;
    display: block;
}

.app-sidenav-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--nav-text-dim);
    padding: 8px 12px 6px;
}

.app-sidenav a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    margin: 1px 0;
    border-radius: var(--radius);
    color: var(--nav-text);
    text-decoration: none;
    font-size: 13.5px;
    position: relative;
}

    .app-sidenav a:hover {
        background: rgba(255,255,255,.06);
        color: #fff;
    }

    .app-sidenav a.active {
        background: rgba(239,65,54,.14);
        color: #fff;
        font-weight: 600;
    }

        .app-sidenav a.active::before {
            content: "";
            position: absolute;
            left: 0;
            top: 6px;
            bottom: 6px;
            width: 3px;
            background: var(--brand);
            border-radius: 0 3px 3px 0;
        }

    .app-sidenav a i.bi {
        font-size: 16px;
        flex-shrink: 0;
        opacity: .9;
    }

.app-sidenav-foot {
    margin-top: auto;
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.app-sidenav-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
}

    .app-sidenav-user .who {
        font-size: 13px;
        color: #fff;
        line-height: 1.2;
    }

        .app-sidenav-user .who small {
            display: block;
            color: var(--nav-text-dim);
            font-size: 11px;
        }

.app-sidenav-actions {
    display: flex;
    gap: 10px;
    padding: 4px 12px;
    font-size: 12px;
}

    .app-sidenav-actions a,
    .app-sidenav-actions button {
        background: none;
        border: none;
        padding: 0;
        color: var(--nav-text-dim);
        text-decoration: none;
    }

        .app-sidenav-actions a:hover,
        .app-sidenav-actions button:hover {
            color: #fff;
        }

.app-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    min-height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 24px;
    position: sticky;
    top: 0;
    z-index: 5;
}

    .app-topbar h1 {
        font-size: 17px;
        font-weight: 600;
        margin: 0;
        flex: 1;
        min-width: 0;
    }

.app-topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-search {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 7px 12px;
    font-size: 13px;
    color: var(--text-muted);
    width: 220px;
}

.app-icon-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text);
    flex-shrink: 0;
}

    .app-icon-btn:hover {
        background: var(--surface-2);
    }

.app-content {
    padding: 24px;
    width: 100%;
}

@media (max-width: 991.98px) {
    .app-topbar h1 {
        font-size: 15px;
    }
}

/*
 * Phase 4: quiet headers + components, app-wide.
 *
 * Semantic color remap for danger/warning/success/info, light and dark.
 * Same pattern established in Phase 2 for --bs-primary: plain root variables
 * (--bs-{color}/-rgb) retint utility classes (.bg-*/.text-*/.border-*) for
 * free since those reference the variable at use time. --bs-{color}-text-
 * emphasis/-bg-subtle/-border-subtle are Bootstrap 5.3's own accessible
 * pairing utilities (.text-warning-emphasis + .bg-warning-subtle etc.) --
 * reused here (rather than inventing new badge classes) specifically
 * because plain amber-on-white fails WCAG AA (~2.5:1) while the emphasis/
 * subtle pairing is verified >6:1 in both modes. --bs-danger maps to the
 * brand red itself per the mockup's rule that red is reserved for brand/
 * primary/destructive -- one red in the app, not two similar ones.
 */
:root {
    --bs-danger: var(--brand);
    --bs-danger-rgb: 207, 55, 46;

    --bs-warning: var(--warning);
    --bs-warning-rgb: 224, 145, 43;
    --bs-warning-text-emphasis: var(--warning-text);
    --bs-warning-bg-subtle: var(--warning-bg);
    --bs-warning-border-subtle: var(--warning);

    --bs-success: var(--success);
    --bs-success-rgb: 46, 158, 91;
    --bs-success-text-emphasis: var(--success-text);
    --bs-success-bg-subtle: var(--success-bg);
    --bs-success-border-subtle: var(--success);

    --bs-info: var(--info);
    --bs-info-rgb: 53, 116, 192;
    --bs-info-text-emphasis: var(--info-text);
    --bs-info-bg-subtle: var(--info-bg);
    --bs-info-border-subtle: var(--info);
}

[data-bs-theme="dark"] {
    --bs-danger: var(--brand);
    --bs-danger-rgb: 239, 65, 54;

    --bs-warning: var(--warning);
    --bs-warning-rgb: 224, 145, 43;
    --bs-warning-text-emphasis: var(--warning-text);
    --bs-warning-bg-subtle: var(--warning-bg);
    --bs-warning-border-subtle: var(--warning);

    --bs-success: var(--success);
    --bs-success-rgb: 59, 181, 109;
    --bs-success-text-emphasis: var(--success-text);
    --bs-success-bg-subtle: var(--success-bg);
    --bs-success-border-subtle: var(--success);

    --bs-info: var(--info);
    --bs-info-rgb: 79, 143, 214;
    --bs-info-text-emphasis: var(--info-text);
    --bs-info-bg-subtle: var(--info-bg);
    --bs-info-border-subtle: var(--info);
}

/* .btn-* components bake literal hex into their own scoped --bs-btn-*
   properties (confirmed in Phase 2 for .btn-primary) rather than reading
   the root color variables -- each used color variant needs the same
   explicit override. Text color per variant follows whichever of black/
   white actually passes contrast against that specific background. */
.btn-success {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--success);
    --bs-btn-border-color: var(--success);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--success-text);
    --bs-btn-hover-border-color: var(--success-text);
    --bs-btn-focus-shadow-rgb: var(--bs-success-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--success-text);
    --bs-btn-active-border-color: var(--success-text);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--success);
    --bs-btn-disabled-border-color: var(--success);
}

.btn-danger {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--brand-strong);
    --bs-btn-hover-border-color: var(--brand-strong);
    --bs-btn-focus-shadow-rgb: var(--bs-danger-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--brand-strong);
    --bs-btn-active-border-color: var(--brand-strong);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
}

.btn-warning {
    --bs-btn-color: #000;
    --bs-btn-bg: var(--warning);
    --bs-btn-border-color: var(--warning);
    --bs-btn-hover-color: #000;
    --bs-btn-hover-bg: var(--warning-text);
    --bs-btn-hover-border-color: var(--warning-text);
    --bs-btn-focus-shadow-rgb: var(--bs-warning-rgb);
    --bs-btn-active-color: #000;
    --bs-btn-active-bg: var(--warning-text);
    --bs-btn-active-border-color: var(--warning-text);
    --bs-btn-disabled-color: #000;
    --bs-btn-disabled-bg: var(--warning);
    --bs-btn-disabled-border-color: var(--warning);
}

.btn-info {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--info);
    --bs-btn-border-color: var(--info);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--info-text);
    --bs-btn-hover-border-color: var(--info-text);
    --bs-btn-focus-shadow-rgb: var(--bs-info-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--info-text);
    --bs-btn-active-border-color: var(--info-text);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--info);
    --bs-btn-disabled-border-color: var(--info);
}

/* Outline variants bake the same literal hex into their own scoped
   properties too -- only the three actually used in this app get the
   explicit override (warning/info outline buttons aren't used anywhere). */
.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--brand);
    --bs-btn-active-border-color: var(--brand);
    --bs-btn-disabled-color: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
}

.btn-outline-danger {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-focus-shadow-rgb: var(--bs-danger-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--brand);
    --bs-btn-active-border-color: var(--brand);
    --bs-btn-disabled-color: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
}

.btn-outline-success {
    --bs-btn-color: var(--success);
    --bs-btn-border-color: var(--success);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--success);
    --bs-btn-hover-border-color: var(--success);
    --bs-btn-focus-shadow-rgb: var(--bs-success-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--success);
    --bs-btn-active-border-color: var(--success);
    --bs-btn-disabled-color: var(--success);
    --bs-btn-disabled-border-color: var(--success);
}

/* Cards + quiet headers: .card and .card-header are fully variable-driven
   in Bootstrap 5.3 (confirmed by reading the vendored CSS), so this alone
   restyles every card app-wide -- EXCEPT instances with bg-primary/bg-light
   text-white utility classes still applied directly in markup (those use
   !important and win regardless); those need the utility classes removed
   at the markup level, done page-by-page separately from this file. */
.card {
    --bs-card-border-radius: var(--radius-lg);
    --bs-card-border-color: var(--border);
    --bs-card-cap-bg: transparent;
    --bs-card-cap-color: var(--text);
    --bs-card-bg: var(--surface);
    --bs-card-color: var(--text);
}

/* Tables: token colors + uppercase muted column headers, matching the
   mockup's th{} rule. --bs-table-bg defaults to --bs-body-bg (mapped to
   --page in Phase 2) which would mismatch a table sitting inside a
   --surface card, so it's pinned to --surface directly here instead. */
.table {
    --bs-table-bg: var(--surface);
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--border);
    --bs-table-hover-bg: var(--surface-2);
    --bs-table-hover-color: var(--text);
}

    .table > thead > tr > th {
        text-transform: uppercase;
        font-size: .75rem;
        letter-spacing: .04em;
        font-weight: 600;
        color: var(--text-muted);
    }

/* Small general-purpose utility, same spirit as Bootstrap's own .bg-light/
   .bg-white but theme-aware (bg-light stays literally light in dark mode). */
.bg-surface-2 {
    background-color: var(--surface-2) !important;
}
