/* ============================================================================
   Cut Log — design system

   Built on the Apple HIG foundations:
   · Color      — semantic tokens (label/fill/background/separator) with light,
                  dark and increased-contrast variants. Never a raw hex in a
                  component rule.
   · Typography — the SF text styles, sized in rem off a Dynamic Type root so
                  the user's text-size setting scales the whole interface.
   · Materials  — Liquid Glass for the control layer only (nav bar, tab bar).
                  The content layer uses opaque grouped backgrounds.
   · Layout     — inset grouped lists, safe areas, 44pt minimum hit targets,
                  content that extends under the floating control layer.
   ============================================================================ */

/* ----------------------------------------------------------------------------
   1. Color — semantic tokens
   Values mirror the documented system colors. The HIG says not to hard-code
   these in a native app because the APIs supply them; on the web there is no
   API, so they are defined here once and every component reads the semantic
   name, never the literal.
   ---------------------------------------------------------------------------- */
:root {
  color-scheme: light dark;

  /* Content — labels */
  --label:            #000000;
  --label-secondary:  rgba(60, 60, 67, 0.76);
  --label-tertiary:   rgba(60, 60, 67, 0.52);
  --label-quaternary: rgba(60, 60, 67, 0.18);

  /* Backgrounds — grouped hierarchy */
  --bg-grouped:            #f2f2f7;
  --bg-grouped-secondary:  #ffffff;
  --bg-grouped-tertiary:   #f2f2f7;
  --bg-base:               #ffffff;
  --bg-elevated:           #ffffff;

  /* Fills — for shapes behind content */
  --fill:            rgba(120, 120, 128, 0.20);
  --fill-secondary:  rgba(120, 120, 128, 0.16);
  --fill-tertiary:   rgba(118, 118, 128, 0.12);
  --fill-quaternary: rgba(116, 116, 128, 0.08);

  /* Separators */
  --separator:        rgba(60, 60, 67, 0.29);
  --separator-opaque: #c6c6c8;

  /* System colors */
  --green:  #34c759;
  --red:    #ff3b30;
  --orange: #ff9500;
  --indigo: #5856d6;
  --gray:   #8e8e93;

  /* Roles. Colour is never the only signal — every use is paired with a
     glyph, a sign character, or a text label.
     Each role has two values: the saturated one for fills and graphics, and a
     `-text` variant for labels and glyphs. systemGreen on a light background
     is only about 1.9:1 as text, so tinted text uses the darker variant while
     bars, dots and the chart line keep the vivid colour. */
  --accent:      var(--green);
  --accent-text: #1e7a33;
  --accent-tint: rgba(52, 199, 89, 0.14);
  --on-accent:   #000000;          /* label on a filled accent control */

  --negative:      var(--red);
  --negative-text: #d70015;
  --negative-tint: rgba(255, 59, 48, 0.12);

  --caution:      var(--orange);
  --caution-text: #a04100;
  --caution-tint: rgba(255, 149, 0, 0.14);

  --intelligence:      var(--indigo);
  --intelligence-text: #3634a3;
  --intelligence-tint: rgba(88, 86, 214, 0.12);

  /* Liquid Glass — control layer only */
  --glass-bg:     rgba(249, 249, 249, 0.72);
  --glass-blur:   saturate(180%) blur(20px);
  --glass-border: rgba(60, 60, 67, 0.16);

  /* Geometry. Corner radii are concentric: an inner radius equals the outer
     radius minus the padding between them. */
  --radius-card: 10px;
  --radius-control: 10px;
  --radius-continuous: 22px;
  --hit-target: 44px;

  /* Layout metrics */
  --margin: 16px;
  --gutter: 20px;
  --nav-h: 44px;
  --tabbar-h: 49px;
  --readable: 42rem;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --label:            #ffffff;
    --label-secondary:  rgba(235, 235, 245, 0.72);
    --label-tertiary:   rgba(235, 235, 245, 0.50);
    --label-quaternary: rgba(235, 235, 245, 0.18);

    --bg-grouped:           #000000;
    --bg-grouped-secondary: #1c1c1e;
    --bg-grouped-tertiary:  #2c2c2e;
    --bg-base:              #000000;
    --bg-elevated:          #1c1c1e;

    --fill:            rgba(120, 120, 128, 0.36);
    --fill-secondary:  rgba(120, 120, 128, 0.32);
    --fill-tertiary:   rgba(118, 118, 128, 0.24);
    --fill-quaternary: rgba(118, 118, 128, 0.18);

    --separator:        rgba(84, 84, 88, 0.60);
    --separator-opaque: #38383a;

    --green:  #30d158;
    --red:    #ff453a;
    --orange: #ff9f0a;
    --indigo: #5e5ce6;
    --gray:   #8e8e93;

    /* On a dark background the vivid system colours already carry enough
       contrast as text, so the text variants track them. */
    --accent-text:       #30d158;
    --negative-text:     #ff6961;
    --caution-text:      #ffb340;
    --intelligence-text: #8b88ff;

    --accent-tint:       rgba(48, 209, 88, 0.18);
    --negative-tint:     rgba(255, 69, 58, 0.18);
    --caution-tint:      rgba(255, 159, 10, 0.18);
    --intelligence-tint: rgba(94, 92, 230, 0.22);

    --glass-bg:     rgba(28, 28, 30, 0.72);
    --glass-border: rgba(84, 84, 88, 0.40);
  }
}

