/*
 * app.css
 *
 * Single-column throughout, sized in relative units, with touch-scale hit
 * targets — so the "mobile later" step is hosting the same files, not a rewrite.
 * Palette values are the validated data-viz reference palette; chart roles and
 * UI roles draw from the same tokens so the charts belong to the page.
 */

/* ── tokens ──────────────────────────────────────────────────────────── */
:root {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface:         #fcfcfb;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --series-1:        #2a78d6;
  --series-2:        #eb6834;
  --good:            #0ca30c;
  --warning:         #fab219;
  --critical:        #d03b3b;
  --success-text:    #006300;
  --accent-ink:      #ffffff;
  --shadow:          0 1px 2px rgba(11, 11, 11, 0.05), 0 4px 16px rgba(11, 11, 11, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface:        #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --success-text:   #0ca30c;
    --shadow:         0 1px 2px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface:        #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --series-1:       #3987e5;
  --series-2:       #d95926;
  --success-text:   #0ca30c;
  --shadow:         0 1px 2px rgba(0, 0, 0, 0.4);
}

/* ── base ────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2 { font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 2px; }
main {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}
[hidden] { display: none !important; }

.sub { margin: 0 0 14px; color: var(--text-secondary); font-size: 13px; }
.empty { color: var(--text-muted); font-size: 14px; text-align: center; padding: 20px 0; }

/* ── controls ────────────────────────────────────────────────────────── */
.btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 9px 14px;
  min-height: 40px;
  cursor: pointer;
}
.btn:hover { border-color: var(--axis); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--series-1);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 550;
}
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }
.btn-quiet { background: transparent; }
.btn-danger { background: var(--critical); border-color: transparent; color: #fff; font-weight: 550; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-icon {
  min-width: 40px;
  padding: 9px 10px;
  line-height: 1;
  color: var(--text-secondary);
}
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.linkbtn {
  font: inherit;
  background: none;
  border: 0;
  padding: 4px 2px;
  color: var(--series-1);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.linkbtn:hover { filter: brightness(1.15); }

input, select {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  min-height: 40px;
  width: 100%;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .linkbtn:focus-visible,
.tab:focus-visible, .pill:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}

.field { display: block; margin-bottom: 12px; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 550;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

/* ── lock screen ─────────────────────────────────────────────────────── */
#screen-lock {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.lock-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px 20px;
  box-shadow: var(--shadow);
}
.lock-title { font-size: 20px; margin: 0 0 6px; }
.lock-lede { color: var(--text-secondary); font-size: 13px; margin: 0 0 18px; }
.warn {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  border-left: 3px solid var(--warning);
  border-radius: 0 6px 6px 0;
  padding: 10px 12px;
  margin: 4px 0 14px;
}
.lock-err {
  color: var(--critical);
  font-size: 13px;
  margin: 12px 0 0;
  text-align: center;
}
.lock-foot {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.lock-foot-note {
  display: block;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── chrome ──────────────────────────────────────────────────────────── */
.demo-banner {
  background: var(--warning);
  color: #0b0b0b;
  font-size: 13px;
  font-weight: 550;
  text-align: center;
  padding: 7px 12px;
}
.demo-banner .linkbtn { color: #0b0b0b; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  font: inherit;
  border: 0;
  background: none;
  color: var(--text-secondary);
  padding: 9px 12px;
  min-height: 40px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text-primary); }
.tab.is-active {
  color: var(--text-primary);
  font-weight: 600;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
}

/* ── day view ────────────────────────────────────────────────────────── */
.daynav { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.daynav-mid { display: flex; align-items: center; gap: 10px; flex: 1; justify-content: center; }
.dateinput { width: auto; max-width: 190px; text-align: center; font-weight: 550; }

.hero { text-align: center; padding: 24px 0 20px; }
.hero-figure {
  font-size: 56px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
}
.hero-label { color: var(--text-secondary); font-size: 13px; margin-top: 6px; }
.hero-sub { color: var(--text-muted); font-size: 12.5px; margin-top: 8px; min-height: 18px; }

.lines { list-style: none; margin: 0 0 14px; padding: 0; }
.line {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
}
.line-qty {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 30px;
}
.line-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-abv { color: var(--text-muted); font-size: 12px; }
.line-drinks {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  font-size: 13px;
}
.line-x {
  font: inherit;
  border: 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
  min-width: 32px;
  border-radius: 6px;
}
.line-x:hover { color: var(--critical); background: color-mix(in srgb, var(--critical) 10%, transparent); }

.addrow { display: flex; gap: 8px; align-items: flex-start; }
.qty { display: flex; align-items: center; gap: 0; }
.qty input {
  width: 56px;
  text-align: center;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  -moz-appearance: textfield;
}
.qty input::-webkit-outer-spin-button,
.qty input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty .btn-icon:first-child { border-radius: 8px 0 0 8px; }
.qty .btn-icon:last-child { border-radius: 0 8px 8px 0; }

.picker { position: relative; flex: 1; }
.results {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  list-style: none;
  margin: 0;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow-y: auto;
}
.result {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  min-height: 40px;
}
.result:hover, .result.is-cursor { background: color-mix(in srgb, var(--series-1) 12%, transparent); }
.result-meta { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.result-new { color: var(--series-1); font-weight: 550; }
/* ODbL §4.3 attribution. Not a row: no pointer, no hover, no hit target.
   Sticky, because the list scrolls at 280px and seven results already overflow
   it — a notice you have to scroll to find is not "reasonably calculated" to
   reach the person looking at the results. The negative margins cancel the
   list's own 4px padding so it sits flush against the bottom edge. */
.result-attrib {
  position: sticky;
  bottom: -4px;
  margin: 4px -4px -4px;
  padding: 7px 10px;
  background: var(--surface);
  border-top: 1px solid var(--grid);
  border-radius: 0 0 7px 7px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.35;
  cursor: default;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.chip {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 8px 13px;
  min-height: 36px;
  cursor: pointer;
}
.chip:hover { border-color: var(--series-1); color: var(--series-1); }
.chips-label {
  width: 100%;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

/* ── cards, tiles, charts ────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin: 0 0 16px;
}
.card-danger { border-color: color-mix(in srgb, var(--critical) 40%, var(--border)); }
figure.card { margin-inline: 0; }
figcaption { margin-bottom: 10px; }

.filterrow { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.pill {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 7px 14px;
  min-height: 36px;
  cursor: pointer;
}
.pill.is-active {
  background: var(--series-1);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 550;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.tile-label { font-size: 12px; color: var(--text-secondary); }
.tile-value { font-size: 27px; font-weight: 600; line-height: 1.15; margin-top: 4px; }
.tile-note { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.tile-note.is-good { color: var(--success-text); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 6px; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
}
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend-swatch.is-line { height: 2px; border-radius: 2px; width: 14px; }

.chartwrap { position: relative; width: 100%; overflow-x: auto; }
.chartwrap svg { display: block; width: 100%; height: auto; }
.tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
/* Dashed here is deliberate and is NOT the dashed-gridline anti-pattern: this
   line is a threshold, which is exactly what dashing is read to mean. */
.limitline { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 5 4; opacity: 0.9; }
.legend-swatch.is-dash {
  height: 2px; width: 16px; border-radius: 0;
  background: repeating-linear-gradient(90deg,
    var(--text-muted) 0 5px, transparent 5px 9px) !important;
}
.datalabel { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }
.hitrect { fill: transparent; cursor: crosshair; }
.crosshair { stroke: var(--axis); stroke-width: 1; pointer-events: none; }

.tooltip {
  position: absolute;
  z-index: 40;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  font-size: 12.5px;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  box-shadow: var(--shadow);
}
.tooltip-date { font-weight: 600; margin-bottom: 3px; }
.tooltip-row { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.tooltip-val { font-variant-numeric: tabular-nums; margin-left: auto; padding-left: 10px; color: var(--text-primary); }

/* horizontal bars — built in HTML so long names wrap instead of clipping */
.hbars { display: flex; flex-direction: column; gap: 9px; }
.hbar {
  display: grid;
  grid-template-columns: minmax(90px, 1.4fr) 3fr auto;
  align-items: center;
  gap: 10px;
}
.hbar-name {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hbar-track { height: 12px; }
.hbar-fill {
  height: 100%;
  background: var(--series-1);
  border-radius: 0 4px 4px 0;   /* rounded data-end, square at the baseline */
}
.hbar-val {
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  min-width: 34px;
  text-align: right;
}
@media (max-width: 480px) {
  .hbar { grid-template-columns: minmax(72px, 1.2fr) 2fr auto; gap: 8px; }
}

.tabletoggle { margin-top: 8px; font-size: 13px; }
.tableview { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-secondary); font-weight: 550; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
.rowbtn {
  font: inherit;
  font-size: 12.5px;
  background: none;
  border: 0;
  color: var(--series-1);
  cursor: pointer;
  padding: 4px 6px;
}
.rowbtn.is-danger { color: var(--critical); }

.catform {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0 12px;
}
.catform .field:first-child { grid-column: 1 / -1; }
.calcnote { font-size: 13px; color: var(--text-secondary); margin: 4px 0 0; min-height: 20px; }
.calcnote.is-err { color: var(--critical); }

/* ── toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--text-primary);
  color: var(--page);
  font-size: 13.5px;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}

@media (max-width: 480px) {
  .hero-figure { font-size: 46px; }
  main { padding: 16px 12px 56px; }
  .topbar { padding: 6px 10px; }
  .tab { padding: 9px 10px; }
}

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