/* ==========================================================================
   Trackion Console

   Same brand as trackion.net -- slate-900 chrome, blue-600 actions, slate
   surfaces -- on an application rhythm rather than a marketing one. The site's
   80px section padding and 4rem headings are right for a landing page and
   wrong for a screen someone reads a fleet off, so the spacing scale is tight
   and the type scale is small and dense.

   COLOR IS SPLIT IN TWO, DELIBERATELY:

     --accent*   UI chrome: buttons, links, focus rings, selected rows.
                 This is the brand blue #2563eb straight off the site.

     --mark-*    Data ink: the marks on the log graph. NOT the brand blue.

   The first draft used brand blue for Driving and violet for Personal
   Conveyance. Run through a CVD check that pair scores deutan ΔE 0.4 -- a
   red-green colorblind reader (about 1 in 12 men, and this is a trucking
   product) sees one color. Blue/orange/aqua scores 9.2 and is what shipped.
   Chrome and data ink answer to different constraints; keeping them separate
   is what lets the brand stay the brand.
   ========================================================================== */

:root {
    color-scheme: light;

    /* Surfaces */
    --bg:            #f1f5f9;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --sidebar:       #0f172a;
    --sidebar-2:     #1e293b;

    /* Ink */
    --ink:           #0f172a;
    --ink-2:         #475569;
    --ink-3:         #64748b;
    --ink-on-dark:   #f8fafc;
    --ink-on-dark-2: #94a3b8;

    /* Lines */
    --line:          #e2e8f0;
    --line-2:        #cbd5e1;

    /* Brand / chrome */
    --accent:        #2563eb;
    --accent-hover:  #1d4ed8;
    --accent-soft:   #eff6ff;
    --accent-line:   #bfdbfe;

    /* Data ink -- CVD-validated trio (deutan ΔE 9.2, normal ΔE 27.6) */
    --mark-driving:  #2a78d6;
    --mark-pc:       #eb6834;
    --mark-ym:       #1baf7a;
    --mark-line:     #334155;   /* the duty step line itself */
    --mark-grid:     #e2e8f0;

    /* Status -- always paired with an icon or a word, never colour alone.
       warning/serious are sub-3:1 on white by design; the label is the relief. */
    --ok:            #0ca30c;
    --warn:          #fab219;
    --serious:       #ec835a;
    --critical:      #d03b3b;
    --ok-soft:       #f0fdf4;
    --warn-soft:     #fffbeb;
    --critical-soft: #fef2f2;

    --radius:        8px;
    --radius-lg:     12px;
    --shadow:        0 1px 2px rgba(15, 23, 42, .06),
                     0 1px 3px rgba(15, 23, 42, .04);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial,
            Helvetica, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --sidebar-w: 232px;
}

/* Dark mode is SELECTED, not flipped: the mark hues are re-stepped for a dark
   surface and re-validated (deutan ΔE 9.4, all three clear 3:1 on #0f172a),
   because simply inverting lightness would have pushed aqua under contrast. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --bg:            #020617;
        --surface:       #0f172a;
        --surface-2:     #1e293b;
        --sidebar:       #020617;
        --sidebar-2:     #0f172a;

        --ink:           #f1f5f9;
        --ink-2:         #cbd5e1;
        --ink-3:         #94a3b8;

        --line:          #1e293b;
        --line-2:        #334155;

        --accent:        #3b82f6;
        --accent-hover:  #60a5fa;
        --accent-soft:   #172554;
        --accent-line:   #1e40af;

        --mark-driving:  #3987e5;
        --mark-pc:       #d95926;
        --mark-ym:       #199e70;
        --mark-line:     #cbd5e1;
        --mark-grid:     #1e293b;

        --ok-soft:       #052e16;
        --warn-soft:     #422006;
        --critical-soft: #450a0a;

        --shadow:        0 1px 2px rgba(0, 0, 0, .4);
    }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ------------------------------------------------------------------ boot */

.boot {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--sidebar);
    color: var(--ink-on-dark);
}
.boot-mark { font-size: 22px; font-weight: 700; letter-spacing: 2px; }
.boot-note { color: var(--ink-on-dark-2); font-size: 13px; }

/* ----------------------------------------------------------------- login */

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(rgba(15, 23, 42, .88), rgba(15, 23, 42, .94)),
        var(--sidebar);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: 0 20px 40px rgba(2, 6, 23, .35);
}
.login-brand {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--ink);
    text-align: center;
}
.login-sub {
    text-align: center;
    color: var(--ink-3);
    font-size: 13px;
    margin: 4px 0 24px;
}

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

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--sidebar);
    color: var(--ink-on-dark);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand {
    padding: 20px 18px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 2px;
    border-bottom: 1px solid rgba(148, 163, 184, .16);
}
.sidebar-org {
    padding: 12px 18px;
    border-bottom: 1px solid rgba(148, 163, 184, .16);
}
.sidebar-org-name {
    font-size: 13px; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-org-meta { font-size: 11px; color: var(--ink-on-dark-2); }

.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.nav-group {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--ink-on-dark-2);
    padding: 14px 10px 6px;
}
.nav a {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: 6px;
    color: #cbd5e1;
    font-size: 13.5px;
    text-decoration: none;
}
.nav a:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; font-weight: 500; }
.nav a .ico { width: 16px; text-align: center; opacity: .9; flex: none; }
.nav a .count {
    margin-left: auto;
    font-size: 11px;
    background: rgba(148, 163, 184, .22);
    padding: 1px 6px;
    border-radius: 999px;
}
.nav a.disabled { opacity: .45; pointer-events: none; }

