/* ===== Design tokens (Referenz-Palette, hell + dunkel) ===== */
:root {
  color-scheme: light;
  --page:           #f9f9f7;
  --surface-1:      #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6;   /* Gewicht / Kalorien */
  --series-1-wash:  rgba(42,120,214,0.10);
  --meter-track:    #cde2fb;
  --status-good:    #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical:#d03b3b;
  --delta-good:     #006300;
  --accent:         #2a78d6;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface-1:      #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --series-1:       #3987e5;
    --series-1-wash:  rgba(57,135,229,0.12);
    --meter-track:    #184f95;
    --delta-good:     #0ca30c;
    --accent:         #3987e5;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

body {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(84px + env(safe-area-inset-bottom, 0px));
}

.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
h3 { font-size: 0.95rem; margin: 0 0 6px; }

/* ===== Header ===== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 2px 12px;
}
.app-header p { margin: 2px 0 0; font-size: 0.85rem; }
.header-badge {
  background: var(--series-1-wash);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

/* ===== Cards ===== */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.card-title-row .hint { font-size: 0.8rem; color: var(--text-muted); }

/* ===== Stat tiles ===== */
.tile-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat-tile .label { font-size: 0.78rem; color: var(--text-secondary); }
.stat-tile .value { font-size: 1.5rem; font-weight: 600; margin-top: 2px; }
.stat-tile .value small { font-size: 0.9rem; font-weight: 500; color: var(--text-secondary); }
.stat-tile .delta { font-size: 0.8rem; margin-top: 2px; }
.delta.good { color: var(--delta-good); }
.delta.bad  { color: var(--status-critical); }

.hero-number {
  font-size: 48px;
  font-weight: 650;
  line-height: 1.1;
}
.hero-number small { font-size: 22px; font-weight: 500; color: var(--text-secondary); }

/* ===== Forms ===== */
input, select, button, textarea { font: inherit; color: inherit; }
input[type="number"], input[type="text"], input[type="date"],
input[type="email"], input[type="password"], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--baseline);
  border-radius: 10px;
  background: var(--page);
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
label.field { display: block; margin-bottom: 12px; font-size: 0.85rem; color: var(--text-secondary); }
label.field > input, label.field > select { margin-top: 4px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
.btn.secondary-btn {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--baseline);
}
.btn.small { padding: 6px 12px; font-size: 0.85rem; }
.btn:active { transform: scale(0.98); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }

.weight-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.weight-input-row input { flex: 1; font-size: 1.3rem; font-weight: 600; text-align: center; }

/* ===== Meter (Kalorien) ===== */
.meter {
  height: 14px;
  border-radius: 7px;
  background: var(--meter-track);
  overflow: hidden;
  margin: 8px 0 6px;
}
.meter > div {
  height: 100%;
  border-radius: 7px;
  background: var(--series-1);
  transition: width 0.4s ease;
}
.meter.over > div { background: var(--status-critical); }
.meter-caption { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-secondary); }

/* ===== Coach / Hinweise ===== */
.coach {
  border-left: 4px solid var(--accent);
  background: var(--series-1-wash);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 0.95rem;
}
.notice { border-radius: 10px; padding: 10px 12px; font-size: 0.88rem; margin-top: 10px; display: flex; gap: 8px; align-items: flex-start; }
.notice.good     { background: rgba(12,163,12,0.10); }
.notice.warning  { background: rgba(250,178,25,0.14); }
.notice.serious  { background: rgba(236,131,90,0.14); }
.notice.critical { background: rgba(208,59,59,0.12); }
.notice .ni { flex: 0 0 auto; }

/* ===== BMI-Skala ===== */
.bmi-scale { position: relative; height: 34px; margin-top: 14px; }
.bmi-scale .seg { position: absolute; top: 10px; height: 10px; }
.bmi-scale .seg:first-child { border-radius: 5px 0 0 5px; }
.bmi-scale .seg:last-of-type { border-radius: 0 5px 5px 0; }
.bmi-scale .pointer {
  position: absolute; top: 2px; width: 2px; height: 26px;
  background: var(--text-primary); border-radius: 1px;
}
.bmi-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 0.75rem; color: var(--text-secondary); }
.bmi-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }

/* ===== Essens-Log ===== */
.food-search { position: relative; }
.food-suggestions {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 30;
  background: var(--surface-1);
  border: 1px solid var(--baseline);
  border-radius: 10px;
  margin-top: 4px;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.food-suggestions button {
  display: flex; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gridline);
}
.food-suggestions button:last-child { border-bottom: none; }
.food-suggestions button:hover, .food-suggestions button:focus { background: var(--series-1-wash); }
.food-suggestions .kcal { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; }

