/* R&S Protect Center – ruhiges Dunkel-Design mit Protect-Akzent #3898ff, heller Modus umschaltbar.
   Keine externen Schriften, keine Inline-Styles (strikte CSP). */
:root,
[data-theme="dark"] {
  --bg: #0b0f17;
  --bg2: #101623;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-solid: #141b2a;
  --border: rgba(255, 255, 255, 0.11);
  --text: #e8edf5;
  --muted: #a3aec2;
  --accent: #3898ff;
  --accent-strong: #5aabff;
  --accent-ink: #04121f;
  --focus: #ffd166;
  --red: #ff6b6b;
  --red-bg: rgba(255, 107, 107, 0.14);
  --yellow: #ffd166;
  --yellow-bg: rgba(255, 209, 102, 0.14);
  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, 0.13);
  --blue-bg: rgba(56, 152, 255, 0.14);
  --grey-bg: rgba(255, 255, 255, 0.08);
  --input: #0e1420;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f3f6fb;
  --bg2: #e9eef6;
  --panel: #ffffff;
  --panel-solid: #ffffff;
  --border: #d3dbe8;
  --text: #121826;
  --muted: #4b5668;
  --accent: #1f6fd1;
  --accent-strong: #1559b0;
  --accent-ink: #ffffff;
  --focus: #b45309;
  --red: #b42318;
  --red-bg: #fde8e6;
  --yellow: #8a5a00;
  --yellow-bg: #fff4d6;
  --green: #12733b;
  --green-bg: #e3f6ea;
  --blue-bg: #e4efff;
  --grey-bg: #eef1f6;
  --input: #ffffff;
  --shadow: 0 4px 18px rgba(20, 30, 50, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent-strong); }
[data-theme="light"] a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6rem; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8rem; }
img, svg { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -9999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: .5rem; top: .5rem; }

/* Kopfzeile */
.topbar {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .55rem 1rem; background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: .04em; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-weight: 400; letter-spacing: 0; color: var(--muted); font-size: .72rem; }
.topbar .spacer { flex: 1; }
.topbar form { margin: 0; }
.orgswitch { display: flex; gap: .35rem; align-items: center; }
.orgswitch select { max-width: 14rem; }
.orgname { font-weight: 600; }
.danger-zone { margin-top: 1rem; }
.danger-zone > summary { list-style: none; display: inline-flex; }
.danger-zone > summary::-webkit-details-marker { display: none; }
.danger-zone[open] > summary { margin-bottom: .75rem; }
.danger-zone fieldset { border: 1px solid var(--border); border-radius: 8px; margin: .75rem 0; padding: .5rem .75rem; }
.btn.menu-toggle { display: none; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; position: relative; z-index: 21; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; padding: .4rem .7rem; border: 1px solid var(--border); border-radius: 8px; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu .menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel-solid); border: 1px solid var(--border); border-radius: 10px; padding: .5rem; min-width: 14rem; box-shadow: var(--shadow); z-index: 30; }
.usermenu .menu a, .usermenu .menu button { display: block; width: 100%; text-align: left; padding: .45rem .6rem; border-radius: 6px; color: var(--text); text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer; }
.usermenu .menu a:hover, .usermenu .menu button:hover { background: var(--grey-bg); }

.banner { padding: .6rem 1rem; border-bottom: 1px solid var(--border); }
.banner-support { background: var(--yellow-bg); color: var(--text); }
.banner-support strong { color: var(--yellow); }
.banner form { display: inline; }

