/* Todo Agenda — drei Layouts aus einer Datei:
   Telefon (< 768px)   eine Spalte, Tab-Leiste unten
   iPad (768–1023px)   zwei Spalten, Detail schiebt sich ein
   Mac (>= 1024px)     drei Spalten, alles gleichzeitig sichtbar        */

:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eeea;
  --ink: #1b1b1d;
  --muted: #6e6e75;
  --line: #e2dfd9;
  --line-strong: #cfcbc2;

  --gerd: #1e5aa8;
  --joanna: #a83a6b;

  --open: #8a8a92;
  --doing: #c2740c;
  --waiting: #7a5cc4;
  --done: #2f8f4e;
  --dropped: #a8a5a0;

  --danger: #b3261e;
  --radius: 10px;
  --radius-lg: 14px;
  --header-h: 52px;
  --tabbar-h: 56px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a;
    --surface: #202024;
    --surface-2: #27272c;
    --ink: #ececf0;
    --muted: #9a9aa3;
    --line: #33333a;
    --line-strong: #45454e;
    --gerd: #6fa5e8;
    --joanna: #e08bb2;
    --open: #8f8f99;
    --doing: #e0a34a;
    --waiting: #a992e8;
    --done: #5fc07f;
    --dropped: #6a6a72;
    --danger: #f2837a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 18px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Muss nach dem Reset stehen: eigene display-Regeln wie `.rec { display: flex }`
   schlagen sonst das `display: none` des Browsers fuer [hidden]. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

/* ------------------------------------------------------------------ Kopf */

header.app-bar {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--header-h);
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app-bar h1 {
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.app-bar .spacer { flex: 1; }

.search {
  flex: 0 1 240px;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}
.search:focus { outline: 2px solid var(--gerd); outline-offset: -1px; }

.chip {
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: .82rem;
  font-weight: 550;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip:hover { border-color: var(--line-strong); }
.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--done);
  flex: none;
}
.status-dot.warn { background: var(--doing); }
.status-dot.off { background: var(--dropped); }

