/* =====================================================================
   BRAINX Analytics — Design System
   ---------------------------------------------------------------------
   A thin theming layer on top of Bootstrap 5.3 (CDN, no build step).
   All colours live as CSS custom properties so new pages/components
   inherit the brand automatically. Two themes: dark (default) + light,
   switched via <html data-bs-theme="...">.

   Brand palette (from the BRAINX logo):
     primary  #1090e0   highlight #38a8f0   navy #203050
   ===================================================================== */

:root,
[data-bs-theme="dark"] {
    --bx-bg:          #0b1120;
    --bx-surface:     #131c30;
    --bx-surface-2:   #1b2540;
    --bx-border:      rgba(255, 255, 255, .07);
    --bx-text:        #e7ecf6;
    --bx-heading:     #ffffff;
    --bx-muted:       #8a97b4;

    --bx-primary:     #1a93e6;
    --bx-primary-2:   #38a8f0;
    --bx-primary-soft: rgba(26, 147, 230, .16);
    --bx-shadow:      0 10px 30px -12px rgba(0, 0, 0, .55);

    --bx-success:     #22c55e;
    --bx-danger:      #f43f5e;
    --bx-warning:     #f59e0b;

    /* Bootstrap overrides so its own components (dropdowns, tables,
       form controls, pagination) pick up the brand automatically. */
    --bs-body-bg: var(--bx-bg);
    --bs-body-color: var(--bx-text);
    --bs-primary: var(--bx-primary);
    --bs-primary-rgb: 26, 147, 230;
    --bs-border-color: var(--bx-border);
    --bs-emphasis-color: var(--bx-heading);
    --bs-secondary-color: var(--bx-muted);
    --bs-link-color: var(--bx-primary-2);
    --bs-link-hover-color: #6fc0f6;
}

[data-bs-theme="light"] {
    --bx-bg:          #eef2f9;
    --bx-surface:     #ffffff;
    --bx-surface-2:   #f2f5fb;
    --bx-border:      #e4e9f2;
    --bx-text:        #1f2a44;
    --bx-heading:     #0f1a30;
    --bx-muted:       #64748b;

    --bx-primary:     #1090e0;
    --bx-primary-2:   #0f7ac2;
    --bx-primary-soft: rgba(16, 144, 224, .10);
    --bx-shadow:      0 10px 30px -14px rgba(20, 40, 80, .22);

    --bs-body-bg: var(--bx-bg);
    --bs-body-color: var(--bx-text);
    --bs-primary: var(--bx-primary);
    --bs-primary-rgb: 16, 144, 224;
    --bs-border-color: var(--bx-border);
    --bs-emphasis-color: var(--bx-heading);
    --bs-secondary-color: var(--bx-muted);
    --bs-link-color: var(--bx-primary);
    --bs-link-hover-color: #0a5f9a;
}

/* The sidebar keeps a deep brand-navy in BOTH themes for identity. */
:root {
    --bx-sidebar-bg:   #0d1526;
    --bx-sidebar-item:  #9aa6c4;
    --bx-sidebar-hover: rgba(255, 255, 255, .06);
    --bx-sidebar-w: 256px;
    --bx-sidebar-w-collapsed: 78px;
    --bx-topbar-h: 68px;
}

/* --------------------------------------------------------------------- */
/* Base                                                                  */
/* --------------------------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--bx-surface-2) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--bx-surface-2); border-radius: 9px; }

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bx-bg);
    color: var(--bx-text);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6, .bx-display {
    font-family: 'Poppins', 'Inter', system-ui, sans-serif;
    color: var(--bx-heading);
    letter-spacing: -.01em;
}

/* --------------------------------------------------------------------- */
/* App shell: sidebar + main                                             */
/* --------------------------------------------------------------------- */
.bx-app {
    display: grid;
    grid-template-columns: var(--bx-sidebar-w) 1fr;
    min-height: 100vh;
    transition: grid-template-columns .22s ease;
}
.bx-app.is-collapsed { grid-template-columns: var(--bx-sidebar-w-collapsed) 1fr; }

/* Backdrop is only used for the mobile slide-over; keep it out of the desktop
   grid entirely (otherwise it becomes an in-flow grid item and shifts columns). */
.bx-backdrop { display: none; }

/* Sidebar ------------------------------------------------------------- */
.bx-sidebar {
    background: var(--bx-sidebar-bg);
    border-right: 1px solid rgba(255, 255, 255, .05);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1040;
    overflow: hidden;
}
.bx-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: 0 1.25rem;
    height: var(--bx-topbar-h);
    flex: 0 0 auto;
    border-bottom: 1px solid rgba(255, 255, 255, .05);
    white-space: nowrap;
}
.bx-brand img { height: 26px; width: auto; display: block; }
.bx-brand .bx-brand-fallback {
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    font-size: 1.15rem;
    color: #fff;
    letter-spacing: .02em;
}
.is-collapsed .bx-brand { padding: 0; justify-content: center; }

