:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e3e6ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --faint: #9aa1ab;
  --accent: #2f6fed;
  --accent-soft: #e8f0fe;

  --ready: #1a9d5a;    --ready-bg: #e6f6ec;
  --moderate: #c98a00; --moderate-bg: #fbf1d9;
  --low: #d9720a;      --low-bg: #fbe9d8;
  --verylow: #d1435b;  --verylow-bg: #fbe1e6;

  --run: #2f6fed; --strength: #8b5cf6; --hike: #0f9d8b;
  --bike: #d9720a; --rest: #9aa1ab; --race: #d1435b;

  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1d222a;
    --border: #2a2f38; --text: #e7eaee; --muted: #9aa1ab; --faint: #6b7280;
    --accent: #5b8dff; --accent-soft: #1c2740;
    --ready-bg: #123222; --moderate-bg: #322a12; --low-bg: #33220f; --verylow-bg: #331820;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .6rem 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); }
.brand-logo { border-radius: 6px; display: block; }
.brand-name { font-weight: 800; font-size: 1.05rem; letter-spacing: -.02em; }
.brand-sub { color: var(--muted); font-size: .82rem; font-weight: 500; padding-left: .1rem; border-left: 1px solid var(--border); margin-left: .1rem; padding-left: .5rem; }
.topnav { display: flex; align-items: center; gap: .35rem; }
.topnav a { color: var(--muted); padding: .35rem .6rem; border-radius: 8px; font-size: .92rem; font-weight: 500; }
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.sync-form { margin: 0; }
.btn-sync {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: .35rem .7rem; border-radius: 8px; font-size: .9rem; font-weight: 600; cursor: pointer;
}
.btn-sync:hover { background: var(--accent-soft); border-color: var(--accent); }

.toast {
  margin: .6rem 1rem 0; padding: .6rem .9rem; border-radius: 10px;
  background: var(--accent-soft); color: var(--text); border: 1px solid var(--border); font-size: .9rem;
}

main { padding: 1rem; max-width: 1400px; margin: 0 auto; }

/* ── Week header ─────────────────────────────────────── */
.week-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; flex-wrap: wrap; }
.week-title { display: flex; flex-direction: column; }
.week-title h1 { font-size: 1.25rem; margin: 0; letter-spacing: -.02em; }
.week-title .sub { color: var(--muted); font-size: .9rem; }
.week-label { font-size: .82rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.week-nav { display: flex; align-items: center; gap: .4rem; }
.week-nav a, .week-nav span { padding: .35rem .7rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: .9rem; color: var(--text); }
.week-nav a.disabled { opacity: .4; pointer-events: none; }

/* ── Weekly totals ───────────────────────────────────── */
.totals { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; min-width: 120px; box-shadow: var(--shadow); }
.tile .k { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tile .v { font-size: 1.15rem; font-weight: 700; }
.tile .v small { font-size: .8rem; color: var(--muted); font-weight: 500; }
.bar { height: 5px; background: var(--surface-2); border-radius: 999px; margin-top: .4rem; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }

/* ── Week grid ───────────────────────────────────────── */
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: .6rem; }
.day {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .55rem; display: flex; flex-direction: column; gap: .5rem; min-height: 150px; box-shadow: var(--shadow);
}
.day.today { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.day-head { display: flex; align-items: baseline; justify-content: space-between; }
.day-head .dow { font-weight: 700; font-size: .85rem; }
.day-head .date { color: var(--muted); font-size: .78rem; }

/* ── Readiness chip ──────────────────────────────────── */
.readiness { display: inline-flex; align-items: center; gap: .3rem; font-size: .74rem; font-weight: 600; padding: .12rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.readiness.ready, .readiness.high, .readiness.maximum { color: var(--ready); background: var(--ready-bg); }
.readiness.moderate { color: var(--moderate); background: var(--moderate-bg); }
.readiness.low { color: var(--low); background: var(--low-bg); }
.readiness.verylow, .readiness.very_low { color: var(--verylow); background: var(--verylow-bg); }
.metrics { display: flex; flex-wrap: wrap; gap: .3rem .7rem; font-size: .74rem; color: var(--muted); }
.metrics b { color: var(--text); font-weight: 600; }

/* ── Sessions ────────────────────────────────────────── */
.session { border-left: 3px solid var(--run); padding: .25rem .5rem; background: var(--surface-2); border-radius: 6px; }
.session.strength { border-color: var(--strength); }
.session.hike { border-color: var(--hike); }
.session.bike { border-color: var(--bike); }
.session.rest { border-color: var(--rest); }
.session.race { border-color: var(--race); }
.session .st { font-size: .82rem; font-weight: 600; }
.session .sd { font-size: .74rem; color: var(--muted); margin-top: .1rem; }
.session .targets { font-size: .72rem; color: var(--faint); margin-top: .15rem; }
.session.revised { border-style: solid; box-shadow: inset 0 0 0 1px var(--accent-soft); }
.session.original-super { opacity: .55; }
.session.original-super .st { text-decoration: line-through; }
.tag-revised { font-size: .64rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }

/* ── Actuals ─────────────────────────────────────────── */
.actual { border-left: 3px solid var(--ready); padding: .25rem .5rem; background: var(--ready-bg); border-radius: 6px; }
.actual .at { font-size: .8rem; font-weight: 600; }
.actual .ad { font-size: .72rem; color: var(--muted); }
.note { font-size: .74rem; font-style: italic; color: var(--muted); border-top: 1px dashed var(--border); padding-top: .35rem; }

.section-label { font-size: .64rem; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 700; margin-top: .1rem; }

/* ── Mobile day view ─────────────────────────────────── */
.day-view { max-width: 560px; margin: 0 auto; }
.day-view-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: .8rem; }
.day-view-head h1 { font-size: 1.2rem; margin: 0; }
.swipe-btn { font-size: 1.4rem; line-height: 1; padding: .3rem .7rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); user-select: none; cursor: pointer; }
.day-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .8rem; }
.day-card.today { border-color: var(--accent); }
.block h3 { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); margin: 0 0 .4rem; }
.empty { color: var(--faint); font-size: .85rem; padding: .5rem 0; }

