:root {
  --bg: #f6f7f9; --card: #fff; --text: #1b1f24; --muted: #596170;
  --line: #e5e7eb; --accent: #4f46e5; --on-accent: #fff; --ok: #16a34a; --warn: #dc2626; --prio: #f59e0b;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --card: #181b21; --text: #e8eaed; --muted: #9aa1ab; --line: #2a2e36; --accent: #818cf8; --on-accent: #0f1115; --warn: #f87171; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font: 16px/1.45 system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text);
  overscroll-behavior-y: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.locked > header, body.locked > main, body.locked > #bottom-nav { display: none; }
body.locked { overflow: hidden; }

h1 { margin: 0; font-size: 1.6rem; }
h2 { margin: 0 0 .75rem; font-size: 1.1rem; }
h3 { margin: 1.2rem 0 .4rem; font-size: .95rem; }
.muted { color: var(--muted); margin: .1rem 0 .5rem; font-size: .92rem; }
.error { color: var(--warn); margin: 0; font-size: .92rem; }

/* Eingaben: 16px verhindert den Auto-Zoom auf iOS, 44px sind gute Touch-Ziele */
input, select, button, .button {
  font: inherit; font-size: 16px; color: inherit; min-height: 44px;
  border: 1px solid var(--line); border-radius: 10px; padding: .5rem .8rem; background: var(--card);
}
input, select { min-width: 0; }
button, .button { cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
button:active, .button:active { transform: scale(.98); }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.secondary { background: transparent; }
.danger { background: transparent; color: var(--warn); border-color: var(--warn); }
.icon { min-width: 44px; padding: .4rem; background: transparent; border-color: transparent; font-size: 1.2rem; }

header { display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  max-width: 1000px; margin: 0 auto; padding: 1rem 1rem 0; }
.actions { display: flex; gap: .2rem; }

main { display: grid; grid-template-columns: 3fr 2fr; gap: 1rem; max-width: 1000px; margin: 1rem auto; padding: 0 1rem 2rem; }
section { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem; align-self: start; }

form { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
#task-form { flex-direction: column; }
#task-form .row, .row { display: flex; gap: .5rem; flex-wrap: wrap; }
#task-form .row > * { flex: 1 1 100px; }
#habit-form input { flex: 1 1 180px; }

.tabs { display: flex; gap: .4rem; margin-bottom: .5rem; }
.tabs button { border-radius: 999px; padding: .25rem 1rem; min-height: 40px; font-size: .95rem; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .4rem; border-top: 1px solid var(--line); min-height: 56px; }
.list li:first-child { border-top: 0; }
.list label.check { display: grid; place-items: center; min-width: 44px; min-height: 44px; cursor: pointer; }
.list .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; padding: .4rem 0; }
.list .meta { font-size: .82rem; color: var(--muted); }
.list .meta.overdue { color: var(--warn); font-weight: 600; }
.done .title { text-decoration: line-through; color: var(--muted); }
.prio-2 .title::before { content: "● "; color: var(--prio); }
input[type=checkbox] { width: 24px; height: 24px; min-height: 0; padding: 0; accent-color: var(--accent); }
.del { border-color: transparent; background: transparent; color: var(--muted); min-width: 44px; padding: .2rem; }
.del:hover, .del:active { color: var(--warn); }
.week { display: flex; gap: 4px; margin-top: .2rem; }
.week i { width: 12px; height: 12px; border-radius: 3px; background: var(--line); }
.week i.on { background: var(--ok); }
.streak { font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); padding: .75rem 0; display: block !important; }

/* Sperrbildschirm */
#lock { position: fixed; inset: 0; z-index: 10; display: none; place-items: center; background: var(--bg);
  padding: env(safe-area-inset-top) 1rem env(safe-area-inset-bottom); }
body.locked #lock { display: grid; }
#lock-form { width: min(360px, 100%); flex-direction: column; align-items: stretch; text-align: center; gap: .7rem; margin: 0; }
#lock-form img { align-self: center; border-radius: 16px; }
#lock-form .muted { margin: 0; }

/* Einstellungen */
dialog { width: min(440px, calc(100% - 1.5rem)); max-height: 90dvh; border: 1px solid var(--line); border-radius: 16px;
  background: var(--card); color: var(--text); padding: 1rem 1.2rem 1.2rem; }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog form { margin-bottom: .5rem; }
dialog input { flex: 1 1 100%; }
.dlg-head { justify-content: space-between; align-items: center; flex-wrap: nowrap; margin: 0; }
.dlg-head h2 { margin: 0; }
details { margin: .6rem 0; }
summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }

/* Mobil: eine Spalte, Tab-Leiste unten */
#bottom-nav { display: none; }
@media (max-width: 760px) {
  main { grid-template-columns: 1fr; padding-bottom: calc(var(--nav-h) + 1.5rem); margin-top: .75rem; }
  body[data-view="tasks"] #view-habits, body[data-view="habits"] #view-tasks { display: none; }
  section { border-radius: 14px; padding: .9rem; }
  #bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line); }
  #bottom-nav button { flex: 1; flex-direction: column; gap: 0; border: 0; border-radius: 0; background: transparent;
    min-height: var(--nav-h); font-size: 1.3rem; color: var(--muted); }
  #bottom-nav button span { font-size: .75rem; }
  #bottom-nav button.active { color: var(--accent); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

[hidden] { display: none !important; }
summary::after { content: "›"; margin-left: auto; font-size: 1.4rem; color: var(--muted); transition: transform .15s; }
details[open] > summary::after { transform: rotate(90deg); }
summary { list-style: none; }
summary::-webkit-details-marker { display: none; }
