/* ============================================================================
   GalaKalk Design-System (Fable-Version)
   Farbwelt: LINDENLAUB-Branding (Grün/Lime), Kontraste nach WCAG 2.1 AA.
   Aufbau: Tokens → Basis → Layout → Komponenten → Seiten → Responsive/A11y.
   ============================================================================ */

/* ─── 1 · Tokens ─────────────────────────────────────────────────────────── */
:root {
  /* Flächen & Linien */
  --bg:           #f3f5ef;
  --surface:      #ffffff;
  --surface-alt:  #f0f4e9;
  --line:         #dde2d4;
  --line-strong:  #b9c4a8;

  /* Text */
  --ink:          #18221b;
  --muted:        #5b6760;

  /* Marke */
  --green:        #285f3a;   /* Primär – Kontrast auf Weiß 7,9:1 */
  --green-dark:   #1d4a2c;
  --green-light:  #e3eed7;
  --green-xlight: #f1f8ea;
  --lime:         #b7cf42;

  /* Funktionsfarben (alle ≥ 4,5:1 auf hellem Grund) */
  --red:          #b3372e;   /* Fehler / Pflicht-Punkt */
  --red-dark:     #962d25;
  --red-light:    #faeae8;
  --amber:        #8a6116;   /* Kann / Warnung */
  --amber-light:  #fdf3dd;
  --blue:         #2c5d80;   /* KI-Vorschlag */
  --blue-light:   #e4eef5;
  --gray-badge:   #5b6760;

  /* Geometrie */
  --radius:       10px;
  --radius-sm:    7px;
  --shadow-sm:    0 1px 3px rgba(24, 34, 27, .08);
  --shadow-md:    0 6px 22px rgba(24, 34, 27, .10);
  --topbar-h:     58px;
}