.bx-nav {
    list-style: none;
    margin: 0;
    padding: 1rem .75rem;
    overflow-y: auto;
    flex: 1 1 auto;
}
.bx-nav-label {
    color: #55617f;
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .1em;
    padding: .75rem .9rem .4rem;
}
.is-collapsed .bx-nav-label { opacity: 0; height: .5rem; padding: 0; }
.bx-nav-item {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .7rem .9rem;
    margin-bottom: .18rem;
    border-radius: 11px;
    color: var(--bx-sidebar-item);
    text-decoration: none;
    font-weight: 500;
    font-size: .92rem;
    white-space: nowrap;
    transition: background .15s, color .15s;
    position: relative;
}
.bx-nav-item svg { width: 20px; height: 20px; flex: 0 0 20px; }
.bx-nav-item:hover { background: var(--bx-sidebar-hover); color: #fff; }
.bx-nav-item.active {
    background: linear-gradient(90deg, var(--bx-primary), var(--bx-primary-2));
    color: #fff;
    box-shadow: 0 8px 18px -8px rgba(26, 147, 230, .8);
}
.is-collapsed .bx-nav-item { justify-content: center; padding: .7rem; }
.is-collapsed .bx-nav-item .bx-nav-text { display: none; }

/* Main ---------------------------------------------------------------- */
.bx-main { display: flex; flex-direction: column; min-width: 0; }

.bx-topbar {
    height: var(--bx-topbar-h);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    background: color-mix(in srgb, var(--bx-surface) 88%, transparent);
    border-bottom: 1px solid var(--bx-border);
    position: sticky;
    top: 0;
    z-index: 1030;
    backdrop-filter: blur(10px);
}
.bx-icon-btn {
    width: 42px; height: 42px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 11px;
    border: 1px solid var(--bx-border);
    background: var(--bx-surface-2);
    color: var(--bx-text);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    position: relative;
}
.bx-icon-btn:hover { color: var(--bx-primary-2); border-color: var(--bx-primary); }
.bx-icon-btn svg { width: 20px; height: 20px; }
.bx-icon-btn .bx-dot {
    position: absolute; top: 9px; right: 10px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--bx-warning);
    border: 2px solid var(--bx-surface);
}

.bx-user {
    display: flex; align-items: center; gap: .6rem;
    padding: .3rem .3rem .3rem .35rem;
    border-radius: 12px;
    border: 1px solid var(--bx-border);
    background: var(--bx-surface-2);
    color: var(--bx-text);
    cursor: pointer;
}
.bx-user:hover { border-color: var(--bx-primary); }
.bx-avatar {
    width: 34px; height: 34px; border-radius: 9px;
    background: linear-gradient(135deg, var(--bx-primary), var(--bx-primary-2));
    color: #fff; font-weight: 600; font-size: .85rem;
    display: inline-flex; align-items: center; justify-content: center;
    font-family: 'Poppins', sans-serif;
}

.bx-content { padding: 1.75rem 1.5rem; flex: 1 1 auto; }
.bx-page-title { font-size: 1.5rem; font-weight: 600; margin: 0; }
.bx-page-sub { color: var(--bx-muted); font-size: .9rem; margin-top: .15rem; }

/* --------------------------------------------------------------------- */
/* Cards                                                                 */
/* --------------------------------------------------------------------- */
.bx-card {
    background: var(--bx-surface);
    border: 1px solid var(--bx-border);
    border-radius: 16px;
    box-shadow: var(--bx-shadow);
}
.bx-card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem;
    padding: 1.15rem 1.35rem;
    border-bottom: 1px solid var(--bx-border);
}
.bx-card-title { font-size: 1.02rem; font-weight: 600; margin: 0; }
.bx-card-sub { color: var(--bx-muted); font-size: .82rem; margin-top: .1rem; }
.bx-card-body { padding: 1.35rem; }

