:root {
  --flaeche: #f4f5f7;
  --karte: #ffffff;
  --text: #1c2430;
  --gedaempft: #5c6878;
  --linie: #d9dee6;
  --akzent: #1f5fbf;
  --akzent-text: #ffffff;
  --akzent-hell: #e3edfb;
  --zeile-alt: #f8f9fb;
  --gefahr: #b3261e;
  --gut: #1e7a46;
  --warnung: #9a6400;
  --schatten: 0 8px 30px rgba(15, 25, 45, .18);
  --radius: 8px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --flaeche: #14181f;
    --karte: #1c222c;
    --text: #e6eaf0;
    --gedaempft: #9aa6b6;
    --linie: #323b49;
    --akzent: #6ea8ff;
    --akzent-text: #0c1626;
    --akzent-hell: #24364f;
    --zeile-alt: #202733;
    --gefahr: #ff8a80;
    --gut: #6fd39a;
    --warnung: #f0b450;
    --schatten: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--flaeche);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

/* ---------- Grundgerüst ---------- */
.kopf {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: var(--karte);
  border-bottom: 1px solid var(--linie);
}
.marke { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; white-space: nowrap; }
.marke img { border-radius: 6px; }
.mandant-wahl { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; color: var(--gedaempft); }
.mandant-wahl select { flex: 1; max-width: 420px; min-width: 0; }

.rahmen { flex: 1; display: flex; min-height: 0; }
.navigation {
  width: 190px; flex: none;
  padding: 12px 8px;
  background: var(--karte);
  border-right: 1px solid var(--linie);
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}
.navigation button {
  all: unset; box-sizing: border-box; width: 100%;
  padding: 8px 12px; border-radius: 6px; cursor: pointer;
  color: var(--text);
}
.navigation button:hover { background: var(--zeile-alt); }
.navigation button:focus-visible { outline: 2px solid var(--akzent); outline-offset: -2px; }
.navigation button[aria-current="page"] { background: var(--akzent-hell); color: var(--akzent); font-weight: 600; }

.inhalt { flex: 1; min-width: 0; padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; overflow: hidden; outline: none; }
.inhalt h1 { margin: 0; font-size: 20px; }
.fuss { padding: 6px 16px; font-size: 12px; color: var(--gedaempft); background: var(--karte); border-top: 1px solid var(--linie); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Bedienelemente ---------- */
.knopf {
  font: inherit; color: var(--text);
  background: var(--karte);
  border: 1px solid var(--linie);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.knopf:hover:not(:disabled) { border-color: var(--akzent); }
.knopf:focus-visible { outline: 2px solid var(--akzent); outline-offset: 1px; }
.knopf:disabled { opacity: .5; cursor: default; }
.knopf.haupt { background: var(--akzent); border-color: var(--akzent); color: var(--akzent-text); font-weight: 600; }
.knopf.gefahr { color: var(--gefahr); }
.knopf.klein { padding: 2px 8px; font-size: 13px; }

input, select {
  font: inherit; color: var(--text);
  background: var(--karte);
  border: 1px solid var(--linie);
  border-radius: 6px;
  padding: 6px 8px;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--akzent); outline-offset: 0; border-color: var(--akzent); }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--akzent); }
input[readonly] { color: var(--gedaempft); background: var(--zeile-alt); }

.werkzeuge { display: flex; flex-wrap: wrap; gap: 6px; }
.filterzeile { display: flex; align-items: center; gap: 8px; }
.filterzeile input { flex: 1; max-width: 420px; }
.filterzeile .anzahl { margin-left: auto; color: var(--gedaempft); font-size: 13px; white-space: nowrap; }
.hinweis { color: var(--gedaempft); padding: 24px 4px; }

