:root {
  --bg: #0f0f14;
  --surface: #18181f;
  --surface-2: #22222b;
  --border: #2e2e3a;
  --text: #ececf1;
  --muted: #9a9aab;
  --accent: #9147ff;
  --accent-hover: #a970ff;
  --accent-soft: rgba(145, 71, 255, 0.16);
  --live: #eb0400;
  --ok: #2fbf71;
  --ok-soft: rgba(47, 191, 113, 0.14);
  --warn: #e6a700;
  --danger: #ff5c5c;
  --danger-soft: rgba(255, 92, 92, 0.12);
  --radius: 10px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f4f7;
    --surface: #ffffff;
    --surface-2: #efeff3;
    --border: #dcdce4;
    --text: #18181f;
    --muted: #63637a;
    --accent: #7c2df0;
    --accent-hover: #6a1fd8;
    --accent-soft: rgba(124, 45, 240, 0.1);
    --ok: #1a8f50;
    --ok-soft: rgba(26, 143, 80, 0.1);
    --danger: #d22f2f;
    --danger-soft: rgba(210, 47, 47, 0.08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0 0 12px; line-height: 1.25; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.spacer { flex: 1; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* Buttons */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.button:hover { border-color: var(--muted); }
.button:disabled { opacity: .5; cursor: default; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.ghost { background: transparent; }
.button.danger { color: var(--danger); }
.button.danger:hover { border-color: var(--danger); background: var(--danger-soft); }
.button.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.button.big { min-height: 46px; padding: 0 22px; font-size: 16px; }
.icon-button {
  width: 34px; height: 34px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 24px; cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(420px, 100%); padding: 32px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
}
.login-card p { color: var(--muted); }
.logo {
  width: 56px; height: 56px; margin: 0 auto 16px; display: grid; place-items: center;
  border-radius: 14px; background: var(--accent); color: #fff; font-weight: 800; font-size: 28px;
}
.logo.small { width: 36px; height: 36px; margin: 0; border-radius: 9px; font-size: 18px; }

/* Kopf */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 700; }
.status-pills { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.user { display: flex; align-items: center; gap: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.live { background: var(--live); color: #fff; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.neutral::before { background: var(--muted); }

.tabs {
  display: flex; gap: 4px; padding: 0 24px; overflow-x: auto;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.tabs button {
  padding: 12px 14px; border: 0; border-bottom: 2px solid transparent;
  background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--text); }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.tab-panel { display: grid; gap: 16px; }

/* Karten */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.live-big { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.live-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.live-dot.on { background: var(--live); box-shadow: 0 0 0 4px rgba(235, 4, 0, .2); animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(235, 4, 0, .05); } }
@media (prefers-reduced-motion: reduce) { .live-dot.on { animation: none; } }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 12px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.chat-form { display: grid; gap: 8px; }

/* Timer-Liste */
.timer-row {
  display: grid; grid-template-columns: minmax(120px, 180px) 1fr auto auto; align-items: center; gap: 16px;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.timer-row:first-child { border-top: 0; }
.timer-name { font-weight: 700; }
.timer-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 90px; text-align: right; }
.countdown.waiting { color: var(--warn); font-weight: 600; font-size: 13px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* Befehle */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar input[type="search"] { flex: 1; min-width: 200px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { padding: 0 12px; min-height: 36px; border: 0; background: var(--surface); color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--text); }

.command-list { display: grid; gap: 10px; }
.command {
  display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: start;
  padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.command.off { opacity: .6; }
.command-main { min-width: 0; }
.command-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.command-name { font-weight: 700; font-size: 16px; }
.command-response { margin: 4px 0 8px; overflow-wrap: anywhere; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { padding: 1px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; }
.tag.accent { background: var(--accent-soft); color: var(--accent-hover); }
.command-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.reorder { display: grid; gap: 2px; }
.reorder button { width: 28px; height: 22px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 11px; }
.reorder button:hover:not(:disabled) { color: var(--text); }
.reorder button:disabled { opacity: .3; cursor: default; }

/* Schalter */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Formulare */
input, textarea, select {
  width: 100%; min-height: 38px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: 14px; }
.field-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 18px; min-height: 18px; height: 18px; margin-top: 2px; flex: none; accent-color: var(--accent); }
.prefix-input { display: flex; }
.prefix-input span { display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--border); border-right: 0; border-radius: 8px 0 0 8px; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.prefix-input input { border-radius: 0 8px 8px 0; }
.chip { padding: 0 6px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-2); color: var(--text); font: 12px ui-monospace, Consolas, monospace; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.preview { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); overflow-wrap: anywhere; }
.timer-box { margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); display: grid; gap: 12px; }
.error-box { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); overflow-wrap: anywhere; }

/* Dialog */
dialog {
  width: min(680px, calc(100% - 32px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dialog-head, .dialog-foot { display: flex; align-items: center; gap: 8px; padding: 14px 20px; }
.dialog-head { border-bottom: 1px solid var(--border); justify-content: space-between; }
.dialog-head h2 { margin: 0; }
.dialog-foot { border-top: 1px solid var(--border); }
.dialog-body { display: grid; gap: 16px; padding: 20px; overflow-y: auto; }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; overflow-wrap: anywhere; }
.stream { border-top: 1px solid var(--border); padding: 12px 0; }
.stream:first-of-type { border-top: 0; }
.stream-head { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.stream-title { font-weight: 700; }

/* Meldungen */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 10; max-width: calc(100% - 32px); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--danger); color: var(--danger); }

@media (max-width: 760px) {
  .topbar, .tabs { padding-left: 16px; padding-right: 16px; }
  main { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .command { grid-template-columns: 1fr; }
  .command .reorder { display: none; }
  .command-actions { justify-content: flex-start; }
  .timer-row { grid-template-columns: 1fr auto; }
  .timer-text { grid-column: 1 / -1; grid-row: 2; }
}
