/* fuel — the "LAB" visual direction.
 *
 * Scientific-instrument / lab-notebook look: warm paper, hairline rules, ruler
 * ticks, tabular figures, monospace metadata. Nerdy via PRECISION, not darkness.
 *
 * THE RULE THAT KEEPS IT COHERENT:
 *   if a human wrote it        -> IBM Plex Sans
 *   if the machine emitted it  -> IBM Plex Mono, uppercase, wide-tracked, muted
 *
 * Two accents only — alert (rust) and positive (green). Everything else is
 * ink/paper/grey. Do not add hues. No shadows anywhere: rules and fills only.
 */
@import url('/fonts/fonts.css');

:root {
  --paper:  #f6f4ee;
  --surface:#ffffff;
  --chrome: #efece4;
  --ink:    #15161a;
  --ink-2:  #2c2e35;
  --muted:  #8b8880;
  --rule:   #dcd8ce;
  --track:  #e5e1d7;
  --wash:   #e9e5db;
  --alert:  #c0492f;
  --positive:#2f6b4a;
  --tick:   #c9c5bb;

  --sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --pad: 22px;                 /* screen horizontal padding */
}

* { box-sizing: border-box; }

/* Must precede every rule that sets `display` on a [hidden]-toggled element:
   the UA's [hidden]{display:none} loses to any ID selector, which once left the
   login form covering the whole app after a successful sign-in. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) 0 0 0;
}
a { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--ink-2); }

/* ── Type roles ─────────────────────────────────────────────────────────────
   `.lab` is the machine voice: every section label, unit, timestamp and count. */
.lab, .hint, .e-sub, .brand, .s-lab, .wb-lab, #nav a, .hour-pill, .hour-tot,
.f-kcal, .macro-top, .c-tick, .a-who, ul.audit time, .lvl, .sum {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
h2, h3, h4 { font-weight: 600; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 21px; line-height: 1.1; letter-spacing: -.02em; }
h3 {
  font-family: var(--mono); font-size: 10px; font-weight: 500;
  letter-spacing: .20em; text-transform: uppercase; color: var(--muted);
  margin: 26px 0 10px;
}
h4 {
  font-family: var(--mono); font-size: 9.5px; font-weight: 500;
  letter-spacing: .16em; text-transform: uppercase; color: var(--muted);
  margin: 16px 0 6px;
}
.muted, .empty { color: var(--muted); }
.empty { padding: 14px 0; font-family: var(--mono); font-size: 12px; }
.hint { font-size: 11px; color: var(--muted); line-height: 1.5; margin: 8px 0; }
.err { color: var(--alert); font-size: 12.5px; min-height: 1em; margin: 8px 0;
       font-family: var(--mono); }
.note { border-left: 2px solid var(--alert); background: var(--surface);
        padding: 10px 12px; font-size: 12.5px; margin: 12px 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── Forms ──────────────────────────────────────────────────────────────── */
label {
  display: block; margin: 14px 0 5px;
  font-family: var(--mono); font-size: 9.5px; font-weight: 500;
  letter-spacing: .16em; text-transform: uppercase; color: var(--muted);
}
label.check { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  text-transform: none; letter-spacing: 0; font-size: 12px; }
label.check input { width: auto; }
label.check .hint { flex-basis: 100%; margin: 2px 0 0; }
input, select, textarea {
  width: 100%; padding: 10px 11px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 2px;
  font-family: var(--sans); font-size: 16px;   /* 16px or iOS zooms on focus */
  font-variant-numeric: tabular-nums;
}
input[type=number] { font-family: var(--mono); }
input:focus, select:focus { outline: 2px solid var(--ink); outline-offset: -1px; }

button, a.btn {
  font-family: var(--sans); font-size: 13px; font-weight: 600; letter-spacing: .02em;
  padding: 12px 16px; border-radius: 2px; cursor: pointer;
  background: transparent; color: var(--ink); border: 1px solid var(--ink);
  text-decoration: none; text-align: center; display: inline-block;
}
button:hover, a.btn:hover { background: var(--wash); }
button:disabled { opacity: .45; cursor: default; }
button.primary, a.btn.primary, #login-btn {
  background: var(--ink); color: var(--paper); border-color: var(--ink); width: 100%;
}
button.primary:hover, #login-btn:hover { background: var(--ink-2); }
a.btn.ghost, button.ghost { font-family: var(--mono); font-weight: 500; }
button.danger { border-color: var(--alert); color: var(--alert); }
button.icon { border: 0; background: transparent; padding: 2px 8px;
  font-size: 18px; line-height: 1; color: var(--muted); }
button.icon:hover { background: transparent; color: var(--ink); }
.row { display: flex; gap: 8px; align-items: center; }
.row .unit { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.row select { flex: 1; }
.row input[type=number] { max-width: 7rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

/* ── Login ──────────────────────────────────────────────────────────────── */
#login { display: grid; place-items: center; min-height: 100vh; padding: var(--pad); }
#login-form { width: 100%; max-width: 340px; background: var(--surface);
  border: 1px solid var(--rule); padding: 24px; }
#login-form h1 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -.02em; }
.sub { margin: 4px 0 18px; color: var(--muted); font-family: var(--mono);
  font-size: 10px; letter-spacing: .16em; text-transform: uppercase; }

/* ── Shell ──────────────────────────────────────────────────────────────── */
#acting {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--alert); color: var(--paper);
  padding: 9px var(--pad); font-family: var(--mono); font-size: 11px;
  letter-spacing: .04em;
}
#acting button { background: var(--paper); color: var(--alert); border: 0;
  padding: 5px 9px; font-size: 10px; margin-left: auto; font-family: var(--mono); }

