/* Fizza tracker. Phone first (360 px), wider layouts from 720 / 1100 px. Chart colours follow the dataviz palette. */

:root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --surface-2: #f0efec;
    --ink: #0b0b0b;
    --ink-2: #52514e;
    --muted: #6f6d68;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, 0.10);
    --accent: #0b0b0b;
    --accent-ink: #fcfcfb;
    --series: #2a78d6;
    --series-hover: #1c5cab;
    --seq-lo: #cde2fb;
    --seq-hi: #0d366b;
    --good: #0ca30c;
    --good-ink: #006300;
    --warn: #fab219;
    --warn-ink: #8a5a00;
    --critical: #d03b3b;
    --critical-ink: #a32424;
    --radius: 12px;
    --gutter: 16px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface: #1a1a19;
        --surface-2: #262624;
        --ink: #f0efec;
        --ink-2: #c3c2b7;
        --muted: #9a988f;
        --grid: #2c2c2a;
        --axis: #383835;
        --border: rgba(255, 255, 255, 0.10);
        --accent: #f0efec;
        --accent-ink: #1a1a19;
        --series: #3987e5;
        --series-hover: #6da7ec;
        --seq-lo: #1d2a3a;
        --seq-hi: #86b6ef;
        --good-ink: #0ca30c;
        --warn-ink: #fab219;
        --critical-ink: #e66767;
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #f0efec;
    --accent-ink: #1a1a19;
    --series: #3987e5;
    --series-hover: #6da7ec;
    --seq-lo: #1d2a3a;
    --seq-hi: #86b6ef;
    --good-ink: #0ca30c;
    --warn-ink: #fab219;
    --critical-ink: #e66767;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font: 16px/1.5 var(--font);
    overflow-x: hidden;
}
body.nav-open { overflow: hidden; }
a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--series); }
h1, h2 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 650; }
small { color: var(--muted); }
:focus-visible { outline: 2px solid var(--series); outline-offset: 2px; }
.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;
}
.skip { position: absolute; left: -9999px; top: 8px; z-index: 50; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* top bar + navigation */
.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 10px;
    padding: 8px var(--gutter);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; min-height: 44px; }
