:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --text: #1a1a1a;
  --muted: #6b6a66;
  --line: #e2e0da;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --danger: #c2372b;
  --ok: #2f8a4c;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --text: #ecebe8;
    --muted: #9a9892;
    --line: #2a2e37;
    --accent: #7b9cff;
    --accent-text: #0f1115;
    --danger: #ff7b6e;
    --ok: #6fd08f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
@media (max-width: 520px) { .brand-label { display: none; } }
.brand { flex: none; display: flex; align-items: center; gap: 8px; font-weight: 650; text-decoration: none; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 40%, #19c3a0)); }
.search {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  max-width: 560px; margin-left: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 12px; height: 40px;
}
.search:focus-within { border-color: var(--accent); }
.search svg { color: var(--muted); flex: none; width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 16px; }
.search-key { font: 12px ui-monospace, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
@media (hover: none) { .search-key { display: none; } }
.icon-btn {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  cursor: pointer; text-decoration: none;
}
.icon-btn:hover { color: var(--text); }

/* ---------- Layout ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 20px 16px 64px; outline: none; }
h1 { font-size: 28px; line-height: 1.2; margin: 8px 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.lead { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.stack > * + * { margin-top: 16px; }

.home-top { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 24px; }
@media (min-width: 800px) { .home-top { grid-template-columns: 1.2fr 1fr; } }

/* ---------- Kacheln ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
@media (max-width: 480px) { .tiles { grid-template-columns: 1fr 1fr; gap: 10px; } }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  min-height: 132px; padding: 14px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 160ms ease-out, border-color 160ms ease-out;
}
.tile:hover { border-color: color-mix(in srgb, var(--hue) 55%, var(--line)); }
.tile:active { transform: scale(0.98); }
.tile-icon {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 20px;
  background: color-mix(in srgb, var(--hue) 16%, var(--surface));
}
.tile-name { font-weight: 650; line-height: 1.25; }
.tile-desc { font-size: 13px; color: var(--muted); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-meta { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.tile.add { align-items: center; justify-content: center; color: var(--muted); border-style: dashed; box-shadow: none; background: transparent; cursor: pointer; font: inherit; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.accent { background: color-mix(in srgb, var(--hue, var(--accent)) 18%, var(--surface)); color: var(--text); }

/* ---------- Heute ---------- */
.today-list { list-style: none; margin: 0; padding: 0; }
.today-list li { display: flex; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); align-items: baseline; }
.today-list li:first-child { border-top: 0; }
.time { flex: none; width: 92px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.quick { display: flex; gap: 8px; margin-top: 12px; }
.quick input { flex: 1; min-width: 0; }
.quick select { max-width: 40%; }

/* ---------- Formulare ---------- */
input[type="text"], input[type="url"], input[type="date"], input[type="search"]:not(#searchInput), select, textarea {
  width: 100%; height: 42px; padding: 0 12px; font-size: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; outline: none;
}
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: block; font-size: 14px; font-weight: 600; margin: 12px 0 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap;
  transition: transform 120ms ease-out;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { height: 34px; padding: 0 12px; font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

/* ---------- Bereich ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 15px; }
.section-head { display: flex; align-items: flex-start; gap: 14px; margin: 8px 0 20px; }
.section-head .tile-icon { width: 52px; height: 52px; font-size: 28px; border-radius: 15px; flex: none; }
.section-head h1 { margin: 0; }
.section-head p { margin: 2px 0 0; color: var(--muted); }
.section-grid { display: grid; gap: 16px; }
@media (min-width: 860px) { .section-grid { grid-template-columns: 1fr 300px; align-items: start; } }

.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 2px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item input[type="checkbox"] { flex: none; width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--accent); cursor: pointer; }
.item-body { flex: 1; min-width: 0; cursor: pointer; }
.item-text { overflow-wrap: anywhere; }
.item-note { font-size: 14px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.item.done .item-text { color: var(--muted); text-decoration: line-through; }
.due { font-size: 12px; color: var(--muted); }
.due.late { color: var(--danger); font-weight: 600; }
.add-item { display: flex; gap: 8px; margin-top: 12px; }
.add-item input { flex: 1; min-width: 0; }
.empty { color: var(--muted); padding: 8px 0; margin: 0; }

.links { list-style: none; margin: 0; padding: 0; }
.links li { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.links a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); text-decoration: none; font-weight: 550; }
.links a:hover { text-decoration: underline; }
.x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; line-height: 0; }
.x:hover { color: var(--danger); }
.x svg { width: 16px; height: 16px; }

.status-row { display: flex; flex-wrap: wrap; gap: 6px; }
.status-row button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 14px; }
.status-row button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* ---------- Kalender ---------- */
.day { margin-top: 18px; }
.day:first-child { margin-top: 0; }
.day h3 { font-size: 14px; margin: 0 0 6px; color: var(--muted); }
.day h3.is-today { color: var(--accent); }

/* ---------- Suche ---------- */
.result { display: block; padding: 10px 2px; border-top: 1px solid var(--line); text-decoration: none; }
.result:first-child { border-top: 0; }
.result-meta { font-size: 13px; color: var(--muted); }
mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- Dialog ---------- */
dialog {
  width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line);
  border-radius: 18px; background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog[open] { animation: pop 180ms cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
#dialogForm { padding: 18px; }
#dialogForm h2 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 18px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 18px; }

/* ---------- Hinweise ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100vw - 32px); z-index: 30;
}
.sync-badge {
  position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 20;
  font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.notice { border-left: 3px solid var(--accent); padding: 10px 14px; background: var(--surface-2); border-radius: 0 10px 10px 0; font-size: 14px; }
.notice p { margin: 0; }
.notice p + p { margin-top: 6px; }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
