:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --wash: rgba(11,11,11,0.04);
  --accent: #2a78d6;
  --accent-wash: rgba(42,120,214,0.10);
  --accent-track: #cde2fb;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --other: #898781;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300;
  --brand: #c8102e;
  --rail: 64px;
  --sidebar-open: 236px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #898781;
    --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255,255,255,0.10); --wash: rgba(255,255,255,0.05);
    --accent: #3987e5; --accent-wash: rgba(57,135,229,0.16); --accent-track: #184f95;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good-text: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #898781;
  --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255,255,255,0.10); --wash: rgba(255,255,255,0.05);
  --accent: #3987e5; --accent-wash: rgba(57,135,229,0.16); --accent-track: #184f95;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-text: #0ca30c;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text-primary); min-width: 1100px;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }

/* ---------- Sidebar: icon rail, expands over the content on hover ---------- */
.sidebar {
  position: fixed; z-index: 1500; left: 0; top: 0; bottom: 0; width: var(--rail);
  display: flex; flex-direction: column; gap: 2px; padding: 12px 10px;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow: hidden; transition: width .18s ease, box-shadow .18s ease;
}
.sidebar:hover, .sidebar:focus-within { width: var(--sidebar-open); box-shadow: 4px 0 24px rgba(0,0,0,.12); }
.sidebar .nav a span, .sidebar .section span, .sidebar .me-text { opacity: 0; transition: opacity .12s ease; white-space: nowrap; }
.sidebar:hover .nav a span, .sidebar:hover .section span, .sidebar:hover .me-text,
.sidebar:focus-within .nav a span, .sidebar:focus-within .section span, .sidebar:focus-within .me-text { opacity: 1; }

/* Logo: the "f" mark when collapsed, the full logo when expanded (cropped from logo.webp via CSS). */
.brand { position: relative; display: block; height: 80px; margin: 0 0 8px; flex: none; }
.brand span { position: absolute; left: 2px; top: 4px; background-image: url("/img/logo.webp"); background-repeat: no-repeat; transition: opacity .15s ease; }
/* logo.webp is 1024×391: the "f" mark sits at x≈65–300, the whole logo at x≈65–945, y≈35–370. */
.brand .logo-icon { width: 38px; height: 42px; top: 16px; background-size: 171px 65px; background-position: -11px -6px; }
.brand .logo-full { width: 204px; height: 76px; opacity: 0; background-size: 236px 90px; background-position: -15px -8px; }
.sidebar:hover .logo-icon, .sidebar:focus-within .logo-icon { opacity: 0; }
.sidebar:hover .logo-full, .sidebar:focus-within .logo-full { opacity: 1; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 11px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--wash); color: var(--text-primary); }
.nav a.active { background: var(--accent-wash); color: var(--text-primary); }
svg.i, .nav a svg, .icon-btn svg {
  width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.nav .section { height: 28px; margin-top: 10px; padding: 0 11px; display: flex; align-items: center; border-top: 1px solid var(--border); }
.nav .section span { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }

.me { margin-top: auto; display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--border); padding-top: 12px; }
.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%; background: var(--accent-wash); color: var(--text-primary);
  display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.me-text { flex: 1; min-width: 0; font-size: 13px; }
