/* ==========================================================================
   Larder — design system

   Written for two readers: someone at a supermarket shelf holding a packet, and
   someone at a kitchen worktop with one hand free. That drives most of it:
   large type, big targets, one obvious action per screen, and detail hidden
   until asked for.

   Rules kept throughout:
   - Every interactive thing is at least 48px tall (the accepted minimum for a
     thumb). Nothing important is a small tap target.
   - Inputs are 17px+. Under 16px, mobile browsers zoom the page on focus, which
     feels broken and scrolls the form out of view.
   - Content sits in labelled sections, so a screen reads as a few named parts
     rather than one continuous wall.
   - Colour lives only in the custom properties below, so re-theming is this
     block and nothing else.
   ========================================================================== */

:root {
  /* surfaces + ink */
  --bg: #12151a;
  --surface: #1a1f27;
  --surface-2: #232936;
  --surface-3: #2c3342;
  --line: #333c4c;
  --text: #eef2f7;
  --muted: #98a3b3;
  --faint: #6c7686;

  /* accents */
  --accent: #6ee7a8;
  --accent-ink: #06251a;
  --accent-dim: #2a5f47;
  --warn: #f2c879;
  --warn-ink: #2e2208;
  --error: #f28b8b;

  /* type scale */
  --t-display: 3rem;
  --t-figure: 2rem;
  --t-h1: 1.5rem;
  --t-h2: 1rem;
  --t-body: 1.0625rem;   /* 17px */
  --t-small: 0.875rem;
  --t-label: 0.75rem;

  /* spacing scale — everything is a multiple of 4 */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  --radius: 16px;
  --radius-sm: 10px;
  --tap: 48px;           /* minimum touch target */
  --tab-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--t-body);
  line-height: 1.45;
}

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--s4) var(--s4) calc(var(--tab-h) + var(--s6) + env(safe-area-inset-bottom));
}

a { color: var(--accent); }
b, strong { font-weight: 650; }

/* --- type ------------------------------------------------------------- */

h1 { font-size: var(--t-h1); margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h2 { font-size: var(--t-h2); margin: 0; font-weight: 650; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: var(--t-small); }
.label {
  font-size: var(--t-label); color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em;
}
.nowrap { white-space: nowrap; }

/* Vertical rhythm: a .stack spaces its children evenly so no template has to
   sprinkle one-off margins. */
.stack > * + * { margin-top: var(--s4); }
.stack--tight > * + * { margin-top: var(--s2); }

/* --- page header ------------------------------------------------------ */

.pagehead { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s4); }
.pagehead__title { flex: 1; min-width: 0; }
.pagehead__sub { color: var(--muted); font-size: var(--t-small); margin-top: 1px; }

.iconbtn {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); border-radius: 50%; border: 0;
  background: var(--surface-2); color: var(--text);
  text-decoration: none; cursor: pointer;
}
.iconbtn:active { background: var(--surface-3); }
.iconbtn--ghost { background: transparent; }

/* --- sections --------------------------------------------------------- */

.section {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.section__head {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
}
.section__head h2 { flex: 1; min-width: 0; }
.section__meta { color: var(--muted); font-size: var(--t-small);
                 font-variant-numeric: tabular-nums; }
.section__body { padding: var(--s4); }
.section__body--flush { padding: 0; }

/* A section header that's just a caption above content, not a bar inside a card */
.caption { display: flex; align-items: baseline; gap: var(--s2);
           margin: var(--s5) 0 var(--s2); }
.caption h2 { flex: 1; }

/* --- the big daily figure --------------------------------------------- */

.figure { text-align: center; padding: var(--s5) var(--s4) var(--s4); }
.figure__value {
  font-size: var(--t-display); font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
  display: block;
}
.figure__unit { color: var(--muted); font-size: var(--t-small); display: block;
                margin-top: var(--s2); }

.bar { height: 8px; border-radius: 4px; background: var(--surface-3);
       margin-top: var(--s3); overflow: hidden; }
.bar__fill { height: 100%; background: var(--accent); border-radius: 4px;
             transition: width .25s ease; }
.bar__fill--over { background: var(--warn); }

/* --- macro row -------------------------------------------------------- */

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2);
          padding: 0 var(--s4) var(--s4); }
.macro { background: var(--surface-2); border-radius: var(--radius-sm);
         padding: var(--s3) var(--s2); text-align: center; }
.macro__value { display: block; font-size: 1.25rem; font-weight: 650;
                font-variant-numeric: tabular-nums; }
.macro__name { display: block; font-size: var(--t-label); color: var(--muted);
               text-transform: uppercase; letter-spacing: .06em; margin-top: 2px; }

/* --- lists ------------------------------------------------------------ */

