/* Tokens match liftlog's design language deliberately — same user, same phone,
   same visual grammar. Inter for all UI text; JetBrains Mono for numbers only. */
:root {
  --bg:      #FAFAFA;
  --surface: #FFFFFF;
  --card:    #F5F5F7;
  --border:  #E5E5EA;
  --text:    #1C1C1E;
  --muted:   #8E8E93;

  --blue:    #4C7FF0;
  --teal:    #2FA89C;
  --green:   #34C759;
  --indigo:  #6C63FF;
  --amber:   #FF9F0A;
  --red:     #FF3B30;

  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px 120px;
}

h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; }
a { color: inherit; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sp-top { margin-top: 24px; }

.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

/* ── day navigation ─────────────────────────────────────────────── */

.daynav { display: flex; align-items: center; gap: 8px; }
.daynav-title { flex: 1; text-align: center; }
.daynav-title p { font-size: 12px; }
.daynav-arrow {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.daynav-arrow svg { width: 20px; height: 20px; }
.daynav-arrow.is-disabled { opacity: 0.35; pointer-events: none; }

/* ── progress rings ─────────────────────────────────────────────── */

.rings {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.ring {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 12px 14px;
  text-align: center;
  --state: var(--muted);
}
.ring-dial { display: block; margin: 0 auto 6px; }
.ring-track { fill: none; stroke: var(--card); }
/* butt caps, not round: at 12% of a target a rounded cap adds a visible arc of
   progress that was not earned. */
.ring-arc { fill: none; stroke: var(--state); stroke-linecap: butt; }
.ring-value {
  font-size: 17px; font-weight: 700; letter-spacing: -0.02em; fill: var(--text);
}
.ring-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.ring-target { font-size: 11px; margin-top: 3px; }

/* State, not nutrient, drives colour: 'over' is bad for sodium and fine for
   protein, so the direction logic lives in nutrition.target_progress and the
   CSS only renders the verdict. */
.ring-on    { --state: var(--green); }
.ring-under { --state: var(--blue); }
.ring-over  { --state: var(--amber); }
.ring-none  { --state: var(--border); }

/* ── totals table ───────────────────────────────────────────────── */

.totals { width: 100%; border-collapse: collapse; }
.totals th {
  text-align: left; font-weight: 500; font-size: 14px; padding: 6px 0;
}
.totals td { text-align: right; padding: 6px 0; font-size: 14px; }
.totals td:first-of-type { font-weight: 600; }
.totals-target { width: 72px; font-size: 12px; }
.totals-state { width: 56px; }
.totals-note { font-size: 12px; margin-top: 10px; line-height: 1.4; }

.pill {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pill-on    { background: rgba(52,199,89,0.14);  color: #1E8E3E; }
.pill-under { background: rgba(76,127,240,0.14); color: #3B63C0; }
.pill-over  { background: rgba(255,159,10,0.16); color: #B26A00; }
.pill-count { background: var(--card); color: var(--muted); }

/* ── trends & charts ────────────────────────────────────────────── */

/* Geometry is liftlog's (app/charts.py): thin indigo line, no data fill, mono
   muted axis labels. What is new here is what MacroLog has to be able to say —
   a dashed stretch is days you did not log, a hollow dot is a day whose total
   is a floor because something in it never declared this nutrient. */
.chart-card { padding-bottom: 12px; }
.chart { display: block; margin-top: 10px; overflow: visible; }
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-line {
  stroke: var(--indigo); stroke-width: 2; fill: none;
  stroke-linecap: round; stroke-linejoin: round;
}
.chart-gap { stroke: var(--muted); stroke-dasharray: 3 4; stroke-width: 1.5; opacity: 0.7; }
/* Over a long range the daily line becomes context and the rolling average
   becomes the subject. Same colour, different weight — this is one series
   looked at two ways, not two series. */
.chart-faint { stroke-width: 1; opacity: 0.35; }
.chart-smooth {
  stroke: var(--indigo); stroke-width: 2.5; fill: none;
  stroke-linecap: round; stroke-linejoin: round;
}
.chart-dot { fill: var(--indigo); }
.chart-dot-partial { fill: var(--surface); stroke: var(--indigo); stroke-width: 1.5; }
.chart-target { stroke: var(--teal); stroke-width: 1; stroke-dasharray: 5 4; }
/* The acceptable region for a banded target. Faint on purpose — it is a
   reference, not data — but it has to survive being 10px tall on a phone. */
.chart-band { fill: var(--teal); opacity: 0.14; }
.chart-label { fill: var(--muted); font-family: var(--font-mono); font-size: 11px; }

.trend-summary { display: flex; gap: 28px; }
.trend-figure { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.trend-caption { font-size: 12px; font-weight: 600; color: var(--muted); }
.trend-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.trend-avg { font-size: 17px; font-weight: 700; }
.trend-avg span { font-size: 12px; font-weight: 500; }
.trend-sub { font-size: 12px; margin-top: 2px; }
.trend-stats {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 8px; font-size: 11px;
}
.trend-note { font-size: 12px; line-height: 1.4; margin-top: 8px; }

/* ── meals & entries ────────────────────────────────────────────── */

.meal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.meal-right { display: flex; align-items: center; gap: 10px; font-size: 12px; }

.entries { list-style: none; }
.entry {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
}
.entry-main { flex: 1; min-width: 0; text-decoration: none; display: block; }
.entry-name { display: block; font-weight: 500; }
.entry-portion { display: block; font-size: 12px; }
.entry-kcal { font-weight: 600; font-size: 15px; }
.entry-del button {
  border: 0; background: none; color: var(--muted);
  width: 28px; height: 28px; display: grid; place-items: center; cursor: pointer;
}
.entry-del svg { width: 15px; height: 15px; }
.entry-del button:hover { color: var(--red); }
.meal-empty { font-size: 13px; padding: 4px 2px; }
.empty-hint { text-align: center; font-size: 14px; }

/* ── forms ──────────────────────────────────────────────────────── */

.screen-head { margin-bottom: 16px; }
.screen-head h1 { margin-top: 6px; }
.back {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; color: var(--muted); text-decoration: none;
}
.back svg { width: 16px; height: 16px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label, .fieldset label {
  display: block; font-size: 13px; font-weight: 600; color: var(--muted);
}

input[type="text"], input[type="search"], input[type="number"],
input[type="password"], select {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-family: var(--font-ui);
  font-size: 16px; /* 16px stops iOS Safari zooming the viewport on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
input[type="number"] { font-family: var(--font-mono); }
input:focus, select:focus { outline: 2px solid var(--indigo); outline-offset: -1px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qty-row { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; }
.fieldset { border: 0; }
.fieldset legend { margin-bottom: 6px; }
.checkline {
  display: flex !important; align-items: center; gap: 8px;
  color: var(--text) !important; font-weight: 500 !important;
}
.checkline input { width: auto; margin: 0; }

button { font-family: var(--font-ui); }
.btn-primary, .btn-secondary, .btn-danger {
  border: 1px solid transparent; border-radius: 10px;
  padding: 12px 16px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--indigo); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--surface); border-color: var(--border); color: var(--red); }
.btn-mini {
  display: inline-block; padding: 4px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 12px; font-weight: 600; text-decoration: none; color: var(--text);
  cursor: pointer;
}
.row-actions { display: flex; gap: 10px; }
.row-actions form, .row-actions > .btn-link { flex: 1; }
.row-actions button { width: 100%; }

.search { display: flex; gap: 8px; margin-top: 12px; }
.search input { flex: 1; margin-top: 0; }
.search button {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: 0 14px; font-weight: 600; cursor: pointer;
}

.meal-picker { display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; color: var(--muted); text-decoration: none;
}
.chip.is-on { background: var(--indigo); border-color: var(--indigo); color: #fff; }

.results-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}

.food-list { list-style: none; margin-top: 8px; }
.food-list li {
  border-bottom: 1px solid var(--border);
}
.food-list a {
  display: block; padding: 12px 2px; text-decoration: none;
}
.food-name { font-weight: 500; }
.food-basis { display: block; font-size: 11px; }
.food-row { display: flex; align-items: center; gap: 10px; }
.food-row a { flex: 1; }

.disclose {
  margin-top: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
}
.disclose summary { font-weight: 600; cursor: pointer; }
.disclose-hint { font-size: 13px; margin: 8px 0 12px; }
.disclose .stack { margin-top: 12px; }

/* Fixed layout so the direction column keeps enough room for its longest
   option; left to auto, the browser starves it and clips "ceiling". */
.settings-table {
  width: 100%; border-collapse: collapse; margin-top: 8px; table-layout: fixed;
}
.settings-table col.c-nutrient  { width: 22%; }
.settings-table col.c-target    { width: 26%; }
.settings-table col.c-direction { width: 28%; }
.settings-table col.c-tick      { width: 12%; }
/* The two tick headers are the tightest text on the screen — drop the tracking
   so "TRACK" and "RING" do not run into each other. */
.settings-table thead th:nth-child(n+4) { letter-spacing: 0; text-align: center; }
.settings-table th { text-align: left; font-size: 13px; font-weight: 600; padding: 8px 6px 8px 0; }
.settings-table thead th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.settings-table td { padding: 6px 3px; }
.settings-table input[type="number"], .settings-table select {
  margin-top: 0; padding: 8px 6px; font-size: 15px;
}
/* The native select chevron eats ~18px; without this, "ceiling" clips. */
.settings-table select { padding-right: 20px; }
.settings-table .tick { text-align: center; }
.settings-table .tick input { width: auto; }

/* ── scanner ────────────────────────────────────────────────────── */

.scanner-stage {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #111114;
  aspect-ratio: 4 / 3;
}
.scanner-stage video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
/* A guide, not a crop: the decoders read the whole frame, and boxing the user
   into a narrow window makes a barcode harder to land, not easier. */
.scanner-reticle {
  position: absolute; inset: 22% 10%;
  border: 2px solid rgba(255,255,255,0.85);
  border-radius: 10px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,0.28);
}
.scanner-status {
  margin-top: 12px; font-size: 14px; text-align: center; min-height: 2.6em;
}
/* The iOS permission note. Folded away by default because it is a one-time
   setting, opened by the scanner itself the moment the camera is refused. */
.camera-note p { font-size: 13px; line-height: 1.5; margin-top: 8px; }
.camera-note em { font-style: normal; font-weight: 600; }

/* ── AI review ──────────────────────────────────────────────────── */

.review-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.review-head { display: flex; align-items: center; gap: 10px; }
.review-head .checkline { flex: 1; min-width: 0; }
.review-name {
  margin-top: 0; font-weight: 600; font-size: 15px !important;
  border-color: transparent; background: transparent; padding: 4px 6px;
}
.review-name:hover { border-color: var(--border); background: var(--surface); }
.review-portion { font-size: 12px; margin-top: 4px; }
/* The amount sits on its own line with the unit beside it, so the box is a
   thumb-sized target rather than a number squeezed into a sentence. */
.review-amount { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.review-amount input {
  width: 6.5em; margin-top: 0; padding: 8px 10px; font-size: 16px;
}
.review-unit { font-size: 13px; font-weight: 500; }
.review-grams { font-size: 12px; margin-left: auto; }
.review-assumption {
  margin-top: 8px; padding: 8px 10px; font-size: 12.5px; line-height: 1.45;
  background: var(--card); border-radius: 8px; color: #6B6B70;
}
.review-nutrients { margin-top: 12px; }
.review-nutrients label { font-size: 12px; }
.review-nutrients input { font-size: 15px; padding: 8px 10px; }

/* ── copy a food or a meal ──────────────────────────────────────── */

.copy-list { list-style: none; margin-top: 14px; }
.copy-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
}
.copy-pick { min-width: 0; }
.copy-name { font-weight: 500; overflow-wrap: anywhere; }
.copy-amount { display: flex; align-items: center; gap: 6px; }
.copy-amount input { width: 5.5em; margin-top: 0; padding: 8px 10px; }
.copy-unit { font-size: 13px; }
/* Spans both columns: what was logged originally, under both controls. */
.copy-was { grid-column: 1 / -1; font-size: 11.5px; }

.pill-conf-high   { background: rgba(52,199,89,0.14);  color: #1E8E3E; }
.pill-conf-medium { background: rgba(255,159,10,0.16); color: #B26A00; }
.pill-conf-low    { background: rgba(255,59,48,0.10);  color: #B3261E; }

textarea {
  width: 100%; margin-top: 4px; padding: 10px 12px;
  font-family: var(--font-ui); font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; resize: vertical;
}
textarea:focus { outline: 2px solid var(--indigo); outline-offset: -1px; }

input[type="file"] {
  width: 100%; font-size: 14px; padding: 10px 0;
}

.btn-link { display: block; text-align: center; text-decoration: none; }
.sp-scan { margin-top: 10px; }

.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;
}

.preview { border-top: 1px solid var(--border); padding-top: 12px; }
.preview-basis { font-size: 12px; margin-top: 6px; }

.error-banner, .ok-banner, .warn {
  border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 12px;
}
.error-banner { background: rgba(255,59,48,0.10); color: #B3261E; }
.ok-banner { background: rgba(52,199,89,0.12); color: #1E8E3E; }
.warn { background: rgba(255,159,10,0.14); color: #8A4B00; }

.login { max-width: 320px; margin: 18vh auto 0; }
.login h1 { text-align: center; margin-bottom: 20px; }

/* ── tab bar ────────────────────────────────────────────────────── */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.tabbar-inner {
  max-width: 560px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 7px; text-decoration: none; color: var(--muted);
  font-size: 10px; font-weight: 600; letter-spacing: 0.02em;
}
.tab svg { width: 22px; height: 22px; }
.tab.is-active { color: var(--indigo); }