.me-text .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.me-text .role { color: var(--text-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { padding: 6px; border: none; background: transparent; color: var(--text-secondary); flex: none; }
.icon-btn:hover { background: var(--wash); color: var(--text-primary); }

/* ---------- Content ---------- */
.content { margin-left: var(--rail); min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; gap: 12px; align-items: center; justify-content: space-between; height: 64px;
  padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 1000;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar .sub { color: var(--text-secondary); font-size: 13px; }
.controls { display: flex; gap: 8px; align-items: center; }

input, select, button {
  font: inherit; color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
button { cursor: pointer; }
button:hover { background: var(--wash); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--critical); }
button:disabled { opacity: .5; cursor: default; }

main.view { max-width: 1600px; width: 100%; margin: 0 auto; padding: 20px 24px 40px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-content: start; }
main.view.live { max-width: none; height: calc(100vh - 64px); grid-template-rows: minmax(0, 1fr) auto; padding: 16px 20px; gap: 16px; }
.content > .banner { margin: 16px 24px 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; min-width: 0;
}
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 2px; }
.card h3 { font-size: 14px; font-weight: 600; margin: 20px 0 8px; }
.card .hint { color: var(--text-secondary); font-size: 13px; margin: 0 0 12px; }
.mapcard { padding: 6px; display: flex; flex-direction: column; }
#map { flex: 1; min-height: 300px; border-radius: 8px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi .label { color: var(--text-secondary); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 600; margin-top: 2px; }
.kpi .note { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
/* Compact tiles under the live map: one row across the full width. */
.kpis.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis.compact .kpi { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "label label" "value note"; column-gap: 14px; align-items: baseline; padding: 10px 16px; }
.kpis.compact .kpi .label { grid-area: label; }
.kpis.compact .kpi .value { grid-area: value; font-size: 24px; margin: 0; }
.kpis.compact .kpi .note { grid-area: note; }
.kpis.compact .kpi .meter.wide { display: none; }
.meter.wide { width: 100%; margin: 6px 0 2px; }

.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; vertical-align: middle; }
th { color: var(--text-secondary); font-weight: 500; font-size: 12px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text-primary); }
tr.total td { font-weight: 600; }
td.wrap { white-space: normal; min-width: 160px; }
td.actions { text-align: right; }
td.actions button { margin-left: 6px; }
.muted { color: var(--text-muted); font-size: 12px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: 0; }
.meter { width: 120px; height: 8px; background: var(--accent-track); border-radius: 4px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 8px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; }
svg text { fill: var(--text-muted); font-size: 11px; font-family: inherit; }
svg .lbl { fill: var(--text-secondary); font-size: 12px; }
svg .val { fill: var(--text-primary); font-size: 12px; }
#tip {
  position: fixed; pointer-events: none; z-index: 2000; display: none;
  background: var(--surface); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15); max-width: 300px;
}
.banner { padding: 10px 14px; border-radius: 8px; background: rgba(208,59,59,.12); border: 1px solid var(--critical); }
.ok-banner { padding: 10px 14px; border-radius: 8px; background: rgba(12,163,12,.10); border: 1px solid var(--good); }
details summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; margin-top: 10px; }

.kpi-caption { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: -10px; }
.key-line { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--accent); margin-right: 8px; vertical-align: middle; }
.key-line.dashed { border-top: 2px dashed var(--text-muted); }
table.preview-table { width: auto; min-width: 480px; }
table.preview-table td:not(:first-child), table.preview-table th:not(:first-child) { text-align: right; padding-left: 32px; }

/* Hero block (top product) */
.hero-block .hero-label { color: var(--text-secondary); font-size: 13px; }
.hero-block .hero-value .swatch { width: 14px; height: 14px; }
.hero-block .hero-value { font-size: 32px; font-weight: 600; line-height: 1.15; margin: 4px 0; }
.hero-block .hero-note { color: var(--text-muted); font-size: 12px; }

/* ---------- Map overlays ---------- */
.drv-icon div {
  width: 30px; height: 30px; border-radius: 50%; color: #fff; font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center; border: 2px solid var(--surface);
  box-shadow: 0 1px 6px rgba(0,0,0,.35);
}
.drv-icon.stale div { opacity: .55; }
.map-legend {
  background: var(--surface); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 12px; line-height: 1.7; box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.cust-icon div {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand); border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(200,16,46,.6); animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(200,16,46,.55); }
  70% { box-shadow: 0 0 0 18px rgba(200,16,46,0); }
  100% { box-shadow: 0 0 0 0 rgba(200,16,46,0); }
}
@media (prefers-reduced-motion: reduce) { .cust-icon div { animation: none; box-shadow: 0 0 0 6px rgba(200,16,46,.3); } }
.leaflet-popup-content { font-size: 13px; }

