/* ---------------------------------------------------------------------------
   BillHR theme layer.

   Colors are expressed through Bootstrap 5.3's CSS variables so light and dark
   both come from one set of rules. Only genuinely theme-specific values live in
   the [data-bs-theme="dark"] block near the bottom.
   --------------------------------------------------------------------------- */

:root {
    --bh-surface: var(--bs-body-bg);
    --bh-login-from: #e8f0ff;
    --bh-login-to: #f2ecfb;

    /* Soft light shell -----------------------------------------------------
       The navbar and sidebar are near-white with hairline separators rather
       than solid dark panels; hierarchy comes from tint and weight instead of
       heavy fills. Every text token below is kept at 4.5:1 or better against
       the surface it sits on. */
    --bh-shell-bg: #ffffff;
    --bh-shell-bg-alt: #fbfcfe;
    --bh-shell-border: #e5eaf2;
    --bh-shell-text: #55637a;
    --bh-shell-text-strong: #16233a;
    --bh-shell-icon: #8d9bb3;
    --bh-shell-heading: #8593ab;
    --bh-shell-hover-bg: #f1f5fb;
    --bh-shell-active-bg: #e9f1ff;
    --bh-shell-active-text: #1d4fd8;

    /* Animated sidebar wash: a vivid blue -> indigo -> violet drift. The
       sidebar is the one dark, saturated panel in the shell, so it carries its
       own light-on-dark text tokens below instead of the shell greys. */
    --bh-sidebar-grad-1: #4438f2;
    --bh-sidebar-grad-2: #3520d6;
    --bh-sidebar-grad-3: #5b28e8;
    --bh-sidebar-grad-4: #2b1cb8;

    --bh-sidebar-text: rgba(255, 255, 255, .85);
    --bh-sidebar-text-strong: #ffffff;
    --bh-sidebar-icon: rgba(255, 255, 255, .70);
    --bh-sidebar-heading: rgba(255, 255, 255, .58);
    --bh-sidebar-hover-bg: rgba(255, 255, 255, .12);
    --bh-sidebar-active-bg: rgba(255, 255, 255, .18);

    --bh-accent-start: #2f6fed;
    --bh-accent-end: #1d4fd8;
    --bh-page-bg: #f5f7fb;
    --bh-card-border: #e8edf5;
    --bh-card-shadow: 0 1px 2px rgba(16, 32, 64, .04), 0 6px 20px rgba(16, 32, 64, .05);
}

body {
    font-size: .9rem;
    background-color: var(--bh-page-bg);
}

/* Top navbar --------------------------------------------------------------- */