.brand img { border-radius: 8px; }
.mode {
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
    padding: 2px 8px; border-radius: 999px; border: 1px solid var(--warn); color: var(--warn-ink);
}
.menu-toggle {
    margin-left: auto; width: 44px; height: 44px; display: grid; place-items: center;
    background: none; border: 1px solid var(--border); border-radius: 10px; color: var(--ink); cursor: pointer;
}
.menu-toggle__bars, .menu-toggle__bars::before, .menu-toggle__bars::after {
    display: block; width: 20px; height: 2px; background: currentColor; border-radius: 2px; position: relative;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.menu-toggle__bars::before, .menu-toggle__bars::after { content: ""; position: absolute; left: 0; }
.menu-toggle__bars::before { top: -6px; }
.menu-toggle__bars::after { top: 6px; }
.menu-toggle[aria-expanded="true"] .menu-toggle__bars { background: transparent; }
.menu-toggle[aria-expanded="true"] .menu-toggle__bars::before { transform: translateY(6px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] .menu-toggle__bars::after { transform: translateY(-6px) rotate(-45deg); }

.nav {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 40;
    width: min(84vw, 320px);
    padding: 72px var(--gutter) var(--gutter);
    background: var(--surface);
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 0.22s ease;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 16px;
}
.nav.is-open { transform: none; }
.nav__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav__link {
    display: flex; align-items: center; min-height: 48px; padding: 0 12px; border-radius: 10px;
    text-decoration: none; font-weight: 550;
}
.nav__link[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.nav__link:hover { background: var(--surface-2); color: var(--ink); }
.nav__link[aria-current="page"]:hover { background: var(--accent); color: var(--accent-ink); }
.nav__lang { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; color: var(--ink-2); }
.nav-backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.4); }

@media (min-width: 1100px) {
    .menu-toggle, .nav-backdrop { display: none !important; }
    .nav {
        position: static; transform: none; width: auto; padding: 0; border: 0; background: none;
        flex-direction: row; align-items: center; margin-left: auto; overflow: visible; transition: none;
    }
    .nav__list { display: flex; gap: 2px; }
    .nav__link { min-height: 40px; padding: 0 10px; font-size: 0.93rem; }
    .nav__lang { font-size: 0.9rem; }
}

/* page */
.page { max-width: 1240px; margin: 0 auto; padding: 16px var(--gutter) 32px; display: grid; gap: 16px; }
.page > * { min-width: 0; }
.page__title { font-size: 1.55rem; font-weight: 750; letter-spacing: -0.01em; }
.section-title { font-size: 1.15rem; margin: 8px 0 -4px; }
.page__lead { margin: -8px 0 0; color: var(--ink-2); }
.crumbs { margin: 0 0 -10px; font-size: 0.9rem; color: var(--ink-2); }
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; min-width: 0;
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card__head a { font-size: 0.9rem; color: var(--ink-2); }
.grid-2, .grid-3 { display: grid; gap: 16px; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.empty { color: var(--muted); margin: 0; }
.note { color: var(--muted); font-size: 0.88rem; margin: 0; max-width: 72ch; }
.notice { margin: 0; padding: 12px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--warn); }
.notice--good { border-color: var(--good); }
.notice--error { border-color: var(--critical); }
.claim { margin: 0; padding: 12px 16px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 10px 10px 0; color: var(--ink-2); }
.claim p { margin: 0 0 4px; }
.claim footer { font-size: 0.85rem; color: var(--muted); }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); } }
.tile {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.tile--hero { grid-column: 1 / -1; }
@media (min-width: 720px) { .tile--hero { grid-column: auto; } }
.tile__label { font-size: 0.85rem; color: var(--ink-2); }
.tile__value { font-size: 1.45rem; font-weight: 650; overflow-wrap: anywhere; }
.tile--hero .tile__value { font-size: 2.2rem; }
@media (min-width: 720px) { .tile--hero .tile__value { font-size: 2.6rem; line-height: 1.1; } }
.tile__sub { font-size: 0.8rem; color: var(--muted); }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chips { display: flex; gap: 6px; border: 0; margin: 0; padding: 0; overflow-x: auto; max-width: 100%; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span, .chip-link {
    display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border); white-space: nowrap; cursor: pointer;
    font-size: 0.92rem; text-decoration: none;
}
.chip input:checked + span, .chip-link[aria-current="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip input:focus-visible + span { outline: 2px solid var(--series); outline-offset: 2px; }
.select select {
    min-height: 44px; font: inherit; font-size: 16px; padding: 0 36px 0 12px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface); color: var(--ink); max-width: 100%;
}
.select { max-width: 100%; }
.sortbar { display: flex; gap: 6px; overflow-x: auto; }
.btn {
    display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px;
    border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--ink);
    font: inherit; font-size: 0.92rem; text-decoration: none; cursor: pointer;
}
.btn--ghost { min-height: 36px; padding: 0 12px; color: var(--ink-2); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* tables: stacked cards on phones */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.table th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 0.82rem; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.table th.num, .table td.num { text-align: right; }
.table tr.is-empty td { color: var(--muted); }
@media (max-width: 719px) {
    .table--stack thead { display: none; }
    .table--stack, .table--stack tbody, .table--stack tr, .table--stack td { display: block; width: 100%; }
    .table--stack tr { padding: 10px 0; border-bottom: 1px solid var(--grid); }
    .table--stack td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
    .table--stack td::before { content: attr(data-label); color: var(--muted); text-align: left; font-size: 0.85rem; }
    .table--stack td.num { text-align: right; }
}

/* badges */
.kind { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.kind--sale { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.kind--refill { border-color: var(--good); color: var(--good-ink); }
.kind--hold { border-style: dashed; color: var(--ink-2); }
.kind--removed, .kind--soldout { border-color: var(--critical); color: var(--critical-ink); }
.kind--released, .kind--returned, .kind--adjust { color: var(--muted); }
.age { white-space: nowrap; font-variant-numeric: tabular-nums; }
.age--ok span[aria-hidden] { color: var(--good); }
.age--warn { color: var(--warn-ink); }
.age--warn span[aria-hidden] { color: var(--warn); }
.age--alert { color: var(--critical-ink); font-weight: 600; }
.age--alert span[aria-hidden] { color: var(--critical); }
.status { color: var(--ink-2); font-size: 0.85rem; }
.status span[aria-hidden] { color: var(--good); }
.status--down { color: var(--critical-ink); }
.status--down span[aria-hidden] { color: var(--critical); }

/* ranking + share bars */
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.rank__row { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 2px 8px; align-items: baseline; }
.rank__n { color: var(--muted); font-variant-numeric: tabular-nums; }
.rank__name { overflow-wrap: anywhere; font-weight: 550; }
.rank__v { font-variant-numeric: tabular-nums; font-weight: 600; }
.rank .share { grid-column: 2 / -1; }
.rank__meta { grid-column: 2 / -1; font-size: 0.82rem; color: var(--muted); }
.share { display: block; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.share__fill { display: block; height: 100%; width: calc(var(--v, 0) * 100%); background: var(--series); border-radius: 0 4px 4px 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list__row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.list__row:last-child { border-bottom: 0; }
.list__main { min-width: 0; overflow-wrap: anywhere; }
.list__sub { display: block; font-size: 0.85rem; color: var(--ink-2); }

/* machine cards */
.machines { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
@media (min-width: 720px) { .machines { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); } }
.machine { display: grid; gap: 10px; }
.machine__link { text-decoration: none; display: grid; }
.machine__name { font-weight: 700; font-size: 1.05rem; }
.machine__addr { color: var(--ink-2); font-size: 0.88rem; }
.machine__facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.machine__facts div { min-width: 0; }
.machine__facts dt { font-size: 0.75rem; color: var(--muted); }
.machine__facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.machine__foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; margin: 0; font-size: 0.88rem; }

/* refill visits */
.visits { list-style: none; margin: 0; padding: 0; }
.visit { border-bottom: 1px solid var(--grid); }
.visit:last-child { border-bottom: 0; }
.visit__head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; min-height: 48px; cursor: pointer; padding: 6px 0; }
.visit__when { font-weight: 600; }
.visit__machine { color: var(--ink-2); }
.visit__units { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--good-ink); }
.visit__removed { color: var(--critical-ink); }
.visit__lines { list-style: none; margin: 0 0 10px; padding: 0 0 0 12px; border-left: 2px solid var(--grid); display: grid; gap: 4px; }
.visit__line { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; font-size: 0.92rem; }
.visit__line--removed { color: var(--critical-ink); }
.visit__delta { color: var(--muted); font-variant-numeric: tabular-nums; }
.visit__link { display: inline-block; margin: 0 0 10px 12px; font-size: 0.88rem; }

/* column chart */
.chart { margin: 0; display: grid; gap: 8px; }
.chart__title { font-weight: 650; font-size: 1rem; }
.chart__plot { position: relative; height: 180px; margin-left: 52px; }
.chart__grid { position: absolute; inset: 0; pointer-events: none; }
.chart__line { position: absolute; left: 0; right: 0; bottom: calc(var(--v, 0) * 100%); border-top: 1px solid var(--grid); }
.chart__line[data-v="0"] { border-top-color: var(--axis); }
.chart__line i {
    position: absolute; right: calc(100% + 6px); top: -0.6em; font-style: normal; font-size: 0.72rem;
    color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chart__bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.bar {
    flex: 1 1 0; min-width: 0; height: 100%; padding: 0; border: 0; background: none; cursor: pointer;
    display: flex; align-items: flex-end; justify-content: center;
}
.bar__fill {
    display: block; width: 100%; max-width: 24px; height: calc(var(--v, 0) * 100%);
    background: var(--series); border-radius: 4px 4px 0 0; transition: background 0.12s;
}
.chart__bars--dense .bar__fill { border-radius: 2px 2px 0 0; }
.bar:hover .bar__fill, .bar:focus-visible .bar__fill, .bar.is-active .bar__fill { background: var(--series-hover); }
.chart__x { display: flex; justify-content: space-between; margin-left: 52px; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart__table summary, .heat + .chart__table summary { cursor: pointer; color: var(--ink-2); font-size: 0.85rem; min-height: 32px; display: inline-flex; align-items: center; }
.chart__table .table { margin-top: 6px; }

/* heatmap */
.heat { margin: 0; display: grid; gap: 8px; }
.heat__wrap { overflow-x: auto; }
.heat__table { border-collapse: separate; border-spacing: 2px; width: 100%; min-width: 320px; table-layout: fixed; }
.heat__table th { font-size: 0.7rem; font-weight: 500; color: var(--muted); text-align: left; padding: 0; }
.heat__table thead th:first-child, .heat__table tbody th { width: 26px; }
.heat__hr { white-space: nowrap; overflow: visible; }
.heat__sum { width: 34px; font-size: 0.72rem; color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }
.heat__cell {
    height: 22px; border-radius: 3px; padding: 0; cursor: pointer;
    background: color-mix(in oklab, var(--seq-hi) calc(var(--v, 0) * 100%), var(--seq-lo));
}
.heat__cell--zero { background: var(--surface-2); }
.heat__cell:hover, .heat__cell:focus-visible { outline: 2px solid var(--ink); outline-offset: -1px; }
.heat__legend { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 0.75rem; color: var(--muted); }
.heat__scale { width: 120px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--seq-lo), var(--seq-hi)); }

/* tooltip */
.tip {
    position: fixed; z-index: 60; pointer-events: none; display: grid; gap: 1px;
    padding: 6px 10px; border-radius: 8px; background: var(--ink); color: var(--surface);
    font-size: 0.82rem; max-width: 240px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.tip__v { font-weight: 700; }
.tip__l { opacity: 0.8; }

/* pager, footer */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; font-size: 0.9rem; color: var(--ink-2); }
.footer { max-width: 1240px; margin: 0 auto; padding: 0 var(--gutter) 32px; color: var(--muted); font-size: 0.85rem; }
.footer p { margin: 4px 0; }
.footer__poll span { color: var(--good); }
.footer__poll--stale span, .footer__poll--stale strong { color: var(--critical-ink); }
.footer__note { max-width: 72ch; }
.footer__version { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; }
.footer__update { color: var(--ink-2); }
.footer__update:empty { display: none; }

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