:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #1b2129;
  --muted: #5f6873;
  --line: #d5dbe3;
  --line-soft: #e7ebf0;
  --primary: #01508e;
  --primary-ink: #ffffff;
  --primary-soft: #e3edf7;
  --accent: #1c7cc9;
  --danger: #a33a2e;
  --danger-soft: #f8e9e6;
  --warn-soft: #fbf2dc;
  --ok-soft: #e5f1e7;
  --info-soft: #e8eef5;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 0 0 .9rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .7rem; font-weight: 650; }
code { background: var(--line-soft); padding: 0 .3em; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.num, table.list .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Kopfzeile */
.topbar {
  background: var(--primary);
  color: var(--primary-ink);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .45rem 1.2rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 3px solid #0b0b0b;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; font-weight: 600; margin-right: auto; }
.brand:hover { color: #fff; }
.brand img { height: 44px; width: auto; }
.brand span { font-size: .98rem; }
.mainnav { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.navgroup { display: flex; align-items: center; gap: .15rem; }
.navgroup.admin { border-left: 1px solid rgba(255,255,255,.25); padding-left: 1rem; }
.navgroup.user { border-left: 1px solid rgba(255,255,255,.25); padding-left: 1rem; }
.navlabel { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; opacity: .7; margin-right: .35rem; }
.mainnav a, .mainnav .linkbtn {
  color: #fff; text-decoration: none; padding: .35rem .6rem; border-radius: 6px; font-size: .93rem;
}
.mainnav a:hover, .mainnav .linkbtn:hover { background: rgba(255,255,255,.12); color: #fff; }
.mainnav a.active { background: rgba(255,255,255,.2); }
.navtoggle { display: none; }

main { width: 100%; max-width: 1180px; margin: 0 auto; padding: 1.4rem 1.2rem 3rem; flex: 1; }
main.wide { max-width: none; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; border-top: 1px solid var(--line); }

/* Karten, Formulare */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.narrowcard { max-width: 620px; margin-left: 0; }
.narrow { max-width: 620px; margin: 2rem auto; }
label { display: block; font-size: .87rem; font-weight: 550; margin-bottom: .75rem; color: #2f3742; }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=search], input[type=number], select, textarea {
  display: block; width: 100%; margin-top: .25rem; padding: .48rem .6rem;
  border: 1px solid #c3cbd6; border-radius: 6px; background: #fff; color: var(--ink);
  font: inherit; font-weight: 400;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
textarea { resize: vertical; }
input[type=file] { margin-top: .3rem; font-weight: 400; }
label.check { display: flex; align-items: flex-start; gap: .45rem; font-weight: 450; }
label.check input { margin-top: .2rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem .2rem; margin: 0 0 1rem; }
fieldset.card { padding-top: .6rem; }
legend { font-weight: 650; padding: 0 .35rem; font-size: .95rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.formactions { display: flex; gap: .6rem; margin-top: .5rem; align-items: center; }
.sticky-bottom { position: sticky; bottom: 0; z-index: 10; background: var(--bg); padding: .8rem 0; border-top: 1px solid var(--line); }
.tablewrap.free { max-height: none; overflow-x: auto; overflow-y: visible; }
form.inline { display: inline; }
input.tiny { display: inline-block; width: 150px; padding: .25rem .4rem; margin: 0; font-size: .82rem; }

.btn {
  display: inline-flex; align-items: center; gap: .3rem; padding: .48rem .95rem; border-radius: 6px;
  border: 1px solid #bec7d2; background: #fff; color: var(--ink); font: inherit; font-size: .92rem; font-weight: 550;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #edf1f6; color: var(--ink); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #013c6b; color: #fff; }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: .25rem .6rem; font-size: .82rem; }
.btn.wide { width: 100%; justify-content: center; padding: .65rem; }
.linkbtn { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; text-underline-offset: 2px; }

.alert { padding: .7rem .95rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert.success { background: var(--ok-soft); border-color: #bcd9c2; }
.alert.error { background: var(--danger-soft); border-color: #e4b9b2; }
.alert.info { background: var(--info-soft); border-color: #c4d2e3; }
.alert.warn { background: var(--warn-soft); border-color: #e8d39b; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .08rem .45rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary); vertical-align: middle; }
.badge.gray { background: #ecebe6; color: #555; }
.badge.red { background: var(--danger-soft); color: var(--danger); }

/* Seitenkopf */
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.pagehead h1 { margin: 0; }
.pagehead .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.count { font-size: .85rem; font-weight: 600; color: var(--muted); background: var(--line-soft); border-radius: 999px; padding: .1rem .55rem; vertical-align: middle; }
.crumbs { margin: 0 0 .5rem; font-size: .9rem; }

.filterbar { display: flex; flex-wrap: wrap; gap: .4rem .9rem; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem .1rem; margin-bottom: 1rem; }
.filterbar label { margin-bottom: .6rem; min-width: 140px; }
.filterbar label.grow { flex: 1 1 220px; }
.filterbar .btn { margin-bottom: .6rem; }

/* Tabellen */
.tablewrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table.list { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
table.list th, table.list td { padding: .45rem .65rem; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
table.list thead th {
  position: sticky; top: 0; z-index: 2; background: #eaeff5; font-weight: 650; font-size: .82rem;
  white-space: nowrap; border-bottom: 1px solid var(--line); color: #2f3742;
}
table.list thead th a { color: inherit; text-decoration: none; }
table.list thead th a:hover { color: var(--accent); }
table.list tbody tr:nth-child(even) td { background: #f9fbfd; }
table.list tbody tr:hover td { background: var(--primary-soft); }
table.list tbody tr[data-href] { cursor: pointer; }
table.list tr.inactive td { color: #7b807c; }
table.list td.clip { max-width: 260px; }
table.members td { white-space: nowrap; }
table.members td.clip { white-space: normal; min-width: 200px; }
.sticky { position: sticky; z-index: 1; background: var(--surface); }
thead .sticky { z-index: 3; }
.sticky.s0 { left: 0; }
table.members .sticky.s0 { min-width: 140px; max-width: 140px; width: 140px; overflow: hidden; text-overflow: ellipsis; }
table.members .sticky.s1 { left: 140px; box-shadow: 2px 0 0 var(--line-soft); }
table.compact th, table.compact td { padding: .3rem .5rem; }
.empty { padding: 2rem; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

table.matrix td.center, table.matrix th.center { text-align: center; min-width: 120px; }
table.matrix tr.section td { background: var(--primary-soft) !important; font-weight: 650; color: var(--primary); font-size: .85rem; }
table.matrix tr.fixed td { color: var(--muted); }
table.matrix input[type=checkbox] { width: 1.1rem; height: 1.1rem; cursor: pointer; }
table.matrix .sticky.s0 { min-width: 260px; }

table.log td.details { font-size: .84rem; min-width: 280px; }
table.log td.details ul { margin: 0; padding-left: 1rem; }
table.log .old { color: var(--danger); text-decoration: line-through; text-decoration-color: rgba(163,58,46,.4); }
table.log .new { color: #22663a; }
table.log tr.warnrow td { background: var(--warn-soft) !important; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 1rem; }

/* Detailansicht */
.detailgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 1rem; align-items: start; }
.detailgrid .card { margin: 0; }
.detailgrid .span2 { grid-column: 1 / -1; }
dl { margin: 0; display: grid; grid-template-columns: minmax(120px, 42%) 1fr; gap: .35rem .8rem; }
dt { color: var(--muted); font-size: .86rem; }
dd { margin: 0; word-break: break-word; }

/* Login */
main.loginmain { display: flex; align-items: center; justify-content: center; }
.login { width: 100%; max-width: 400px; text-align: center; padding-top: 3vh; }
.login.wide { max-width: 520px; }
.login form { text-align: left; margin-top: 1rem; }
.login h1 { font-size: 1.35rem; line-height: 1.3; margin: .8rem 0 .3rem; color: var(--primary); }
.loginlogo { width: 140px; height: auto; max-height: 170px; object-fit: contain; }
.logopreview { background: var(--bg); border: 1px dashed var(--line); border-radius: 6px; padding: .8rem; text-align: center; margin-bottom: .8rem; }
.logopreview img { max-height: 120px; max-width: 100%; }
dl.kv { grid-template-columns: minmax(140px, 45%) 1fr; }

@media (max-width: 820px) {
  .navtoggle { display: inline-block; background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 6px; padding: .4rem .7rem; font: inherit; }
  .mainnav { display: none; width: 100%; flex-direction: column; align-items: stretch; gap: .4rem; padding-bottom: .5rem; }
  .mainnav.open { display: flex; }
  .navgroup { flex-wrap: wrap; }
  .navgroup.admin, .navgroup.user { border-left: 0; padding-left: 0; border-top: 1px solid rgba(255,255,255,.2); padding-top: .4rem; }
  .brand span { font-size: .88rem; }
  .row2 { grid-template-columns: 1fr; }
  main { padding: 1rem .7rem 2rem; }
  .tablewrap { max-height: none; }
  table.members .sticky.s1 { position: static; box-shadow: none; }
}
@media print {
  .topbar, .filterbar, .actions, .foot, .crumbs { display: none !important; }
  .tablewrap { max-height: none; overflow: visible; box-shadow: none; }
  body { background: #fff; }
}

details.dangerzone { margin-top: 1.5rem; border-color: #e4c3bd; }
details.dangerzone summary { cursor: pointer; font-weight: 650; color: var(--danger); }
details.dangerzone[open] summary { margin-bottom: .6rem; }
.filterbar.plain { border: 0; padding: 0; background: none; box-shadow: none; margin: 0; }
.linkbtn.danger { color: var(--danger); }
.forgotlink { margin: .9rem 0 0; }
.fieldhint { margin: -.5rem 0 .8rem; }

/* Spaltenfilter */
table.members thead tr:first-child th { height: 36px; }
table.members thead tr.filters th { top: 36px; padding: .3rem .4rem; background: #f3f6fa; font-weight: 400; }
table.members thead tr.filters input, table.members thead tr.filters select {
  margin: 0; padding: .25rem .35rem; font-size: .8rem; min-width: 70px; border-radius: 4px;
}
table.members thead tr.filters th.on input, table.members thead tr.filters th.on select { border-color: var(--accent); background: #eef5fd; font-weight: 600; }
table.members thead tr.filters th.sticky { z-index: 3; }
.emptyrow { text-align: center !important; color: var(--muted); padding: 2rem !important; }
.activefilters { margin: -.4rem 0 .7rem; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; color: var(--muted); }
.chip { background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: .12rem .6rem; text-decoration: none; font-weight: 600; font-size: .8rem; }
.chip:hover { background: #d3e3f3; color: var(--primary); }
.filterhelp { margin-top: .5rem; }