/* ── Import / NoPlan ─────────────────────────────────── */
.panel { max-width: 640px; margin: 1rem auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow); }
.panel h1 { font-size: 1.3rem; margin-top: 0; }
.panel code { background: var(--surface-2); padding: .1rem .35rem; border-radius: 5px; font-size: .85em; }
.err { color: var(--verylow); background: var(--verylow-bg); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; margin: .8rem 0; font-size: .88rem; }
.err ul { margin: .4rem 0 0; padding-left: 1.2rem; }
input[type=file] { display: block; margin: 1rem 0; }
.btn { display: inline-block; background: var(--accent); color: #fff; border: none; padding: .55rem 1.1rem; border-radius: 9px; font-weight: 600; cursor: pointer; font-size: .95rem; }

/* ── Clickable cards + note indicator ────────────────── */
.card-link { display: block; text-decoration: none; color: inherit; margin: 0; }
.card-link:hover .session, .card-link:hover .actual { outline: 1px solid var(--accent); }
.note-dot { font-size: .7rem; margin-left: .15rem; }

/* ── Collapsible week summary (day view) ─────────────── */
.week-summary { margin-bottom: .8rem; }
.summary-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: .5rem .8rem; color: var(--text); font-weight: 600; font-size: .9rem; cursor: pointer;
}
.summary-toggle .chev { transition: transform .15s ease; color: var(--muted); }
.week-summary.collapsed .chev { transform: rotate(-90deg); }
.summary-body { margin-top: .6rem; }
.week-summary.collapsed .summary-body { display: none; }
.week-summary .totals { margin-bottom: 0; }

/* ── Detail pages ────────────────────────────────────── */
.detail .back { display: inline-block; margin-bottom: .6rem; font-size: .9rem; }
.detail h1 { margin: .2rem 0; font-size: 1.25rem; }
.detail-sub { color: var(--muted); font-size: .88rem; margin-bottom: .8rem; }
.detail-targets { font-weight: 600; margin-bottom: .5rem; }
.detail-desc { line-height: 1.5; background: var(--surface-2); border-radius: 8px; padding: .6rem .8rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; margin: 1rem 0; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; display: flex; flex-direction: column; gap: .15rem; }
.stat .sk { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat .sv { font-size: 1.05rem; font-weight: 700; }
.note-form { margin-top: 1rem; display: flex; flex-direction: column; gap: .4rem; }
.note-form label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.note-form textarea { width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: .6rem; font: inherit; resize: vertical; }
.note-form .btn { align-self: flex-start; }

/* ── Responsive: week grid → stacked on phones ──────── */
@media (max-width: 820px) {
  .week-grid { grid-template-columns: 1fr; }
  .day { min-height: auto; }
  .topnav a { padding: .35rem .45rem; }
}
@media (max-width: 560px) {
  .brand-sub { display: none; }
}
