/* Lohnanalyse-Dashboard */
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --fg: #1f2733;
  --muted: #5b6470;
  --line: #d9dee6;
  --grid: rgba(31, 39, 51, .12);
  --accent: #2f5496;
  --accent-fg: #ffffff;
  --head: #2f5496;
  --head-fg: #ffffff;
  --total: #203864;
  --flash: #fff4d6;
  --flash-line: #e8c96b;
}
:root[data-theme="dark"] {
  --bg: #12161c;
  --panel: #1b212a;
  --fg: #e7ebf0;
  --muted: #9aa4b1;
  --line: #313a47;
  --grid: rgba(231, 235, 240, .14);
  --accent: #4a7ebb;
  --head: #2b3a5c;
  --total: #33507e;
  --flash: #3a3117;
  --flash-line: #7a6528;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #12161c; --panel: #1b212a; --fg: #e7ebf0; --muted: #9aa4b1;
    --line: #313a47; --grid: rgba(231,235,240,.14); --accent: #4a7ebb;
    --head: #2b3a5c; --total: #33507e; --flash: #3a3117; --flash-line: #7a6528;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  /* Seite selbst scrollt nicht - nur <main>. Verhindert doppelte Scrollbalken. */
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}
a { color: var(--accent); }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap; flex: 0 0 auto;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand span { font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 12px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a {
  padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--fg);
  font-weight: 500; white-space: nowrap;
}
.tabs a:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.tabs a.active { background: var(--accent); color: var(--accent-fg); }
.right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.stand { color: var(--muted); font-size: 12px; }
.ghost {
  background: none; border: 1px solid var(--line); color: var(--fg);
  border-radius: 6px; padding: 4px 9px; cursor: pointer; text-decoration: none;
  font-size: 13px;
}
.ghost:hover { border-color: var(--accent); }

/* ---- Content ---- */
main { padding: 16px 16px 28px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
h1 { font-size: 19px; margin: 4px 0 8px; }
.note {
  color: var(--muted); font-size: 12.5px; max-width: 110ch; margin: 0 0 14px;
}
.flash {
  background: var(--flash); border: 1px solid var(--flash-line);
  padding: 8px 12px; border-radius: 6px; margin-bottom: 14px;
}
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.controls input, .controls select {
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--fg); font-size: 13px;
}
.controls input[type="search"] { min-width: 240px; }
.count { color: var(--muted); font-size: 12px; }
.controls .chk, label.chk {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px;
  color: var(--fg); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 9px; background: var(--panel); cursor: pointer;
}
.controls .chk input { margin: 0; }
.btnreset {
  margin-left: auto; font-size: 12.5px; color: var(--fg); cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; background: var(--panel);
}
.btnreset:hover { border-color: var(--accent); }

/* ---- Multiselect (details.multi) ---- */
.multi { position: relative; }
.multi > summary {
  list-style: none; cursor: pointer; user-select: none;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--fg); font-size: 13px; white-space: nowrap;
}
.multi > summary::-webkit-details-marker { display: none; }
.multi > summary::after { content: " ▾"; color: var(--muted); }
.multi[open] > summary { border-color: var(--accent); }
.multi .msum { color: var(--muted); }
.multi .mpanel {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0;
  min-width: 240px; max-height: 300px; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 12px 34px rgba(0,0,0,.18); padding: 8px;
}
.multi .mpanel label {
  display: flex; align-items: center; gap: 7px; padding: 4px 6px;
  border-radius: 5px; font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.multi .mpanel label:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.multi .msearch {
  width: 100%; margin-bottom: 6px; padding: 6px 8px; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg);
  position: sticky; top: 0;
}
.multi .mbtns { display: flex; gap: 6px; margin-bottom: 6px; }
.multi .mbtns button {
  flex: 1; font-size: 12px; padding: 4px 6px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg);
}
.multi .mbtns button:hover { border-color: var(--accent); }

