/* =========================================================================
 *  Anrechnung – Personalstunden-Simulation
 *  Modernes Teal-Corporate-Design, Hell/Dunkel über [data-theme]
 * ====================================================================== */

:root {
  --bg:          #eef2f2;
  --bg-grad:     radial-gradient(1200px 600px at 80% -10%, #d7ecea 0%, transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, #dde9f5 0%, transparent 55%);
  --surface:     #ffffff;
  --surface-2:   #f6f9f9;
  --border:      #e1e8e8;
  --border-2:    #cfdadb;
  --text:        #15201f;
  --muted:       #5d6f6e;
  --primary:     #0f766e;
  --primary-600: #0b5d56;
  --primary-700: #094c46;
  --accent:      #14b8a6;
  --ring:        rgba(15, 118, 110, 0.28);
  --shadow:      0 1px 2px rgba(16, 38, 36, .06), 0 8px 24px rgba(16, 38, 36, .07);
  --shadow-sm:   0 1px 2px rgba(16, 38, 36, .07);

  --rot:    #ef4444;
  --orange: #f97316;
  --gelb:   #eab308;
  --lime:   #84cc16;
  --gruen:  #22c55e;

  --radius: 16px;
  --radius-sm: 10px;
}

:root[data-theme="dark"] {
  --bg:          #0c1413;
  --bg-grad:     radial-gradient(1200px 600px at 80% -10%, #0f2724 0%, transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, #0d1f2b 0%, transparent 55%);
  --surface:     #14201f;
  --surface-2:   #182625;
  --border:      #243534;
  --border-2:    #2f4341;
  --text:        #e7efee;
  --muted:       #9bafad;
  --primary:     #2dd4bf;
  --primary-600: #5eead4;
  --primary-700: #99f6e4;
  --accent:      #2dd4bf;
  --ring:        rgba(45, 212, 191, 0.30);
  --shadow:      0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  --shadow-sm:   0 1px 2px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

/* hidden muss display-Regeln (z. B. .empty { display:grid }) schlagen */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

/* ---- Kopfzeile --------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 36px);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(140deg, var(--primary), var(--accent));
  color: #fff; font-weight: 800; font-size: 18px;
  box-shadow: 0 4px 12px var(--ring);
}
.brand-text { min-width: 0; }
.brand-title { font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.toolbar { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

.btn-primary {
  background: linear-gradient(140deg, var(--primary), var(--primary-600));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px var(--ring);
}
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }

.btn-icon { padding: 9px 11px; font-size: 16px; line-height: 1; }

/* ---- Layout ------------------------------------------------------------ */
.wrap { max-width: 1500px; margin: 0 auto; padding: clamp(16px, 3vw, 30px); }

/* Leerzustand */
.empty {
  display: grid; place-items: center; text-align: center;
  min-height: 60vh; gap: 14px; padding: 30px;
}
.empty-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 40px 36px; max-width: 540px;
}
.empty-icon { font-size: 44px; }
.empty h2 { margin: 8px 0 4px; font-size: 22px; }
.empty p { margin: 0 0 18px; color: var(--muted); }
.empty .hint { font-size: 12.5px; color: var(--muted); margin-top: 16px; }
.empty code {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 6px; font-size: 12px;
}

/* KPI-Leiste */
.kpis {
  display: grid; gap: 14px; margin-bottom: 18px;
  grid-template-columns: repeat(4, 1fr);
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 16px 18px;
}
.kpi-wert { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.kpi-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* Panel-Raster */
.panels {
  display: grid; gap: 18px; margin-bottom: 18px;
  grid-template-columns: 1fr 1fr;
}
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  min-width: 0;
}
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; min-height: 34px; }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-head .sub { font-size: 12px; color: var(--muted); }

/* ---- Übersichtstabelle ------------------------------------------------- */
#uebersicht { overflow-x: auto; }
.tbl { width: 100%; min-width: 440px; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-weight: 600; color: var(--muted);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  height: 32px; vertical-align: bottom;
  padding: 0 10px 8px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
/* Spaltenausrichtung – Kopf und Daten identisch ausgerichtet */
.tbl th:nth-child(2), .tbl th:nth-child(3), .tbl th:nth-child(4) { text-align: right; }
.tbl td:nth-child(2), .tbl td:nth-child(3), .tbl td:nth-child(4) { text-align: right; }
.tbl td { padding: 6px 10px; height: 46px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl td.col-gruppe { font-weight: 600; }
.gruppe-zelle { display: flex; align-items: center; gap: 9px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num { white-space: nowrap; }

.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.dot.sm { width: 9px; height: 9px; }

.soll {
  width: 78px; font: inherit; font-size: 13px; text-align: right;
  padding: 5px 9px; border-radius: 8px;
  border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.soll:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }

.js-diff.pos { color: var(--gruen); }
.js-diff.neg { color: var(--rot); }

.erf { display: flex; align-items: center; gap: 10px; }
.bar {
  position: relative;
  flex: 1; height: 8px; min-width: 60px;
  background: var(--surface-2); border-radius: 99px; overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--border);
}
.bar-fill { display: block; height: 100%; width: 0; border-radius: 99px; transition: width .35s ease, background .25s ease; }
/* §16-Erfüllungsziel als senkrechte Markierung im Balken */
.bar-ziel {
  position: absolute; top: -1px; bottom: -1px; width: 2px;
  background: var(--text); opacity: .5; border-radius: 1px;
  transform: translateX(-1px); pointer-events: none;
}

/* Erfüllungsziel-Selektor im Panel-Kopf */
.ziel-ctrl { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.ziel-label { font-size: 11.5px; color: var(--muted); }
.ziel-sel {
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 4px 8px; border-radius: 8px;
  border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text);
  cursor: pointer;
}
.ziel-sel:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.bar-fill.is-rot    { background: var(--rot); }
.bar-fill.is-orange { background: var(--orange); }
.bar-fill.is-gelb   { background: var(--gelb); }
.bar-fill.is-lime   { background: var(--lime); }
.bar-fill.is-gruen  { background: var(--gruen); }
.bar-fill.is-none   { background: var(--border-2); }
.erf-pct { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; }

/* ---- Abgaben ----------------------------------------------------------- */
.abg-liste { display: flex; flex-direction: column; }
.abg-row {
  display: grid; grid-template-columns: 130px 1fr 64px; align-items: center; gap: 12px;
  height: 46px; border-bottom: 1px solid var(--border);
}
.abg-liste .abg-row:last-child { border-bottom: none; }
.abg-head { height: 32px; padding-bottom: 8px; align-items: end; }
.abg-head span { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.abg-head span:last-child { text-align: right; }
.abg-name { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; min-width: 0; }
.abg-name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack {
  display: flex; height: 12px; border-radius: 99px; overflow: hidden;
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border);
}
.stack-seg { height: 100%; min-width: 2px; }
.stack-seg.leer { flex: 1; background: var(--surface-2); }
.abg-h { font-size: 12.5px; color: var(--muted); }

/* ---- Personen-Karten --------------------------------------------------- */
/* Steuerleiste */
.karten-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin: 24px 2px 8px;
}
.karten-titel { display: flex; align-items: baseline; gap: 10px; }
.karten-titel > span:first-child { font-size: 17px; font-weight: 700; }
.karten-sub { font-size: 12.5px; color: var(--muted); }
.karten-tools { display: flex; align-items: center; gap: 8px; }
.suche {
  font: inherit; font-size: 13.5px; width: 220px; max-width: 48vw;
  padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.suche::placeholder { color: var(--muted); }
.suche:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.btn-sm { padding: 8px 13px; font-size: 13px; }

/* Schalter für die Sammel-Verteilung */
.verteil-ctrl { display: flex; align-items: center; gap: 7px; }
.verteil-label { font-size: 11.5px; color: var(--muted); }
.verteil-sel {
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 7px 9px; border-radius: 9px;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text); cursor: pointer;
}
.verteil-sel:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }

/* Hinweis zu den §8-Vertretungsregeln */
.karten-hinweis {
  display: flex; align-items: flex-start; gap: 8px;
  margin: 0 2px 4px; padding: 9px 12px;
  font-size: 12.5px; color: var(--muted);
  background: color-mix(in srgb, var(--primary) 7%, var(--surface));
  border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: 10px;
}
.hinweis-ic {
  flex: none; width: 16px; height: 16px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  background: var(--primary); color: #fff;
}

/* Aufklappbare Gruppe */
details.gruppe {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-sm);
  margin-top: 12px; overflow: hidden;
}
details.gruppe[open] { box-shadow: var(--shadow); }

