/* Design language — BUILD_SPEC §2. Fraunces (headings), Inter (body),
   IBM Plex Mono (numbers). paper #EEF1F4, ink #14171C, red #DD3B2C,
   sage #2C7A57, amber #BC7A12. Mobile-first, big tap targets. */
:root {
  --paper: #eef1f4;
  --ink: #14171c;
  --ink-soft: #3a4049;
  --red: #dd3b2c;
  --sage: #2c7a57;
  --amber: #bc7a12;
  --blue: #1666d6;
  --card: #fff;
  --line: #dce2e8;
  --line-soft: #e8ecf0;
  --muted: #697079;
  --radius: 14px;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --body: "Inter", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top);
}
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.12; }

.disclaimer {
  background: var(--ink); color: var(--paper);
  font-size: 0.72rem; line-height: 1.3; text-align: center;
  padding: 0.5rem 1rem; position: sticky; top: 0; z-index: 20;
}
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

.view { max-width: 560px; margin: 0 auto; padding: 1rem 0.9rem; }
.tab-view { padding-bottom: 5.5rem; } /* clear bottom nav */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 0.85rem;
}
.cardhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem; }
.card h3 { font-size: 1.05rem; margin-bottom: 0.5rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.grid2 .card { margin-bottom: 0; }

/* ---- Auth ---- */
.auth { max-width: 460px; }
.brand { text-align: center; margin: 1.4rem 0 0.6rem; }
.brand h1 { font-size: 2rem; }
.tabs { display: flex; gap: 0.25rem; background: var(--paper); border-radius: 12px; padding: 0.25rem; margin-bottom: 1rem; }
.tab { flex: 1; border: 0; background: transparent; padding: 0.6rem; border-radius: 10px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; }
.tab.is-active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(20,23,28,0.08); }
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.85rem; }
.field span { font-size: 0.8rem; font-weight: 500; color: var(--muted); }
.field input { font: inherit; font-size: 1rem; padding: 0.8rem 0.9rem; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); min-height: 48px; }
.field input:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
.error { color: var(--red); font-size: 0.85rem; margin-bottom: 0.75rem; }

/* ---- Buttons ---- */
.btn-primary { width: 100%; min-height: 52px; border: 0; border-radius: 12px; background: var(--ink); color: var(--paper); font: inherit; font-weight: 600; font-size: 1rem; cursor: pointer; margin-top: 0.2rem; }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; }
.btn-ghost { border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; font-weight: 500; padding: 0.6rem 0.9rem; border-radius: 10px; cursor: pointer; min-height: 44px; }
.btn-ghost.full { width: 100%; margin-top: 0.5rem; }
.btn-dashed { width: 100%; margin-top: 0.6rem; padding: 0.7rem; border: 1px dashed var(--line); border-radius: 11px; background: transparent; color: var(--muted); font: inherit; font-size: 0.85rem; cursor: pointer; }

/* ---- Topbar ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.85rem; }
.topbar h2 { font-size: 1.5rem; }
.date-input, .text-input { font: inherit; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); min-height: 44px; width: 100%; }
.text-input { margin-bottom: 0.6rem; }

/* ---- Heart hero ---- */
.hero { border-color: color-mix(in srgb, var(--red) 25%, var(--line)); }
.hero-label { color: var(--red); }
.vitals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; margin: 0.4rem 0; }
.vital { text-align: center; background: var(--paper); border-radius: 12px; padding: 0.7rem 0.3rem; }
.vital-num { display: block; font-family: var(--mono); font-size: 1.35rem; font-weight: 600; }
.vital-cap { display: block; font-size: 0.65rem; color: var(--muted); margin-top: 0.2rem; }

