/* =========================================================================
   Weight Tracker — design system.

   Dark first. Light is separately tuned rather than an inversion: in dark,
   elevation means lighter; in light it means whiter plus a real shadow, and
   the semantic hues are re-picked for contrast on white rather than computed.

   Theme resolution, three states:
     no attribute            -> dark
     OS says light           -> light, unless [data-theme="dark"]
     explicit [data-theme]   -> always wins

   Every colour pair below was measured, not estimated. Where a value differs
   from the same token in laptime-sim, the reason is a contrast failure and it
   is noted inline.
   ========================================================================= */

@font-face {
    font-family: 'InterVariable';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('/assets/fonts/inter-latin-wght-normal.woff2') format('woff2');
}

:root {
    /* --- type --- */
    --font-sans: 'InterVariable', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

    --text-xs: 11px;
    --text-sm: 12px;
    --text-base: 13.5px;
    --text-md: 15px;
    --text-lg: 18px;
    --text-xl: 24px;
    /* 9vw, not 6vw: at 390px 6vw resolves to 23px and clamps up to the floor,
       so a phone would get the SMALLEST hero. Backwards for a mobile-first app. */
    --text-hero: clamp(34px, 9vw, 44px);
    --text-display: clamp(44px, 15vw, 64px);
    --text-input: 16px;            /* the iOS focus-zoom floor, as a token */

    --micro-size: 10.5px;
    --micro-track: 0.07em;

    /* --- space --- */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    /* --- radius --- */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-pill: 999px;

    /* --- layout --- */
    --header-h: 52px;
    --tab-h: 56px;
    --content-max: 720px;
    --gutter: 16px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --tap: 44px;                   /* nothing interactive is ever smaller */
    --chart-h: 168px;

    /* --- motion --- */
    --ease: cubic-bezier(0.2, 0.6, 0.25, 1);
    --fast: 120ms;
    --bump: 900ms;                 /* the one animation longer than --fast */
}

/* ---------- dark (default) ---------- */

