:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #efeae0;
  --text: #1d2430;
  --muted: #6b7280;
  --line: #e2dccf;
  --brand: #1f4068;
  --brand-text: #ffffff;
  --accent: #e8902f;
  --danger: #c2410c;
  --ok: #3f7d4e;
  --bubble-me: #1f4068;
  --bubble-me-text: #ffffff;
  --bubble-ai: #ffffff;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .05);
  --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: #0f1724;
    --surface: #172234;
    --surface-2: #1e2b40;
    --text: #e8e6e1;
    --muted: #9aa3b2;
    --line: #26354d;
    --brand: #5b8fd1;
    --brand-text: #0b1220;
    --accent: #f0a04b;
    --danger: #fb923c;
    --ok: #7cc48f;
    --bubble-me: #2c5282;
    --bubble-me-text: #ffffff;
    --bubble-ai: #172234;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Kopfzeile */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.tabs { margin-left: auto; display: flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.tabs button { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: 14px; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.icon-btn { border: 0; background: transparent; font-size: 20px; padding: 6px; color: var(--muted); }

main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view { display: none; padding: 16px 16px 24px; max-width: 680px; margin: 0 auto; }
.view.active { display: block; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* Heute */
.hello { margin: 4px 2px 14px; }
.hello h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
.hello p { margin: 2px 0 0; color: var(--muted); }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 12px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 2px 0 6px; font-weight: 650; }
.card.warn h2 { color: var(--danger); }
.entry { display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.entry:first-of-type { border-top: 0; }
.entry .body { flex: 1; min-width: 0; }
.entry .t { font-weight: 560; overflow-wrap: anywhere; }
.entry .meta { font-size: 13px; color: var(--muted); }
.entry .meta b { color: var(--accent); font-weight: 600; }
.tick {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line); background: transparent; margin-top: 1px;
  display: grid; place-items: center; font-size: 14px; color: transparent;
}
.tick:hover, .tick:focus-visible { border-color: var(--ok); }
.tick.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.mini { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--muted); flex: none; }
.prio { color: var(--danger); font-weight: 700; margin-right: 4px; }
.state-faellig .t::after { content: " · fällig"; color: var(--accent); font-weight: 600; font-size: 13px; }
.state-dim { opacity: .55; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }

/* Chat */
#messages { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 86%; padding: 9px 13px; border-radius: 18px; box-shadow: var(--shadow); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--bubble-me); color: var(--bubble-me-text); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--bubble-ai); border-bottom-left-radius: 6px; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; }
.msg ul { margin: 4px 0; padding-left: 18px; }
.msg .time { display: block; font-size: 11px; opacity: .6; margin-top: 4px; }
.msg.typing { color: var(--muted); }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0 2px; }

/* Eingabe */
#composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px calc(8px + var(--safe-b));
  background: var(--bg); border-top: 1px solid var(--line);
}
#input {
  flex: 1; resize: none; max-height: 140px; min-height: 42px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 21px;
  padding: 9px 14px; outline: none; font-size: 16px;
}
#input:focus { border-color: var(--brand); }
.mic, .send { flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; display: grid; place-items: center; }
.mic { background: var(--surface-2); color: var(--text); }
.mic svg, .send svg { width: 22px; height: 22px; fill: currentColor; }
.send { background: var(--brand); color: var(--brand-text); }
.send:disabled { opacity: .5; }
.mic.listening { background: var(--accent); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 25%, transparent); } }
@media (prefers-reduced-motion: reduce) { .mic.listening { animation: none; } }

/* Einstellungen */
dialog { border: 0; padding: 0; border-radius: 20px; background: var(--surface); color: var(--text); width: min(520px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 16, 28, .45); }
.sheet { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.sheet h2 { margin: 0 0 4px; font-size: 20px; }
.sheet h3 { margin: 10px 0 0; font-size: 15px; }
.sheet label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.sheet input[type=password] { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
.sheet button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 10px 14px; font-weight: 600; }
.sheet button.primary, .sheet .close { background: var(--brand); color: var(--brand-text); border-color: transparent; }
.sheet .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sheet .check { flex-direction: row; align-items: center; gap: 8px; }
.sheet p { margin: 0; }
