@import url('https://fonts.googleapis.com/css2?family=Geist:wght@300..700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ============================================================
   THEME TOKENS — Linear/Vercel-style cool neutrals
   ============================================================ */

:root,
:root[data-theme="dark"] {
    --bg:         #08090a;
    --surface:    #0f1011;
    --surface-2:  #16181b;
    --surface-3:  #1c1e22;
    --surface-h:  #131517;
    --rule:       #1f2225;
    --rule-2:     #2a2d31;
    --rule-3:     #3a3d42;
    --text:       #e6e7ea;
    --text-2:     #9a9ca1;
    --text-3:     #6a6d73;
    --muted:      #6a6d73;

    --brand:      #5b6cff;
    --brand-h:    #7280ff;
    --brand-soft: rgba(91, 108, 255, 0.12);

    --pos:        #3fb950;
    --pos-soft:   rgba(63, 185, 80, 0.12);
    --neg:        #f85149;
    --neg-soft:   rgba(248, 81, 73, 0.12);
    --warn:       #d29922;
    --warn-soft:  rgba(210, 153, 34, 0.13);
    --info:       #388bfd;
    --info-soft:  rgba(56, 139, 253, 0.13);
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg:         #fafaf9;
    --surface:    #ffffff;
    --surface-2:  #f5f5f4;
    --surface-3:  #ebebe9;
    --surface-h:  #f8f8f7;
    --rule:       #e7e7e4;
    --rule-2:     #d4d4d1;
    --rule-3:     #b8b8b4;
    --text:       #18191c;
    --text-2:     #5e6068;
    --text-3:     #8e9098;
    --muted:      #8e9098;

    --brand:      #4f5be8;
    --brand-h:    #3a47cc;
    --brand-soft: rgba(79, 91, 232, 0.10);

    --pos:        #22863a;
    --pos-soft:   rgba(34, 134, 58, 0.10);
    --neg:        #cf222e;
    --neg-soft:   rgba(207, 34, 46, 0.10);
    --warn:       #9a6700;
    --warn-soft:  rgba(154, 103, 0, 0.10);
    --info:       #0969da;
    --info-soft:  rgba(9, 105, 218, 0.10);
    color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Geist', system-ui, -apple-system, sans-serif;
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

.tnum, .kpi-value, .val, .num, .ax-y, .ax-x, .delta {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1;
}

.muted { color: var(--text-3); }

::selection { background: var(--brand-soft); color: var(--text); }

a { color: inherit; text-decoration: none; }

.compact .dashboard { padding-top: 1.25rem; }
.compact .widgets { gap: 0.55rem; }
.compact .widget { padding: 0.85rem 1rem; }
.compact .kpi-value { font-size: 1.5rem; }

/* ============================================================
   AUTH SCREENS
   ============================================================ */

.auth-shell {
    display: grid; grid-template-columns: 1.05fr 1fr; min-height: 100vh;
}
.deck {
    padding: 3rem 3.5rem;
    display: flex; flex-direction: column; justify-content: space-between;
    border-right: 1px solid var(--rule);
    background: var(--surface);
}
.brand {
    display: inline-flex; align-items: center; gap: 0.6rem;
    font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase;
    color: var(--text-2); font-weight: 500;
}
.brand-mark {
    width: 16px; height: 16px;
    background: var(--brand);
    position: relative; flex-shrink: 0;
    border-radius: 3px;
}
.brand-mark::after {
    content: ''; position: absolute;
    top: 50%; left: 50%;
    width: 5px; height: 5px;
    background: var(--bg);
    transform: translate(-50%, -50%);
    border-radius: 1px;
}
.brand b { color: var(--text); font-weight: 600; }
.brand .slash { color: var(--rule-2); margin: 0 0.3rem; }

/* Invisible top-of-deck placeholder so the auth-shell keeps its layout
   rhythm now that the login page doesn't show a brand in the corner. */
.brand-spacer { display: block; min-height: 22px; }

.deck-body { padding: 5rem 0 2rem; max-width: 32rem; }

.kicker {
    display: inline-flex; align-items: center; gap: 0.5rem;
    font-size: 11px; letter-spacing: 0.07em; text-transform: uppercase;
    color: var(--brand); margin-bottom: 1.25rem; font-weight: 500;
}
.kicker::before { content: ''; width: 14px; height: 1px; background: var(--brand); }

.display {
    font-family: 'Geist', sans-serif;
    font-size: clamp(2.5rem, 5vw, 4rem);
    font-weight: 500; line-height: 1; letter-spacing: -0.035em;
    color: var(--text);
}
.display em { font-style: normal; color: var(--brand); font-weight: 500; }

.deck-lede {
    font-size: 14px; color: var(--text-2); line-height: 1.6;
    max-width: 26rem; margin-top: 1.25rem;
}
.deck-lede b { color: var(--text); font-weight: 500; }

.deck-foot {
    display: flex; justify-content: space-between;
    font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase;
    color: var(--text-3);
}
.deck-foot b { color: var(--text-2); font-weight: 500; }

.form-panel {
    padding: 4rem 3.5rem;
    display: flex; flex-direction: column; justify-content: center;
}
.form-stack {
    display: flex; flex-direction: column; gap: 1.25rem;
    max-width: 22rem; width: 100%; margin: 0 auto;
}
.form-head { padding-bottom: 0.85rem; border-bottom: 1px solid var(--rule); }
.form-head h2 {
    font-family: 'Geist', sans-serif; font-weight: 600;
    font-size: 18px; letter-spacing: -0.015em;
}
.form-head .meta {
    font-size: 12px; color: var(--text-3); display: block; margin-top: 0.25rem;
}

.alert {
    border: 1px solid var(--neg);
    border-left-width: 3px;
    background: var(--neg-soft);
    padding: 0.6rem 0.85rem; color: var(--text); font-size: 13px;
    border-radius: 3px;
}
.alert.ok { border-color: var(--pos); background: var(--pos-soft); }

.field-label {
    display: block;
    font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
    color: var(--text-3); margin-bottom: 0.4rem; font-weight: 500;
}
.field-input-wrap {
    border: 1px solid var(--rule);
    background: var(--bg);
    border-radius: 4px;
    transition: border-color 0.15s ease;
}
.field-input-wrap:focus-within { border-color: var(--brand); }
.field input {
    width: 100%; background: transparent; border: 0;
    padding: 0.7rem 0.85rem;
    font-family: 'Geist', sans-serif; font-size: 14px;
    color: var(--text);
}
.field input:focus { outline: none; }
.field input::placeholder { color: var(--text-3); }

.submit {
    appearance: none;
    background: var(--brand); color: white;
    border: 0; padding: 0.7rem 1.2rem;
    font-family: 'Geist', sans-serif;
    font-size: 13px; font-weight: 500;
    cursor: pointer; border-radius: 4px;
    align-self: flex-start;
    transition: background 0.15s ease;
}
.submit:hover { background: var(--brand-h); }
.submit .arrow { margin-left: 0.3rem; transition: transform 0.15s ease; display: inline-block; }
.submit:hover .arrow { transform: translateX(2px); }

.aside { font-size: 13px; color: var(--text-2); }
.aside a { color: var(--brand); border-bottom: 1px solid transparent; transition: border-color 0.15s ease; }
.aside a:hover { border-bottom-color: var(--brand); }

/* ============================================================
   TOPBAR
   ============================================================ */

.app { min-height: 100vh; }

.topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    padding: 0.6rem 1.25rem;
    border-bottom: 1px solid var(--rule);
    background: var(--surface);
    position: sticky; top: 0; z-index: 50;
    gap: 1rem;
}
.topbar .brand-mark { width: 14px; height: 14px; }
.topbar .brand { font-size: 11px; }

.topnav {
    display: flex; gap: 0;
    justify-self: center;
}
.topnav a {
    padding: 0.45rem 0.85rem;
    font-size: 12px; letter-spacing: 0.02em;
    color: var(--text-2); font-weight: 500;
    border-bottom: 1px solid transparent;
    margin: 0 0.15rem;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.topnav a:hover { color: var(--text); }
.topnav a.active { color: var(--text); border-bottom-color: var(--brand); }

.toolbox {
    justify-self: end;
    display: flex; align-items: center; gap: 0.4rem;
}
.tool {
    appearance: none;
    display: inline-flex; align-items: center; gap: 0.4rem;
    border: 1px solid var(--rule); background: var(--surface);
    color: var(--text-2);
    padding: 0.4rem 0.7rem;
    font-family: 'Geist', sans-serif;
    font-size: 12px; font-weight: 500;
    cursor: pointer; border-radius: 4px;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.tool:hover { color: var(--text); border-color: var(--rule-2); background: var(--surface-2); }
.tool .btn-glyph { font-size: 13px; line-height: 1; opacity: 0.8; }
.tool.active { color: var(--text); background: var(--surface-2); border-color: var(--rule-2); }
.tool.active .btn-glyph { color: var(--brand); opacity: 1; }

.userpill {
    display: inline-flex; align-items: center; gap: 0.45rem;
    border: 1px solid var(--rule); background: var(--surface);
    padding: 0.3rem 0.65rem 0.3rem 0.3rem;
    color: var(--text-2);
    font-size: 12px; font-weight: 500; border-radius: 4px;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.userpill:hover { color: var(--text); border-color: var(--rule-2); background: var(--surface-2); }
.userpill.active { color: var(--text); background: var(--surface-2); border-color: var(--rule-2); }
.userpill .avatar {
    width: 22px; height: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand-soft); color: var(--brand);
    font-family: 'Geist', sans-serif; font-weight: 600;
    font-size: 12px; border-radius: 3px;
}
.userpill .who { color: var(--text); }

.signout {
    color: var(--text-2);
    font-size: 12px; font-weight: 500;
    padding: 0.4rem 0.7rem;
    border-radius: 4px;
    border: 1px solid transparent;
    transition: color 0.15s ease, background 0.15s ease;
}
.signout:hover { color: var(--text); background: var(--surface-2); }

/* ============================================================
   DASHBOARD / SECTION HEAD
   ============================================================ */

.dashboard {
    padding: 1.5rem 1.25rem 4rem;
    max-width: 1400px; margin: 0 auto;
}
.dash-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1.5rem; margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.dash-title {
    font-family: 'Geist', sans-serif; font-weight: 500;
    font-size: clamp(20px, 2.2vw, 26px); letter-spacing: -0.025em; line-height: 1;
}
.dash-title em { font-style: normal; color: var(--brand); font-weight: 500; }
.dash-sub {
    margin-top: 0.4rem; font-size: 12px; color: var(--text-3);
    display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.dash-sub b { color: var(--text-2); font-weight: 500; }

.range-picker {
    display: inline-flex;
    background: var(--surface); border: 1px solid var(--rule);
    border-radius: 5px; padding: 3px;
    gap: 1px;
}
.range-picker a {
    padding: 0.38rem 0.75rem;
    font-size: 11px; font-weight: 500;
    color: var(--text-2);
    border-radius: 3px;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: -0.01em;
    transition: color 0.15s ease, background 0.15s ease;
}
.range-picker a:hover { color: var(--text); background: var(--surface-2); }
.range-picker a.active {
    background: var(--surface-3); color: var(--text);
    box-shadow: 0 0 0 1px var(--rule-2) inset;
    position: relative;
}
.range-picker a.active::after {
    content: '';
    position: absolute; bottom: -1px; left: 50%;
    width: 12px; height: 2px;
    background: var(--brand);
    transform: translateX(-50%);
    border-radius: 2px;
}

.dash-tools {
    display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
}

.badge {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--rule); background: var(--surface);
    font-size: 11px; color: var(--text-2); border-radius: 4px; font-weight: 500;
}
.badge .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--warn);
}
.badge .dot.pulse { animation: pulse 2.4s ease-in-out infinite; }
.badge.ok .dot { background: var(--pos); }
.badge.info .dot { background: var(--info); }

/* ============================================================
   WIDGETS — denser, with sparklines + deltas
   ============================================================ */

.widgets {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 204px;
    grid-auto-flow: dense;
    gap: 0.7rem;
    align-items: stretch;
}
.widget {
    position: relative;
    display: flex; flex-direction: column;
    border: 1px solid var(--rule);
    background: var(--surface);
    padding: 1rem 1.1rem;
    color: inherit;
    border-radius: 7px;
    overflow: hidden;
    height: 100%;
    transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}
/* Subtle top edge glow on hover — adds atmosphere without noise. */
.widget::before {
    content: '';
    position: absolute; inset: 0 0 auto 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--rule-2), transparent);
    opacity: 0; transition: opacity 0.3s ease;
    pointer-events: none;
}
.widget:hover {
    border-color: var(--rule-2);
    background: var(--surface-h);
}
.widget:hover::before { opacity: 0.7; }
.widget[data-size="2"] { grid-column: span 2; }
.widget[data-size="3"] { grid-column: span 3; }
.widget[data-size="4"] { grid-column: span 4; }
.widget[data-rows="2"] { grid-row: span 2; }
.widget[data-rows="3"] { grid-row: span 3; }