:root,
:root[data-theme='dark'] {
    color-scheme: dark;

    --bg: #0a0d13;
    --bg-grad: radial-gradient(1200px 600px at 70% -10%, #16202e 0%, transparent 60%);
    --surface-1: #121821;
    --surface-2: #1a212c;
    --surface-3: #232c39;
    --border: #27313f;
    --border-strong: #3a4759;
    /* Control boundaries need 3:1 (WCAG 1.4.11). --border-strong measures
       1.89:1, so fields get their own heavier token: this is 3.40:1. */
    --field-border: #63748c;

    --ink: #e9eff7;                /* 15.41:1 on --surface-1 */
    --ink-2: #98a5b6;              /*  7.12:1 */
    --ink-3: #8b98a9;              /*  6.08:1 — laptime's #6b7889 measures 3.97 */

    --brand: #4da3ff;              /*  6.79:1 */
    --brand-hover: #74b8ff;
    --brand-ink: #05121f;          /*  7.19:1 on --brand */
    --brand-soft: rgb(77 163 255 / 14%);

    --ok: #3ddc97;                 /* 10.08:1 */
    --ok-soft: rgb(61 220 151 / 13%);
    --caution: #ffb340;            /*  9.99:1 */
    --caution-soft: rgb(255 179 64 / 13%);
    --danger: #ff6b6b;             /*  6.42:1 */
    --danger-soft: rgb(255 107 107 / 13%);

    --shadow-1: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-2: 0 8px 24px rgb(0 0 0 / 45%);
    --ring: 0 0 0 3px rgb(77 163 255 / 35%);

    --series-1: #4aa3ff;
    --series-over: #ffb340;
}

/* ---------- light ---------- */

@media (prefers-color-scheme: light) {
    :root:not([data-theme='dark']) {
        color-scheme: light;

        --bg: #eef1f6;
        --bg-grad: radial-gradient(1200px 600px at 70% -10%, #dce6f5 0%, transparent 60%);
        --surface-1: #ffffff;
        --surface-2: #f2f5f9;
        --surface-3: #e5ebf3;
        --border: #d9e0ea;
        --border-strong: #b9c4d2;
        --field-border: #828d9c;   /* 3.37:1 on white */

        --ink: #0f151d;            /* 18.34:1 */
        --ink-2: #56616f;          /*  6.30:1 */
        --ink-3: #5f6a78;          /*  5.50:1 — laptime's #7d8896 measures 3.60 */

        --brand: #0a66d0;          /*  5.49:1 */
        --brand-hover: #0857b1;
        --brand-ink: #ffffff;      /*  5.49:1 on --brand */
        --brand-soft: rgb(10 102 208 / 10%);

        --ok: #07794c;             /*  5.46:1 — laptime's #0a8f5a measures 4.13 */
        --ok-soft: rgb(7 121 76 / 12%);
        --caution: #8a5a00;        /*  5.93:1 */
        --caution-soft: rgb(138 90 0 / 12%);
        --danger: #cc342c;         /*  5.13:1 */
        --danger-soft: rgb(204 52 44 / 10%);

        --shadow-1: 0 1px 2px rgb(16 24 40 / 8%);
        --shadow-2: 0 8px 24px rgb(16 24 40 / 10%);
        --ring: 0 0 0 3px rgb(10 102 208 / 25%);

        --series-1: #0a66d0;
        --series-over: #8a5a00;
    }
}

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

    --bg: #eef1f6;
    --bg-grad: radial-gradient(1200px 600px at 70% -10%, #dce6f5 0%, transparent 60%);
    --surface-1: #ffffff;
    --surface-2: #f2f5f9;
    --surface-3: #e5ebf3;
    --border: #d9e0ea;
    --border-strong: #b9c4d2;
    --field-border: #828d9c;

    --ink: #0f151d;
    --ink-2: #56616f;
    --ink-3: #5f6a78;

    --brand: #0a66d0;
    --brand-hover: #0857b1;
    --brand-ink: #ffffff;
    --brand-soft: rgb(10 102 208 / 10%);

    --ok: #07794c;
    --ok-soft: rgb(7 121 76 / 12%);
    --caution: #8a5a00;
    --caution-soft: rgb(138 90 0 / 12%);
    --danger: #cc342c;
    --danger-soft: rgb(204 52 44 / 10%);

    --shadow-1: 0 1px 2px rgb(16 24 40 / 8%);
    --shadow-2: 0 8px 24px rgb(16 24 40 / 10%);
    --ring: 0 0 0 3px rgb(10 102 208 / 25%);

    --series-1: #0a66d0;
    --series-over: #8a5a00;
}

@media (min-width: 720px) {
    :root {
        --header-h: 60px;
        --chart-h: 240px;
        --gutter: 24px;
    }
}

@media (prefers-reduced-motion: reduce) {
    :root { --fast: 1ms; --bump: 1ms; }
}

/* =========================================================================
   Base
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg-grad), var(--bg);
    background-attachment: fixed;
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: var(--text-md);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

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

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
/* The page title is deliberately smaller than the hero metric. The number is
   the reason you opened the app; the word "Today" is not. */
h1 { font-size: var(--text-lg); font-weight: 650; }
h2 { font-size: var(--text-md); font-weight: 650; }
h3 { font-size: var(--text-base); font-weight: 650; }
p { margin: 0 0 var(--space-3); }
p:last-child { margin-bottom: 0; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

.icon { width: 20px; height: 20px; flex: none; }

.skip {
    position: absolute; left: -9999px; top: 0; z-index: 60;
    background: var(--brand); color: var(--brand-ink);
    padding: var(--space-3) var(--space-4); border-radius: 0 0 var(--radius-md) 0;
}
.skip:focus { left: 0; }

.micro {
    font-size: var(--micro-size);
    font-weight: 700;
    letter-spacing: var(--micro-track);
    text-transform: uppercase;
    /* --ink-2, not --ink-3: this is the smallest text in the app, and the
       faintest grey on the smallest type is exactly the mistake being fixed. */
    color: var(--ink-2);
    margin: 0 0 var(--space-1);
}

.muted { color: var(--ink-2); }
.small { font-size: var(--text-base); }
.tnum  { font-variant-numeric: tabular-nums; }

/* =========================================================================
   Shell
   ========================================================================= */

.topbar {
    position: sticky; top: 0; z-index: 25;
    min-height: var(--header-h);
    display: flex; align-items: center; gap: var(--space-3);
    padding: 0 var(--gutter);
    background: color-mix(in srgb, var(--bg) 78%, transparent);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    backdrop-filter: blur(12px) saturate(140%);
    border-bottom: 1px solid var(--border);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .topbar, .tabbar { background: var(--surface-1); }
}

.brand {
    display: flex; align-items: center; gap: var(--space-2);
    color: var(--ink); font-weight: 700; letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; }
.topbar-title { font-size: var(--text-lg); font-weight: 650; letter-spacing: -0.01em; }
.topbar-date { margin-left: auto; color: var(--ink-2); font-size: var(--text-base); }

.topnav { display: none; gap: var(--space-1); margin-left: var(--space-5); }
.topnav-item {
    min-height: 36px; display: inline-flex; align-items: center; gap: var(--space-2);
    padding: 0 var(--space-3); border-radius: var(--radius-pill);
    color: var(--ink-2); font-size: var(--text-base); font-weight: 600;
    transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.topnav-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.topnav-item[aria-current='page'] { background: var(--brand-soft); color: var(--brand); }

.content { padding-top: var(--space-4); }
.content-inner {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0 var(--gutter) calc(var(--tab-h) + var(--safe-b) + var(--space-6));
}
.content-inner-wide { max-width: 1040px; }
/* The single rule that makes sideways scroll impossible: no grid or flex child
   may claim its min-content width as a floor. */
.content-inner > * { min-width: 0; }

.tabbar {
    position: fixed; inset: auto 0 0 0; z-index: 30;
    display: grid; grid-template-columns: repeat(4, 1fr);
    background: color-mix(in srgb, var(--surface-1) 88%, transparent);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    backdrop-filter: blur(12px) saturate(140%);
    border-top: 1px solid var(--border);
    /* The bar's background runs under the home indicator; its contents do not. */
    padding-bottom: var(--safe-b);
}
.tabbar-item {
    min-height: var(--tab-h);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px;
    color: var(--ink-2); font-size: var(--text-xs); font-weight: 600;
    transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.tabbar-item:hover { text-decoration: none; }
.tabbar-item .icon { width: 22px; height: 22px; }
.tabbar-item[aria-current='page'] { color: var(--brand); }
.tabbar-item:active { background: var(--surface-2); }

@media (min-width: 720px) {
    .tabbar { display: none; }
    .topnav { display: flex; }
    .content-inner { padding-bottom: var(--space-6); }
}

/* =========================================================================
   Surfaces — importance is size + surface + space, never all three flat
   ========================================================================= */

.hero {
    padding: var(--space-5) var(--space-5) var(--space-4);
    border-radius: var(--radius-xl);
    background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface-1) 100%);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-2);
    margin-bottom: var(--space-5);
}
.hero-value {
    font-size: var(--text-display);
    font-weight: 700; line-height: 1; letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}
.hero-unit { font-size: var(--text-xl); font-weight: 600; color: var(--ink-2); margin-left: var(--space-1); }
.hero-sub { margin: var(--space-3) 0 0; color: var(--ink-2); font-size: var(--text-base); }

.card {
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    background: var(--surface-1);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-1);
    margin-bottom: var(--space-4);
}
.card-accent { border-color: color-mix(in srgb, var(--brand) 35%, var(--border)); }
.card-head {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: var(--space-3); margin-bottom: var(--space-3);
}
.card-head .card-action { font-size: var(--text-base); font-weight: 600; }

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}
.tile {
    padding: var(--space-3) var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    background: var(--surface-1);
    border: 1px solid var(--border);
}
.tile-value {
    font-size: var(--text-xl); font-weight: 680; letter-spacing: -0.015em;
    font-variant-numeric: tabular-nums; line-height: 1.15;
}
.tile-value-unavailable { font-size: var(--text-md); font-weight: 550; color: var(--ink-2); }
.tile-sub { margin: var(--space-1) 0 0; color: var(--ink-2); font-size: var(--text-sm); }

