:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #12222c;
  --muted: #5b6b76;
  --line: #dde4e9;
  --accent: #0b6fa4;
  --accent-ink: #ffffff;
  --on: #1a8a5a;
  --off: #8a8f94;
  --warn: #b4441c;
  --accent-line: #9cc6dd;
  --accent-soft: #e8f2f8;
  --disabled-bg: #8c979f;
  --disabled-ink: #ffffff;
  --master-idle: #e3ebee;
  --master-idle-ink: #5a737f;
  --master-idle-hover: #d5e1e6;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d171d;
    --surface: #152430;
    --ink: #eaf1f5;
    --muted: #9fb2be;
    --line: #263946;
    --accent: #3ea3d8;
    --accent-ink: #06202c;
    --on: #46c98b;
    --off: #7b8892;
    --warn: #ef8a5f;
    --accent-line: #2f6f93;
    --accent-soft: #163449;
    --disabled-bg: #2c3c47;
    --disabled-ink: #8fa3b0;
    --master-idle: #1d3240;
    --master-idle-ink: #8fa6b3;
    --master-idle-hover: #244050;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overflow-anchor: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
#app { max-width: 34rem; margin: 0 auto; padding: 16px 16px 48px; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 6px; }
p { margin: 0 0 12px; }
.muted, .hint { color: var(--muted); font-size: .9rem; }
.hint { margin: 10px 0 0; }
header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.eyebrow { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card > :last-child { margin-bottom: 0; }

button, .as-button {
  font: inherit;
  border-radius: 10px;
  /* Blau beschriftet, damit ein Knopf nicht wie blosser Text aussieht. */
  border: 1px solid var(--accent-line);
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  padding: 11px 14px;
  min-height: 44px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .08s ease, background-color .15s ease, border-color .15s ease, filter .15s ease;
  -webkit-tap-highlight-color: transparent;
}
/* Jeder Druck soll sichtbar sein, auch bevor der Server antwortet. */
button:not([disabled]):active, .as-button:active { transform: scale(.97); filter: brightness(.92); }
button:not([disabled]):hover, .as-button:hover { border-color: var(--accent); background-color: var(--accent-soft); }
button:focus-visible, .as-button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary, .as-button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:not([disabled]):hover, .as-button.primary:hover { background: var(--accent); filter: brightness(1.08); }
button.secondary, .as-button.secondary { background: transparent; }
button.small, .as-button.small { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
/* Nicht verfuegbar: grau gefuellt statt nur blasser, damit es nicht wie ein normaler Knopf wirkt. */
button[disabled], .as-button.is-done {
  background: var(--disabled-bg); border-color: var(--disabled-bg); color: var(--disabled-ink);
  cursor: default; pointer-events: none;
}

.login { text-align: center; padding-top: 12vh; }
.login .mark { font-size: 2.6rem; }
.login form { display: grid; gap: 8px; text-align: left; margin-top: 18px; }
.login label { font-size: .85rem; color: var(--muted); }
input[type=password], input[type=time], input[type=number], input[type=tel] {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 44px; width: 100%;
}
.error { color: var(--warn); font-size: .9rem; min-height: 1.2em; }
/* Meldungen als Snackbar unten: liegt ueber dem Inhalt und verschiebt nichts. */
.banner {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom)); width: min(560px, calc(100% - 32px));
  border-radius: var(--radius); padding: 12px 14px; font-size: .92rem; font-weight: 600;
  /* Vollflaechig, damit sie sich in beiden Farbschemen klar vom Inhalt abhebt. */
  background: var(--warn); border: 0; color: var(--accent-ink);
  box-shadow: 0 8px 28px rgb(0 0 0 / .35);
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  overflow: hidden;
}
/* Ablaufende Zeitleiste: zeigt, dass die Meldung gleich verschwindet. */
.banner-timer { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: currentColor; opacity: .8; transform-origin: left; }
.banner .secondary { color: inherit; border-color: currentColor; }
.banner button:not([disabled]):hover { background: rgb(255 255 255 / .16); border-color: currentColor; }
.banner .close { border: 0; background: none; color: inherit; min-height: 0; padding: 4px 6px; font-size: 1.2rem; line-height: 1; }
.banner[hidden] { display: none; }
.banner #bannerText { flex: 1 1 12rem; }
.banner.ok { background: var(--on); }

