:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #17202a;
  --muted: #667085;
  --accent: #0f766e;
  --accent-soft: #d9f2ef;
  --ring: #0f766e;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --warn: #b54708;
  --warn-soft: #fef0c7;
  --ok: #067647;
  --ok-soft: #d3f8df;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2b313c;
    --text: #e7eaf0;
    --muted: #98a2b3;
    --accent: #2dd4bf;
    --accent-soft: #10312e;
    --ring: #2dd4bf;
    --danger: #fda29b;
    --danger-soft: #3a1b18;
    --warn: #fdb022;
    --warn-soft: #3a2a10;
    --ok: #6ce9a6;
    --ok-soft: #102d1f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ------------------------------ Anmeldung ------------------------------ */
.gate {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: grid; place-items: center; padding: 16px;
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(420px, 100%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px; display: grid; gap: 14px;
}
.gate-card h1 { margin: 0; font-size: 20px; }
.gate-card p { margin: 0; color: var(--muted); font-size: 14px; }
.gate-card input {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.gate-card .row { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.gate-error { color: var(--danger); }

/* -------------------------------- Kopf --------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 18px;
}
.brand strong { display: block; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 12px; }
.topstats { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.topstats .stat {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--muted);
}
.topstats .stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.topactions { display: flex; align-items: center; gap: 10px; }
.topactions input[type="search"] {
  width: 240px; padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.ext-badge {
  font: 600 13px var(--mono); padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.off { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

main { padding: 16px; display: grid; gap: 16px; max-width: 1500px; margin: 0 auto; }

/* ------------------------------ Screen-Pop ----------------------------- */
.pop {
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); overflow: hidden;
}
.pop[hidden] { display: none; }
.pop.ringing { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
}
@media (prefers-reduced-motion: reduce) { .pop.ringing { animation: none; } }
.pop-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; background: var(--accent-soft); color: var(--accent);
  font-size: 13px; font-weight: 600; letter-spacing: .02em;
}
.pop-timer { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pop-body { display: grid; grid-template-columns: 1fr minmax(260px, 340px); gap: 20px; padding: 18px 16px; }
@media (max-width: 860px) { .pop-body { grid-template-columns: 1fr; } }
.pop-who h2 { margin: 0 0 4px; font-size: 26px; line-height: 1.2; }
.pop-number { font-family: var(--mono); font-size: 17px; color: var(--muted); }
.pop-tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.pop-meta { color: var(--muted); font-size: 14px; display: grid; gap: 2px; }
.pop-side { display: grid; gap: 12px; align-content: start; }
.pop-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.quick { display: grid; gap: 6px; }
.quick label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.quick textarea, .quick input {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); resize: vertical;
}

/* ------------------------------- Spalten ------------------------------- */
.columns { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(340px, 1.4fr) minmax(260px, .9fr); gap: 16px; }
@media (max-width: 1180px) { .columns { grid-template-columns: 1fr 1fr; } .panel.wide { grid-column: 1 / -1; } }
@media (max-width: 720px) { .columns { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column; min-height: 220px;
}
.panel-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.panel-head h3 { margin: 0; font-size: 14px; letter-spacing: .02em; }
.panel-head small { color: var(--muted); font-size: 12px; }
.panel-head .count {
  margin-left: auto; background: var(--warn-soft); color: var(--warn);
  border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600;
}
.tabs { margin-left: auto; display: flex; gap: 4px; }
.tab {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 4px 10px; border-radius: 999px; cursor: pointer; font-size: 13px;
}
.tab.active { background: var(--surface); border-color: var(--border); color: var(--text); }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; max-height: 460px; }
.list li { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list li.empty { color: var(--muted); font-size: 14px; }
.list li.item { cursor: pointer; display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: center; }
.list li.item:hover { background: var(--surface-2); }
.list li.item .who { min-width: 0; }
.list li.item .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li.item .who span { color: var(--muted); font-size: 13px; font-family: var(--mono); }
.list li.item .when { color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }
.arrow { font-size: 15px; text-align: center; }
.arrow.in { color: var(--ok); }
.arrow.out { color: var(--accent); }
.arrow.missed { color: var(--danger); }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid transparent;
}
.badge.box { background: var(--accent-soft); color: var(--accent); }
.badge.hnr { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.plain { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

.detail { padding: 14px; overflow-y: auto; max-height: 520px; display: grid; gap: 14px; }
.detail .empty { color: var(--muted); }
.detail h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.numbers { display: grid; gap: 6px; }
.numbers .num {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-family: var(--mono); font-size: 14px;
}
.timeline { display: grid; gap: 8px; }
.tl {
  border-left: 3px solid var(--border); padding: 4px 0 4px 12px;
}
.tl.call { border-color: var(--accent); }
.tl.note { border-color: var(--warn); }
.tl.task { border-color: var(--ok); }
.tl time { display: block; color: var(--muted); font-size: 12px; }

.btn {
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.btn:hover { filter: brightness(1.06); }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 13px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn { color: #06201d; }
}

.sim .panel-head { gap: 12px; }
.sim-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 14px; }
.sim-form input[type="text"], .sim-form select {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
}
.sim-form input[type="text"]:first-child { flex: 1 1 260px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow);
  z-index: 40; font-size: 14px;
}
.toast[hidden] { display: none; }