.delta { font-variant-numeric: tabular-nums; font-weight: 650; }
.delta-ok { color: var(--ok); }
.delta-caution { color: var(--caution); }
.delta-danger { color: var(--danger); }
.delta-flat { color: var(--ink-2); }

.meter {
    height: 6px; border-radius: var(--radius-pill);
    background: var(--surface-3); overflow: hidden; margin: var(--space-3) 0 var(--space-2);
}
.meter-fill {
    display: block; height: 100%; border-radius: var(--radius-pill);
    background: var(--brand); transition: width var(--fast) var(--ease);
}
.meter-over .meter-fill { background: var(--caution); }

/* =========================================================================
   Controls
   ========================================================================= */

.btn {
    min-height: var(--tap);
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    padding: 0 var(--space-4);
    border: 1px solid transparent; border-radius: var(--radius-md);
    background: var(--brand); color: var(--brand-ink);
    font: inherit; font-weight: 620; cursor: pointer;
    transition: background var(--fast) var(--ease), transform var(--fast) var(--ease),
                border-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.btn:hover { background: var(--brand-hover); text-decoration: none; }
/* A press must be acknowledged before the page navigates. Its absence is most
   of why the old interface felt dead. */
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-quiet { background: var(--surface-2); color: var(--ink); border-color: var(--border-strong); }
.btn-quiet:hover { background: var(--surface-3); }
.btn-danger {
    background: transparent; color: var(--danger); border-color: var(--border);
    padding: 0 var(--space-3); font-size: var(--text-base);
}
.btn-danger:hover { background: var(--danger-soft); }

.field { margin-bottom: var(--space-3); }
.field-label {
    display: block; margin-bottom: var(--space-1);
    font-size: var(--text-base); font-weight: 600; color: var(--ink-2);
}
input[type='text'], input[type='number'], input[type='date'], input[type='email'],
input[type='password'], select, textarea {
    width: 100%; min-height: 48px; padding: 0 var(--space-3);
    background: var(--surface-2); color: var(--ink);
    border: 1px solid var(--field-border); border-radius: var(--radius-md);
    font: inherit;
    font-size: var(--text-input);   /* 16px stops iOS zooming the page on focus */
    transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
textarea { min-height: 80px; padding: var(--space-3); line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
    border-color: var(--brand); box-shadow: var(--ring); outline: none;
}
input[aria-invalid='true'] { border-color: var(--danger); }
.field-hint { margin: var(--space-1) 0 0; font-size: var(--text-sm); color: var(--ink-2); }
.field-error { margin: var(--space-1) 0 0; font-size: var(--text-base); font-weight: 600; color: var(--danger); }
.field-error[hidden] { display: none; }

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); }

