/* Mission Control v2.0 — quiet theme. Calm dark (default) + light, generous spacing, phone-first. */
:root {
  --bg: #14181f;
  --card: #1b2029;
  --card-2: #212733;
  --line: #2c3340;
  --text: #e4e7ec;
  --muted: #9aa3b2;
  --accent: #7fb8a8;      /* soft sage-teal */
  --accent-2: #d4b483;    /* sand */
  --accent-3: #8fa9cf;    /* dusty blue */
  --ok: #7fbf8f;
  --warn: #d9b26a;
  --bad: #d98a86;
  --radius: 12px;
  --focus: #b9d8ff;
  --topbar-bg: rgba(20, 24, 31, .94);
  --accent-hover: #a5d3c6;
  --on-accent: #10201b;
  --on-bad: #2a1210;
  --err-text: #f0c4c1;
  --backdrop: rgba(8, 10, 14, .7);
  --tag-bg: rgba(127, 184, 168, .15);
  --band-mds: rgba(127, 191, 143, .35);
  color-scheme: dark;
}

/* Light theme — warm paper, darker accents so text stays readable in sunlight */
:root[data-theme="light"] {
  --bg: #f6f4ef;
  --card: #ffffff;
  --card-2: #eeebe4;
  --line: #ddd8cc;
  --text: #1f2328;
  --muted: #5d6470;
  --accent: #2f7a68;
  --accent-2: #9a6b22;
  --accent-3: #3f6295;
  --ok: #2e7d45;
  --warn: #9a6400;
  --bad: #b23b35;
  --focus: #1f5fbf;
  --topbar-bg: rgba(246, 244, 239, .95);
  --accent-hover: #215a4c;
  --on-accent: #ffffff;
  --on-bad: #ffffff;
  --err-text: #8f2621;
  --backdrop: rgba(30, 30, 30, .45);
  --tag-bg: rgba(47, 122, 104, .12);
  --band-mds: rgba(46, 125, 69, .25);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; color: var(--muted); font-weight: 500; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.tiny { font-size: .82rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip-link { position: absolute; left: -999px; top: .5rem; background: var(--card); color: var(--text); padding: .5rem .75rem; border-radius: 6px; z-index: 50; }
.skip-link:focus { left: .5rem; }

/* ---------- Top bar & nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .75rem 1.25rem;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 1.1rem; }
.brand-title { font-weight: 600; letter-spacing: .01em; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a {
  color: var(--muted); text-decoration: none;
  padding: .45rem .8rem; border-radius: 999px; min-height: 40px;
  display: inline-flex; align-items: center;
}
.nav a:hover { color: var(--text); background: var(--card); }
.nav a.active { color: var(--text); background: var(--card-2); }

/* ---------- Layout ---------- */
.main { max-width: 1040px; margin: 0 auto; padding: 1.5rem 1.25rem 2rem; }
.main:focus { outline: none; }
.page-head { margin: .5rem 0 1.5rem; }
.page-head.with-actions { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.card-head h2 { margin-bottom: .75rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.two-col > .card { margin-bottom: 0; }
.two-col { margin-bottom: 1rem; }
.link-quiet { color: var(--muted); text-decoration: none; font-size: .9rem; }
.link-quiet:hover { color: var(--text); }

details.card > summary, details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details.card > summary { display: flex; align-items: center; justify-content: space-between; }
details.card > summary h2 { margin: 0; }
details.card > summary::after { content: "＋"; color: var(--muted); font-size: 1rem; }
details.card[open] > summary::after { content: "－"; }
details.card[open] > summary { margin-bottom: 1rem; }

/* ---------- Stats ---------- */
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1rem; }
.summary-grid.five { grid-template-columns: repeat(5, 1fr); }
.summary-grid > .card { margin-bottom: 0; }
.stat-label { color: var(--muted); font-size: .82rem; margin-bottom: .2rem; }
.stat-value { font-size: 1.6rem; font-weight: 600; line-height: 1.2; margin-bottom: .4rem; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: .85rem; font-weight: 400; color: var(--muted); }
.bar { height: 6px; background: var(--card-2); border-radius: 999px; overflow: hidden; margin: .35rem 0 .5rem; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* Day bars */
.day-bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: .5rem; align-items: end; }
.day-col { text-align: center; }
.day-bar-track { height: 90px; background: var(--card-2); border-radius: 6px; display: flex; align-items: flex-end; overflow: hidden; }
.day-bar-fill { width: 100%; background: var(--accent); opacity: .8; border-radius: 6px 6px 0 0; }
.day-km { font-size: .85rem; margin-top: .3rem; font-variant-numeric: tabular-nums; }
.day-label { font-size: .78rem; color: var(--muted); }
.day-col.today .day-label { color: var(--text); font-weight: 600; }
.day-col.future .day-bar-track { opacity: .5; }

/* Activity list */
.activity-list { list-style: none; padding: 0; margin: 0; }
.activity-list li { display: grid; grid-template-columns: 3.5rem 1fr auto; gap: .75rem; padding: .55rem 0; border-top: 1px solid var(--line); align-items: baseline; }
.activity-list li:first-child { border-top: none; }
.activity-list.compact li { grid-template-columns: 6rem 1fr auto; font-size: .9rem; }
.act-date { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.act-meta { color: var(--muted); font-size: .85rem; white-space: nowrap; }

/* Chips */
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin: 1.25rem 0 0; }
.chip {
  display: flex; flex-direction: column; gap: .1rem;
  padding: .9rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card);
  color: var(--text); text-decoration: none;
}
.chip span { color: var(--muted); font-size: .85rem; }
.chip:hover { border-color: var(--accent); color: var(--text); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 42px; padding: .5rem 1rem;
  border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.07); color: var(--on-accent); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); font-weight: 500; }