/* Increased contrast — the HIG asks for a variant with markedly more
   differentiation, not a slightly darker one. */
@media (prefers-contrast: more) {
  :root {
    --label-secondary:  rgba(60, 60, 67, 0.82);
    --label-tertiary:   rgba(60, 60, 67, 0.58);
    --separator:        rgba(60, 60, 67, 0.65);
    --separator-opaque: #8e8e93;
    --accent: #248a3d;
    --accent-text: #1a6b2e;
    --negative: #d70015;
    --negative-text: #a80010;
    --caution: #b25000;
    --caution-text: #8a3800;
    --intelligence: #3634a3;
    --intelligence-text: #2b2980;
    --glass-border: rgba(60, 60, 67, 0.45);
  }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root {
    --label-secondary:  rgba(235, 235, 245, 0.85);
    --label-tertiary:   rgba(235, 235, 245, 0.62);
    --separator:        rgba(235, 235, 245, 0.45);
    --separator-opaque: #545458;
    --accent: #30db5b;
    --accent-text: #4ce570;
    --negative: #ff6961;
    --negative-text: #ff8f88;
    --caution: #ffb340;
    --caution-text: #ffc973;
    --intelligence: #7d7aff;
    --intelligence-text: #a3a1ff;
  }
}

/* Reduced transparency — materials become opaque rather than blurred. */
@media (prefers-reduced-transparency: reduce) {
  :root { --glass-bg: var(--bg-base); --glass-blur: none; }
}
@media (prefers-reduced-transparency: reduce) and (prefers-color-scheme: dark) {
  :root { --glass-bg: #1c1c1e; }
}

/* ----------------------------------------------------------------------------
   2. Typography — the SF text styles

   The root carries the Dynamic Type body size, so every rem below scales with
   the reader's text-size setting. 1rem == Body (17pt at the default size).
   Only Regular/Medium/Semibold/Bold are used; the HIG warns off the lighter
   weights because they lose legibility at small sizes.
   ---------------------------------------------------------------------------- */
:root {
  font-size: 17px;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-rounded: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, var(--font-sans);
}

/* WebKit exposes the live Dynamic Type body metric. Where it exists, the whole
   interface follows the reader's chosen text size. */
@supports (font: -apple-system-body) {
  :root { font: -apple-system-body; }
}

/* Text styles: size / line-height / weight / tracking.
   Tracking tightens as size grows, which is how SF is optically drawn. */
.t-large-title { font-size: 2.000rem;  line-height: 1.206; font-weight: 700; letter-spacing: -0.024em; }
.t-title-1     { font-size: 1.647rem;  line-height: 1.214; font-weight: 700; letter-spacing: -0.022em; }
.t-title-2     { font-size: 1.294rem;  line-height: 1.273; font-weight: 700; letter-spacing: -0.019em; }
.t-title-3     { font-size: 1.176rem;  line-height: 1.250; font-weight: 600; letter-spacing: -0.015em; }
.t-headline    { font-size: 1.000rem;  line-height: 1.294; font-weight: 600; letter-spacing: -0.025em; }
.t-body        { font-size: 1.000rem;  line-height: 1.294; font-weight: 400; letter-spacing: -0.025em; }
.t-callout     { font-size: 0.941rem;  line-height: 1.313; font-weight: 400; letter-spacing: -0.019em; }
.t-subhead     { font-size: 0.882rem;  line-height: 1.333; font-weight: 400; letter-spacing: -0.015em; }
.t-footnote    { font-size: 0.765rem;  line-height: 1.385; font-weight: 400; letter-spacing: -0.006em; }
.t-caption-1   { font-size: 0.706rem;  line-height: 1.333; font-weight: 400; letter-spacing: 0; }
.t-caption-2   { font-size: 0.647rem;  line-height: 1.182; font-weight: 400; letter-spacing: 0.006em; }

/* ----------------------------------------------------------------------------
   3. Base
   ---------------------------------------------------------------------------- */
* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg-grouped);
  /* Clipping lives on the root, not on body: `overflow` on body promotes it
     to its own scroll container, which breaks position:sticky and stops
     window scroll events from firing. */
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg-grouped);
  color: var(--label);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.294;
  letter-spacing: -0.025em;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }

