/* Trainingstagebuch – Gestaltung. Farben als Tokens, Dunkelmodus über System oder Einstellung. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16191d;
  --muted: #4d5560;
  --border: #cfd5dc;
  --grid: #e3e6ea;
  --accent: #0a5fb4;
  --accent-text: #ffffff;
  --accent-soft: #e3eefa;
  --accent-2: #b4410b;
  --accent-3: #0f766e;
  --accent-4: #6d28d9;
  --danger: #b3261e;
  --ok: #1d7a3a;
  --empty: #b9c0c8;
  --ring-bg: #dfe5ec;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1215;
    --surface: #1a1f25;
    --surface-2: #232a32;
    --text: #e9edf1;
    --muted: #a7b0bb;
    --border: #3a444f;
    --grid: #2a323b;
    --accent: #6cb0ff;
    --accent-text: #08131f;
    --accent-soft: #1c2d42;
    --accent-2: #ff9a5c;
    --accent-3: #4fd1c5;
    --accent-4: #c4a5ff;
    --danger: #ff8a80;
    --ok: #6fdc8c;
    --empty: #4a545f;
    --ring-bg: #2a323b;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1215;
  --surface: #1a1f25;
  --surface-2: #232a32;
  --text: #e9edf1;
  --muted: #a7b0bb;
  --border: #3a444f;
  --grid: #2a323b;
  --accent: #6cb0ff;
  --accent-text: #08131f;
  --accent-soft: #1c2d42;
  --accent-2: #ff9a5c;
  --accent-3: #4fd1c5;
  --accent-4: #c4a5ff;
  --danger: #ff8a80;
  --ok: #6fdc8c;
  --empty: #4a545f;
  --ring-bg: #2a323b;
  --shadow: none;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; z-index: 100; background: var(--surface); padding: .5rem 1rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Kopf und Navigation ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .5rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.topnav { display: flex; flex-wrap: wrap; gap: .25rem; }
.topnav a {
  color: var(--text); text-decoration: none; padding: .55rem .7rem; border-radius: 8px;
  min-height: 44px; display: inline-flex; align-items: center;
}
.topnav a:hover { background: var(--surface-2); }
.topnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.logout-form { margin-left: auto; }
.demo-banner { margin: 0; padding: .5rem 1rem; background: var(--accent-2); color: #fff; text-align: center; font-weight: 600; }
.login-step[hidden] { display: none; }
.qr-box { background: #fff; padding: 12px; border-radius: 8px; width: max-content; margin: 0 auto; }
.qr-box img { display: block; width: 200px; height: 200px; }
.secret { font-family: ui-monospace, Consolas, monospace; word-break: break-all; background: var(--surface-2); padding: .4rem .6rem; border-radius: 6px; }
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: min(100%, 380px); }
.login-box form { display: grid; gap: .75rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 1rem 1.25rem 3rem; }

.bottomnav, .fab-wrap { display: none; }

/* ---------- Karten, Kacheln, Listen ---------- */
.card, .tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
section { margin-bottom: 1rem; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.section-head h1, .section-head h2 { margin-bottom: 0; }
.crumbs { margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tile { margin: 0; }
.tile-water { grid-row: span 2; }
.tile .big { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--grid); padding: .6rem 0; display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1 1 12rem; min-width: 0; }
.list a.row-link { color: inherit; text-decoration: none; display: block; }
.list a.row-link:hover strong { text-decoration: underline; }
.list-links a { display: flex; flex-direction: column; padding: .4rem 0; text-decoration: none; font-weight: 600; min-height: 44px; }
.list-links a .muted { font-weight: 400; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: .75rem 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: .7rem .8rem; }
.kpi .label { color: var(--muted); font-size: .875rem; }
.kpi .value { font-size: 1.35rem; font-weight: 700; }
.kpi .sub { color: var(--muted); font-size: .8rem; }

.badge {
  display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); vertical-align: middle;
}
.badge-record { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }

