:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --bullet: #b4b9c0;
  --bullet-ring: #dfe3e8;
  --accent: #2f6feb;
  --mark: #ffe694;
  --tag: #7c4dde;
  --date: #0f7a68;
  --panel: #ffffff;
  --shadow: 0 8px 28px rgba(15, 23, 42, .14);
  --row: 1.55;
  --indent: 26px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --fg: #e6e8ec;
    --muted: #9aa1ad;
    --faint: #6d7480;
    --line: #2b2f37;
    --bullet: #6d7480;
    --bullet-ring: #343945;
    --accent: #6ea0ff;
    --mark: #6b5a1d;
    --tag: #b79bff;
    --date: #4fc9b3;
    --panel: #1e2129;
    --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

/* .banner/.touchbar/.menu setzen display, das sonst [hidden] aushebelt. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }

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

.gate { display: grid; place-items: center; min-height: 100dvh; }
.login { width: min(320px, 88vw); }
.login h1 { font-size: 20px; font-weight: 600; margin: 0 0 18px; }
.login form { display: grid; gap: 8px; }
.login label { font-size: 13px; color: var(--muted); }
.login input {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--bg); color: var(--fg);
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.login button {
  padding: 9px 11px; border: 0; border-radius: 7px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.login .err { color: #d33; font-size: 13px; margin: 2px 0 0; }

/* --- Kopfzeile ------------------------------------------------------ */

#bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

#bar .spacer { flex: 1; }

#crumbs { display: flex; align-items: center; gap: 4px; font-size: 13px; min-width: 0; overflow: hidden; }
#crumbs button {
  border: 0; background: none; padding: 2px 4px; border-radius: 5px;
  color: var(--muted); cursor: pointer; white-space: nowrap;
  max-width: 22ch; overflow: hidden; text-overflow: ellipsis;
}
#crumbs button:hover { background: var(--line); color: var(--fg); }
#crumbs .sep { color: var(--faint); }
#crumbs .here { color: var(--fg); font-weight: 600; }
#crumbs .here.static { cursor: default; }
#crumbs .here.static:hover { background: none; }

#search {
  font: inherit; font-size: 14px; width: 180px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); color: var(--fg);
}
#search:focus { outline: none; border-color: var(--accent); width: 240px; }

.icon {
  border: 1px solid transparent; background: none; cursor: pointer;
  width: 30px; height: 30px; border-radius: 7px; color: var(--muted);
  display: grid; place-items: center;
}
.icon:hover { background: var(--line); color: var(--fg); }
.icon[aria-pressed="true"] { background: var(--line); color: var(--accent); }

.status { font-size: 12px; color: var(--faint); min-width: 74px; text-align: right; }
.status[data-state="saving"] { color: var(--muted); }
.status[data-state="error"] { color: #d33; }

/* --- Menü ----------------------------------------------------------- */

.menu {
  position: fixed; right: 12px; top: 50px; z-index: 40;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 5px; min-width: 210px;
}
#rowmenu { right: auto; top: 0; min-width: 190px; }

.menu button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.menu button:hover { background: var(--line); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }

/* --- Gliederung ----------------------------------------------------- */

#outline {
  max-width: 780px;
  margin: 0 auto;
  padding: 22px 20px 45vh;
}

.zoom-title {
  font-size: 26px; font-weight: 600; line-height: 1.25;
  margin: 0 0 14px; padding: 2px 0; outline: none; white-space: pre-wrap;
}
.zoom-title:empty::before { content: "Ohne Titel"; color: var(--faint); }

.kids { list-style: none; margin: 0; padding: 0; }
.kids .kids { margin-left: var(--indent); position: relative; }
.kids .kids::before {
  content: ""; position: absolute; left: -13px; top: 2px; bottom: 4px;
  width: 1px; background: var(--line);
}

.item { position: relative; }

.row { display: flex; align-items: flex-start; gap: 2px; padding: 1px 0; }

.arrow {
  flex: 0 0 auto; width: 16px; height: calc(1em * var(--row));
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--faint); opacity: 0; transition: opacity .12s;
  display: grid; place-items: center; font-size: 10px;
}
.item:hover > .row > .arrow,
.row.has-kids.collapsed .arrow { opacity: 1; }
.arrow:hover { color: var(--fg); }
.row:not(.has-kids) .arrow { visibility: hidden; }
.arrow svg { transition: transform .12s; }
.row.collapsed .arrow svg { transform: rotate(-90deg); }

.bullet {
  flex: 0 0 auto; width: 18px; height: calc(1em * var(--row));
  border: 0; background: none; padding: 0; cursor: pointer;
  display: grid; place-items: center;
}
.bullet i {
  display: block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--bullet);
}
.row.collapsed .bullet i { box-shadow: 0 0 0 4px var(--bullet-ring); }
.bullet:hover i { background: var(--accent); }

.body { flex: 1 1 auto; min-width: 0; padding-left: 4px; }

.text, .note {
  outline: none; white-space: pre-wrap; overflow-wrap: anywhere;
  line-height: var(--row); padding: 0 2px; border-radius: 3px;
}
.text:empty:focus::before { content: "Schreib etwas\2026"; color: var(--faint); pointer-events: none; }
.note:empty:focus::before { content: "Notiz\2026"; color: var(--faint); pointer-events: none; }
.note { font-size: 13.5px; color: var(--muted); }
.note[hidden] { display: none; }

