/*
 * Aevo – Gestaltung nach dem Prototyp "Trainingsplan 10 km":
 * Barlow Condensed für Überschriften und große Zahlen, IBM Plex Sans für Text,
 * IBM Plex Mono für Daten. Ruhige Grau-Grün-Fläche, vier Statusfarben (ok, warn, alert, stop).
 */
:root {
  --bg: #F2F3EF;
  --surface: #FFFFFF;
  --fg: #1C2420;
  --muted: #5F6A64;
  --line: #D9DDD6;
  --run: #0F7A63;
  --ride: #C47A12;
  --kraft: #5B6B8F;
  --rest: #8C958F;
  --ok: #2F7D3A;
  --warn: #A97A00;
  --alert: #C25A12;
  --stop: #B3372A;
  --ok-bg: #E4F0E2;
  --warn-bg: #F6EDCF;
  --alert-bg: #F8E3D3;
  --stop-bg: #F6DEDA;
  --focus: #1D5FD1;
  --font-display: "Barlow Condensed", "Arial Narrow", Arial, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;

  /* Aevo-Namen, abgeleitet */
  --brand: var(--run);
  --brand-fg: #FFFFFF;
  --track: color-mix(in srgb, var(--line) 70%, var(--bg));
  --green: var(--ok);
  --yellow: var(--warn);
  --red: var(--stop);
  --grey: var(--rest);
  --danger: var(--stop);
  --radius: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131815; --surface: #1B221E; --fg: #E6EAE5; --muted: #98A39C; --line: #2C352F;
    --run: #3FBE9F; --ride: #E3A13F; --kraft: #93A3C6; --rest: #7D877F;
    --ok: #6CC77A; --warn: #E2BC4A; --alert: #EE9659; --stop: #EE7B6D;
    --ok-bg: #1E3322; --warn-bg: #3A3118; --alert-bg: #3D2717; --stop-bg: #3F201C;
    --focus: #7DA6F2;
    --brand-fg: #0D1511;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131815; --surface: #1B221E; --fg: #E6EAE5; --muted: #98A39C; --line: #2C352F;
  --run: #3FBE9F; --ride: #E3A13F; --kraft: #93A3C6; --rest: #7D877F;
  --ok: #6CC77A; --warn: #E2BC4A; --alert: #EE9659; --stop: #EE7B6D;
  --ok-bg: #1E3322; --warn-bg: #3A3118; --alert-bg: #3D2717; --stop-bg: #3F201C;
  --focus: #7DA6F2;
  --brand-fg: #0D1511;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(88px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.app main { display: flex; flex-direction: column; gap: 16px; }
.app main > * { margin: 0; }
.loading { color: var(--muted); text-align: center; margin-top: 30vh; font-family: var(--font-data); font-size: 13px; }

/* Schrift */
h1 { font-family: var(--font-display); font-weight: 700; font-size: 40px; line-height: 1; letter-spacing: .01em; text-transform: uppercase; margin: 0; text-wrap: balance; }
h2 { font-family: var(--font-display); font-weight: 600; font-size: 21px; letter-spacing: .04em; text-transform: uppercase; margin: 0 0 10px; text-wrap: balance; }
h3 { font-size: 12.5px; font-weight: 600; margin: 18px 0 6px; color: var(--muted); letter-spacing: .05em; text-transform: uppercase; }
p { margin: 0; }
.sub { color: var(--muted); font-family: var(--font-data); font-size: 12.5px; margin-top: -8px; }
.num, time { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.note { color: var(--muted); font-size: 12.5px; }
.error { color: var(--stop); font-size: 13px; min-height: 1.4em; margin-top: 10px; }

/* Kopf */
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 24px; letter-spacing: .06em; text-transform: uppercase; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.brand .env { font-size: 12px; margin-left: 2px; }

/* Panels (Karten) */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card > p { margin: 0 0 10px; }
.card > :last-child { margin-bottom: 0; }

/* Knöpfe */
button, .button-like {
  font: inherit; font-size: 14px; cursor: pointer;
  border-radius: 4px; border: 1px solid var(--line);
  background: var(--surface); color: var(--fg);
  padding: 9px 14px;
}
button:hover, .button-like:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); font-weight: 600; width: 100%; margin-top: 16px; padding: 11px 14px; }
.primary:hover { border-color: var(--fg); opacity: .92; }
.primary:disabled { cursor: progress; }
.primary.danger { background: var(--stop); border-color: var(--stop); color: #fff; }
.secondary { background: var(--surface); color: var(--fg); font-weight: 600; margin-top: 12px; }
.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 4px 10px; font-size: 13px; }
.ghost:hover { color: var(--fg); border-color: var(--line); }
.ghost.small { padding: 2px 8px; font-size: 12.5px; }
.wide { width: 100%; }
.ghost.wide { margin-top: 8px; }
.button-like { display: block; text-align: center; margin: 14px 0 0; }
.button-like.primary { color: var(--bg); }