.sidebar-user {
    padding: 12px 18px;
    border-top: 1px solid rgba(148, 163, 184, .16);
    font-size: 12px;
}
.sidebar-user .who { color: var(--ink-on-dark); font-weight: 500; }
.sidebar-user .mail {
    color: var(--ink-on-dark-2);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-user button {
    margin-top: 8px; width: 100%;
    background: transparent;
    border: 1px solid rgba(148, 163, 184, .3);
    color: #cbd5e1;
    padding: 6px; border-radius: 6px;
    font: inherit; font-size: 12px; cursor: pointer;
}
.sidebar-user button:hover { background: var(--sidebar-2); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 14px 24px;
    display: flex; align-items: center; gap: 16px;
    position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; font-weight: 600; }
.topbar .sub { color: var(--ink-3); font-size: 12.5px; }
.topbar .spacer { flex: 1; }

.content { padding: 22px 24px 48px; }

/* ------------------------------------------------------------- primitives */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.card-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 12px;
}
.card-head h2 { font-size: 14px; font-weight: 600; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 18px; }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    background: var(--accent); color: #fff;
    border: 1px solid transparent; border-radius: var(--radius);
    font: inherit; font-size: 13px; font-weight: 500;
    cursor: pointer; text-decoration: none;
    transition: background .15s ease;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary {
    background: var(--surface); color: var(--ink);
    border-color: var(--line-2);
}
.btn.secondary:hover { background: var(--surface-2); }
.btn.small { padding: 5px 10px; font-size: 12px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span {
    display: block; font-size: 12px; font-weight: 500;
    color: var(--ink-2); margin-bottom: 5px;
}
input, select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    font: inherit; font-size: 13.5px;
    background: var(--surface); color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.inline-field { display: flex; flex-direction: column; gap: 4px; }
.inline-field > span { font-size: 11px; font-weight: 500; color: var(--ink-3); }
.inline-field input, .inline-field select { width: auto; min-width: 170px; }

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

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    text-align: left;
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em;
    color: var(--ink-3);
    padding: 9px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
    position: sticky; top: 0;
}
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.table-scroll { overflow-x: auto; }

/* --------------------------------------------------------------- badges */

.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px; font-weight: 600;
    border: 1px solid var(--line-2);
    color: var(--ink-2);
    background: var(--surface-2);
    white-space: nowrap;
}
.badge.accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-hover); }
.badge.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.badge.warn { background: var(--warn-soft); border-color: var(--warn); color: #92400e; }
.badge.critical { background: var(--critical-soft); border-color: var(--critical); color: var(--critical); }

/* ------------------------------------------------------------ stat tiles */

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
}
.tile {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}
.tile .label {
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em;
    color: var(--ink-3);
}
/* A hero number: no plot, so no hover layer. The number IS the chart. */
.tile .value {
    font-size: 30px; font-weight: 600; line-height: 1.15;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}
.tile .note { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.tile.alert .value { color: var(--critical); }

/* ------------------------------------------------------------- log graph */

.logchart { width: 100%; overflow-x: auto; }
.logchart svg { display: block; min-width: 720px; }
.lane-label { font-size: 11px; font-weight: 600; fill: var(--ink-2); }
.hour-label { font-size: 10px; fill: var(--ink-3); }
.grid-line { stroke: var(--mark-grid); stroke-width: 1; }
.grid-line.major { stroke: var(--line-2); }
/* 2px, per the mark spec -- the step line is the primary read */
.duty-line { fill: none; stroke: var(--mark-line); stroke-width: 2; stroke-linejoin: round; }
.seg-driving { fill: var(--mark-driving); opacity: .16; }
.seg-pc { fill: var(--mark-pc); opacity: .18; }
.seg-ym { fill: var(--mark-ym); opacity: .22; }
.seg-hit { fill: transparent; cursor: crosshair; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }

.totals { display: flex; gap: 22px; flex-wrap: wrap; }
.totals .t-label { font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.totals .t-value { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }

.tooltip {
    position: fixed;
    z-index: 100;
    pointer-events: none;
    background: var(--sidebar);
    color: #f8fafc;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.45;
    box-shadow: 0 6px 18px rgba(2, 6, 23, .3);
    max-width: 260px;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 2px; }
.tooltip .tt-row { color: #cbd5e1; }

/* ------------------------------------------------------------- messaging */

.empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--ink-3);
}
.empty .empty-title { font-weight: 600; color: var(--ink-2); margin-bottom: 4px; font-size: 14px; }
.empty .empty-note { font-size: 13px; max-width: 460px; margin: 0 auto; }

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid;
    margin-bottom: 14px;
}
.alert.error { background: var(--critical-soft); border-color: var(--critical); color: var(--critical); }
.alert.info { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-hover); }

.skeleton {
    height: 12px; border-radius: 4px;
    background: linear-gradient(90deg, var(--line) 25%, var(--surface-2) 50%, var(--line) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.3s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ------------------------------------------------------------ responsive */

@media (max-width: 860px) {
    .shell { flex-direction: column; }
    .sidebar {
        width: 100%; flex: none; height: auto; position: static;
        flex-direction: row; align-items: center; overflow-x: auto;
    }
    .sidebar-org, .sidebar-user { display: none; }
    .sidebar-brand { border: 0; white-space: nowrap; }
    .nav { display: flex; gap: 4px; padding: 8px; }
    .nav-group { display: none; }
    .nav a { white-space: nowrap; }
    .content { padding: 16px 14px 40px; }
    .topbar { padding: 12px 14px; }
}
