:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1c2430; --muted: #687587; --line: #e1e6ed; --line2: #eef1f5;
  --brand: #1f3a5f; --brand2: #2c5282; --accent: #c8792a; --ok: #2f7d4f; --bad: #b23b3b; --hl: #fff4d6;
  --chip: #e8eef6; --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand2); }
.boot { padding: 40px; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* Buttons & Inputs */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 11px; cursor: pointer; line-height: 1.2; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { border-color: #c3ccd8; background: #f8fafc; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand2); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.active { background: var(--chip); border-color: #b9c7da; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid #9db8dc; outline-offset: 0; border-color: #9db8dc; }
label.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

/* Login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #1f3a5f, #2c5282 60%, #3d6aa6); }
.login { background: #fff; border-radius: 12px; padding: 28px 30px; width: 360px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login p { margin: 0 0 18px; }
.login .stack input { width: 100%; padding: 9px 11px; }
.login .err { color: var(--bad); min-height: 18px; font-size: 13px; }

/* Layout */
.app { display: grid; grid-template-columns: 230px 1fr; grid-template-rows: 54px 1fr; height: 100vh; }
.top { grid-column: 1 / 3; display: flex; align-items: center; gap: 14px; padding: 0 16px; background: var(--brand); color: #fff; }
.top .logo { font-weight: 700; letter-spacing: .3px; white-space: nowrap; cursor: pointer; }
.top .logo span { opacity: .65; font-weight: 400; }
.top .gsearch { flex: 1; display: flex; max-width: 720px; }
.top .gsearch input { flex: 1; border-radius: 6px 0 0 6px; border: 0; padding: 8px 12px; }
.top .gsearch select { border-radius: 0; border: 0; border-left: 1px solid var(--line); }
.top .gsearch button { border-radius: 0 6px 6px 0; border: 0; background: var(--accent); color: #fff; padding: 0 14px; cursor: pointer; }
.top .user { margin-left: auto; display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.top .user .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.top .user .btn:hover { background: rgba(255,255,255,.1); }
.role { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: rgba(255,255,255,.18); text-transform: uppercase; letter-spacing: .5px; }
.side { background: #fff; border-right: 1px solid var(--line); overflow: auto; padding: 10px 8px 20px; }
.side h4 { margin: 14px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
.side a { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.side a:hover { background: var(--bg); }
.side a.on { background: var(--chip); color: var(--brand); font-weight: 600; }
.side a .n { color: var(--muted); font-size: 12px; font-weight: 400; }
.side .meta { margin: 16px 10px 0; font-size: 11px; color: var(--muted); line-height: 1.5; }
.main { overflow: auto; padding: 18px 22px 40px; min-width: 0; }
.main h2 { margin: 0 0 4px; font-size: 20px; }
.main h3 { margin: 18px 0 8px; font-size: 15px; }
.sub { color: var(--muted); margin-bottom: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 14px 16px; }

/* Toolbar */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar .search { display: flex; }
.toolbar .search input { width: 260px; border-radius: 6px 0 0 6px; }
.toolbar .search select { border-radius: 0 6px 6px 0; border-left: 0; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.quick label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
.quick input { width: 210px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; align-items: center; }
.chip { background: var(--chip); border-radius: 14px; padding: 3px 4px 3px 10px; font-size: 12px; display: inline-flex; gap: 4px; align-items: center; border: 1px solid transparent; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 0 5px; font-size: 14px; line-height: 1; }
.chip button:hover { color: var(--bad); }
.chip.tog { cursor: pointer; padding: 3px 10px; background: #fff; border-color: var(--line); user-select: none; }
.chip.tog.yes { background: #e3f1e8; border-color: #9fcfb1; color: #1d5b37; }
.chip.tog.no { background: #f9e5e5; border-color: #e2aaaa; color: #8a2a2a; text-decoration: line-through; }
.count { font-weight: 600; }

/* Grid */
.gridwrap { overflow: auto; max-height: calc(100vh - 290px); border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line2); padding: 6px 9px; text-align: left; vertical-align: top; }
table.grid thead th { position: sticky; top: 0; background: #f7f9fb; z-index: 2; font-weight: 600; font-size: 12.5px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; }
table.grid thead tr.filters th { top: 33px; cursor: default; padding: 4px 5px; background: #fbfcfd; }
table.grid thead tr.filters input, table.grid thead tr.filters select { width: 100%; min-width: 80px; padding: 3px 6px; font-size: 12px; font-weight: 400; }
table.grid thead tr.filters input.set, table.grid thead tr.filters select.set { background: var(--hl); border-color: #e7c77d; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover td { background: #f3f7fc; }
table.grid td { max-width: 360px; }
table.grid td .clip { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.bool { text-align: center; color: var(--ok); }
.sortmark { color: var(--accent); font-size: 11px; margin-left: 3px; }
mark { background: #ffe58a; padding: 0; border-radius: 2px; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

/* Dropdown / Popover */
.dd { position: relative; display: inline-block; }
.dd-menu { position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(16,24,40,.15); z-index: 50; min-width: 220px; padding: 6px; }
.dd-menu.left { left: 0; right: auto; }
.dd-menu button.item { display: flex; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 5px; cursor: pointer; gap: 8px; }
.dd-menu button.item:hover { background: var(--bg); }
.dd-menu .sep { border-top: 1px solid var(--line); margin: 5px 0; }
.colpick { max-height: 380px; overflow: auto; columns: 2; column-gap: 14px; min-width: 420px; padding: 6px 8px; }
.colpick label { display: flex; gap: 6px; padding: 3px 0; break-inside: avoid; font-size: 13px; }

/* Drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 80; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 96vw); background: #fff; z-index: 81; box-shadow: -10px 0 40px rgba(0,0,0,.2); display: flex; flex-direction: column; }
.drawer header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.drawer header h3 { margin: 0; font-size: 16px; flex: 1; }
.drawer .body { overflow: auto; padding: 14px 18px 30px; }
dl.rec { display: grid; grid-template-columns: 190px 1fr; gap: 0; margin: 0; }
dl.rec dt, dl.rec dd { padding: 6px 8px; border-bottom: 1px solid var(--line2); margin: 0; }
dl.rec dt { color: var(--muted); font-size: 12.5px; }
dl.rec dd { white-space: pre-wrap; word-break: break-word; }
dl.rec dd.empty { color: #b8c0cc; }
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 90; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: 460px; max-width: 100%; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 12px; }
.modal .stack input, .modal .stack select { width: 100%; }

/* Gruppieren */
.groupbox { margin-bottom: 12px; }
.bars { display: flex; flex-direction: column; gap: 2px; max-height: 460px; overflow: auto; }
.bar { display: grid; grid-template-columns: minmax(160px, 34%) 1fr 64px; gap: 10px; align-items: center; padding: 3px 6px; border-radius: 5px; cursor: pointer; }
.bar:hover { background: #f3f7fc; }
.bar .lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { background: var(--line2); border-radius: 4px; height: 12px; overflow: hidden; }
.bar .fill { background: linear-gradient(90deg, var(--brand2), #5d87c2); height: 100%; border-radius: 4px; min-width: 2px; }
.bar .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* Ergebnisse / Karten */
.cards { display: grid; gap: 14px; }
.card h3 { margin: 0; font-size: 15px; display: flex; gap: 10px; align-items: baseline; }
.card table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.card td, .card th { padding: 5px 7px; border-bottom: 1px solid var(--line2); text-align: left; font-size: 13px; vertical-align: top; }
.card th { color: var(--muted); font-weight: 600; font-size: 12px; }
.card tbody tr { cursor: pointer; }
.card tbody tr:hover td { background: #f3f7fc; }
.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 14px; }
.kpis { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; min-width: 130px; cursor: pointer; }
.kpi b { display: block; font-size: 20px; color: var(--brand); }
.kpi span { color: var(--muted); font-size: 12px; }

/* Register */
.az { display: flex; flex-wrap: wrap; gap: 3px; margin: 8px 0 12px; }
.az button { min-width: 30px; padding: 4px 6px; border: 1px solid var(--line); background: #fff; border-radius: 5px; cursor: pointer; font-weight: 600; }
.az button:disabled { opacity: .3; cursor: default; }
.az button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.reglist { display: grid; gap: 6px; }
.regitem { display: grid; grid-template-columns: minmax(200px, 1fr) auto; gap: 10px; padding: 9px 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; align-items: center; }
.regitem .name { font-weight: 600; }
.regitem .badges { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 12px; background: var(--chip); border-radius: 12px; padding: 2px 9px; cursor: pointer; border: 1px solid transparent; white-space: nowrap; }
.badge:hover { border-color: #9db8dc; }
.badge b { color: var(--brand); }

/* Admin */
table.list { border-collapse: collapse; width: 100%; background: #fff; }
table.list th, table.list td { border-bottom: 1px solid var(--line2); padding: 7px 9px; text-align: left; font-size: 13px; vertical-align: top; }
table.list th { background: #f7f9fb; font-size: 12px; color: var(--muted); }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--chip); }
.pill.admin { background: #fde8d4; color: #8a4b12; }
.pill.bad { background: #f9e0e0; color: #8a2a2a; }
.pill.ok { background: #e1f1e7; color: #1d5b37; }
.help { font-size: 12.5px; line-height: 1.6; }
.help code { background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.help table td { padding: 2px 10px 2px 0; vertical-align: top; }

#toasts { position: fixed; bottom: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,.25); max-width: 420px; }
.toast.err { background: var(--bad); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .side { display: flex; overflow-x: auto; padding: 6px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side h4, .side .meta { display: none; }
  .side a { white-space: nowrap; }
  .top { flex-wrap: wrap; height: auto; padding: 8px; }
  .top .gsearch { order: 3; flex-basis: 100%; max-width: none; }
  .bar { grid-template-columns: 40% 1fr 50px; }
  dl.rec { grid-template-columns: 1fr; }
  dl.rec dt { border-bottom: 0; padding-bottom: 0; }
}
@media print {
  .side, .top, .toolbar, .pager { display: none; }
  .app { display: block; height: auto; }
  .gridwrap { max-height: none; overflow: visible; }
}
