:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #15201c;
  --muted: #5f6d68;
  --faint: #93a09b;
  --border: #dde4e1;
  --accent: #0b8a6a;
  --accent-ink: #ffffff;
  --accent-soft: #dff3ec;
  --danger: #c4372f;
  --warn: #b26b00;
  --grid: #e6ecea;
  --shadow: 0 1px 2px rgba(16, 32, 26, .06), 0 2px 10px rgba(16, 32, 26, .04);

  --c-aktivitaet: #e0731f;
  --c-schlaf: #5b5fd6;
  --c-herz: #d63a4a;
  --c-vital: #138a9b;
  --c-koerper: #2f6fd1;
  --c-ernaehrung: #3c9a3a;
  --c-sonst: #7a7f8c;

  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1513;
    --surface: #171f1c;
    --surface-2: #1f2925;
    --text: #e8efec;
    --muted: #9aa8a3;
    --faint: #6b7975;
    --border: #2a3531;
    --accent: #2fc59c;
    --accent-ink: #062018;
    --accent-soft: #163a30;
    --danger: #ff6b60;
    --warn: #f0a838;
    --grid: #24302c;
    --shadow: none;
    --c-aktivitaet: #f08b3a;
    --c-schlaf: #8b8ef0;
    --c-herz: #f2606d;
    --c-vital: #3cc0d0;
    --c-koerper: #5c94f0;
    --c-ernaehrung: #66c45f;
    --c-sonst: #a1a6b3;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1513; --surface: #171f1c; --surface-2: #1f2925; --text: #e8efec; --muted: #9aa8a3; --faint: #6b7975;
  --border: #2a3531; --accent: #2fc59c; --accent-ink: #062018; --accent-soft: #163a30; --danger: #ff6b60; --warn: #f0a838;
  --grid: #24302c; --shadow: none; --c-aktivitaet: #f08b3a; --c-schlaf: #8b8ef0; --c-herz: #f2606d; --c-vital: #3cc0d0;
  --c-koerper: #5c94f0; --c-ernaehrung: #66c45f; --c-sonst: #a1a6b3; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}
.topbar h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { max-width: 920px; margin: 0 auto; padding: 4px 16px 0; }

/* Tableiste */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar a {
  position: relative; flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: 12px; text-decoration: none; color: var(--faint); font-size: 12px; font-weight: 600;
}
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { background: var(--accent-soft); border-radius: 999px; padding: 2px 14px; width: 52px; box-sizing: content-box; height: 22px; margin: -2px 0; }
.badge { position: absolute; top: 4px; right: calc(50% - 22px); width: 9px; height: 9px; border-radius: 50%; background: var(--danger); border: 2px solid var(--surface); }

/* Allgemein */
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 10px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.stack > * + * { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* Tagesnavigation */
.daynav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 6px; }
.daynav .label { font-weight: 700; font-size: 17px; }
.daynav .sub { font-size: 13px; color: var(--muted); }

/* Kachelgrid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column; gap: 6px; padding: 14px; min-height: 128px;
  text-decoration: none; color: inherit; cursor: pointer; position: relative; overflow: hidden;
}
.tile:hover { border-color: color-mix(in srgb, var(--c) 45%, var(--border)); }
.tile .head { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.tile .ico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 14px; background: color-mix(in srgb, var(--c) 16%, transparent); }
.tile .val { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.tile .val small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.tile .meta { font-size: 12px; color: var(--faint); }
.tile svg.spark { margin-top: auto; width: 100%; height: 34px; display: block; }
.tile.empty .val { color: var(--faint); }

/* Verlaufs-Liste */
.list { overflow: hidden; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; text-decoration: none; color: inherit; }
.list-item + .list-item { border-top: 1px solid var(--border); }
.list-item:hover { background: var(--surface-2); }
.list-item .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; background: color-mix(in srgb, var(--c) 16%, transparent); flex: none; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; }
.list-item .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .r { text-align: right; font-weight: 600; white-space: nowrap; }
.chev { color: var(--faint); flex: none; }

/* Detail */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted);
}
.chip.active { background: var(--text); border-color: var(--text); color: var(--bg); }
.hero { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; margin: 12px 2px 4px; }
.hero .big { font-size: 34px; font-weight: 750; letter-spacing: -.02em; }
.hero .unit { font-size: 16px; color: var(--muted); font-weight: 600; }
.hero .cap { width: 100%; font-size: 13px; color: var(--muted); }
.chart { position: relative; height: 240px; margin-top: 8px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart text { fill: var(--faint); font-size: 11px; }
.tip {
  position: absolute; top: 0; pointer-events: none; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 6px 10px; border-radius: 10px; font-size: 12px; white-space: nowrap; font-weight: 600;
}
.tip span { display: block; font-weight: 500; opacity: .75; font-size: 11px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 12px; }
.stat { padding: 12px 14px; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat .d { font-size: 12px; color: var(--faint); }

.stagebar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; margin-top: 6px; background: var(--surface-2); }
.stagebar i { display: block; height: 100%; }

/* Einstellungen */
.setting { padding: 16px; }
.setting + .setting { border-top: 1px solid var(--border); }
.setting h3 { margin: 0 0 4px; font-size: 16px; }
.setting p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; margin-bottom: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; overflow-wrap: anywhere; }
.copybox { display: flex; gap: 8px; align-items: stretch; }
.copybox input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px;
}
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.new { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.pill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 10px 0; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
ol.steps { margin: 8px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
ol.steps li + li { margin-top: 4px; }

/* Login */
.login { max-width: 400px; margin: 10vh auto 0; text-align: center; }
.login .logo { width: 72px; height: 72px; margin: 0 auto 12px; }
.login h2 { margin: 0 0 6px; font-size: 24px; }
.login form { margin-top: 20px; text-align: left; }
.field { display: block; width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); margin-bottom: 12px; }
.field:focus, .copybox input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }

.empty-state { text-align: center; padding: 36px 20px; }
.empty-state .e { font-size: 40px; }
.empty-state h3 { margin: 8px 0 6px; }
.empty-state p { color: var(--muted); margin: 0 0 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  z-index: 50; max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); }
@keyframes sk { to { background-position: -200% 0; } }

@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .chart { height: 300px; }
}
