:root {
  --bg: #f4f5f9; --panel: #fff; --text: #1b2130; --muted: #6b7385; --line: #e3e6ee;
  --side: #161a2b; --side-text: rgba(255,255,255,.72); --side-active: rgba(255,255,255,.09);
  --accent: #5b4cf0; --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--panel)); --ok: #18a058; --ok-soft: #e4f6ec;
  --warn: #d98a00; --warn-soft: #fff4dc; --bad: #d63c3c; --bad-soft: #fde8e8;
  --head: #fafbfd; --hover: color-mix(in srgb, var(--accent) 5%, var(--panel)); --group: #f4f5fa; --chip: #eef0f6; --field: #fff; --hover-line: #c8cdda;
  --radius: 8px; --shadow: 0 1px 2px rgba(20,25,45,.06), 0 2px 8px rgba(20,25,45,.05);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f1220; --panel: #181c2e; --text: #e6e8f0; --muted: #9298ad; --line: #2a2f45;
  --ok-soft: #12321f; --warn-soft: #3a2b0c; --bad-soft: #3d1717;
  --head: #1d2236; --group: #1d2236; --chip: #262b42; --field: #12162a; --hover-line: #3a4060;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Layout */
.layout { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 20px; }
.brand svg { width: 28px; height: 28px; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--side-text); padding: 9px 10px; border-radius: 7px; margin-bottom: 2px; font-weight: 500; }
.nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; font-size: 12px; padding: 8px 10px; border-top: 1px solid #2a3050; }
.side-foot button { background: none; border: 0; color: var(--side-text); padding: 0; cursor: pointer; text-decoration: underline; font: inherit; }
.main { padding: 22px 28px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.crumb { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* Panels & grid */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.panel + .panel { margin-top: 16px; }
.panel.flush { padding: 0; overflow-x: auto; }
.split > *, .grid > * { min-width: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .v { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.split { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }

/* Buttons & forms */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 12px; border-radius: 7px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--hover-line); text-decoration: none; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover { filter: brightness(.92); background: var(--accent); }
.danger { color: var(--bad); }
.ghost { border-color: transparent; background: transparent; }
.icon-btn { padding: 4px 7px; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; background: var(--field); color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar input[type=date] { width: auto; }
.toolbar select { width: auto; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); font-weight: 500; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); background: var(--head); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--hover); }
tr.group td { background: var(--group); font-weight: 650; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
tr.sub td:first-child { padding-left: 28px; }
td input { padding: 4px 6px; }
td input.qty { width: 70px; text-align: right; }
td input.price { width: 90px; text-align: right; }
.thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; background: var(--chip); display: inline-block; vertical-align: middle; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--chip); color: var(--muted); white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-accent { background: var(--accent-soft); color: var(--accent); }
.avail { font-weight: 700; }
.avail.ok { color: var(--ok); } .avail.warn { color: var(--warn); } .avail.bad { color: var(--bad); }
.st-konzept { background: var(--chip); color: var(--muted); }
.st-option { background: var(--warn-soft); color: var(--warn); }
.st-bestaetigt { background: var(--ok-soft); color: var(--ok); }
.st-vorbereitet { background: color-mix(in srgb, #1f6fd1 14%, var(--panel)); color: #3b82f6; }
.st-unterwegs { background: var(--accent-soft); color: var(--accent); }
.st-zurueck { background: color-mix(in srgb, #128074 14%, var(--panel)); color: #14a090; }
.st-storniert { background: var(--bad-soft); color: var(--bad); }

/* Tree */
.tree a { display: flex; justify-content: space-between; padding: 6px 8px; border-radius: 6px; color: var(--text); }
.tree a:hover { background: var(--hover); text-decoration: none; }
.tree a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree .lvl1 { padding-left: 22px; } .tree .lvl2 { padding-left: 36px; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Planer */
.planner { overflow: auto; max-height: calc(100vh - 210px); }
.planner table { border-collapse: separate; border-spacing: 0; }
.planner th, .planner td { padding: 5px 4px; text-align: center; font-size: 12px; border-bottom: 1px solid var(--line); }
.planner th:first-child, .planner td:first-child { position: sticky; left: 0; background: var(--panel); text-align: left; min-width: 230px; z-index: 1; border-right: 1px solid var(--line); padding-left: 10px; }
.planner thead th { position: sticky; top: 0; z-index: 2; }
.planner thead th:first-child { z-index: 3; }
.planner .we { background: var(--group); }
.planner .today { box-shadow: inset 0 -2px var(--accent); }
.cell { display: block; border-radius: 4px; padding: 3px 0; font-weight: 650; min-width: 30px; }
.c-full { background: var(--ok-soft); color: var(--ok); }
.c-part { background: var(--warn-soft); color: var(--warn); }
.c-none { background: var(--chip); color: var(--muted); }
.c-neg { background: var(--bad); color: #fff; }
.bars { display: flex; gap: 2px; align-items: flex-end; height: 70px; }
.bars div { flex: 1; border-radius: 2px 2px 0 0; min-height: 2px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,18,35,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
#toast { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1b2130; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.err { background: var(--bad); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #161a2b, #2b2464); padding: 16px; }
.login .panel { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { color: var(--text); padding: 0 0 18px; }

/* Scanner */
.scan { display: flex; gap: 8px; align-items: center; }
.scan input { font-size: 18px; padding: 10px 12px; }
.scan-log { margin-top: 10px; max-height: 220px; overflow: auto; font-size: 13px; }
.scan-log div { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.progress { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.progress div { height: 100%; background: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 30px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
.img-box { width: 100%; aspect-ratio: 4/3; background: var(--chip); border-radius: 8px; display: grid; place-items: center; overflow: hidden; color: var(--muted); }
.img-box img { width: 100%; height: 100%; object-fit: cover; }
.dropdown { position: relative; }
.results { position: absolute; left: 0; right: 0; top: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.12); max-height: 340px; overflow: auto; z-index: 20; }
.results div { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.results div:hover, .results div.sel { background: var(--accent-soft); }

/* Druck: Angebot / Packliste */
.print-only { display: none; }
@media print {
  .sidebar, .no-print, .tabs, #toast { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  .panel { border: 0; box-shadow: none; padding: 0; }
  .print-only { display: block; }
  body { background: #fff; color: #000; font-size: 12px; }
  [data-theme="dark"] { --panel: #fff; --text: #111; --muted: #555; --line: #ddd; --head: #f4f4f4; --group: #f4f4f4; --chip: #eee; --field: #fff; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px; }
  .brand { padding: 0 10px 0 4px; }
  .nav { display: flex; }
  .nav a span { display: none; }
  .side-foot { display: none; }
  .main { padding: 16px; }
  .toolbar input[type=search] { max-width: none; }
  .split .tree { max-height: 180px; overflow: auto; }
  .g2, .g3, .split, .form-grid { grid-template-columns: 1fr; }
}

/* Logo, Farben, Kalender, Etiketten */
.brand img { max-height: 32px; max-width: 150px; object-fit: contain; }
.login .brand img { max-height: 44px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; background: var(--accent); }
input[type=color] { padding: 2px; height: 36px; width: 70px; cursor: pointer; }
.colors { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.colors button { width: 26px; height: 26px; border-radius: 50%; padding: 0; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line); }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal > div { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-height: 110px; padding: 4px; min-width: 0; background: var(--panel); }
.cal .dow { min-height: 0; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--head); padding: 6px; }
.cal .out { background: var(--group); }
.cal .out .dnum { opacity: .45; }
.cal .dnum { font-size: 12px; font-weight: 600; color: var(--muted); padding: 2px 4px; }
.cal .is-today .dnum { background: var(--accent); color: #fff; border-radius: 99px; display: inline-block; min-width: 22px; text-align: center; }
.ev { display: block; font-size: 12px; padding: 2px 6px; border-radius: 4px; margin-top: 2px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none !important; }
.ev.dim { opacity: .55; }
.labels { display: grid; grid-template-columns: repeat(3, 70mm); gap: 0; }
.label { width: 70mm; height: 37mm; padding: 3mm 4mm; border: 1px dashed var(--line); display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; background: #fff; color: #000; }
.label .ln { font-weight: 700; font-size: 11pt; line-height: 1.15; max-height: 2.4em; overflow: hidden; }
.label .lm { font-size: 8pt; color: #333; }
.label svg { width: 100%; height: 13mm; display: block; }
.label .lc { font-family: ui-monospace, monospace; font-size: 9pt; text-align: center; letter-spacing: .08em; }
.labels-wrap { overflow-x: auto; }
.lbl-sel { width: 30px; }
@media print {
  .labels-page .label { border: 0; }
  .labels-page .labels { margin: 0; }
  .cal-page .cal > div { min-height: 80px; }
  .cal-page .ev { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
[data-side="light"] { --side-text: rgba(20,25,45,.72); --side-active: rgba(20,25,45,.07); }
[data-side="light"] .brand, [data-side="light"] .nav a:hover { color: #1b2130; }
[data-side="light"] .side-foot { border-top-color: rgba(20,25,45,.12); }
[data-side="light"] .sidebar { border-right: 1px solid var(--line); }
.conflict { color: var(--bad); font-size: 12px; }