.empty { color: var(--muted); padding: .5rem 0; }

/* ---------- Tabellen ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.note { white-space: normal; min-width: 8rem; }
caption { text-align: left; color: var(--muted); font-size: .85rem; padding-bottom: .3rem; }

/* ---------- Formulare und Knöpfe ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .75rem 1rem; align-items: start; }
.field-wide { grid-column: 1 / -1; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.field { display: flex; flex-direction: column; gap: .25rem; margin: 0 0 .25rem; min-width: 0; }
.field label, .field legend { font-weight: 600; font-size: .9rem; }
.field > label > input { margin-top: .25rem; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .65rem;
  min-height: 44px; width: 100%; min-width: 0;
}
textarea { resize: vertical; }
input[type="radio"], input[type="checkbox"] { width: 1.2rem; min-height: 1.2rem; height: 1.2rem; accent-color: var(--accent); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
.field-error { color: var(--danger); font-size: .875rem; margin: .1rem 0 0; font-weight: 600; }
.input-xl { font-size: 1.8rem; font-weight: 700; padding: .4rem .7rem; max-width: 12rem; }
.check { display: inline-flex; gap: .5rem; align-items: center; min-height: 44px; }

.btn {
  font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 44px; min-width: 44px; padding: .5rem 1rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  cursor: pointer; text-decoration: none; font-weight: 600; touch-action: manipulation;
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-small { min-height: 44px; min-width: 44px; padding: .3rem .6rem; font-size: .9rem; }
.btn-link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: .5rem 0; min-height: 44px; text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

.tabs { display: flex; flex-wrap: wrap; gap: .25rem; }
.tab {
  font: inherit; min-height: 44px; padding: .3rem .75rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.tab[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }

.segmented { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin: .25rem 0 .5rem; }
.segmented label { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; cursor: pointer; }

.nav-inline { display: flex; align-items: center; gap: .35rem; }
.nav-inline input[type="date"] { width: auto; }
.custom-range { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin: .5rem 0; }
.custom-range label { display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); }

.stepper { display: grid; grid-template-columns: 52px 1fr 52px; gap: .35rem; }
.stepper input { text-align: center; font-size: 1.25rem; font-weight: 700; }
.step { font-size: 1.4rem; padding: 0; }
.quick-reps { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .4rem; }
.set-no { margin: .25rem 0 .5rem; }
.setup { margin: .25rem 0 .5rem; border: 1px dashed var(--border); border-radius: 8px; padding: .25rem .75rem; }
.setup summary { cursor: pointer; font-weight: 600; min-height: 40px; display: flex; align-items: center; }
.setup > div { padding: .25rem 0 .5rem; }
.note-text p { margin: 0 0 .5rem; white-space: pre-wrap; }
.note-text ul { margin: 0 0 .5rem; padding-left: 1.3rem; }

.set-group { margin-bottom: 1rem; }
.set-group h3 a { color: inherit; }
.run-preview { margin: 0; font-weight: 600; min-height: 1.5em; }

.energy { display: flex; flex-wrap: wrap; gap: .35rem; }
.energy legend { margin-bottom: .25rem; }
.energy-opt {
  display: inline-flex; align-items: center; gap: .35rem; min-height: 44px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; padding: .25rem .6rem; font-weight: 400;
}
.energy-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.energy-sym { font-size: 1.4rem; line-height: 1; }
.energy-text { font-size: .85rem; }

.quick-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

details > summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
details[open] > summary { margin-bottom: .5rem; }

/* ---------- Wasser ---------- */
.water-widget { display: flex; flex-direction: column; align-items: center; gap: .9rem; }
.ring { position: relative; width: min(220px, 70vw); aspect-ratio: 1; }
.tile .ring { width: min(170px, 60vw); }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring-bg { stroke: var(--ring-bg); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 1.2rem; }
.ring-amount { font-weight: 700; font-size: 1.05rem; }
.tile .ring-amount { font-size: .9rem; }
.ring-pct { color: var(--muted); font-size: .95rem; }
.water-widget.reached .ring-pct { color: var(--ok); font-weight: 700; }
.water-widget.pulse .ring { animation: pulse .5s ease; }
@keyframes pulse { 50% { transform: scale(1.04); } }
.water-buttons { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; width: 100%; }
.water-btn { flex: 1 1 8rem; min-height: 52px; }
.water-custom { display: grid; gap: .5rem; width: 100%; max-width: 360px; }