.checkline {
    display: flex; align-items: center; gap: var(--space-3);
    min-height: var(--tap); cursor: pointer;
    font-size: var(--text-base); font-weight: 600; color: var(--ink-2); margin: 0;
}
.checkline input[type='checkbox'] {
    width: 20px; height: 20px; min-height: 0; flex: none;
    accent-color: var(--brand); cursor: pointer;
}

.segmented {
    display: grid; grid-auto-flow: column; gap: 2px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 3px; margin-bottom: var(--space-4);
}
.segmented label, .segmented a {
    min-height: 38px; display: grid; place-items: center;
    border-radius: var(--radius-sm); cursor: pointer;
    color: var(--ink-2); font-size: var(--text-base); font-weight: 600;
    transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.segmented a:hover, .segmented label:hover { color: var(--ink); text-decoration: none; }
.segmented a[aria-current='true'] { background: var(--brand); color: var(--brand-ink); }

/* Panel switching with no JavaScript: hidden sibling radios drive the panels. */
.seg-radio { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.panel { display: none; }
#tab-weight:checked ~ #panel-weight,
#tab-food:checked   ~ #panel-food,
#tab-train:checked  ~ #panel-train { display: block; }
#tab-weight:checked ~ .segmented label[for='tab-weight'],
#tab-food:checked   ~ .segmented label[for='tab-food'],
#tab-train:checked  ~ .segmented label[for='tab-train'] { background: var(--brand); color: var(--brand-ink); }
#tab-weight:focus-visible ~ .segmented label[for='tab-weight'],
#tab-food:focus-visible   ~ .segmented label[for='tab-food'],
#tab-train:focus-visible  ~ .segmented label[for='tab-train'] { box-shadow: var(--ring); }

/* One-tap re-logging of something eaten before. Each chip is a submit button
   in a shared form, so a tap is an ordinary form post and needs no JavaScript. */
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
    min-height: var(--tap);
    display: inline-flex; align-items: center; gap: var(--space-2);
    padding: 0 var(--space-3);
    border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
    background: var(--surface-2); color: var(--ink);
    font: inherit; font-size: var(--text-base); font-weight: 600;
    cursor: pointer; text-align: left;
    transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
                transform var(--fast) var(--ease);
}
.chip:hover { background: var(--surface-3); border-color: var(--brand); }
.chip:active { transform: translateY(1px); }
.chip-kcal {
    color: var(--ink-2); font-variant-numeric: tabular-nums;
    padding-left: var(--space-2); border-left: 1px solid var(--border);
}

.disclosure { margin: var(--space-3) 0 0; border-top: 1px solid var(--border); padding-top: var(--space-2); }
.disclosure > summary {
    min-height: var(--tap); display: flex; align-items: center; gap: var(--space-2);
    cursor: pointer; color: var(--ink-2); font-size: var(--text-base); font-weight: 600;
    list-style: none;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after { content: '+'; margin-left: auto; font-size: var(--text-lg); font-weight: 400; }
.disclosure[open] > summary::after { content: '\2212'; }
.disclosure > summary:hover { color: var(--ink); }

/* =========================================================================
   Quick log — the reason the redesign exists
   ========================================================================= */

.quicklog-row { display: flex; gap: var(--space-2); align-items: stretch; }
.quicklog-input { position: relative; flex: 1; }
.quicklog-input input {
    min-height: 56px; padding-right: 42px;
    font-size: var(--text-xl); font-weight: 650; font-variant-numeric: tabular-nums;
    scroll-margin-top: calc(var(--header-h) + var(--space-3));
}
.quicklog-unit {
    position: absolute; right: var(--space-3); top: 50%; transform: translateY(-50%);
    color: var(--ink-2); font-size: var(--text-md); font-weight: 600; pointer-events: none;
}
.quicklog-save { min-height: 56px; padding: 0 var(--space-5); }
.quicklog-hint { margin: var(--space-3) 0 0; color: var(--ink-2); font-size: var(--text-base); }

/* The confirmation. The only animation longer than 120ms, because it IS the
   feedback that the number changed. */
.is-updated { animation: cell-bump var(--bump) var(--ease); border-radius: var(--radius-sm); }
@keyframes cell-bump {
    0%   { background-color: var(--brand-soft); }
    100% { background-color: transparent; }
}

/* =========================================================================
   Findings
   ========================================================================= */

.findings { display: flex; flex-direction: column; gap: var(--space-3); }
.finding {
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    background: var(--surface-1);
}
.finding-critical { border-left-color: var(--danger); background: var(--danger-soft); }
.finding-warning  { border-left-color: var(--caution); background: var(--caution-soft); }
.finding-info     { border-left-color: var(--brand); background: var(--brand-soft); }
.finding-fact { margin: 0; }
.finding-action { margin: var(--space-2) 0 0; font-weight: 620; }

/* =========================================================================
   Rows and tables — stacked on a phone, tabular on a desktop
   ========================================================================= */

.rows { display: flex; flex-direction: column; }
.row {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-3) 0; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; }
.row-meta { color: var(--ink-2); font-size: var(--text-sm); }
.row-value { font-variant-numeric: tabular-nums; font-weight: 650; text-align: right; }
.row-actions { display: flex; gap: var(--space-2); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); }
th {
    font-size: var(--micro-size); text-transform: uppercase;
    letter-spacing: var(--micro-track); color: var(--ink-2); font-weight: 700;
}
td.num, th.num { text-align: right; }