.widget-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 0.45rem;
    min-height: 32px;
}
.widget-title {
    font-family: 'Geist', sans-serif; font-weight: 600;
    font-size: 13px; color: var(--text); letter-spacing: -0.005em;
}
.widget-sub {
    display: block;
    font-size: 11px; color: var(--text-3); margin-top: 0.2rem;
    letter-spacing: 0.01em;
}

.kpi-row {
    display: flex; align-items: baseline; gap: 0.55rem;
    margin: 0.2rem 0 0.1rem;
    flex-wrap: wrap;
    flex-shrink: 0;       /* don't get squashed by parent flex column */
    min-height: 30px;     /* always reserve space for the value */
}
.kpi-value {
    font-family: 'Geist', sans-serif;
    font-size: 30px; line-height: 1;
    color: var(--text); font-weight: 500; letter-spacing: -0.025em;
    white-space: nowrap;
    flex-shrink: 0;
}
.kpi-value.muted { color: var(--text-3); }
/* .kpi-unit is no longer rendered as a separate block; unit info lives in the
   widget-foot instead. Keep the class so legacy markup degrades cleanly. */
.kpi-unit { display: none; }

.delta {
    display: inline-flex; align-items: center; gap: 0.2rem;
    font-size: 11px; font-weight: 500;
    padding: 0.18rem 0.45rem;
    border-radius: 3px;
    line-height: 1.2;
}
.delta-up   { color: var(--pos); background: var(--pos-soft); }
.delta-down { color: var(--neg); background: var(--neg-soft); }
.delta-flat { color: var(--text-3); background: var(--surface-2); }

