/* ---------- Farben: hell, bei Handy im Dunkelmodus automatisch dunkel ---------- */
:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --sunken: #efefec;
  --line: #e6e6e2;
  --text: #17171a;
  --muted: #74747c;
  --faint: #a8a8ae;
  --accent: #2458e6;
  --accent-soft: #2458e614;
  --pos: #15803d;
  --neg: #c62828;
  --warn: #b45309;
  --r: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e10;
    --surface: #18181b;
    --sunken: #222226;
    --line: #2a2a2f;
    --text: #ececee;
    --muted: #8d8d95;
    --faint: #5c5c64;
    --accent: #5b8cff;
    --accent-soft: #5b8cff1f;
    --pos: #4ade80;
    --neg: #f87171;
    --warn: #fbbf24;
    color-scheme: dark;
  }
  .sheet-bg { background: #000000a6 !important; }
  .sheet { border-top: 1px solid var(--line); }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(64px + var(--safe-b));
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num, .v, .amt, .big, .timer, .stat-line b { font-variant-numeric: tabular-nums; }
.i { width: 20px; height: 20px; flex: none; display: block; }

main { max-width: 620px; margin: 0 auto; padding: calc(20px + var(--safe-t)) 16px 24px; }

/* ---------- Kopfzeile ---------- */
.head { display: flex; align-items: flex-end; gap: 8px; margin: 4px 0 18px; }
.head .title { flex: 1; min-width: 0; }
.head h1 { font-size: 26px; line-height: 1.15; margin: 0; font-weight: 700; letter-spacing: -.4px; }
.head .sub { color: var(--muted); font-size: 14px; margin-top: 3px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; flex: none; padding: 0; color: var(--text);
}
.icon-btn .i { width: 18px; height: 18px; }
.icon-btn.accent { background: var(--text); border-color: var(--text); color: var(--bg); }
.icon-btn:disabled { opacity: .35; }

/* ---------- Abschnitte ---------- */
.label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  margin: 22px 2px 8px;
}
.label .grow { flex: 1; }
.label button { background: none; border: 0; padding: 0; color: var(--accent); font: 600 13px/1 inherit; text-transform: none; letter-spacing: 0; }
.surface { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 14px; }
.surface.pad { padding: 14px; }
.surface + .surface { margin-top: 10px; }

/* ---------- Kacheln ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 13px; text-align: left; display: flex; flex-direction: column; gap: 2px; min-height: 84px;
}
.tile:last-child:nth-child(odd) { grid-column: span 2; }
.tile .k { color: var(--muted); font-size: 12.5px; }
.tile .v { font-size: 21px; font-weight: 650; letter-spacing: -.3px; }
.tile .v small { font-size: 13px; color: var(--faint); font-weight: 500; letter-spacing: 0; }
.tile .bar { margin-top: auto; height: 3px; }

/* ---------- Segment-Umschalter ---------- */
.seg { display: flex; background: var(--sunken); border-radius: 9px; padding: 3px; gap: 2px; margin-bottom: 4px; }
.seg button, .seg label { flex: 1; border: 0; background: none; padding: 7px 4px; border-radius: 7px; font-size: 13.5px; color: var(--muted); text-align: center; font-weight: 550; }
.seg button.on, .seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px #0000001a; }
.seg label { padding: 0; display: flex; }
.seg label input { display: none; }
.seg label span { flex: 1; padding: 7px 4px; border-radius: 7px; }

/* ---------- Listen ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); min-height: 48px; }
.row:last-child { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; }
.row .t { overflow-wrap: anywhere; }
.row .m { color: var(--muted); font-size: 13px; margin-top: 1px; }
.row .amt { font-weight: 600; white-space: nowrap; }
.row .r { color: var(--muted); font-size: 14px; white-space: nowrap; }
.tap { cursor: pointer; }
.chk {
  width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--faint);
  background: none; flex: none; display: grid; place-items: center; padding: 0; color: #fff;
}
.chk .i { width: 13px; height: 13px; stroke-width: 3; }
.chk.on { background: var(--accent); border-color: var(--accent); }
.done .t { text-decoration: line-through; color: var(--faint); }
.tag { display: inline-block; font-size: 12px; font-weight: 550; margin-right: 6px; color: var(--muted); }
.tag.bad { color: var(--neg); }
.tag.warn { color: var(--warn); }
.star { color: var(--warn); display: inline-block; vertical-align: -2px; margin-right: 4px; }
.star .i { width: 14px; height: 14px; fill: currentColor; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 20px 8px; font-size: 14px; }
.more { display: block; width: 100%; background: none; border: 0; color: var(--accent); font-size: 14px; font-weight: 550; padding: 12px 0; }

.quick { display: flex; gap: 8px; margin: 12px 0 0; }
.quick input { flex: 1; min-width: 0; }

/* ---------- Eingaben ---------- */
input[type=text], input[type=date], input[type=time], select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
.sheet input[type=text], .sheet input[type=date], .sheet input[type=time], .sheet select, .sheet textarea { background: var(--sunken); border-color: transparent; }
input:focus, select:focus, textarea:focus { border-color: var(--accent) !important; }
input[type=date], input[type=time] { min-height: 45px; }
textarea { min-height: 170px; resize: vertical; line-height: 1.5; }
textarea.small { min-height: 96px; }