/* Below 720px every table becomes a stack of labelled rows, so nothing is ever
   pushed off-screen — which is where the delete button used to live. */
@media (max-width: 719px) {
    table.stacked, table.stacked tbody, table.stacked tr, table.stacked td { display: block; width: 100%; }
    table.stacked thead { display: none; }
    table.stacked tr {
        border: 1px solid var(--border); border-radius: var(--radius-md);
        padding: var(--space-2) var(--space-3); margin-bottom: var(--space-2);
        background: var(--surface-1);
    }
    table.stacked td {
        display: flex; justify-content: space-between; gap: var(--space-3);
        border: 0; padding: var(--space-1) 0; text-align: left;
    }
    table.stacked td::before {
        content: attr(data-label);
        font-size: var(--micro-size); text-transform: uppercase;
        letter-spacing: var(--micro-track); color: var(--ink-2); font-weight: 700;
    }
}

.pill {
    display: inline-block; padding: 1px var(--space-2); border-radius: var(--radius-pill);
    background: var(--surface-3); color: var(--ink-2);
    font-size: var(--text-xs); font-weight: 650;
}

/* =========================================================================
   Charts — geometry in SVG, every glyph in HTML
   ========================================================================= */

.chart { margin: 0; }
.chart-legend {
    display: flex; flex-wrap: wrap; gap: var(--space-3);
    margin: 0 0 var(--space-3);
    font-size: var(--text-base); color: var(--ink-2);
}
.legend-item { display: inline-flex; align-items: center; gap: var(--space-2); }
/* Values wear text tokens; the swatch beside them carries the identity. */
.legend-item strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.swatch { width: 14px; height: 3px; border-radius: 2px; background: var(--series-1); flex: none; }
.swatch-raw { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); opacity: .75; }
.swatch-target { background: transparent; height: 0; border-top: 2px dashed var(--caution); }
.swatch-over { background: var(--series-over); }