header {
  display: flex; align-items: center; gap: 10px;
  padding: 20px var(--pad) 16px;
  border-bottom: 1px solid var(--ink);
}
header strong { font-family: var(--mono); font-size: 10px; font-weight: 500;
  letter-spacing: .20em; text-transform: uppercase; color: var(--muted); }
#switch { margin-left: auto; }
#switch select { padding: 4px 6px; font-size: 11px; width: auto; max-width: 150px;
  font-family: var(--mono); border-color: var(--rule); }
#who { font-family: var(--mono); font-size: 10px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted); }
#switch:not([hidden]) + #who { display: none; }
#logout { border: 0; padding: 4px 6px; font-family: var(--mono); font-weight: 500;
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
#logout:hover { background: transparent; color: var(--ink); }

main { padding: 0 var(--pad) 96px; max-width: 720px; margin: 0 auto; }

#nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--chrome); border-top: 1px solid var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
#nav a {
  flex: 1; text-align: center; padding: 14px 2px 14px;
  font-family: var(--mono); font-size: 10px; font-weight: 500;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); text-decoration: none;
}
#nav a.on { color: var(--ink); }

/* ── Hero / ring ────────────────────────────────────────────────────────── */
.today-top { display: flex; gap: 20px; align-items: center; flex-wrap: wrap;
  padding-top: 6px; }
.ring { width: 150px; height: 150px; flex: 0 0 auto; }
.r-track { fill: none; stroke: var(--track); stroke-width: 9; }
.r-fill  { fill: none; stroke: var(--ink); stroke-width: 9; stroke-linecap: butt; }
.r-fill.over { stroke: var(--alert); }
.r-big { fill: var(--ink); font-size: 34px; font-weight: 600; letter-spacing: -.05em;
  font-family: 'IBM Plex Sans', sans-serif; }
.r-sub { fill: var(--muted); font-size: 10px; font-family: 'IBM Plex Mono', monospace; }
.macros { flex: 1; min-width: 190px; }

/* Macro cells: one bordered box, columns divided by hairlines, square corners. */
.macro { margin-bottom: 12px; }
.macro-top { display: flex; justify-content: space-between; font-size: 9.5px;
  letter-spacing: .16em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 5px; }
.macro-track { height: 3px; background: var(--track); }
.macro-fill { height: 100%; background: var(--ink); }
.macro-fill.over { background: var(--alert); }

/* ── Timeline ───────────────────────────────────────────────────────────── */
.datenav { display: flex; align-items: center; justify-content: space-between;
  padding: 18px 0 12px; }
.datenav strong { font-size: 21px; font-weight: 600; letter-spacing: -.02em; }
.weighed { font-family: var(--mono); font-size: 11px; color: var(--muted);
  margin: 12px 0 0; }

.viewbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 20px 0 6px; padding-bottom: 8px; border-bottom: 1px solid var(--rule);
  font-family: var(--mono); font-size: 11px; color: var(--muted); }
.viewbar label.check { margin: 0; font-size: 11px; }
.viewbar .range { display: flex; align-items: center; gap: 5px; margin-left: auto; }
.viewbar select { width: auto; padding: 3px 5px; font-size: 11px; font-family: var(--mono); }

.timeline { position: relative; padding-left: 16px; margin-left: 34px;
  border-left: 1px solid var(--rule); }