/* ─── 2 · Basis ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 70px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
h1 { font-size: 23px; margin: 0 0 6px; line-height: 1.25; }
h2 { font-size: 17px; margin: 26px 0 10px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
p  { margin: 8px 0; }
a  { color: var(--green); }
a:hover { color: var(--green-dark); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono  { font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ─── 3 · Topbar & Seitengerüst ──────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 22px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand img { height: 30px; width: auto; display: block; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand-sub  { display: block; font-size: 10.5px; color: var(--muted); font-weight: 500; letter-spacing: .4px; text-transform: uppercase; }
.spacer { flex: 1; }
.who { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.role-badge {
  font-size: 11.5px; font-weight: 600; letter-spacing: .3px;
  background: var(--green-light); color: var(--green-dark);
  border-radius: 999px; padding: 2px 10px;
}
.nav-link {
  text-decoration: none; color: var(--ink); font-weight: 600; font-size: 14px;
  padding: 7px 12px; border-radius: var(--radius-sm);
}
.nav-link:hover { background: var(--surface-alt); color: var(--ink); }
.nav-link .count {
  background: var(--amber-light); color: var(--amber);
  border-radius: 999px; font-size: 11.5px; padding: 1px 7px; margin-left: 4px;
}

main { max-width: 1060px; margin: 0 auto; padding: 26px 28px 80px; }

.breadcrumb { font-size: 13px; color: var(--muted); margin: 0 0 14px; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--green); text-decoration: underline; }
.breadcrumb .sep { margin: 0 6px; color: var(--line-strong); }

.page-head { margin-bottom: 18px; }
.page-head .lead { color: var(--muted); margin: 2px 0 0; max-width: 70ch; }

/* ─── 4 · Stepper (Wo bin ich?) ──────────────────────────────────────────── */
.stepper {
  display: flex; align-items: stretch; gap: 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  margin: 0 0 22px; box-shadow: var(--shadow-sm);
}
.step {
  flex: 1; display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; font-size: 13.5px; color: var(--muted);
  border-right: 1px solid var(--line); text-decoration: none; min-width: 0;
}
.step:last-child { border-right: 0; }
.step .dot {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  background: var(--surface-alt); color: var(--muted);
  border: 1.5px solid var(--line-strong);
}
.step .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step .sub { display: block; font-size: 11.5px; color: var(--muted); }
.step.done .dot    { background: var(--green); border-color: var(--green); color: #fff; }
.step.done         { color: var(--ink); }
.step.current      { background: var(--green-xlight); color: var(--ink); font-weight: 600; }
.step.current .dot { background: #fff; border-color: var(--green); color: var(--green); }
.step.locked       { opacity: .65; }
a.step:hover { background: var(--surface-alt); }

/* ─── 5 · Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; font-size: 14px; font-weight: 600; line-height: 1.2;
  cursor: pointer; text-decoration: none; color: var(--ink);
  transition: background .12s ease, border-color .12s ease;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.ghost { background: var(--surface); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--surface-alt); }
.btn.danger { background: var(--surface); border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: var(--red-light); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled], .btn.disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn .spin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── 6 · Badges & Labels ────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; line-height: 1;
  border-radius: 999px; padding: 4px 11px; white-space: nowrap;
}
.badge .pt { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

/* Projekt-/Unterlagen-Status */
.badge.entwurf        { background: var(--surface-alt); color: var(--muted); }
.badge.in-arbeit      { background: var(--amber-light); color: var(--amber); }
.badge.abgeschlossen  { background: var(--green-light); color: var(--green-dark); }
.badge.anonymisiert   { background: var(--blue-light); color: var(--blue); }
.badge.freigegeben    { background: var(--green-light); color: var(--green-dark); }
.badge.ausgeschlossen { background: var(--surface-alt); color: var(--muted); text-decoration: line-through; }
.badge.unsicher       { background: var(--red-light); color: var(--red); }

/* Positions-Labels 🔴🟡⚪🔵 (Pflichtenheft Abschnitt 4.1) */
.badge.lbl-pflicht  { background: var(--red-light);   color: var(--red-dark); }
.badge.lbl-pflicht .pt  { background: var(--red); }
.badge.lbl-kann     { background: var(--amber-light); color: var(--amber); }
.badge.lbl-kann .pt     { background: #d9a527; }
.badge.lbl-optional { background: var(--surface-alt); color: var(--muted); }
.badge.lbl-optional .pt { background: #fff; border: 1.5px solid var(--line-strong); }
.badge.lbl-ki       { background: var(--blue-light);  color: var(--blue); }
.badge.lbl-ki .pt       { background: var(--blue); }

/* ─── 7 · Banner / Hinweise ──────────────────────────────────────────────── */
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  border-radius: var(--radius-sm); padding: 12px 15px; margin: 0 0 16px;
  font-size: 14px; border: 1px solid;
}
.banner .ico { flex: 0 0 auto; font-size: 16px; line-height: 1.3; }
.banner.error   { background: var(--red-light);   border-color: #e5b8b3; color: var(--red-dark); }
.banner.success { background: var(--green-light); border-color: var(--line-strong); color: var(--green-dark); }
.banner.warn    { background: var(--amber-light); border-color: #e8d3a4; color: var(--amber); }
.banner.info    { background: var(--blue-light);  border-color: #bdd3e2; color: var(--blue); }
.banner b { font-weight: 700; }

/* ─── 8 · Karten & Formulare ─────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-sm);
}
.card.slim { padding: 16px 18px; }
.card h2:first-child { margin-top: 0; }

label.field { display: block; margin-bottom: 14px; font-size: 13.5px; color: var(--ink); font-weight: 600; }
label.field .hint { font-weight: 400; color: var(--muted); }
label.field input, label.field textarea, label.field select {
  display: block; width: 100%; margin-top: 5px;
  padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font: inherit; font-weight: 400; color: var(--ink); background: #fff;
}
label.field textarea { resize: vertical; }
label.check { display: flex; gap: 9px; align-items: flex-start; font-size: 14px; margin: 10px 0; cursor: pointer; }
label.check input { margin-top: 3px; }

.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.right { margin-left: auto; }

/* Datei-Ablagezone */
.dropzone {
  display: block;
  border: 2px dashed var(--line-strong); border-radius: var(--radius);
  background: var(--surface); padding: 26px 20px; text-align: center;
  color: var(--muted); cursor: pointer; transition: border-color .12s, background .12s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--green); background: var(--green-xlight); color: var(--green-dark); }
.dropzone strong { color: var(--green); }
.dropzone input[type=file] { display: none; }
.dropzone .picked { margin-top: 8px; font-size: 13px; color: var(--ink); }

/* ─── 9 · Tabellen ───────────────────────────────────────────────────────── */
table.list {
  width: 100%; border-collapse: collapse;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
}
table.list th, table.list td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list th { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; background: var(--surface); }
table.list tbody tr:hover { background: var(--green-xlight); }

/* ─── 10 · Fortschritt ───────────────────────────────────────────────────── */
.progress { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--muted); }
.progress .bar {
  flex: 1; height: 8px; min-width: 80px; background: var(--surface-alt);
  border-radius: 999px; overflow: hidden; border: 1px solid var(--line);
}
.progress .bar > i { display: block; height: 100%; background: var(--green); border-radius: 999px; transition: width .25s ease; }

/* ─── 11 · LV-Arbeitsplatz ───────────────────────────────────────────────── */
.lv-toolbar {
  position: sticky; top: var(--topbar-h); z-index: 40;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 10px 16px; margin-bottom: 18px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.lv-stat { display: flex; align-items: baseline; gap: 5px; font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.lv-stat b { font-size: 16px; color: var(--ink); font-variant-numeric: tabular-nums; }
.lv-stat.ok b { color: var(--green-dark); }
.lv-stat.warn b { color: var(--red); }

.lv-gruppe { margin-bottom: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.lv-gruppe > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; font-weight: 600; font-size: 15px;
}
.lv-gruppe > summary::-webkit-details-marker { display: none; }
.lv-gruppe > summary .chev { transition: transform .15s ease; color: var(--muted); font-size: 12px; }
.lv-gruppe[open] > summary .chev { transform: rotate(90deg); }
.lv-gruppe > summary:hover { background: var(--green-xlight); }
.lv-gruppe > summary .gnr { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.lv-gruppe .gstat { font-size: 12.5px; color: var(--muted); font-weight: 400; white-space: nowrap; }
.lv-gruppe .gactions { margin-left: auto; display: flex; gap: 6px; }

.lv-rows { border-top: 1px solid var(--line); }
.lv-row {
  display: grid;
  grid-template-columns: 52px minmax(220px, 1fr) 150px 120px 150px;
  gap: 10px; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  transition: background .12s ease;
}
.lv-row:last-child { border-bottom: 0; }
.lv-row.taken    { background: var(--green-xlight); }
.lv-row.rejected { background: #fafafa; }
.lv-row.rejected .pos-text { text-decoration: line-through; color: var(--muted); }
.lv-row .oz { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.lv-row .pos-text { font-size: 14px; }
.lv-row .herkunft { margin-top: 3px; }
.lv-row .herkunft summary { font-size: 12px; color: var(--muted); cursor: pointer; list-style: none; }
.lv-row .herkunft summary::-webkit-details-marker { display: none; }
.lv-row .herkunft summary:hover { color: var(--green); text-decoration: underline; }
.lv-row .herkunft p { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; background: var(--surface-alt); border-radius: var(--radius-sm); padding: 6px 9px; }
.lv-row .menge { font-size: 14px; font-variant-numeric: tabular-nums; }
.lv-row .menge-form { display: flex; gap: 5px; align-items: center; }
.lv-row .menge-form input { width: 72px; padding: 5px 7px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font: inherit; font-size: 13px; }
.lv-row .menge-offen { color: var(--red); font-size: 12.5px; font-weight: 600; }
.lv-actions { display: flex; gap: 5px; justify-content: flex-end; }
.lv-actions form { display: inline; }

/* Entscheidungs-Buttons */
.dec {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 14px; font-weight: 700; cursor: pointer; color: var(--muted);
  display: inline-grid; place-items: center; line-height: 1;
}
.dec:hover { background: var(--surface-alt); color: var(--ink); }
.dec.on-take { background: var(--green); border-color: var(--green); color: #fff; }
.dec.on-reject { background: var(--red); border-color: var(--red); color: #fff; }

/* Gruppen-Inhaltsverzeichnis */
.lv-toc { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 18px; }
.lv-toc a {
  font-size: 12.5px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px;
}
.lv-toc a:hover { border-color: var(--green); color: var(--green-dark); background: var(--green-xlight); }
.lv-toc a .n { color: var(--muted); font-size: 11.5px; }

/* ─── 12 · Maskeneditor ──────────────────────────────────────────────────── */
.editor-help { display: flex; gap: 14px; flex-wrap: wrap; margin: 0 0 14px; }
.editor-help .tip { display: flex; gap: 8px; align-items: baseline; font-size: 13px; color: var(--muted); }
.editor-help .tip b { color: var(--ink); font-weight: 600; }
#canvasWrap { position: relative; display: inline-block; max-width: 100%; border: 1px solid var(--line-strong); border-radius: 4px; overflow: hidden; background: #fff; }
#canvasWrap img { display: block; max-width: 100%; height: auto; }
.maskbox {
  position: absolute; background: rgba(10, 10, 10, .55);
  border: 2px solid #111; box-sizing: border-box; cursor: move;
}
.maskbox:focus-visible { outline: 3px solid var(--blue); outline-offset: 1px; }
.maskbox .del {
  position: absolute; top: -12px; right: -12px; width: 24px; height: 24px;
  border-radius: 50%; background: var(--red); color: #fff; font-weight: 700;
  text-align: center; line-height: 21px; cursor: pointer;
  border: 2px solid #fff; user-select: none; font-size: 14px; padding: 0;
}
.maskbox .resz {
  position: absolute; bottom: -9px; right: -9px; width: 18px; height: 18px;
  background: var(--green); border: 2px solid #fff; cursor: nwse-resize; border-radius: 3px; padding: 0;
}

/* ─── 13 · Auswertungs-Ladescreen ────────────────────────────────────────── */
.aw-wrap { display: flex; justify-content: center; padding: 46px 0; }
.aw-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 40px 44px; max-width: 500px; width: 100%; text-align: center; box-shadow: var(--shadow-md);
}
.aw-spinner {
  width: 56px; height: 56px; margin: 4px auto 22px;
  border: 5px solid var(--surface-alt); border-top-color: var(--green);
  border-radius: 50%; animation: spin 1s linear infinite;
}
.aw-timer { font-variant-numeric: tabular-nums; font-size: 34px; font-weight: 700; color: var(--green); margin: 12px 0 4px; letter-spacing: 1px; }
.aw-hint { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 12px auto 0; max-width: 380px; }

/* ─── 14 · Login ─────────────────────────────────────────────────────────── */
.login-wrap { display: flex; justify-content: center; padding: 7vh 16px 0; }
.login-card { width: 100%; max-width: 400px; }
.login-card .brandmark { text-align: center; margin-bottom: 18px; }
.login-card .brandmark img { height: 44px; }

/* ─── 15 · Leerzustände ──────────────────────────────────────────────────── */
.empty {
  text-align: center; padding: 44px 24px; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius);
}
.empty .ico { font-size: 30px; display: block; margin-bottom: 8px; }
.empty b { color: var(--ink); }

/* Nummerierte Schrittliste für Onboarding-Leerzustand */
ol.steps-mini { text-align: left; max-width: 430px; margin: 14px auto 0; padding-left: 22px; font-size: 14px; color: var(--ink); }
ol.steps-mini li { margin: 6px 0; }
ol.steps-mini .why { color: var(--muted); font-size: 12.5px; display: block; }

/* ─── 16 · Responsive & A11y ─────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (max-width: 900px) {
  main { padding: 18px 14px 70px; }
  .stepper { flex-wrap: wrap; }
  .step { flex: 1 1 46%; border-bottom: 1px solid var(--line); }
  .lv-row { grid-template-columns: 1fr; gap: 6px; padding: 12px 14px; }
  .lv-row .oz { font-weight: 700; }
  .lv-actions { justify-content: flex-start; }
  .lv-toolbar { position: static; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
