/* ============================================================
   NutriKompass – Stylesheet
   Dark-first, helles Schema via prefers-color-scheme.
   Farbrollen basieren auf einer CVD-validierten Chart-Palette.
   ============================================================ */

:root {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --good: #0ca30c;
  --good-soft: rgba(12, 163, 12, 0.15);
  --warn: #fab219;
  --warn-soft: rgba(250, 178, 25, 0.14);
  --crit: #d03b3b;
  --crit-soft: rgba(208, 59, 59, 0.16);
  --radius: 16px;
  --radius-s: 10px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f9f9f7;
    --surface: #fcfcfb;
    --surface-2: #f0efec;
    --ink: #0b0b0b;
    --ink-2: #52514e;
    --muted: #898781;
    --grid: #e1e0d9;
    --border: rgba(11, 11, 11, 0.10);
    --accent: #2a78d6;
    --accent-soft: rgba(42, 120, 214, 0.12);
    --s1: #2a78d6;
    --s2: #eb6834;
    --s3: #1baf7a;
    --shadow: 0 8px 24px rgba(11, 11, 11, 0.07);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--ink);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.65rem; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0.4em 0 0.9em; }
small, .small { font-size: 0.85rem; }
.muted { color: var(--ink-2); }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.8em; }
.opt { color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.spacer { flex: 1; }

/* ---------- Topbar & Navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1160px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 18px;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-size: 1.05rem; color: var(--ink); font-weight: 500;
}
.brand:hover { text-decoration: none; }
.brand b { font-weight: 700; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
}
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 13px; border-radius: 10px;
  color: var(--ink-2); font-size: 0.9rem;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-logout { color: var(--muted); display: flex; padding: 8px; border-radius: 10px; }
.nav-logout:hover { color: var(--crit); background: var(--crit-soft); }

/* ---------- Layout ---------- */
.container { max-width: 1160px; margin: 0 auto; padding: 26px 20px 60px; }
.footer {
  max-width: 1160px; margin: 0 auto; padding: 18px 20px 28px;
  display: flex; gap: 14px; flex-wrap: wrap;
  color: var(--muted); font-size: 0.8rem;
  border-top: 1px solid var(--border);
}
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.page-head p { margin-bottom: 0; }
.grid-main {
  display: grid; grid-template-columns: 1.25fr 1fr;
  gap: 18px; align-items: start; margin-top: 18px;
}
.grid-main .col { display: grid; gap: 18px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 10px;
}
.card-head h2 { margin: 0; }
.card-danger { border-color: color-mix(in srgb, var(--crit) 45%, var(--border)); }
.sep { border: 0; border-top: 1px solid var(--border); margin: 22px 0 18px; }

/* ---------- Flash & Banner ---------- */
.flash {
  padding: 12px 16px; border-radius: var(--radius-s);
  margin-bottom: 14px; font-size: 0.92rem;
  border: 1px solid var(--border); background: var(--surface);
}
.flash ul { margin: 6px 0 0; padding-left: 20px; }
.flash-success { border-color: color-mix(in srgb, var(--good) 50%, transparent); background: var(--good-soft); }
.flash-error { border-color: color-mix(in srgb, var(--crit) 50%, transparent); background: var(--crit-soft); }
.flash-warn { border-color: color-mix(in srgb, var(--warn) 50%, transparent); background: var(--warn-soft); }
.flash-info { border-color: color-mix(in srgb, var(--accent) 50%, transparent); background: var(--accent-soft); }

/* ---------- Stat-Kacheln ---------- */
.stat-row {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  display: flex; flex-direction: column; gap: 3px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 0.8rem; color: var(--ink-2); display: flex; align-items: center; gap: 7px; }
.stat-value { font-size: 1.75rem; font-weight: 650; letter-spacing: -0.02em; }
.stat-value small { font-size: 0.95rem; font-weight: 500; color: var(--ink-2); }
.stat-sub { font-size: 0.8rem; color: var(--muted); }
.stat-hero { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.stat-donut { flex-direction: row; align-items: center; gap: 14px; }
.stat-donut canvas { max-width: 110px; max-height: 110px; }
.stat-donut-side { display: grid; gap: 6px; }
.chip-line {
  font-size: 0.8rem; color: var(--ink-2);
  background: var(--surface-2); border-radius: 999px; padding: 4px 11px;
  white-space: nowrap;
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot-s1 { background: var(--s1); }
.dot-s2 { background: var(--s2); }
.dot-s3 { background: var(--s3); }
.dot-muted { background: var(--muted); }
.legend { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--ink-2); flex-wrap: wrap; }
.legend .dot { margin-left: 8px; }
.legend .dot:first-child { margin-left: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink);
  font: inherit; font-size: 0.92rem; font-weight: 550;
  cursor: pointer; text-decoration: none;
  transition: filter 0.12s ease, background 0.12s ease;
}
.btn:hover { filter: brightness(1.12); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn-good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.btn-bad { background: var(--crit-soft); border-color: color-mix(in srgb, var(--crit) 45%, transparent); }
.btn-small { padding: 6px 12px; font-size: 0.83rem; border-radius: 9px; }
.btn-block { width: 100%; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Formulare ---------- */
label { display: block; font-size: 0.88rem; color: var(--ink-2); font-weight: 550; }
input, select, textarea {
  width: 100%; margin-top: 5px;
  padding: 10px 12px;
  font: inherit; color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  outline-offset: 1px; border-color: var(--accent);
}
input[type="checkbox"], input[type="radio"] { width: auto; margin: 0; accent-color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.stack-form { display: grid; gap: 12px; }
.stack-form .btn { justify-self: start; }
.check-label { display: flex; gap: 10px; align-items: flex-start; font-weight: 450; }

/* Ziel-Karten */
.goal-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.goal-card { cursor: pointer; }
.goal-card input { position: absolute; opacity: 0; pointer-events: none; }
.goal-card-body {
  display: flex; flex-direction: column; gap: 5px;
  height: 100%; padding: 14px 15px;
  border: 1.5px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface-2); transition: border-color 0.12s ease;
}
.goal-card-body strong { color: var(--ink); }
.goal-card-body small { color: var(--muted); font-weight: 400; line-height: 1.45; }
.goal-card input:checked + .goal-card-body {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.goal-pcts { margin-top: 14px; max-width: 420px; }

/* Tages-Chips */
.days-fieldset { border: 0; padding: 0; margin: 14px 0 0; }
.days-fieldset legend { font-size: 0.88rem; color: var(--ink-2); font-weight: 550; padding: 0 0 6px; }
.day-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 7px 14px;
  border: 1.5px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); font-weight: 550;
}
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- Wizard ---------- */
.wizard-wrap { max-width: 780px; margin: 0 auto; }
.wizard-steps {
  list-style: none; display: flex; gap: 6px;
  padding: 0; margin: 0 0 16px;
}
.wizard-steps li {
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 10px;
  font-size: 0.83rem; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
}
.wizard-steps li span {
  display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-2); font-weight: 650; font-size: 0.78rem; flex: none;
}
.wizard-steps li.active { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.wizard-steps li.active span { background: var(--accent); color: #fff; }
.wizard-steps li.done { color: var(--good); }
.wizard-steps li.done span { background: var(--good-soft); color: var(--good); }
.wizard-nav { display: flex; align-items: center; gap: 10px; margin-top: 22px; }

/* ---------- Plan-Editor ---------- */
.plan-editor { display: grid; gap: 10px; }
.plan-day {
  border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface-2); padding: 12px 14px;
}
.plan-day-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.plan-day-head strong { font-size: 0.95rem; }
.plan-day-head .muted { font-size: 0.8rem; }
.plan-row {
  display: grid; grid-template-columns: 1.6fr 1.1fr 90px 38px;
  gap: 8px; margin-top: 10px; align-items: center;
}
.plan-row select, .plan-row input { margin-top: 0; background: var(--surface); }
.plan-row-remove {
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  border-radius: 9px; height: 40px; cursor: pointer; font-size: 1rem;
}
.plan-row-remove:hover { color: var(--crit); border-color: var(--crit); }
.plan-empty { color: var(--muted); font-size: 0.83rem; margin: 8px 0 0; }

/* ---------- Check-ins ---------- */
.checkin-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.checkin-item {
  border: 1px solid var(--border); border-radius: var(--radius-s);
  padding: 12px 14px; background: var(--surface-2);
}
.checkin-info { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.checkin-date {
  font-size: 0.75rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted);
}
.checkin-date.is-today { color: var(--accent); }
.checkin-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.checkin-edit {
  display: grid; grid-template-columns: 110px 1fr auto;
  gap: 10px; align-items: end; margin-top: 10px;
}
.checkin-edit input, .checkin-edit select { background: var(--surface); }
.today-sessions { margin-top: 14px; display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.badge {
  font-size: 0.75rem; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2);
}
.badge-absolviert { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge-extra { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-angepasst { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-ausgelassen { background: var(--crit-soft); color: var(--crit); border-color: transparent; }
.badge-today { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-undo {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 0.72rem; padding: 0 0 0 6px; opacity: 0.65;
}
.badge-undo:hover { opacity: 1; }
.empty-note { color: var(--muted); padding: 8px 0; }

/* Extra-Form */
.extra-form { border: 1px dashed var(--border); border-radius: var(--radius-s); padding: 14px; margin-bottom: 14px; }
.extra-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }

/* ---------- Segmented Control ---------- */
.seg {
  display: inline-flex; gap: 3px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px;
}
.seg-btn {
  border: 0; background: transparent; color: var(--ink-2);
  font: inherit; font-size: 0.84rem; font-weight: 550;
  padding: 7px 13px; border-radius: 8px; cursor: pointer;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: var(--accent); color: #fff; }

/* Ernährungs-Check */
.intake-row { border-top: 1px solid var(--border); padding: 12px 0; }
.intake-row:first-of-type { border-top: 0; }
.intake-head { display: flex; gap: 12px; align-items: baseline; margin-bottom: 8px; }
.intake-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.intake-kcal { display: flex; gap: 6px; align-items: center; }
.intake-kcal input { width: 170px; margin-top: 0; }

/* ---------- Gewicht ---------- */
.weight-now { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.weight-form { display: flex; gap: 8px; }
.weight-form input { margin-top: 0; }
.delta { font-size: 0.88rem; font-weight: 600; }
.delta-down { color: var(--s3); }
.delta-up { color: var(--s2); }
.chart-box { margin-top: 14px; position: relative; height: 200px; }
.chart-tall { height: 260px; }
.chart-box canvas { width: 100% !important; height: 100% !important; }

/* ---------- Wochen-Strip ---------- */
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.week-day {
  display: flex; flex-direction: column; gap: 3px; align-items: center;
  padding: 10px 6px; border-radius: var(--radius-s);
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--ink); text-align: center;
}
.week-day:hover { text-decoration: none; border-color: var(--accent); }
.week-day.is-today { border-color: var(--accent); background: var(--accent-soft); }
.week-day-name { font-size: 0.72rem; font-weight: 650; text-transform: uppercase; color: var(--muted); }
.week-day.is-today .week-day-name { color: var(--accent); }
.week-day-kcal { font-weight: 650; font-size: 0.92rem; }
.week-day-train { font-size: 0.7rem; color: var(--muted); }

/* ---------- Tabellen ---------- */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.plan-table th, .plan-table td, .sci-table th, .sci-table td {
  text-align: left; padding: 10px 12px;
  border-bottom: 1px solid var(--grid);
  vertical-align: top;
}
.plan-table thead th, .sci-table thead th {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.plan-table tfoot td { border-bottom: 0; color: var(--ink-2); }
.plan-table tr.is-today td { background: var(--accent-soft); }
.plan-table td:nth-child(n+3) { font-variant-numeric: tabular-nums; white-space: nowrap; }
.plan-session { display: block; font-size: 0.85rem; }
.kv-table td { padding: 7px 0; border-bottom: 1px solid var(--grid); font-size: 0.88rem; }
.kv-table tr:last-child td { border-bottom: 0; }
.kv-table td:first-child { color: var(--ink-2); padding-right: 14px; }
.kv-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Verlauf ---------- */
.adj-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.adj-list li {
  display: grid; grid-template-columns: auto auto 1fr; gap: 4px 12px; align-items: baseline;
  border-bottom: 1px solid var(--grid); padding-bottom: 10px; font-size: 0.87rem;
}
.adj-list li:last-child { border-bottom: 0; }
.adj-date { color: var(--muted); white-space: nowrap; }
.adj-delta { font-weight: 650; font-variant-numeric: tabular-nums; }
.adj-note { grid-column: 1 / -1; color: var(--ink-2); }
.export-links { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Landing & Auth ---------- */
.landing {
  display: grid; grid-template-columns: 1.35fr 1fr;
  gap: 34px; align-items: start; padding-top: 26px;
}
.eyebrow {
  display: inline-block; font-size: 0.75rem; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 999px; padding: 5px 13px; margin-bottom: 14px;
}
.landing-hero h1 { font-size: 2.3rem; margin-bottom: 0.4em; }
.landing-hero h1 em { font-style: normal; color: var(--accent); }
.lead { font-size: 1.05rem; color: var(--ink-2); }
.feature-list { list-style: none; padding: 0; margin: 20px 0; display: grid; gap: 12px; }
.feature-list li {
  padding: 12px 16px 12px 40px; position: relative;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-s); font-size: 0.92rem; color: var(--ink-2);
}
.feature-list li::before {
  content: "✓"; position: absolute; left: 15px; top: 11px;
  color: var(--good); font-weight: 700;
}
.feature-list strong { color: var(--ink); }
.auth-card { position: sticky; top: 80px; }
.auth-card form { display: grid; gap: 13px; margin-top: 6px; }
.auth-alt { margin: 14px 0 0; font-size: 0.88rem; color: var(--ink-2); }
.auth-single { max-width: 460px; margin: 30px auto 0; }

/* ---------- Wissenschaft ---------- */
.sci .card { margin-top: 18px; }
.sci-toc { display: flex; gap: 6px 16px; flex-wrap: wrap; align-items: baseline; font-size: 0.88rem; }
.formula {
  display: grid; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-s); padding: 14px 16px; margin: 10px 0 14px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.86rem; overflow-x: auto;
}
.ref-list { padding-left: 22px; display: grid; gap: 8px; font-size: 0.86rem; color: var(--ink-2); }
.sci ul { margin: 0.4em 0 0.9em; padding-left: 22px; }
.sci li { margin-bottom: 0.4em; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .grid-main { grid-template-columns: 1fr; }
  .landing { grid-template-columns: 1fr; }
  .auth-card { position: static; }
  .landing-hero h1 { font-size: 1.9rem; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .container { padding: 18px 14px 96px; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    margin: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    justify-content: space-around;
  }
  .nav a { flex-direction: column; gap: 3px; padding: 6px 10px; font-size: 0.62rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .goal-cards { grid-template-columns: 1fr; }
  .extra-grid { grid-template-columns: 1fr 1fr; }
  .plan-row { grid-template-columns: 1fr 82px 38px; }
  .plan-row select.plan-sport { grid-column: 1 / -1; }
  .wizard-steps li { flex-direction: column; text-align: center; font-size: 0.68rem; gap: 4px; padding: 8px 4px; }
  .week-strip { grid-template-columns: repeat(4, 1fr); }
  .stat-donut { flex-direction: row; }
  .checkin-edit { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}