.hour { padding: 0 0 6px; }
.hour-head { display: flex; align-items: center; gap: 8px; padding: 8px 0 4px; }
.hour-pill {
  position: absolute; left: -34px; width: 30px; text-align: right;
  font-size: 10px; color: var(--muted); letter-spacing: .02em;
}
.hour-head { position: relative; }
.hour-add { border: 1px solid var(--rule); background: var(--surface);
  padding: 0 7px; font-size: 14px; line-height: 20px; color: var(--muted);
  font-weight: 500; }
.hour-add:hover { border-color: var(--ink); color: var(--ink); background: var(--wash); }
.hour-tot { margin-left: auto; display: flex; align-items: baseline; gap: 7px;
  font-size: 10px; color: var(--muted); }
.hour-tot b { color: var(--ink); font-weight: 500; font-size: 11px; }
.hour-tot i { font-style: normal; }
.hour-items { list-style: none; margin: 0; padding: 0; }
.hour-items li { display: grid; grid-template-columns: 1fr auto auto; gap: 12px;
  align-items: center; padding: 11px 0; border-top: 1px solid var(--rule); }
.hour-items li:last-child { border-bottom: 1px solid var(--rule); }
.e-main { min-width: 0; }
/* The whole row is a hit target for editing; keep it looking like text. */
.e-open { display: block; width: 100%; text-align: left; background: none;
  border: 0; padding: 0; font-family: var(--sans); font-size: 13.5px;
  font-weight: 500; color: var(--ink); }
.e-open:hover { background: none; text-decoration: underline; text-underline-offset: 2px; }
.e-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.e-sub { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.e-kcal { font-family: var(--mono); font-size: 13px; }
.brand { color: var(--muted); font-size: 10px; margin-left: 6px; }
.day-actions { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 26px; }
.day-actions > * { flex: 1; }

/* ── Search ─────────────────────────────────────────────────────────────── */
.searchbar { display: flex; gap: 8px; align-items: center; position: sticky;
  top: 0; background: var(--paper); padding: 14px 0 10px; z-index: 2; }
.searchbar input { flex: 1; }
.scanbtn { flex: 0 0 auto; display: grid; place-items: center; width: 44px; height: 44px;
  background: transparent; border: 1px solid var(--ink); border-radius: 2px;
  text-decoration: none; color: var(--ink); font-family: var(--mono); font-size: 13px; }
.foodlist { list-style: none; margin: 0; padding: 0; }
.foodcard { display: flex; align-items: baseline; gap: 10px; width: 100%;
  text-align: left; background: transparent; border: 0;
  border-top: 1px solid var(--rule); border-radius: 0; padding: 11px 2px;
  font-weight: 500; font-size: 13.5px; }
.foodlist li:last-child .foodcard { border-bottom: 1px solid var(--rule); }
.f-name { flex: 1; min-width: 0; }
.f-kcal { color: var(--muted); font-size: 11px; }
h3 .src { font-size: 9px; border: 1px solid var(--rule); color: var(--muted);
  padding: 1px 5px; margin-left: 8px; letter-spacing: .1em; }
.newfood { margin-top: 32px; border-top: 1px solid var(--ink); padding-top: 8px; }

/* ── Sheet ──────────────────────────────────────────────────────────────── */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(21,22,26,.35);
  display: flex; align-items: flex-end; z-index: 50; }
.sheet { width: 100%; max-height: 92vh; overflow-y: auto; background: var(--paper);
  border-top: 1px solid var(--ink); padding: 18px var(--pad) 26px;
  padding-bottom: calc(26px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; justify-content: center; }
  .sheet { max-width: 460px; border: 1px solid var(--ink); }
}
.sheet header { border: 0; padding: 0 0 10px; display: flex; align-items: flex-start; gap: 8px; }
.sheet header > div { flex: 1; }
.sheet header strong { font-family: var(--sans); font-size: 15px; font-weight: 600;
  letter-spacing: -.01em; text-transform: none; color: var(--ink); }
.prev { border-top: 1px solid var(--ink); border-bottom: 1px solid var(--rule);
  padding: 12px 0; margin-top: 18px; display: flex; align-items: baseline;
  gap: 10px; flex-wrap: wrap; }
