/* ==========================================================================
   DYNAMIC — analytics dashboard showcase
   One stylesheet: tokens → shell → controls → hero → panels → visuals → motion
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. TOKENS
   -------------------------------------------------------------------------- */
:root {
    color-scheme: dark;

    /* Surfaces */
    --bg:        #0F1420;
    --bg-deep:   #0B0F19;
    --panel:     #151B29;
    --panel-2:   #1B2333;
    --panel-3:   #212A3D;
    --line:      rgba(255, 255, 255, 0.07);
    --line-2:    rgba(255, 255, 255, 0.13);
    --line-3:    rgba(255, 255, 255, 0.22);
    --scrim:     rgba(6, 9, 16, 0.72);

    /* Ink */
    --ink:       #EEF2FA;
    --ink-2:     #A9B3C6;
    --ink-3:     #6F7A91;
    --ink-inv:   #0E1424;

    /* Series (validated: adjacent CVD ΔE ≥ 10, all ≥ 3:1 on --panel) */
    --s1: #3F83F0;   /* blue    */
    --s2: #E0702F;   /* orange  */
    --s3: #22A97D;   /* mint    */
    --s4: #8F7BEE;   /* violet  */
    --s5: #DB4F8E;   /* rose    */
    --s6: #BE8A18;   /* amber   */
    --s1-rgb: 63,131,240;
    --s2-rgb: 224,112,47;
    --s3-rgb: 34,169,125;
    --s4-rgb: 143,123,238;
    --s5-rgb: 219,79,142;
    --s6-rgb: 190,138,24;

    /* Sequential ramp (single hue, from --s1) */
    --q1: #16233D; --q2: #1B3560; --q3: #234B8A; --q4: #2E64B8; --q5: #3F83F0; --q6: #6FA3F5; --q7: #A9C8FA;

    /* Status */
    --good:  #2FBF71;
    --warn:  #E5A322;
    --bad:   #EF5B5B;
    --good-rgb: 47,191,113;
    --warn-rgb: 229,163,34;
    --bad-rgb:  239,91,91;

    --accent: var(--s1);
    --accent-rgb: var(--s1-rgb);

    /* Geometry */
    --top-h:    60px;
    --tick-h:   34px;
    --rail-w:   236px;
    --gap:      16px;
    --r-lg:     16px;
    --r-md:     10px;
    --r-sm:     7px;

    /* Type */
    --f-display: 'Bricolage Grotesque', 'Instrument Sans', system-ui, sans-serif;
    --f-ui:      'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --f-mono:    'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

    /* Motion */
    --ease:      cubic-bezier(0.22, 1, 0.36, 1);
    --ease-io:   cubic-bezier(0.65, 0, 0.35, 1);
    --dur:       .5s;

    --shadow-1: 0 1px 0 rgba(255,255,255,0.03) inset, 0 8px 24px -16px rgba(0,0,0,0.6);
    --shadow-2: 0 1px 0 rgba(255,255,255,0.05) inset, 0 24px 48px -20px rgba(0,0,0,0.75);
}

[data-theme="light"] {
    color-scheme: light;

    --bg:        #F3F5FA;
    --bg-deep:   #FFFFFF;
    --panel:     #FFFFFF;
    --panel-2:   #F4F6FB;
    --panel-3:   #EAEEF6;
    --line:      rgba(15, 20, 32, 0.08);
    --line-2:    rgba(15, 20, 32, 0.14);
    --line-3:    rgba(15, 20, 32, 0.24);
    --scrim:     rgba(15, 20, 32, 0.45);

    --ink:       #0E1424;
    --ink-2:     #4A5468;
    --ink-3:     #7B8599;
    --ink-inv:   #FFFFFF;

    --s1: #2563EB;
    --s2: #D65A18;
    --s3: #0F8A62;
    --s4: #6D5AE0;
    --s5: #C42C74;
    --s6: #B07A0A;
    --s1-rgb: 37,99,235;
    --s2-rgb: 214,90,24;
    --s3-rgb: 15,138,98;
    --s4-rgb: 109,90,224;
    --s5-rgb: 196,44,116;
    --s6-rgb: 176,122,10;

    --q1: #E4ECFB; --q2: #C6D8F7; --q3: #9DBDF2; --q4: #6E9DEB; --q5: #3B78E6; --q6: #2563EB; --q7: #1A47B0;

    --good:  #16944F;
    --warn:  #B7791F;
    --bad:   #D63A3A;
    --good-rgb: 22,148,79;
    --warn-rgb: 183,121,31;
    --bad-rgb:  214,58,58;

    --shadow-1: 0 1px 2px rgba(15,20,32,0.04), 0 8px 24px -16px rgba(15,20,32,0.18);
    --shadow-2: 0 2px 6px rgba(15,20,32,0.06), 0 24px 48px -20px rgba(15,20,32,0.28);
}

/* --------------------------------------------------------------------------
   2. BASE
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: var(--f-ui);
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background-color .35s ease, color .35s ease;
}
h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
svg { display: block; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: rgba(var(--accent-rgb), .35); }

.eyebrow {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--ink-3);
}
.icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* Ambient field: a very faint radial wash behind the sheet */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(900px 500px at 18% -10%, rgba(var(--s1-rgb), .16), transparent 60%),
        radial-gradient(700px 400px at 95% 10%, rgba(var(--s4-rgb), .10), transparent 60%);
    opacity: 1;
    transition: opacity .35s;
}
[data-theme="light"] body::before { opacity: .55; }