.app-navbar {
    /* Solid navy chrome in both themes; text flips to light to match. */
    background: linear-gradient(90deg, #101c3d, #16295c);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    box-shadow: 0 1px 3px rgba(6, 12, 30, .35);
}

.app-navbar .navbar-brand {
    color: #ffffff;
    font-weight: 600;
}

.app-navbar .navbar-brand .bi {
    color: #8fb4ff;
}

.app-navbar .nav-link,
.app-navbar .navbar-user {
    color: rgba(255, 255, 255, .85);
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link:focus {
    color: #ffffff;
}

.app-navbar .navbar-toggler {
    border-color: rgba(255, 255, 255, .25);
    color: rgba(255, 255, 255, .85);
}

.app-navbar .navbar-toggler-icon {
    /* Bootstrap bakes the stroke colour into a background image, so the light
       stroke for the navy bar has to be supplied here rather than via a CSS
       variable. */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%23dbe4f5' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* Sidebar ----------------------------------------------------------------- */

.sidebar {
    min-height: calc(100vh - 48px);
    /* Slow drifting colour wash. The gradient is 4x the pane height and the
       animation slides it, so the visible slice cycles through all four hues.
       The gradient lives in background-image so the markup's .bg-light class
       (whose background-color carries !important) can't paint over it. */
    background-color: var(--bh-sidebar-grad-2);
    background-image: linear-gradient(170deg,
        var(--bh-sidebar-grad-1) 0%,
        var(--bh-sidebar-grad-2) 30%,
        var(--bh-sidebar-grad-3) 55%,
        var(--bh-sidebar-grad-4) 80%,
        var(--bh-sidebar-grad-1) 100%);
    background-size: 100% 400%;
    animation: bh-sidebar-drift 24s ease-in-out infinite alternate;
    border-right: 1px solid rgba(255, 255, 255, .08);
}

@keyframes bh-sidebar-drift {
    from { background-position: 50% 0%; }
    to   { background-position: 50% 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar {
        /* Keep the static gradient (the light text depends on it); only the
           motion is dropped. */
        animation: none;
    }
}

/* Independent scroll panes ------------------------------------------------
   At md+ the sidebar and main content sit side by side (Bootstrap's own
   col-md-* breakpoint), so that's also where we lock the navbar in place and
   give the sidebar and main content each their own scrollbar. Below md the
   sidebar collapses into a toggleable in-flow panel (Bootstrap's .collapse),
   so the page is left to scroll normally there rather than fighting that
   mechanic with a split-pane layout that doesn't apply to a stacked view. */
@media (min-width: 768px) {
    html, body {
        height: 100%;
    }

    body {
        display: flex;
        flex-direction: column;
        overflow: hidden; /* the shell itself never scrolls — only the panes below do */
    }

    body > .navbar {
        flex: 0 0 auto;
    }

    body > .container-fluid {
        flex: 1 1 auto;
        min-height: 0; /* let this shrink so its children can scroll instead of overflowing the page */
        display: flex;
        flex-direction: column;
    }

    body > .container-fluid > .row {
        flex: 1 1 auto;
        min-height: 0;
    }

    .sidebar,
    main {
        height: 100%;
        overflow-y: auto;
        overscroll-behavior: contain; /* stop scroll chaining into the other pane */
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar {
        min-height: 0; /* replaces the min-height:100vh rule above now that height is flex-driven */
    }
}

.sidebar .nav-link {
    color: var(--bh-sidebar-text);
    font-weight: 500;
    font-size: .95rem;
    padding: .55rem 1rem;
    border-radius: .6rem;
    margin: .1rem .6rem;
    transition: background-color .15s ease, color .15s ease;
    /* Keep every menu label on one line; ellipsize rather than wrap. */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar .nav-link:hover {
    background: var(--bh-sidebar-hover-bg);
    color: var(--bh-sidebar-text-strong);
}

.sidebar .nav-link .bi {
    margin-right: 8px;
    color: var(--bh-sidebar-icon);
}

.sidebar .nav-link:hover .bi {
    color: var(--bh-sidebar-text-strong);
}

/* The active item is a frosted white pill on the gradient, like the mock's
   glassy card: translucent fill, full-white text. */
.sidebar .nav-link.active,
.sidebar .nav-link.active .bi {
    color: var(--bh-sidebar-text-strong);
}

.sidebar .nav-link.active {
    background: var(--bh-sidebar-active-bg);
    font-weight: 600;
}

.sidebar-heading {
    font-size: .72rem;
    letter-spacing: .06em;
    color: var(--bh-sidebar-heading) !important;
    font-weight: 700;
}

/* Support card: frosted glass panel at the foot of the gradient sidebar. */
.sidebar-support {
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 1rem;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.sidebar-support-img {
    width: 35%;
    height: auto;
}

.sidebar-support-sub {
    color: rgba(255, 255, 255, .75);
}

.sidebar-support-btn {
    background: linear-gradient(90deg, #6a5cff, #9256f0);
    color: #fff;
    border: 0;
    border-radius: 2rem;
    font-weight: 600;
}

.sidebar-support-btn:hover,
.sidebar-support-btn:focus {
    color: #fff;
    filter: brightness(1.1);
}

/* Cards / tables ---------------------------------------------------------- */

/* A hairline plus a soft shadow keeps white cards legible on the light page
   background now that there is no dark chrome to frame them. */
.card {
    border: 1px solid var(--bh-card-border);
    border-radius: .9rem;
    box-shadow: var(--bh-card-shadow);
}

.card .card-header {
    background: var(--bh-shell-bg-alt);
    border-bottom-color: var(--bh-card-border);
}

.card .card-footer {
    background: var(--bh-shell-bg-alt);
    border-top-color: var(--bh-card-border);
}

.stat-card {
    border: 1px solid var(--bh-card-border);
    border-left: 4px solid var(--bs-primary);
    border-radius: .9rem;
    transition: transform .15s ease, box-shadow .15s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 .5rem 1.25rem rgba(20, 30, 70, .09) !important;
}

.stat-card .display-6 {
    font-weight: 700;
}

.table-sm td, .table-sm th {
    vertical-align: middle;
}

/* Theme switcher -----------------------------------------------------------
   The navbar has no .navbar-expand-* class (its collapsible content is the
   separate #sidebarMenu, not a .navbar-collapse), so Bootstrap's own rule
   that keeps `.navbar-nav .dropdown-menu` in-flow (`position: static`) at
   narrow widths never gets overridden back to `absolute`. Without this, the
   theme dropdown pushes the navbar taller instead of floating over it. */

.theme-switch .dropdown-menu {
    position: absolute !important;
    z-index: 1080;
}

.theme-switch .dropdown-item.active {
    background: var(--bs-secondary-bg);
    color: var(--bs-body-color);
}

/* Login / OTP ------------------------------------------------------------- */

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bh-login-from) 0%, var(--bh-login-to) 100%);
}

.login-card {
    max-width: 380px;
    width: 100%;
}

.login-theme-switch {
    position: fixed;
    top: 1rem;
    right: 1rem;
}

/* Invoice ----------------------------------------------------------------- */

.invoice-box {
    background: var(--bh-surface);
    padding: 2rem;
    border: 1px solid var(--bs-border-color);
    border-radius: .5rem;
}

/* Dark theme -------------------------------------------------------------- */

[data-bs-theme="dark"] {
    --bh-surface: var(--bs-secondary-bg);
    --bh-page-bg: var(--bs-body-bg);
    --bh-login-from: #16233f;
    --bh-login-to: #241a3d;

    /* The shell tokens flip here so the light rules above need no dark twins. */
    --bh-shell-bg: #151b2b;
    --bh-shell-bg-alt: #171d2e;
    --bh-shell-border: rgba(255, 255, 255, .09);
    --bh-shell-text: #a9b4c9;
    --bh-shell-text-strong: #ffffff;
    --bh-shell-icon: #7e8ba4;
    --bh-shell-heading: #7f8da8;
    --bh-shell-hover-bg: rgba(255, 255, 255, .06);
    --bh-shell-active-bg: rgba(47, 111, 237, .20);
    --bh-shell-active-text: #93b4ff;

    /* Dark twins of the sidebar wash: the same blue -> indigo -> violet drift,
       deepened a step so the panel doesn't glow against the dark page. */
    --bh-sidebar-grad-1: #3229c4;
    --bh-sidebar-grad-2: #2617a8;
    --bh-sidebar-grad-3: #441dba;
    --bh-sidebar-grad-4: #1e148c;
    --bh-card-border: rgba(255, 255, 255, .08);
    --bh-card-shadow: 0 1px 2px rgba(0, 0, 0, .28);
}

[data-bs-theme="dark"] .app-navbar .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%23a9b4c9' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* Bootstrap's .bg-light / .table-light / .badge.bg-light are fixed light
   colors that do not respond to data-bs-theme; remap them so existing markup
   stays readable in dark mode. */
[data-bs-theme="dark"] .bg-light {
    background-color: var(--bs-tertiary-bg) !important;
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .table-light {
    --bs-table-bg: var(--bs-tertiary-bg);
    --bs-table-color: var(--bs-body-color);
    --bs-table-border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .badge.bg-light {
    background-color: var(--bs-secondary-bg) !important;
}

[data-bs-theme="dark"] .badge.bg-light.text-dark {
    color: var(--bs-body-color) !important;
}

/* Print: always render the light, ink-friendly version. ------------------- */

@media print {
    html, body, .container-fluid, .container-fluid > .row, main {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
    }
    .no-print, .sidebar, .navbar, .theme-switch {
        display: none !important;
    }
    main {
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }
    .invoice-box {
        border: none !important;
        box-shadow: none !important;
        background: #fff !important;
        color: #000 !important;
    }
    body {
        background: #fff !important;
        color: #000 !important;
    }
}