.kpi-viz {
    margin: 0.7rem -0.2rem 0;
    display: block;
    color: var(--brand);
    overflow: hidden;
    flex-shrink: 0;
}
.kpi-viz-line, .kpi-viz-bars { height: 52px; }
.kpi-viz-bullet { color: var(--text-3); }
.kpi-viz-stack  { color: var(--text-3); }

.spark { width: 100%; height: 52px; display: block; }
.spark.empty line { stroke: var(--rule-2); stroke-dasharray: 3 4; }

/* color sparklines by trend direction */
.widget.is-positive .kpi-viz-line,
.widget.is-positive .kpi-viz-bars { color: var(--pos); }
.widget.is-negative .kpi-viz-line,
.widget.is-negative .kpi-viz-bars { color: var(--neg); }

/* bullet chart */
.kpi-viz.kpi-viz-bullet .bullet { height: 22px; }
.bullet-meta {
    display: flex; justify-content: space-between;
    margin-top: 0.35rem; padding: 0 0.2rem;
    font-size: 11px; color: var(--text-3);
}
.bullet-meta b { color: var(--text); font-weight: 500; }

/* stacked bar */
.stack-bar { height: 10px; border-radius: 2px; overflow: hidden; }
.stack-legend {
    display: flex; flex-wrap: wrap; gap: 0.5rem 0.7rem;
    margin-top: 0.4rem; padding: 0 0.2rem;
    font-size: 10px; color: var(--text-3);
}
.leg { display: inline-flex; align-items: center; gap: 0.3rem; }
.leg-dot {
    width: 7px; height: 7px; border-radius: 1.5px;
    display: inline-block;
}

.widget-foot {
    display: flex; align-items: center;
    gap: 0.4rem;
    font-size: 11px; color: var(--text-3);
    margin-top: auto;
    padding-top: 0.65rem;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.widget-foot > span { overflow: hidden; text-overflow: ellipsis; }

/* ---- LINE CHART ---- */

.chart-frame {
    position: relative;
    margin-top: 0.5rem;
    flex: 1;
    min-height: 0;
}
.chart-frame.chart-tall { flex: 1; }
.line-chart {
    width: 100%;
    height: 100%;
    color: var(--brand);
    display: block;
}
.line-chart .grid line { stroke: var(--rule); stroke-dasharray: 2 4; }
.line-chart .grid .ax-y,
.line-chart .xlab .ax-x {
    fill: var(--text-2);
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    font-feature-settings: 'tnum' 1;
    letter-spacing: -0.005em;
}
.line-chart .line { stroke: currentColor; stroke-width: 1.75; fill: none; vector-effect: non-scaling-stroke; }
.line-chart .area { fill: currentColor; fill-opacity: 0.14; }

/* Chart frame stretches to fill widget body; SVG inside uses preserveAspectRatio="meet"
   so text stays readable. The .chart-frame itself can grow; the SVG centers within. */
.chart-frame .line-chart {
    width: 100%; height: 100%;
    max-height: 100%;
    display: block;
}

/* Hover-interactive data points */
.line-chart .dp .hit { fill: transparent; }
.line-chart .dp .guide { stroke: var(--rule-2); stroke-width: 1; opacity: 0; pointer-events: none; }
.line-chart .dp .dot {
    fill: currentColor; stroke: var(--bg); stroke-width: 2;
    opacity: 0; pointer-events: none;
    transition: opacity 0.1s;
}
.line-chart .dp:hover .guide,
.line-chart .dp:hover .dot { opacity: 1; }
.line-chart:hover { cursor: crosshair; }
.line-chart .dp.clickable .hit { cursor: pointer; }
.line-chart .dp.clickable:hover .dot {
    fill: var(--brand);
    stroke: var(--bg);
}

/* Tooltip injected by app.js */
.chart-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--surface-2);
    border: 1px solid var(--rule-2);
    border-top: 2px solid var(--brand);
    color: var(--text);
    padding: 0.4rem 0.65rem;
    border-radius: 5px;
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    font-feature-settings: 'tnum' 1;
    white-space: nowrap;
    box-shadow: 0 6px 16px rgba(0,0,0,0.5);
    z-index: 10;
    opacity: 0;
    transform: translate(-50%, calc(-100% - 8px));
    transition: opacity 0.12s ease, transform 0.18s cubic-bezier(0.2, 0.65, 0.3, 1);
    text-align: center;
    min-width: 78px;
}
.chart-tooltip.show {
    opacity: 1;
    transform: translate(-50%, calc(-100% - 12px));
}
.chart-tooltip .ct-date {
    color: var(--text-3);
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
}
.chart-tooltip .ct-val  {
    color: var(--text);
    font-weight: 600;
    font-size: 12.5px;
    letter-spacing: -0.005em;
}

/* Active-touch state: when a finger is held over a data point, show the dot
   and guide line the same way desktop hover does. Reuses the same .dot/.guide
   elements that mouseover already styles. */
.line-chart .dp.active-touch .guide,
.line-chart .dp.active-touch .dot { opacity: 1; }

.chart-frame.empty {
    height: 160px;
    border: 1px dashed var(--rule);
    display: flex; align-items: center; justify-content: center;
}
.chart-empty span { color: var(--text-3); font-size: 12px; }

/* ---- LIST (row-list) ---- */

.row-list {
    list-style: none;
    margin-top: 0.4rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.row-list .row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center; gap: 0.7rem;
    padding: 0.42rem 0;
    border-top: 1px solid var(--rule);
    font-size: 12px;
    line-height: 1.3;
    min-width: 0;
}
.row-list .row:first-child { border-top: 0; padding-top: 0.15rem; }
.row-list.compact .row { padding: 0.34rem 0; }