/* --------------------------------------------------------------------------
   3. SHELL — top bar, ticker, rail, main
   -------------------------------------------------------------------------- */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--top-h);
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 16px;
    background: color-mix(in srgb, var(--bg-deep) 82%, transparent);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    backdrop-filter: saturate(160%) blur(14px);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-mark {
    width: 30px; height: 30px; border-radius: 9px;
    background: linear-gradient(135deg, var(--s1), var(--s4));
    display: grid; place-items: center;
    box-shadow: 0 6px 18px -6px rgba(var(--s1-rgb), .8);
    position: relative; overflow: hidden;
}
.brand-mark svg { width: 16px; height: 16px; stroke: #fff; }
.brand-mark::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.35) 50%, transparent 70%);
    transform: translateX(-120%);
    animation: sheen 5s var(--ease) 1.2s infinite;
}
.brand-name { font-family: var(--f-display); font-size: 19px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.brand-tag  { display: block; margin-top: 3px; font-size: 10.5px; color: var(--ink-3); letter-spacing: .04em; }

.topbar-center { margin-left: auto; margin-right: auto; display: flex; align-items: center; gap: 12px; }
.topbar-right  { display: flex; align-items: center; gap: 8px; }

/* Ticker — a continuous strip of live figures under the bar */
.ticker {
    position: fixed;
    top: var(--top-h); left: 0; right: 0;
    height: var(--tick-h);
    z-index: 55;
    overflow: hidden;
    background: var(--bg-deep);
    border-bottom: 1px solid var(--line);
    font-family: var(--f-mono);
    font-size: 11.5px;
    letter-spacing: .01em;
    color: var(--ink-2);
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent);
            mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent);
}
.ticker-track {
    display: flex;
    width: max-content;
    height: 100%;
    align-items: center;
    animation: ticker 60s linear infinite;
    will-change: transform;
}
.ticker:hover .ticker-track { animation-play-state: paused; }
.ticker-item { display: inline-flex; align-items: center; gap: 8px; padding: 0 22px; white-space: nowrap; border-right: 1px solid var(--line); }
.ticker-item b { font-weight: 500; color: var(--ink); }
.ticker-item .k { color: var(--ink-3); text-transform: uppercase; font-size: 10.5px; letter-spacing: .06em; }
.ticker-item .d { font-weight: 500; }
.ticker-item .d.up { color: var(--good); }
.ticker-item .d.dn { color: var(--bad); }
.ticker-live { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-3); }

/* Rail — section index and legend */
.rail {
    position: fixed;
    top: calc(var(--top-h) + var(--tick-h));
    bottom: 0;
    left: 0;
    width: var(--rail-w);
    z-index: 50;
    display: flex;
    flex-direction: column;
    padding: 22px 14px 18px;
    background: var(--bg-deep);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform .4s var(--ease);
}
.rail.open { transform: none; }
.rail-title { padding: 0 10px 12px; }
.rail-nav { list-style: none; margin: 0; padding: 0; }
.rail-nav a {
    position: relative;
    display: flex; align-items: center; gap: 11px;
    padding: 9px 10px;
    border-radius: var(--r-sm);
    color: var(--ink-2);
    text-decoration: none;
    font-weight: 500;
    transition: background .2s, color .2s;
}
.rail-nav a .icon { width: 17px; height: 17px; color: var(--ink-3); transition: color .2s; }
.rail-nav a:hover { background: var(--panel); color: var(--ink); }
.rail-nav a:hover .icon { color: var(--ink-2); }
.rail-nav a.on { background: var(--panel-2); color: var(--ink); }
.rail-nav a.on .icon { color: var(--accent); }
.rail-nav a.on::before {
    content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px;
    border-radius: 0 3px 3px 0; background: var(--accent);
    box-shadow: 0 0 12px rgba(var(--accent-rgb), .8);
}
.rail-nav .cnt { margin-left: auto; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.rail-block { margin-top: 22px; padding: 14px 10px 0; border-top: 1px solid var(--line); }
.rail-block .eyebrow { margin-bottom: 10px; }
.rail-stat { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 0; font-size: 12.5px; color: var(--ink-2); }
.rail-stat b { font-family: var(--f-display); font-size: 17px; font-weight: 700; color: var(--ink); }
.rail-legend { display: grid; gap: 7px; font-size: 12px; color: var(--ink-2); }
.rail-legend span { display: flex; align-items: center; gap: 9px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.rail-foot { margin-top: auto; padding: 18px 10px 0; font-size: 11.5px; color: var(--ink-3); line-height: 1.5; }
.rail-foot a { color: var(--ink-2); text-decoration: none; border-bottom: 1px solid var(--line-2); }

.scrim {
    position: fixed; inset: 0; z-index: 45;
    background: var(--scrim);
    opacity: 0; pointer-events: none;
    transition: opacity .3s;
}
.scrim.on { opacity: 1; pointer-events: auto; }

.main {
    padding: calc(var(--top-h) + var(--tick-h) + 22px) 16px 60px;
    max-width: 1560px;
    margin: 0 auto;
}

/* --------------------------------------------------------------------------
   4. CONTROLS
   -------------------------------------------------------------------------- */
.seg {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 9px;
    position: relative;
}
.seg button {
    position: relative;
    z-index: 1;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--ink-2);
    transition: color .2s;
    white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button.on { color: var(--ink); }
.seg .seg-thumb {
    position: absolute; z-index: 0;
    top: 3px; bottom: 3px; left: 0; width: 0;
    background: var(--panel);
    border: 1px solid var(--line-2);
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,.18);
    transition: left .35s var(--ease), width .35s var(--ease);
}
.seg.seg-sm button { padding: 3px 9px; font-size: 11.5px; }
.seg.seg-sm { border-radius: 8px; padding: 2px; }
.seg.seg-sm .seg-thumb { top: 2px; bottom: 2px; border-radius: 5px; }
.seg.seg-sm .seg-thumb + button { }

.ibtn {
    display: inline-grid; place-items: center;
    width: 32px; height: 32px;
    border-radius: 8px;
    color: var(--ink-2);
    border: 1px solid transparent;
    transition: background .2s, color .2s, border-color .2s, transform .15s;
}
.ibtn:hover { background: var(--panel-2); color: var(--ink); border-color: var(--line); }
.ibtn:active { transform: scale(.94); }
.ibtn.on { color: var(--accent); background: rgba(var(--accent-rgb), .12); border-color: rgba(var(--accent-rgb), .3); }
.ibtn .icon { width: 16px; height: 16px; }
.ibtn-lbl {
    display: inline-flex; align-items: center; gap: 7px;
    height: 32px; padding: 0 12px;
    border-radius: 8px;
    font-size: 12.5px; font-weight: 500;
    color: var(--ink-2);
    border: 1px solid var(--line);
    background: var(--panel-2);
    transition: background .2s, color .2s, border-color .2s;
}
.ibtn-lbl:hover { color: var(--ink); border-color: var(--line-2); }
.ibtn-lbl .icon { width: 15px; height: 15px; }

/* Live toggle */
.live {
    display: inline-flex; align-items: center; gap: 8px;
    height: 32px; padding: 0 12px 0 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    font-size: 12.5px; font-weight: 600;
    color: var(--ink-2);
    transition: all .25s;
}
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); position: relative; }
.live.on { color: var(--good); border-color: rgba(var(--good-rgb), .4); background: rgba(var(--good-rgb), .10); }
.live.on .dot { background: var(--good); }
.live.on .dot::after {
    content: ""; position: absolute; inset: -4px; border-radius: 50%;
    border: 2px solid var(--good); opacity: 0;
    animation: ping 1.6s var(--ease) infinite;
}

