:root {
  --accent: #b3122e;
  --accent-dark: #8a0e23;
  --accent-soft: #f6e3e6;
  --ink: #2a2320;
  --muted: #7a716b;
  --bg: #faf7f3;
  --card: #ffffff;
  --line: #e7ded6;
  --ok: #2e7d4f;
  --shadow: 0 6px 22px rgba(60, 40, 30, 0.10);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  min-height: 100vh;
}

/* ---------- Foto-Collage Hintergrund (wild gestreut) ---------- */
#collage {
  position: absolute;
  top: 0; left: 0; width: 100%;
  z-index: -2;
  overflow: hidden;
  opacity: 0.72;
  pointer-events: none;
}
#collage img {
  position: absolute;
  height: auto;
  border: 4px solid #fff;
  border-radius: 5px;
  box-shadow: 0 8px 20px rgba(45,28,16,0.30);
}
/* leichtes Aufhellen für Lesbarkeit über der gesamten Seite */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(rgba(250,247,243,0.12), rgba(250,247,243,0.36));
}

/* ---------- Layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 18px 60px; }

header.site {
  position: relative;
  text-align: center;
  padding: 28px 18px 12px;
}
header.site .heart { color: var(--accent); font-size: 30px; }
header.site h1 {
  margin: 4px 0 2px; font-size: 30px; letter-spacing: 0.3px; line-height: 1.25;
}
header.site p.sub { margin: 0; color: var(--muted); }
header.site .heart-inline { color: var(--accent); white-space: nowrap; }

/* Startseite: schmales, weißes Karten-Fenster (passt sich der Textbreite an) */
header.site.home {
  width: fit-content;
  max-width: 100%;
  margin: 18px auto 0;
  padding: 22px 48px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
header.site.home .adminlink { position: fixed; top: 14px; right: 16px; }

header.site .adminlink {
  position: absolute; top: 16px; right: 18px;
  font-size: 13px; color: var(--muted); text-decoration: none;
  border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px;
  background: rgba(255,255,255,0.7);
}
header.site .adminlink:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Controls ---------- */
.controls {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid;
  grid-template-columns: 2fr 1.6fr 1fr 1.4fr;
  gap: 12px;
  margin: 16px 0;
}
.sort-row { display: flex; gap: 8px; }
.sort-row select { flex: 1; }
.dir-btn {
  flex: 0 0 auto; width: 42px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--accent);
  border-radius: 9px; font-size: 15px; font-weight: 700;
}
.dir-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.dir-btn:disabled { color: var(--muted); cursor: default; opacity: 0.6; }
.field label {
  display: block; font-size: 12px; color: var(--muted);
  margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
}
input, select, button, textarea {
  font: inherit; color: var(--ink);
}
input[type=text], input[type=search], input[type=date], select, textarea {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ---------- Such-Combobox (Zwinger) ---------- */
.combo { position: relative; }
.combo-list {
  display: none;
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  box-shadow: var(--shadow); max-height: 260px; overflow-y: auto;
}
.combo-list.open { display: block; }
.combo-item { padding: 8px 11px; cursor: pointer; font-size: 14px; }
.combo-item:hover { background: var(--accent-soft); }
.combo-item.active { background: #fbf6f1; font-weight: 600; }
.combo-empty { padding: 8px 11px; color: var(--muted); font-size: 13px; }
.combo-item.combo-new { color: var(--accent-dark); font-weight: 600; border-top: 1px solid var(--line); }

/* Zwinger-Verwaltung */
.zw-list { max-height: 50vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; }
.zw-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
}
.zw-row:last-child { border-bottom: none; }
.zw-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.zw-count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.zw-row .row-actions { flex: 0 0 auto; }
.btn.small:disabled { opacity: 0.45; cursor: default; }
.btn.small.danger:disabled:hover { background: #fff; color: var(--accent); }

/* ---------- Leeren-/Zurücksetzen-Button (✕) ---------- */
.clearable { position: relative; }
.clearable input, .clearable select { padding-right: 34px; }
.clear-x {
  position: absolute; top: 50%; right: 7px; transform: translateY(-50%);
  display: none; cursor: pointer; border: none; background: transparent;
  color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px; border-radius: 6px;
}
.clear-x.for-select { right: 30px; } /* Platz für den Dropdown-Pfeil */
.clear-x:hover { color: var(--accent); }
.clear-x.show { display: block; }

.sort-hint { color: var(--muted); font-size: 13px; margin: 0 2px 6px; }

/* ---------- Sortierbare Spaltenköpfe ---------- */
thead th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
thead th.sortable:hover { color: var(--accent); }
thead th.sortable.sorted { color: var(--accent); }
thead th .arrow { font-size: 11px; color: #cbb8ad; margin-left: 2px; }
thead th.sortable:hover .arrow { color: var(--muted); }
thead th.sorted .arrow { color: var(--accent); }

.count-bar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px; margin: 4px 2px 10px;
}
.count { color: var(--muted); font-size: 14px; }
.legend {
  color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; box-shadow: var(--shadow);
}
.legend .lg { font-weight: 700; padding: 1px 9px; border-radius: 999px; line-height: 1.5; }
.legend .lg.bf-0 { color: #1f7a45; background: #e3f3ea; }
.legend .lg.bf-1 { color: #8a6d00; background: #faf1cf; }
.legend .lg.bf-2 { color: #b85c00; background: #fde6cf; }
.legend .lg.bf-3 { color: #b23025; background: #f8ded9; }

/* ---------- Tabelle ---------- */
.table-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--muted); background: #fbf6f1; padding: 11px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: #fdf8f4; }
tbody tr:last-child td { border-bottom: none; }
.name-cell { font-weight: 600; }
.zb { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sex-badge {
  display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-dark); white-space: nowrap;
}
.sex-w { background: #efe7f6; color: #6b3fa0; }

.exams { display: flex; flex-direction: column; gap: 4px; }
.exam-chip {
  font-size: 13px; background: #f5f0ea; border: 1px solid var(--line);
  border-radius: 8px; padding: 3px 8px; display: inline-flex; gap: 8px; align-items: baseline;
  white-space: nowrap;
}
.exam-chip .dt { font-variant-numeric: tabular-nums; }
.exam-chip .age { color: var(--muted); }
.exam-chip .bf { font-weight: 700; color: var(--accent-dark); }
.exam-chip .bf.bf-0 { color: #1f7a45; }
.exam-chip .bf.bf-1 { color: #8a6d00; }
.exam-chip .bf.bf-2 { color: #b85c00; }
.exam-chip .bf.bf-3 { color: #b23025; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

/* Startseiten-Tabelle: feste Spaltenbreiten, Datenspalten einzeilig */
.results-table { table-layout: fixed; }
.results-table tbody td {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.results-table tbody td.exam-cell { white-space: normal; overflow: visible; }
.results-table thead th { white-space: normal; }
.results-table tbody tr { cursor: pointer; }
.th-sub { font-weight: normal; text-transform: none; letter-spacing: 0; color: var(--muted); font-size: 11px; }

/* Detailansicht */
.detail-grid { display: grid; grid-template-columns: max-content 1fr; gap: 7px 18px; margin: 0; }
.detail-grid dt { color: var(--muted); font-size: 13px; align-self: center; }
.detail-grid dd { margin: 0; font-weight: 600; }
.detail-sub { margin: 18px 0 8px; font-size: 14px; color: var(--ink); }

/* Detail-Fenster größer */
#detailModal .modal { padding: 28px 30px; }
#detailModal h2 { font-size: 27px; margin-bottom: 16px; }
#detailModal .detail-grid { font-size: 17px; gap: 11px 24px; }
#detailModal .detail-grid dt { font-size: 14px; }
#detailModal .detail-sub { font-size: 19px; margin: 22px 0 10px; }
#detailModal .exams { gap: 8px; }
#detailModal .exam-chip { font-size: 17px; padding: 7px 13px; border-radius: 10px; }
#detailModal .btn { font-size: 16px; padding: 11px 20px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 14px; border-radius: 9px; font-weight: 600;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); color: #fff; }
.btn.danger { color: var(--accent); }
.btn.danger:hover { background: var(--accent); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }

/* Gestyltes Datei-Auswahl-Feld */
.file-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.file-input { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.file-btn {
  display: inline-flex;
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-dark);
}
.file-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.file-input:focus + .file-btn { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.file-name { color: var(--muted); font-size: 14px; }

/* ---------- Admin ---------- */
/* Verwaltungs-Tabelle: feste Spaltenbreiten, eine Zeile pro Eintrag */
.admin-table { table-layout: fixed; }
.admin-table td {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.admin-table thead th { white-space: normal; }
.admin-table td.row-actions { overflow: visible; }
.admin-table .row-actions { flex-wrap: nowrap; justify-content: flex-end; }
.admin-table .btn.small { padding: 5px 9px; white-space: nowrap; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 16px 0; }
.toolbar .spacer { flex: 1; }
.row-actions { display: flex; gap: 6px; }

.modal-back {
  position: fixed; inset: 0; background: rgba(40,30,25,0.45);
  display: none; align-items: flex-start; justify-content: center; padding: 30px 14px; z-index: 50;
  overflow: auto;
}
.modal-back.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 680px; padding: 22px;
}
.modal h2 { margin: 0 0 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.exam-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; margin-bottom: 8px; }
.hint { font-size: 12px; color: var(--muted); }
.msg { padding: 10px 12px; border-radius: 9px; margin: 10px 0; font-size: 14px; }
.msg.err { background: var(--accent-soft); color: var(--accent-dark); }
.msg.ok { background: #e4f3ea; color: var(--ok); }

/* Eigene Dialoge (Bestätigen/Hinweis/Eingabe) */
.dialog-back { align-items: center; z-index: 70; }
.modal.dialog { max-width: 440px; }
.modal.dialog h2 { margin-bottom: 10px; }
.dialog-msg { color: var(--ink); line-height: 1.5; }
.dlg-input { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; margin-top: 12px; }
.dlg-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.dialog-actions { margin-top: 18px; }

.login-box {
  max-width: 380px; margin: 60px auto; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px;
}
.login-box .field { margin-bottom: 14px; }

@media (max-width: 760px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr { border-bottom: 2px solid var(--line); padding: 8px 0; }
  tbody td { border: none; padding: 4px 12px; }
  tbody td::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; }
}
