:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e2dc;
  --line-strong: #d4d0c8;
  --accent: #ea580c;
  --accent-ink: #ffffff;
  --accent-soft: #fff1e8;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --head: #1f2937;
  --head-ink: #f9fafb;
  --weekend: #faf8f4;
  --today: #fff7ed;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b; --panel: #1e2126; --ink: #e8e6e3; --muted: #9ca3af; --line: #2d3138; --line-strong: #3a3f47;
    --accent: #fb923c; --accent-ink: #1a1a1a; --accent-soft: #3a2618; --head: #0d0f12; --head-ink: #f3f4f6;
    --weekend: #1b1d22; --today: #2a2118; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171b; --panel: #1e2126; --ink: #e8e6e3; --muted: #9ca3af; --line: #2d3138; --line-strong: #3a3f47;
  --accent: #fb923c; --accent-ink: #1a1a1a; --accent-soft: #3a2618; --head: #0d0f12; --head-ink: #f3f4f6;
  --weekend: #1b1d22; --today: #2a2118; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 54px;
  background: var(--head); color: var(--head-ink);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.brand img { width: 28px; height: 28px; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav button {
  background: none; border: 0; color: #cbd5e1; padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  position: relative;
}
.nav button:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav button.active { color: #fff; background: rgba(255,255,255,.13); }
.badge-count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #cbd5e1; white-space: nowrap; }
.userbox button { background: rgba(255,255,255,.1); border: 0; color: #fff; padding: 6px 10px; border-radius: 8px; cursor: pointer; }

main { padding: 16px; max-width: 1700px; margin: 0 auto; }

/* ---------- Grundbausteine ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink); white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: currentColor; background: transparent; }
.pill.warn { color: var(--warn); border-color: currentColor; background: transparent; }
.pill.bad { color: var(--bad); border-color: currentColor; background: transparent; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.field > span { font-weight: 500; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  border: 1px solid var(--line-strong); background: var(--panel); border-radius: 8px; padding: 7px 9px; min-width: 0; width: 100%; color: var(--ink);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=color] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); cursor: pointer; }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--weekend); }
table.list tr:hover td { background: var(--weekend); }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* ---------- Toolbar Wochenplan ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.weeknav { display: flex; align-items: center; gap: 4px; }
.weeknav .wk { min-width: 190px; text-align: center; font-weight: 600; }
.weeknav .wk small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: none; padding: 7px 11px; cursor: pointer; border-right: 1px solid var(--line); white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--ink); color: var(--bg); }
.status-pub { font-size: 12.5px; }

/* ---------- Wochenraster ---------- */
.plan-wrap { overflow-x: auto; border-radius: var(--radius); }
table.plan { width: 100%; min-width: 980px; border-collapse: separate; border-spacing: 0; table-layout: fixed; background: var(--panel); }
table.plan th, table.plan td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); vertical-align: top; }
table.plan th:last-child, table.plan td:last-child { border-right: 0; }
table.plan thead th { position: sticky; top: 0; z-index: 3; background: var(--panel); padding: 8px 6px; text-align: left; font-weight: 600; border-bottom: 2px solid var(--line-strong); }
table.plan thead th .d { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
table.plan th.namecol, table.plan td.namecol { width: 180px; position: sticky; left: 0; z-index: 2; background: var(--panel); }
table.plan thead th.namecol { z-index: 4; }
table.plan col.sumcol, table.plan td.sumcol, table.plan th.sumcol { width: 92px; }
table.plan td.weekend, table.plan th.weekend { background: var(--weekend); }
table.plan td.today, table.plan th.today { background: var(--today); }
table.plan td.cell { padding: 4px; height: 48px; cursor: pointer; position: relative; }
table.plan td.cell:hover { box-shadow: inset 0 0 0 2px var(--line-strong); }
table.plan td.cell.dragover { box-shadow: inset 0 0 0 2px var(--accent); background: var(--accent-soft); }
table.plan td.cell.unavail { background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgba(220,38,38,.08) 6px 12px); }
table.plan td.cell.readonly { cursor: default; }
table.plan td.cell.readonly:hover { box-shadow: none; }
table.plan tr.group td { background: var(--bg); font-weight: 700; padding: 6px 10px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.plan tr.group td .dot { margin-right: 6px; vertical-align: -1px; }
table.plan tr.me td.namecol { box-shadow: inset 3px 0 0 var(--accent); }
.namecell { padding: 6px 8px; display: flex; gap: 8px; align-items: flex-start; }
.namecell .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.namecell .sub { font-size: 11.5px; color: var(--muted); }
.avatar { width: 26px; height: 26px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; text-shadow: 0 1px 1px rgba(0,0,0,.25); }
.sumcell { padding: 6px 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
.sumcell b { font-size: 13px; }
.sumcell .over { color: var(--bad); }
.sumcell .under { color: var(--warn); }

.chip {
  display: block; border-radius: 6px; padding: 3px 6px 3px 8px; margin-bottom: 3px; font-size: 12px; line-height: 1.3;
  background: var(--bg); border: 1px solid var(--line); border-left: 4px solid var(--c, #94a3b8); cursor: grab; position: relative;
}
.chip:last-child { margin-bottom: 0; }
.chip .t { font-weight: 600; font-variant-numeric: tabular-nums; }
.chip .p { color: var(--muted); }
.chip .n { display: block; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.code { border-left-width: 1px; text-align: center; font-weight: 600; background: var(--c); color: #1f2937; border-color: transparent; }
.chip.absence { border-left-width: 1px; text-align: center; font-weight: 600; background: #bbf7d0; color: #14532d; border-color: transparent; cursor: default; }
.chip.absence.sick { background: #fecaca; color: #7f1d1d; }
.chip.absence.req { background: transparent; border: 1px dashed var(--ok); color: var(--ok); }
.chip.conflict { outline: 2px solid var(--bad); outline-offset: -1px; }
.chip.open { border-style: dashed; border-left-style: solid; background: transparent; }
.chip.readonly { cursor: default; }
.chip .warnicon { position: absolute; right: 3px; top: 2px; color: var(--bad); font-weight: 800; }
.chip.dragging { opacity: .4; }
.chip .who { font-weight: 600; }

.evrow td { background: var(--weekend); }
.ev { display: block; border-radius: 6px; padding: 3px 6px; margin-bottom: 3px; font-size: 11.5px; line-height: 1.3; background: var(--c); color: #1f2937; cursor: pointer; overflow: hidden; }
.ev b { font-variant-numeric: tabular-nums; }
.ev .areas { opacity: .7; }
.addev { display: block; width: 100%; border: 1px dashed var(--line-strong); background: none; border-radius: 6px; color: var(--muted); font-size: 11.5px; padding: 2px; cursor: pointer; }
.addev:hover { color: var(--accent); border-color: var(--accent); }
.footrow td { font-size: 11.5px; color: var(--muted); padding: 5px 8px; background: var(--weekend); font-variant-numeric: tabular-nums; }

.issues { margin-top: 12px; }
.issues li { margin: 3px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; gap: 5px; align-items: center; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15,17,20,.5); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: min(620px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--panel); }
.modal .x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.quick button { border: 1px solid var(--line-strong); background: var(--panel); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; }
.quick button:hover { border-color: var(--accent); color: var(--accent); }
.quick button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); color: #fff; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(400px, 100%); padding: 28px; }
.login h1 { margin: 10px 0 4px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

/* ---------- Abwesenheits-Zeitstrahl ---------- */
.timeline { overflow-x: auto; }
.timeline table { border-collapse: collapse; font-size: 11px; }
.timeline th, .timeline td { border: 1px solid var(--line); padding: 0; width: 24px; min-width: 24px; height: 24px; text-align: center; }
.timeline th { font-weight: 500; color: var(--muted); }
.timeline td.nm, .timeline th.nm { width: 150px; min-width: 150px; text-align: left; padding: 0 8px; position: sticky; left: 0; background: var(--panel); white-space: nowrap; font-size: 12.5px; }
.timeline td.we, .timeline th.we { background: var(--weekend); }
.timeline td.u { background: #86efac; }
.timeline td.k { background: #fca5a5; }
.timeline td.r { background: repeating-linear-gradient(135deg, #86efac 0 4px, transparent 4px 8px); }

/* ---------- Mitarbeiter-Ansicht ---------- */
.shiftlist { display: flex; flex-direction: column; gap: 8px; }
.shiftitem { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); border-left: 5px solid var(--c, var(--line)); }
.shiftitem .date { width: 64px; text-align: center; flex: none; }
.shiftitem .date b { display: block; font-size: 20px; line-height: 1; }
.shiftitem .date small { color: var(--muted); text-transform: uppercase; font-size: 11px; }
.shiftitem .info { flex: 1; min-width: 0; }
.shiftitem .info .t { font-weight: 700; font-size: 15px; }
.shiftitem.today { box-shadow: 0 0 0 2px var(--accent); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12.5px; }

.pos-row { display: grid; grid-template-columns: 1fr 44px 110px 110px 36px; gap: 8px; align-items: center; margin-bottom: 6px; }
.code-row { display: grid; grid-template-columns: 80px 1fr 44px 140px 36px; gap: 8px; align-items: center; margin-bottom: 6px; }
.type-row { display: grid; grid-template-columns: 1fr 44px 36px; gap: 8px; align-items: center; margin-bottom: 6px; }

@media (max-width: 760px) {
  main { padding: 12px; }
  .topbar { gap: 10px; padding: 0 10px; }
  .brand span { display: none; }
  .userbox .who { display: none; }
  .weeknav .wk { min-width: 0; flex: 1; }
  .weeknav { width: 100%; }
  .weeknav input[type=date] { display: none; }
  .toolbar .seg { max-width: 100%; overflow-x: auto; }
  table.plan { min-width: 860px; }
  table.plan th.namecol, table.plan td.namecol { width: 112px; }
  .namecell .avatar { display: none; }
  .pos-row { grid-template-columns: 1fr 44px 36px; }
  .pos-row .t1, .pos-row .t2 { display: none; }
  .code-row { grid-template-columns: 64px 1fr 44px 36px; }
  .code-row select { display: none; }
}

/* ---------- Druck ---------- */
@media print {
  @page { size: A4 landscape; margin: 8mm; }
  :root { --bg: #fff; --panel: #fff; --weekend: #f5f5f5; --today: #fff; --shadow: none; }
  body { font-size: 10px; }
  .topbar, .toolbar .noprint, .noprint, .addev, #toast { display: none !important; }
  .print-title { display: block !important; font-size: 16px; font-weight: 700; margin-bottom: 6px; }
  main { padding: 0; max-width: none; }
  .plan-wrap { overflow: visible; }
  table.plan { min-width: 0; }
  table.plan th.namecol, table.plan td.namecol { width: 110px; position: static; }
  table.plan thead th { position: static; }
  table.plan td.cell { height: auto; }
  .chip, .ev { break-inside: avoid; font-size: 9.5px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .card { box-shadow: none; border: 0; }
}
.print-title { display: none; }
