:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --sidebar: #0f1b2d;
  --sidebar-text: #c9d3e1;
  --sidebar-active: #1d2d46;
  --text: #1c2430;
  --muted: #667085;
  --border: #e3e7ee;
  --primary: #1565c0;
  --primary-text: #ffffff;
  --ok: #2e7d32;
  --ok-bg: #e8f5e9;
  --off: #8a94a6;
  --off-bg: #eef1f5;
  --danger: #c62828;
  --danger-bg: #fdecea;
  --warn: #b26a00;
  --warn-bg: #fff4e0;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141a;
    --surface: #181e26;
    --sidebar: #0b0f15;
    --sidebar-text: #aab4c3;
    --sidebar-active: #1a2230;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --border: #283140;
    --primary: #4c9aff;
    --primary-text: #0b1220;
    --ok: #66bb6a;
    --ok-bg: #1d3320;
    --off: #8a94a6;
    --off-bg: #232b36;
    --danger: #ef5350;
    --danger-bg: #3a1d1d;
    --warn: #ffb74d;
    --warn-bg: #3a2c14;
    color-scheme: dark;
  }
  .role-badge.admin { background: #1a2a44; }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono, code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.error { color: var(--danger); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
h2 svg { width: 18px; height: 18px; fill: var(--muted); }
a { color: var(--primary); }

button {
  font: inherit; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
button:hover { filter: brightness(.97); }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.ghost { background: transparent; }
button.block { width: 100%; }
button.ring { background: var(--warn-bg); color: var(--warn); border-color: transparent; font-weight: 600; }
button.stop { background: var(--danger); color: #fff; border-color: var(--danger); font-weight: 600; }
button.link { border: none; background: none; color: var(--primary); padding: 4px 6px; }
button.link.danger { color: var(--danger); }

input, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
label { display: block; margin-bottom: 12px; }
label > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.lang { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang button { border: none; border-radius: 0; padding: 5px 10px; background: transparent; color: inherit; }
.lang button.active { background: var(--primary); color: var(--primary-text); }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand svg { width: 22px; height: 22px; fill: var(--primary); flex: none; }
.brand.big { font-size: 18px; margin-bottom: 18px; }

/* --- Anmeldung --- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; position: relative; }
.auth-lang { position: absolute; top: 16px; right: 16px; }
.auth-card { width: min(380px, 100%); padding: 28px; }
.auth-card h1 { font-size: 20px; margin-bottom: 16px; }

/* --- Shell --- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { color: #fff; padding: 0 8px 18px; }
.sidebar .brand svg { fill: #6aa8ff; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: inherit; text-decoration: none;
}
.nav a svg { width: 19px; height: 19px; fill: currentColor; opacity: .8; flex: none; }
.nav a:hover { background: var(--sidebar-active); }
.nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.pill { margin-left: auto; font-size: 12px; background: #2e7d32; color: #fff; border-radius: 999px; padding: 0 8px; font-weight: 600; }
.pill:empty { display: none; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 4px; }
.sidebar-foot .lang { border-color: #2a3a52; align-self: flex-start; }
.sidebar-foot button.ghost { color: var(--sidebar-text); border-color: #2a3a52; }
.me { display: flex; align-items: center; gap: 8px; font-size: 14px; color: #fff; }

.content { padding: 24px 28px 40px; min-width: 0; }
.page { display: none; max-width: 1200px; }
.page.active { display: block; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card.flush { padding: 0; overflow-x: auto; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
  display: flex; flex-direction: column; text-decoration: none; color: inherit;
}
.stat:hover { border-color: var(--primary); }
.stat strong { font-size: 30px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.ok strong { color: var(--ok); }
.stat.off strong { color: var(--off); }
.stat.alarm strong { color: var(--danger); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--off); display: inline-block; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }

.rows { list-style: none; padding: 0; margin: 0; }
.rows li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.rows li:last-child { border-bottom: none; }
.rows .who { display: flex; flex-direction: column; min-width: 0; }
.rows .who span { font-size: 13px; color: var(--muted); }
.rows .right { text-align: right; font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rows .empty-row { color: var(--muted); justify-content: center; }
.more { display: inline-block; margin-top: 10px; font-size: 14px; }

.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { max-width: 340px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: none; border-radius: 0; padding: 7px 12px; }
.seg button.active { background: var(--primary); color: var(--primary-text); }
.regcode { color: var(--muted); font-size: 14px; }
.regcode code, .kv code { color: var(--text); font-weight: 600; letter-spacing: .04em; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.is-ringing { background: var(--danger-bg); }
td .sub { display: block; font-size: 13px; color: var(--muted); }
td.mono { font-size: 14px; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nowrap { white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.online { color: var(--ok); background: var(--ok-bg); }
.badge.offline { color: var(--off); background: var(--off-bg); }
.ringstate { display: block; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.actions .ring, .actions .stop { margin-right: 6px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.form-inline { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr 160px auto; gap: 12px; align-items: end; }
.form-inline h2 { grid-column: 1 / -1; margin-bottom: 0; }
.form-inline label { margin-bottom: 0; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.row > button { flex: none; }
.code-input { font-size: 18px; letter-spacing: .08em; font-weight: 600; }
#codeForm .row { margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 22px; width: min(540px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(10, 15, 25, .45); }
dialog h2 { font-size: 18px; margin-bottom: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#historyList { max-height: 55vh; overflow: auto; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1c2430; color: #fff;
  padding: 10px 16px; border-radius: 8px; max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, .25); z-index: 20;
}

/* --- Rollen: Manager sieht keine Admin-Bereiche --- */
body.role-manager [data-role="admin"] { display: none !important; }
.role-tag { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--sidebar-text); border: 1px solid #2a3a52; border-radius: 999px; padding: 0 7px; }
.role-badge { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--off-bg); color: var(--muted); white-space: nowrap; }
.role-badge.admin { background: #e3eefc; color: var(--primary); }
select {
  font: inherit; width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
td select { width: auto; padding: 4px 8px; }
.role-help { grid-column: 1 / -1; margin: 0; }

/* --- App-Download --- */
.app-link { display: flex; gap: 8px; align-items: center; margin: 4px 0 12px; }
.app-link code { flex: 1; min-width: 0; overflow-wrap: anywhere; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 14px; }
a.button { display: inline-block; text-decoration: none; border-radius: 8px; padding: 8px 14px; }
a.button.primary { background: var(--primary); color: var(--primary-text); }
a.button.disabled { opacity: .45; pointer-events: none; }
.steps { margin: 14px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.steps li { margin-bottom: 4px; }
.mini-actions { display: flex; align-items: center; gap: 8px; }
.mini-actions button { padding: 3px 9px; font-size: 13px; }

/* --- Rufen / Zuweisen --- */
button.ring.big { padding: 9px 18px; font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.chips button { border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.ack { display: block; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--ok); }
.ringmsg { display: block; margin-top: 2px; font-size: 13px; color: var(--danger); font-style: italic; }
.assign-tools { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.assign-tools input { flex: 1; }
.checklist { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.checklist li { border-bottom: 1px solid var(--border); }
.checklist li:last-child { border-bottom: none; }
.checklist label { display: flex; align-items: center; gap: 10px; padding: 9px 12px; margin: 0; cursor: pointer; }
.checklist input { width: auto; }
.checklist .sub { color: var(--muted); font-size: 13px; }
.assigned { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

/* --- Tablet / Smartphone --- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 10; height: auto; padding: 10px 12px; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .sidebar .brand { padding: 0; flex: 1; }
  .sidebar-foot { margin: 0; flex-direction: row; align-items: center; padding: 0; }
  .sidebar-foot .me { display: none; }
  .sidebar-foot button.block { width: auto; padding: 5px 10px; }
  .nav { order: 3; width: 100%; flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav a { padding: 7px 10px; white-space: nowrap; }
  .nav a svg { display: none; }
  .content { padding: 16px; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { border-bottom: 1px solid var(--border); padding: 10px 0; }
  tbody tr:last-child { border-bottom: none; }
  td { border: none; padding: 4px 16px; }
  td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  td.owner::before { display: none !important; }
  td.owner { font-size: 16px; }
  .toolbar input { max-width: none; }
  .form-inline { grid-template-columns: 1fr; }
}
