:root {
  color-scheme: dark;
  --bg: #141518;
  --surface: #1c1d21;
  --raised: #232429;
  --text: #e4e4e2;
  --muted: #95969c;
  --line: #2c2e33;
  --input: #17181b;
  --input-line: #3a3c42;
  --accent: #7aa7d4;
  --btn: #2f5f8a;
  --btn-hover: #3a6f9e;
  --ok: #57b07f;
  --warn: #d49a4a;
  --err: #e0756d;
  --danger-line: #5c3430;
  --danger-bg: #2a1d1c;
  --radius: 4px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; scrollbar-color: #3a3c42 var(--bg); }

body {
  margin: 0;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.45rem; font-weight: 600; margin: 0 0 1.25rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 2rem 0 .75rem; }
h2:first-child { margin-top: 0; }
p { margin: 0 0 1rem; }

/* Kopfzeile */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 28px; min-height: 56px; flex-wrap: wrap;
}
.brand { color: var(--text); font-weight: 600; white-space: nowrap; }
.brand span { color: var(--muted); font-weight: 400; margin-left: 6px; }
.brand:hover { text-decoration: none; }
.nav-wrap { display: flex; align-items: center; gap: 28px; flex: 1; }
.nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.nav-toggle { display: none; }
.nav a {
  color: var(--muted); padding: 17px 10px 15px; border-bottom: 2px solid transparent;
}
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); border-bottom-color: var(--accent); }
.userbox { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: .9rem; }
.userbox form { margin: 0; }

.linkbutton {
  background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer;
}
.linkbutton:hover { text-decoration: underline; }

main { max-width: 1080px; margin: 0 auto; padding: 32px 20px 64px; }

/* Flächen */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.panel + .panel { margin-top: 16px; }
.panel-flush { padding: 0; overflow-x: auto; }
.narrow { max-width: 560px; }