/* KPI cards ----------------------------------------------------------- */
.bx-kpi {
    background: var(--bx-surface);
    border: 1px solid var(--bx-border);
    border-radius: 16px;
    padding: 1.3rem 1.35rem;
    box-shadow: var(--bx-shadow);
    height: 100%;
    position: relative;
    overflow: hidden;
    transition: transform .15s ease, border-color .15s ease;
}
.bx-kpi:hover { transform: translateY(-3px); border-color: rgba(26,147,230,.4); }
.bx-kpi-top { display: flex; align-items: flex-start; justify-content: space-between; }
.bx-kpi-label {
    color: var(--bx-muted);
    font-size: .82rem;
    font-weight: 500;
}
.bx-kpi-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--bx-primary-soft);
    color: var(--bx-primary-2);
    flex: 0 0 auto;
}
.bx-kpi-icon svg { width: 22px; height: 22px; }
.bx-kpi-value {
    font-family: 'Poppins', sans-serif;
    font-size: 2rem;
    font-weight: 600;
    color: var(--bx-heading);
    line-height: 1.1;
    margin-top: .9rem;
    word-break: break-word;
}
.bx-kpi-foot { margin-top: .55rem; font-size: .8rem; color: var(--bx-muted); display: flex; align-items: center; gap: .4rem; }
.bx-chip {
    display: inline-flex; align-items: center; gap: .25rem;
    padding: .12rem .5rem; border-radius: 999px;
    font-size: .72rem; font-weight: 600;
}
.bx-chip-up   { background: rgba(34,197,94,.15);  color: #4ade80; }
.bx-chip-down { background: rgba(244,63,94,.15);   color: #fb7185; }
.bx-chip-info { background: var(--bx-primary-soft); color: var(--bx-primary-2); }

/* --------------------------------------------------------------------- */
/* Segmented control (date filters)                                      */
/* --------------------------------------------------------------------- */
.bx-seg { display: inline-flex; background: var(--bx-surface-2); border-radius: 12px; padding: 4px; gap: 2px; }
.bx-seg button {
    border: 0; background: transparent; color: var(--bx-muted);
    padding: .45rem .9rem; border-radius: 9px; font-size: .85rem; font-weight: 600;
    cursor: pointer; transition: all .15s;
}
.bx-seg button:hover { color: var(--bx-text); }
.bx-seg button.active {
    background: linear-gradient(90deg, var(--bx-primary), var(--bx-primary-2));
    color: #fff; box-shadow: 0 6px 14px -6px rgba(26,147,230,.7);
}

.bx-field-label { color: var(--bx-muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: .3rem; }

/* Form controls tuned to the surface tones */
.bx-card .form-control,
.bx-card .form-select,
.bx-input {
    background: var(--bx-surface-2);
    border: 1px solid var(--bx-border);
    color: var(--bx-text);
    border-radius: 10px;
}
.bx-input:focus, .bx-card .form-control:focus {
    background: var(--bx-surface-2);
    color: var(--bx-text);
    border-color: var(--bx-primary);
    box-shadow: 0 0 0 3px var(--bx-primary-soft);
}

/* --------------------------------------------------------------------- */
/* Tables                                                                */
/* --------------------------------------------------------------------- */
.bx-table { width: 100%; margin: 0; color: var(--bx-text); border-collapse: separate; border-spacing: 0; }
.bx-table thead th {
    background: var(--bx-surface-2);
    color: var(--bx-muted);
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: .8rem 1rem;
    border: 0;
    white-space: nowrap;
}
.bx-table thead th:first-child { border-top-left-radius: 10px; border-bottom-left-radius: 10px; }
.bx-table thead th:last-child { border-top-right-radius: 10px; border-bottom-right-radius: 10px; }
.bx-table tbody td {
    padding: .78rem 1rem;
    border-top: 1px solid var(--bx-border);
    font-size: .88rem;
    vertical-align: middle;
}
.bx-table tbody tr { transition: background .12s; }
.bx-table tbody tr:hover td { background: var(--bx-surface-2); }
.bx-th-sort { cursor: pointer; user-select: none; }
.bx-th-sort:hover { color: var(--bx-text); }
.bx-sort-ind { color: var(--bx-primary-2); }
.bx-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }

.bx-badge-soft {
    display: inline-block; padding: .2rem .55rem; border-radius: 8px;
    background: var(--bx-primary-soft); color: var(--bx-primary-2);
    font-size: .75rem; font-weight: 600;
}

/* Expand/collapse button in session rows */
.bx-expand {
    width: 26px; height: 26px; border-radius: 8px; line-height: 1;
    border: 1px solid var(--bx-border); background: var(--bx-surface-2);
    color: var(--bx-text); cursor: pointer; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center;
}
.bx-expand:hover { border-color: var(--bx-primary); color: var(--bx-primary-2); }
.bx-sublog { background: var(--bx-bg); border-radius: 12px; padding: 1rem; }

/* Pagination (Livewire bootstrap view) */
.bx-card .pagination { --bs-pagination-bg: var(--bx-surface-2); margin: 0; }
.bx-card .page-link {
    background: var(--bx-surface-2); border-color: var(--bx-border); color: var(--bx-text);
}
.bx-card .page-link:hover { background: var(--bx-primary-soft); color: var(--bx-primary-2); }
.bx-card .page-item.active .page-link { background: var(--bx-primary); border-color: var(--bx-primary); color: #fff; }
.bx-card .page-item.disabled .page-link { background: var(--bx-surface); color: var(--bx-muted); }

/* Dropdown menu polish */
.dropdown-menu {
    background: var(--bx-surface);
    border: 1px solid var(--bx-border);
    box-shadow: var(--bx-shadow);
    border-radius: 12px;
}
.dropdown-item { color: var(--bx-text); border-radius: 8px; }
.dropdown-item:hover { background: var(--bx-surface-2); color: var(--bx-primary-2); }

/* --------------------------------------------------------------------- */
/* Responsive                                                            */
/* --------------------------------------------------------------------- */
@media (max-width: 991.98px) {
    .bx-app { grid-template-columns: 1fr; }
    .bx-sidebar {
        position: fixed; left: 0; top: 0; width: var(--bx-sidebar-w);
        transform: translateX(-100%); transition: transform .22s ease;
    }
    .bx-app.is-mobile-open .bx-sidebar { transform: translateX(0); }
    .bx-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1035; display: none; }
    .bx-app.is-mobile-open .bx-backdrop { display: block; }
}
