:root {
    --bg: #f4f6f8; --panel: #fff; --text: #1d2733; --muted: #6b7785; --line: #dde3ea;
    --primary: #b3261e; --primary-dark: #8c1d17; --ok: #1e7b3b; --warn: #a86400; --info: #2457a6;
    --ok-bg: #e5f4ea; --warn-bg: #fff3dc; --err-bg: #fde8e6; --info-bg: #e7eefb;
    --shift-f: #fff4c2; --shift-s: #d9ecff; --shift-n: #e4dcf7; --shift-t: #e2f3e5;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--info); }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; background: var(--primary); color: #fff; padding: .5rem 1rem; }
.topbar a { color: #fff; text-decoration: none; }
.brand { font-weight: 700; white-space: nowrap; }
.mainnav { display: flex; flex-wrap: wrap; gap: .2rem; flex: 1; }
.mainnav a { padding: .35rem .6rem; border-radius: 4px; }
.mainnav a.active, .mainnav a:hover { background: rgba(255,255,255,.18); }
.userbox { display: flex; gap: .5rem; align-items: center; font-size: .9rem; }
.userbox .muted { color: #f3d1cf; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; }
button.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; font: inherit; }

.container { max-width: 1200px; margin: 1rem auto; padding: 0 1rem; }
.container.wide { max-width: none; }
.footer { text-align: center; padding: 1.5rem; font-size: .8rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 1rem; margin-bottom: 1rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: .8rem 1rem; }
.card .num { font-size: 1.6rem; font-weight: 700; }

.flash { padding: .6rem .9rem; border-radius: 4px; margin-bottom: .8rem; border: 1px solid transparent; }
.flash-success { background: var(--ok-bg); border-color: #b5dfc2; }
.flash-error { background: var(--err-bg); border-color: #f2b8b2; }
.flash-info { background: var(--info-bg); border-color: #bccbea; }
.flash-warning { background: var(--warn-bg); border-color: #f0d197; }

table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { border-bottom: 1px solid var(--line); padding: .4rem .5rem; text-align: left; vertical-align: top; }
th { background: #eef1f5; font-weight: 600; font-size: .9rem; }
td.num, th.num { text-align: right; }
tr.inactive td { color: var(--muted); }
.table-wrap { overflow-x: auto; }

form.inline { display: inline; }
label { display: block; font-weight: 600; font-size: .9rem; margin: .5rem 0 .2rem; }
label.check { font-weight: 400; display: inline-flex; gap: .3rem; align-items: center; margin-right: .8rem; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], input[type=email], select, textarea {
    width: 100%; padding: .4rem .5rem; border: 1px solid #c6ced8; border-radius: 4px; font: inherit; background: #fff;
}
textarea { min-height: 4rem; }
.row { display: flex; gap: .8rem; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.row > .shrink { flex: 0 0 auto; }
.actions { margin-top: 1rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.btn, button.btn { display: inline-block; padding: .45rem .9rem; border-radius: 4px; border: 1px solid var(--primary); background: var(--primary); color: #fff; text-decoration: none; cursor: pointer; font: inherit; font-size: .92rem; }
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--primary); }
.btn.secondary:hover { background: #fbeeed; }
.btn.small { padding: .2rem .5rem; font-size: .82rem; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.danger { background: #fff; color: #a01010; border-color: #d99; }
.btn[disabled] { opacity: .5; cursor: default; }

.badge { display: inline-block; padding: .05rem .45rem; border-radius: 10px; font-size: .78rem; background: #e8ecf1; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: #a01010; }
.badge.info { background: var(--info-bg); color: var(--info); }

.findings { list-style: none; padding: 0; margin: 0; }
.findings li { padding: .35rem .6rem; border-left: 4px solid; margin-bottom: .25rem; background: var(--panel); font-size: .9rem; }
.findings li.error { border-color: #c62828; background: var(--err-bg); }
.findings li.warning { border-color: #e09100; background: var(--warn-bg); }
.findings li.info { border-color: #5b84c4; background: var(--info-bg); }

/* Dienstplan */
:root { --q1: #9aa3ad; --q2: #2e9d55; --q3: #2563c9; --q4: #8b3fb5; --today: #b3261e; }
.plan-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: .6rem; }
.plan-head h1 { margin: 0; }
.kpis { display: flex; gap: .6rem; flex-wrap: wrap; }
.kpi { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid #c3cbd4;
    border-radius: 6px; padding: .35rem .8rem; min-width: 120px; color: var(--text); text-decoration: none; font-size: .8rem; }
.kpi .kpi-num { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.kpi.good { border-left-color: var(--ok); } .kpi.bad { border-left-color: #c62828; }
.kpi.bad .kpi-num { color: #b3261e; }
a.kpi:hover { background: #fafbfc; }

.toolbar { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; margin: .4rem 0; }
.seg { display: inline-flex; border: 1px solid #c6ced8; border-radius: 6px; overflow: hidden; }
.seg a { padding: .35rem .9rem; text-decoration: none; color: var(--text); font-size: .9rem; background: #fff; }
.seg a + a { border-left: 1px solid #c6ced8; }
.seg a.on { background: var(--primary); color: #fff; }
.pills { display: flex; flex-wrap: wrap; gap: .3rem; }
.pills a { padding: .2rem .6rem; border-radius: 999px; border: 1px solid #c6ced8; text-decoration: none; color: var(--text); font-size: .82rem; background: #fff; }
.pills a.on { background: #1d2733; border-color: #1d2733; color: #fff; }
.toolbar .tools { margin-left: auto; display: flex; gap: .4rem; }
.plan-actions { margin: .2rem 0 .4rem; }

.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .8rem; margin: .5rem 0; color: var(--muted); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.qbar { display: inline-block; width: 4px; height: 14px; border-radius: 2px; }
.qbar.q1 { background: var(--q1); } .qbar.q2 { background: var(--q2); } .qbar.q3 { background: var(--q3); } .qbar.q4 { background: var(--q4); }

.plan-scroll { overflow: auto; max-height: calc(100vh - 230px); min-height: 320px; background: var(--panel);
    border: 1px solid var(--line); border-radius: 6px; }
table.plan { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: .78rem; background: var(--panel); }
table.plan th, table.plan td { border-bottom: 1px solid #edf0f3; border-right: 1px solid #f2f4f6; padding: 2px 3px; text-align: center; vertical-align: middle; }
table.plan thead th { position: sticky; background: #f6f8fa; z-index: 2; font-weight: 600; }
table.plan thead tr.kw-row th { top: 0; height: 20px; font-size: .7rem; color: var(--muted); font-weight: 500; border-bottom: 0; }
table.plan thead tr.kw-row th.kw { border-left: 2px solid #c9d1da; }
table.plan thead tr.day-row th { top: 20px; border-bottom: 2px solid #c9d1da; }
table.plan .sticky-col { position: sticky; left: 0; z-index: 1; background: var(--panel); text-align: left; }
table.plan thead .sticky-col { z-index: 3; background: #f6f8fa; }
.day-row th .wd { display: block; font-size: .66rem; color: var(--muted); font-weight: 500; }
.day-row th .dn { display: block; font-size: .85rem; }
table.plan .we { background: #f7f7f9; } table.plan thead .we { background: #eef0f3; }
table.plan .hol { background: #fdf0ec; } table.plan thead .hol { background: #fbe0d8; }
table.plan .wk { border-left: 2px solid #c9d1da; }
table.plan thead th.today { background: var(--today); color: #fff; } table.plan thead th.today .wd { color: #ffd9d6; }
table.plan td.today { box-shadow: inset 2px 0 0 var(--today), inset -2px 0 0 var(--today); }

table.plan tr.group-row th { background: #e9edf2; padding: .35rem 0; border-top: 2px solid #c9d1da; text-align: left; }
/* Beschriftung bleibt beim waagerechten Scrollen links stehen */
.group-label { position: sticky; left: 0; display: inline-block; padding: 0 .6rem; }
.group-title { font-weight: 700; font-size: .9rem; margin-right: .6rem; }
.rowlabel { white-space: nowrap; font-weight: 400; padding: 2px 8px !important; min-width: 190px; }
.rowlabel .veh { display: inline-block; width: 4.6rem; font-weight: 700; }
.rowlabel .time { color: var(--muted); font-size: .75rem; margin-left: .2rem; }
tr.vehicle-first > * { border-top: 1px solid #c9d1da; }

/* Besatzung in der Fahrzeugansicht */
.plan-vehicles td { min-width: 88px; max-width: 100px; padding: 2px; }
.plan-vehicles td.none { background-image: repeating-linear-gradient(135deg, transparent 0 4px, #f0f2f5 4px 5px); }
.crew { display: block; text-align: left; padding: 1px 4px 1px 5px; margin: 1px 0; border-radius: 3px; border-left: 3px solid var(--q2);
    background: #f4f7fa; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.35; }
a.crew:hover { background: #e3ecf8; }
.crew.q1 { border-left-color: var(--q1); } .crew.q2 { border-left-color: var(--q2); } .crew.q3 { border-left-color: var(--q3); } .crew.q4 { border-left-color: var(--q4); }
.crew.open { background: #fde3e0; border-left-color: #c62828; color: #a01010; font-weight: 600; }
.crew.mine { background: #dbe8fb; font-weight: 700; }
.crew.locked::after, .chip.locked::after { content: "🔒"; font-size: .6rem; margin-left: 2px; }
.crew.ki { box-shadow: inset -3px 0 0 #7b5bd6; }

/* Mitarbeiteransicht */
.plan-employees td { min-width: 30px; height: 28px; padding: 1px; position: relative; }
.rowlabel.emp { min-width: 230px; }
.qtag { display: inline-block; min-width: 2.4rem; text-align: center; font-size: .66rem; font-weight: 700; color: #fff; border-radius: 3px; padding: 0 3px; background: var(--q2); }
.qtag.q1 { background: var(--q1); } .qtag.q3 { background: var(--q3); } .qtag.q4 { background: var(--q4); }
.chip { display: inline-block; min-width: 22px; padding: 2px 3px; border-radius: 4px; font-weight: 700; font-size: .78rem; text-decoration: none;
    color: #1d2733; line-height: 1.2; }
.chip sup { font-size: .55rem; font-weight: 600; color: #5a6470; margin-left: 1px; }
a.chip:hover { outline: 2px solid var(--info); }
.sh-F { background: #ffe58a; } .sh-S { background: #9cc8ff; } .sh-N { background: #c9b5f2; } .sh-T { background: #a8e3b4; } .sh-M { background: #ffd2a1; }
.chip.abs { background: #e4e6ea; color: #5a6470; font-weight: 600; }
.chip.ki { box-shadow: inset 0 -3px 0 #7b5bd6; }
.dot { position: absolute; top: 2px; right: 2px; width: 6px; height: 6px; border-radius: 50%; }
.legend .dot { position: static; display: inline-block; }
.dot.frei { background: #2e9d55; } .dot.dienst { background: #2457a6; } .dot.ki { background: #7b5bd6; }
.pt { font-size: .66rem; color: var(--info); background: var(--info-bg); border-radius: 3px; padding: 0 3px; margin-left: 3px; }
.diff { font-weight: 700; } .diff.ok { color: var(--ok); } .diff.under { color: var(--warn); } .diff.over { color: #b3261e; }
tr.mine-row > * { background: #eef4fd !important; }

/* Lückenzeile */
tfoot .gap-row th, tfoot .gap-row td { position: sticky; bottom: 0; background: #f6f8fa; border-top: 2px solid #c9d1da; z-index: 2; }
tfoot .gap-row th.sticky-col { z-index: 3; }
.gap { display: inline-block; min-width: 20px; background: #c62828; color: #fff; border-radius: 10px; font-weight: 700; padding: 0 5px; }
.nogap { color: var(--ok); font-weight: 700; }
table.plan td.empty { text-align: left; padding: 1rem; color: var(--muted); }

/* ältere Klassen (andere Seiten) */
.shift-F { background: #ffe58a; } .shift-S { background: #9cc8ff; } .shift-N { background: #c9b5f2; } .shift-T { background: #a8e3b4; }
.wish-frei { box-shadow: inset 0 0 0 2px #2e9d55; }
.wish-dienst { box-shadow: inset 0 0 0 2px #2457a6; }

.progress { background: #e8ecf1; border-radius: 4px; height: .7rem; overflow: hidden; margin: .5rem 0; }
.progress > div { background: var(--primary); height: 100%; width: 0; transition: width .3s; }
.ai-log { font-size: .85rem; max-height: 22rem; overflow: auto; background: #fafbfc; border: 1px solid var(--line); padding: .5rem; white-space: pre-wrap; }

.weekday-picker label.check { margin-right: .4rem; }
.login-box { max-width: 380px; margin: 3rem auto; }
.wish-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; }
.wish-cal .day { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: .3rem; min-height: 4.5rem; font-size: .85rem; }
.wish-cal .day.empty { background: transparent; border: 0; }
.wish-cal .day select { font-size: .8rem; padding: .15rem; }
.wish-cal .head { font-weight: 600; text-align: center; font-size: .85rem; }

@media (max-width: 800px) {
    .nav-toggle { display: block; margin-left: auto; }
    .mainnav, .userbox { display: none; width: 100%; }
    body.nav-open .mainnav, body.nav-open .userbox { display: flex; flex-direction: column; }
}
@media print {
    .topbar, .footer, .actions, .no-print, .flash { display: none !important; }
    .container { max-width: none; margin: 0; padding: 0; }
    body { background: #fff; font-size: 10px; }
    @page { size: A4 landscape; margin: 8mm; }
    .plan-scroll { max-height: none; overflow: visible; border: 0; }
    table.plan { font-size: 7px; }
    table.plan .sticky-col, table.plan thead th, tfoot .gap-row th, tfoot .gap-row td { position: static; }
    .rowlabel, .rowlabel.emp { min-width: 0; }
    .plan-vehicles td { min-width: 0; }
    .kpis, .legend, .toolbar { display: none !important; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .panel { border: 0; padding: 0; }
}