.row-list .rank {
    color: var(--text-3); font-size: 10px; font-weight: 600;
    width: 18px;
    font-family: 'JetBrains Mono', monospace;
}
.row-list .name {
    color: var(--text); font-weight: 500;
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-list .name small {
    display: block; color: var(--text-3);
    font-size: 10px; margin-top: 0.1rem; font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    overflow: hidden; text-overflow: ellipsis;
}
.row-list .val { color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap; }
.row-list .row.empty {
    grid-template-columns: 1fr;
    text-align: center;
    color: var(--text-3); font-size: 12px;
    padding: 1rem 0;
}

.avatar-sm {
    width: 24px; height: 24px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand-soft); color: var(--brand);
    font-size: 10px; font-weight: 600; border-radius: 3px;
}

.status-pill {
    display: inline-flex; align-items: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px; font-weight: 500;
    padding: 0.18rem 0.45rem;
    border-radius: 3px;
    background: var(--surface-2);
    color: var(--text-2);
    border: 1px solid var(--rule);
}
.status-pill.bad  { color: var(--neg); background: var(--neg-soft); border-color: transparent; }
.status-pill.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.status-pill.ok   { color: var(--pos); background: var(--pos-soft); border-color: transparent; }

.stock-list .row { grid-template-columns: auto 1fr 100px; }

.mini-bar {
    display: block; width: 100%;
    height: 4px; background: var(--surface-2);
    border-radius: 2px; overflow: hidden;
}
.mini-bar-fill {
    display: block; height: 100%; background: var(--text-3);
    transition: width 0.4s ease;
}
.mini-bar-fill.bad  { background: var(--neg); }
.mini-bar-fill.warn { background: var(--warn); }
.mini-bar-fill.ok   { background: var(--pos); }

/* ---- GAUGE ---- */

.gauge-wrap { display: flex; align-items: center; gap: 1rem; margin-top: 0.5rem; }
.gauge { width: 88px; height: 88px; flex-shrink: 0; }
.gauge .track { stroke: var(--rule); }
.gauge .fill { stroke: var(--brand); stroke-linecap: round; transition: stroke-dasharray 0.45s ease; }
.gauge text { fill: var(--text); font-family: 'Geist', sans-serif; font-weight: 600; font-size: 16px; }
.gauge-info { display: flex; flex-direction: column; gap: 0.25rem; }
.gauge-info .lbl { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; }
.gauge-info .val { font-family: 'Geist', sans-serif; font-size: 16px; font-weight: 500; color: var(--text); }
.gauge-info .muted { font-size: 11px; }

/* ---- BARS ---- */

.bar-list {
    list-style: none; display: flex; flex-direction: column;
    gap: 0.32rem; margin-top: 0.35rem;
    flex: 1; min-height: 0; overflow: hidden;
}
.bar-row {
    display: grid; grid-template-columns: minmax(48px, 70px) 1fr 56px;
    align-items: center; gap: 0.6rem;
    font-size: 12px;
    line-height: 1.25;
    min-width: 0;
}
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-val { white-space: nowrap; }
.bar-row.empty { grid-template-columns: 1fr; text-align: center; color: var(--text-3); }
.bar-name { color: var(--text-2); }
.bar-track {
    position: relative; height: 5px; background: var(--surface-2);
    border-radius: 3px; overflow: hidden;
}
.bar-fill {
    position: absolute; top: 0; left: 0; bottom: 0;
    background: var(--brand);
    border-radius: 3px;
    transition: width 0.45s ease;
}
.bar-val { text-align: right; color: var(--text-2); font-size: 11px; }

/* ---- STATUS ---- */

.status-list { display: flex; flex-direction: column; margin-top: 0.4rem; }
.status-row {
    display: grid; grid-template-columns: 1fr auto;
    align-items: center; padding: 0.55rem 0;
    border-top: 1px solid var(--rule); font-size: 12px;
}
.status-row:first-child { border-top: 0; }
.status-name { color: var(--text); font-weight: 500; }
.status-name small {
    display: block; color: var(--text-3);
    font-size: 10px; margin-top: 0.1rem; font-weight: 400;
}
.status-state {
    display: inline-flex; align-items: center; gap: 0.4rem;
    font-size: 11px; font-weight: 500;
    padding: 0.18rem 0.45rem; border-radius: 3px;
}
.status-state .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
.status-state.ok   { color: var(--pos); background: var(--pos-soft); }
.status-state.ok   .dot { background: var(--pos); }
.status-state.warn { color: var(--warn); background: var(--warn-soft); }
.status-state.warn .dot { background: var(--warn); animation: pulse 2.4s ease-in-out infinite; }
.status-state.bad  { color: var(--neg); background: var(--neg-soft); }
.status-state.bad  .dot { background: var(--neg); }

/* ---- ACTIVITY ---- */

.activity-list {
    list-style: none; margin-top: 0.4rem;
    display: flex; flex-direction: column;
    flex: 1; min-height: 0; overflow: hidden;
}
.activity-item { border-top: 1px solid var(--rule); }
.activity-item:first-child { border-top: 0; }
.evt-link {
    display: grid; grid-template-columns: 76px minmax(0, 1fr) auto;
    align-items: center; gap: 0.7rem;
    padding: 0.5rem 0.4rem;
    margin: 0 -0.4rem;
    color: inherit;
    border-radius: 4px;
    text-decoration: none;
    font-size: 12px;
    transition: background 0.12s ease, color 0.12s ease;
    position: relative;
    min-width: 0;
}
.evt-msg { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.evt-link:hover {
    background: var(--surface-2);
}
.evt-link:hover .evt-msg { color: var(--brand); }
.evt-link::after {
    content: '→';
    position: absolute;
    right: 0.4rem;
    top: 50%;
    transform: translateY(-50%) translateX(8px);
    color: var(--text-3);
    opacity: 0;
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.evt-link:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}
.evt-link:hover .evt-time { opacity: 0; }

.evt-type {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px; font-weight: 500;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    text-align: center;
    background: var(--surface-2);
    color: var(--text-2);
}
.evt-type.evt-order    { color: var(--brand); background: var(--brand-soft); }
.evt-type.evt-shipment { color: var(--info);  background: var(--info-soft); }
.evt-type.evt-stock    { color: var(--warn);  background: var(--warn-soft); }
.evt-type.evt-delivery { color: var(--pos);   background: var(--pos-soft); }
.evt-type.evt-return   { color: var(--text-2); background: var(--surface-2); }
.evt-msg { color: var(--text); transition: color 0.12s ease; }
.evt-time { font-size: 11px; color: var(--text-3); white-space: nowrap; transition: opacity 0.12s ease; }

.widget-more {
    font-size: 11px; color: var(--text-3); font-weight: 500;
    text-decoration: none;
    transition: color 0.12s ease;
}
.widget-more:hover { color: var(--brand); }

a.kpi-value.stat-link {
    color: var(--text);
    text-decoration: none;
    font-size: 17px;
    line-height: 1.2;
    transition: color 0.15s ease;
    font-weight: 500;
    word-break: break-word;
}
a.kpi-value.stat-link .arrow {
    color: var(--text-3);
    margin-left: 0.25rem;
    transition: color 0.15s ease, transform 0.15s ease;
    display: inline-block;
}
a.kpi-value.stat-link:hover { color: var(--brand); }
a.kpi-value.stat-link:hover .arrow { color: var(--brand); transform: translateX(2px); }

/* ============================================================
   EDIT MODE
   ============================================================ */

.widgets.edit-mode .widget {
    cursor: grab;
    border-style: dashed;
    border-color: var(--brand);
}
.widgets.edit-mode .widget::before {
    content: '⤢';
    position: absolute;
    top: 0.55rem; right: 0.7rem;
    color: var(--brand);
    font-size: 12px;
    background: var(--surface-2);
    width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--brand);
    border-radius: 3px;
    pointer-events: none;
    z-index: 2;
}
.widgets.edit-mode .widget:hover { background: var(--surface-h); }
.widget.dragging { cursor: grabbing; opacity: 0.5; transform: scale(0.985); }