/* Theme switch — a small sun/moon flip */
.theme-btn .icon-sun, .theme-btn .icon-moon { position: absolute; transition: transform .45s var(--ease), opacity .3s; }
.theme-btn { position: relative; }
[data-theme="dark"]  .theme-btn .icon-sun  { transform: rotate(-90deg) scale(.5); opacity: 0; }
[data-theme="light"] .theme-btn .icon-moon { transform: rotate(90deg) scale(.5); opacity: 0; }

.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px; font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}
.pill .icon { width: 11px; height: 11px; stroke-width: 2.4; }
.pill.up   { color: var(--good); background: rgba(var(--good-rgb), .13); }
.pill.dn   { color: var(--bad);  background: rgba(var(--bad-rgb), .13); }
.pill.flat { color: var(--ink-2); background: var(--panel-3); }
.pill.good { color: var(--good); background: rgba(var(--good-rgb), .13); }
.pill.warn { color: var(--warn); background: rgba(var(--warn-rgb), .15); }
.pill.bad  { color: var(--bad);  background: rgba(var(--bad-rgb), .13); }
.pill.info { color: var(--s1);   background: rgba(var(--s1-rgb), .13); }
.pill.neutral { color: var(--ink-2); background: var(--panel-3); }
.pill i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* --------------------------------------------------------------------------
   5. HERO — the live pulse
   -------------------------------------------------------------------------- */
