:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1b1b1a;
  --muted: #6d6a64;
  --line: #e1ded7;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --accent-soft: #fbe6dc;
  --ok: #2b8a3e;
  --danger: #c92a2a;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --surface: #1e1e1d;
    --surface-2: #2a2a28;
    --text: #f1efea;
    --muted: #9a968e;
    --line: #33322f;
    --accent: #ff7a3d;
    --accent-text: #1b0d05;
    --accent-soft: #3a2116;
    --ok: #69db7c;
    --danger: #ff8787;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px 24px;
}

main.wide { max-width: 1100px; }

h1 { font-size: 26px; margin: 4px 0 16px; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 24px 0 10px; }

a { color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Kopfzeile mit Zurück-Knopf ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.topbar h1 { margin: 0; flex: 1; font-size: 22px; }
.back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: -10px;
  border-radius: 50%;
  text-decoration: none;
  font-size: 28px;
  line-height: 1;
}
.back:active { background: var(--surface-2); }

/* ---------- Startseite ---------- */
.days {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.day {
  display: block;
  padding: 16px 14px;
  min-height: 108px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  position: relative;
}
.day:active { transform: scale(0.98); }
.day .num { font-size: 13px; color: var(--muted); font-weight: 600; }
.day .name { display: block; font-size: 19px; font-weight: 700; margin: 2px 0 10px; line-height: 1.2; }
.day .last { font-size: 13px; color: var(--muted); }
.day.next { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.day.next .num::after {
  content: "Als Nächstes";
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
}

.quick {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.quick a {
  display: flex;
  flex-direction: column;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 650;
}
.quick a span { font-weight: 400; font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ---------- Formulare ---------- */
input, textarea, select, button { font: inherit; color: inherit; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="date"], input[type="password"], textarea, select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 17px;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
textarea { min-height: 80px; resize: vertical; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.btn:disabled { opacity: 0.55; }
.btn.secondary { background: var(--surface-2); color: var(--text); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { position: relative; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span {
  display: inline-block;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  cursor: pointer;
}
.chips input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
.chips input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---------- Trainings-Eingabe ---------- */
.date-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.date-row input { width: auto; min-height: 40px; font-size: 15px; padding: 6px 10px; }

.draft-note {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  border-radius: 10px;
  background: var(--accent-soft);
  font-size: 14px;
}
.draft-note span { flex: 1; }
.linkbtn {
  border: 0;
  background: none;
  padding: 6px 4px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.ex {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 12px 8px;
  margin-bottom: 10px;
}
.ex-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.ex-title { flex: 1; min-width: 0; }
.ex-name { font-weight: 700; font-size: 17px; }
.ex-meta { font-size: 13px; color: var(--muted); }
.tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  vertical-align: 2px;
}
.skip {
  border: 1px solid var(--line);
  background: none;
  border-radius: 99px;
  padding: 5px 10px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.ex.skipped .rows, .ex.skipped .ex-name { opacity: 0.35; }
.ex.skipped .rows { pointer-events: none; }
.ex.skipped .skip { background: var(--text); color: var(--bg); border-color: var(--text); }

.set-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.set-row .no { font-size: 13px; color: var(--muted); text-align: center; }
.unit-input { position: relative; display: block; }
.unit-input input { padding-right: 54px; text-align: right; font-variant-numeric: tabular-nums; }
.unit-input em {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-style: normal;
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
}
.unit-input input::placeholder { color: var(--muted); opacity: 0.7; font-size: 14px; }
.unit-input input[data-k="w"] { padding-right: 42px; }

.cardio-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin: 18px 0 10px;
}
.switch { display: flex; align-items: center; gap: 12px; font-weight: 700; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }
.cardio-fields { margin-top: 12px; display: grid; gap: 12px; }
.cardio-box.off .cardio-fields { display: none; }
.minutes { max-width: 160px; }

.savebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  z-index: 20;
}
.savebar .btn { max-width: 608px; margin: 0 auto; }

/* ---------- Untere Navigation ---------- */
#tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 10;
}
#tabs[hidden] { display: none; }
#tabs a {
  flex: 1;
  max-width: 220px;
  padding: 14px 8px 16px;
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  color: var(--muted);
}
#tabs a.active { color: var(--accent); }

/* ---------- Anmeldung ---------- */
.login { max-width: 360px; margin: 18vh auto 0; }
.login p { margin: -8px 0 20px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 8px 0; }

/* ---------- Auswertung ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.chart-wrap { position: relative; height: 260px; }
.empty { padding: 30px 10px; text-align: center; color: var(--muted); }

table.list { width: 100%; border-collapse: collapse; font-size: 15px; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 4px; }
table.list td { padding: 8px 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.list td.num, table.list th.num { text-align: right; }

/* ---------- Hinweis-Meldung ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: 99px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
  max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); color: #fff; }

@media (min-width: 720px) {
  .days { grid-template-columns: repeat(4, 1fr); }
  .chart-wrap { height: 340px; }
}
