:root {
  --bg: #f6f7f9; --card: #ffffff; --ink: #1d2430; --muted: #5d6878; --line: #dde2e8; --accent: #24577a;
  --warn-bg: #fff6e0; --warn: #7a5200; --bad-bg: #fde8e6; --bad: #8f1d12; --ok: #2e6b3f;
  --z0: #c9d6df; --z1: #8ec5e8; --z2: #4a90c9; --z3: #e8c15a; --z4: #e08a3c; --z5: #c4452f; --z6: #7d2a1d; --z7: #5a4a78; --zu: #eeeeee;
  font-size: 16px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--ink); line-height: 1.45; }
a { color: var(--accent); }
header.top { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header.top h1 { font-size: 1.1rem; margin: 0; font-weight: 600; }
nav.tabs { display: flex; flex-wrap: wrap; gap: .25rem; }
nav.tabs button { border: 1px solid transparent; background: none; padding: .4rem .7rem; border-radius: 6px; font: inherit; color: var(--muted); cursor: pointer; }
nav.tabs button[aria-selected="true"] { background: var(--accent); color: #fff; }
nav.tabs button:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid #f0b400; outline-offset: 2px; }
#saveState { margin-left: auto; font-size: .85rem; color: var(--muted); }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.banner { padding: .6rem .9rem; border-radius: 8px; margin: 0 0 1rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.banner.info { background: #e8f1f8; color: #1d4560; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; }
.card h2 { font-size: 1rem; margin: 0 0 .5rem; font-weight: 600; }
.card h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
.big { font-size: 2.6rem; font-weight: 600; line-height: 1.1; }
.mid { font-size: 1.4rem; font-weight: 600; }
.muted { color: var(--muted); font-size: .88rem; }
.empty { color: var(--muted); font-style: italic; }
.tag { display: inline-block; font-size: .72rem; padding: .05rem .4rem; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); vertical-align: middle; white-space: nowrap; }
.tag.measured { border-color: #9cc5a8; color: var(--ok); }
.tag.provisional, .tag.estimated, .tag.observed { border-color: #e0c27a; color: var(--warn); }
.tag.calculated, .tag.modelled, .tag.device { border-color: #a9bfd3; color: #2f5677; }
form .row, .row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: .75rem; }
label { display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); gap: .2rem; }
label.inline { flex-direction: row; align-items: center; gap: .35rem; color: var(--ink); font-size: .95rem; }
input, select, textarea { font: inherit; padding: .4rem .5rem; border: 1px solid #b9c2cd; border-radius: 6px; background: #fff; color: var(--ink); min-width: 0; }
input[type=number] { width: 7.5rem; }
input[type=checkbox], input[type=radio] { width: 1.1rem; height: 1.1rem; }
textarea { width: 100%; min-height: 3rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; margin: 0 0 .8rem; }
legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.err { color: var(--bad); font-size: .82rem; min-height: 1em; }
button { font: inherit; padding: .42rem .8rem; border-radius: 6px; border: 1px solid #9fb0c2; background: #fff; color: var(--ink); cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.small { padding: .15rem .45rem; font-size: .82rem; }
button.danger { color: var(--bad); border-color: #d9a49e; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: .35rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.scroll { overflow-x: auto; }
.zonebar { display: flex; height: 26px; border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.zonebar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem .8rem; font-size: .8rem; margin-top: .4rem; }
.legend i { display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; margin-right: .25rem; vertical-align: -1px; }
.seg { display: inline-flex; border: 1px solid #9fb0c2; border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: .2rem .6rem; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.guidance-state { font-size: 1.3rem; font-weight: 600; }
.chart { width: 100%; height: auto; display: block; }
.week { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); gap: .5rem; }
.week .daycol { background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: .4rem; min-height: 6rem; }
.session { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--z1); border-radius: 6px; padding: .3rem .4rem; margin-bottom: .35rem; font-size: .82rem; }
.session.done { opacity: .75; border-left-color: var(--ok); }
.session.skipped { text-decoration: line-through; opacity: .6; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
details > summary { cursor: pointer; color: var(--accent); }
/* morning page */
.morning { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
fieldset.q { border: 0; padding: .2rem 0; margin: 0 0 .3rem; }
fieldset.q legend { font-weight: 600; color: var(--ink); padding: 0; }
.qbtns { display: flex; gap: .4rem; flex-wrap: nowrap; }
.qends { display: flex; justify-content: space-between; gap: .5rem; width: 13.1rem; max-width: 100%; font-size: .75rem; color: var(--muted); margin-top: .15rem; }
.qends span:last-child { text-align: right; }
.qopt { flex-direction: row; }
.qopt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.qopt span { display: inline-block; width: 2.3rem; height: 2.3rem; line-height: 2.3rem; text-align: center; border: 1px solid #9fb0c2; border-radius: 50%; color: var(--ink); font-weight: 600; cursor: pointer; }
.qopt input:checked + span { background: var(--accent); color: #fff; border-color: var(--accent); }
.qopt input:focus-visible + span { outline: 3px solid #f0b400; outline-offset: 2px; }
.decision { display: inline-block; font-size: 1.5rem; font-weight: 700; letter-spacing: .04em; padding: .2rem .8rem; border-radius: 8px; margin-bottom: .3rem; }
.decision.load { background: #e3f1e6; color: var(--ok); }
.decision.maintain { background: #e8f1f8; color: #1d4560; }
.decision.recover { background: var(--warn-bg); color: var(--warn); }
.decision.reassess { background: #efe9f6; color: #4d3a6b; }
.phase { text-align: center; padding: .8rem; border-radius: 10px; }
.phase.lying { background: #e8f1f8; } .phase.standing { background: #fff1d6; }
.phase .big { font-size: 3.4rem; }
ol.steps { padding-left: 1.2rem; } ol.steps li { margin: .2rem 0; }
.result table td:first-child { color: var(--muted); }
#themeBtn { margin-left: .25rem; }

/* ---------- optional dark mode ---------- */
[data-theme="dark"] {
  --bg: #12161c; --card: #1b2129; --ink: #e3e8ee; --muted: #a0acba; --line: #2f3843; --accent: #3f82b8;
  --warn-bg: #3a2f12; --warn: #f0c868; --bad-bg: #3d1d19; --bad: #ff9c8f; --ok: #6cc28a; --zu: #3a424c;
  color-scheme: dark;
}
[data-theme="dark"] a, [data-theme="dark"] details > summary { color: #8cc3ec; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { background: #11161c; color: var(--ink); border-color: #45515f; }
[data-theme="dark"] button { background: #232b35; color: var(--ink); border-color: #4a5766; }
[data-theme="dark"] button.primary, [data-theme="dark"] nav.tabs button[aria-selected="true"], [data-theme="dark"] .seg button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
[data-theme="dark"] nav.tabs button { background: none; border-color: transparent; color: var(--muted); }
[data-theme="dark"] button.danger { color: var(--bad); border-color: #7a3a33; }
[data-theme="dark"] .banner.info { background: #16293a; color: #a9cdf0; }
[data-theme="dark"] .week .daycol { background: #161b22; }
[data-theme="dark"] .session { background: #1f262f; }
[data-theme="dark"] .qopt span { border-color: #5a6878; color: var(--ink); }
[data-theme="dark"] .qopt input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="dark"] .decision.load { background: #16301f; color: #7fd39a; }
[data-theme="dark"] .decision.maintain { background: #16293a; color: #9cc8ee; }
[data-theme="dark"] .decision.reassess { background: #2a2238; color: #c8b4ec; }
[data-theme="dark"] .phase.lying { background: #16293a; } [data-theme="dark"] .phase.standing { background: #3a2f12; }
[data-theme="dark"] .tag.measured { border-color: #3f7a52; } [data-theme="dark"] .tag.calculated, [data-theme="dark"] .tag.modelled, [data-theme="dark"] .tag.device { border-color: #3d5a75; color: #9cc0e0; }
[data-theme="dark"] tr[style*="#eaf4ec"] { background: #1d3324 !important; }
[data-theme="dark"] tr[style*="#fbefd5"] { background: #3a2f12 !important; }
/* charts: lighter versions of the same colours on a dark background */
[data-theme="dark"] .chart line[stroke="#e6e9ee"] { stroke: #2c3542; }
[data-theme="dark"] .chart text[fill="#5d6878"] { fill: #9aa7b6; }
[data-theme="dark"] .chart [stroke="#24577a"] { stroke: #6fb0e0; } [data-theme="dark"] .chart [fill="#24577a"] { fill: #6fb0e0; }
[data-theme="dark"] .chart [stroke="#b8c4d0"] { stroke: #5a6b7d; } [data-theme="dark"] .chart [fill="#b8c4d0"] { fill: #5a6b7d; }
[data-theme="dark"] .chart [stroke="#c4452f"] { stroke: #ee7a64; } [data-theme="dark"] .chart [fill="#c4452f"] { fill: #ee7a64; }
[data-theme="dark"] .chart [stroke="#2e6b3f"] { stroke: #6cc28a; } [data-theme="dark"] .chart [fill="#2e6b3f"] { fill: #6cc28a; }
[data-theme="dark"] .chart [stroke="#7a5200"] { stroke: #e0b050; } [data-theme="dark"] .chart [fill="#7a5200"] { fill: #e0b050; }

@media (max-width: 640px) {
  main { padding: .6rem; }
  header.top { position: static; }
  .big { font-size: 2.1rem; }
  .week { grid-template-columns: 1fr; }
  input[type=number] { width: 6.5rem; }
  .morning { grid-template-columns: 1fr; }
  .qopt span { width: 2.6rem; height: 2.6rem; line-height: 2.6rem; }
  .qends { width: 14.6rem; }
}