/* Layout */
.layout { display: flex; flex: 1; min-width: 0; }
.sidebar { width: 230px; flex-shrink: 0; padding: 1rem .6rem; border-right: 1px solid var(--border); background: var(--bg2); }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a { display: flex; justify-content: space-between; align-items: center; padding: .5rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; }
.sidebar li a:hover { background: var(--grey-bg); }
.sidebar li a[aria-current="page"] { background: var(--blue-bg); color: var(--accent-strong); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
[data-theme="light"] .sidebar li a[aria-current="page"] { color: var(--accent); }
.sidebar .sep { border-top: 1px solid var(--border); margin: .6rem .4rem; }
.count { background: var(--grey-bg); border-radius: 999px; padding: 0 .5rem; font-size: .8rem; min-width: 1.6rem; text-align: center; }
main { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 2rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* Fußzeile */
.footer { display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; padding: .75rem 1rem; border-top: 1px solid var(--border); background: var(--bg2); font-size: .875rem; color: var(--muted); }
.footer a { color: var(--muted); }
.notruf { color: var(--red); font-weight: 700; }

/* Panels, Kacheln */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow); min-width: 0; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.panel-head h2 { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.tile { display: block; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: .9rem 1rem; color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent); }
.tile .label { color: var(--muted); font-size: .9rem; }
.tile .value { font-size: 2rem; font-weight: 700; line-height: 1.1; margin: .15rem 0; }
.tile .sub { font-size: .9rem; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid-side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 1rem; }

/* Statusabzeichen – immer mit Text */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .08rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.b-red { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.b-yellow { background: var(--yellow-bg); color: var(--yellow); border-color: var(--yellow); }
.b-green { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.b-blue { background: var(--blue-bg); color: var(--accent-strong); border-color: var(--accent); }
[data-theme="light"] .b-blue { color: var(--accent); }
.b-grey { background: var(--grey-bg); color: var(--muted); border-color: var(--border); }

/* Listen und Tabellen */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--grey-bg); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: .6rem; align-items: baseline; justify-content: space-between; padding: .5rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.list li:last-child { border-bottom: 0; }
.list .main { flex: 1; min-width: 12rem; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

/* Formulare */
form p, .field { margin: 0 0 .9rem; }
label { display: block; font-weight: 600; margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=search], input[type=tel], input[type=url], select, textarea {
  width: 100%; max-width: 100%; padding: .55rem .65rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--input); color: var(--text); font: inherit;
}
textarea { resize: vertical; }
input[type=file] { max-width: 100%; color: var(--text); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
form > div, .form-grid > div { margin-bottom: .9rem; }
.helptext, form div > div[id$="_helptext"] { display: block; color: var(--muted); font-size: .85rem; margin-top: .2rem; }
ul.errorlist { list-style: none; margin: .25rem 0; padding: 0; color: var(--red); font-weight: 600; }
.errorlist.nonfield { padding: .6rem .8rem; border: 1px solid var(--red); border-radius: 8px; background: var(--red-bg); }
form div:has(> input[type=checkbox]) { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
form div:has(> input[type=checkbox]) label { margin: 0; font-weight: 500; order: 2; }
form div:has(> input[type=checkbox]) input { order: 1; width: 1.15rem; height: 1.15rem; }
form div:has(> input[type=checkbox]) > div { order: 3; flex-basis: 100%; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; margin-bottom: .25rem; padding: 0; }
form div div > div > label, .radio-row label { font-weight: 500; display: inline-flex; gap: .35rem; align-items: center; margin-right: .9rem; }
[role=radiogroup] > div, form ul:not(.errorlist) { display: flex; flex-wrap: wrap; gap: .25rem .4rem; list-style: none; padding: 0; margin: 0; }
form ul:not(.errorlist) li label { font-weight: 500; display: inline-flex; gap: .35rem; align-items: center; }
input[type=checkbox], input[type=radio] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }
.inline-form > div { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters > div { min-width: 9rem; }
.filters label { font-size: .85rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .55rem 1rem; border-radius: 9px; border: 1px solid var(--border); background: var(--grey-bg); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.btn-rd { background: var(--panel-solid); border-color: var(--accent); }
.rd-alt { margin: 1rem 0; }
.rd-alt .btn { width: 100%; }
.btn-small { padding: .3rem .65rem; min-height: 34px; font-size: .875rem; }
.btn-link { background: none; border: 0; color: var(--accent-strong); padding: 0; min-height: 0; text-decoration: underline; font-weight: 500; }

/* Hinweise */
.notice { padding: .75rem .9rem; border-radius: 10px; border: 1px solid var(--border); background: var(--blue-bg); margin: 0 0 1rem; }
.notice-warn { background: var(--yellow-bg); border-color: var(--yellow); }
.notice-danger { background: var(--red-bg); border-color: var(--red); }
.notice-notruf { background: var(--red-bg); border-color: var(--red); font-weight: 600; }
.messages { list-style: none; margin: 0 0 1rem; padding: 0; }
.messages li { padding: .7rem .9rem; border-radius: 10px; margin-bottom: .5rem; border: 1px solid var(--border); background: var(--blue-bg); }
.messages .success { background: var(--green-bg); border-color: var(--green); }
.messages .warning { background: var(--yellow-bg); border-color: var(--yellow); }
.messages .error { background: var(--red-bg); border-color: var(--red); }

/* Reiter */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: .8rem; }
.tabs a { padding: .45rem .8rem; border-radius: 8px 8px 0 0; text-decoration: none; color: var(--muted); }
.tabs a[aria-current="page"] { color: var(--text); background: var(--grey-bg); font-weight: 600; box-shadow: inset 0 -3px 0 var(--accent); }

/* Verlauf */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--border); padding: .2rem 0 .8rem .9rem; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .55rem; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .meta { color: var(--muted); font-size: .85rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Notfallplan, Diff */
.plan-section { margin-bottom: 1rem; }
.plan-section h3 { color: var(--accent-strong); }
[data-theme="light"] .plan-section h3 { color: var(--accent); }
.diff { font-family: Consolas, "Cascadia Mono", Menlo, monospace; font-size: .9rem; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.diff div { padding: .15rem .6rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.diff .add { background: var(--green-bg); }
.diff .del { background: var(--red-bg); text-decoration: line-through; }
.diff .add::before { content: "+ "; font-weight: 700; }
.diff .del::before { content: "− "; font-weight: 700; }
.diff .same::before { content: "  "; }
.codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: .5rem; font-family: Consolas, Menlo, monospace; font-size: 1.05rem; }
.codes li { list-style: none; padding: .4rem .6rem; border: 1px dashed var(--border); border-radius: 8px; text-align: center; }
.qr { background: #fff; padding: 8px; border-radius: 10px; width: 220px; height: 220px; }
.secret { font-family: Consolas, Menlo, monospace; letter-spacing: .08em; overflow-wrap: anywhere; }

/* Anmeldeseiten */
.auth-wrap { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; }
.auth-card { width: 100%; max-width: 30rem; }
.auth-card .brand { margin-bottom: 1rem; }

/* Mobile */
@media (max-width: 900px) {
  .grid2, .grid-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  main { padding: 1rem 1rem 2rem; }
  .js .btn.menu-toggle { display: inline-flex; }
  .js .sidebar { display: none; }
  .js .sidebar.open { display: block; }
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); padding: .5rem; }
  .orgswitch select { max-width: 10rem; }
  .brand small { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .value { font-size: 1.6rem; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--border); padding: .4rem 0; }
  table.stack td { border: 0; padding: .15rem .3rem; }
  table.stack td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .85rem; }
  dl.facts { grid-template-columns: minmax(0, 1fr); }
  dl.facts dt { margin-top: .4rem; }
}

/* Druck */
@media print {
  .topbar, .sidebar, .footer, .no-print, .messages, .banner { display: none !important; }
  body { background: #fff; color: #000; }
  main { padding: 0; }
  .panel { box-shadow: none; border: 1px solid #999; background: #fff; }
  a { color: #000; }
}
.print-page { max-width: 820px; margin: 0 auto; padding: 1.5rem; background: #fff; color: #111; }
.print-page h1, .print-page h2, .print-page h3 { color: #111; }
.print-page table th, .print-page table td { border: 1px solid #999; color: #111; }
.print-page .notice-notruf { background: #fff; color: #8a1c1c; border: 2px solid #8a1c1c; }
.print-body { background: #fff; color: #111; }
