/* Oura dashboard – calm light theme. Chart colours are read from these tokens by app.js. */

:root {
  color-scheme: light;

  --bg: #eef1ef;
  --panel: #ffffff;
  --ink: #1a2420;
  --ink-2: #4b5852;
  --ink-3: #7c8781;
  --rule: #d8dfdb;
  --rule-soft: #e7ece9;

  --accent: #184f95;
  --accent-soft: #e3ecf7;

  /* steps relative to the goal: warm = short of it, blue = reached */
  --s-far-below: #d95926;
  --s-below: #f2b48f;
  --s-hit: #86b6ef;
  --s-far-above: #1c5cab;
  --s-none: #e1e6e3;
  --s-today: #f6f8f7;

  /* sleep stages: one hue, deep = darkest */
  --sl-deep: #184f95;
  --sl-rem: #3987e5;
  --sl-light: #a9cbf3;

  --good: #2b7a3d;
  --bad: #b8432a;
  --warn: #c8641f;
  --info: #2a6fbf;

  --serif: "Charter", "Iowan Old Style", "Sitka Text", Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --radius: 6px;
  --gutter: clamp(16px, 4vw, 40px);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* --- masthead ------------------------------------------------------------ */

.masthead {
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
}

.masthead-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 18px var(--gutter);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px 32px;
}

.masthead h1 {
  font-family: var(--serif);
  font-size: 1.45rem;
  line-height: 1.2;
  letter-spacing: -0.005em;
}

.period { margin: 2px 0 0; color: var(--ink-2); font-size: 0.9rem; }

.masthead-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
}

.range {
  display: inline-flex;
  background: var(--bg);
  border-radius: 999px;
  padding: 3px;
}

.range button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 0.9rem;
  padding: 5px 13px;
  border-radius: 999px;
  cursor: pointer;
}

.range button:hover { color: var(--ink); }

.range button[aria-pressed="true"] {
  background: var(--panel);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--rule);
}

.sync { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.sync-meta { color: var(--ink-2); font-size: 0.85rem; }

.button {
  appearance: none;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 6px 14px;
  cursor: pointer;
}

.button:hover { background: #123f78; }

.button:disabled { background: var(--ink-3); border-color: var(--ink-3); cursor: progress; }

.button-quiet {
  color: var(--accent);
  background: transparent;
  border-color: var(--rule);
  margin-top: 12px;
}

.button-quiet:hover { background: var(--accent-soft); }

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

.notices { max-width: 1160px; margin: 0 auto; padding: 0 var(--gutter); }

.notice {
  margin-top: 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border-left: 3px solid var(--info);
  font-size: 0.92rem;
}

.notice-warn { border-left-color: var(--bad); }

.notice-progress { display: flex; align-items: center; gap: 10px; }

.notice-progress::before {
  content: "";
  width: 12px; height: 12px; flex: none;
  border-radius: 50%;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .notice-progress::before { animation: none; }
}

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

.page {
  max-width: 1160px;
  margin: 0 auto;
  padding: 8px var(--gutter) 40px;
}

.page[aria-busy="true"] .overview,
.page[aria-busy="true"] .block { opacity: 0.55; transition: opacity 0.2s; }

/* overview: the headline sentence + last seven days */

.overview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px 48px;
  align-items: end;
  padding: 36px 0 30px;
  border-bottom: 1px solid var(--rule);
}

.lede {
  margin: 0;
  max-width: 30ch;
  font-family: var(--serif);
  font-size: clamp(1.75rem, 1.1rem + 2.4vw, 2.75rem);
  line-height: 1.15;
  letter-spacing: -0.012em;
  font-weight: 500;
  text-wrap: balance;
}

.lede-sub {
  margin: 14px 0 0;
  max-width: 62ch;
  color: var(--ink-2);
  font-size: 1rem;
  line-height: 1.55;
}

.week-strip { margin: 0; }

.week-strip ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(7, 52px);
  gap: 6px;
}

.week-strip li { display: grid; gap: 4px; justify-items: center; font-size: 0.78rem; color: var(--ink-2); }

.week-strip .cell {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 5px;
  background: var(--s-none);
}

.week-strip .steps { color: var(--ink); font-weight: 600; }

.week-strip figcaption { margin-top: 8px; font-size: 0.8rem; color: var(--ink-3); }

.cell.far-below { background: var(--s-far-below); }
.cell.below { background: var(--s-below); }
.cell.hit { background: var(--s-hit); }
.cell.far-above { background: var(--s-far-above); }
.cell.none { background: var(--s-none); }
.cell.today { background: var(--s-today); outline: 1px dashed var(--ink-3); outline-offset: -1px; }

/* blocks */

.block { padding-top: 40px; }

.block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 24px;
  margin-bottom: 14px;
}

.block-head h2 {
  font-family: var(--serif);
  font-size: 1.4rem;
  letter-spacing: -0.005em;
}

.block-note {
  margin: 0;
  color: var(--ink-2);
  font-size: 0.86rem;
  max-width: 70ch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
}

.panel + .panel { margin-top: 14px; }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 20px;
  margin-bottom: 6px;
}

.panel-head h3 { font-size: 0.98rem; }