.prev .big { font-size: 32px; font-weight: 600; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; }
.prev .m { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* ── Chart ──────────────────────────────────────────────────────────────── */
.chart { width: 100%; height: 200px; }
.c-grid { stroke: var(--rule); stroke-width: 1; }
.c-tick { fill: var(--muted); font-size: 10px; font-family: 'IBM Plex Mono', monospace; }
.c-raw  { fill: var(--tick); }
.c-line { fill: none; stroke: var(--ink); stroke-width: 1.75;
  stroke-linejoin: round; stroke-linecap: round; }
.chart-empty { color: var(--muted); padding: 28px 0; text-align: center;
  font-family: var(--mono); font-size: 12px; }
.legend { font-family: var(--mono); font-size: 10px; color: var(--muted);
  display: flex; gap: 16px; align-items: center; letter-spacing: .06em; }
.k-raw, .k-line { display: inline-block; width: 14px; margin-right: 5px; }
.k-raw { height: 4px; background: var(--tick); }
.k-line { height: 2px; background: var(--ink); }

.stat-row { display: flex; gap: 26px; margin: 10px 0 18px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; }
.s-big { font-size: 22px; font-weight: 600; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; }
.s-big.good { color: var(--positive); }
.s-big.warn { color: var(--alert); }
.s-lab { font-size: 9.5px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted); margin-top: 2px; }

/* ── Dashboard ──────────────────────────────────────────────────────────── */
.dash-actions { display: flex; gap: 9px; margin-top: 18px; flex-wrap: wrap; }
.dash-actions > * { flex: 1; white-space: nowrap; }
.weekbars { display: flex; gap: 5px; align-items: flex-end; height: 82px; margin: 6px 0 14px; }
.wb { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; }
.wb-track { position: relative; flex: 1; width: 100%; background: var(--track); }
.wb-fill { position: absolute; left: 0; right: 0; bottom: 0; background: var(--ink); }
.wb-fill.over { background: var(--alert); }
/* A day with no entries is absence, not compliance — hatch it rather than
   drawing a zero-height bar that reads as "stayed under target". */
.wb-fill.none { background: repeating-linear-gradient(45deg,
  var(--rule), var(--rule) 2px, transparent 2px, transparent 5px); }
.wb-target { position: absolute; left: 0; right: 0; height: 0;
  border-top: 1px solid var(--alert); }
.wb-lab { font-size: 9px; color: var(--muted); letter-spacing: .06em; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--rule);
  padding: 16px; margin-bottom: 14px; }
.card h3:first-child { margin-top: 0; }
.muted-card { background: transparent; border-style: dashed; }

table.kv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.kv td { padding: 9px 0; border-top: 1px solid var(--rule); }
table.kv td:first-child { font-family: var(--mono); font-size: 10px;
  letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
table.kv td:last-child { text-align: right; font-variant-numeric: tabular-nums;
  font-weight: 500; }
.explain { margin-top: 22px; border-top: 1px solid var(--rule); padding-top: 10px; }
.explain summary { cursor: pointer; font-family: var(--mono); font-size: 11px;
  letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.explain p { font-size: 12.5px; color: var(--muted); }

.target-hero { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 6px; }
.t-big { font-size: 64px; font-weight: 600; line-height: .9; letter-spacing: -.05em;
  font-variant-numeric: tabular-nums; }
.t-unit { font-family: var(--mono); font-size: 11px; color: var(--muted); }

ul.grants { list-style: none; margin: 0; padding: 0; }
ul.grants li { display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-top: 1px solid var(--rule); }
ul.grants li > span:first-child { flex: 1; }
.lvl { font-size: 9px; letter-spacing: .1em; text-transform: uppercase;
  border: 1px solid var(--rule); color: var(--muted); padding: 1px 5px; }
.lvl.act { border-color: var(--alert); color: var(--alert); }

ul.audit { list-style: none; margin: 0; padding: 0; }
ul.audit li { padding: 10px 0; border-top: 1px solid var(--rule);
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.a-who { font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--alert); }
.a-what { grid-column: 1; font-size: 13.5px; }
ul.audit time { grid-column: 2; grid-row: 1 / span 2; color: var(--muted);
  font-size: 10px; align-self: center; }

/* ── Scanner ────────────────────────────────────────────────────────────── */
.scanwrap { position: relative; background: var(--ink); overflow: hidden;
  aspect-ratio: 4 / 3; border: 1px solid var(--ink); }
.scanwrap video, #scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.reticle { position: absolute; inset: 22% 10%; border: 1px solid rgba(246,244,238,.9);
  box-shadow: 0 0 0 100vmax rgba(21,22,26,.4); }
.scan-status { text-align: center; color: var(--muted); font-family: var(--mono);
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase; margin: 12px 0; }
.scan-controls { display: flex; gap: 8px; justify-content: center; }
.scan-controls button.on { background: var(--ink); color: var(--paper); }
.scan-fallback { margin-top: 16px; border-top: 1px solid var(--rule); padding-top: 12px; }
.scan-fallback button { width: 100%; margin-top: 8px; }
#scan-video[hidden] { display: none !important; }