/* Tracker-Reiter: seitlich wischbar */
.seg.scroll { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.seg.scroll::-webkit-scrollbar { display: none; }
.seg.scroll button { flex: none; padding: 7px 13px; }

/* Tages-Check-in */
.ci .ico { width: 30px; height: 30px; border-radius: 8px; background: var(--sunken); display: grid; place-items: center; flex: none; color: var(--muted); }
.ci .ico .i { width: 17px; height: 17px; }
.ci.filled .ico { background: var(--accent-soft); color: var(--accent); }
.ci .r.add { color: var(--accent); font-weight: 550; }
.ci .quote { font-style: italic; color: var(--text); white-space: normal; }

/* Gewichts-Kurve */
.line { width: 100%; height: 120px; display: block; margin-top: 10px; overflow: visible; }
.line path.l { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.line path.a { fill: var(--accent-soft); stroke: none; }
.line-x { display: flex; justify-content: space-between; color: var(--faint); font-size: 11px; margin-top: 4px; }
.journal-day { padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.journal-day:last-child { border-bottom: 0; }
.journal-day .m { color: var(--muted); font-size: 12.5px; margin-bottom: 3px; }
.journal-day .t { line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.btn { border: 1px solid var(--line); border-radius: 10px; padding: 11px 16px; font-weight: 600; background: var(--surface); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.danger { color: var(--neg); background: none; }
.btn.small { padding: 6px 8px; border-radius: 8px; color: var(--muted); }
.btn.small .i { width: 16px; height: 16px; }
.btn.wide { width: 100%; }
.btn .i { width: 16px; height: 16px; }

/* ---------- Fortschritt ---------- */
.bar { height: 6px; background: var(--sunken); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar.over > i { background: var(--neg); }
.bar.done > i { background: var(--pos); }
.stat-line { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; margin: 14px 0 7px; }
.stat-line:first-child { margin-top: 2px; }
.stat-line b { font-weight: 600; }
.stat-line b small { color: var(--muted); font-weight: 400; }
.trio { display: grid; grid-template-columns: repeat(3, 1fr); }
.trio > div + div { border-left: 1px solid var(--line); padding-left: 12px; }
.trio .k { color: var(--muted); font-size: 12.5px; }
.trio .v { font-weight: 650; font-size: 17px; margin-top: 2px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- Gewohnheiten ---------- */
.hrow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hrow:last-child { border-bottom: 0; }
.hrow .main { flex: 1; min-width: 0; cursor: pointer; }
.hrow .t { font-weight: 550; }
.hrow .m { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.dots { display: flex; gap: 4px; }
.dot { border: 0; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10px; color: var(--faint); }
.dot i { width: 16px; height: 16px; border-radius: 4px; background: var(--sunken); display: block; }
.dot.on i { background: var(--accent); opacity: .55; }
.today-chk {
  width: 32px; height: 32px; border-radius: 9px; border: 1.5px solid var(--line); background: var(--surface);
  flex: none; display: grid; place-items: center; padding: 0; color: transparent;
}
.today-chk .i { width: 18px; height: 18px; stroke-width: 2.6; }
.today-chk.on { background: var(--accent); border-color: var(--accent); color: #fff; }


/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 0; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 10px;
  font-size: 13.5px; text-decoration: none; color: var(--text); display: inline-flex; gap: 6px; align-items: baseline;
}
.chip .muted { font-size: 12px; }
.chip.add { color: var(--accent); border-style: dashed; }
.chip.edit { border-color: var(--accent); color: var(--accent); }

/* ---------- Notizen ---------- */
.notes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.note { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 13px; cursor: pointer; min-height: 104px; overflow: hidden; }
.note b { display: block; margin-bottom: 4px; font-weight: 600; overflow-wrap: anywhere; }
.note p { margin: 0; color: var(--muted); font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.note .d { color: var(--faint); font-size: 11.5px; margin-top: 8px; }

/* ---------- Diagramm ---------- */
.cols { display: flex; align-items: flex-end; gap: 6px; height: 96px; margin: 14px 0 4px; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 5px; font-size: 11px; color: var(--faint); }
.col i { width: 100%; max-width: 30px; background: var(--sunken); border-radius: 4px; min-height: 3px; display: block; }
.col.has i { background: var(--accent); opacity: .5; }
.col.today i { opacity: 1; }
.col.today span { color: var(--text); font-weight: 600; }

/* ---------- Timer ---------- */
.timer { font-size: 40px; font-weight: 600; text-align: center; letter-spacing: -1px; padding-top: 6px; }
.timer-sub { text-align: center; color: var(--muted); margin-bottom: 14px; font-size: 14px; }
.live { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--neg); margin-right: 6px; vertical-align: 1px; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- Monats-/Tageswechsel ---------- */
.switch { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 0; }
.switch b { font-size: 15px; font-weight: 600; }

/* ---------- Tab-Leiste ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(4px + var(--safe-b));
}
.tabbar button { flex: 1; border: 0; background: none; color: var(--faint); display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 550; padding: 3px 0; }
.tabbar .i { width: 22px; height: 22px; }
.tabbar button.on { color: var(--text); }

/* ---------- Eingabe-Blatt ---------- */
#sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.sheet-bg { position: absolute; inset: 0; background: #0000004d; animation: fade .18s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 620px; margin: 0 auto;
  background: var(--surface); border-radius: 16px 16px 0 0; padding: 8px 18px calc(16px + var(--safe-b));
  max-height: 92vh; overflow-y: auto; animation: up .22s cubic-bezier(.2,.8,.3,1);
}
.sheet-handle { width: 36px; height: 4px; border-radius: 9px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 16px; font-size: 18px; font-weight: 650; }
.field { margin-bottom: 12px; display: block; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.field.check { display: flex; align-items: center; gap: 10px; }
.field.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.field.check > span { margin: 0; font-size: 15px; color: var(--text); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.sheet-actions .primary { flex: 1; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-weight: 550; font-size: 14px;
  animation: fade .18s; white-space: nowrap;
}