/* Numerals in data positions must not jitter as values change. */
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
[hidden] { display: none !important; }

::selection { background: var(--accent-tint); }

/* ----------------------------------------------------------------------------
   4. Shell
   ---------------------------------------------------------------------------- */
.app { display: flex; flex-direction: column; min-height: 100dvh; }

/* --- Nav bar: Liquid Glass, floats above content --- */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--nav-h) + var(--sat));
  padding: var(--sat) calc(var(--margin) + var(--sar)) 0 calc(var(--margin) + var(--sal));
  background: transparent;
  border-bottom: 0.5px solid transparent;
  transition: background .25s ease, border-color .25s ease;
}
/* Scroll edge effect: the material and its hairline appear only once content
   has travelled underneath. At rest the bar is invisible. */
.header.is-scrolled {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom-color: var(--separator);
}
.nav-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .2s ease, transform .2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header.is-scrolled .nav-title { opacity: 1; transform: none; }

/* --- Content --- */
.content {
  flex: 1;
  width: 100%;
  padding: 0 calc(var(--margin) + var(--sar))
           calc(var(--tabbar-h) + var(--sab) + 28px) calc(var(--margin) + var(--sal));
}
.view {
  max-width: var(--readable);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--gutter);
  padding-top: 4px;
}
.view[hidden] { display: none; }

/* Large title, collapsing into the nav bar as it scrolls away. */
.title-block { padding: 4px 0 2px; }
.large-title { color: var(--label); }
.title-sub { color: var(--label-secondary); margin-top: 3px; }

/* --- Tab bar: Liquid Glass --- */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--sab));
  padding-bottom: var(--sab);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 0.5px solid var(--separator);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--hit-target);
  padding: 0;
  border: 0;
  background: none;
  /* Unselected items dim the full label colour rather than using the
     secondary token: the tab bar's translucent material lifts the effective
     background, and plain secondary drops under 4.5:1 against it. */
  color: var(--label);
  opacity: 0.68;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s ease, opacity .15s ease;
}
.tab-label { font-size: 0.588rem; line-height: 1.2; font-weight: 500; letter-spacing: 0;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--accent-text); opacity: 1; }
.tab[aria-selected="true"] .tab-label { font-weight: 600; }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; border-radius: 8px; }

/* --- Sidebar: regular-width layouts --- */
.sidebar { display: none; }