/* ============================================================
   DETAIL PAGE — uses same widgets grid as the overview
   ============================================================ */

.detail {
    padding: 1.5rem 1.25rem 4rem;
    max-width: 1400px; margin: 0 auto;
}
.detail .widgets { margin-top: 0.5rem; }

/* hero variant of a widget — big numbers, more padding */
.widget.widget-hero {
    padding: 1.5rem 1.7rem;
}
.widget.widget-hero .widget-title { font-size: 14px; }
.widget.widget-hero .widget-sub  { font-size: 12px; }
.widget.widget-hero .kpi-row {
    margin-top: 0.95rem; gap: 0.95rem;
    flex-wrap: wrap;
}
.widget.widget-hero .kpi-value {
    font-size: clamp(38px, 4.6vw, 56px);
    line-height: 1;
    letter-spacing: -0.035em;
    font-weight: 500;
}
.widget.widget-hero .delta {
    font-size: 13px; padding: 0.32rem 0.6rem;
}
.widget.widget-hero .kpi-viz { margin-top: 1.1rem; }
.widget.widget-hero .kpi-viz-line,
.widget.widget-hero .kpi-viz-bars { height: 82px; }
.widget.widget-hero .widget-foot {
    margin-top: 1rem; font-size: 12px;
}

/* big chart widget — fill 2x2 */
.widget.widget-chart {
    overflow: visible;
}
.widget.widget-chart .chart-frame { flex: 1; min-height: 0; margin-top: 0.4rem; }

/* table inside a widget — flush, no padding on the widget itself */
.widget.widget-table {
    padding: 0;
}
.widget.widget-table > .widget-head {
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 0;
}
.widget.widget-table .table-wrap {
    flex: 1;
    overflow: auto;
    min-height: 0;
}
.widget.widget-table table { width: 100%; }
.widget.widget-table .widget-foot {
    padding: 0.55rem 1.1rem;
    border-top: 1px solid var(--rule);
    margin: 0;
}

/* clickable table rows that link out */
.data-table tr.linked { cursor: pointer; }
.data-table tr.linked a { color: inherit; text-decoration: none; }
.data-table tr.linked:hover td { background: var(--surface-2); }
.data-table tr.linked:hover td:first-child { color: var(--brand); }

/* bigger avatar for hero on /person.php */
.avatar-xl {
    width: 56px; height: 56px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand-soft); color: var(--brand);
    font-family: 'Geist', sans-serif; font-weight: 600;
    font-size: 22px; border-radius: 6px;
    border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
}

.person-head {
    display: flex; gap: 1rem; align-items: center;
}
.person-head h2 {
    font-family: 'Geist', sans-serif; font-weight: 500;
    font-size: 22px; letter-spacing: -0.015em;
}
.person-head .sub { font-size: 12px; color: var(--text-3); margin-top: 0.15rem; }

/* day-of-week / hour bars (in widget) */
.dow-bars, .hr-bars {
    display: grid; gap: 4px;
    align-items: end;
    flex: 1;
    padding-top: 0.5rem;
}
.dow-bars { grid-template-columns: repeat(7, 1fr); }
.hr-bars  { grid-template-columns: repeat(12, 1fr); }
.dow-bars .b, .hr-bars .b {
    display: flex; flex-direction: column; align-items: stretch; gap: 4px;
    min-height: 0;
}
.dow-bars .b .bar-col, .hr-bars .b .bar-col {
    background: var(--brand);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
}
.dow-bars .b .lbl, .hr-bars .b .lbl {
    font-size: 9px; color: var(--text-3); text-align: center;
    font-family: 'JetBrains Mono', monospace;
}