summary.gruppe-titel {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; cursor: pointer; user-select: none;
  font-size: 15px; list-style: none;
}
summary.gruppe-titel::-webkit-details-marker { display: none; }
summary.gruppe-titel:hover { background: var(--surface-2); }
summary.gruppe-titel:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--ring); }

.chevron { display: inline-flex; color: var(--muted); transition: transform .2s ease; flex: none; }
details.gruppe[open] .chevron { transform: rotate(90deg); }

.gruppe-name { font-weight: 700; }
.gruppe-spacer { flex: 1; }
.gruppe-sum { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.gruppe-anzahl {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 99px; padding: 1px 9px; min-width: 26px; text-align: center;
}
.js-umverteilt {
  font-size: 11.5px; font-weight: 600; color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border-radius: 99px; padding: 2px 9px; white-space: nowrap;
}
.js-umverteilt:empty { display: none; }

/* Sammel-Regler: ganze Gruppe verschieben */
.gruppe-shift {
  margin: 4px 16px 0;
  padding: 11px 14px 12px;
  background: color-mix(in srgb, var(--primary) 6%, var(--surface-2));
  border: 1px solid var(--border);
  border-radius: 12px;
}
.gs-titel {
  display: flex; align-items: center; gap: 7px; margin-bottom: 8px;
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
}
.gs-ic { display: inline-flex; color: var(--primary); }
.gs-row { display: grid; grid-template-columns: 1fr 150px 64px; align-items: center; gap: 10px; padding: 3px 0; }
.gs-label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text); font-weight: 600; min-width: 0; }
.gs-label span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-wert { font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: right; color: var(--muted); white-space: nowrap; }
.gs-wert.aktiv { color: var(--primary); font-weight: 700; }