/* Formulare */
label { display: block; font-size: 12.5px; color: var(--muted); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 15px; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 9px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
textarea { resize: vertical; min-height: 44px; }
input[type="number"], input[inputmode="decimal"], input[inputmode="numeric"] { font-family: var(--font-data); }
.fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 12px; }
.field label { margin-top: 12px; }
.with-unit { display: flex; align-items: center; gap: 8px; }
.with-unit input { min-width: 0; }
.with-unit span { color: var(--muted); font-family: var(--font-data); font-size: 12.5px; min-width: 2.4em; }
.with-unit.narrow { max-width: 240px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
input[type="file"]:focus-visible + .button-like { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Anmeldung */
.login { margin-top: 10vh; }
.login .brand { justify-content: center; font-size: 34px; }
.login .brand img { width: 40px; height: 40px; border-radius: 10px; }
.login .sub { text-align: center; margin: 4px 0 8px; }

/* Pills und Badges (wie im Prototyp mit Punkt) */
.badge {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-family: var(--font-display); font-weight: 600; font-size: 13px; letter-spacing: .06em; text-transform: uppercase;
  border-radius: 999px; padding: 2px 10px; white-space: nowrap;
  color: var(--muted); background: var(--bg);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.alert { color: var(--alert); background: var(--alert-bg); }
.badge.stop { color: var(--stop); background: var(--stop-bg); }

/* Hinweise: bremsen statt loben */
.hint { border-radius: 4px; padding: 10px 12px; margin: 0 0 12px; border-left: 4px solid; font-size: 14px; }
.hint p { margin: 0; }
.hint button { margin-top: 8px; }
.hint.stop { background: var(--stop-bg); border-color: var(--stop); }
.hint.warn { background: var(--warn-bg); border-color: var(--warn); }
.hint.info { background: var(--ok-bg); border-color: var(--ok); margin-top: 12px; }

/* Heute (Ampel-Karte wie "Heute" im Prototyp: Statusfarbe links) */
.today { border-left-width: 6px; border-left-color: var(--rest); }
.today.l0 { border-left-color: var(--ok); }
.today.l1 { border-left-color: var(--warn); }
.today.l2 { border-left-color: var(--alert); }
.today.l3 { border-left-color: var(--stop); }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }
.headline { font-size: 16px; font-weight: 600; text-wrap: pretty; }
.light { display: flex; align-items: center; gap: 12px; }
.light .dot { display: none; }

/* Tacho (Nadel-Tacho wie im Prototyp) */
.gauges { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.gauge { text-align: center; padding: 12px 10px 14px; }
.gauge svg { width: 100%; max-width: 230px; height: auto; display: block; margin: 0 auto; }
.gauge svg text { fill: var(--muted); font-family: var(--font-data); font-size: 9px; }
.gauge svg .val { fill: var(--fg); font-family: var(--font-display); font-weight: 700; font-size: 34px; }
.gauge svg .needle { stroke: var(--fg); stroke-width: 3; stroke-linecap: round; }
.gauge svg .hub { fill: var(--fg); }
.gauge svg .tick { stroke: var(--surface); stroke-width: 2; }
.gauge svg .empty { stroke: var(--track); }
.gauge .label { font-family: var(--font-display); font-weight: 600; font-size: 17px; letter-spacing: .04em; text-transform: uppercase; margin: 2px 0 6px; }
.gauge .hint-text { margin: 0; }
.gauge .trend { font-family: var(--font-data); font-size: 11.5px; color: var(--muted); margin: 6px 0 0; }
.goal-gauge .gauge { border: 0; padding: 0; max-width: 280px; margin: 0 auto; }

/* Themen */
.themes { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.themes li { position: relative; padding: 6px 0 6px 22px; font-size: 14px; }
.themes li::before { position: absolute; left: 0; top: 6px; width: 16px; text-align: center; font-weight: 700; font-family: var(--font-data); }
.themes li.achtung::before { content: "!"; color: var(--stop); }
.themes li.gut::before { content: "✓"; color: var(--ok); }
.themes li.tipp::before { content: "→"; color: var(--run); }

/* Ziele: Fortschrittsbalken wie die Übersicht im Prototyp */
.progress-list { list-style: none; margin: 10px 0; padding: 0; }
.progress-list > li { padding: 12px 0; border-top: 1px solid var(--line); }
.progress-list > li:first-child { border-top: 0; }
.goal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 600; }
.bar { position: relative; height: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 2px; overflow: visible; }
.bar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 1px; background: var(--run); }
.bar .fill.b-top, .bar .fill.b-good { background: var(--ok); }
.bar .fill.b-mid { background: var(--warn); }
.bar .fill.b-low { background: var(--alert); }
.bar .fill.b-bad { background: var(--stop); }
.bar .mark { position: absolute; top: -5px; bottom: -5px; width: 4px; margin-left: -2px; border-radius: 2px; background: var(--fg); box-shadow: 0 0 0 2px var(--surface); }
.progress-list p.small { margin: 8px 0 4px; font-size: 13.5px; }
.log-form { margin-top: 8px; padding: 12px; border: 1px dashed var(--line); border-radius: var(--radius); }
.log-list { list-style: none; margin: 12px 0 0; padding: 0; font-size: 13px; }
.log-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); font-family: var(--font-data); }