/* ---------- Diagramme ---------- */
.chart-wrap { position: relative; width: 100%; }
.chart-table { margin-top: .5rem; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 1.25rem; z-index: 60; display: flex; flex-direction: column; gap: .5rem; width: min(92vw, 460px); }
.toast {
  background: var(--text); color: var(--bg); border-radius: 10px; padding: .55rem .9rem;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast-error { background: var(--danger); color: #fff; }
.toast-action { font: inherit; font-weight: 700; background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; min-height: 44px; padding: 0 .25rem; }

/* ---------- Satzformular als Sheet ---------- */
.sheet-head { display: none; }
.only-mobile { display: none; }

@media (min-width: 761px) {
  #sets-section { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 0 1.25rem; align-items: start; }
  #sets-section[hidden] { display: none; }
  #sets-section > .section-head { grid-column: 1 / -1; }
  #set-sheet { position: sticky; top: 72px; }
}

/* ---------- Mobil ---------- */
@media (max-width: 760px) {
  h1 { font-size: 1.4rem; }
  .topnav { display: none; }
  .topbar { padding: .6rem 1rem; }
  .container { padding: .75rem 16px calc(88px + env(safe-area-inset-bottom)); }
  .card, .tile { padding: .9rem; }
  .tiles { grid-template-columns: 1fr 1fr; gap: .75rem; }
  .tile-water { grid-column: 1 / -1; grid-row: auto; }
  #tile-training { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .bottomnav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; color: var(--muted); text-decoration: none; font-size: .75rem; }
  .bottomnav a[aria-current="page"] { color: var(--accent); font-weight: 700; }
  .bottomnav svg { width: 24px; height: 24px; fill: currentColor; }
  .fab-wrap { display: block; position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 40; }
  .fab { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); font-size: 2rem; line-height: 1; box-shadow: 0 4px 14px rgba(0,0,0,.3); cursor: pointer; }
  .fab-menu { position: absolute; right: 0; bottom: 66px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.25); display: flex; flex-direction: column; min-width: 170px; overflow: hidden; }
  .fab-menu[hidden] { display: none; }
  .fab-menu a { padding: .8rem 1rem; min-height: 48px; color: var(--text); text-decoration: none; border-top: 1px solid var(--grid); }
  .fab-menu a:first-child { border-top: 0; }
  .toasts { bottom: calc(140px + env(safe-area-inset-bottom)); }

  .only-mobile { display: inline-flex; }
  .sheet { display: none; }
  .sheet.open {
    display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 50;
    background: var(--bg); overflow-y: auto; padding: .75rem 16px calc(1rem + env(safe-area-inset-bottom));
  }
  .sheet.open .sheet-head { display: flex; align-items: center; justify-content: space-between; }
  .sheet.open .set-form { margin: 0; }
  body.sheet-open { overflow: hidden; }
}

@media (max-width: 420px) {
  .tiles { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .water-buttons { display: grid; grid-template-columns: repeat(3, 1fr); }
  .water-btn { padding: .4rem; font-size: .9rem; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { margin-bottom: .4rem; }
}

@media (prefers-reduced-motion: reduce) {
  .ring-fg { transition: none; }
  .water-widget.pulse .ring { animation: none; }
}

/* Umschalter Trainingstagebuch / Planer (Web-Version) */
.appswitch { display: inline-flex; flex: none; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.appswitch a { padding: 5px 14px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 0.95rem; }
.appswitch a:hover { background: var(--surface-2); }
.appswitch a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
