:root {
  color-scheme: dark;
  --bg: #111315;
  --surface: #1b1e21;
  --surface-2: #23272b;
  --border: #2c3035;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --faint: #5f6368;
  --accent: #8ab4f8;
  --accent-text: #0b1a33;
  --danger: #f28b82;
  --done: #81c995;
  --radius: 12px;
  --gap: 16px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }

/* Nur die Liste scrollt, nie die Seite. overscroll-behavior verhindert Chromes
   "Ziehen zum Neuladen", damit das Ziehen oben nur den Rückblick öffnet. */
html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

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

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 0;
  position: relative;
}

#app.loading::after {
  content: "";
  margin: auto;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: .25; } }

h1 { font-size: 1.5rem; font-weight: 600; margin: 0; }

button { font: inherit; color: inherit; }

.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.button {
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
}
.button:focus-visible, input:focus-visible, select:focus-visible, .chip:focus-visible, .icon-button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.button--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button--danger { color: var(--danger); }
.button:disabled { opacity: .6; cursor: default; }

.icon-button {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: none; color: var(--muted);
  cursor: pointer;
}

.hint { margin: 0; color: var(--muted); font-size: .875rem; }

/* ---------- Login ---------- */

.login {
  flex: 1;
  display: flex; flex-direction: column; justify-content: flex-end; gap: var(--gap);
  width: 100%; max-width: 420px;
  margin: 0 auto;
  padding: 24px 16px calc(32px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.login__logo { border-radius: 14px; }
.login__form { display: flex; flex-direction: column; gap: var(--gap); margin-top: 8px; }
.login__form label, .field > span, .field > legend { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: .875rem; }
.login__form input, .field input, .field select {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  width: 100%;
}
.login__error, .form__error { margin: 0; color: var(--danger); font-size: .9rem; }

/* ---------- Startseite ---------- */

.home {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.home__header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 4px 8px 16px;
}
.chips { display: flex; gap: 8px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.chip {
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 18px;
  background: none; color: var(--muted);
  font-size: .9rem; white-space: nowrap; cursor: pointer;
}
.chip.is-active { background: var(--surface-2); border-color: var(--accent); color: var(--text); }

.list-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding-bottom: 96px; /* Platz für die Rückgängig-Leiste */
}

.pull {
  display: flex; align-items: flex-end; justify-content: center;
  width: 100%; height: 32px;
  padding: 0 0 6px;
  border: 0; background: none;
  color: var(--faint); font-size: .75rem;
  transition: height .15s ease;
  cursor: pointer;
}
.pull.is-armed { color: var(--accent); }
.pull[hidden] { display: none; }

.section__title {
  position: sticky; top: 0; z-index: 1;
  margin: 0; padding: 14px 16px 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
}
.section--danger .section__title { color: var(--danger); }

.tasks { list-style: none; margin: 0; padding: 0; }

.task {
  position: relative;
  overflow: hidden;
  transition: height .2s ease, opacity .2s ease;
}
.task__bg {
  position: absolute; inset: 0;
  display: flex; align-items: center; gap: 8px;
  padding-left: 20px;
  background: #1e3a2a; color: var(--done);
  font-size: .9rem; font-weight: 500;
}
.task__fg {
  position: relative;
  display: flex; align-items: center; gap: 4px;
  width: 100%;
  min-height: 60px;
  padding: 6px 16px 6px 4px;
  border: 0;
  background: var(--bg);
  text-align: left;
  touch-action: pan-y; /* senkrecht scrollt der Browser, waagerecht wischen wir */
  cursor: pointer;
  transition: transform .2s ease;
}
.task--dragging .task__fg { transition: none; }
.task--armed .task__bg { background: #245c3b; }

.task__check {
  flex: none;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: 0; background: none; padding: 0;
  cursor: pointer;
}
.task__check::before {
  content: "";
  grid-area: 1 / 1;
  width: 24px; height: 24px;
  border: 2px solid var(--faint); border-radius: 50%;
  transition: background .15s ease, border-color .15s ease;
}
.task__check .icon {
  grid-area: 1 / 1;
  width: 16px; height: 16px;
  stroke-width: 3;
  color: var(--accent-text);
  opacity: 0;
}
.task--overdue .task__check::before { border-color: var(--danger); }
.task--done .task__check::before { background: var(--done); border-color: var(--done); }
.task--done .task__check .icon { opacity: 1; }
.task--done .task__title { text-decoration: line-through; color: var(--muted); }
.task--collapse { height: 0 !important; opacity: 0; }

.task__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.task__title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.task__urgent {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px; margin-right: 6px;
  border-radius: 50%;
  background: var(--danger); color: #3c0d0a;
  font-size: .75rem; font-weight: 700;
  vertical-align: 2px;
}
.task__meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .8rem; }
.task--overdue .task__due { color: var(--danger); }
.task__who { padding: 0 6px; border-radius: 6px; background: var(--surface-2); font-size: .75rem; line-height: 18px; }
.task__who--open { color: var(--accent); }
.task__repeat .icon { width: 14px; height: 14px; }

/* Rückblick */
.review { padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.review[hidden] { display: none; }
.review__empty { margin: 0; padding: 8px 16px 16px; color: var(--faint); font-size: .9rem; }
.task--closed .task__fg { min-height: 52px; color: var(--faint); }
.task--closed .task__title { text-decoration: line-through; }
.task--missed .task__title, .task--skipped .task__title { text-decoration: none; font-style: italic; }
.task__check--closed { width: 48px; }
.task__check--closed::before { border-color: var(--border); }
.task--done .task__check--closed::before { background: var(--surface-2); border-color: var(--surface-2); }
.task--done .task__check--closed .icon { opacity: 1; color: var(--faint); }

.empty { margin: 48px 16px; color: var(--muted); text-align: center; }

/* Rückgängig-Leiste über der Navigation */
.snackbar {
  position: absolute;
  left: 12px; right: 12px;
  bottom: 12px; /* über dem Bereich "Ohne Termin" */
  z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 0 8px 0 16px;
  border-radius: var(--radius);
  background: #e8eaed; color: #202124;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}
.snackbar[hidden] { display: none; }
.snackbar button {
  min-height: 44px; padding: 0 12px;
  border: 0; background: none;
  color: #1a5fd0; font-weight: 600; cursor: pointer;
}
.snackbar button[hidden] { display: none; }

/* Navigation unten */
.tabbar {
  /* Eigene Ebene über dem Bereich "Ohne Termin": dessen Zeilen sind positioniert (fürs Wischen)
     und würden sonst den nach oben herausragenden "+"-Knopf überdecken. */
  position: relative;
  z-index: 3;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 16px env(safe-area-inset-bottom);
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 48px;
  border: 0; background: none;
  color: var(--muted); font-size: .75rem;
  cursor: pointer;
}
.tab.is-active { color: var(--accent); }
.tab:disabled { opacity: .35; cursor: default; }
.tab--add {
  width: 56px; height: 56px; min-height: 0;
  margin-top: -20px;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .4);
}
.tab--add .icon { width: 28px; height: 28px; stroke-width: 2.5; }
.tab--add:disabled { opacity: 1; background: var(--surface-2); color: var(--faint); box-shadow: none; }

/* ---------- Vollbild-Ansichten (Bearbeiten, Einstellungen) ---------- */

.sheet {
  position: absolute; inset: 0;
  z-index: 10;
  display: flex; flex-direction: column;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
}
.sheet__header { display: flex; align-items: center; gap: 4px; padding: 8px 16px 8px 4px; }
.sheet__header h1 { font-size: 1.15rem; }
.sheet__body {
  flex: 1; min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  display: flex; flex-direction: column; gap: var(--gap);
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet__actions { display: flex; flex-direction: column; gap: 12px; margin-top: auto; padding-top: 8px; }
.sheet__secondary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sheet__secondary .button[hidden] { display: none; }
.sheet__secondary:has(.button[hidden]) { grid-template-columns: 1fr; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > legend { padding: 0; margin-bottom: 6px; }
.field-row { display: flex; gap: 12px; }
.field-row[hidden], .field[hidden] { display: none; }
.field-row > .field { flex: 1; }
.field--time { flex: 0 0 9.5rem !important; }
.field--every { flex: 0 0 6rem !important; }
.field input:disabled { opacity: .4; }

.segmented { display: flex; gap: 4px; padding: 4px; border-radius: var(--radius); background: var(--surface); }
.segmented label { flex: 1; position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: grid; place-items: center;
  min-height: 40px; padding: 0 6px;
  border-radius: 9px;
  color: var(--muted); font-size: .875rem; text-align: center;
}
.segmented input:checked + span { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--accent); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.toggle {
  flex-direction: row-reverse;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 48px; padding: 0 14px;
  border-radius: var(--radius); background: var(--surface);
  cursor: pointer;
}
.toggle input { width: 22px; height: 22px; accent-color: var(--danger); }

.settings__who { margin: 0; }
.version { color: var(--faint); font-size: .75rem; text-align: center; }

/* ---------- Fester Bereich "Ohne Termin" über dem Menü ---------- */

.nodate {
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.nodate__header {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; min-height: 44px;
  padding: 0 16px;
  border: 0; background: none;
  color: var(--muted);
  font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  cursor: pointer;
  touch-action: none; /* Wischen auf der Kopfzeile gehört uns, nicht dem Browser */
}
.nodate__chevron { width: 18px; height: 18px; transition: transform .2s ease; }
.nodate.is-collapsed .nodate__chevron { transform: rotate(180deg); }
.nodate.is-empty .nodate__chevron { visibility: hidden; }
.nodate__list {
  max-height: calc(33dvh - 44px); /* zusammen mit der Kopfzeile etwa ein Drittel */
  overflow-y: auto;
  padding-bottom: 24px; /* letzte Zeile lässt sich über den "+"-Knopf scrollen */
  overscroll-behavior-y: contain;
}
.nodate.is-collapsed .nodate__list { display: none; }

/* "Übernehmen" bei offenen Aufgaben */
.task__claim {
  flex: none;
  min-height: 36px; padding: 0 12px; margin-left: 8px;
  border: 1px solid var(--accent); border-radius: 18px;
  background: none; color: var(--accent);
  font-size: .8rem; font-weight: 500;
  cursor: pointer;
}

/* ---------- Anlegen: Feld unten über der Tastatur ---------- */

.fields { display: flex; flex-direction: column; gap: var(--gap); }
.fields[hidden] { display: none; }

.add {
  position: fixed; inset: 0;
  z-index: 20;
  display: flex; align-items: flex-end;
  background: rgba(0, 0, 0, .55);
}
.add__sheet {
  width: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  background: var(--surface);
}
.add__row { display: flex; gap: 8px; }
.add__input {
  flex: 1; min-width: 0;
  min-height: 52px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  font: inherit; font-size: 1.05rem;
}
.add__input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.add__save {
  flex: none;
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  cursor: pointer;
}
/* Feste Höhe: die Bestätigung darf das Feld nicht verschieben, während getippt wird. */
.add__status { margin: 0; min-height: 1.3em; color: var(--done); font-size: .85rem; line-height: 1.3; }
.add__more {
  align-self: flex-start;
  min-height: 40px; padding: 0 4px;
  border: 0; background: none;
  color: var(--accent); font-weight: 500;
  cursor: pointer;
}
.add__more[aria-expanded="true"]::after { content: " ▴"; }
.add__more[aria-expanded="false"]::after { content: " ▾"; }
.add__fields .field input, .add__fields .field select { background: var(--bg); }
.add__fields .segmented, .add__fields .toggle { background: var(--bg); }

/* ---------- Offline / Senden ---------- */

.netbar {
  margin: 0 16px 6px;
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .8rem;
  text-align: center;
}
.netbar.is-offline { background: #3b2f12; color: #f6c26b; }
.netbar[hidden] { display: none; }
.task__pending { color: var(--faint); font-size: .7rem; font-style: italic; }

/* ---------- Einstellungen ---------- */

.settings__group { display: flex; flex-direction: column; gap: 12px; }
.settings__title {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
}
.settings__device { display: flex; flex-direction: column; gap: 8px; }
.settings__device .button[hidden] { display: none; }
.settings__toggles { display: flex; flex-direction: column; gap: 8px; }
.settings__toggles[hidden] { display: none; }
.settings__hint:empty { display: none; }
.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 0 14px;
  border-radius: var(--radius); background: var(--surface);
  cursor: pointer;
}
.switch--sub { margin-left: 16px; }
.switch:has(input:disabled) { opacity: .45; cursor: default; }
.switch input {
  appearance: none; flex: none;
  width: 44px; height: 26px; margin: 0;
  border-radius: 13px; background: var(--border);
  position: relative; cursor: inherit;
  transition: background .15s ease;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--text);
  transition: transform .15s ease;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); background: var(--accent-text); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* API-Zugänge */
.tokens { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.token {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 10px 10px 14px; border-radius: var(--radius); background: var(--surface);
}
.token div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.token small { color: var(--muted); font-size: .75rem; }
.token .button { min-height: 40px; padding: 0 12px; flex: none; }
.token-new { display: flex; gap: 8px; }
.token-new[hidden] { display: none; }
.token-new input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit;
}
.token-created {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 14px; border: 1px solid var(--accent); border-radius: var(--radius);
}
.token-created[hidden] { display: none; }
.token-created p { margin: 0; font-size: .875rem; }
.token-created code {
  padding: 8px 10px; border-radius: 8px; background: var(--bg);
  font-size: .8rem; overflow-wrap: anywhere; user-select: all;
}