.status-pill.confirmed { color: var(--info); background: var(--info-soft); border-color: transparent; }
.status-pill.shipped   { color: var(--brand); background: var(--brand-soft); border-color: transparent; }
.status-pill.delivered { color: var(--pos); background: var(--pos-soft); border-color: transparent; }
.breadcrumb {
    font-size: 11px; color: var(--text-3); margin-bottom: 1rem; font-weight: 500;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.breadcrumb a { color: var(--text-2); }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { margin: 0 0.5rem; color: var(--rule-2); }

.detail-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 1.5rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.detail-head h1 {
    font-family: 'Geist', sans-serif; font-weight: 500;
    font-size: clamp(24px, 3vw, 32px); letter-spacing: -0.025em; line-height: 1.1;
}
.detail-head p {
    margin-top: 0.45rem;
    font-size: 13px; color: var(--text-2); max-width: 44rem; line-height: 1.55;
}

.controls {
    display: flex; flex-wrap: wrap; gap: 0.75rem;
    align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.filter-bar { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.filter {
    appearance: none;
    display: inline-flex; align-items: center; gap: 0.4rem;
    border: 1px solid var(--rule); background: var(--surface);
    color: var(--text-2);
    padding: 0.4rem 0.7rem;
    font-family: 'Geist', sans-serif;
    font-size: 12px; font-weight: 500;
    cursor: pointer; border-radius: 4px;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.filter:hover { color: var(--text); border-color: var(--rule-2); }
.filter:disabled { opacity: 0.5; cursor: not-allowed; }
.filter .car { color: var(--text-3); }

.hero-strip {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 0.65rem;
    margin-bottom: 0.65rem;
}
.hero-num {
    border: 1px solid var(--rule); background: var(--surface);
    padding: 1.5rem 1.5rem;
    display: flex; flex-direction: column;
    gap: 0.4rem;
    border-radius: 6px;
}
.hero-num .lbl {
    font-size: 11px; color: var(--text-3); font-weight: 500;
    text-transform: uppercase; letter-spacing: 0.05em;
}
.hero-num .big {
    font-family: 'Geist', sans-serif;
    font-size: clamp(40px, 5vw, 56px);
    font-weight: 500; line-height: 1;
    letter-spacing: -0.035em;
    color: var(--text);
    display: flex; align-items: baseline; gap: 0.8rem;
}
.hero-num .big small {
    font-size: 13px; color: var(--text-3); font-weight: 500;
    text-transform: lowercase;
}
.hero-num .below {
    font-size: 12px; color: var(--text-2);
    display: flex; align-items: center; gap: 0.5rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 0.65rem;
    margin-bottom: 0.65rem;
}

.detail-panel {
    border: 1px solid var(--rule); background: var(--surface);
    border-radius: 6px;
}
.detail-panel header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid var(--rule);
}
.detail-panel header h2 {
    font-family: 'Geist', sans-serif; font-weight: 600;
    font-size: 13px;
}
.detail-panel header .meta {
    font-size: 11px; color: var(--text-3);
}
.detail-panel .body { padding: 1.1rem; }
.detail-panel .big-chart .line-chart { aspect-ratio: 800 / 280; }

/* Stats table inside detail panels */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
    border-radius: 4px;
    overflow: hidden;
}
.stat-cell {
    background: var(--surface);
    padding: 0.85rem 1rem;
}
.stat-cell .lbl {
    font-size: 10px; color: var(--text-3); font-weight: 500;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.stat-cell .val {
    font-family: 'Geist', sans-serif;
    font-size: 18px; font-weight: 500;
    color: var(--text); margin-top: 0.3rem;
}

/* Data table for detail pages */
.data-table {
    width: 100%; border-collapse: collapse;
    font-size: 12px;
}
.data-table th {
    text-align: left;
    font-size: 10px; font-weight: 500;
    color: var(--text-3);
    text-transform: uppercase; letter-spacing: 0.05em;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--rule);
    background: var(--surface);
}
.data-table th.num { text-align: right; }
.data-table td {
    padding: 0.55rem 1rem;
    border-bottom: 1px solid var(--rule);
    color: var(--text);
    font-weight: 500;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: var(--surface-2); }
.data-table td.num { text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }
.data-table td.id { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-2); }
.data-table td .spark { width: 80px; height: 18px; }
.data-table td.delta { text-align: right; }

/* Zone bars (warehouse detail) */
.zone-list { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.5rem 0; }
.zone-row {
    display: grid; grid-template-columns: 1fr 60px;
    align-items: center; gap: 0.7rem; font-size: 12px;
}
.zone-name { color: var(--text); font-weight: 500; }
.zone-name small { display: block; color: var(--text-3); font-size: 10px; margin-top: 0.1rem; }
.zone-meter { position: relative; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; grid-column: 1 / -1; }
.zone-meter-fill { position: absolute; inset: 0; background: var(--brand); border-radius: 3px; }
.zone-meter-fill.warn { background: var(--warn); }
.zone-meter-fill.bad { background: var(--neg); }
.zone-pct { text-align: right; color: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }

/* ============================================================
   SETTINGS / PROFILE
   ============================================================ */

.page {
    max-width: 720px; margin: 0 auto;
    padding: 1.75rem 1.25rem 5rem;
}
.page-head { margin-bottom: 1.5rem; }
.page-head h1 {
    font-family: 'Geist', sans-serif; font-weight: 500;
    font-size: clamp(22px, 2.5vw, 28px); letter-spacing: -0.02em; line-height: 1;
}
.page-head h1 em { font-style: normal; color: var(--brand); font-weight: 500; }
.page-head p { margin-top: 0.4rem; font-size: 13px; color: var(--text-2); }

.card {
    border: 1px solid var(--rule); background: var(--surface);
    margin-bottom: 0.75rem; border-radius: 6px;
}
.card-head {
    padding: 0.85rem 1.1rem; border-bottom: 1px solid var(--rule);
    display: flex; justify-content: space-between; align-items: center;
}
.card-head h2 { font-family: 'Geist', sans-serif; font-weight: 600; font-size: 14px; }
.card-head .meta { font-size: 11px; color: var(--text-3); }
.card-body { padding: 1.1rem; }
.card-body p { font-size: 13px; color: var(--text-2); line-height: 1.6; }

.setting-row {
    display: grid; grid-template-columns: 1fr auto;
    align-items: center; gap: 1rem;
    padding: 0.85rem 0; border-top: 1px solid var(--rule);
}
.setting-row:first-child { border-top: 0; }
.setting-row .label { font-size: 13px; color: var(--text); font-weight: 500; }
.setting-row .label small { display: block; color: var(--text-3); font-size: 12px; margin-top: 0.2rem; font-weight: 400; }

.toggle-group {
    display: inline-flex; gap: 0;
    background: var(--surface-2); border: 1px solid var(--rule);
    border-radius: 4px; padding: 2px;
}
.toggle-group button {
    appearance: none; background: transparent; border: 0; color: var(--text-2);
    padding: 0.35rem 0.85rem;
    font-family: 'Geist', sans-serif; font-size: 12px; font-weight: 500;
    border-radius: 3px; cursor: pointer;
}
.toggle-group button:hover { color: var(--text); }
.toggle-group button.active { background: var(--surface); color: var(--text); }

.switch { position: relative; width: 34px; height: 20px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; inset: 0;
    background: var(--surface-2); border: 1px solid var(--rule);
    cursor: pointer; transition: background 0.18s ease;
    border-radius: 999px;
}
.switch .slider::before {
    content: ''; position: absolute;
    top: 50%; left: 2px;
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--text-3);
    transform: translateY(-50%);
    transition: transform 0.18s ease, background 0.18s ease;
}
.switch input:checked + .slider { background: var(--brand); border-color: var(--brand); }
.switch input:checked + .slider::before { transform: translate(14px, -50%); background: white; }

.danger {
    appearance: none; background: transparent; color: var(--neg);
    border: 1px solid color-mix(in srgb, var(--neg) 35%, var(--rule));
    padding: 0.45rem 0.85rem; border-radius: 4px;
    font-family: 'Geist', sans-serif; font-size: 12px; font-weight: 500;
    cursor: pointer;
}
.danger:hover { background: var(--neg); color: white; border-color: var(--neg); }

