/* ---------- Farb-Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --gross: #eb6834;
  --gross-soft: rgba(235, 104, 52, 0.12);
  --klein: #2a78d6;
  --klein-soft: rgba(42, 120, 214, 0.12);
  --mouse: #a3a5ae;
  --primary-bg: #0b0b0b;
  --primary-fg: #ffffff;
  --good: #0ca30c;
  --good-text: #006300;
  --good-soft: rgba(12, 163, 12, 0.12);
  --warn: #fab219;
  --warn-text: #8a5a00;
  --warn-soft: rgba(250, 178, 25, 0.18);
  --critical: #d03b3b;
  --critical-soft: rgba(208, 59, 59, 0.10);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --grid: #2c2c2a;
    --axis: #383835;
    --gross: #d95926;
    --gross-soft: rgba(217, 89, 38, 0.18);
    --klein: #3987e5;
    --klein-soft: rgba(57, 135, 229, 0.18);
    --primary-bg: #f0efec;
    --primary-fg: #0b0b0b;
    --good-text: #0ca30c;
    --good-soft: rgba(12, 163, 12, 0.18);
    --warn-text: #fab219;
    --warn-soft: rgba(250, 178, 25, 0.14);
    --critical-soft: rgba(208, 59, 59, 0.18);
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --border: rgba(255, 255, 255, 0.10);
  --grid: #2c2c2a;
  --axis: #383835;
  --gross: #d95926;
  --gross-soft: rgba(217, 89, 38, 0.18);
  --klein: #3987e5;
  --klein-soft: rgba(57, 135, 229, 0.18);
  --primary-bg: #f0efec;
  --primary-fg: #0b0b0b;
  --good-text: #0ca30c;
  --good-soft: rgba(12, 163, 12, 0.18);
  --warn-text: #fab219;
  --warn-soft: rgba(250, 178, 25, 0.14);
  --critical-soft: rgba(208, 59, 59, 0.18);
  --shadow: none;
}

/* ---------- Grundlagen ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 650; }
p { margin: 0; }
[hidden] { display: none !important; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; white-space: nowrap; }
.mainnav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.mainnav a {
  text-decoration: none; color: var(--text-2);
  padding: 6px 12px; border-radius: 8px; white-space: nowrap;
}
.mainnav a:hover { background: var(--surface-2); color: var(--text); }
.mainnav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.topbar-actions a.active { background: var(--surface-2); }

@media (max-width: 1020px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .brand span { display: none; }
  .mainnav { order: 3; flex-basis: 100%; }
  .topbar-actions { margin-left: auto; }
  #nav-user { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
}

/* ---------- Buttons & Formulare ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary-bg); color: var(--primary-fg); border-color: transparent; }
.btn-primary:hover { background: var(--primary-bg); opacity: 0.88; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--critical); }
.btn-danger:hover { background: var(--critical-soft); }
.btn-sm { padding: 6px 12px; font-size: 0.9rem; }
.icon-btn { width: 34px; padding: 6px 0; }
:focus-visible { outline: 2px solid var(--klein); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="datetime-local"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--klein); outline-offset: -1px; }
textarea { min-height: 160px; resize: vertical; }
.field { margin-bottom: 18px; }
.field-hint { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; margin: 0; }
.checkbox input { width: 16px; height: 16px; }
.form-error {
  background: var(--critical-soft); color: var(--critical);
  border-radius: 9px; padding: 10px 12px; margin-bottom: 16px; font-weight: 550;
}
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

/* Größen-Auswahl */
.size-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.size-option { position: relative; margin: 0; }
.size-option input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.size-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px; border-radius: var(--radius);
  border: 2px solid var(--border); background: var(--surface);
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.size-card strong { font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.size-card span { font-weight: 400; color: var(--text-2); font-size: 0.88rem; }
.size-option input:checked + .size-card.gross { border-color: var(--gross); background: var(--gross-soft); }
.size-option input:checked + .size-card.klein { border-color: var(--klein); background: var(--klein-soft); }
.size-option input:focus-visible + .size-card { outline: 2px solid var(--klein); outline-offset: 2px; }

/* ---------- Karten / Panels ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { color: var(--text-2); margin-top: 4px; }
.stack > * + * { margin-top: 16px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge-gross { background: var(--gross-soft); color: var(--text); }
.badge-gross::before { background: var(--gross); }
.badge-klein { background: var(--klein-soft); color: var(--text); }
.badge-klein::before { background: var(--klein); }
.badge-open { background: var(--warn-soft); color: var(--warn-text); }
.badge-open::before { content: "●"; background: none; width: auto; height: auto; font-size: 0.7rem; color: var(--warn); }
.badge-done { background: var(--good-soft); color: var(--good-text); }
.badge-done::before { content: "✓"; background: none; width: auto; height: auto; font-size: 0.8rem; }
.badge-role { background: var(--surface-2); color: var(--text-2); }
.badge-role::before { display: none; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.dot-gross { background: var(--gross); }
.dot-klein { background: var(--klein); }

/* ---------- Dashboard ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 20px; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--text-2);
  font: inherit; font-size: 0.88rem; font-weight: 550;
  padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.filters select { width: auto; min-width: 160px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 16px 18px; }
.kpi .kpi-label { font-size: 0.85rem; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.kpi .kpi-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.kpi .kpi-sub { font-size: 0.82rem; color: var(--muted); }

.size-split { display: flex; height: 8px; border-radius: 4px; overflow: hidden; gap: 2px; margin-top: 10px; background: var(--surface-2); }
.size-split div { height: 100%; }
.size-split .g { background: var(--gross); border-radius: 4px 0 0 4px; }
.size-split .k { background: var(--klein); border-radius: 0 4px 4px 0; }

.dash-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.span-8 { grid-column: span 8; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-12 { grid-column: span 12; }
@media (max-width: 960px) { .span-8, .span-4, .span-6 { grid-column: span 12; } }

.chart-card h2 { margin-bottom: 2px; }
.chart-card .chart-sub { font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 300px; }
.legend { display: flex; gap: 16px; font-size: 0.85rem; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.empty-chart { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 0.9rem; text-align: center; }
details.table-view { margin-top: 10px; font-size: 0.85rem; }
details.table-view summary { cursor: pointer; color: var(--muted); }
details.table-view table { margin-top: 8px; }

/* ---------- Listen ---------- */
.piep-list { list-style: none; margin: 0; padding: 0; }
.piep-item {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 14px; align-items: center;
  padding: 14px 4px; border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
}
.piep-item:last-child { border-bottom: 0; }
.piep-item:hover .piep-title { text-decoration: underline; }
.piep-bar { width: 4px; align-self: stretch; border-radius: 2px; }
.piep-bar.gross { background: var(--gross); }
.piep-bar.klein { background: var(--klein); }
.piep-title { font-weight: 600; overflow-wrap: anywhere; }
.piep-meta { font-size: 0.85rem; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; }
.piep-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
@media (max-width: 560px) {
  .piep-item { grid-template-columns: 4px 1fr; }
  .piep-right { grid-column: 2; flex-direction: row; align-items: center; }
}

.list-toolbar { display: grid; grid-template-columns: 2fr repeat(3, 1fr) auto; gap: 10px; margin-bottom: 16px; align-items: center; }
@media (max-width: 860px) { .list-toolbar { grid-template-columns: 1fr 1fr; } .list-toolbar input[type="search"] { grid-column: span 2; } }

.empty { text-align: center; padding: 40px 16px; color: var(--text-2); }
.empty img { opacity: 0.85; margin-bottom: 8px; }

/* ---------- Detail ---------- */
.detail-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.detail-title { font-size: 1.6rem; font-weight: 700; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; margin: 20px 0; }
.fact { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; }
.fact dt { font-size: 0.8rem; color: var(--muted); }
.fact dd { margin: 2px 0 0; font-weight: 600; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment { padding: 12px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: 0; }
.comment-head { display: flex; justify-content: space-between; gap: 8px; font-size: 0.85rem; color: var(--text-2); margin-bottom: 4px; }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
td.actions { white-space: nowrap; text-align: right; }

/* ---------- Login ---------- */
.auth-wrap { min-height: calc(100vh - 80px); display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 420px; }
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 20px; text-align: center; }
.auth-logo h1 { font-size: 1.5rem; }
.auth-switch { margin-top: 16px; text-align: center; font-size: 0.9rem; color: var(--text-2); }
.auth-switch button { background: none; border: 0; color: var(--klein); font: inherit; cursor: pointer; text-decoration: underline; }

/* ---------- Toast & Modal ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--primary-bg); color: var(--primary-fg);
  padding: 10px 18px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,0.2);
  z-index: 100; max-width: calc(100% - 32px);
}
.toast.error { background: var(--critical); color: #fff; }
.modal {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 24px; width: min(460px, calc(100% - 32px));
}
.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal h2 { margin-bottom: 14px; }

/* ---------- Ursache / Lösung & Wissen ---------- */
.solution-box {
  margin-top: 20px; padding: 14px 16px;
  border-radius: 10px; background: var(--good-soft);
  border-left: 4px solid var(--good);
}
.solution-box h2 { margin-bottom: 6px; }
.solution-box.empty-solution { background: var(--surface-2); border-left-color: var(--axis); }
.has-solution { color: var(--good-text); font-weight: 600; }

.knowledge-item {
  display: block; text-decoration: none; color: inherit;
  padding: 16px 4px; border-bottom: 1px solid var(--border);
}
.knowledge-item:last-child { border-bottom: 0; }
.knowledge-item:hover h3 { text-decoration: underline; }
.knowledge-item h3 { font-size: 1.05rem; margin: 2px 0 8px; overflow-wrap: anywhere; }
.knowledge-item .detail-head { margin-bottom: 2px; }
.knowledge-solution { background: var(--good-soft); border-radius: 8px; padding: 8px 12px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Anhänge ---------- */
.attach-zone { transition: outline-color 0.15s; outline: 2px dashed transparent; outline-offset: -2px; }
.attach-zone.dragging { outline-color: var(--klein); background: var(--klein-soft); }
.attach-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
@media (pointer: coarse) { .hide-touch { display: none; } }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.thumb { margin: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.thumb a { display: block; aspect-ratio: 4 / 3; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb figcaption {
  display: flex; align-items: center; gap: 4px; justify-content: space-between;
  padding: 4px 4px 4px 10px; font-size: 0.8rem; color: var(--text-2);
}
.thumb figcaption span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list, .pending-list { list-style: none; margin: 10px 0 0; padding: 0; }
.file-list li, .pending-list li {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 0; border-bottom: 1px solid var(--border);
}
.file-list li:last-child, .pending-list li:last-child { border-bottom: 0; }
.file-name { font-weight: 600; overflow-wrap: anywhere; }
.file-name::before { content: "📄 "; }
.pending-list li span:first-child { flex: 1; overflow-wrap: anywhere; }
.camera-view { width: 100%; max-height: 60vh; border-radius: 10px; background: #000; margin-bottom: 12px; }
.modal:has(.camera-view) { width: min(720px, calc(100% - 32px)); }

/* ---------- Verlauf ---------- */
.history { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--grid); }
.hist-item { position: relative; padding: 0 0 16px 4px; }
.hist-item::before {
  content: ""; position: absolute; left: -25px; top: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--axis);
}
.hist-item:last-child { padding-bottom: 0; }
.hist-head { overflow-wrap: anywhere; }
.hist-change { font-size: 0.9rem; margin: 4px 0; overflow-wrap: anywhere; }
.hist-change summary { cursor: pointer; }
.hist-diff { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.hist-diff > div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
@media (max-width: 640px) { .hist-diff { grid-template-columns: 1fr; } }
code { font-size: 0.85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- Textersetzungen ---------- */
.repl-table td { padding: 6px 6px 6px 0; }
.repl-table td:nth-child(2) { width: 24px; text-align: center; }
.repl-table td:last-child { width: 44px; }