/* ---------- Kundenabfrage ---------- */
.searchbar { display: flex; gap: 10px; align-items: center; }
.searchbar input { width: 340px; font-size: 16px; padding: 8px 12px; }
.searchbar button { font-size: 15px; padding: 8px 18px; }
.cust-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); gap: 20px; margin-bottom: 20px; }
#custMap { height: 480px; border-radius: 8px; }
#custMapNote:not(:empty) { padding: 6px 8px 2px; }
.cust-name { font-size: 20px; font-weight: 600; }
#custData dl { margin: 14px 0 0; display: grid; gap: 4px; }
#custData dt { color: var(--text-secondary); font-size: 12px; margin-top: 10px; }
#custData dd { margin: 0; }
#custData .big { font-size: 24px; font-weight: 600; }
#custData ul.items { margin: 2px 0 4px; padding-left: 18px; }

.eta-badge {
  display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface);
}
.eta-icon { font-size: 22px; width: 28px; text-align: center; }
.eta-main { font-size: 18px; font-weight: 600; }
.eta-sub { font-size: 13px; opacity: .85; }
/* Status fills with ink chosen per fill so text always clears contrast. */
.eta-badge.lvl-red { background: var(--critical); border-color: var(--critical); color: #fff; }
.eta-badge.lvl-orange { background: var(--serious); border-color: var(--serious); color: #0b0b0b; }
.eta-badge.lvl-yellow { background: var(--warning); border-color: var(--warning); color: #0b0b0b; }
.eta-badge.lvl-green { background: var(--good); border-color: var(--good); color: #0b0b0b; }

table.matches { margin-top: 12px; }
table.matches tbody tr { cursor: pointer; }
table.matches tbody tr:hover { background: var(--accent-wash); }

/* ---------- Werkzeuge ---------- */
.toolbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.tool-btn {
  display: flex; align-items: center; gap: 14px; text-align: left; padding: 16px 18px;
  border-radius: 12px; background: var(--surface);
}
.tool-btn svg.i { width: 28px; height: 28px; color: var(--accent); }
.tool-btn b { display: block; font-size: 15px; }
.tool-btn small { display: block; color: var(--text-secondary); font-size: 12px; margin-top: 2px; }
.tool-btn.active { border-color: var(--accent); background: var(--accent-wash); }
.assign-grid { margin: 16px 0 0; }
.mapcard.inner { border: 1px solid var(--border); border-radius: 10px; }
#assignMap { height: 520px; border-radius: 8px; }
#assignResult p { margin: 10px 0; }
#assignResult .note { padding: 8px 10px; border-radius: 8px; background: var(--wash); font-size: 13px; }
table.assign-table { margin-top: 8px; }
ul.cand { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 6px; }
ul.cand button { width: 100%; text-align: left; }
ul.cand button b { display: inline-block; width: 20px; height: 20px; border-radius: 50%; background: var(--text-primary); color: var(--surface); text-align: center; font-size: 12px; line-height: 20px; margin-right: 6px; }
.cand-icon div {
  width: 26px; height: 26px; border-radius: 50%; background: #0b0b0b; color: #fff; border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; box-shadow: 0 1px 6px rgba(0,0,0,.35); cursor: pointer;
}
.quick { display: flex; gap: 8px; margin-bottom: 12px; }
.form-inline label.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-primary); padding-bottom: 6px; }

/* ---------- Seitenzugriff ---------- */
.access { display: grid; gap: 14px; max-width: 720px; }
.access-user { display: grid; gap: 4px; font-size: 13px; color: var(--text-secondary); max-width: 360px; }
.access-pages { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 16px; }
.access-pages label.check { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.access .row { display: flex; gap: 8px; align-items: center; }
.ok-inline { color: var(--good-text); font-size: 13px; font-weight: 600; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 12px; max-width: 420px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.form .row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.form-inline label { display: grid; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.error { color: var(--critical); font-size: 13px; min-height: 1em; }

/* ---------- Login ---------- */
.login-page { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .form { max-width: none; margin-top: 16px; }
.login-logo { width: 220px; height: auto; display: block; margin: 0 auto 8px; }