.kv { display: grid; grid-template-columns: 9rem 1fr; gap: 0.55rem 1rem; font-size: 13px; }
.kv dt { color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; align-self: center; font-weight: 500; }
.kv dd { color: var(--text); font-weight: 500; }
.kv dd b { color: var(--brand); font-weight: 600; }

.form-block { display: flex; flex-direction: column; gap: 1rem; }

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.001s !important; transition: none !important; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* ============================================================
   HAMBURGER + OFF-CANVAS DRAWER (mobile only)
   ============================================================ */
.hamburger {
    display: none;
    appearance: none; border: 0; background: transparent;
    cursor: pointer; padding: 0.55rem;
    width: 40px; height: 40px;
    flex-direction: column; justify-content: center; align-items: center;
    gap: 5px;
    border-radius: 6px;
}
.hamburger .bar {
    width: 18px; height: 1.5px; background: var(--text);
    border-radius: 2px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}
.hamburger:active { background: var(--surface-2); }
.hamburger.active .bar:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
.hamburger.active .bar:nth-child(2) { opacity: 0; transform: translateX(-8px); }
.hamburger.active .bar:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

.drawer {
    display: none;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(86vw, 340px);
    background: var(--surface);
    border-left: 1px solid var(--rule);
    z-index: 60;
    transform: translateX(100%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    /* Critical: while off-screen, don't capture clicks */
    pointer-events: none;
    visibility: hidden;
}
.drawer.open {
    transform: translateX(0);
    pointer-events: auto;
    visibility: visible;
}

.drawer-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 55;
    opacity: 0;
    transition: opacity 0.32s ease;
    /* Critical: while invisible, don't block clicks on the page underneath */
    pointer-events: none;
    visibility: hidden;
}
.drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

body.drawer-open { overflow: hidden; }

.drawer-head {
    padding: 1.4rem 1.5rem 1rem;
    border-bottom: 1px solid var(--rule);
}
.drawer-user {
    display: flex; align-items: center; gap: 0.85rem;
    color: inherit; text-decoration: none;
}
.drawer-user .avatar-xl {
    width: 48px; height: 48px; font-size: 18px;
}
.drawer-user-text { display: flex; flex-direction: column; gap: 0.15rem; }
.drawer-user-text b { font-family: 'Geist', sans-serif; font-weight: 600; font-size: 15px; letter-spacing: -0.015em; }
.drawer-user-text small { color: var(--text-3); font-size: 11px; letter-spacing: 0.02em; }

.drawer-nav {
    display: flex; flex-direction: column;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--rule);
}
.drawer-nav a {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.95rem 1.5rem;
    color: var(--text-2);
    font-family: 'Geist', sans-serif;
    font-size: 15px; font-weight: 500;
    letter-spacing: -0.005em;
    border-left: 2px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.drawer-nav a:active { background: var(--surface-2); }
.drawer-nav a.active {
    color: var(--text);
    border-left-color: var(--brand);
    background: var(--brand-soft);
}
.drawer-nav a .chev { color: var(--text-3); font-size: 18px; font-weight: 300; }
.drawer-nav a.active .chev { color: var(--brand); }

.drawer-tools {
    display: flex; flex-direction: column;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--rule);
}
.drawer-tool {
    display: flex; align-items: center; gap: 0.7rem;
    padding: 0.75rem 1.5rem;
    appearance: none; border: 0; background: transparent;
    color: var(--text-2);
    font-family: 'Geist', sans-serif;
    font-size: 13.5px; font-weight: 500;
    text-align: left;
    cursor: pointer;
}
.drawer-tool .btn-glyph {
    width: 22px; text-align: center;
    color: var(--text-3); font-size: 14px;
}
.drawer-tool:active { background: var(--surface-2); }