.hero {
    position: relative;
    display: grid;
    grid-template-columns: minmax(280px, 380px) 1fr;
    gap: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
    overflow: hidden;
    margin-bottom: var(--gap);
}
.hero::before {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: radial-gradient(600px 240px at 0% 100%, rgba(var(--s1-rgb), .16), transparent 70%);
}
.hero-copy { position: relative; padding: 30px 30px 26px; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.hero-copy .eyebrow { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.hero-copy .eyebrow .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(var(--good-rgb), .5); animation: pulse-ring 2s ease-out infinite; }
.hero-title {
    font-family: var(--f-display);
    font-size: clamp(24px, 2.4vw, 32px);
    font-weight: 700;
    line-height: 1.08;
    letter-spacing: -.025em;
    text-wrap: balance;
    max-width: 14ch;
}
.hero-title em { font-style: normal; color: var(--accent); }
.hero-sub { margin-top: 12px; color: var(--ink-2); font-size: 13.5px; max-width: 34ch; }
.hero-figure { margin-top: auto; padding-top: 26px; }
.hero-figure .lbl { font-size: 12px; color: var(--ink-3); margin-bottom: 4px; }
.hero-value {
    font-family: var(--f-display);
    font-size: clamp(38px, 4vw, 54px);
    font-weight: 800;
    letter-spacing: -.035em;
    line-height: 1;
    color: var(--ink);
}
.hero-delta { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 12.5px; color: var(--ink-3); }

.hero-stage { position: relative; min-height: 300px; }
.hero-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hero-tag {
    position: absolute; right: 14px; top: 14px;
    display: flex; gap: 6px; align-items: center;
    padding: 4px 8px; border-radius: 6px;
    background: color-mix(in srgb, var(--panel) 70%, transparent);
    border: 1px solid var(--line);
    font-family: var(--f-mono); font-size: 11px; color: var(--ink-2);
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.hero-tag b { color: var(--ink); font-weight: 500; }
.hero-tip {
    position: absolute; top: 0; left: 0;
    transform: translate(-50%, 0);
    padding: 6px 9px; border-radius: 7px;
    background: var(--ink); color: var(--ink-inv);
    font-size: 11.5px; font-weight: 500; white-space: nowrap;
    pointer-events: none; opacity: 0; transition: opacity .15s;
    box-shadow: 0 8px 20px -8px rgba(0,0,0,.6);
}
.hero-tip.on { opacity: 1; }
.hero-tip small { display: block; font-weight: 400; opacity: .7; }
.hero-foot {
    position: absolute; left: 0; right: 0; bottom: 0;
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 16px;
    font-size: 11px; color: var(--ink-3);
    pointer-events: none;
}
.hero-foot .k { display: inline-flex; gap: 14px; }
.hero-foot .k span { display: inline-flex; align-items: center; gap: 6px; }
.hero-foot .k i { width: 14px; height: 2px; border-radius: 2px; background: var(--s1); }
.hero-foot .k i.ghost { background: var(--ink-3); height: 0; border-top: 2px dashed var(--ink-3); }

/* --------------------------------------------------------------------------
   6. KPI STRIP
   -------------------------------------------------------------------------- */
.kpis {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: var(--gap);
    margin-bottom: 30px;
}
.kpi {
    position: relative;
    padding: 16px 16px 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-1);
    overflow: hidden;
    transition: transform .3s var(--ease), border-color .3s, box-shadow .3s;
}
.kpi:hover { transform: translateY(-2px); border-color: var(--line-2); box-shadow: var(--shadow-2); }
.kpi-name { font-size: 12px; font-weight: 500; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.kpi-value {
    margin-top: 8px;
    font-family: var(--f-display);
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -.03em;
    line-height: 1;
    color: var(--ink);
}
.kpi-spark { position: absolute; left: 0; right: 0; bottom: 0; height: 44px; color: var(--s1); }
.kpi-spark svg { width: 100%; height: 100%; }
.kpi-spark path.line { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.kpi-spark path.fill { fill: currentColor; opacity: .14; }
.kpi-spark circle { fill: currentColor; stroke: var(--panel); stroke-width: 2; }
.kpi .kpi-body { padding-bottom: 34px; }
.kpi[data-tone="s2"] .kpi-spark { color: var(--s2); }
.kpi[data-tone="s3"] .kpi-spark { color: var(--s3); }
.kpi[data-tone="s4"] .kpi-spark { color: var(--s4); }
.kpi[data-tone="s5"] .kpi-spark { color: var(--s5); }
.kpi[data-tone="s6"] .kpi-spark { color: var(--s6); }

/* --------------------------------------------------------------------------
   7. SECTIONS + GRID
   -------------------------------------------------------------------------- */
.section { margin-bottom: 40px; scroll-margin-top: calc(var(--top-h) + var(--tick-h) + 12px); }
.section-head {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 20px;
    padding: 0 2px 14px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--line);
}
.section-head .eyebrow { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.section-head .eyebrow i { width: 8px; height: 8px; border-radius: 2px; background: var(--accent); }
.section-title {
    font-family: var(--f-display);
    font-size: clamp(20px, 2vw, 26px);
    font-weight: 700;
    letter-spacing: -.025em;
    line-height: 1.1;
}
.section-sub { margin-top: 5px; color: var(--ink-3); font-size: 12.5px; }
.section-hint { display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.section-hint .icon { width: 14px; height: 14px; }

.grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: var(--gap);
    min-height: 40px;
}
.span-3  { grid-column: span 3; }
.span-4  { grid-column: span 4; }
.span-5  { grid-column: span 5; }
.span-6  { grid-column: span 6; }
.span-7  { grid-column: span 7; }
.span-8  { grid-column: span 8; }
.span-12 { grid-column: span 12; }

/* --------------------------------------------------------------------------
   8. CARD ANATOMY
   -------------------------------------------------------------------------- */
.card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-1);
    min-width: 0;
    transition: transform .3s var(--ease), border-color .3s, box-shadow .3s, opacity .3s;
}
.card:hover { border-color: var(--line-2); box-shadow: var(--shadow-2); }
.card-head {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 12px 10px 14px;
    min-height: 52px;
}
.drag-handle {
    display: grid; place-items: center;
    width: 22px; height: 26px;
    margin-left: -6px;
    border-radius: 6px;
    color: var(--ink-3);
    cursor: grab;
    opacity: 0;
    transition: opacity .2s, background .2s, color .2s;
}
.drag-handle:active { cursor: grabbing; }
.card:hover .drag-handle, .drag-handle:focus-visible { opacity: 1; }
.drag-handle:hover { background: var(--panel-2); color: var(--ink); }
.drag-handle svg { width: 12px; height: 14px; }
.card-titles { min-width: 0; flex: 1 1 auto; }
.card-titles h3 { font-size: 14px; font-weight: 600; letter-spacing: -.005em; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-titles p  { font-size: 12px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-tools { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.card-tools .seg { margin-right: 6px; }
.card-tools .ibtn { width: 28px; height: 28px; opacity: .55; }
.card-tools .ibtn .icon { width: 15px; height: 15px; }
.card:hover .card-tools .ibtn, .card-tools .ibtn:focus-visible, .card-tools .ibtn.on { opacity: 1; }
.card-body { position: relative; flex: 1 1 auto; padding: 0 16px 16px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.card-foot { padding: 0 16px 14px; font-size: 11.5px; color: var(--ink-3); display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* Chart wells: fixed height, Chart.js needs a bounded box */
.well { position: relative; width: 100%; height: var(--h, 260px); min-height: 0; }
.well canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

/* Table twin — hidden until toggled */
.twin { display: none; max-height: calc(var(--h, 260px) + 60px); overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.card.show-table .well, .card.show-table .legend, .card.show-table .viz { display: none !important; }
.card.show-table .twin { display: block; animation: fade-in .3s var(--ease); }

/* HTML legend, generated */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); }
.legend button { display: inline-flex; align-items: center; gap: 7px; padding: 2px 4px; border-radius: 5px; color: inherit; transition: opacity .2s, background .2s; }
.legend button:hover { background: var(--panel-2); }
.legend button.off { opacity: .4; text-decoration: line-through; }
.legend button i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.legend button i.line { height: 2px; width: 14px; border-radius: 2px; }
.legend button i.dash { height: 0; width: 14px; border-top: 2px dashed var(--c); background: none; border-radius: 0; }
.legend .v { color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* Expanded panel */
body.has-expanded { overflow: hidden; }
.card.is-expanded {
    position: fixed;
    z-index: 80;
    inset: 4vh 4vw;
    box-shadow: 0 40px 100px -20px rgba(0,0,0,.7);
    animation: pop-in .35s var(--ease);
    overflow: auto;
}
.card.is-expanded .well { height: max(320px, calc(92vh - 170px)); }
.card.is-expanded .twin { max-height: calc(92vh - 140px); }
.expand-scrim { position: fixed; inset: 0; z-index: 75; background: var(--scrim); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); opacity: 0; pointer-events: none; transition: opacity .3s; }
.expand-scrim.on { opacity: 1; pointer-events: auto; }

/* Sortable states */
.card.sortable-ghost { opacity: .25; }
.card.sortable-ghost::after { content: ""; position: absolute; inset: 0; border: 2px dashed var(--accent); border-radius: 14px; }
.card.sortable-drag { transform: rotate(-1deg) scale(1.02); box-shadow: var(--shadow-2); opacity: .95 !important; }
.card.sortable-chosen { border-color: var(--accent); }
.grid.drop-target { outline: 1px dashed rgba(var(--accent-rgb), .5); outline-offset: 6px; border-radius: 10px; }

/* Flash when a panel receives new live data */
.card.flash { animation: card-flash 1.1s var(--ease); }

/* --------------------------------------------------------------------------
   9. VISUALS — the custom, non-Chart.js pieces
   -------------------------------------------------------------------------- */

/* Doughnut centre figure */
.donut-wrap { position: relative; }
.donut-centre { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-centre b { font-family: var(--f-display); font-size: 24px; font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.donut-centre span { font-size: 11px; color: var(--ink-3); margin-top: 4px; }

/* Value list (label · bar · value) */
.vlist { display: grid; gap: 9px; }
.vlist-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; font-size: 12.5px; }
.vlist-row .n { display: flex; align-items: center; gap: 8px; color: var(--ink-2); min-width: 0; }
.vlist-row .n i { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; background: var(--c); }
.vlist-row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.vlist-row .v small { color: var(--ink-3); font-weight: 400; margin-left: 5px; }
.vlist-row .bar { grid-column: 1 / -1; height: 4px; border-radius: 3px; background: var(--panel-3); overflow: hidden; }
.vlist-row .bar i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--c); transition: width 1.1s var(--ease); }
.in .vlist-row .bar i { width: var(--w); }

/* Funnel */
.funnel { display: grid; gap: 6px; padding-top: 4px; }
.funnel-row { display: grid; grid-template-columns: 96px 1fr 64px; align-items: center; gap: 12px; font-size: 12.5px; }
.funnel-row .n { color: var(--ink-2); font-weight: 500; }
.funnel-row .v { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.funnel-bar { position: relative; height: 30px; display: flex; justify-content: center; }
.funnel-bar i {
    display: block; height: 100%; width: 0;
    border-radius: 6px;
    background: var(--c, var(--s1));
    transition: width 1s var(--ease);
    position: relative;
}
.in .funnel-bar i { width: var(--w); }
.funnel-bar i::after { content: attr(data-lbl); position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 600; opacity: 0; transition: opacity .3s .8s; }
.in .funnel-bar i::after { opacity: 1; }
.funnel-step { display: grid; grid-template-columns: 96px 1fr 64px; gap: 12px; }
.funnel-step span { grid-column: 2; text-align: center; font-size: 11px; color: var(--ink-3); display: flex; align-items: center; justify-content: center; gap: 6px; }
.funnel-step span::before, .funnel-step span::after { content: ""; flex: 0 1 30px; height: 1px; background: var(--line-2); }

/* Heatmap */
.heat { display: grid; grid-template-columns: 34px 1fr; gap: 6px; font-size: 11px; color: var(--ink-3); }
.heat-y { display: grid; grid-auto-rows: 1fr; align-items: center; padding-bottom: 18px; }
.heat-grid { display: grid; grid-template-columns: repeat(24, 1fr); grid-auto-rows: 1fr; gap: 3px; }
.heat-cell {
    aspect-ratio: 1.15 / 1;
    border-radius: 3px;
    background: var(--q1);
    opacity: 0;
    transform: scale(.6);
    transition: transform .4s var(--ease), opacity .4s, background .4s, box-shadow .2s;
    cursor: default;
}
.in .heat-cell { opacity: 1; transform: none; }
.heat-cell:hover { box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--ink-2); z-index: 1; }
.heat-x { grid-column: 2; display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; }
.heat-x span { text-align: center; }
.heat-scale { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--ink-3); }
.heat-scale i { display: block; width: 90px; height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--q1), var(--q3), var(--q5), var(--q7)); }

/* Cohort grid */
.cohort { font-size: 11.5px; width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 3px; }
.cohort col.k { width: 64px; } .cohort col.s { width: 46px; }
.cohort th { font-weight: 500; color: var(--ink-3); text-align: left; padding: 2px 6px; font-size: 11px; }
.cohort th.c { text-align: center; }
.cohort td { padding: 0; }
.cohort td.k { color: var(--ink-2); font-weight: 500; white-space: nowrap; padding: 0 8px 0 4px; }
.cohort td.s { color: var(--ink-3); font-variant-numeric: tabular-nums; padding-right: 8px; }
.cohort .cell {
    display: grid; place-items: center;
    height: 30px; border-radius: 5px;
    background: var(--q1); color: var(--ink);
    font-weight: 500; font-variant-numeric: tabular-nums;
    opacity: 0; transform: translateY(6px);
    transition: opacity .4s var(--ease), transform .4s var(--ease), background .4s;
}
.in .cohort .cell { opacity: 1; transform: none; }
.cohort .cell.hi { color: var(--ink-inv); }

/* Gauges */
.gauges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.gauge svg { width: 100%; height: auto; }
.gauge .track { fill: none; stroke: var(--panel-3); stroke-width: 10; stroke-linecap: round; }
.gauge .arc { fill: none; stroke: var(--c, var(--s1)); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 0.01 1000; transition: stroke-dasharray 1.4s var(--ease); }
.in .gauge .arc { stroke-dasharray: var(--d) 1000; }
.gauge .tgt { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.gauge-v { font-family: var(--f-display); font-size: 21px; font-weight: 700; letter-spacing: -.03em; margin-top: -30px; position: relative; }
.gauge-l { font-size: 11.5px; color: var(--ink-3); margin-top: 6px; line-height: 1.35; }
.gauge-list { display: grid; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12.5px; }
.gauge-list div { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.gauge-list div span:first-child { color: var(--ink-2); }
.gauge-list b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Treemap */
.treemap { position: relative; width: 100%; height: var(--h, 240px); border-radius: 10px; overflow: hidden; }
.tm-node {
    position: absolute;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--c);
    color: #fff;
    overflow: hidden;
    opacity: 0;
    transform: scale(.85);
    transition: opacity .5s var(--ease), transform .6s var(--ease), filter .2s;
    box-shadow: 0 0 0 2px var(--panel);
    cursor: default;
}
.in .tm-node { opacity: 1; transform: none; }
.tm-node:hover { filter: brightness(1.12); z-index: 1; }
.tm-node b { display: block; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tm-node span { display: block; font-size: 11px; opacity: .85; font-variant-numeric: tabular-nums; }
.tm-node.sm b { font-size: 11px; } .tm-node.sm span { display: none; }
.tm-node.xs { padding: 4px 6px; } .tm-node.xs b { display: none; } .tm-node.xs span { display: none; }

/* Bullet charts */
.bullets { display: grid; gap: 14px; }
.bullet { display: grid; grid-template-columns: 110px 1fr 70px; align-items: center; gap: 12px; font-size: 12.5px; }
.bullet .n { color: var(--ink-2); font-weight: 500; }
.bullet .n small { display: block; color: var(--ink-3); font-size: 11px; font-weight: 400; }
.bullet .v { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.bullet .v small { display: block; color: var(--ink-3); font-weight: 400; font-size: 11px; }
.bullet-track { position: relative; height: 16px; border-radius: 4px; background: var(--panel-3); overflow: hidden; }
.bullet-track .band { position: absolute; top: 0; bottom: 0; left: 0; background: var(--panel-2); border-right: 1px solid var(--line-2); }
.bullet-track .band.b2 { background: rgba(255,255,255,.04); }
[data-theme="light"] .bullet-track .band.b2 { background: rgba(15,20,32,.04); }
.bullet-track .meas { position: absolute; top: 5px; bottom: 5px; left: 0; width: 0; border-radius: 3px; background: var(--c, var(--s1)); transition: width 1.1s var(--ease); }
.in .bullet-track .meas { width: var(--w); }
.bullet-track .tgt { position: absolute; top: 2px; bottom: 2px; width: 2px; background: var(--ink); left: var(--t); }
.bullet.over .meas { background: var(--bad); }

/* Rings */
.rings { display: grid; grid-template-columns: 1fr; gap: 10px; }
.ring { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.ring svg { width: 46px; height: 46px; flex: 0 0 auto; transform: rotate(-90deg); }
.ring .trk { fill: none; stroke: var(--panel-3); stroke-width: 5; }
.ring .prg { fill: none; stroke: var(--c, var(--s1)); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 0.01 999; transition: stroke-dasharray 1.3s var(--ease); }
.in .ring .prg { stroke-dasharray: var(--d) 999; }
.ring b { font-family: var(--f-display); font-size: 15px; font-weight: 700; display: block; letter-spacing: -.02em; }
.ring .rn { font-size: 12.5px; font-weight: 500; }
.ring .rs { font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.ring .rp { margin-left: auto; text-align: right; }
.ring .rp small { display: block; font-size: 10.5px; color: var(--ink-3); }

/* Sparkline table (financial health) */
.stab { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.stab th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); padding: 0 8px 8px; border-bottom: 1px solid var(--line); }
.stab td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.stab tr:last-child td { border-bottom: 0; }
.stab td.k { font-weight: 500; }
.stab td.k small { display: block; color: var(--ink-3); font-weight: 400; font-size: 11px; }
.stab td.v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.stab td.sp svg { width: 92px; height: 26px; }
.stab td.sp path { fill: none; stroke: var(--c, var(--s1)); stroke-width: 1.6; stroke-linecap: round; }
.stab td.st { text-align: right; }
.stab tbody tr { transition: background .15s; }
.stab tbody tr:hover { background: var(--panel-2); }

/* Data table (orders) */
.dtable-wrap { overflow: auto; border-radius: 10px; border: 1px solid var(--line); }
.dtable { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 560px; }
.dtable thead th {
    position: sticky; top: 0; z-index: 1;
    text-align: left; padding: 9px 12px;
    font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
    color: var(--ink-3); background: var(--panel-2); border-bottom: 1px solid var(--line);
    cursor: pointer; user-select: none; white-space: nowrap;
}
.dtable thead th:hover { color: var(--ink); }
.dtable thead th .sort { display: inline-block; width: 8px; margin-left: 5px; opacity: 0; transition: opacity .15s; }
.dtable thead th:hover .sort { opacity: .5; }
.dtable thead th.asc .sort, .dtable thead th.desc .sort { opacity: 1; color: var(--accent); }
.dtable thead th.desc .sort { transform: rotate(180deg); }
.dtable thead th.r, .dtable td.r { text-align: right; }
.dtable td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.dtable tbody tr { transition: background .15s; }
.dtable tbody tr:hover { background: var(--panel-2); }
.dtable tbody tr.new { animation: row-in .8s var(--ease); }
.dtable td.mono { font-family: var(--f-mono); font-size: 11.5px; color: var(--ink-2); }
.dtable .cust { display: flex; align-items: center; gap: 9px; }
.dtable .av { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; font-weight: 700; color: #fff; background: var(--c, var(--s1)); flex: 0 0 auto; }
.dtable .amt { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.dtable .amt i { display: inline-block; width: 56px; height: 4px; border-radius: 2px; background: var(--panel-3); position: relative; overflow: hidden; }
.dtable .amt i::after { content: ""; position: absolute; inset: 0; width: var(--w); background: var(--s1); border-radius: 2px; }
.dtable-tools { display: flex; align-items: center; gap: 8px; }
.search { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-3); }
.search input { border: 0; background: none; outline: none; color: var(--ink); font: inherit; width: 120px; }
.search input::placeholder { color: var(--ink-3); }
.search .icon { width: 14px; height: 14px; }

/* Activity feed */
.feed { position: relative; display: grid; gap: 0; max-height: 300px; overflow: auto; padding-right: 4px; }
.feed-item { position: relative; display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; padding: 8px 0; align-items: start; }
.feed-item::before { content: ""; position: absolute; left: 12px; top: 30px; bottom: -8px; width: 1px; background: var(--line-2); }
.feed-item:last-child::before { display: none; }
.feed-item .ic { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: rgba(var(--c-rgb, var(--s1-rgb)), .14); color: rgb(var(--c-rgb, var(--s1-rgb))); }
.feed-item .ic .icon { width: 13px; height: 13px; }
.feed-item .t { font-size: 12.5px; }
.feed-item .t b { font-weight: 600; }
.feed-item .m { font-size: 11px; color: var(--ink-3); margin-top: 1px; }
.feed-item .w { font-size: 11px; color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed-item.new { animation: row-in .7s var(--ease); }

/* Tasks */
.tasks { display: grid; gap: 4px; }
.task { display: flex; align-items: center; gap: 10px; padding: 8px 8px; border-radius: 8px; transition: background .15s; }
.task:hover { background: var(--panel-2); }
.task .chk { width: 18px; height: 18px; border-radius: 6px; border: 1.5px solid var(--line-3); display: grid; place-items: center; color: #fff; flex: 0 0 auto; transition: background .2s, border-color .2s; }
.task .chk .icon { width: 11px; height: 11px; stroke-width: 3; opacity: 0; transform: scale(.5); transition: opacity .2s, transform .25s var(--ease); }
.task.done .chk { background: var(--good); border-color: var(--good); }
.task.done .chk .icon { opacity: 1; transform: none; }
.task .tn { flex: 1 1 auto; font-size: 12.5px; position: relative; }
.task .tn::after { content: ""; position: absolute; left: 0; top: 50%; height: 1px; width: 0; background: var(--ink-3); transition: width .3s var(--ease); }
.task.done .tn { color: var(--ink-3); }
.task.done .tn::after { width: 100%; }
.task .tm { font-size: 11px; color: var(--ink-3); white-space: nowrap; }
.tasks-sum { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--ink-3); }
.tasks-sum .bar { flex: 1 1 auto; height: 4px; margin: 0 12px; border-radius: 3px; background: var(--panel-3); overflow: hidden; }
.tasks-sum .bar i { display: block; height: 100%; width: var(--w); background: var(--good); transition: width .5s var(--ease); }

/* NPS distribution bar */
.dist { display: flex; height: 14px; border-radius: 6px; overflow: hidden; gap: 2px; }
.dist i { display: block; height: 100%; width: 0; background: var(--c); transition: width 1s var(--ease); }
.in .dist i { width: var(--w); }
.nps-score { display: flex; align-items: baseline; gap: 12px; }
.nps-score b { font-family: var(--f-display); font-size: 44px; font-weight: 800; letter-spacing: -.04em; line-height: 1; }
.nps-score span { color: var(--ink-3); font-size: 12px; }

/* Twin tables */
.twin table { width: 100%; border-collapse: collapse; font-size: 12px; }
.twin th, .twin td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.twin th:first-child, .twin td:first-child { text-align: left; position: sticky; left: 0; background: var(--panel); }
.twin thead th { position: sticky; top: 0; background: var(--panel-2); color: var(--ink-3); font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; z-index: 1; }
.twin thead th:first-child { z-index: 2; background: var(--panel-2); }
.twin tbody tr:hover td { background: var(--panel-2); }

/* Toast */
.toast {
    position: fixed; left: 50%; bottom: 22px; z-index: 90;
    transform: translate(-50%, 20px);
    padding: 9px 14px; border-radius: 10px;
    background: var(--ink); color: var(--ink-inv);
    font-size: 12.5px; font-weight: 500;
    box-shadow: 0 16px 40px -12px rgba(0,0,0,.6);
    opacity: 0; pointer-events: none;
    transition: opacity .3s, transform .35s var(--ease);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* Footer */
.foot { margin-top: 20px; padding: 22px 4px 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--ink-3); }
.foot b { color: var(--ink-2); font-weight: 500; }

/* --------------------------------------------------------------------------
   10. MOTION
   -------------------------------------------------------------------------- */
@keyframes ticker { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@keyframes ping { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(1.9); opacity: 0; } }
@keyframes pulse-ring { 0% { box-shadow: 0 0 0 0 rgba(var(--good-rgb), .55); } 100% { box-shadow: 0 0 0 9px rgba(var(--good-rgb), 0); } }
@keyframes sheen { 0%, 60% { transform: translateX(-120%); } 90%, 100% { transform: translateX(120%); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes row-in { from { background: rgba(var(--accent-rgb), .22); transform: translateY(-4px); } to { background: transparent; transform: none; } }
@keyframes card-flash { 0% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), .55); } 100% { box-shadow: 0 0 0 10px rgba(var(--accent-rgb), 0); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* Entrance: everything below the bar rises in; charts draw once in view */
html.js .reveal { opacity: 0; transform: translateY(14px); }
html.js .reveal.in { opacity: 1; transform: none; transition: opacity .6s var(--ease), transform .6s var(--ease); }
html.js .topbar { animation: rise .5s var(--ease) both; }
html.js .ticker { animation: rise .5s var(--ease) .1s both; }
html.js .rail  { }
.hero.reveal.in { transition-delay: .05s; }

/* Value change flip */
.tick-up { animation: tick-up .6s var(--ease); }
.tick-dn { animation: tick-dn .6s var(--ease); }
@keyframes tick-up { 0% { color: var(--good); transform: translateY(3px); } 100% { color: inherit; transform: none; } }
@keyframes tick-dn { 0% { color: var(--bad); transform: translateY(-3px); } 100% { color: inherit; transform: none; } }

/* Chart.js tooltip (external, HTML) */
.cj-tip {
    position: absolute; z-index: 20;
    pointer-events: none;
    min-width: 120px;
    padding: 8px 10px;
    border-radius: 9px;
    background: color-mix(in srgb, var(--ink) 96%, transparent);
    color: var(--ink-inv);
    font-size: 12px;
    box-shadow: 0 12px 30px -10px rgba(0,0,0,.6);
    opacity: 0;
    transform: translate(-50%, calc(-100% - 12px));
    transition: opacity .15s, transform .2s var(--ease), left .12s linear, top .12s linear;
}
.cj-tip.on { opacity: 1; }
.cj-tip .tt { font-weight: 600; margin-bottom: 4px; opacity: .85; font-size: 11px; letter-spacing: .03em; }
.cj-tip .tr { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 1px 0; }
.cj-tip .tr span { display: inline-flex; align-items: center; gap: 7px; opacity: .85; }
.cj-tip .tr i { width: 8px; height: 8px; border-radius: 2px; background: var(--c); }
.cj-tip .tr b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   11. RESPONSIVE
   -------------------------------------------------------------------------- */
@media (min-width: 1024px) {
    .rail { transform: none; }
    .main { margin-left: var(--rail-w); padding-left: 24px; padding-right: 24px; }
    .menu-btn { display: none; }
    .scrim { display: none; }
}
@media (min-width: 1360px) {
    .main { padding-left: 32px; padding-right: 32px; }
}
@media (max-width: 1200px) {
    .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .span-3 { grid-column: span 6; }
    .span-4 { grid-column: span 6; }
    .span-5 { grid-column: span 6; }
    .span-7 { grid-column: span 6; }
    .span-8 { grid-column: span 12; }
}
@media (max-width: 900px) {
    .hero { grid-template-columns: 1fr; }
    .hero-copy { border-right: 0; border-bottom: 1px solid var(--line); padding: 22px 20px 20px; }
    .hero-stage { min-height: 240px; }
    .topbar-center { display: none; }
    .range-mobile { display: flex !important; margin: 0 0 14px; }
}
@media (max-width: 720px) {
    :root { --gap: 12px; }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .span-3, .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
    .brand-tag { display: none; }
    .topbar { padding: 0 12px; gap: 10px; }
    .live span.t { display: none; }
    .ibtn-lbl span { display: none; }
    .ibtn-lbl { width: 32px; padding: 0; justify-content: center; }
    .section-hint { display: none; }
    .card-head { padding: 12px 10px 8px 12px; flex-wrap: wrap; row-gap: 8px; }
    .card-titles { flex: 1 1 calc(100% - 60px); }
    .card-tools { margin-left: auto; }
    .card-body { padding: 0 12px 12px; }
    .drag-handle { opacity: 1; }
    .funnel-row, .funnel-step { grid-template-columns: 74px 1fr 54px; }
    .bullet { grid-template-columns: 90px 1fr 60px; }
    .gauges { grid-template-columns: repeat(3, 1fr); gap: 4px; }
    .gauge-v { font-size: 17px; }
    .heat-x span:nth-child(odd) { visibility: hidden; }
    .card.is-expanded { inset: 2vh 2vw; }
}
.range-mobile { display: none; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
    html.js .reveal { opacity: 1; transform: none; }
    .ticker-track { animation: none; }
}
html.no-motion *, html.no-motion *::before, html.no-motion *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
html.no-motion .reveal { opacity: 1; transform: none; }