/* ---- Patterns tiles ---- */
.patterns { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 0.5rem; }
.ptile { text-align: center; background: var(--paper); border-radius: 10px; padding: 0.6rem 0.3rem; }
.pval { display: block; font-family: var(--mono); font-weight: 600; font-size: 1.05rem; }
.pval.good { color: var(--sage); }
.pval.warn { color: var(--amber); }
.pcap { display: block; font-size: 0.6rem; color: var(--muted); margin-top: 0.2rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---- ECG trace + rhythm tag ---- */
.ecg { width: 100%; height: 52px; margin: 0.3rem 0 0.6rem; }
.ecg path { fill: none; stroke: var(--red); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ecg .lead { stroke-dasharray: 1400; stroke-dashoffset: 1400; animation: ecgtrace 4.5s linear infinite; }
@keyframes ecgtrace { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .ecg .lead { animation: none; stroke-dashoffset: 0; } }
.rhythm-tag { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 30%, var(--line)); border-radius: 999px; padding: 2px 8px; }
.rhythm-tag.ok { color: var(--sage); border-color: color-mix(in srgb, var(--sage) 30%, var(--line)); }
.vbadge { display: block; margin-top: 3px; font-family: var(--mono); font-size: 0.55rem; letter-spacing: 0.04em; text-transform: uppercase; padding: 1px 5px; border-radius: 999px; }
.vbadge.warn { background: #f3eee3; color: var(--amber); }
.vbadge.flag { background: #fceeec; color: var(--red); }

/* ---- Numbers / totals ---- */
.cal-line { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.7rem; }
.big-num { font-family: var(--mono); font-weight: 600; font-size: 2rem; letter-spacing: -0.02em; }
.chip-static { font-family: var(--mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--sage); background: #e7f1ec; padding: 0.2rem 0.55rem; border-radius: 999px; }

/* ---- Progress bars ---- */
.bar { margin: 0.45rem 0; }
.bar .bl { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.25rem; }
.track { height: 7px; background: var(--line-soft); border-radius: 4px; overflow: hidden; }
.fill { height: 100%; width: 0; border-radius: 4px; background: var(--sage); transition: width 0.35s ease; }
.fill.over { background: var(--amber); }

/* ---- Chips ---- */
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.7rem; }
.chip { font: inherit; font-size: 0.85rem; padding: 0.55rem 0.85rem; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); color: var(--ink-soft); cursor: pointer; min-height: 40px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---- Numeric field grids ---- */
.fields4, .fields3, .fields2 { display: grid; gap: 0.5rem; margin-bottom: 0.7rem; }
.fields4 { grid-template-columns: repeat(5, 1fr); }
.fields3 { grid-template-columns: repeat(3, 1fr); }
.fields2 { grid-template-columns: 1fr 1fr; }
.nfield { display: flex; flex-direction: column; gap: 0.25rem; }
.nfield span { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.nfield input, .nfield select { font: inherit; font-family: var(--mono); font-weight: 500; font-size: 1.05rem; padding: 0.6rem 0.4rem; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); min-height: 46px; min-width: 0; width: 100%; }
.nfield input:focus, .nfield select:focus { outline: none; border-color: var(--ink); background: #fff; }
@media (max-width: 420px) { .fields4 { grid-template-columns: repeat(3, 1fr); } }

/* ---- Entry lists ---- */
.loghead { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin: 1rem 0 0.5rem; }
.entry-list { list-style: none; display: flex; flex-direction: column; gap: 0.45rem; }
.entry-list li { display: flex; align-items: center; gap: 0.7rem; background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 0.7rem 0.85rem; }
.entry-list li.empty { background: transparent; border-style: dashed; justify-content: center; }
.entry-list .ei { flex: 1; min-width: 0; }
.entry-list .ei .t { font-size: 0.95rem; font-weight: 500; }
.entry-list .ev { font-family: var(--mono); font-weight: 600; }
.entry-list .ev small { color: var(--muted); font-weight: 500; }
.del { border: 0; background: none; color: var(--muted); font-size: 1.2rem; line-height: 1; cursor: pointer; padding: 0.3rem 0.4rem; min-height: 40px; }

/* ---- Quit card ---- */
.quit .big-streak { font-family: var(--mono); font-weight: 600; font-size: 2.4rem; line-height: 1; margin: 0.2rem 0; }
.quit .big-streak small { display: block; font-size: 0.7rem; font-weight: 500; color: var(--muted); letter-spacing: 0.04em; }

/* ---- Flags ---- */
.flag-high { color: var(--amber); }
.flag-low { color: var(--red); }
.flag-normal { color: var(--sage); }
.mini-list { list-style: none; display: flex; flex-direction: column; gap: 0.3rem; }

/* ---- Program week ---- */
.week { display: flex; flex-direction: column; gap: 0.4rem; }
.weekrow { display: grid; grid-template-columns: 3rem 1fr; align-items: center; gap: 0.6rem; }
.weekrow .dow { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }
.weekrow select { font: inherit; padding: 0.5rem; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); min-height: 42px; text-transform: capitalize; }

/* ---- Set logger ---- */
.setrow { display: grid; grid-template-columns: 1fr 4rem 4rem; align-items: center; gap: 0.4rem; padding: 0.35rem 0; border-bottom: 1px solid var(--line-soft); }
.setrow:last-of-type { border-bottom: 0; }
.setrow { align-items: start; }
.setrow .exn { font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.1rem; }
.setrow input { font: inherit; font-family: var(--mono); padding: 0.45rem 0.4rem; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); min-width: 0; min-height: 42px; text-align: center; }
.last-hint { font-size: 0.72rem; line-height: 1.2; }
.last-hint .try { color: var(--sage); font-weight: 600; }
.tut { display: inline-block; margin-top: 0.15rem; font-size: 0.68rem; font-weight: 600; color: var(--blue); text-decoration: none; border: 1px solid var(--blue); border-radius: 6px; padding: 1px 7px; white-space: nowrap; line-height: 1.5; }
.tut:active { opacity: 0.6; }
.cal-toggle { display: flex; align-items: center; gap: 0.5rem; margin: 0.2rem 0 0.6rem; font-size: 0.85rem; cursor: pointer; }
.cal-toggle input { width: 1.1rem; height: 1.1rem; accent-color: var(--blue); flex-shrink: 0; }
.vers { margin-top: 0.2rem; }
.vers summary { font-size: 0.72rem; color: var(--blue); cursor: pointer; list-style: none; padding: 0.1rem 0; }
.vers summary::-webkit-details-marker { display: none; }
.vers summary::before { content: "▾ "; }
.vers[open] summary::before { content: "▴ "; }
.vers-list { list-style: none; margin: 0.15rem 0 0.2rem; padding-left: 0.6rem; display: flex; flex-direction: column; gap: 0.25rem; }
.vers-list li { font-size: 0.78rem; display: flex; align-items: center; gap: 0.4rem; }
.mini-tut { padding: 0 6px; }
.ex-list .tut { margin-left: 0.1rem; }

/* ---- Exercise lists ---- */
.ex-list { list-style: none; margin: 0.4rem 0 0.2rem; display: flex; flex-direction: column; gap: 0.2rem; }
.ex-list li { padding: 0.25rem 0; border-bottom: 1px solid var(--line-soft); }
.ex-list li:last-child { border-bottom: 0; }
.exhead { display: flex; justify-content: space-between; align-items: baseline; gap: 0.6rem; }
.exn { font-size: 0.85rem; }
.exr { font-family: var(--mono); font-size: 0.74rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.ex-list li .exn { flex: 1 1 auto; min-width: 0; }
.ss { font-family: var(--mono); font-size: 0.6rem; color: var(--amber); border: 1px solid currentColor; border-radius: 4px; padding: 0 3px; vertical-align: middle; }
.weekday { padding: 0.5rem 0; border-bottom: 1px solid var(--line-soft); }
.weekday:last-child { border-bottom: 0; }
.load-row { display: flex; gap: 0.5rem; margin-top: 0.7rem; }
.load-row select { flex: 1; font: inherit; padding: 0.55rem; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); min-height: 44px; }
.load-row .btn-ghost { min-height: 44px; }

/* ---- Weight import row ---- */
.import-row { display: flex; align-items: center; gap: 0.6rem; margin: 0.6rem 0; }
.file-btn { cursor: pointer; margin-top: 0; flex: 1; text-align: center; }
.units-toggle { font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 0.3rem; }
.units-toggle select { font: inherit; padding: 0.3rem; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); }

/* ---- Review queue ---- */
.badge { font-family: var(--mono); font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 1px 6px; border-radius: 999px; vertical-align: middle; }
.badge.ok { background: #e7f1ec; color: var(--sage); }
.badge.warn { background: #f3eee3; color: var(--amber); }
.mini { border: 1px solid var(--line); background: var(--paper); font: inherit; font-size: 0.78rem; font-weight: 500; padding: 0.4rem 0.6rem; border-radius: 9px; cursor: pointer; min-height: 38px; }
.mini.ok { border-color: var(--sage); color: var(--sage); }
.range-row { margin: 0.6rem 0; padding-top: 0.6rem; border-top: 1px solid var(--line-soft); }
.range-row > .muted { display: block; margin-bottom: 0.4rem; }

/* ---- AI insight ---- */
.insight p { margin: 0 0 0.5rem; font-size: 0.9rem; line-height: 1.5; }
.insight p:last-child { margin-bottom: 0; }
.insight b { font-weight: 600; }

/* ---- Devices ---- */
.dev-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line-soft); }
.dev-row .dn { flex: 1; min-width: 0; }
.dev-row .dn .t { font-weight: 500; }
.dev-row a.mini { text-decoration: none; display: inline-block; }
.oura-token { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.oura-token .text-input { margin-bottom: 0; }
.oura-token .btn-ghost { min-height: 44px; }

/* ---- Bottom nav ---- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 15;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.navbtn { border: 0; background: none; cursor: pointer; font: inherit; font-size: 0.65rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 0.15rem; padding: 0.55rem 0.2rem 0.5rem; min-height: 56px; }
.navbtn .ic { font-size: 1.15rem; line-height: 1; }
.navbtn.is-active { color: var(--ink); font-weight: 600; }
.navbtn.is-active .ic { filter: none; }

/* ---- Toast ---- */
.toast { position: fixed; left: 50%; bottom: 5rem; transform: translateX(-50%) translateY(60px); background: var(--ink); color: #fff; font-size: 0.85rem; font-weight: 500; padding: 0.7rem 1.1rem; border-radius: 999px; opacity: 0; transition: 0.3s; z-index: 30; pointer-events: none; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ---- Admin dashboard ---- */
.admin-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
.admin-stats .stat { background: var(--paper); border-radius: 12px; padding: 0.7rem 0.8rem; }
.stat-num { display: block; font-family: var(--mono); font-size: 1.5rem; font-weight: 600; line-height: 1.1; }
.stat-cap { font-size: 0.75rem; color: var(--muted); }
.auser { display: flex; flex-direction: column; gap: 0.3rem; padding: 0.7rem 0; border-bottom: 1px solid var(--line-soft); }
.auser:last-child { border-bottom: 0; }
.auser-head { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.auser-acts { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.2rem; }
.btn-ghost.mini { min-height: 36px; padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.abadge { font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; padding: 0.12rem 0.45rem; border-radius: 999px; background: var(--line); color: var(--ink-soft); }
.abadge.active { background: #d8efe3; color: var(--sage); }
.abadge.paused { background: #f7e7c8; color: var(--amber); }
.abadge.archived { background: var(--line); color: var(--muted); }
.abadge.warn { background: #fbe0dc; color: var(--red); }
.dot-on { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--sage); }
.temp-box { margin-top: 0.7rem; padding: 0.7rem; background: var(--paper); border-radius: 12px; }
.temp-box .import-row { margin-top: 0.4rem; }
.temp-box .text-input { font-family: var(--mono); margin-bottom: 0; }
