/* =========================================================================
   Momentum — design system
   Dark-first, minimal, one accent. Tuned for an ADHD brain: high signal,
   low clutter, big tap targets, calm color, satisfying micro-animations.
   ========================================================================= */

/* ---- Design tokens ---- */
:root {
  /* Accent is overridden at runtime from settings (js/app.js). */
  --accent: #3ddc97;
  --accent-ink: #05130d;          /* text that sits on the accent */

  /* Dark theme (default) */
  --bg: #0b0f0e;
  --bg-elev: #151a19;
  --card: #161c1b;
  --card-2: #1d2423;
  --text: #f4f7f6;
  --text-dim: #97a3a0;
  --line: #262e2c;
  --danger: #ff6b6b;
  --good: var(--accent);
  --accent-2: oklch(0.78 0.1 235); /* quieter second accent for informational moments */

  --radius: 20px;
  --radius-sm: 14px;
  --gap: 16px;
  --tap: 46px;                    /* minimum comfortable tap target */

  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;

  /* iOS safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Light theme */
[data-theme="light"] {
  --bg: #f3f5f4;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-2: #eef1f0;
  --text: #10201b;
  --text-dim: #5d6b67;
  --line: #e2e7e5;
  --shadow: 0 8px 24px rgba(20,40,35,0.10);
}

/* ---- Reset / base ---- */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
/* .view is the only scroll container.
   The height calc is an iOS standalone-PWA workaround: iOS gives the app a layout
   box that stops short of the screen's bottom edge, floating the tab bar upward.
   Device testing showed the dead strip equals the BOTTOM safe-area inset (34pt on
   the user's iPhone — extending by the top inset, 47pt, overshot and clipped the
   bar). Everywhere else the inset is 0 → plain 100%. */
html, body { height: calc(100% + env(safe-area-inset-bottom, 0px)); overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  /* The body must NEVER scroll — .view is the only scroll container. This is what
     keeps the fixed tab bar truly fixed: short pages used to rubber-band the whole
     viewport on iOS, dragging the bar up with them. */
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, textarea, select { outline: none; }
h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; }
.muted { color: var(--text-dim); }
.center { text-align: center; }

/* ---- App layout ---- */
#app {
  /* Inherits the corrected document height (see html,body above). Don't size this
     with 100dvh/100vh or measured innerHeight — on iOS standalone they all report
     the short (screen - status bar) box, which is exactly the bug being fixed. */
  height: 100%;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) 20px 12px;
  background: linear-gradient(var(--bg), color-mix(in srgb, var(--bg) 80%, transparent));
  backdrop-filter: blur(10px);
}
.app-header__eyebrow { display: block; font-size: 12px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; }
.app-header__title { font-size: 28px; }

.icon-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  color: var(--text-dim);
  border-radius: 50%;
  transition: color .15s, background .15s;
}
.icon-btn:active { background: var(--card); color: var(--text); }

.view {
  flex: 1;
  overflow-y: auto;                   /* the ONLY scroll container in the app */
  overscroll-behavior-y: contain;     /* rubber-band stays inside, never moves the chrome */
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px 120px;      /* bottom pad clears tab bar + FAB */
  animation: viewIn .28s ease;
}
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Bottom tab bar ----
   NOT position:fixed — it's the last row of the 100dvh #app flex column, so it's
   glued to the screen bottom by construction. Fixed positioning depended on iOS
   computing the viewport edge correctly, and it floated the bar ~1cm up. */
.tab-bar {
  flex: none;
  display: flex;
  padding: 8px 8px calc(var(--safe-bottom) + 8px);
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0;
  color: var(--text-dim);
  font-size: 10px; font-weight: 600;
  transition: color .15s, transform .1s;
}
.tab svg { width: 24px; height: 24px; }
.tab:active { transform: scale(0.92); }
.tab.is-active { color: var(--accent); }