.chart-body { display: grid; grid-template-columns: 44px 1fr; gap: var(--space-2); }
.chart-yaxis {
    position: relative; height: var(--chart-h);
    font-size: var(--text-xs); color: var(--ink-2);
    font-variant-numeric: tabular-nums;
}
.chart-yaxis span { position: absolute; right: 0; transform: translateY(-50%); white-space: nowrap; }

.chart-plot { position: relative; height: var(--chart-h); touch-action: pan-y; }
.chart-svg { width: 100%; height: 100%; display: block; overflow: visible; }

.chart-xaxis {
    display: flex; justify-content: space-between;
    margin: var(--space-2) 0 0 52px;
    font-size: var(--text-xs); color: var(--ink-2);
}

.chart-grid       { stroke: var(--border); stroke-width: 1; }
.chart-trend      { fill: none; stroke: var(--series-1); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart-raw        { stroke: var(--ink-3); stroke-width: 4; stroke-linecap: round; opacity: .65; }
.chart-projection { stroke: var(--series-1); stroke-width: 1.6; opacity: .55; }
/* Intake bars are HTML, not SVG: a rounded bar end and a real gap between bars
   both survive only outside a non-uniformly scaled viewBox. */
.bars {
    position: relative; display: flex; align-items: flex-end; gap: 2px;
    height: var(--chart-h);
}
.bar {
    flex: 1; min-width: 0; border-radius: 4px 4px 0 0;
    background: var(--series-1); opacity: .9;
    transition: opacity var(--fast) var(--ease);
}
.bar-over { background: var(--series-over); opacity: 1; }
/* A day with no log is a stub, never a zero-height bar: "did not log" and
   "ate nothing" are different claims and must not look the same. */
.bar-missing { background: var(--border-strong); border-radius: 2px; opacity: .8; }
.bars:hover .bar { opacity: .55; }
.bars .bar:hover { opacity: 1; }

/* A dashed rule is drawn in HTML, not SVG: stroke-dasharray is measured in
   user units along the path, so under a stretched x-scale the dashes compress. */
.chart-rule {
    position: absolute; left: 0; right: 0; height: 0;
    border-top: 1.5px dashed var(--caution); transform: translateY(-50%);
}
.chart-flag {
    position: absolute; left: 0; transform: translateY(-100%);
    padding: 0 var(--space-1); border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--surface-1) 85%, transparent);
    color: var(--caution); font-size: var(--text-xs); font-weight: 650;
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chart-crosshair {
    position: absolute; top: 0; bottom: 0; width: 1px;
    background: var(--ink-2); opacity: .55; pointer-events: none;
}
.chart-crosshair[hidden] { display: none; }

.chart-table { margin-top: var(--space-3); }
.chart-table > summary {
    min-height: var(--tap); display: flex; align-items: center;
    cursor: pointer; color: var(--ink-2); font-size: var(--text-base); font-weight: 600;
}

/* =========================================================================
   Flash, empty states, auth
   ========================================================================= */

.flash {
    padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
    margin-bottom: var(--space-4); font-weight: 600;
    border: 1px solid transparent;
}
.flash-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

.how-formula {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: var(--text-base);
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: var(--space-3);
    overflow-x: auto; white-space: nowrap;
}
.card ul { margin: 0 0 var(--space-3); padding-left: var(--space-4); }
.card li { margin-bottom: var(--space-2); }
.card li:last-child { margin-bottom: 0; }
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.9em; background: var(--surface-2);
    padding: 1px var(--space-1); border-radius: var(--radius-sm);
}

.empty { text-align: center; padding: var(--space-5) var(--space-4); color: var(--ink-2); }
.empty-action { display: block; margin-top: var(--space-3); font-weight: 620; }

.auth-shell { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand {
    display: flex; align-items: center; justify-content: center; gap: var(--space-2);
    margin-bottom: var(--space-4); font-size: var(--text-xl); font-weight: 700;
    letter-spacing: -0.02em;
}

.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.row-between { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.section-gap { margin-top: var(--space-6); }