@media (min-width: 900px) {
  .app { flex-direction: row; }
  .header { display: none; }
  .tabbar { display: none; }

  .sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 260px;
    flex: 0 0 260px;
    height: 100dvh;
    padding: 22px 12px calc(16px + var(--sab));
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-right: 0.5px solid var(--separator);
  }
  .sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 0 10px; margin-bottom: 20px; color: var(--label);
  }
  .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: var(--hit-target);
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-control);
    background: none;
    color: var(--label);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background .15s ease;
  }
  .nav-item > svg { color: var(--label-secondary); flex: 0 0 auto; }
  .nav-item:hover { background: var(--fill-quaternary); }
  .nav-item[aria-selected="true"] { background: var(--fill-tertiary); }
  .nav-item[aria-selected="true"],
  .nav-item[aria-selected="true"] > svg { color: var(--accent-text); }
  .nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .nav-spacer { flex: 1; }

  .content { padding: 28px var(--gutter) 56px; }
  .view { max-width: 56rem; padding-top: 0; }

  .view-today {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
    gap: var(--gutter);
  }
  .view-today > .span-2 { grid-column: 1 / -1; }
  .view-today > .col-1  { grid-column: 1; }
  .view-today > .col-2  { grid-column: 2; }
}

/* ----------------------------------------------------------------------------
   5. Inset grouped lists — the standard iOS structure for data
   ---------------------------------------------------------------------------- */
.group { display: flex; flex-direction: column; gap: 7px; }

/* Sentence case, not all-caps: current iOS grouped headers read as Footnote
   in secondary label, which stays legible at accessibility text sizes. */
.group-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 var(--margin);
  color: var(--label-secondary);
}
.group-header > span:last-child:not(:only-child):not(.ai-badge) { color: var(--label-secondary); }
.group-footer {
  padding: 0 var(--margin);
  color: var(--label-secondary);
}

.card {
  background: var(--bg-grouped-secondary);
  border-radius: var(--radius-continuous);
  overflow: hidden;
}
.card-pad { padding: var(--margin); }

/* Rows separated by inset hairlines, as in a grouped table view. */
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--hit-target);
  padding: 11px var(--margin);
  position: relative;
}
.row + .row::before {
  content: '';
  position: absolute;
  top: 0; left: var(--margin); right: 0;
  border-top: 0.5px solid var(--separator);
}
.row-main { flex: 1; min-width: 0; }
.row-title { color: var(--label); display: block; }
.row-sub { color: var(--label-secondary); display: block; margin-top: 1px; }
.row-value { color: var(--label-secondary); white-space: nowrap; flex: 0 0 auto; }
.row-value strong { color: var(--label); font-weight: 600; }

/* Tappable rows carry a chevron and a press state. */
button.row {
  width: 100%;
  border: 0;
  background: var(--bg-grouped-secondary);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  color: inherit;
  transition: background .12s ease;
}
button.row:active { background: var(--fill-quaternary); }
button.row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.chevron { color: var(--label-tertiary); flex: 0 0 auto; }

/* ----------------------------------------------------------------------------
   6. Controls
   ---------------------------------------------------------------------------- */
button {
  font-family: inherit;
  font-size: 1rem;
  letter-spacing: -0.025em;
  color: var(--accent-text);
  background: none;
  border: 0;
  border-radius: var(--radius-control);
  cursor: pointer;
  transition: opacity .12s ease, background .12s ease;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .4; cursor: not-allowed; }
button:active:not(:disabled) { opacity: .65; }

.btn-filled {
  min-height: var(--hit-target);
  padding: 0 20px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  white-space: nowrap;
}

.btn-tinted {
  min-height: var(--hit-target);
  padding: 0 18px;
  background: var(--fill-tertiary);
  color: var(--accent-text);
  font-weight: 600;
}
.btn-tinted.is-ai { background: var(--intelligence-tint); color: var(--intelligence-text); }

.btn-plain { min-height: var(--hit-target); padding: 0 6px; font-weight: 400; }
.btn-destructive { color: var(--negative-text); }
.btn-block { width: 100%; justify-content: center; display: inline-flex; align-items: center; gap: 7px; }

.btn-icon {
  display: grid;
  place-items: center;
  width: var(--hit-target);
  height: var(--hit-target);
  margin: 0 -10px;               /* optical alignment to the layout margin */
  color: var(--accent-text);
  flex: 0 0 auto;
}
/* Reads as a compact control but keeps a full 44pt hit target: the pseudo
   element extends the touchable area without changing the visual size. */
.btn-small {
  position: relative;
  min-height: 32px;
  padding: 0 12px;
  font-size: 0.882rem;
  font-weight: 600;
}
.btn-small::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: var(--hit-target);
  transform: translateY(-50%);
}

