:root {
  --bg: #f6f7f9; --card: #ffffff; --text: #14181f; --muted: #5d6675; --line: #e3e6eb;
  --accent: #16a34a; --accent-soft: #dcfce7; --warn: #d97706; --bad: #dc2626; --blue: #2563eb;
  --p: #2563eb; --c: #d97706; --f: #9333ea; --track: #eceff3;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --card: #171b21; --text: #e7eaee; --muted: #98a1ae; --line: #262c35;
    --accent: #22c55e; --accent-soft: #14301f; --warn: #f59e0b; --bad: #f87171; --blue: #60a5fa;
    --p: #60a5fa; --c: #fbbf24; --f: #c084fc; --track: #232932;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
nav button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.datebar { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.datebar button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 5px 10px; cursor: pointer; }
.datebar input { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 4px 8px; }

main { max-width: 1150px; margin: 0 auto; padding: 18px 16px 60px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; min-width: 0; }
.card h2 { margin: 0 0 10px; font-size: 15px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h2 .muted { font-weight: 400; font-size: 13px; }
.span2 { grid-column: span 2; }
@media (max-width: 700px) { .span2 { grid-column: auto; } .datebar { margin-left: 0; } }
.hero { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: baseline; margin-bottom: 14px; }
.hero .big { font-size: 28px; font-weight: 700; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

.stat { font-size: 26px; font-weight: 700; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; font-size: 14px; }
.kv b { font-weight: 600; }

.bar { margin: 9px 0; }
.bar .lbl { display: flex; justify-content: space-between; font-size: 13px; }
.bar .track { height: 9px; background: var(--track); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.bar .fill { height: 100%; border-radius: 99px; background: var(--accent); }
.bar.over .fill { background: var(--bad); }

input[type=number], input[type=text], input[type=time], textarea { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 8px; min-width: 0; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.btn { border: 0; background: var(--accent); color: #fff; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 600; }
.btn.ghost, .ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 0 4px; }
.x:hover { color: var(--bad); }

.checks label { display: flex; gap: 10px; align-items: center; padding: 5px 0; cursor: pointer; }
.checks input { width: 18px; height: 18px; accent-color: var(--accent); }
.checks label.done span { color: var(--muted); text-decoration: line-through; }

table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
.tablewrap { overflow-x: auto; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 4px 11px; cursor: pointer; font-size: 13px; text-align: left; }
.chip:hover { border-color: var(--accent); }
.chip small { color: var(--muted); }

.mealform { display: grid; grid-template-columns: 1fr repeat(4, 70px) auto; gap: 6px; align-items: center; }
@media (max-width: 700px) { .mealform { grid-template-columns: 1fr 1fr; } .mealform input[name=name] { grid-column: span 2; } }

.ex { border-top: 1px solid var(--line); padding: 10px 0; }
.ex:first-of-type { border-top: 0; }
.ex .head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.sets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.set { display: flex; gap: 4px; align-items: center; font-size: 13px; }
.set input { width: 62px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 6px 8px; border-radius: 8px; }
.timeline li.now { background: var(--accent-soft); font-weight: 600; }
.timeline li.past { color: var(--muted); }
.timeline time { font-variant-numeric: tabular-nums; color: var(--muted); }

.lib { display: grid; grid-template-columns: 240px 1fr; gap: 14px; align-items: start; }
@media (max-width: 800px) { .lib { grid-template-columns: 1fr; } }
.lib nav { flex-direction: column; flex-wrap: nowrap; gap: 0; }
.lib nav h3 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 12px 0 4px; }
.lib nav a { padding: 4px 8px; border-radius: 6px; text-decoration: none; color: var(--text); font-size: 14px; }
.lib nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.md h1 { font-size: 24px; margin: 0 0 12px; }
.md h2 { font-size: 18px; margin: 22px 0 8px; display: block; }
.md h3 { font-size: 15px; margin: 18px 0 6px; }
.md blockquote { margin: 10px 0; padding: 8px 12px; border-left: 3px solid var(--warn); background: var(--bg); border-radius: 6px; }
.md code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md ul { padding-left: 22px; }
.md li.task { list-style: none; margin-left: -20px; }
.md a.wl { text-decoration: none; border-bottom: 1px dashed currentColor; }

svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 5px; border-radius: 2px; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: .95; }
@media (max-width: 480px) { .timeline li { grid-template-columns: 78px 1fr; gap: 8px; padding: 6px 4px; } .timeline time { font-size: 13px; } }
.headscale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.headscale button { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 8px; padding: 8px 0; font: inherit; font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
.headscale button:hover { border-color: var(--accent); }
.headscale button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