/* Check-in */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; max-width: 320px; }
.segmented button { padding: 8px; background: var(--bg); color: var(--fg); }
.segmented button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); font-weight: 600; }

/* Schmerzskala 0–10 als Kästchen (wie im Prototyp) */
.scale { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 4px; margin-top: 4px; }
.scale input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.scale label { display: flex; align-items: center; justify-content: center; margin: 0; border: 1px solid var(--line); border-radius: 4px; padding: 8px 0; font-family: var(--font-data); font-size: 14px; color: var(--fg); cursor: pointer; background: var(--bg); }
.scale input:checked + label { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.scale input:checked + label.p-mid { background: var(--warn); border-color: var(--warn); color: #fff; }
.scale input:checked + label.p-high { background: var(--stop); border-color: var(--stop); color: #fff; }
.scale input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 2px; }
.scale-hint { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: 6px; }

.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 4px; }
.stepper output { flex: 1; text-align: center; font-family: var(--font-display); font-weight: 600; font-size: 24px; }
.step { width: 48px; height: 48px; padding: 0; font-size: 1.4rem; line-height: 1; background: var(--bg); }
.step:disabled { opacity: .4; }

/* Warnzeichen wie "Rote Flaggen" im Prototyp */
.checks { display: grid; gap: 6px; }
.check { display: flex; align-items: flex-start; gap: 10px; margin: 0; font-size: 14px; color: var(--fg); padding: 9px 12px; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; accent-color: var(--stop); }
.check:has(input:checked) { background: var(--stop-bg); border-color: var(--stop); }
.check.plain { border: 0; padding: 0; margin-top: 14px; }
.check.plain input, .check.consent input { accent-color: var(--run); }
.check.plain:has(input:checked) { background: none; }
.check.consent { margin-top: 16px; font-size: 13px; }
.check.consent:has(input:checked) { border-color: var(--ok); background: var(--ok-bg); }

/* Listen */
.entries, .measurements, .latest, .goals { list-style: none; margin: 0; padding: 0; }
.entries li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.entries li:first-child { border-top: 0; padding-top: 0; }
.entries time { color: var(--muted); font-size: 12.5px; }
.measurements li { padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.measurements li:first-child { border-top: 0; padding-top: 0; }
.m-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
.measurements a { color: var(--run); font-size: 12.5px; }
.latest li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.latest li:first-child { border-top: 0; }
.latest strong { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.goals li { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.goals li:first-child { border-top: 0; }
.goals strong { margin-right: 8px; }
.goal-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Profil: aufklappbare Abschnitte wie "Regeln" im Prototyp */
details.section { padding: 0; }
details.section > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::after { content: "›"; color: var(--muted); font-size: 22px; line-height: 1; transition: transform .15s; }
details.section[open] > summary::after { transform: rotate(90deg); }
.sec-title { font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: .04em; text-transform: uppercase; }
.sec-sum { color: var(--muted); font-family: var(--font-data); font-size: 12px; flex: 1; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec-body { padding: 0 16px 16px; border-top: 1px solid var(--line); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; margin: 0; font-size: 13.5px; color: var(--fg); padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; background: var(--bg); }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip:has(input:checked) { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.chip:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

.activity-rows { display: grid; gap: 8px; }
.activity-row { display: grid; grid-template-columns: 1fr 150px auto; gap: 8px; align-items: center; }
.activity-row button[hidden] { visibility: hidden; display: inline-block; }
@media (max-width: 420px) {
  .activity-row { grid-template-columns: 1fr auto; }
  .activity-row select { grid-column: 1 / -1; }
}

.zones { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13.5px; }
.zones th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 500; padding: 0 0 6px; }
.zones td { padding: 7px 0; border-top: 1px solid var(--line); font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.zones td:last-child { font-family: var(--font-body); }
.zones tr td:first-child { width: 5em; font-family: var(--font-display); font-weight: 600; font-size: 15px; border-left: 4px solid transparent; padding-left: 8px; }
.zones tbody tr:nth-child(1) td:first-child { border-left-color: var(--kraft); }
.zones tbody tr:nth-child(2) td:first-child { border-left-color: var(--ok); }
.zones tbody tr:nth-child(3) td:first-child { border-left-color: var(--warn); }
.zones tbody tr:nth-child(4) td:first-child { border-left-color: var(--alert); }
.zones tbody tr:nth-child(5) td:first-child { border-left-color: var(--stop); }

/* Navigation unten */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
}
.nav ul { list-style: none; display: flex; justify-content: space-around; max-width: 560px; margin: 0 auto; padding: 0; gap: 4px; }
.nav li { flex: 1; text-align: center; }
.nav button {
  width: 100%; background: none; border: 1px solid transparent; border-radius: 999px; padding: 7px 4px;
  font-family: var(--font-display); font-weight: 600; font-size: 15px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
}
.nav button[aria-current="page"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.nav button:disabled { opacity: .5; }
.nav small { display: block; font-size: 10px; font-family: var(--font-body); text-transform: none; letter-spacing: 0; }

/* Waage */
.spinner { width: 34px; height: 34px; margin: 8px auto 12px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--run); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Kurze Rückmeldung */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 6;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); background: var(--fg); color: var(--bg);
  padding: 9px 16px; border-radius: 4px; font-size: 13.5px;
  transition: opacity .2s, transform .2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .gauges { grid-template-columns: 1fr; }
  .fields { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