input[type="number"], input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  min-height: var(--hit-target);
  padding: 11px 14px;
  background: var(--fill-quaternary);
  border: 0.5px solid transparent;
  border-radius: var(--radius-control);
  color: var(--label);
  font-family: inherit;
  font-size: 1rem;               /* never below 1rem: smaller triggers iOS zoom */
  letter-spacing: -0.025em;
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
input::placeholder, textarea::placeholder { color: var(--label-tertiary); }
input[type="number"] {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
select { appearance: none; cursor: pointer; padding-right: 34px; }
textarea { resize: vertical; min-height: 76px; line-height: 1.4; }

.field-row { display: flex; gap: 10px; align-items: stretch; }
.field-row > input, .field-row > textarea { flex: 1; min-width: 0; }

.form-note { color: var(--label-secondary); padding: 0 var(--margin); }
.form-error { color: var(--negative-text); padding: 0 var(--margin); }

/* ----------------------------------------------------------------------------
   7. Components
   ---------------------------------------------------------------------------- */

/* --- Stats --- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); }
.stat { text-align: center; min-width: 0; padding: 4px 6px; position: relative; }
.stat + .stat::before {
  content: '';
  position: absolute;
  top: 10%; bottom: 10%; left: 0;
  border-left: 0.5px solid var(--separator);
}
.stat-value {
  display: block;
  font-size: 1.647rem;
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -0.028em;
  color: var(--label);
}
.stat-unit { font-size: 0.55em; font-weight: 500; color: var(--label-secondary); margin-left: 1px; }
.stat-key { color: var(--label-secondary); margin-top: 3px; }
.stat-sub { color: var(--label-secondary); margin-top: 1px; min-height: 1.2em; }

/* --- Progress --- */
.prog-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.prog-value { font-size: 1.647rem; font-weight: 600; letter-spacing: -0.028em; }
.prog-value small { font-size: 0.55em; font-weight: 500; color: var(--label-secondary); margin-left: 3px; }
.prog-pct { color: var(--accent-text); font-weight: 600; }
.track {
  height: 8px;
  margin-top: 10px;
  background: var(--fill-tertiary);
  border-radius: 999px;
  overflow: hidden;
}
.fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .5s cubic-bezier(.4, 0, .2, 1);
}
.scale { display: flex; justify-content: space-between; color: var(--label-secondary); margin-top: 6px; }
.prog-caption { color: var(--label-secondary); margin-top: 10px; }

/* --- Inline notices --- */
.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px var(--margin);
  background: var(--caution-tint);
  color: var(--label);
}
.notice > svg { color: var(--caution-text); flex: 0 0 auto; margin-top: 1px; }
.notice strong { font-weight: 600; }
.notice.is-inset { border-radius: var(--radius-card); margin: 0 var(--margin) var(--margin); }

/* --- AI surfaces --- */
.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 6px;
  border-radius: 999px;
  background: var(--intelligence-tint);
  color: var(--intelligence-text);
  font-weight: 600;
  letter-spacing: 0;
}
.ai-headline { color: var(--label); font-weight: 600; }
.ai-text { color: var(--label); }
.ai-secondary { color: var(--label-secondary); }
.ai-list { display: flex; flex-direction: column; gap: 9px; }
.ai-list li { display: flex; gap: 9px; color: var(--label-secondary); }
.ai-list li::before {
  content: '';
  flex: 0 0 auto;
  width: 5px; height: 5px;
  margin-top: 0.55em;
  border-radius: 50%;
  background: var(--accent);
}
.ai-error { display: flex; gap: 11px; align-items: flex-start; padding: 14px var(--margin); }
.ai-error > svg { color: var(--caution-text); flex: 0 0 auto; margin-top: 1px; }
.ai-error-body { flex: 1; min-width: 0; }
.ai-error-body strong { display: block; color: var(--label); font-weight: 600; }
.ai-error-body span { color: var(--label-secondary); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--fill-tertiary);
  color: var(--label-secondary);
  font-weight: 500;
  letter-spacing: 0;
}
.pill-high { background: var(--accent-tint); color: var(--accent-text); }
.pill-medium { background: var(--caution-tint); color: var(--caution-text); }
.pill-low { background: var(--fill-tertiary); color: var(--label-secondary); }