.list { list-style: none; margin: 0; padding: 0; }
.list__item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
  min-height: var(--tap);
}
.list__item:last-child { border-bottom: 0; }
.list__main { flex: 1; min-width: 0; }
.list__name { display: block; overflow: hidden; text-overflow: ellipsis;
              white-space: nowrap; }
.list__sub { display: block; font-size: var(--t-small); color: var(--muted); }
.list__value { font-variant-numeric: tabular-nums; text-align: right; flex: none; }
.list__value b { display: block; }

/* The text half of a row being a link, while the row keeps its own buttons —
   a diary entry opens for editing but still has its own delete. */
.list__main--link { color: var(--text); text-decoration: none; }
.list__main--link:active { opacity: .6; }

/* An amount edited in place, inside a list row (recipe ingredients). Narrow on
   purpose: it holds three digits, and a full-width field would push the row's
   buttons off the side of a phone. */
.ingredient { display: flex; align-items: center; gap: var(--s1); flex: none; }
.ingredient input[type=number] { width: 72px; min-height: 40px; padding: var(--s2);
                                 text-align: right; font-variant-numeric: tabular-nums; }
.ingredient__unit { font-size: var(--t-small); color: var(--muted); }

/* Logged on the phone, not yet sent (the offline queue). Dashed rather than a
   colour, so it reads as provisional instead of as an error. */
.pending { border: 1px dashed var(--line); border-radius: var(--radius);
           padding: var(--s3) var(--s4); margin-bottom: var(--s4); }
.pending__head { display: flex; align-items: center; gap: var(--s2);
                 color: var(--muted); font-size: var(--t-small); font-weight: 600; }
.pending__list { list-style: none; margin: var(--s2) 0 0; padding: 0;
                 font-size: var(--t-small); }
.pending__list li { display: flex; gap: var(--s2); padding: var(--s1) 0; }
.pending__list li span:first-child { flex: 1; min-width: 0; overflow: hidden;
                                     text-overflow: ellipsis; white-space: nowrap; }

/* Whole-row links (search results, quick add) */
.list__link { display: flex; align-items: center; gap: var(--s3);
              padding: var(--s3) var(--s4); min-height: var(--tap);
              text-decoration: none; color: var(--text); }
.list__link:active { background: var(--surface-2); }
.list__chevron { flex: none; color: var(--faint); }

/* --- buttons ---------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  width: 100%; min-height: var(--tap); padding: var(--s3) var(--s4);
  border: 0; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: var(--t-body); font-weight: 600;
  text-align: center; text-decoration: none;
  background: var(--surface-2); color: var(--text); cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn--go { background: var(--accent); color: var(--accent-ink); }
.btn--big { min-height: 56px; font-size: 1.125rem; }
.btn--auto { width: auto; }
.btn--quiet { background: transparent; color: var(--muted);
              border: 1px solid var(--line); }
.btn--danger { background: transparent; color: var(--error);
               border: 1px solid var(--line); }
.btnrow { display: flex; gap: var(--s2); }
.btnrow > * { flex: 1; }

/* --- forms ------------------------------------------------------------ */

.field { margin-bottom: var(--s4); }
.field:last-child { margin-bottom: 0; }
.field > label { display: block; margin-bottom: var(--s2);
                 font-size: var(--t-label); color: var(--muted); font-weight: 600;
                 text-transform: uppercase; letter-spacing: .07em; }
.field__hint { margin: var(--s2) 0 0; font-size: var(--t-small); color: var(--muted); }

input[type=text], input[type=number], input[type=password], input[type=search],
select, textarea {
  width: 100%; min-height: var(--tap); padding: var(--s3);
  font-size: var(--t-body); font-family: var(--font);
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible, .btn:focus-visible,
.chip:focus-visible, .stepper__btn:focus-visible, .seg__btn:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
/* Number inputs: hide the spinners. They're 12px tall, impossible to hit, and
   the stepper below does the job properly. */
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

/* --- stepper (the portion control) ----------------------------------- */

.stepper { display: flex; align-items: stretch; gap: var(--s2); }
.stepper__btn {
  flex: none; width: 56px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font-size: 1.5rem; font-weight: 400; line-height: 1; cursor: pointer;
}
.stepper__btn:active { background: var(--surface-3); }
.stepper__btn[disabled] { opacity: .35; cursor: default; }
.stepper__readout {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: var(--s2); min-height: 64px;
}
.stepper__value { font-size: 1.375rem; font-weight: 650; line-height: 1.1;
                  font-variant-numeric: tabular-nums; }
.stepper__note { font-size: var(--t-small); color: var(--muted); margin-top: 2px; }

/* --- segmented control ----------------------------------------------- */

.seg { display: flex; gap: 0; background: var(--surface-2);
       border: 1px solid var(--line); border-radius: var(--radius-sm);
       padding: 3px; }
.seg__btn {
  flex: 1; min-height: 40px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font-family: var(--font); font-size: var(--t-small);
  font-weight: 600; cursor: pointer;
}
.seg__btn[aria-selected="true"] { background: var(--surface-3); color: var(--text); }

/* --- chips ------------------------------------------------------------ */

.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 var(--s4);
  border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--line); color: var(--text);
  font-family: var(--font); font-size: var(--t-small); font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.chip--on { background: var(--accent); color: var(--accent-ink);
            border-color: var(--accent); }