.drawer-signout {
    display: block;
    padding: 1rem 1.5rem 1.4rem;
    color: var(--neg);
    font-family: 'Geist', sans-serif; font-size: 13.5px; font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.drawer-signout:active { background: var(--neg-soft); }

/* ============================================================
   RESPONSIVE — designed, not just shrunk
   - 1100px: 3-col grid, large widgets compact
   - 860px:  off-canvas drawer; 2-col grid; cleaner topbar
   - 560px:  phone — single column, hero-feel cards, chip range
   ============================================================ */

@media (max-width: 1100px) {
    .widgets { grid-template-columns: repeat(3, 1fr); }
    .widget[data-size="4"] { grid-column: span 3; }
    .detail-grid { grid-template-columns: 1fr; }
    .hero-strip  { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .auth-shell { grid-template-columns: 1fr; }
    .deck       { padding: 2rem 1.25rem; border-right: 0; border-bottom: 1px solid var(--rule); }
    .deck-body  { padding: 2rem 0 1rem; }
    .form-panel { padding: 2.5rem 1.25rem; }

    /* Minimal topbar — just brand + hamburger. Everything else lives in drawer. */
    .topbar {
        display: flex; align-items: center; justify-content: space-between;
        padding: 0.6rem 1rem;
        padding-top: calc(0.6rem + env(safe-area-inset-top, 0));
        gap: 0.5rem;
        position: sticky; top: 0; z-index: 50;
        background: color-mix(in srgb, var(--surface) 92%, transparent);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--rule);
    }
    .topnav, .toolbox { display: none; }
    .hamburger { display: inline-flex; }
    .drawer, .drawer-backdrop { display: block; }
    .topbar .brand-mark { width: 14px; height: 14px; }
    .topbar .brand { font-size: 12px; letter-spacing: 0.02em; }

    /* Main content padding + 2-col grid */
    .dashboard, .detail {
        padding: 1.25rem 0.9rem 3rem;
        padding-bottom: calc(3rem + env(safe-area-inset-bottom, 0));
    }
    .widgets {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: 196px;
        gap: 0.6rem;
    }
    .widget[data-size="2"],
    .widget[data-size="3"],
    .widget[data-size="4"] { grid-column: span 2; }

    /* Header stacks; range picker becomes a horizontal scrolling chip strip. */
    .dash-head { flex-direction: column; align-items: flex-start; gap: 1rem; }
    .dash-title { font-size: clamp(22px, 5.5vw, 30px); }
    .dash-tools { width: 100%; }
    .range-picker {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        scroll-snap-type: x mandatory;
        padding: 3px; gap: 2px;
        max-width: 100%;
    }
    .range-picker::-webkit-scrollbar { display: none; }
    .range-picker a {
        flex-shrink: 0;
        scroll-snap-align: start;
        padding: 0.5rem 0.95rem;
        font-size: 12px;
        min-height: 36px;
        display: inline-flex; align-items: center;
    }

    /* Hero cards: bigger numbers, more breathing space, less chrome. */
    .widget.widget-hero { padding: 1.4rem 1.4rem; }
    .widget.widget-hero .kpi-value {
        font-size: clamp(34px, 10vw, 52px);
        letter-spacing: -0.04em;
    }
    .widget.widget-hero .kpi-viz-line,
    .widget.widget-hero .kpi-viz-bars { height: 64px; }

    /* Tables → horizontal scroll, cells don't wrap */
    .widget.widget-table .table-wrap,
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    .data-table th, .data-table td { white-space: nowrap; }

    /* Breadcrumbs can wrap on small screens */
    .breadcrumb { white-space: normal; line-height: 1.6; }

    /* Charts on mobile: axis labels need to be larger because the whole SVG
       is scaled down to fit the narrow phone width. Browsers render SVG text
       font-size in user units, so when the SVG scales 0.4x the text scales
       too — bumping these sizes compensates so labels stay readable. */
    .line-chart .ax-x,
    .line-chart .grid .ax-y,
    .line-chart .xlab .ax-x { font-size: 20px; font-weight: 500; }
    .line-chart .line { stroke-width: 2.5; }
    .line-chart .grid line { stroke-width: 1; opacity: 0.6; }

    /* Mobile chart is a touch surface — let horizontal drags scrub the chart,
       vertical drags scroll the page. */
    .line-chart { touch-action: pan-y; }

    /* On a finger, the dot needs to be findable — make it always at least faintly
       visible, and prominent when active-touch is on. Guide line stays clean. */
    .line-chart .dp .dot { opacity: 0.35; }
    .line-chart .dp.active-touch .dot { opacity: 1; r: 6; }
    .line-chart .dp.active-touch .guide { opacity: 1; stroke: var(--brand); }

    /* Tooltip on mobile: larger, more readable, with refined typography */
    .chart-tooltip {
        font-size: 13px;
        padding: 0.55rem 0.8rem;
        border-radius: 7px;
        min-width: 96px;
        box-shadow: 0 8px 22px rgba(0,0,0,0.55);
    }
    .chart-tooltip .ct-date { font-size: 10.5px; margin-bottom: 3px; }
    .chart-tooltip .ct-val  {
        font-family: 'Geist', sans-serif;
        font-weight: 600;
        font-size: 16px;
        letter-spacing: -0.015em;
    }
}


/* Phone — refined single-column, intentional hero feel */
@media (max-width: 560px) {
    .dashboard, .detail { padding: 0.95rem 0.75rem 2.6rem; }
    body { font-size: 14px; }

    /* Smallest phones — SVG charts get scaled down even more, so push axis
       text larger still + thicker data line for legibility. */
    .line-chart .ax-x,
    .line-chart .grid .ax-y,
    .line-chart .xlab .ax-x { font-size: 26px; }
    .line-chart .line { stroke-width: 3; }
    .line-chart .dp .dot { r: 5; opacity: 0.4; }
    .line-chart .dp.active-touch .dot { r: 8; opacity: 1; }
    .line-chart .area { fill-opacity: 0.2; }

    /* Tooltip even more presence on tiny screens */
    .chart-tooltip {
        font-size: 13.5px;
        padding: 0.6rem 0.9rem;
        min-width: 108px;
    }
    .chart-tooltip .ct-val { font-size: 17px; }

    /* Single column; 1×1 cards become tall enough for big numbers + sparkline + meta */
    .widgets {
        grid-template-columns: 1fr;
        grid-auto-rows: 168px;
        gap: 0.55rem;
    }
    .widget,
    .widget[data-size="2"],
    .widget[data-size="3"],
    .widget[data-size="4"] { grid-column: span 1; }
    .widget[data-rows="2"] { grid-row: span 2; }
    .widget[data-rows="3"] { grid-row: span 3; }

    /* On a single-column phone screen, KPI cards have more horizontal room than
       desktop equivalents. Give the number some presence. */
    .widget { padding: 1rem 1.1rem; border-radius: 8px; }
    .widget-title { font-size: 13px; letter-spacing: -0.005em; }
    .widget-sub   { font-size: 11px; margin-top: 0.25rem; }
    .kpi-row { margin: 0.55rem 0 0.15rem; gap: 0.65rem; }
    .kpi-value { font-size: 32px; letter-spacing: -0.03em; }
    .kpi-viz { margin-top: 0.85rem; }
    .kpi-viz-line, .kpi-viz-bars { height: 56px; }
    .spark { height: 56px; }
    .widget-foot { font-size: 11.5px; padding-top: 0.75rem; }
    .delta { font-size: 11.5px; padding: 0.22rem 0.5rem; }

    /* Hero on phone — full-bleed number */
    .widget.widget-hero { padding: 1.5rem 1.5rem 1.3rem; }
    .widget.widget-hero .kpi-value {
        font-size: clamp(40px, 12vw, 60px);
    }
    .widget.widget-hero .kpi-viz-line,
    .widget.widget-hero .kpi-viz-bars { height: 72px; }

    /* Lists: bigger touch targets, more vertical space */
    .row-list .row { padding: 0.62rem 0; font-size: 13px; min-height: 44px; }
    .row-list .name { font-size: 13px; }
    .row-list .name small { font-size: 11px; }
    .row-list .val { font-size: 13px; }

    /* Activity feed — phones love this layout */
    .evt-link {
        grid-template-columns: 68px minmax(0, 1fr) auto;
        padding: 0.7rem 0.5rem;
        min-height: 48px;
        font-size: 12.5px;
    }
    .evt-type { font-size: 9.5px; padding: 0.18rem 0.42rem; }

    /* Stat cards stack 1-up on phone */
    .detail .widget[data-size="1"] { grid-column: span 1; }

    /* Bar widgets: bigger bars, better readability */
    .bar-list { gap: 0.45rem; }
    .bar-row { grid-template-columns: minmax(56px, 80px) 1fr 64px; font-size: 12.5px; }
    .bar-track { height: 6px; }

    /* Chart frames feel more like an artifact, less like a panel */
    .chart-frame { margin-top: 0.65rem; }

    /* Range chip strip — friendlier on phone */
    .range-picker { padding: 4px; }
    .range-picker a {
        padding: 0.55rem 1.05rem;
        font-size: 12.5px;
        min-height: 38px;
        font-family: 'JetBrains Mono', monospace;
    }
    .range-picker a.active::after {
        width: 18px; height: 2px; bottom: -2px;
    }

    /* Breadcrumb tighter */
    .breadcrumb { font-size: 10.5px; margin-bottom: 0.8rem; }

    /* Topbar brand simpler */
    .topbar .brand .slash { display: none; }
    .topbar .brand span:not(.brand-mark) { font-size: 11.5px; }
}

/* Entrance animation was removed — on some browsers (esp. iOS Safari) the
   animation could stall while paused with `fill-mode: both`, leaving the
   widget stuck at opacity 0 and hiding the kpi-value entirely. Static layout
   reliably ships visible content; refinements can come back later. */