.btn-ghost:hover { background: var(--card-2); color: var(--text); }
.btn-small { min-height: 36px; padding: .3rem .75rem; font-size: .9rem; background: var(--card-2); color: var(--text); border-color: var(--line); font-weight: 500; }
.btn-small.btn-ghost { background: transparent; }
.btn-danger { background: var(--bad); color: var(--on-bad); }
.btn-icon {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: .3rem .5rem; border-radius: 6px; cursor: pointer; font: inherit; font-size: .85rem;
  min-height: 36px;
}
.btn-icon:hover { color: var(--text); border-color: var(--line); }
.btn-icon.danger:hover { color: var(--bad); }
form.inline { display: inline; }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: .55rem .7rem; min-height: 42px; width: 100%;
}
input[type="checkbox"] { width: 1.1rem; height: 1.1rem; min-height: 0; accent-color: var(--accent); }
input[type="range"] { padding: 0; min-height: 28px; accent-color: var(--accent); background: none; border: none; }
input[type="file"] { padding: .4rem; }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem 1rem; }
.form-grid.one-col { grid-template-columns: 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .more-fields .form-grid { margin-top: .75rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.filter-bar { display: flex; gap: .75rem 1rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filter-bar label { min-width: 9rem; }
.filter-count { margin-left: auto; align-self: center; }
.form-error { background: rgba(217, 138, 134, .12); border: 1px solid rgba(217, 138, 134, .4); color: var(--err-text); padding: .6rem .8rem; border-radius: 8px; }
.template-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.more-fields > summary { padding: .25rem 0; font-size: .9rem; }

/* Filters (Analyse) */
.filter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem 1.5rem; }
fieldset { border: none; padding: 0; margin: 0; }
legend { color: var(--muted); font-size: .9rem; margin-bottom: .35rem; }
.check-row { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
.range-group { display: flex; flex-direction: column; gap: .5rem; }
.range-group output { color: var(--text); }
.range-group label { display: block; }
.range-group label input { display: block; margin-top: .3rem; }
.show-sm { display: none; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: .8rem; padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
.table td { padding: .65rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.row-actions { white-space: nowrap; text-align: right; }

/* Tags */
.tag { display: inline-block; font-size: .72rem; padding: .1rem .5rem; border-radius: 999px; background: var(--tag-bg); color: var(--accent); vertical-align: middle; }
.tag-soft { background: var(--card-2); color: var(--muted); }

/* ---------- Charts ---------- */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.chart-grid > .card { margin-bottom: 0; }
.chart-wrap.wide { grid-column: 1 / -1; }
.chart-wrap canvas { width: 100% !important; }
.chart-empty { color: var(--muted); padding: 2rem 0; text-align: center; font-size: .9rem; }

/* ---------- Plan ---------- */
.race-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin-bottom: .5rem; }
.race-grid > .card { margin-bottom: 0; }
.race h2 { margin: .15rem 0 .5rem; }
.done-races { margin: 0 0 1rem; }
.week-list { display: flex; flex-direction: column; gap: .75rem; }
.week { border: 1px solid var(--line); border-radius: 10px; padding: .85rem 1rem; }
.week.current { border-color: var(--accent); }
.week.cutback { background: rgba(143, 169, 207, .05); }
.countdown { white-space: nowrap; }
.countdown-focus { color: var(--text); font-weight: 600; }
.countdown-line { font-size: .82rem; color: var(--muted); }
.countdown-race { color: var(--accent); font-weight: 600; }
.week header { display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; margin-bottom: .35rem; }
.week-facts { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; font-size: .9rem; color: var(--muted); margin-bottom: .35rem; }
.week-facts b { color: var(--text); font-weight: 600; }
.week p { margin: .25rem 0 .5rem; color: var(--muted); }
.week-note { display: flex; gap: .5rem; }
.week-note input { min-height: 36px; padding: .35rem .6rem; font-size: .9rem; }
.phase-list, .pack-steps, .stage-list { list-style: none; padding: 0; margin: 0; }
.phase-list li { padding: .5rem 0 .5rem 1rem; border-left: 2px solid var(--line); }
.phase-list li.phase-now { border-left-color: var(--accent); }
.phase-list li.phase-done { opacity: .55; }
.pack-steps li { display: flex; gap: .75rem; align-items: baseline; padding: .35rem 0; border-top: 1px solid var(--line); }
.pack-steps li:first-child { border-top: none; }
.pack-steps .pack-kg { font-weight: 600; min-width: 4rem; font-variant-numeric: tabular-nums; }
.pack-steps li.done .pack-kg { color: var(--ok); }
.stage-list li { padding: .35rem 0; }
.check-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 1.5rem; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li form { display: flex; gap: .6rem; align-items: center; padding: .3rem 0; }
.checklist li.done span { color: var(--muted); text-decoration: line-through; }
.check-btn {
  width: 26px; height: 26px; flex: 0 0 26px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ok);
  cursor: pointer; font-size: .9rem; line-height: 1; padding: 0;
}
.checklist li.done .check-btn { border-color: var(--ok); }
.note { border-top: 1px solid var(--line); padding: .6rem 0; }
.note summary { font-size: .95rem; }
.note-body { white-space: pre-wrap; color: var(--muted); font-size: .9rem; margin-top: .5rem; }
.note-edit { display: flex; flex-direction: column; gap: .5rem; margin-top: .5rem; align-items: flex-start; }
#notes .form-grid { margin-bottom: 1rem; }
.rules { margin: 0; padding-left: 1.1rem; color: var(--muted); }
.rules li { margin-bottom: .4rem; }

/* ---------- Kit ---------- */
.kit-switch .filter-bar { margin-bottom: .5rem; }
.kit-switch label { min-width: 14rem; }
.pack-meter { margin: .5rem 0 .75rem; }
.pack-meter-track { position: relative; height: 12px; background: var(--card-2); border-radius: 999px; }
.pack-meter-band { position: absolute; top: 0; bottom: 0; background: var(--band-mds); border-radius: 999px; }
.pack-meter-needle { position: absolute; top: -5px; width: 4px; height: 22px; margin-left: -2px; border-radius: 2px; background: var(--text); transition: left .3s; }
.pack-meter-needle.band-green { background: var(--ok); }
.pack-meter-needle.band-amber { background: var(--warn); }
.pack-meter-needle.band-red { background: var(--bad); }
.pack-meter-labels { position: relative; height: 1.2rem; font-size: .75rem; color: var(--muted); margin-top: .35rem; }
.pack-meter-labels span { position: absolute; transform: translateX(-50%); }
.pack-meter-labels span:first-child { left: 0; transform: none; }
.pack-meter-labels span:last-child { right: 0; left: auto; transform: none; }
.pack-meter-goal { position: absolute; top: -4px; bottom: -4px; width: 0; border-left: 2px dashed var(--accent-2); }
.pack-meter-needle { background: var(--accent); }
.pack-meter-labels span { white-space: nowrap; }
.totals-table td { padding: .45rem .4rem; }
.totals-table tr.subtotal td { font-weight: 600; border-top: 2px solid var(--line); }
.totals-table tr.grand td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--accent); color: var(--text); }
.cat-total { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.add-inline { margin-top: .5rem; }
.add-inline > summary { display: inline-block; padding: .35rem 0; }
.add-inline[open] > summary { margin-bottom: .6rem; }
.day-tabs { display: grid; grid-template-columns: repeat(7, 1fr); gap: .35rem; margin: .5rem 0 1rem; }
.day-tab {
  display: flex; flex-direction: column; align-items: center; gap: .05rem;
  padding: .45rem .2rem; min-height: 48px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card-2); color: var(--muted); font: inherit; font-size: .85rem;
}
.day-tab.active { border-color: var(--accent); color: var(--text); background: var(--card); font-weight: 600; }
.day-tab.warn .day-tab-sub { color: var(--warn); }
.day-tab-sub { font-size: .72rem; font-weight: 400; font-variant-numeric: tabular-nums; }
.day-tabs { display: none; }
.js .day-tabs { display: grid; }
.js .day-panel[data-hide] { display: none; }
.js .day-panel-title { display: none; }
.day-panel { margin-bottom: 1rem; }
.copy-day { display: inline-block; margin-top: .5rem; }
.week-note .week-pack { flex: 0 0 5.2rem; }
.week-note .week-pack input { min-height: 36px; padding: .35rem .5rem; font-size: .9rem; }
.pack-note-line { color: var(--muted); }
.theme-toggle { margin-left: auto; border-color: var(--line); }
.band-green { color: var(--ok); font-weight: 600; }
.band-amber { color: var(--warn); font-weight: 600; }
.band-red { color: var(--bad); font-weight: 600; }

/* ---------- Misc ---------- */
.flash-wrap { max-width: 1040px; margin: 1rem auto 0; padding: 0 1.25rem; }
.flash { padding: .65rem .9rem; border-radius: 8px; background: var(--card); border: 1px solid var(--line); margin-bottom: .5rem; }
.flash-ok { border-color: rgba(127, 191, 143, .45); }
.flash-err { border-color: rgba(217, 138, 134, .5); color: var(--err-text); }
.code { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .75rem; overflow-x: auto; font-size: .82rem; color: var(--muted); }
.danger-zone { border-color: rgba(217, 138, 134, .35); }
.login-main { max-width: 26rem; margin: 4rem auto; }
.footer { max-width: 1040px; margin: 0 auto; padding: 1rem 1.25rem 2.5rem; color: var(--muted); font-size: .88rem; border-top: 1px solid var(--line); }
.footer a { color: var(--muted); }
.footer a.version-whisper { text-decoration: none; color: inherit; cursor: default; }
.footer p { margin: .25rem 0; }

/* Modals */
body.modal-open { overflow: hidden; }
.modal-backdrop { position: fixed; inset: 0; background: var(--backdrop); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 100; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; }
.modal-head h2 { margin: 0; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .5rem; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .summary-grid, .summary-grid.five { grid-template-columns: 1fr 1fr; }
  .chips { grid-template-columns: 1fr 1fr; }
  .two-col, .chart-grid { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  body { font-size: 15.5px; }
  .topbar { padding: .6rem .75rem; gap: .4rem; }
  .brand { flex: 1; }
  .theme-toggle { order: 2; margin-left: 0; }
  .nav { order: 3; width: 100%; justify-content: space-between; gap: 0; }
  .day-tabs { grid-template-columns: repeat(4, 1fr); }
  .week-note { flex-wrap: wrap; }
  .week-note input[name="body"] { flex: 1 1 100%; }
  .nav a { padding: .4rem .6rem; }
  .main { padding: 1rem .75rem 1.5rem; }
  .card { padding: 1rem; }
  h1 { font-size: 1.4rem; }
  .stat-value { font-size: 1.35rem; }
  .form-grid, .filter-grid { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .show-sm { display: inline; }
  .table td, .table th { padding-left: .4rem; padding-right: .4rem; }
  .row-actions { display: flex; flex-direction: column; align-items: flex-end; gap: .1rem; }
  .row-actions .btn-icon { min-height: 32px; padding: .2rem .4rem; }
  .day-bar-track { height: 70px; }
  .activity-list li { grid-template-columns: 3rem 1fr; }
  .activity-list li .act-meta { grid-column: 2; }
  .activity-list.compact li { grid-template-columns: 1fr; gap: .1rem; }
  .activity-list.compact li .act-meta { grid-column: 1; }
  .filter-count { margin-left: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
