:root {
  --bg: #f2f5f6;
  --card: #ffffff;
  --text: #1a2326;
  --muted: #64737a;
  --line: #dde4e7;
  --accent: #0f6e8c;
  --accent-soft: #e0f0f5;
  --fill: #0f6e8c;
  --red: #c0392b;
  --red-soft: #fbe7e4;
  --amber: #a86400;
  --amber-soft: #fdf0d9;
  --green: #2e7d32;
  --green-soft: #e5f3e6;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171a;
    --card: #1b2226;
    --text: #e6edf0;
    --muted: #94a3aa;
    --line: #2c363b;
    --accent: #4cb8d6;
    --accent-soft: #173640;
    --red: #ff7a6b;
    --red-soft: #3d201d;
    --amber: #f0b45a;
    --amber-soft: #3a2c16;
    --green: #7bcf7f;
    --green-soft: #1d3320;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.err { color: var(--red); min-height: 1.2em; margin: 0; }


/* Kopfzeile */
header.top {
  position: sticky; top: 0; z-index: 20; background: var(--fill); color: #fff;
  padding: 8px 14px; display: flex; align-items: center; gap: 14px;
}
header.top h1 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
header.top h1 img { border-radius: 7px; }
.hauptnav { display: flex; gap: 4px; flex: 1; }
.hauptnav a {
  color: #fff; text-decoration: none; padding: 7px 12px; border-radius: 8px; opacity: .85; white-space: nowrap;
}
.hauptnav a:hover { background: rgba(255,255,255,.12); opacity: 1; }
.hauptnav a.active { background: rgba(255,255,255,.2); opacity: 1; font-weight: 600; }
.live { font-size: 12px; opacity: .8; white-space: nowrap; }
.live.aus { color: #ffc94d; opacity: 1; }
.icon-btn {
  border: 0; background: transparent; color: #fff; font-size: 22px; line-height: 1;
  padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.15); }
.menu-wrap { position: relative; margin-left: auto; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.18);
  min-width: 230px; padding: 6px; display: flex; flex-direction: column;
}
.menu > div { display: flex; flex-direction: column; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.menu a, .menu button {
  text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px;
  text-decoration: none; color: inherit; cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--accent-soft); }
.menu-user { padding: 8px 12px; font-size: 13px; color: var(--muted); }

main { max-width: 1600px; margin: 0 auto; padding: 12px 16px 60px; }

/* Login */
.login-box {
  width: 100%; max-width: 360px; margin: 8vh auto 0; background: var(--card); border-radius: 16px;
  padding: 28px 22px; box-shadow: var(--shadow); text-align: center;
  display: flex; flex-direction: column; gap: 10px; border: 1px solid var(--line);
}
.login-box h2 { margin: 4px 0 0; font-size: 22px; }
.login-box p { margin: 0 0 4px; }
.login-box img { margin: 0 auto; border-radius: 14px; }

/* Eingaben & Buttons */
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 17px; height: 17px; padding: 0; accent-color: var(--accent); flex: none; }
textarea { min-height: 70px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 9px;
  cursor: pointer; text-decoration: none; color: var(--text); font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b1a1f; } }