.head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 1.25rem; }
.head h1 { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 28px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.stat b { display: block; font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.stat a, .stat span { color: var(--muted); font-size: .9rem; }

/* Tabellen */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 500; color: var(--muted); font-size: .85rem; background: var(--raised); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; word-break: break-all; }
.empty { padding: 18px 16px; color: var(--muted); }

/* Status */
.state { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.state.ok::before { background: var(--ok); }
.state.warn::before { background: var(--warn); }
.state.err::before { background: var(--err); }

.bar { height: 4px; background: var(--line); border-radius: 2px; width: 90px; margin-top: 5px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* Formulare */
label { display: block; font-weight: 500; margin-bottom: 4px; font-size: .9rem; }
.field { margin-bottom: 16px; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--input); border: 1px solid var(--input-line); border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(122, 167, 212, .3); border-color: var(--accent); }
textarea { resize: vertical; }
.helptext, .field .help { display: block; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--err); font-size: .85rem; }
.input-suffix { display: flex; align-items: stretch; }
.input-suffix input { border-radius: var(--radius) 0 0 var(--radius); }
.input-suffix span { padding: 8px 10px; border: 1px solid var(--input-line); border-left: 0; background: var(--raised); border-radius: 0 var(--radius) var(--radius) 0; color: var(--muted); white-space: nowrap; }

.btn {
  display: inline-block; padding: 8px 16px; font: inherit; font-weight: 500; cursor: pointer;
  background: var(--btn); color: #fff; border: 1px solid var(--btn); border-radius: var(--radius);
}
.btn:hover { background: var(--btn-hover); border-color: var(--btn-hover); text-decoration: none; }
.btn-plain { background: var(--surface); color: var(--text); border-color: var(--input-line); }
.btn-plain:hover { background: var(--raised); border-color: var(--input-line); }
.btn-small { padding: 4px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline { display: inline; margin: 0; }

/* Meldungen */
.messages { list-style: none; padding: 0; margin: 0 0 20px; }
.messages li { padding: 10px 14px; border: 1px solid var(--line); border-left: 3px solid var(--accent); background: var(--surface); margin-bottom: 8px; border-radius: var(--radius); }
.messages li.error { border-left-color: var(--err); }
.messages li.success { border-left-color: var(--ok); }
.notice { padding: 10px 14px; background: var(--raised); border-radius: var(--radius); color: var(--muted); font-size: .9rem; margin-bottom: 16px; }

/* Anmeldung */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-brand { font-weight: 600; margin-bottom: 20px; }
.auth-brand span { color: var(--muted); font-weight: 400; margin-left: 6px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.foot { margin-top: 18px; color: var(--muted); font-size: .8rem; }

/* Tickets */
.thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.msg { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.msg.staff { border-left: 3px solid var(--accent); }
.msg-head { padding: 9px 16px; border-bottom: 1px solid var(--line); font-size: .85rem; color: var(--muted); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.msg-head b { color: var(--text); font-weight: 500; }
.msg-body { padding: 14px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.filters a { padding: 4px 10px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); background: var(--surface); font-size: .875rem; }
.filters a.active { color: var(--text); border-color: var(--text); }
.filters a:hover { text-decoration: none; color: var(--text); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

@media (max-width: 900px) {
  .topbar-inner { gap: 0; padding: 0 16px; min-height: 52px; flex-wrap: wrap; }
  .nav-toggle {
    display: inline-flex; align-items: center; gap: 8px; margin-left: auto; padding: 7px 10px;
    background: none; border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); font: inherit; font-size: .9rem; cursor: pointer;
  }
  .nav-toggle[aria-expanded="true"] { background: var(--raised); }
  .nav-wrap { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 0; padding: 6px 0 12px; border-top: 1px solid var(--line); }
  .nav-wrap.open { display: flex; }
  .nav { flex-direction: column; gap: 0; }
  .nav a { padding: 11px 12px; border-bottom: 0; border-left: 2px solid transparent; border-radius: 0 var(--radius) var(--radius) 0; }
  .nav a.active { border-left-color: var(--accent); background: var(--raised); }
  .userbox { justify-content: space-between; margin-top: 8px; padding: 12px 12px 0; border-top: 1px solid var(--line); font-size: .95rem; }
}

@media (max-width: 760px) {
  main { padding: 22px 16px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  th, td { padding: 9px 12px; }
}

/* Verwaltung */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar form { display: flex; gap: 8px; align-items: center; margin: 0; flex-wrap: wrap; }
.toolbar input[type=text], .toolbar select { width: auto; min-width: 180px; padding: 6px 9px; }
.toolbar .spacer { flex: 1; }
td select.assign { padding: 4px 6px; font-size: .875rem; min-width: 170px; width: auto; }
.btn-danger { background: var(--surface); color: var(--err); border-color: var(--danger-line); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger-line); }
.danger-zone { margin-top: 16px; border-color: var(--danger-line); }
.checkbox-field { display: flex; gap: 8px; align-items: flex-start; }
.checkbox-field input { margin-top: 4px; }
.checkbox-field label { margin: 0; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; font-size: .925rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 28px 0 10px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.tag { display: inline-block; padding: 1px 7px; border: 1px solid var(--line); border-radius: 3px; font-size: .78rem; color: var(--muted); background: var(--raised); }
.linkbutton.danger { color: var(--err); }

input::placeholder, textarea::placeholder { color: #6c6d73; }
input[type=checkbox] { accent-color: var(--btn); }
input:-webkit-autofill { -webkit-box-shadow: 0 0 0 40px var(--input) inset; -webkit-text-fill-color: var(--text); }
::selection { background: rgba(122, 167, 212, .35); }

.invite-panel { padding: 0; }
.invite-form { padding: 18px 20px; margin: 0; }
.invite-row { display: flex; gap: 10px; }
.invite-row input { flex: 1; max-width: 440px; }
.invite-row .btn { white-space: nowrap; }
.invite-item { padding: 14px 20px; border-top: 1px solid var(--line); }
.invite-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.invite-head b { font-weight: 500; margin-right: 10px; }
.invite-actions { display: flex; gap: 14px; }
.copy-field { display: flex; margin-top: 10px; max-width: 640px; }
.copy-field input { border-radius: var(--radius) 0 0 var(--radius); color: var(--muted); }
.copy-field .btn { border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; white-space: nowrap; }
@media (max-width: 560px) {
  .invite-row { flex-direction: column; }
  .invite-row input { max-width: none; }
}

/* Auswahlfelder (Radio) */
.field ul.radio, .field div:has(> div > label > input[type=radio]) { list-style: none; padding: 0; margin: 4px 0 0; }
.field label:has(> input[type=radio]) { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; margin-bottom: 6px; cursor: pointer; }
.field label:has(> input[type=radio]) input { margin-top: 4px; accent-color: var(--btn); }

.assign-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line); margin: 0; }
.assign-form select { width: auto; min-width: 240px; padding: 6px 9px; }
.assign-form .help { margin: 0; }

/* E-Mail-Programm-Einstellungen */
.mail-settings { margin-top: 10px; padding: 0; }
.mail-settings summary { padding: 12px 18px; cursor: pointer; color: var(--accent); list-style: none; }
.mail-settings summary::-webkit-details-marker { display: none; }
.mail-settings summary::before { content: "▸"; display: inline-block; width: 1em; color: var(--muted); }
.mail-settings[open] summary::before { content: "▾"; }
.mail-settings[open] summary { border-bottom: 1px solid var(--line); }
.mail-settings > .mail-settings-grid, .mail-settings > p { padding: 0 18px; }
.mail-settings > p { padding-bottom: 16px; }
.mail-settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; padding-top: 14px !important; }
.mail-settings h3 { font-size: .85rem; font-weight: 500; color: var(--muted); margin: 0 0 6px; text-transform: none; }
@media (max-width: 640px) { .mail-settings-grid { grid-template-columns: 1fr; } }

/* Statuszusammenfassung auf der Übersicht */
.health { display: flex; align-items: baseline; gap: 6px 14px; flex-wrap: wrap; padding: 14px 18px 14px 40px; margin-bottom: 20px; position: relative;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.health::before { content: ""; position: absolute; left: 18px; top: 21px; width: 10px; height: 10px; border-radius: 50%; }
.health-ok::before { background: var(--ok); }
.health-bad { border-color: var(--danger-line); }
.health-bad::before { background: var(--err); }
.health b { font-weight: 500; }
.health ul { flex-basis: 100%; margin: 4px 0 0; padding: 0; list-style: none; font-size: .9rem; color: var(--muted); }
.health li { padding: 2px 0; }

/* E-Mail-Vorlagen */
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; background: var(--raised); padding: 1px 5px; border-radius: 3px; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; line-height: 1.5; tab-size: 2; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.template-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.template-preview { padding: 0; overflow: hidden; position: sticky; top: 16px; }
.preview-head { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.preview-head b { font-weight: 500; }
.template-preview iframe { display: block; width: 100%; height: 640px; border: 0; background: #f2f2f0; }
@media (max-width: 1000px) { .template-editor { grid-template-columns: 1fr; } .template-preview { position: static; } }

.check-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--input-line); border-radius: var(--radius); background: var(--input); padding: 6px 10px; }
.check-list > div > div { padding: 2px 0; }
.check-list label { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; margin: 0; cursor: pointer; }
.check-list input { margin-top: 4px; accent-color: var(--btn); }

/* Anmelden als */
.impersonation-bar { display: flex; justify-content: center; align-items: center; gap: 8px 16px; flex-wrap: wrap; padding: 8px 16px;
  background: #4a3418; color: #f3dfbf; border-bottom: 1px solid #6b4c22; font-size: .9rem; text-align: center; }
.impersonation-bar b { font-weight: 600; color: #fff; }
.impersonation-bar form { margin: 0; }
.impersonation-bar .btn { background: #d49a4a; border-color: #d49a4a; color: #1c1c1c; }
.impersonation-bar .btn:hover { background: #e0aa5c; border-color: #e0aa5c; }

/* Schalter Status-Prüfung */
.toggle { display: inline-flex; align-items: center; gap: 7px; background: none; border: 0; padding: 2px 0; cursor: pointer; color: var(--muted); font: inherit; font-size: .85rem; }
.toggle-track { width: 30px; height: 16px; border-radius: 8px; background: var(--input-line); position: relative; transition: background .15s; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--text); transition: left .15s; }
.toggle.on .toggle-track { background: var(--btn); }
.toggle.on .toggle-thumb { left: 16px; background: #fff; }
.toggle.on { color: var(--text); }