.chart { width: 100%; height: 240px; }
.chart-tall { height: 280px; }
.chart-sleep { height: 340px; }

.empty {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--ink-3);
  font-size: 0.9rem;
}

/* legends */

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 0.8rem;
  color: var(--ink-2);
}

.legend li { display: inline-flex; align-items: center; gap: 6px; }

.key {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  vertical-align: -1px;
  background: var(--s-none);
}

.block-note .key { margin: 0 3px 0 10px; }
.block-note .key:first-child { margin-left: 0; }
.note-item + .note-item { margin-left: 10px; }
.label-short { display: none; }

/* daily vs. weekly bar mode (weekly only on phones, see app.js) */
.legend-weekly { display: none !important; }
.panel.weekly .legend-weekly { display: inline-flex !important; }
.panel.weekly .legend-daily { display: none !important; }

.key-line { height: 2px; width: 16px; border-radius: 1px; background: var(--accent); vertical-align: 3px; }
.key-deep { background: var(--sl-deep); }
.key-rem { background: var(--sl-rem); }
.key-light { background: var(--sl-light); }
.key-ink { background: var(--ink); }
.key-goal { height: 1px; width: 16px; border-radius: 0; background: var(--ink-2); vertical-align: 3px; }
.key-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); vertical-align: 1px; }
.key-band { background: rgba(24, 79, 149, 0.14); }

.heatmap-scroll { overflow-x: auto; overscroll-behavior-x: contain; }

.swipe-hint { margin: 4px 0 0; font-size: 0.78rem; color: var(--ink-3); }

/* facts under charts */

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 32px;
  margin: 10px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--rule-soft);
}

.facts div { display: flex; flex-direction: column-reverse; }
.facts dt { font-size: 0.8rem; color: var(--ink-2); }
.facts dd { margin: 0; font-size: 1.05rem; font-weight: 600; }

/* explanations */

.explain { margin-top: 10px; font-size: 0.9rem; }

.explain summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  width: fit-content;
}

.explain[open] summary { margin-bottom: 6px; }

.explain h4 { margin: 10px 0 2px; font-size: 0.86rem; color: var(--ink); }
.explain p { margin: 0; max-width: 72ch; color: var(--ink-2); line-height: 1.55; }

/* --- KPIs ---------------------------------------------------------------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.kpi {
  display: flex;
  flex-direction: column;
  padding: 14px 18px 16px;
  border-right: 1px solid var(--rule-soft);
  border-bottom: 1px solid var(--rule-soft);
}

.kpi:nth-child(4n) { border-right: 0; }
.kpi:nth-last-child(-n + 4) { border-bottom: 0; }

.kpi dt { font-size: 0.84rem; color: var(--ink-2); }

.kpi dd { margin: 0; }

.kpi .value {

  margin-top: 2px;
  font-size: 1.7rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.kpi .unit { font-size: 0.95rem; font-weight: 500; color: var(--ink-2); margin-left: 3px; }

.kpi .delta-wrap { margin-top: 2px; font-size: 0.84rem; color: var(--ink-2); }

.delta .arrow { font-size: 0.7rem; margin-right: 4px; }
.delta.good .arrow { color: var(--good); }
.delta.bad .arrow { color: var(--bad); }
.delta.flat .arrow { color: var(--ink-3); }

/* --- hints --------------------------------------------------------------- */