.btn.danger { color: var(--red); border-color: var(--red-soft); }
.btn.gruen { color: var(--green); border-color: var(--green-soft); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.box {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.box h3 { margin: 0 0 10px; font-size: 16px; }
.box h3 .muted { font-weight: 400; font-size: 13px; }
.leer { text-align: center; color: var(--muted); padding: 30px 10px; }
.tag {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}
.tag.grau { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.tag.gruen { background: var(--green-soft); color: var(--green); }
.tag.rot { background: var(--red-soft); color: var(--red); }
.tag.gelb { background: var(--amber-soft); color: var(--amber); }

/* Ansichten-Chips */
.ansichten { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.ansichten a {
  display: inline-flex; gap: 6px; align-items: center; padding: 6px 12px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); text-decoration: none; color: var(--text); font-size: 14px;
}
.ansichten a:hover { border-color: var(--accent); }
.ansichten a.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.ansichten a .n { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.toolbar { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 220px; max-width: 420px; }
.toolbar select, .toolbar input[type=date] { width: auto; }
.toolbar .rechts { margin-left: auto; display: flex; gap: 8px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.seg button.active { background: var(--card); box-shadow: var(--shadow); font-weight: 600; color: var(--accent); }
label.check { display: inline-flex; flex-direction: row; align-items: center; gap: 7px; font-size: 14px; color: var(--text); cursor: pointer; }

/* Tabelle */
.tabelle-wrap {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: auto; max-height: calc(100vh - 230px);
}
table.liste { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.liste th {
  position: sticky; top: 0; z-index: 2; background: var(--card); text-align: left; font-size: 12px;
  color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line);
  cursor: pointer; user-select: none; white-space: nowrap;
}
table.liste th:hover { color: var(--accent); }
table.liste th.sort { color: var(--accent); }
table.liste td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.liste td.lang { white-space: normal; min-width: 200px; font-size: 12.5px; color: var(--muted); }
table.liste tbody tr { cursor: pointer; }
table.liste tbody tr:hover td { background: var(--accent-soft); }
table.liste tr.frisch td { animation: frisch 3s ease-out; }
@keyframes frisch { from { background: var(--amber-soft); } to { background: transparent; } }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mehr { text-align: center; padding: 10px; color: var(--muted); font-size: 13px; }
.stift { font-size: 11px; color: var(--amber); white-space: nowrap; }

/* Status-Farben in der Tabelle */
.st { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--bg); border: 1px solid var(--line); }
.st.offen { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.st.erfolg { background: var(--green-soft); color: var(--green); border-color: transparent; }
.st.ende { background: var(--red-soft); color: var(--red); border-color: transparent; }
.st.fertig { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* Kacheln */
.kacheln { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.kachel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kachel .l { font-size: 12px; color: var(--muted); }
.kachel .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kachel .u { font-size: 12px; color: var(--muted); }

/* KPI-Tabelle */
table.kpi { width: 100%; border-collapse: collapse; font-size: 13px; }
table.kpi th, table.kpi td { padding: 6px 7px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
table.kpi th:first-child, table.kpi td:first-child { text-align: left; white-space: nowrap; }
table.kpi thead th { font-size: 11.5px; color: var(--muted); font-weight: 600; vertical-align: bottom; max-width: 90px; white-space: normal; line-height: 1.2; }
table.kpi tbody td.z { cursor: pointer; }
table.kpi tbody td.z:hover { background: var(--accent-soft); color: var(--accent); }
table.kpi td.null { color: var(--line); }
table.kpi tfoot td { font-weight: 700; border-bottom: 0; }
table.kpi tfoot tr.anteil td { font-weight: 400; color: var(--muted); font-size: 12px; }
table.kpi .q { font-weight: 700; }
.scroll-x { overflow-x: auto; }
.raster { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 12px; }
.raster .box { margin: 0; }

/* Balken (einfarbig, eine Reihe) */
.hbar { display: grid; grid-template-columns: 150px 1fr 70px; gap: 4px 10px; align-items: center; font-size: 13px; }
.hbar .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .b { height: 12px; position: relative; }
.hbar .b i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .w { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.hbar .zeile { display: contents; }
.hbar .zeile:hover .n, .hbar .zeile:hover .w { color: var(--accent); }
.vbar { display: flex; align-items: flex-end; gap: 2px; height: 160px; padding-top: 18px; border-bottom: 1px solid var(--line); }
.vbar .s { flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; }
.vbar .s i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 1px; }
.vbar .s:hover i { filter: brightness(1.15); }
.vachse { display: flex; gap: 2px; font-size: 10.5px; color: var(--muted); margin-top: 4px; }
.vachse span { flex: 1; min-width: 0; white-space: nowrap; overflow: visible; }
.tooltip {
  position: fixed; z-index: 200; pointer-events: none; background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12.5px;
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
}

/* Dialog */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 20px));
  background: var(--card); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.3);
  max-height: calc(100dvh - 20px);
}
dialog.breit { width: min(1040px, calc(100vw - 20px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
#dlgForm { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
#dlgForm h3 { margin: 0; font-size: 18px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
label > input, label > select, label > textarea { color: var(--text); font-size: 14.5px; }
.gruppen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 18px; }
.gruppe { display: flex; flex-direction: column; gap: 9px; }
.gruppe h4 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.gruppe.breit { grid-column: 1 / -1; }
.feld-geaendert > input, .feld-geaendert > select, .feld-geaendert > textarea { border-color: var(--amber); background: var(--amber-soft); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.dlg-kopf { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; align-items: center; }
.dlg-actions .links { margin-right: auto; display: flex; gap: 8px; }
.hinweis { background: var(--amber-soft); color: var(--amber); padding: 9px 12px; border-radius: 10px; font-size: 13px; }
.info { background: var(--accent-soft); padding: 9px 12px; border-radius: 10px; font-size: 13px; }
.ok { background: var(--green-soft); color: var(--green); padding: 9px 12px; border-radius: 10px; font-size: 13px; }
table.konflikt { width: 100%; border-collapse: collapse; font-size: 13px; }
table.konflikt th, table.konflikt td { text-align: left; padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.konflikt th { font-size: 12px; color: var(--muted); }
.verlauf-liste { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.verlauf-liste .v { display: grid; grid-template-columns: 130px 150px 1fr; gap: 10px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.verlauf-liste .v .alt { color: var(--muted); text-decoration: line-through; }
.verlauf-liste .v a { color: var(--accent); cursor: pointer; }

table.tab { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tab th, table.tab td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.tab th { font-size: 12px; color: var(--muted); font-weight: 600; }
pre.log, pre.bericht {
  margin: 0; background: #0d1317; color: #cfe3ea; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 10px 12px; border-radius: 10px; max-height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 100;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.3);
  max-width: calc(100vw - 30px);
}
.toast.fehler { background: var(--red); color: #fff; }
.fuss { text-align: center; color: var(--muted); font-size: 12px; margin-top: 30px; }

@media (max-width: 900px) {
  .gruppen { grid-template-columns: 1fr 1fr; }
  .hauptnav a { padding: 6px 8px; font-size: 14px; }
  header.top h1 span { display: none; }
}
@media (max-width: 600px) {
  .gruppen { grid-template-columns: 1fr; }
  .raster { grid-template-columns: 1fr; }
  .hbar { grid-template-columns: 100px 1fr 60px; }
  .live { display: none; }
}
@media print {
  header.top, .toolbar, .ansichten, .fuss, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  main { padding: 0; max-width: none; }
  .tabelle-wrap { max-height: none; overflow: visible; }
  .box, .kachel { box-shadow: none; break-inside: avoid; }
}