/* ---------- Tabellen ---------- */
.tabellenrahmen {
  flex: 1; min-height: 0; overflow: auto;
  background: var(--karte);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
}
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 10px; text-align: left; white-space: nowrap; }
td.breit { max-width: 340px; overflow: hidden; text-overflow: ellipsis; color: var(--gedaempft); }
th.zahl, td.zahl { text-align: right; font-variant-numeric: tabular-nums; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--karte);
  border-bottom: 1px solid var(--linie);
  font-weight: 600; color: var(--gedaempft);
  user-select: none;
}
thead th.sortierbar { cursor: pointer; }
thead th.sortierbar:hover { color: var(--text); }
thead th .pfeil { display: inline-block; width: 1em; color: var(--akzent); }
tbody tr { border-bottom: 1px solid var(--linie); }
tbody tr:nth-child(even) { background: var(--zeile-alt); }
tbody tr.waehlbar { cursor: default; }
tbody tr.waehlbar:hover { background: var(--akzent-hell); }
tbody tr.gewaehlt, tbody tr.gewaehlt:hover { background: var(--akzent-hell); box-shadow: inset 3px 0 0 var(--akzent); }
td.kasten, th.kasten { width: 34px; padding-right: 0; }

.marke-status { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid currentColor; }
.marke-status.entwurf { color: var(--gedaempft); }
.marke-status.festgeschrieben { color: var(--warnung); }
.marke-status.exportiert { color: var(--gut); }

/* ---------- Formular (Einstellungen) ---------- */
.formular { display: grid; grid-template-columns: max-content minmax(180px, 340px); gap: 10px 14px; align-items: center; }
.formular label { color: var(--gedaempft); }
.karte { background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius); padding: 18px; max-width: 640px; }

/* ---------- Dialoge ---------- */
dialog {
  border: 1px solid var(--linie); border-radius: 12px;
  background: var(--karte); color: var(--text);
  padding: 0; box-shadow: var(--schatten);
  max-width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(10, 16, 28, .45); }
dialog form { display: contents; }
.dialog-kopf { padding: 14px 18px; font-size: 16px; font-weight: 600; border-bottom: 1px solid var(--linie); }
.dialog-inhalt { padding: 16px 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.dialog-fuss { padding: 12px 18px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--linie); }
.dialog-inhalt .tabellenrahmen { max-height: 56vh; flex: none; }
.dialog-inhalt pre { margin: 0; white-space: pre-wrap; font: inherit; }
.fehlertext { color: var(--gefahr); min-height: 1.4em; }
.summenzeile { display: flex; flex-wrap: wrap; gap: 6px 22px; font-variant-numeric: tabular-nums; }
.summenzeile b.abweichung { color: var(--gefahr); }
.vorwahl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
td input[type="time"] { padding: 3px 6px; }
td select { padding: 3px 6px; max-width: 220px; }
tr.frei td { color: var(--gedaempft); }

/* ---------- Anmeldung ---------- */
.benutzer { color: var(--gedaempft); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.anmeldung { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--flaeche); }
.anmeldekarte { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--schatten); }
.anmeldekarte .marke { margin-bottom: 10px; }
.anmeldekarte .marke span { display: inline; }
.anmeldekarte label { color: var(--gedaempft); margin-top: 4px; }
.anmeldekarte .knopf { margin-top: 6px; padding: 9px 12px; }

/* ---------- Meldungen ---------- */
.toasts { position: fixed; right: 16px; bottom: 40px; display: flex; flex-direction: column; gap: 8px; z-index: 50; pointer-events: none; }
.toast {
  pointer-events: auto;
  max-width: 440px; padding: 10px 14px;
  background: var(--karte); color: var(--text);
  border: 1px solid var(--linie); border-left: 4px solid var(--akzent);
  border-radius: var(--radius); box-shadow: var(--schatten);
  white-space: pre-wrap;
}
.toast.fehler { border-left-color: var(--gefahr); }
.toast.gut { border-left-color: var(--gut); }

.beschaeftigt {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(10, 16, 28, .4); color: #fff; font-weight: 600;
}
.beschaeftigt[hidden] { display: none; }
.kreisel { width: 42px; height: 42px; border: 4px solid rgba(255, 255, 255, .35); border-top-color: #fff; border-radius: 50%; animation: drehen .8s linear infinite; }
@keyframes drehen { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .kreisel { animation-duration: 2.4s; } }

/* ---------- Schmale Fenster ---------- */
@media (max-width: 760px) {
  .rahmen { flex-direction: column; }
  .navigation { width: auto; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--linie); padding: 6px 8px; overflow-x: auto; }
  .navigation button { width: auto; white-space: nowrap; }
  .kopf .marke span, .benutzer { display: none; }
  .inhalt { padding: 12px; }
  .formular { grid-template-columns: 1fr; }
}