.banner {
  padding: 8px 14px;
  background: #fdf3d6;
  color: #6b4b06;
  font-size: .85rem;
  border-bottom: 1px solid var(--line);
}
@media (prefers-color-scheme: dark) {
  .banner { background: #3a3216; color: #f0d79a; }
}

/* --------------------------------------------------------------- Gerüst */

main.shell {
  display: grid;
  height: calc(100dvh - var(--header-h) - env(safe-area-inset-top));
  grid-template-columns: 1fr;
}

.pane {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.pane-head {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.pane-head h2 {
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}
.pane-head .spacer { flex: 1; }

#pane-areas { background: var(--surface-2); border-right: 1px solid var(--line); }
#pane-tree { background: var(--bg); }
#pane-side { background: var(--surface-2); border-left: 1px solid var(--line); }

/* ---------------------------------------------------------- Bereichsmenü */

.area-list { padding: 8px; display: flex; flex-direction: column; gap: 2px; }

.area {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius);
  text-align: left;
  border-left: 3px solid transparent;
}
.area:hover { background: rgba(127, 127, 127, .1); }
.area[aria-current="true"] {
  background: var(--surface);
  box-shadow: var(--shadow);
  border-left-color: var(--accent, var(--muted));
}
.area .name { flex: 1; font-weight: 550; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.area .count {
  font-variant-numeric: tabular-nums;
  font-size: .78rem;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 1px 8px;
}

.owner-mark {
  width: 9px; height: 9px; border-radius: 3px; flex: none;
  background: var(--accent, var(--muted));
}
.owner-gerd { --accent: var(--gerd); }
.owner-joanna { --accent: var(--joanna); }

.filter-row { padding: 6px 8px 14px; display: flex; flex-wrap: wrap; gap: 6px; }

/* ----------------------------------------------------------------- Baum */

.tree { padding: 8px 8px 120px; }

.row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 9px;
  position: relative;
  min-height: 38px;
}
.row:hover { background: rgba(127, 127, 127, .08); }
.row.selected { background: var(--surface); box-shadow: var(--shadow); }
.row.drop-inside { outline: 2px solid var(--gerd); outline-offset: -2px; }
.row.drop-before::before,
.row.drop-after::after {
  content: "";
  position: absolute;
  left: 8px; right: 8px;
  height: 2px;
  background: var(--gerd);
  border-radius: 2px;
}
.row.drop-before::before { top: -1px; }
.row.drop-after::after { bottom: -1px; }
.row.dragging { opacity: .4; }

.twisty {
  width: 20px; height: 20px; flex: none;
  display: grid; place-items: center;
  color: var(--muted);
  border-radius: 5px;
  transition: transform .12s ease;
}
.twisty:hover { background: rgba(127, 127, 127, .16); }
.twisty.open { transform: rotate(90deg); }
.twisty.leaf { visibility: hidden; }

.state {
  width: 20px; height: 20px; flex: none;
  border-radius: 50%;
  border: 2px solid var(--state, var(--open));
  display: grid; place-items: center;
  color: var(--state, var(--open));
  font-size: 11px;
  line-height: 1;
}
.state.filled { background: var(--state); color: var(--surface); border-color: var(--state); }

.st-open { --state: var(--open); }
.st-doing { --state: var(--doing); }
.st-waiting { --state: var(--waiting); }
.st-done { --state: var(--done); }
.st-dropped { --state: var(--dropped); }

.title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row.is-done .title { color: var(--muted); text-decoration: line-through; }
.row.is-dropped .title { color: var(--dropped); text-decoration: line-through; }

.title-input {
  flex: 1;
  min-width: 0;
  height: 26px;
  padding: 0 6px;
  border: 1px solid var(--gerd);
  border-radius: 6px;
  background: var(--surface);
}

.badge {
  flex: none;
  font-size: .72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.badge.due-soon { background: #fdf0d5; color: #8a5a06; }
.badge.due-over { background: #fbe3e1; color: var(--danger); }
.badge.cal { background: rgba(30, 90, 168, .12); color: var(--gerd); }
@media (prefers-color-scheme: dark) {
  .badge.due-soon { background: #3d3418; color: #ecc477; }
  .badge.due-over { background: #43221f; color: #f5a49c; }
}

.progress {
  flex: none;
  width: 46px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.progress > i { display: block; height: 100%; background: var(--done); }

.row-add {
  flex: none;
  width: 24px; height: 24px;
  border-radius: 6px;
  color: var(--muted);
  display: grid; place-items: center;
  opacity: 0;
}
.row:hover .row-add, .row.selected .row-add { opacity: 1; }
.row-add:hover { background: rgba(127, 127, 127, .18); color: var(--ink); }
@media (hover: none) { .row-add { opacity: 1; } }

.children { position: relative; margin-left: 19px; }
.children::before {
  content: "";
  position: absolute;
  top: 0; bottom: 7px;
  left: -2px;
  width: 1px;
  background: var(--line);
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
}

/* --------------------------------------------------------------- Detail */

.detail { padding: 14px; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.input, select.input, textarea.input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  min-height: 36px;
}
textarea.input { min-height: 90px; resize: vertical; line-height: 1.45; }
.input:focus { outline: 2px solid var(--gerd); outline-offset: -1px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  height: 38px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 560;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.btn:hover { border-color: var(--line-strong); }
.btn.primary { background: var(--gerd); border-color: var(--gerd); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: var(--line); }
.btn.danger:hover { background: rgba(179, 38, 30, .09); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.wide { width: 100%; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px;
}
.card > h3 {
  font-size: .74rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 9px;
}

.breadcrumb { font-size: .8rem; color: var(--muted); }

/* ------------------------------------------------------------- Kalender */

.cal-week { display: flex; flex-direction: column; gap: 8px; }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-nav .label { flex: 1; font-weight: 600; font-size: .9rem; }
.cal-nav button {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface);
}

.cal-day { border-top: 1px solid var(--line); padding-top: 7px; }
.cal-day > .day-label {
  font-size: .76rem; font-weight: 700; color: var(--muted);
  display: flex; justify-content: space-between;
}
.cal-day.today > .day-label { color: var(--gerd); }

.event {
  display: flex; align-items: baseline; gap: 8px;
  padding: 5px 8px; margin-top: 4px;
  border-radius: 8px;
  background: var(--surface);
  border-left: 3px solid var(--accent, var(--muted));
  font-size: .85rem;
}
.event .time { font-variant-numeric: tabular-nums; color: var(--muted); flex: none; }
.event .summary { flex: 1; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.event.linked { cursor: pointer; }
.event.linked:hover { box-shadow: var(--shadow); }

.cal-empty { font-size: .82rem; color: var(--muted); padding: 3px 0 5px; }

/* ---------------------------------------------------------------- Modal */

dialog.modal {
  border: none;
  border-radius: 18px;
  padding: 0;
  /* Der Reset oben setzt margin: 0 und wuerde den Dialog links oben ankleben. */
  margin: auto;
  width: min(560px, calc(100vw - 24px));
  max-height: min(86dvh, 760px);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog.modal::backdrop { background: rgba(0, 0, 0, .45); backdrop-filter: blur(3px); }

.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 1rem; font-weight: 650; flex: 1; }
.modal-body { padding: 16px; overflow-y: auto; max-height: 62dvh; }
.modal-foot {
  display: flex; gap: 9px; justify-content: flex-end;
  padding: 12px 16px; border-top: 1px solid var(--line);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------------------------------------------------------------- Diktat */

.rec-hint { font-size: .84rem; color: var(--muted); text-align: center; margin-bottom: 8px; }

.dictate-input { min-height: 100px; font-size: 1rem; }

.transcript {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px;
  font-size: .92rem;
  white-space: pre-wrap;
}

/* Diff der Vorschläge */
.ops { display: flex; flex-direction: column; gap: 8px; }
.op {
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius);
  padding: 9px 11px;
  background: var(--surface);
}
.op.create { border-left-color: var(--done); background: rgba(47, 143, 78, .07); }
.op.update { border-left-color: var(--doing); background: rgba(194, 116, 12, .07); }
.op.move   { border-left-color: var(--waiting); background: rgba(122, 92, 196, .07); }
.op.delete { border-left-color: var(--danger); background: rgba(179, 38, 30, .07); }

.op-head { display: flex; align-items: baseline; gap: 8px; }
.op-kind {
  font-size: .68rem; font-weight: 800; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
}
.op-title { font-weight: 600; flex: 1; }
.op-detail { font-size: .84rem; color: var(--muted); margin-top: 3px; }
.op-path { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.op-reason { font-size: .82rem; margin-top: 5px; font-style: italic; color: var(--muted); }

.meta-line {
  display: flex; flex-wrap: wrap; gap: 8px;
  font-size: .78rem; color: var(--muted); margin-bottom: 10px;
}

/* ------------------------------------------------------------ Tab-Leiste */

nav.tabbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 70;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
nav.tabbar button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-size: .66rem;
  font-weight: 550;
  color: var(--muted);
}
nav.tabbar button[aria-selected="true"] { color: var(--gerd); }

.fab {
  display: none;
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 65;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  place-items: center;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .28);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%) translateY(12px);
  z-index: 90;
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 11px;
  background: var(--ink);
  color: var(--bg);
  font-size: .88rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }

/* ============================ Telefon ============================ */

@media (max-width: 767px) {
  main.shell {
    grid-template-columns: 1fr;
    height: calc(100dvh - var(--header-h) - env(safe-area-inset-top) - var(--tabbar-h)
                 - env(safe-area-inset-bottom));
  }
  .pane { display: none; grid-column: 1; grid-row: 1; }
  .pane.active { display: block; }
  #pane-side { border-left: none; }
  nav.tabbar { display: flex; }
  .fab { display: grid; }
  .search { flex: 1; }
  .app-bar h1 { display: none; }
  .row { min-height: 44px; padding: 8px; }
  .state { width: 24px; height: 24px; }
  .twisty { width: 26px; height: 26px; }
  .detail { padding: 12px 12px 90px; }
  .tree { padding-bottom: 90px; }
}

/* ============================== iPad ============================== */

@media (min-width: 768px) and (max-width: 1023px) {
  main.shell { grid-template-columns: minmax(0, 1fr) 340px; }
  #pane-areas {
    position: fixed;
    top: calc(var(--header-h) + env(safe-area-inset-top));
    bottom: 0; left: 0;
    width: 260px;
    z-index: 55;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  #pane-areas.open { transform: translateX(0); }
  .scrim {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(0, 0, 0, .3);
  }
}

/* =============================== Mac =============================== */

@media (min-width: 1024px) {
  main.shell { grid-template-columns: 244px minmax(0, 1fr) 380px; }
  #btn-areas { display: none; }
  .scrim { display: none; }
  .row { min-height: 34px; padding: 4px 8px; }
}

@media (min-width: 1440px) {
  main.shell { grid-template-columns: 268px minmax(0, 1fr) 430px; }
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
