/* Pulse: WHOOP-style dark theme (D6). Tokens from PRD "Visual tokens" and SCORING.md §6. */
:root {
  --bg: #0B0D0F;
  --surface: #15191D;
  --surface-2: #1E2328;
  --border: #2A3036;
  --track: #2A3036;
  --text: #F2F4F5;
  --muted: #8B949E;
  --accent: #00B7FF; /* selection only */
  --green: #16EC06;
  --yellow: #FFDE00;
  --red: #FF0026;
  --none: #2A3036;
  --on-band: #0B0D0F;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
  --radius: 12px;
  --hero: 56px;
  --tabbar-h: 56px;
  --rail-w: 88px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.pad { padding: var(--s4); }
svg text { font-family: inherit; font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
main {
  max-width: 1200px; margin: 0 auto; outline: none;
  padding: calc(var(--safe-t) + var(--s3)) calc(var(--safe-r) + var(--s4)) calc(var(--safe-b) + var(--tabbar-h) + var(--s5)) calc(var(--safe-l) + var(--s4));
  display: flex; flex-direction: column; gap: var(--s3);
}
.tabs {
  position: fixed; z-index: 10; left: 0; right: 0; bottom: 0;
  display: flex; background: rgba(11, 13, 15, .94); border-top: 1px solid var(--border);
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.tabs a {
  flex: 1; min-height: var(--tabbar-h); min-width: 44px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--accent); }
body.locked .tabs { display: none; }
body.locked main { padding-bottom: calc(var(--safe-b) + var(--s5)); }

@media (min-width: 1024px) {
  .tabs {
    top: 0; right: auto; width: calc(var(--rail-w) + var(--safe-l)); flex-direction: column; justify-content: flex-start;
    gap: var(--s2); padding: calc(var(--safe-t) + var(--s5)) 0 var(--s4) var(--safe-l);
    border-top: 0; border-right: 1px solid var(--border);
  }
  .tabs a { flex: 0 0 auto; min-height: 64px; }
  body:not(.locked) main { margin-left: max(calc(var(--rail-w) + var(--safe-l)), calc((100vw - 1200px) / 2)); padding-left: var(--s5); padding-right: var(--s5); padding-bottom: var(--s5); }
}

/* ---------- common ---------- */
.top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); padding: var(--s1) 0 var(--s2); }
.top h1 { font-size: 22px; font-weight: 700; }
.top .meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s4); min-width: 0; }
.card > h2, .card-title { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: var(--s3); }
.grid { display: grid; gap: var(--s3); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 768px) {
  .grid-md-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-md-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1024px) { .grid-lg-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.big { font-size: var(--hero); font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.big small { font-size: 18px; font-weight: 600; color: var(--muted); letter-spacing: 0; margin-left: var(--s1); }
.stat .v { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
.err { color: var(--muted); border-color: var(--red); }
.empty { color: var(--muted); font-size: 14px; }

/* horizontal meter */
.meter { height: 8px; border-radius: 4px; background: var(--track); position: relative; overflow: visible; }
.meter > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; max-width: 100%; }
.meter > b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); border-radius: 1px; }
.meter.thin { height: 4px; }
.meter.thin > b { top: -3px; bottom: -3px; }
.meter-row { display: grid; grid-template-columns: 76px 1fr 44px; align-items: center; gap: var(--s3); font-size: 14px; }
.meter-row + .meter-row { margin-top: var(--s3); }
.meter-row .n { text-align: right; font-weight: 700; }

/* comments */
.comment .c + .c { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--border); }
.comment .who { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: var(--s1); }
.comment p { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }

/* ---------- overview ---------- */
.hero { display: flex; flex-direction: column; align-items: center; padding: var(--s5) var(--s4); }
.ring { display: block; }
.ring-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--s2); justify-items: center; }
.ring-row figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: var(--s1); }
.ring-row figcaption { font-size: 12px; color: var(--muted); font-weight: 600; }
.day-strip { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: var(--s1); margin-top: var(--s4); }
.day {
  min-height: 52px; min-width: 0; padding: var(--s1) 0; border-radius: 10px; border: 1px solid transparent;
  background: var(--surface-2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
}
.day span { font-size: 10px; color: var(--muted); font-weight: 600; }
.day b { font-size: 12px; font-weight: 700; }
.day i { width: 6px; height: 6px; border-radius: 3px; }
.day.is-sel { border-color: var(--accent); }
.day.is-sel b { color: var(--accent); }

.pair { display: grid; gap: var(--s4); }
@media (min-width: 768px) { .pair { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pair figure { margin: 0; min-width: 0; }
.pair figcaption { font-size: 12px; color: var(--muted); margin-bottom: var(--s1); }
.chart { display: block; width: 100%; height: auto; overflow: visible; }

/* ---------- sleep ---------- */
.night-hero { display: flex; gap: var(--s4); align-items: center; flex-wrap: wrap; }
.night-hero .facts { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: var(--s2); }
.stages { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; margin: var(--s3) 0 var(--s2); }
.legend { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--c); margin-right: 6px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
@media (min-width: 768px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.list { display: flex; flex-direction: column; }
.list .row { display: grid; align-items: center; gap: var(--s2); padding: var(--s2) 0; border-top: 1px solid var(--border); font-size: 14px; min-height: 44px; }
.list .row:first-child { border-top: 0; }
.list .row.head { color: var(--muted); font-size: 12px; min-height: 0; }
.nights .row { grid-template-columns: 1.2fr .8fr 1fr 1fr 1fr; }
.list .r { text-align: right; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 4px; background: var(--c, var(--muted)); }
.score { display: inline-block; min-width: 34px; text-align: center; font-weight: 700; font-size: 13px; padding: 2px 6px; border-radius: 6px; color: var(--on-band); }
.score.none { color: var(--muted); background: var(--surface-2); }

/* ---------- habits ---------- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { min-height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--accent); }
.habit-head { display: flex; align-items: center; gap: var(--s4); }
.habits { display: flex; flex-direction: column; gap: var(--s2); }
.habit {
  display: grid; grid-template-columns: 32px 1fr auto; grid-template-rows: auto auto; column-gap: var(--s3); row-gap: var(--s2);
  align-items: center; width: 100%; min-height: 64px; padding: var(--s3) var(--s4); text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
button.habit { cursor: pointer; }
button.habit:active { background: var(--surface-2); }
.habit .tick { grid-row: 1 / span 2; width: 32px; height: 32px; border-radius: 16px; border: 2px solid var(--border); display: grid; place-items: center; }
.habit .tick svg { width: 18px; height: 18px; fill: none; stroke: var(--on-band); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; visibility: hidden; }
.habit.is-done .tick { background: var(--green); border-color: var(--green); }
.habit.is-done .tick svg { visibility: visible; }
.habit.ro .tick { border-style: dashed; }
.habit .name { font-weight: 700; font-size: 16px; }
.habit .name small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.habit .prog { font-weight: 700; font-size: 16px; text-align: right; white-space: nowrap; }
.habit .meter { grid-column: 2 / span 2; }
.toast { font-size: 13px; color: var(--text); background: var(--surface-2); border: 1px solid var(--red); border-radius: 10px; padding: var(--s2) var(--s3); }

/* ---------- money ---------- */
.cat .head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s2); margin-bottom: var(--s2); }
.cat .name { font-weight: 700; overflow-wrap: anywhere; }
.cat .amt { font-size: 20px; font-weight: 700; margin: var(--s1) 0 var(--s2); }
.cat .amt small { font-size: 13px; color: var(--muted); font-weight: 500; }
.cat .foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: var(--s2); }
.tx .row { grid-template-columns: 1fr auto; }
.tx .row small { display: block; color: var(--muted); font-size: 12px; }
.strip { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 3px; }
.strip div { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.strip i { width: 100%; height: 28px; border-radius: 4px; display: grid; place-items: center; font-style: normal; font-size: 10px; font-weight: 700; color: var(--on-band); }
.strip span { font-size: 9px; color: var(--muted); }
.q .row { grid-template-columns: 1fr; gap: var(--s1); }
.q .who { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.q .rec { color: var(--muted); font-size: 13px; }
.soon { opacity: .45; }
.proj + .proj { margin-top: var(--s3); }
.proj > div:first-child { display: flex; justify-content: space-between; gap: var(--s2); font-size: 14px; margin-bottom: 6px; }
.proj span { overflow-wrap: anywhere; }

/* ---------- login ---------- */
.login { min-height: calc(100vh - 120px); display: flex; align-items: center; justify-content: center; }
.login form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: var(--s3); }
.login h1 { font-size: 28px; font-weight: 700; text-align: center; margin-bottom: var(--s2); }
.login input {
  font-size: 16px; min-height: 48px; padding: 0 var(--s4); border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); outline: none;
}
.login input:focus { border-color: var(--accent); }
.login button { min-height: 48px; border: 0; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 700; font-size: 16px; cursor: pointer; }
.login .msg { min-height: 20px; color: var(--red); font-size: 14px; text-align: center; }