/* Erledigt heisst blass, nicht weg. Der Punkt wird zum Haken. */
.row.done { opacity: .45; }
.row.done > .body > .text { color: var(--muted); }
.row.done .bullet i,
.row.done .bullet:hover i {
  width: auto; height: auto; border-radius: 0; background: none;
  color: var(--muted); font-size: 11px; line-height: 1;
}
.row.done .bullet i::before { content: "\2713"; }

.text mark, .note mark { background: var(--mark); color: inherit; border-radius: 2px; }

.text a, .note a, .zoom-title a {
  color: var(--accent); text-decoration: underline;
  text-underline-offset: 2px; text-decoration-thickness: 1px; cursor: pointer;
}
.text a:hover, .note a:hover, .zoom-title a:hover { text-decoration-thickness: 2px; }

.tag {
  color: var(--tag); cursor: pointer; border-radius: 4px; padding: 0 2px;
  background: color-mix(in srgb, var(--tag) 12%, transparent);
}
.tag:hover { background: color-mix(in srgb, var(--tag) 26%, transparent); }
.row.done .tag { background: none; }

.date {
  color: var(--date); cursor: pointer; border-radius: 4px; padding: 0 2px;
  background: color-mix(in srgb, var(--date) 13%, transparent);
  font-variant-numeric: tabular-nums;
}
.date:hover { background: color-mix(in srgb, var(--date) 28%, transparent); }
.row.done .date { background: none; }

/* --- Tagesplan ------------------------------------------------------- */

.dayhead { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.dayhead button, .daypick {
  font: inherit; color: inherit; background: none;
  border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 9px; cursor: pointer;
}
.dayhead button:hover, .daypick:hover { background: var(--line); }
.daynav { min-width: 32px; }
.daypick { font-size: 14px; }

.daytitle { font-size: 21px; font-weight: 600; margin: 0 0 16px; }

.dayempty { color: var(--muted); font-size: 14px; max-width: 46ch; line-height: 1.6; }

.kids.day .item { border-top: 1px solid var(--line); }
.kids.day .item:last-child { border-bottom: 1px solid var(--line); }
.kids.day .row { align-items: baseline; gap: 12px; padding: 9px 2px; }

.when {
  flex: 0 0 66px; font-variant-numeric: tabular-nums;
  color: var(--date); font-weight: 600; font-size: 14px;
}
.when.allday { color: var(--faint); font-weight: 400; font-size: 12.5px; }

.daycrumb {
  display: block; margin-top: 2px; padding: 1px 3px; border: 0; background: none;
  font-size: 12px; color: var(--faint); cursor: pointer; border-radius: 4px;
  text-align: left; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.daycrumb:hover { background: var(--line); color: var(--fg); }

.hidden { display: none !important; }

/* --- Banner, Touchbar, Hilfe ---------------------------------------- */

.banner {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 50;
  display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 10px 14px; font-size: 14px;
}
.banner button {
  border: 1px solid var(--line); background: none; border-radius: 6px;
  padding: 5px 9px; cursor: pointer; font-size: 13px;
}
.banner button:hover { background: var(--line); }

/* --kb-inset ist die Hoehe der eingeblendeten Tastatur, gesetzt aus app.js.
   Ohne sie klebt die Leiste am Layout-Viewport und liegt hinter der Tastatur. */
.touchbar {
  position: fixed; left: 0; right: 0; bottom: var(--kb-inset, 0px); z-index: 45;
  display: flex; justify-content: space-around;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
}
/* Bei offener Tastatur verdeckt diese die Home-Zone - der Puffer waere doppelt. */
html.kb-open .touchbar { padding-bottom: 6px; }
.touchbar button {
  flex: 1; border: 0; background: none; padding: 10px 0;
  font-size: 18px; color: var(--muted); cursor: pointer; border-radius: 8px;
}
.touchbar button:active { background: var(--line); }
.touchbar button svg { display: block; margin: 0 auto; }

dialog#help {
  border: 1px solid var(--line); border-radius: 12px; padding: 22px 26px;
  background: var(--panel); color: var(--fg); box-shadow: var(--shadow);
  max-width: min(440px, 92vw);
}
dialog#help::backdrop { background: rgba(0, 0, 0, .35); }
dialog#help h2 { margin: 0 0 12px; font-size: 17px; }
dialog#help dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0 0 18px; font-size: 14px; }
dialog#help dt { color: var(--muted); white-space: nowrap; }
dialog#help dd { margin: 0; }
dialog#help button {
  border: 1px solid var(--line); background: none; border-radius: 7px;
  padding: 6px 12px; cursor: pointer;
}

@media (max-width: 620px) {
  :root { --indent: 20px; }
  /* Etwas groesser als am Schreibtisch. Ab 16px hoert iOS ausserdem auf,
     beim Antippen eines Feldes in die Seite hineinzuzoomen. */
  html, body { font-size: 16.5px; }
  .note { font-size: 15px; }
  #search { font-size: 16px; width: 120px; }
  #search:focus { width: 150px; }
  #outline { padding: 16px 12px 40vh; }
  .status { display: none; }
}