.gs-reg { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 99px;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--border-2); cursor: pointer; }
.gs-reg::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: linear-gradient(140deg, var(--primary), var(--accent)); border: 2px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: pointer; transition: transform .1s ease; }
.gs-reg::-webkit-slider-thumb:hover { transform: scale(1.12); }
.gs-reg::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--surface); cursor: pointer; }
.gs-reg:focus-visible { outline: none; box-shadow: inset 0 0 0 1px var(--border-2), 0 0 0 3px var(--ring); }
.gs-reg:disabled { opacity: .45; cursor: not-allowed; }
.gs-reg:disabled::-webkit-slider-thumb { background: var(--muted); }

@media (max-width: 620px) { .gs-row { grid-template-columns: 1fr 96px 56px; } }

.karten-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  padding: 4px 16px 18px;
}
details.gruppe[open] > .karten-grid { animation: aufklappen .22s ease; }
@keyframes aufklappen {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}
.karte {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 14px 16px 16px;
  transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
}
.karte:hover { box-shadow: var(--shadow); border-color: var(--border-2); }

.karte-kopf {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px dashed var(--border);
}
.karte-name { font-weight: 700; font-size: 14.5px; }
.karte-meta { display: flex; align-items: baseline; gap: 10px; font-size: 12px; }
.karte-std { font-weight: 600; color: var(--text); }
.karte-rest { color: var(--muted); }
.karte-rest.warn { color: var(--orange); font-weight: 600; }

.karte-body { display: flex; flex-direction: column; gap: 9px; }
.karte-hint { font-size: 12.5px; color: var(--muted); font-style: italic; }

.reg-row { display: grid; grid-template-columns: 1fr 110px 62px; align-items: center; gap: 10px; }
.reg-label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); min-width: 0; }
.reg-label span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.reg { -webkit-appearance: none; appearance: none; width: 100%; height: 5px; border-radius: 99px;
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); cursor: pointer; }
.reg::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.25); cursor: pointer;
  transition: transform .1s ease;
}
.reg::-webkit-slider-thumb:hover { transform: scale(1.12); }
.reg::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); border: 2px solid var(--surface); cursor: pointer; }
.reg:focus-visible { outline: none; box-shadow: inset 0 0 0 1px var(--border), 0 0 0 3px var(--ring); }

.reg-wert {
  font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: right;
  color: var(--muted); white-space: nowrap;
}
.reg-wert.aktiv { color: var(--primary); font-weight: 700; }

.reg:disabled { opacity: .45; cursor: not-allowed; }
.reg:disabled::-webkit-slider-thumb { background: var(--muted); cursor: not-allowed; }
.reg:disabled::-moz-range-thumb { background: var(--muted); cursor: not-allowed; }
.karte.gesperrt .reg-row { opacity: .7; }

/* #2 Sperr-Hinweis, solange kein Soll gesetzt ist */
.karte-sperre {
  font-size: 12px; color: var(--orange); font-weight: 600;
  background: color-mix(in srgb, var(--orange) 12%, transparent);
  border-radius: 8px; padding: 6px 10px; margin-bottom: 2px;
}

/* #6 Aufteilung der Stunden je Person */
.karte-vert {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border);
}
.vert-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-right: 2px; }
.vert-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-variant-numeric: tabular-nums;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 99px; padding: 2px 9px 2px 7px;
}

/* ---- Toast ------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 18px; font-size: 13.5px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .25s ease;
  z-index: 50; max-width: min(90vw, 460px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok  { border-left-color: var(--gruen); }
.toast.err { border-left-color: var(--rot); }

/* ---- Responsiv --------------------------------------------------------- */
@media (max-width: 1080px) {
  .panels { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 620px) {
  .brand-sub { display: none; }
  .toolbar .btn span.lbl { display: none; }
  .reg-row { grid-template-columns: 1fr 80px 56px; }
  .abg-row { grid-template-columns: 100px 1fr 52px; }
}