.meta-row {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  color: var(--label-secondary);
}
.meta-spacer { flex: 1; }

/* Loading placeholders sized to the text they replace. */
.skeleton { display: flex; flex-direction: column; gap: 10px; }
.sk-line {
  height: 0.75em;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--fill-quaternary) 25%, var(--fill-tertiary) 50%, var(--fill-quaternary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.stream-text { color: var(--label); white-space: pre-wrap; }
.stream-text.is-streaming::after {
  content: '';
  display: inline-block;
  width: 0.5em; height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--accent);
  border-radius: 1px;
  animation: caret 1s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* --- Meals ---
   Every stacked label inside a row must be a block; as spans they would run
   together on one line. */
.meal-name { display: block; color: var(--label); font-weight: 400; }
.meal-meta { display: block; color: var(--label-secondary); margin-top: 1px; }
.meal-meta b { color: var(--accent-text); font-weight: 600; }

/* The meal tab stacks several groups; they need the same rhythm as .view. */
#meals, #settings-body { display: flex; flex-direction: column; gap: var(--gutter); }

.summary-note { padding: 12px var(--margin); color: var(--label-secondary); }
.summary-note b { color: var(--label); font-weight: 600; }
.summary-note .ok { color: var(--accent-text); font-weight: 600; }
.summary-note .drift { color: var(--caution-text); font-weight: 600; }

/* --- History --- */
.delta {
  display: inline-block;
  min-width: 4.2em;
  padding: 3px 9px;
  border-radius: 999px;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.delta-loss { background: var(--accent-tint); color: var(--accent-text); }
.delta-gain { background: var(--negative-tint); color: var(--negative-text); }
.delta-flat { background: var(--fill-tertiary); color: var(--label-secondary); }
.hist-weight { color: var(--label); font-weight: 600; font-variant-numeric: tabular-nums; }

.empty { text-align: center; color: var(--label-secondary); padding: 26px var(--margin); }

/* --- Chart --- */
.chart { width: 100%; height: 190px; display: block; overflow: visible; }
.c-grid { stroke: var(--separator); stroke-width: 0.5; }
.c-axis { fill: var(--label-tertiary); font-size: 10px; font-family: inherit; }
.c-goal { stroke: var(--label-tertiary); stroke-width: 1; stroke-dasharray: 3 3; }
.c-goal-label { fill: var(--label-tertiary); font-size: 9.5px; font-family: inherit; }
.c-raw { fill: none; stroke: var(--label-tertiary); stroke-width: 1.25; }
.c-trend { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.c-dot { fill: var(--label-tertiary); }
.c-dot-last { fill: var(--accent); stroke: var(--bg-grouped-secondary); stroke-width: 2; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--label-secondary); margin-top: 10px; }
.chart-legend i { display: inline-block; width: 14px; height: 2.5px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart-legend i.dash { height: 0; border-radius: 0; border-top: 2px dashed var(--label-tertiary); }

/* --- Exercises --- */
.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.filter { display: block; min-width: 0; }
.filter select {
  /* Chevron drawn inline so no network request is needed for it. */
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1.5 1.5 6 6l4.5-4.5' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

.exercise-thumb {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--fill-tertiary);
}
.exercise-glyph {
  display: grid; place-items: center;
  color: var(--label-tertiary);
}

/* Video demonstration */
.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius-continuous);
  overflow: hidden;
}
.video-frame video { width: 100%; height: 100%; object-fit: contain; display: block; }
.video-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; height: 100%; padding: var(--margin);
  background: var(--fill-quaternary); color: var(--label-secondary); text-align: center;
}
.video-empty > svg { color: var(--label-tertiary); }