/* ---- Spaltenverwaltung (#fcols) ---- */
#tbl.draggable-cols thead th[draggable="true"] { cursor: grab; }
#tbl.draggable-cols thead th.dragging { opacity: .45; }
#tbl.draggable-cols thead th.dropbefore { box-shadow: inset 3px 0 0 0 var(--accent); }
#tbl.draggable-cols thead th.dropafter  { box-shadow: inset -3px 0 0 0 var(--accent); }
#fcols .mpanel { min-width: 230px; }
#fcols .mbtns { margin-top: 6px; margin-bottom: 0; }
#fcols .mhead {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 8px 2px 3px; border-top: 1px solid var(--line); padding-top: 6px;
}
#fcols .yearrow { display: flex; flex-wrap: wrap; gap: 1px 6px; }
#fcols .yearrow label { padding: 3px 5px; white-space: nowrap; }

/* ---- Tabellen ---- */
.tablewrap {
  overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
/* Auf reinen Tabellenseiten fuellt die Tabelle exakt den Restplatz:
   eigener vertikaler Scrollcontainer (sticky Kopfzeile), Seite scrollt nicht. */
body.tablepage main { display: flex; flex-direction: column; }
body.tablepage .tablewrap { flex: 1 1 auto; min-height: 0; }
/* zusaetzliche horizontale Scrollleiste - klebt beim Scrollen oben an */
.scrollx-top {
  overflow-x: auto; overflow-y: hidden; height: 14px; margin-bottom: 2px;
  position: sticky; top: 0; z-index: 9; background: var(--bg);
}
.scrollx-top > div { height: 1px; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; }
table.grid th, table.grid td {
  padding: 5px 8px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
  text-align: center; white-space: nowrap;
}
table.grid th {
  position: sticky; top: 0; z-index: 5;
  background: var(--head); color: var(--head-fg); font-weight: 600;
}
table.grid th.l, table.grid td.l { text-align: left; }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.b { font-weight: 700; }
table.grid tbody tr:hover td { background: color-mix(in srgb, var(--accent) 8%, transparent); }
table.grid .totalrow td { background: var(--total); color: #fff; font-weight: 700; }
table.grid .bf { font-style: italic; }
th.sortcol { cursor: pointer; }
th.sortcol[data-dir="asc"]::after { content: " ▲"; font-size: 9px; }
th.sortcol[data-dir="desc"]::after { content: " ▼"; font-size: 9px; }

/* erste zwei Spalten fixieren */
table.grid th:nth-child(1), table.grid td:nth-child(1) { position: sticky; left: 0; z-index: 6; background: var(--panel); }
table.grid th:nth-child(2), table.grid td:nth-child(2) { position: sticky; left: 54px; z-index: 6; background: var(--panel); }
table.grid thead th:nth-child(1), table.grid thead th:nth-child(2) { z-index: 8; background: var(--head); }
table.grid .totalrow td:nth-child(1), table.grid .totalrow td:nth-child(2) { background: var(--total); }

/* KPI-Tabelle (schmal) */
table.grid.kpi { width: auto; min-width: 420px; font-size: 13px; }
table.grid.kpi td, table.grid.kpi th { border-right: 1px solid var(--line); }
table.grid.kpi tr.strong td { font-weight: 700; }

/* ---- Delta-%-Farbbänder (aus make_excel.py BANDS) ---- */
.band-darkgreen   { background: #2E7D32; color: #fff; }
.band-medgreen    { background: #82C983; color: #000; }
.band-lightgreen  { background: #B7E2B4; color: #000; }
.band-vlightgreen { background: #E4F5E1; color: #000; }
.band-yellow      { background: #FFF59D; color: #000; }
.band-lightorange { background: #FFD8A8; color: #000; }
.band-medorange   { background: #FFA45C; color: #000; }
.band-medred      { background: #F0685A; color: #000; }
.band-darkred     { background: #B71C1C; color: #fff; }

/* ---- Charts ---- */
.chartbox {
  margin-top: 18px; padding: 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; height: 460px;
}
.chartbox canvas { width: 100% !important; height: 100% !important; }

/* ---- Login ---- */
.loginwrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.loginbox {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 32px 30px; width: 320px; box-shadow: 0 10px 40px rgba(0,0,0,.12);
}
.loginbox h1 { margin: 0; font-size: 20px; }
.loginbox .sub { margin: 2px 0 18px; color: var(--muted); font-size: 13px; }
.loginbox label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 16px; }
.loginbox input {
  width: 100%; margin-top: 5px; padding: 9px 11px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--fg);
}
.loginbox button {
  width: 100%; padding: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 7px;
}

/* ---- Topbar: Firmen-Umschalter ---- */
.compform { display: inline-flex; margin: 0; }
#companysel {
  padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--fg); font-size: 13px; max-width: 220px;
}
#companysel:hover { border-color: var(--accent); }
.ghost.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }

/* ---- Fehlerseite ---- */
.errbox {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; overflow: auto; font-size: 12px; color: var(--muted);
  white-space: pre-wrap;
}

/* ---- Einstellungen ---- */
table.grid.settings { width: auto; min-width: 640px; font-size: 13px; }
table.grid.settings td, table.grid.settings th { white-space: nowrap; }
.settings .muted, .muted { color: var(--muted); font-size: 11.5px; }
.settings .nowrap { white-space: nowrap; }
form.inline { display: inline; margin: 0; }
button.link {
  background: none; border: 0; color: var(--accent); cursor: pointer;
  font-size: 12.5px; padding: 0 4px; text-decoration: underline;
}
button.link.danger { color: #b71c1c; }
:root[data-theme="dark"] button.link.danger { color: #f0685a; }

.cform {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px 16px; max-width: 780px; margin-top: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px;
}
.cform label { display: block; font-size: 12px; color: var(--muted); }
.cform label.check {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--fg);
}
.cform input[type="text"], .cform input:not([type]),
.cform input[type="number"], .cform input[type="password"] {
  width: 100%; margin-top: 4px; padding: 8px 10px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--fg);
}
.cform input[readonly] { opacity: .6; }
.cform .actions { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; }
.cform .actions button {
  padding: 9px 18px; font-size: 13px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 7px;
}
.cform .actions button.secondary {
  background: var(--panel); color: var(--fg); border: 1px solid var(--line); font-weight: 500;
}
h2 { font-size: 16px; margin: 26px 0 6px; }

/* ---- Vergleich: Einzel-MA-Zeilen ---- */
table.grid tr.emprow td { font-style: italic; }
table.grid tr.emprow td.l { font-style: normal; }

/* ---- 2FA ---- */
.loginbox.wide { width: 460px; max-width: 92vw; }
.loginbox.wide h2 { font-size: 14px; margin: 18px 0 6px; }
.totpsetup { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; margin: 8px 0 4px; }
.qrbox { width: 180px; flex: 0 0 auto; }
.qrbox svg { width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
code.secret {
  display: inline-block; font-size: 13px; letter-spacing: 1px; padding: 4px 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; word-break: break-all;
}
.codeform { margin-top: 12px; }
.codeform label { display: block; font-size: 12px; color: var(--muted); }
.codeform input {
  margin-top: 4px; padding: 8px 10px; font-size: 15px; letter-spacing: 3px; width: 160px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--fg);
}
.codeform button, button.secondary {
  margin-top: 8px; padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 7px;
}
button.secondary { background: var(--panel); color: var(--fg); border: 1px solid var(--line); }
.pkmsg { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.pkmsg.err { color: #b71c1c; }
:root[data-theme="dark"] .pkmsg.err { color: #f0685a; }

/* ---- Dashboard ---- */
.kpirow { display: flex; flex-wrap: wrap; gap: 12px; margin: 6px 0 16px; }
.kpi {
  flex: 1 1 150px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 3px;
}
.kpi .kv { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .kl { font-size: 11.5px; color: var(--muted); }
.dashgrid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px;
}
.dashcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
}
.dashcard h2 { font-size: 13.5px; margin: 0 0 8px; }
.dashcard .cc { height: 240px; position: relative; }
.dashcard .cc canvas { width: 100% !important; height: 100% !important; }

/* ---- Benutzerverwaltung: Zugriffs-Editor ---- */
.accessblock { grid-column: 1 / -1; }
.accessblock h3 { font-size: 13px; margin: 8px 0 6px; }
.accessfs {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px;
}
.accessfs legend { font-size: 12.5px; padding: 0 4px; }
.accessfs .rad {
  display: inline-flex; align-items: center; gap: 5px; margin-right: 14px; font-size: 12.5px;
}
.accessfs .cclist { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 6px; }
.accessfs .cclist label {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--fg);
}
.accessfs .cctext {
  width: 100%; margin-top: 6px; padding: 6px 8px; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg);
}