.food-list { list-style: none; margin: 10px 0 0; padding: 0; }
.food-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--gridline);
  font-size: 0.92rem;
}
.food-list li:last-child { border-bottom: none; }
.food-list .fname { flex: 1; }
.food-list .fdetail { color: var(--text-muted); font-size: 0.78rem; }
.food-list .fkcal { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.food-list .fdel {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 1rem; padding: 4px;
}
.food-qty-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.food-qty-row input { width: 90px; text-align: center; }
.food-qty-row .selected-name { flex: 1; font-weight: 600; }

/* ===== Charts ===== */
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 6px; font-size: 0.78rem; color: var(--text-secondary); }
.chart-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .swatch-line { width: 16px; height: 0; border-top: 2px solid; border-radius: 1px; }
.chart-tooltip {
  position: fixed; z-index: 100;
  background: var(--surface-1);
  border: 1px solid var(--baseline);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.8rem;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.16);
  max-width: 220px;
}
.chart-tooltip .tt-title { font-weight: 600; margin-bottom: 2px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.chart-tooltip .tt-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.range-row { display: flex; gap: 6px; margin-bottom: 10px; }
.range-row button {
  border: 1px solid var(--baseline);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}
.range-row button.active {
  border-color: var(--accent);
  color: var(--text-primary);
  font-weight: 600;
  background: var(--series-1-wash);
}

/* ===== Belohnung ===== */
.milestone-list { list-style: none; margin: 10px 0 0; padding: 0; }
.milestone-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--gridline);
  font-size: 0.92rem;
}
.milestone-list li:last-child { border-bottom: none; }
.milestone-list .m-icon { font-size: 1.1rem; }
.milestone-list .m-amount { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.milestone-list li.locked { color: var(--text-muted); }

/* ===== Tabbar ===== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px));
  max-width: 640px;
  margin: 0 auto;
}
.tabbar button {
  flex: 1;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  font-size: 0.68rem;
  color: var(--text-muted);
  padding: 4px 0;
}
.tabbar button.active { color: var(--accent); font-weight: 600; }
.tabbar .tab-icon { font-size: 1.25rem; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.data-table th, table.data-table td {
  text-align: left; padding: 6px 8px;
  border-bottom: 1px solid var(--gridline);
}
table.data-table td.num, table.data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

details.card summary { cursor: pointer; font-weight: 600; }
.small-note { font-size: 0.78rem; color: var(--text-muted); margin-top: 8px; }

/* ===== Auth ===== */
#auth-screen[hidden] { display: none; }
#auth-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--page);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.auth-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: left;
}
.auth-box h1 { text-align: center; margin-bottom: 4px; }
.auth-box .secondary { text-align: center; font-size: 0.88rem; margin: 0 0 18px; }
.auth-logo { font-size: 2.4rem; text-align: center; margin-bottom: 6px; }
.linklike {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--accent); font-size: 0.85rem; text-decoration: underline;
}
.sync-badge { font-size: 0.7rem; color: var(--text-muted); }
.btn[disabled] { opacity: 0.6; cursor: wait; }
.ki-btn {
  display: flex; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  padding: 10px 12px;
  color: var(--accent);
  font-weight: 600;
}

/* ===== Coach-Chat ===== */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0 12px;
  min-height: 120px;
}
.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.bot {
  align-self: flex-start;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.bot strong { font-weight: 650; }
.msg.error { align-self: flex-start; background: rgba(208,59,59,0.10); border: 1px solid var(--status-critical); }
.msg.typing { align-self: flex-start; color: var(--text-muted); background: var(--surface-1); border: 1px solid var(--border); }
.chat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chat-chips button {
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.82rem;
  cursor: pointer;
}
.chat-chips button:hover { border-color: var(--accent); color: var(--text-primary); }
.chat-input-row {
  position: sticky;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 8px;
  background: var(--page);
  padding: 8px 0;
  z-index: 10;
}
.chat-input-row input { flex: 1; }
.chat-input-row .btn { flex: 0 0 auto; }
.chat-clear { text-align: center; margin-top: 4px; }

/* ===== Wasser-Tracking ===== */
.water-row { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.water-glass {
  width: 40px; height: 48px;
  border: 1px solid var(--baseline);
  border-radius: 8px 8px 12px 12px;
  background: var(--page);
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--text-muted);
}
.water-glass.filled { background: var(--series-1-wash); border-color: var(--accent); }

/* ===== Barcode-Scanner ===== */
.scanner-modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.88);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 20px;
}
.scanner-modal video { width: 100%; max-width: 420px; border-radius: 12px; }
.scanner-modal p { color: #fff; margin: 0; }

/* ===== Favoriten-Stern ===== */
.food-list .fstar {
  background: none; border: none; cursor: pointer;
  font-size: 1rem; padding: 4px; color: var(--text-muted);
}

/* ===== Push-Einstellungen ===== */
.push-toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; font-size: 0.92rem;
  border-bottom: 1px solid var(--gridline);
}
.push-toggle:last-of-type { border-bottom: none; }
.push-toggle input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

/* ===== Admin / Impersonation ===== */
.imp-banner {
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--status-warning);
  color: #2b2200;
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 10px;
  font-weight: 600;
  font-size: 0.9rem;
}
.imp-banner .btn { background: #2b2200; color: #fff; }
.admin-list { list-style: none; margin: 0; padding: 0; }
.admin-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gridline);
}
.admin-list li:last-child { border-bottom: none; }
.admin-list li.current { background: var(--series-1-wash); border-radius: 8px; padding: 10px 8px; }
.admin-list .admin-user { min-width: 0; }
