:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #ecebe8;
  --border: #dddcd8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --warn: #b35a00;
  --danger: #c43c3b;
  --grid: #e6e5e1;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #262624;
    --border: #353532;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-soft: #1d2d42;
    --warn: #e8973f;
    --danger: #e66767;
    --grid: #2b2b29;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
main { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; }

h1 { font-size: 1.35rem; margin: 4px 0 12px; }
h2 { font-size: 1.05rem; margin: 0; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }

/* Navigation */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs a {
  flex: 1; max-width: 180px; text-align: center; padding: 8px 4px 10px;
  color: var(--muted); text-decoration: none; font-size: .78rem;
}
#tabs a .ico { display: block; font-size: 1.3rem; line-height: 1.3; }
#tabs a.active { color: var(--accent); font-weight: 600; }
body.hide-tabs #tabs { display: none; }
body.hide-tabs { padding-bottom: 0; }

/* Karten & Listen */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px; border-top: 1px solid var(--grid); cursor: pointer;
}
.list li:first-child { border-top: 0; }
.list li:hover { background: var(--surface-2); }
.list .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .meta { color: var(--muted); font-size: .82rem; }
.badge {
  font-size: .7rem; padding: 2px 6px; border-radius: 6px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.empty { color: var(--muted); padding: 8px 2px; font-size: .9rem; }

/* Formulare */
label { display: block; font-size: .85rem; color: var(--text-2); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 8px; }
@media (max-width: 420px) { .grid4 { grid-template-columns: 1fr 1fr; } }

button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 10px; padding: 10px 14px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.block { width: 100%; margin-top: 14px; }
button:disabled { opacity: .5; cursor: default; }
.icon-btn { padding: 8px 12px; min-width: 44px; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 10px 0 14px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 8px 14px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* Tagesübersicht */
.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.daynav h1 { margin: 0; text-align: center; flex: 1; }
.hero { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.hero small { font-size: .95rem; font-weight: 400; color: var(--muted); }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 6px 0 2px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.over > span { background: var(--warn); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.macros .lbl { font-size: .8rem; color: var(--text-2); }
.over-text { color: var(--warn); font-size: .85rem; }
.meal-head { display: flex; align-items: center; justify-content: space-between; }
.meal-head .kcal { color: var(--text-2); font-size: .9rem; margin-left: auto; margin-right: 8px; }

/* Vorschau beim Eintragen */
.preview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin-top: 14px; }
.preview div { background: var(--surface-2); border-radius: 10px; padding: 8px 4px; }
.preview b { display: block; font-size: 1.1rem; }
.preview span { font-size: .75rem; color: var(--text-2); }

/* Scanner */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame {
  position: absolute; left: 12%; right: 12%; top: 35%; bottom: 35%;
  border: 2px solid rgba(255,255,255,.85); border-radius: 8px;
}

/* Gewichts-Chart */
.chart { position: relative; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 240px; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .goal { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .goal-label { fill: var(--text-2); font-size: 11px; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: .85rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.12); white-space: nowrap; transform: translate(-50%, -110%);
}

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; max-width: 90vw;
}
#toast.show { opacity: 1; }

.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