.status-line { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--off); flex: none; }
.dot.on { background: var(--on); }
.dot.unknown { background: var(--muted); }

/* Status direkt unter dem Hauptschalter: alles, was gerade gilt, an einer Stelle. */
.status { text-align: left; border-top: 1px solid var(--line); padding-top: 14px; }
.status .status-line strong { font-size: 1.1rem; }
.status #statusText { margin: 0 0 10px; }
.status-rows { display: grid; gap: 6px; margin: 0; }
.status-rows > div { display: flex; justify-content: space-between; gap: 12px; font-size: .92rem; }
.status-rows > div[hidden] { display: none; }
.status-rows dt { color: var(--muted); }
.status-rows dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.status-rows > .warn dd { color: var(--warn); }
.forward-warn { border: 1px solid var(--warn); border-radius: 10px; padding: 10px 12px; margin: 10px 0; color: var(--warn); font-size: .92rem; }
.forward-warn[hidden] { display: none; }
.info { display: flex; gap: 8px; align-items: flex-start; text-align: left; }
.info-icon { flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%; border: 1.5px solid currentColor; display: inline-grid; place-items: center; font: 700 .72rem/1 Georgia, serif; font-style: italic; }
.forward-warn p { margin: 0 0 10px; }
.setup-choice { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.setup-choice p { margin: 0; }
.setup-state { display: inline-block; padding: 1px 10px; border-radius: 999px; background: var(--line); }
.setup-state.on { background: var(--on); color: var(--surface); }
.setup-choice p.small { font-size: .85rem; margin-top: 2px; }
.status > button { width: 100%; margin-top: 12px; }

.override { margin-top: 12px; border: 1px solid var(--accent); border-radius: 12px; padding: 12px; }
.override-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-weight: 600; }
.countdown { font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.override p { margin: 2px 0 10px; }
.override button { width: 100%; }

.busy { display: flex; align-items: center; gap: 8px; color: var(--accent); font-size: .92rem; font-weight: 600; margin: 0 0 10px; }
.busy[hidden] { display: none; }
.spinner {
  display: inline-block; width: 16px; height: 16px; flex: none; vertical-align: -3px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* Waehrend eine Aktion laeuft: gedrueckter Knopf dreht, alle anderen warten. */
.is-busy button, .is-busy .as-button { pointer-events: none; }
.is-busy button:not(.busy) { opacity: .6; }
button.busy { position: relative; color: transparent !important; }
button.busy::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px;
  border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
.master-btn.busy::after, button.primary.busy::after { border-color: #fff; border-right-color: transparent; }
@media (prefers-reduced-motion: reduce) { .spinner, button.busy::after { animation-duration: 2s; } }

/* Aufklappbare Karten: geschlossen reicht die Ueberschrift. */
.fold > summary {
  list-style: none; cursor: pointer; font-weight: 600; font-size: 1.05rem;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: -16px; padding: 16px; min-height: 44px;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: ''; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s ease; flex: none; }
.fold[open] > summary::after { transform: rotate(-135deg); }
.fold[open] > summary + * { margin-top: 16px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; }
.segmented > button { border: none; min-height: 40px; background: transparent; color: var(--muted); font-weight: 600; padding: 6px 4px; }
.segmented > button.active { background: var(--accent); color: var(--accent-ink); }

.choices { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.choices button { flex: 1 1 calc(33% - 8px); }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: .9rem; color: var(--muted); }
.check input { margin-top: 3px; width: 18px; height: 18px; }

.forward-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.forward-actions .as-button { flex: 1; }
.codes-more { margin: 4px 0 10px; }
.codes-more > summary { cursor: pointer; color: var(--muted); font-size: .88rem; padding: 6px 0; }
.codes { display: grid; gap: 8px; margin: 8px 0 0; }
.codes code { font-size: .85rem; color: var(--muted); }
.sub-title { font-size: 1rem; margin: 18px 0 4px; }
.ring-time { display: grid; gap: 6px; margin: 8px 0; font-size: .92rem; }
.conditional { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 10px; }
.conditional li { display: grid; gap: 6px; }
.conditional-actions { display: flex; gap: 8px; }
.conditional-actions .as-button { flex: 1; }
.conditional li { padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); }
.cond-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; }
.cond-state { flex: none; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; color: #fff; }
.cond-state.on { background: var(--on); }
.cond-state.off { background: var(--off); }
.conditional-actions > * { flex: 1; }

/* Wochenplan: erst die knappe Uebersicht, die Felder nur zum Aendern. */
.plan-summary { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0 0 14px; font-variant-numeric: tabular-nums; }
.plan-summary dt { font-weight: 600; }
.plan-summary dd { margin: 0; }
.plan-summary dd.closed { color: var(--muted); }
.warn-text { color: var(--warn); }
#editPlan { width: 100%; }
.fold[open] > summary ~ #planEdit { margin-top: 16px; }
.plan { display: grid; gap: 8px; margin-bottom: 14px; }
.bulk { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); font-size: .88rem; display: grid; gap: 6px; }
.bulk p { margin: 0; }
.day { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.day > .day-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day-name { font-weight: 600; font-size: .95rem; }
.day-closed { color: var(--muted); font-size: .85rem; }
.interval { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; align-items: center; gap: 6px; margin-top: 8px; }
.interval input { min-width: 0; padding: 10px 8px; }
.interval .dash { color: var(--muted); }
.interval .remove {
  border: none; background: none; color: var(--warn);
  min-height: 36px; width: 36px; padding: 0; font-size: 1.1rem; line-height: 1;
}
.day .add { margin-top: 8px; }
.plan-actions { display: flex; align-items: center; gap: 8px; }
.plan-actions .primary { flex: 1; }

/* Anrufe: eine Zeile je Anruf (wann, wer, wie lange), das Gespraech erst aufgeklappt. */
.anrufe { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.anrufe > li { border: 1px solid var(--line); border-radius: 10px; }
.anruf-kopf {
  list-style: none; cursor: pointer; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px;
  align-items: center; padding: 10px 12px; min-height: 44px; font-size: .92rem; font-variant-numeric: tabular-nums;
}
.anruf-kopf::-webkit-details-marker { display: none; }
.anruf-kopf time { color: var(--muted); }
.anruf-wer { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.anruf-dauer { color: var(--muted); }
.anrufe details[open] > .anruf-kopf { border-bottom: 1px solid var(--line); }
.anruf-inhalt { padding: 10px 12px 12px; }
.anruf-nummer { display: inline-block; margin-bottom: 8px; color: var(--accent); font-variant-numeric: tabular-nums; }
.anruf-summe { font-size: .92rem; }
.anruf-felder { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 10px; font-size: .85rem; }
.anruf-felder dt { color: var(--muted); }
.anruf-felder dd { margin: 0; }
.zug { margin: 0 0 4px; font-size: .9rem; line-height: 1.45; }
.zug b { color: var(--muted); font-weight: 600; margin-right: 4px; }
.zug.anrufer { color: var(--ink); }
.zug.assistent { color: var(--muted); }
.anrufe > li.ist-erledigt { opacity: .55; }
.anruf-inhalt > button { margin-top: 8px; }

.foot { text-align: center; margin-top: 28px; }
.mode { font-size: .8rem; color: var(--muted); }

/* Hauptschalter: die wichtigste Bedienung, deshalb gross und ohne Umwege. */
.master{text-align:center}
.master-switch{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:14px}
.master-btn{min-height:76px;font-size:1.5rem;font-weight:800;letter-spacing:.04em;border-radius:16px;background:var(--master-idle);color:var(--master-idle-ink);border:2px solid transparent}
.master-btn[data-master="on"].active{background:#0b775d;color:#fff;border-color:#0b775d}
.master-btn[data-master="off"].active{background:#b42318;color:#fff;border-color:#b42318}
.master-btn:not(.active):not(.temp):hover{background:var(--master-idle-hover);border-color:transparent}
.master-btn{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px}
/* Rufumleitung: nach dem Anruf-Dialog fragt die Kachel nach, die andere bricht ab. */
.master-btn.pending .master-label,.master-btn.cancel .master-label{font-size:1.05rem;letter-spacing:0}
.master-btn[data-master="on"].pending{background:#3f9a83;color:#fff;border-color:#0b775d}
.master-btn[data-master="off"].pending{background:#cf5a4f;color:#fff;border-color:#b42318}
.master-btn.cancel{background:transparent;color:var(--accent);border:1px solid var(--accent-line)}
.master-sub{font-size:.78rem;font-weight:600;letter-spacing:0}
.master-sub:empty{display:none}
/* Zeitfenster oder Pause: nur heller hervorgehoben, weil es nicht dauerhaft gilt. */
.master-btn[data-master="on"].temp{background:#3f9a83;color:#fff;border-color:#0b775d}
.master-btn[data-master="off"].temp{background:#cf5a4f;color:#fff;border-color:#b42318}
.master #masterPlan{width:100%;margin-top:12px}

/* Freie Dauer neben den festen Knoepfen. */
.custom{margin-top:14px}
.custom-row{display:flex;gap:8px;align-items:center}
.custom-row input{flex:1;min-width:0;margin-bottom:0}
.custom-row button{flex:0 0 auto;padding:0 18px}

/* Passkey: Anmeldung per Fingerabdruck, Gesicht oder Geraete-PIN. */
.passkey-login { display: grid; gap: 8px; margin-top: 18px; }
.passkey-login button { width: 100%; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; margin: 6px 0 0; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.offer { border-color: var(--accent); }
.offer p { margin-bottom: 10px; }
.offer-actions { display: flex; gap: 8px; }
.offer-actions button { flex: 1; }
.passkeys { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.passkeys li { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px 8px 12px; }
.passkeys li span { display: grid; }
.passkeys small { color: var(--muted); }
#passkeyAdd { width: 100%; }

/* Eigene Rueckfrage statt confirm(): passt ins Design und laeuft auch in eingebetteten Ansichten. */
.ask { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 18px; width: min(420px, calc(100% - 32px)); }
.ask::backdrop { background: rgb(0 0 0 / .45); }
.ask-title { font-weight: 700; font-size: 1.05rem; margin-bottom: 6px; }
.ask-actions { display: flex; gap: 8px; margin-top: 16px; }
.ask-actions button { flex: 1; }

/* Weiterleitung durch den Assistenten: Ziel, Ausloeser und ob es bei Umleitung ankommt. */
.transfers { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.transfers li { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 4px; }
.transfer-head { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
.transfer-head a { color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.transfer-trigger { color: var(--muted); font-size: .88rem; }
.transfer-check { font-size: .88rem; margin: 0; }
.transfer-check.ok { color: var(--on); }
.transfer-check.warn { color: var(--warn); }
.transfer-check.open { color: var(--muted); }
.handy { margin-top: 14px; display: grid; gap: 6px; }
.handy label { font-size: .92rem; }

/* Weiterleitung durch den Assistenten im Statusbereich: eigener Kasten, damit sie
   nicht mit der Rufumleitung am Handy verwechselt wird. */
.transfer-box { margin-top: 14px; padding: 12px; border-radius: 12px; background: var(--accent-soft); text-align: left; }
.transfer-box.warn { background: transparent; border: 1px solid var(--warn); }
.transfer-box ul { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; font-size: .92rem; }
.transfer-box li b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.transfer-box .transfer-check { display: block; }

/* Auswahlfeld im Stil der Eingabefelder, Pfeil wie bei den aufklappbaren Karten. */
.select { position: relative; display: block; }
.select select {
  appearance: none; -webkit-appearance: none; width: 100%; min-height: 44px; cursor: pointer;
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 40px 10px 12px;
}
.select select:hover { border-color: var(--accent); }
.select select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.select::after {
  content: ''; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px; pointer-events: none;
  border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent); transform: translateY(-70%) rotate(45deg);
}
/* Mit Rufumleitung: Zeiten aendern nur hinter einer Warnung. */
.plan-risk > summary { cursor: pointer; color: var(--muted); font-size: .88rem; padding: 6px 0; }
.plan-risk[open] > summary { margin-bottom: 6px; }
.plan-risk p { font-size: .9rem; margin-bottom: 10px; }
.plan-risk button { width: 100%; }