.hints {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.hint {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 2px 12px;
  align-items: start;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.hint-icon {
  grid-row: span 2;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1;
  margin-top: 1px;
}

.hint-warn .hint-icon { background: var(--warn); }
.hint-info .hint-icon { background: var(--info); }
.hint-good .hint-icon { background: var(--good); }

.hint-title { font-weight: 600; }
.hint-text { color: var(--ink-2); font-size: 0.92rem; }

.hint-empty { background: transparent; border-style: dashed; color: var(--ink-2); grid-template-columns: 1fr; }

/* --- marker cards -------------------------------------------------------- */

.markers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.markers .panel + .panel { margin-top: 0; }

.marker-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 2px 16px;
}

.marker-head h3 { font-size: 0.98rem; }

.marker-now { font-size: 1.25rem; font-weight: 600; }
.marker-now .unit { font-size: 0.85rem; font-weight: 500; color: var(--ink-2); margin-left: 2px; }

.marker-sub { margin: 0 0 4px; font-size: 0.82rem; color: var(--ink-2); }

.markers .chart { height: 200px; }
.markers-small .chart { height: 170px; }

/* --- weeks table --------------------------------------------------------- */

.table-scroll {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.weeks { width: 100%; border-collapse: collapse; font-size: 0.92rem; }

.weeks th, .weeks td {
  padding: 9px 14px;
  text-align: left;
  border-bottom: 1px solid var(--rule-soft);
  white-space: nowrap;
}

.weeks thead th { font-size: 0.8rem; font-weight: 600; color: var(--ink-2); background: #f7f9f8; }
.weeks tbody tr:last-child td, .weeks tbody tr:last-child th { border-bottom: 0; }
.weeks tbody th { font-weight: 600; }
.weeks .dates { display: block; font-weight: 400; font-size: 0.78rem; color: var(--ink-3); }
.weeks .num { text-align: right; }

.goal-dots { display: inline-flex; gap: 3px; vertical-align: -1px; margin-right: 8px; }

/* week cards replace the table on phones */
.week-cards { display: none; }

.week-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.week-card { padding: 10px 12px; border-bottom: 1px solid var(--rule-soft); font-size: 0.92rem; }
.week-card:last-child { border-bottom: 0; }

.week-card-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 12px;
}

.week-card-line + .week-card-line { justify-content: flex-start; margin-top: 3px; }
.week-card .dates { font-weight: 400; color: var(--ink-3); }
.week-card-steps { font-weight: 600; }
.week-card-steps .unit { font-weight: 400; font-size: 0.82rem; color: var(--ink-2); }
.week-card-meta { margin-top: 3px; font-size: 0.8rem; color: var(--ink-3); }

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  vertical-align: 0;
}

.dot-hit { background: var(--s-far-above); }
.dot-miss { background: transparent; box-shadow: inset 0 0 0 1.5px var(--s-far-below); }
.dot-none { background: var(--s-none); }

.colophon {
  max-width: 1160px;
  margin: 0 auto;
  padding: 18px var(--gutter) 36px;
  border-top: 1px solid var(--rule);
  color: var(--ink-3);
  font-size: 0.82rem;
}

.colophon p { margin: 0; max-width: 80ch; }

/* --- connect page -------------------------------------------------------- */

.connect {
  max-width: 640px;
  margin: 0 auto;
  padding: 56px var(--gutter) 64px;
}

.connect h1 {
  font-family: var(--serif);
  font-size: clamp(1.8rem, 1.3rem + 2vw, 2.4rem);
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.connect > p { color: var(--ink-2); max-width: 60ch; }

.connect .panel { margin-top: 22px; }
.connect .panel h2 { font-size: 1.05rem; margin-bottom: 4px; }
.connect .panel p { margin: 0 0 12px; color: var(--ink-2); font-size: 0.92rem; }

.connect ol { margin: 0 0 12px; padding-left: 1.3em; color: var(--ink-2); font-size: 0.92rem; }
.connect ol li + li { margin-top: 4px; }

.connect label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }

.connect textarea {
  width: 100%;
  min-height: 92px;
  font: 0.88rem/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fbfcfb;
  color: var(--ink);
  resize: vertical;
}

.connect .button { margin-top: 10px; text-decoration: none; display: inline-block; }

/* --- narrow screens ------------------------------------------------------ */

@media (max-width: 860px) {
  .overview { grid-template-columns: 1fr; align-items: start; padding-top: 28px; }
  .markers { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(4n) { border-right: 1px solid var(--rule-soft); }
  .kpi:nth-child(2n) { border-right: 0; }
  .kpi:nth-last-child(-n + 4) { border-bottom: 1px solid var(--rule-soft); }
  .kpi:nth-last-child(-n + 2) { border-bottom: 0; }
}

@media (max-width: 520px) {
  body { font-size: 14.5px; }
  .masthead-controls, .sync { width: 100%; }
  .range { width: 100%; }
  .range button { flex: 1; padding: 6px 4px; }
  .sync { justify-content: space-between; }
  .week-strip ol { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
  .panel { padding: 14px 12px 12px; }
  .kpi { padding: 12px 12px 14px; }
  .kpi .value { font-size: 1.4rem; }
  .facts { gap: 10px 22px; }
}

/* phones: see isMobile() in app.js (same breakpoint) */
@media (max-width: 600px) {
  .facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
  .facts div { justify-content: flex-end; } /* values on one line even when a label wraps */
  .legend li, .note-item { white-space: nowrap; }
  .note-item { display: inline-block; margin-right: 10px; }
  .note-item + .note-item { margin-left: 0; }
  .label-long { display: none; }
  .label-short { display: inline; }
  .table-scroll { display: none; }
  .week-cards { display: block; }
  .markers .chart { height: 160px; }
  .markers-small .chart { height: 136px; }
}

/* --- login / passkeys ---------------------------------------------------- */

.connect .field {
  display: block;
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  margin-bottom: 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fbfcfb;
  color: var(--ink);
}

.passkey-list { list-style: none; margin: 0; padding: 0; }
.passkey-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--rule-soft);
}
.passkey-list li:first-child { border-top: 0; }
.passkey-list li div { display: flex; flex-direction: column; min-width: 0; }
.passkey-list li span { color: var(--ink-2); font-size: 0.85rem; }
.passkey-list .button { margin-top: 0; flex: none; }
.passkey-list .button:disabled { opacity: 0.5; cursor: not-allowed; background: transparent; color: var(--ink-3); }

.masthead-links { display: flex; align-items: center; gap: 14px; font-size: 0.9rem; }
.masthead-links form { margin: 0; }
.link-button {
  appearance: none; border: 0; background: none; padding: 0; font: inherit;
  color: var(--accent); text-decoration: underline; cursor: pointer;
}

@media (max-width: 600px) {
  .connect { padding-top: 32px; }
  .passkey-list li { flex-wrap: wrap; }
}
