:root {
  --bg: #f5f6f2;
  --surface: #ffffff;
  --text: #1b1d1f;
  --muted: #5f6368;
  --border: #dfe2dc;
  --accent: #2e7d5a;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --radius: 14px;
  --gap: 16px;
  /* Task-6-Review: eine Quelle für die Tabbar-Höhe statt zweier getrennter Annahmen in .tabbar
     (implizit über Innenabstand/Inhalt) und .chat-form (vorher die literale Zahl 58px). */
  --tabbar-height: 58px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1f2226;
    --text: #eceeea;
    --muted: #a3a8ad;
    --border: #33373c;
    --accent: #5cbf8f;
    --accent-text: #0d1a13;
    --danger: #f2877f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + var(--gap)) var(--gap)
           calc(env(safe-area-inset-bottom) + 96px);
}

h1 { font-size: 1.6rem; margin: 0 0 8px; }
h2 { font-size: 1.2rem; margin: 0 0 8px; }

.page-header { margin-bottom: var(--gap); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
  margin-bottom: var(--gap);
}

.center { text-align: center; }
.stack { display: grid; gap: 12px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn[disabled] { opacity: 0.6; }

form { margin: 0; }

input[type="text"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row .btn { width: auto; flex: 1 1 auto; }
.badge { font-size: 0.8rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.copy-box { word-break: break-all; user-select: all; font-family: ui-monospace, monospace; font-size: 0.9rem; }

/* --- Teilplan 2: Formulare, Tabbar, Listen --- */
input[type="number"], input[type="date"], input[type="url"], input[type="search"], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 96px; resize: vertical; }

.field { display: grid; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field-label { font-weight: 600; font-size: 0.95rem; padding: 0; }
.field-error { color: var(--danger); margin: 0; font-size: 0.9rem; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
.chip input { margin: 0; }
.chip:has(input:checked) { border-color: var(--accent); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
}
.tab {
  flex: 1; text-align: center; padding: 10px 4px;
  color: var(--muted); text-decoration: none; font-size: 0.85rem; font-weight: 600;
}
.tab.is-active { color: var(--accent); }
.tab.is-disabled { opacity: 0.4; }

.back { display: inline-block; margin-bottom: 4px; color: var(--accent); text-decoration: none; }
.nav-list a { display: flex; justify-content: space-between; color: var(--text); text-decoration: none; }
.item-title { font-weight: 600; }
.item-meta { color: var(--muted); font-size: 0.9rem; }
.badge-warn { color: var(--danger); border-color: var(--danger); }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: var(--gap); }
.filters a { white-space: nowrap; width: auto; min-height: 40px; }
.filters a.is-active { border-color: var(--accent); color: var(--accent); }

.progress { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 var(--gap); }
.progress li { flex: 1; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; text-indent: -999px; }
.progress li.is-done, .progress li.is-current { background: var(--accent); }

.nav-list-link { display: block; color: var(--text); text-decoration: none; }
.row > .field { flex: 1 1 120px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { text-align: left; padding: 6px 4px; border-top: 1px solid var(--border); }
.data-table th { color: var(--muted); font-weight: 600; border-top: 0; }

.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale-option { position: relative; }
.scale-option input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.scale-option span {
  display: flex; align-items: center; justify-content: center; min-height: 44px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-weight: 600;
}
.scale-option input:checked + span { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.scale-option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.scale-legend { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.8rem; }
details.field summary { cursor: pointer; }

.card-link { display: block; color: var(--text); text-decoration: none; border-color: var(--accent); }
.readiness { display: flex; align-items: baseline; gap: 12px; margin: 0; }
.readiness-score { font-size: 2.4rem; font-weight: 700; }
.readiness-gut .readiness-score { color: var(--accent); }
.readiness-niedrig .readiness-score { color: var(--danger); }
.hint-list { margin: 0; padding-left: 18px; color: var(--muted); font-size: 0.9rem; }
.load-meta { color: var(--muted); font-size: 0.9rem; margin: 0; }

.day-card.is-today { border-color: var(--accent); }
.session + .session { margin-top: var(--gap); padding-top: var(--gap); border-top: 1px solid var(--border); }
.session-ruhe .item-title { color: var(--muted); }

/* --- Teilplan 6: Trainingsmodus --- */
.sync-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 20px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.sync-status.sync-ok { color: var(--accent); }
.sync-status.sync-pending { color: var(--muted); }
.sync-status.sync-error { color: var(--danger); }
.sync-dismiss { width: auto; min-height: 44px; padding: 6px 16px; font-size: 0.85rem; }

.training-list { display: grid; gap: 12px; }
.training-list > li { border-top: 0; padding: 0; }
.training-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
}
.training-item.is-done { border-color: var(--accent); }
.training-item.is-done .item-title { color: var(--accent); }

.item-toggle {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  min-height: 44px;
  padding: 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.item-load-hint, .item-notes { padding: 0 12px; }
.item-watch { margin: 0 12px 12px; width: auto; display: inline-flex; }

.item-details { padding: 0 12px 12px; }
.item-details summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }

/* --- Teilplan 7: Coach-Chat --- */
/* Zusätzlicher Platz unten auf der Coach-Seite für die fixierte Eingabe (siehe .chat-form) –
   überschreibt die normale Tabbar-Reserve von .page, damit #chat-live/#chat-status/.chat-form
   nicht von der Tabbar verdeckt werden. */
.page:has(#chat-form) {
  padding-bottom: calc(env(safe-area-inset-bottom) + 180px);
}
.chat-log {
  display: grid;
  gap: 10px;
}
.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.chat-bubble .chat-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-bubble .chat-time {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}
.chat-user {
  margin-left: auto;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.chat-user .chat-time { color: inherit; opacity: 0.8; }
.chat-assistant { margin-right: auto; }
.chat-note {
  margin: 0 auto;
  max-width: 95%;
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.chat-action {
  max-width: 85%;
  margin: -2px auto 0 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px dashed var(--border);
}
.chat-action .row .btn { width: auto; flex: 1 1 120px; }

/* Fest über der Tabbar, über die ganze Breite, mit iOS-Safe-Area unten. */
.chat-form {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-height));
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 560px;
  margin: 0 auto;
  padding: 8px var(--gap);
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.chat-form textarea {
  flex: 1 1 auto;
  min-height: 44px;
  max-height: 120px;
  resize: none;
}
.chat-form .btn { width: auto; flex: 0 0 auto; }

/* --- Teilplan 8: Verlauf (Diagramme + Wochenliste) --- */
.chart { width: 100%; height: auto; display: block; }
.chart-bar { fill: var(--accent); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-axis-label { fill: var(--muted); font-size: 10px; text-anchor: middle; }

.history-day + .history-day { margin-top: var(--gap); padding-top: var(--gap); border-top: 1px solid var(--border); }