/* Segmented control — angle and gender variants */
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill-tertiary);
}
.segmented button {
  min-height: 30px;
  padding: 0 14px;
  border-radius: 7px;
  font-size: 0.765rem;
  font-weight: 600;
  color: var(--label);
  background: transparent;
}
.segmented button[aria-selected="true"] {
  background: var(--bg-grouped-secondary);
  box-shadow: 0 1px 3px rgba(0,0,0,.14);
}
.video-controls {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px var(--margin);
}
.video-controls-label { color: var(--label-secondary); }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- Topics --- */
.topic-title { color: var(--label); display: block; }
.topic-blurb { color: var(--label-secondary); display: block; margin-top: 1px; }
button.row[aria-selected="true"] .topic-title { color: var(--accent-text); font-weight: 600; }

/* ----------------------------------------------------------------------------
   8. Sheets — modal presentation
   ---------------------------------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg-grouped);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 calc(var(--margin) + var(--sar)) calc(40px + var(--sab)) calc(var(--margin) + var(--sal));
  animation: sheet-in .32s cubic-bezier(.32, .72, 0, 1);
}
@keyframes sheet-in { from { transform: translateY(100%); } }

.sheet { max-width: var(--readable); margin: 0 auto; display: flex; flex-direction: column; gap: var(--gutter); }

.sheet-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  height: calc(var(--nav-h) + var(--sat));
  padding-top: var(--sat);
  margin: 0 calc(var(--margin) * -1);
  padding-left: var(--margin);
  padding-right: var(--margin);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 0.5px solid var(--separator);
}
.sheet-title { flex: 1; min-width: 0; text-align: center; color: var(--label); }
.sheet-bar .btn-plain { margin: 0 -6px; }
.sheet-bar-spacer { width: 44px; flex: 0 0 auto; }

@media (min-width: 900px) {
  .overlay {
    background: rgba(0, 0, 0, .35);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    padding: 40px 20px;
    animation: fade-in .2s ease;
  }
  @keyframes fade-in { from { opacity: 0; } }
  .sheet {
    max-width: 40rem;
    background: var(--bg-grouped);
    border-radius: var(--radius-continuous);
    padding: 0 var(--margin) var(--margin);
    overflow: hidden;
  }
  .sheet-bar { border-radius: var(--radius-continuous) var(--radius-continuous) 0 0; }
}

/* Recipe detail */
.recipe-title { color: var(--label); }
.recipe-slot { color: var(--accent-text); font-weight: 600; letter-spacing: 0; }
.recipe-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--label-secondary); }
.recipe-meta b { color: var(--label); font-weight: 600; }

.steps { counter-reset: step; display: flex; flex-direction: column; }
.steps li {
  counter-increment: step;
  display: flex;
  gap: 12px;
  padding: 12px var(--margin);
  position: relative;
  color: var(--label);
}
.steps li + li::before {
  content: '';
  position: absolute;
  top: 0; left: calc(var(--margin) + 28px + 12px); right: 0;
  border-top: 0.5px solid var(--separator);
}
.steps li::after {
  content: counter(step);
  order: -1;
  flex: 0 0 auto;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent-text);
  font-size: 0.765rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Settings */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: var(--margin); }
.settings-field label { display: block; color: var(--label-secondary); margin-bottom: 5px; }
.key-status { display: flex; align-items: center; gap: 8px; padding: 0 var(--margin) 14px; color: var(--label-secondary); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.status-on { background: var(--accent); }
.status-off { background: var(--label-tertiary); }
.button-row { display: flex; gap: 10px; padding: 0 var(--margin) var(--margin); flex-wrap: wrap; }
.button-row > button { flex: 1; min-width: 7rem; }

/* ----------------------------------------------------------------------------
   9. Toast — feedback, with undo where an action is destructive
   ---------------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--sab) + 14px);
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(30rem, calc(100vw - 2 * var(--margin)));
  padding: 11px 8px 11px 18px;
  border-radius: 999px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 0.5px solid var(--glass-border);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
  color: var(--label);
  animation: toast-in .3s cubic-bezier(.32, .72, 0, 1);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 14px); } }
.toast-text { flex: 1; min-width: 0; }
.toast-action { flex: 0 0 auto; padding: 0 14px; min-height: 32px; font-weight: 600; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* ----------------------------------------------------------------------------
   10. Motion
   ---------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
  .sk-line { background: var(--fill-tertiary); }
  .stream-text.is-streaming::after { animation: none; }
}
