:root {
    --color-bg: #f3f5f8;
    --color-surface: #ffffff;
    --color-border: #dde2e8;
    --color-text: #1f2937;
    --color-text-muted: #667085;
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-danger: #dc2626;
    --color-success: #16a34a;
    --color-warning: #d97706;

    --color-weekend: #eef1f6;
    --color-holiday: #ffe0d0; /* light salmon */
    --color-wish-pos: #d5f2df;
    --color-wish-pos-text: #15803d;
    --color-wish-neg: #fbdede;
    --color-wish-neg-text: #b91c1c;
    --color-vacation: #e7e2fb;
    --color-vacation-text: #5b21b6;
    --color-fixed: #dbeafe;
    --color-fixed-text: #1e40af;

    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    font-size: 15px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}
.topbar-brand a {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--color-text);
    text-decoration: none;
}
.topbar-nav { display: flex; align-items: center; gap: 1.25rem; }
.topbar-user { color: var(--color-text-muted); font-size: 0.9rem; }
.topbar-logout { color: var(--color-text-muted); }

.page {
    max-width: 100%;
    padding: 1.5rem 2rem 3rem;
}

/* ---------- Login ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #eef2ff, #f3f5f8);
}
.login-card {
    background: var(--color-surface);
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card .subtitle { margin: -0.5rem 0 0.5rem; color: var(--color-text-muted); font-size: 0.9rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; color: var(--color-text-muted); }

/* ---------- Forms / Buttons ---------- */
input[type="text"], input[type="password"], input[type="number"], input[type="month"], select {
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.95rem;
    background: var(--color-surface);
    color: var(--color-text);
}
input:focus, select:focus { outline: 2px solid var(--color-primary); outline-offset: 1px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border-radius: 6px;
    border: 1px solid transparent;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn:hover { background: #f7f8fa; }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-danger { color: var(--color-danger); border-color: #f3c9c9; }
.btn-danger:hover { background: #fdf1f1; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn:disabled, .btn:disabled:hover {
    opacity: 0.45;
    cursor: not-allowed;
    background: var(--color-surface);
    color: var(--color-text-muted);
    border-color: var(--color-border);
}

/* ---------- Cards / Sections ---------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card h2 { margin-top: 0; font-size: 1.1rem; }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.5rem; align-items: start; }

.score-settings-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem 1.5rem;
    align-items: end;
}
.score-settings-grid input[type="number"] { width: 100%; }

table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th, table.data-table td {
    text-align: left;
    padding: 0.55rem 0.6rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}
table.data-table th { color: var(--color-text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; }
table.data-table tr:last-child td { border-bottom: none; }

.plan-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--color-border);
}
.plan-list-item:last-child { border-bottom: none; }
.plan-list-item .month { font-weight: 600; }

.alert {
    padding: 0.7rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}
.alert-error { background: #fdecec; color: var(--color-danger); }
.alert-warning { background: #fef6e7; color: var(--color-warning); }
.alert-success { background: #eafaf0; color: var(--color-success); }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-muted { background: #eef1f6; color: var(--color-text-muted); }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
    display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 360px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal h3 { margin-top: 0; }
.modal .form-row { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; }
.modal .form-row label { font-size: 0.85rem; color: var(--color-text-muted); }
.modal .form-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

/* ---------- Plan page ---------- */
.plan-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.plan-toolbar h1 { margin: 0; font-size: 1.3rem; }
.plan-toolbar .toolbar-actions { display: flex; align-items: center; gap: 0.6rem; }

.view-toggle {
    display: inline-flex;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    overflow: hidden;
}
.view-toggle a {
    display: inline-block;
    border: none;
    background: var(--color-surface);
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--color-text-muted);
    text-decoration: none;
}
.view-toggle a.active { background: var(--color-primary); color: #fff; }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.9rem; font-size: 0.8rem; color: var(--color-text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

#optimize-result { margin-bottom: 1rem; }
#optimize-result .alert { margin-bottom: 0.4rem; }

.matrix-wrap {
    width: 100%;
    overflow-x: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

table.matrix {
    border-collapse: collapse;
    width: 100%;
    table-layout: fixed;
    font-size: 0.78rem;
}

table.matrix th, table.matrix td {
    border: 1px solid var(--color-border);
    padding: 0;
    text-align: center;
    white-space: nowrap;
}

/* Tagesgrenze in der aufgeschluesselten Ansicht deutlicher absetzen als die
   Trennung zwischen den Schichten innerhalb eines Tages. */
table.matrix th.col-day-start, table.matrix td.col-day-start {
    border-left: 2px solid var(--color-text-muted);
}

.col-sticky {
    position: sticky;
    left: 0;
    background: var(--color-surface);
    z-index: 3;
    text-align: left !important;
    padding: 0.4rem 0.6rem !important;
    width: 170px;
    min-width: 170px;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

thead th { position: sticky; top: 0; background: var(--color-surface); z-index: 2; }
thead th.col-sticky { z-index: 4; }
/* Mehrzeiliger sticky Header (aufgeschluesselte Ansicht): jede Zeile braucht
   einen eigenen top-Offset, sonst ueberlappen sich die Zeilen beim Scrollen. */
thead tr.row-shift-codes th { top: 46px; }
thead tr.row-role-counts th { top: 64px; }

th.day-head {
    height: 46px;
    padding: 0.3rem 0.2rem !important;
    min-width: 34px;
}
th.day-head .day-num { font-weight: 700; font-size: 0.85rem; }
th.day-head .day-dow { color: var(--color-text-muted); font-size: 0.65rem; text-transform: uppercase; }
th.day-head .holiday-toggle {
    margin-top: 0.15rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.85rem;
    opacity: 0.35;
    padding: 0;
    line-height: 1;
}
th.day-head .holiday-toggle:hover { opacity: 1; }
th.day-head.col--holiday .holiday-toggle { opacity: 1; }

th.shift-code-head {
    height: 18px;
    font-size: 0.65rem;
    color: var(--color-text-muted);
    padding: 0.15rem 0 !important;
    font-weight: 600;
    min-width: 34px;
}

th.role-count-head {
    font-size: 0.6rem;
    color: var(--color-text-muted);
    padding: 0.15rem 0 0.25rem !important;
    font-weight: 700;
    min-width: 34px;
    border-top: none;
}
th.role-count-head span {
    display: block;
    line-height: 1.35;
}

tr.role-group-row td {
    background: #f0f2f6;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-muted);
    padding: 0.35rem 0.6rem !important;
    position: sticky;
    left: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.emp-name { font-weight: 600; }
.emp-role {
    display: block;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.col--weekend { background: var(--color-weekend); }
.col--holiday { background: var(--color-holiday); }

td.cell {
    position: relative;
    height: 30px;
    min-width: 34px;
    cursor: pointer;
    user-select: none;
    font-weight: 700;
    color: var(--color-text-muted);
}
td.cell:hover { outline: 2px solid var(--color-primary); outline-offset: -2px; }

/* Kleine Stundenzahl der zugeordneten Schicht, immer unten rechts in der
   Zelle - unabhaengig vom zentrierten Text/Symbol der Zelle (eigene
   position:absolute) und in der jeweiligen Schichtfarbe (nur aggregierte
   Ansicht). */
.cell-hours {
    position: absolute;
    right: 6px;
    bottom: 5px;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
}
.cell-hours--F, .cell-hours--T { color: #4CB3BC; }
.cell-hours--S { color: #F5CF64; }
.cell-hours--vacation { color: var(--color-vacation-text); }
.cell-hours--N { color: #44207A; }
/* Eine einzelne Umrandung um den gesamten per Ziehen markierten Bereich
   (statt einzelner Rahmen je Zelle). pointer-events:none, damit
   elementFromPoint() waehrend des Ziehens weiterhin die Zelle darunter
   erkennt. */
#range-selection-box {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid var(--color-primary);
    background: rgba(37, 99, 235, 0.10);
    pointer-events: none;
    z-index: 55;
}

td.cell.col--weekend { background: var(--color-weekend); }
td.cell.col--holiday { background: var(--color-holiday); }

td.cell.cell--wish-positive { background: var(--color-wish-pos); color: var(--color-wish-pos-text); }
td.cell.cell--wish-negative { background: var(--color-wish-neg); color: var(--color-wish-neg-text); }
td.cell.cell--vacation { background: var(--color-vacation); color: var(--color-vacation-text); }
td.cell.cell--fixed { background: var(--color-fixed); color: var(--color-fixed-text); }
td.cell.cell--mixed { background: repeating-linear-gradient(135deg, #eef1f6, #eef1f6 5px, #e2e6ec 5px, #e2e6ec 10px); color: var(--color-text-muted); }

/* Zuordnung (manuell ODER Solver): ueberlagert die bestehende Wunsch-/Urlaub-
   Faerbung als dicke, nach Schicht eingefaerbte Umrandung, statt sie zu
   ersetzen - Eingabe und tatsaechliche Zuordnung bleiben beide sichtbar. */
td.cell.cell--shift-F { box-shadow: inset 0 0 0 3px #4CB3BC; }
td.cell.cell--shift-S { box-shadow: inset 0 0 0 3px #F5CF64; }
td.cell.cell--shift-N { box-shadow: inset 0 0 0 3px #44207A; }
td.cell.cell--shift-T { box-shadow: inset 0 0 0 3px #4CB3BC; }

/* ---------- Cell picker popover ---------- */
.cell-picker {
    position: absolute;
    z-index: 60;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.18);
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    min-width: 190px;
}
.cell-picker button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
    background: transparent;
    padding: 0.45rem 0.6rem;
    text-align: left;
    font-size: 0.85rem;
    border-radius: 6px;
    cursor: pointer;
    color: var(--color-text);
}
.cell-picker button:hover { background: var(--color-bg); }
.cell-picker .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.cell-picker .picker-group-label {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    padding: 0.4rem 0.6rem 0.1rem;
}
.cell-picker hr { border: none; border-top: 1px solid var(--color-border); margin: 0.3rem 0; width: 100%; }

/* ---------- Bewertungs-Karte (SolutionScorer-Kriterien) ---------- */
.score-total {
    font-size: 1.1rem;
    margin-top: 0;
    margin-bottom: 1rem;
}
.score-group {
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}
.score-group summary {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    list-style: none;
}
.score-group summary::-webkit-details-marker { display: none; }
.score-group summary::before {
    content: '▸';
    display: inline-block;
    margin-right: 0.5rem;
    color: var(--color-text-muted);
    transition: transform 0.15s ease;
}
.score-group[open] summary::before { transform: rotate(90deg); }
.score-group-meta {
    font-weight: 400;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    white-space: nowrap;
}
.score-empty {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    margin: 0.5rem 0 0.25rem 1.5rem;
}
.score-events {
    margin: 0.5rem 0 0.25rem 1.5rem;
    padding: 0;
    font-size: 0.85rem;
    list-style: disc;
}
.score-events li { margin-bottom: 0.2rem; }
.score-points {
    color: var(--color-text-muted);
    font-weight: 600;
}

/* ---------- Balances table ---------- */
.balances-table input[type="number"] { width: 80px; }