/* --- notices ---------------------------------------------------------- */

.flashes { list-style: none; margin: 0 0 var(--s4); padding: 0; }
.notice {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4); border-radius: var(--radius-sm);
  margin-bottom: var(--s2); background: var(--surface-2);
  border-left: 3px solid var(--accent); font-size: var(--t-small);
}
.notice--error { border-left-color: var(--error); }
.notice--warn  { border-left-color: var(--warn); }
.notice--plain { border-left-color: var(--line); }
.notice__body { flex: 1; min-width: 0; }
.notice ul { margin: var(--s2) 0 0; padding-left: var(--s5); }
.notice li + li { margin-top: var(--s1); }
.notice form { flex: none; }

.empty { text-align: center; padding: var(--s6) var(--s4); color: var(--muted); }
.empty__icon { color: var(--faint); margin-bottom: var(--s3); }
.empty p { margin: 0 0 var(--s4); }

/* --- collapsible detail ---------------------------------------------- */

details.collapse { border-top: 1px solid var(--line); }
details.collapse > summary {
  display: flex; align-items: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s4);
  color: var(--muted); font-size: var(--t-small); font-weight: 600;
  cursor: pointer; list-style: none;
}
details.collapse > summary::-webkit-details-marker { display: none; }
details.collapse > summary::after { content: "⌄"; margin-left: auto; font-size: 1rem; }
details.collapse[open] > summary::after { content: "⌃"; }
.collapse__body { padding: 0 var(--s4) var(--s4); }

/* Definition-style rows for nutrient detail */
.rows { display: grid; grid-template-columns: 1fr auto; gap: var(--s2) var(--s4);
        font-size: var(--t-small); }
.rows dt { color: var(--muted); }
.rows dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* --- scanner ---------------------------------------------------------- */

.scanner { position: relative; background: #000; border-radius: var(--radius);
           overflow: hidden; aspect-ratio: 3 / 4; max-height: 58vh; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner__frame {
  position: absolute; inset: 30% 10%; border: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: 0 0 0 100vmax rgba(0,0,0,.4);
}
.scanner__status {
  position: absolute; left: 0; right: 0; bottom: 0; padding: var(--s3);
  background: rgba(0,0,0,.66); font-size: var(--t-small); text-align: center;
}

/* --- week table ------------------------------------------------------- */

.week { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.week th, .week td { padding: var(--s3) var(--s2); text-align: right; }
.week thead th { font-size: var(--t-label); color: var(--muted); font-weight: 600;
                 text-transform: uppercase; letter-spacing: .06em;
                 border-bottom: 1px solid var(--line); }
.week th.week__day, .week td.week__day { text-align: left; font-weight: 400; }
.week tbody th { font-size: var(--t-small); font-weight: 400; }
.week tbody td { border-bottom: 1px solid var(--line); }
.week tbody tr:last-child td { border-bottom: 0; }
.week tfoot th, .week tfoot td { border-top: 2px solid var(--line); font-weight: 650; }
.week__today th, .week__today td { background: var(--surface-2); }
.week__kcal { font-size: 1.0625rem; font-weight: 650; }
.week__sub { display: block; font-size: var(--t-label); color: var(--faint); }
.week__ok { color: var(--accent); }

/* --- floating action button ------------------------------------------ */

.fab {
  position: fixed; right: var(--s4);
  bottom: calc(var(--tab-h) + var(--s4) + env(safe-area-inset-bottom));
  z-index: 9;
  display: inline-flex; align-items: center; gap: var(--s2);
  height: 56px; padding: 0 var(--s5);
  border-radius: 28px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--font); font-size: var(--t-body); font-weight: 650;
  text-decoration: none; box-shadow: 0 6px 20px rgba(0,0,0,.45);
}

/* --- bottom tab bar --------------------------------------------------- */

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; min-height: var(--tab-h);
  text-decoration: none; color: var(--faint);
  font-size: var(--t-label); font-weight: 600; letter-spacing: .02em;
}
.tab svg { width: 22px; height: 22px; }
.tab--on { color: var(--accent); }
.tab__label { max-width: 100%; overflow: hidden; text-overflow: ellipsis;
              white-space: nowrap; }

code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px;
       font-size: .9em; }

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