/* ---- Floating quick-capture button ---- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--safe-bottom) + 78px);
  z-index: 31;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform .12s ease;
}
.fab:active { transform: scale(0.9); }

/* ---- Cards & sections ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: var(--gap);
  border: 1px solid var(--line);   /* dark UIs separate with tone + line, not shadow */
  box-shadow: none;
}
.card--flat { box-shadow: none; border: 1px solid var(--line); }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin: 22px 4px 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack > * + * { margin-top: 10px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius-sm);
  background: var(--card-2);
  color: var(--text);
  font-weight: 600;
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--ghost { background: transparent; border: 1px solid var(--line); }
.btn--danger { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); }
.btn--full { width: 100%; }
.btn--sm { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }

/* ---- Inputs ---- */
.input, .textarea, .select {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-dim); }
.field-label { font-size: 13px; color: var(--text-dim); margin-bottom: 6px; display: block; }

/* ---- Score ring (Today hero) ---- */
.hero { text-align: center; padding: 8px 0 4px; }
.hero__day { font-size: 15px; color: var(--text-dim); }
.hero__split { color: var(--accent); font-weight: 700; }
.ring-wrap { position: relative; width: 180px; height: 180px; margin: 10px auto 4px; }
.ring { transform: rotate(-90deg); width: 100%; height: 100%; }
.ring__bg { fill: none; stroke: var(--card-2); stroke-width: 14; }
.ring__fg { fill: none; stroke: var(--accent); stroke-width: 14; stroke-linecap: round;
  transition: stroke-dashoffset 1s cubic-bezier(.22,1,.36,1); }
.ring__center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring__score { font-size: 46px; font-weight: 800; letter-spacing: -0.03em; }
.ring__label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }

/* score breakdown chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.chip { font-size: 12px; padding: 6px 10px; border-radius: 999px; background: var(--card-2); color: var(--text-dim); display: inline-flex; align-items: center; gap: 6px; }
.chip.is-hit { color: var(--accent); }
.chip__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---- Habit / task rows (tap to toggle) ---- */
.check-row {
  display: flex; align-items: center; gap: 14px;
  min-height: var(--tap);
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.check-row:last-child { border-bottom: none; }
.check-box {
  width: 26px; height: 26px; flex: none;
  border-radius: 8px;
  border: 2px solid var(--line);
  display: grid; place-items: center;
  transition: background .15s, border-color .15s, transform .12s;
}
.check-box svg { width: 16px; height: 16px; opacity: 0; transform: scale(.4); transition: opacity .15s, transform .2s cubic-bezier(.34,1.56,.64,1); color: var(--accent-ink); }
.check-row.is-done .check-box { background: var(--accent); border-color: var(--accent); }
.check-row.is-done .check-box svg { opacity: 1; transform: scale(1); }
.check-row.is-done .check-row__text { color: var(--text-dim); text-decoration: line-through; }
.check-row__text { flex: 1; }
.check-row__action { color: var(--text-dim); padding: 6px; }
.pop { animation: pop .3s ease; }
@keyframes pop { 0% { transform: scale(1);} 40% { transform: scale(1.12);} 100% { transform: scale(1);} }

/* ---- Segmented control & rating dots ---- */
.segment { display: flex; background: var(--card-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segment button { flex: 1; min-height: 38px; border-radius: 9px; color: var(--text-dim); font-weight: 600; transition: background .15s, color .15s; }
.segment button.is-active { background: var(--accent); color: var(--accent-ink); }
.segment--tier button { font-size: 12px; padding: 0 6px; }

.rating { display: flex; gap: 10px; }
.rating button {
  flex: 1; aspect-ratio: 1; max-width: 52px;
  border-radius: 12px; background: var(--card-2); color: var(--text-dim);
  font-weight: 700; font-size: 16px; transition: background .12s, color .12s, transform .1s;
}
.rating button:active { transform: scale(.92); }
.rating button.is-active { background: var(--accent); color: var(--accent-ink); }

/* ---- Sleep time inputs (Today check-in) ----
   iOS Safari gives time inputs a UA-enforced intrinsic min-width that flex can't
   shrink, which pushed "Woke up" past the screen edge on iPhone. Three defenses:
   grid minmax(0,1fr) hard-caps each column, appearance:none strips the UA sizing,
   and overflow:hidden is the last-resort clamp so nothing can ever overhang. */
.sleep-times { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.sleep-time { min-width: 0; overflow: hidden; }
.sleep-time > span { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.sleep-time .input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  padding: 12px 8px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Water counter ---- */
.counter { display: flex; align-items: center; gap: 16px; flex: none; }
.counter__btn { width: 44px; height: 44px; border-radius: 50%; background: var(--card-2); font-size: 22px; display: grid; place-items: center; flex: none; }
.counter__val { font-size: 30px; font-weight: 800; min-width: 46px; text-align: center; }
.counter__goal { color: var(--text-dim); font-size: 14px; white-space: nowrap; }  /* keep "/ 2" on one line */

/* ---- Workout ---- */
.wk-day-picker { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; }
.wk-day { flex: none; padding: 8px 12px; border-radius: 12px; background: var(--card-2); color: var(--text-dim); font-weight: 600; font-size: 13px; text-align: center; }
.wk-day small { display: block; font-size: 10px; font-weight: 500; opacity: .8; }
.wk-day.is-active { background: var(--accent); color: var(--accent-ink); }
.wk-day.is-rest { opacity: .6; }

.exercise { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; border: 1px solid var(--line); }
.exercise__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.exercise__name { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.exercise__last { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.set-row { display: grid; grid-template-columns: 22px 1fr 1fr 34px; align-items: center; gap: 8px; margin-top: 8px; }
.set-row__idx { color: var(--text-dim); font-size: 13px; text-align: center; }
.set-row input { text-align: center; padding: 8px; min-height: 40px; }
.set-row .del { color: var(--text-dim); }
.set-unit { font-size: 11px; color: var(--text-dim); text-align:center; }
.exercise__actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---- Notes / expense list ---- */
.list-item { background: var(--card); border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 10px; border: 1px solid var(--line); }
.list-item__meta { font-size: 12px; color: var(--text-dim); margin-top: 6px; display: flex; justify-content: space-between; }
.expense { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.expense__cat { font-size: 12px; color: var(--text-dim); }
.expense__amt { font-weight: 800; font-size: 17px; }

/* ---- CSV import preview ---- */
.csv-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.csv-row:last-child { border-bottom: none; }
.csv-row .csv-inc { width: 20px; height: 20px; margin-top: 4px; flex: none; accent-color: var(--accent); }
.csv-mid { flex: 1; min-width: 0; }
.csv-note { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csv-amt { font-weight: 800; white-space: nowrap; }

/* ---- Stats grid (weekly review) ---- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card-2); border-radius: var(--radius-sm); padding: 14px; }
.stat__val { font-size: 24px; font-weight: 800; }
.stat__label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ---- Charts ---- */
.chart { width: 100%; height: auto; display: block; }
.barchart { display: flex; flex-direction: column; gap: 10px; }
.barchart__row { display: grid; grid-template-columns: 84px 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.barchart__label { color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barchart__track { height: 10px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.barchart__fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .5s ease; }
.barchart__val { font-weight: 700; }

/* ---- Sheet / modal ---- */
.sheet-host { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet-host[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); animation: fade .2s ease; }
.sheet {
  position: relative; width: 100%;
  background: var(--bg-elev);
  border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(var(--safe-bottom) + 24px);
  max-height: 88vh; overflow-y: auto;
  box-shadow: 0 -10px 40px rgba(0,0,0,.4);
  animation: sheetUp .32s cubic-bezier(.22,1,.36,1);
}
.sheet__grip { width: 40px; height: 5px; border-radius: 999px; background: var(--line); margin: 8px auto 14px; }
.sheet h2 { font-size: 20px; margin-bottom: 14px; }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 96px); transform: translateX(-50%);
  z-index: 60;
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); animation: toastIn .25s ease;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---- Empty states ---- */
.empty { text-align: center; color: var(--text-dim); padding: 40px 20px; }
.empty svg { width: 40px; height: 40px; opacity: .4; margin-bottom: 10px; }

/* ---- Misc rows for settings ---- */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: none; }
.switch { width: 50px; height: 30px; border-radius: 999px; background: var(--card-2); position: relative; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch.is-on { background: var(--accent); }
.switch.is-on::after { transform: translateX(20px); }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); }
.swatch.is-active { border-color: var(--text); transform: scale(1.1); }
.swatches { display: flex; gap: 12px; }

/* ---- Brain sub-navigation: a scrollable row of pill buttons ---- */
.chip-nav { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 2px; margin: 6px 0 14px; }
.chip-nav::-webkit-scrollbar { display: none; }
.chip-nav button {
  flex: 0 0 auto; min-height: 38px; padding: 0 11px; border-radius: 999px;
  background: var(--card-2); color: var(--text-dim); font-weight: 600; font-size: 13px;
  transition: background .15s, color .15s;
}
.chip-nav button.is-active { background: var(--accent); color: var(--accent-ink); }

/* ---- The one nudge card on Today ---- */
.nudge-card { border-left: 3px solid var(--accent); position: relative; padding-right: 40px; }
.nudge-card__kicker { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin-bottom: 4px; }
.nudge-card__title { font-weight: 700; margin-bottom: 2px; }
.nudge-card__body { color: var(--text-dim); font-size: 14px; }
.nudge-card__dismiss { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 50%; color: var(--text-dim); font-size: 18px; line-height: 1; }
.nudge-card__actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---- Date stepper on Today (view/edit any past day) ---- */
.stepper { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 2px 0 6px; }
.stepper button { min-width: 40px; min-height: 34px; border-radius: 10px; color: var(--text-dim); font-size: 18px; }
.stepper button:disabled { opacity: .3; }
.stepper__label { font-size: 13px; font-weight: 600; color: var(--text-dim); min-width: 130px; text-align: center; }
.stepper__label.is-past { color: var(--accent); }

/* ---- Mood dots on feeling list items ---- */
.mood-dots { display: inline-flex; gap: 3px; vertical-align: middle; }
.mood-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--card-2); }
.mood-dots i.on { background: var(--accent); }

/* ---- Per-exercise measure toggle (Settings → Workout split) ---- */
.measure-seg { display: inline-flex; background: var(--card-2); border-radius: 9px; padding: 3px; gap: 3px; flex: none; }
.measure-seg button { min-height: 28px; padding: 0 10px; border-radius: 7px; color: var(--text-dim); font-weight: 600; font-size: 12px; }
.measure-seg button.is-active { background: var(--accent); color: var(--accent-ink); }

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---- v4 design updates ---- */
/* (segmented ring reverted — single .ring__fg arc + tap-to-expand breakdown kept) */
.ring-hint { font-size: 11px; color: var(--text-dim); }

/* Collapsed check-in summary */
.checkin-summary { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.checkin-summary__check { width: 26px; height: 26px; flex: none; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.checkin-summary__check svg { width: 15px; height: 15px; color: var(--accent-ink); }
.checkin-summary__text { flex: 1; font-size: 14px; color: var(--text-dim); }
.checkin-summary__chev { color: var(--text-dim); font-size: 17px; }

/* Emoji mood picker */
.rating--mood button { font-size: 23px; }
.rating--mood button.is-active { background: color-mix(in srgb, var(--accent) 22%, transparent); transform: scale(1.06); }

/* Workout logged pill on Today */
.wk-status { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 44px; margin: 6px 0 4px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 600; font-size: 14px; }

/* Brain home grid */
.brain-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.brain-cell { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-align: left; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-height: 104px; transition: transform .1s; }
.brain-cell:active { transform: scale(.97); }
.brain-cell--wide { grid-column: 1 / -1; min-height: 0; }
.brain-cell__label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.brain-cell__count { font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.brain-cell__hint { font-size: 12px; color: var(--text-dim); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.brain-back { display: flex; align-items: center; gap: 4px; color: var(--text-dim); font-weight: 600; font-size: 14px; padding: 10px 4px 6px; }

/* Second accent: informational cards (review, lesson) */
.nudge-card--info { border-left-color: var(--accent-2); }
.nudge-card--info .nudge-card__kicker { color: var(--accent-2); }

/* Review lede — the sentence leads, stats follow */
.review-lede { font-size: 16px; line-height: 1.55; }
