/* Terminplanung – ruhiges, klassisches Theme.
   - Feste, zentrierte Breite (900px)
   - Klar getrennte Abschnitte: Kopfblock + Karten
   - Tabelle mit sichtbaren Gitterlinien und Zebrazeilen
   - Angenehmes Blau-Grau-Theme, Rot nur für Löschen */

:root {
    --bg: #e8edf2;
    --surface: #ffffff;
    --ink: #223441;
    --muted: #5f7484;
    --line: #d3dde5;
    --grid: #a6b9ca;
    --head-bg: #edf3f8;
    --head-text: #41617a;
    --zebra: #f5f9fc;
    --row-hover: #e8f1f8;
    --header-from: #174e6c;
    --header-to: #2a7ba6;
    --header-sub: #cfe2ef;
    --primary: #176a96;
    --primary-hover: #125877;
    --danger-text: #b42323;
    --danger-border: #dfa3a3;
    --danger-weak: #fdeeee;
    --input-border: #b9c7d2;
    --focus-ring: #bcd9ee;
    --frei: #d9e9fb;
    --frei-we: #b4d1f2;
    --dabei: #d8f0dc;
    --dabei-we: #b0e1b9;
    --nein: #f4d0d0;
    --nein-we: #e9a8a8;
    --date-we: #e6d2a6;
    --weekend-mark: #b42323;
    --radius: 12px;
    --radius-sm: 8px;
    --width: 900px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d141b;
        --surface: #14202b;
        --ink: #e2e8ef;
        --muted: #93a4b3;
    --line: #263748;
    --grid: #3d5469;
        --head-bg: #1a2836;
        --head-text: #a9bccd;
        --zebra: #17242f;
        --row-hover: #1f303f;
        --header-from: #12394f;
        --header-to: #1c5a7c;
        --header-sub: #b7d2e2;
        --primary: #3d9cd4;
        --primary-hover: #63b3e2;
        --danger-text: #f39494;
        --danger-border: #7a3a3a;
        --danger-weak: #2c1517;
    --input-border: #33465a;
    --focus-ring: #1e3d55;
    --frei: #2c4f73;
    --frei-we: #39658f;
    --dabei: #265732;
    --dabei-we: #317144;
    --nein: #5e2f28;
    --nein-we: #7e3b30;
    --date-we: #54432a;
    --weekend-mark: #f39494;
    }
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Feste, zentrierte Breite */

.wrap {
    width: var(--width);
    max-width: calc(100% - 32px);
    margin: 30px auto 70px;
}

/* Kopfblock */

.site-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    padding: 26px 28px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--header-from), var(--header-to));
    color: #fff;
    box-shadow: 0 10px 24px -18px rgba(23, 78, 108, .55);
}

.site-header h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -.02em;
}

.site-header .lead {
    margin: 6px 0 0;
    color: var(--header-sub);
    font-size: 14px;
}

.site-header .btn {
    flex: none;
}

/* Abschnitte als Karten */

.card {
    margin-top: 22px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(23, 52, 68, .06);
    overflow: hidden;
    scroll-margin-top: 20px;
}

.card__head {
    padding: 12px 20px;
    background: var(--head-bg);
    border-bottom: 1px solid var(--line);
}

.card__head h2 {
    margin: 0;
    font-size: 12.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--head-text);
}

/* Tabelle mit Gitterlinien */

.table-scroll {
    overflow-x: auto;
}

.grid {
    width: 100%;
    border-collapse: collapse;
}

.grid th,
.grid td {
    border: 1px solid var(--grid);
    padding: 10px 16px;
    text-align: left;
}

.grid thead th {
    background: var(--head-bg);
    color: var(--head-text);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    white-space: nowrap;
}

.grid tbody tr:nth-child(even) td {
    background: var(--zebra);
}

.grid tbody tr:hover td {
    background: var(--row-hover);
}

.grid__name {
    font-weight: 650;
}

.grid .col-actions {
    text-align: right;
    white-space: nowrap;
}

.grid .col-actions .btn + .btn {
    margin-left: 8px;
}

.empty {
    margin: 0;
    padding: 42px 20px;
    color: var(--muted);
    text-align: center;
    font-size: 14px;
}

/* Dialog ("Neue Terminplanung" als Popup) */

.dialog {
    width: 560px;
    max-width: calc(100% - 32px);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 28px 64px -20px rgba(23, 52, 68, .5);
}

.dialog::backdrop {
    background: rgba(20, 35, 48, .5);
}

.dialog__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    background: var(--head-bg);
    border-bottom: 1px solid var(--line);
}

.dialog__head h2 {
    margin: 0;
    font-size: 12.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--head-text);
}

/* Wartedialog (Seite während Serverzugriff gesperrt) */

.wait[hidden] {
    display: none;
}

.wait {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 35, 48, .5);
}

.wait__box {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: calc(100% - 48px);
    padding: 18px 22px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .45);
    font-weight: 600;
}

.wait__box p {
    margin: 0;
}

.spinner {
    flex: none;
    width: 22px;
    height: 22px;
    border: 3px solid var(--grid);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Schaltflächen */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 36px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    font-weight: 650;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}

.btn--sm {
    height: 31px;
    padding: 0 12px;
    font-size: 13.5px;
    border-radius: 7px;
}

.btn--primary {
    background: var(--primary);
    color: #fff;
}

.btn--primary:hover {
    background: var(--primary-hover);
}

.btn--contrast {
    background: #fff;
    color: var(--header-from);
}

.btn--contrast:hover {
    background: var(--header-sub);
}

.btn--secondary {
    border-color: var(--input-border);
    background: var(--surface);
    color: var(--ink);
}

.btn--secondary:hover {
    background: var(--head-bg);
}

.btn--danger {
    border-color: var(--danger-border);
    background: transparent;
    color: var(--danger-text);
}

.btn--danger:hover {
    background: var(--danger-weak);
}

.btn:active {
    transform: translateY(.5px);
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Formular */

.form {
    padding: 20px;
}

.form__grid {
    display: grid;
    gap: 18px;
    max-width: 620px;
}

.form__field label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 650;
    color: var(--muted);
}

.input {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    transition: border-color .12s ease, box-shadow .12s ease;
}

.input::placeholder {
    color: var(--muted);
    opacity: .8;
}

select.input {
    appearance: none;
    padding-right: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%235f7484' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

@media (forced-colors: active) {
    select.input {
        appearance: auto;
        background-image: none;
    }
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.daterow {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.daterow .input {
    width: auto;
    min-width: 158px;
}

.daterow .sep {
    color: var(--muted);
    font-size: 14px;
}

.hint {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.form__actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

/* Breite Variante für die Matrix */

.wrap--wide {
    --width: 1180px;
}

.site-header__actions {
    display: flex;
    flex: none;
    gap: 10px;
    flex-wrap: wrap;
}

.btn--light {
    border-color: rgba(255, 255, 255, .55);
    background: transparent;
    color: #fff;
}

.btn--light:hover {
    background: rgba(255, 255, 255, .16);
    border-color: #fff;
}

/* Legende */

.legend {
    display: flex;
    align-items: center;
    gap: 6px 14px;
    flex-wrap: wrap;
    font-size: 12.5px;
    color: var(--muted);
    font-weight: 600;
}

.legend__item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chip {
    display: inline-block;
    width: 15px;
    height: 15px;
    border: 1px solid var(--grid);
    border-radius: 4px;
    vertical-align: -2px;
}

.chip--c0 {
    background: var(--frei);
}

.chip--c1 {
    background: var(--dabei);
}

.chip--c2 {
    background: var(--nein);
}

.legend__hint {
    font-weight: 400;
}

/* Matrix mit fixierter Kopf- und Datumsspalte */

.matrix-scroll {
    overflow: auto;
    max-height: calc(100vh - 330px);
    min-height: 240px;
}

/* Terminansicht: Die Tabelle nutzt die verbleibende Viewport-Höhe. */
.termin-page {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.termin-page .wrap {
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: 100%;
    margin: 0 auto;
    padding: 16px 0;
    overflow: auto;
}

.termin-page .site-header,
.termin-page .weekend-summary {
    flex: none;
}

.termin-page .card {
    margin-top: 0;
}

.termin-page .matrix-card {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.termin-page .matrix-card .card__head {
    flex: none;
}

.termin-page .matrix-scroll {
    flex: 1;
    min-height: 0;
    max-height: none;
}

@media (max-height: 600px) {
    .termin-page .wrap {
        gap: 8px;
        padding: 8px 0;
    }

    .termin-page .site-header {
        padding: 10px 16px;
    }

    .termin-page .site-header h1 {
        font-size: 22px;
    }

    .termin-page .card__head {
        padding: 8px 16px;
    }

    .termin-page .weekend-summary__body {
        padding: 8px 16px;
    }

    .termin-page .weekend-summary__copy {
        margin: 8px 0;
    }
}

.matrix {
    border-collapse: separate;
    border-spacing: 0;
    width: max-content;
    min-width: 100%;
}

.matrix th,
.matrix td {
    border-right: 1px solid var(--grid);
    border-bottom: 1px solid var(--grid);
}

.matrix tr > :first-child {
    border-left: 1px solid var(--grid);
    width: 1px;
}

.matrix thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--head-bg);
    border-bottom: 2px solid var(--input-border);
    padding: 10px 12px;
    font-size: 13.5px;
    text-align: left;
    white-space: nowrap;
}

.matrix thead th:first-child {
    left: 0;
    z-index: 4;
}

.matrix tbody th {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--head-bg);
    padding: 9px 14px;
    font-size: 13.5px;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}

.matrix tbody th .wd {
    margin-left: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.matrix tbody th.we {
    background: var(--date-we);
}

.matrix td.cell {
    min-width: 96px;
    height: 40px;
    padding: 0;
    text-align: center;
    cursor: default;
}

.matrix td.cell--editable {
    cursor: pointer;
}

.matrix th.column--editable {
    background: var(--focus-ring);
}

.matrix-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-bottom: 6px;
}

.mode-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    position: relative;
    font-size: 13px;
    cursor: pointer;
    min-width: 0;
}

#editModeLabel {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#editPersonDialog .form__actions {
    flex-wrap: wrap;
}

.mode-switch input {
    position: absolute;
    right: 0;
    width: 40px;
    height: 24px;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.mode-switch__track {
    flex: none;
    width: 40px;
    height: 24px;
    padding: 3px;
    border-radius: 12px;
    background: var(--muted);
    pointer-events: none;
}

.mode-switch__track::before {
    content: '';
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
}

.mode-switch input:checked + .mode-switch__track {
    background: var(--primary);
}

.mode-switch input:checked + .mode-switch__track::before {
    transform: translateX(16px);
}

.mode-switch input:focus-visible + .mode-switch__track {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.termin-page button:disabled {
    opacity: .5;
    cursor: default;
}

.matrix .c0 {
    background: var(--frei);
    color: #22303c;
}

.matrix .c0.we {
    background: var(--frei-we);
    color: #22303c;
}

.matrix .c1 {
    background: var(--dabei);
    color: #22303c;
}

.matrix .c1.we {
    background: var(--dabei-we);
    color: #22303c;
}

.matrix .c2 {
    background: var(--nein);
    color: #22303c;
}

.matrix .c2.we {
    background: var(--nein-we);
    color: #22303c;
}

.matrix .c-missing {
    background: var(--surface);
}

/* Vollständige Wochenenden ohne Ablehnung: Statusfarben bleiben sichtbar. */
.matrix tr.weekend-available-start {
    --weekend-edge: inset 0 2px var(--weekend-mark);
}

.matrix tr.weekend-available-end {
    --weekend-edge: inset 0 -2px var(--weekend-mark);
}

.matrix tr.weekend-available > * {
    box-shadow: var(--weekend-edge);
}

.matrix tr.weekend-available > th {
    background: var(--date-we);
    box-shadow: inset 3px 0 var(--weekend-mark), var(--weekend-edge);
}

.matrix tr.weekend-available > th .wd {
    color: inherit;
}

.matrix tr.weekend-available > :last-child {
    border-right: 3px solid var(--weekend-mark);
}

/* Blauer Spaltenrahmen bleibt zusammen mit dem roten Wochenendrahmen sichtbar. */
.matrix thead th.column--editable {
    box-shadow: inset 3px 0 var(--primary), inset -3px 0 var(--primary), inset 0 3px var(--primary);
}

.matrix tbody tr > td.column--editable {
    box-shadow: inset 3px 0 var(--primary), inset -3px 0 var(--primary),
        var(--weekend-edge, inset 0 0 transparent), var(--column-bottom, inset 0 0 transparent);
}

.matrix tbody tr:last-child > td.column--editable {
    --column-bottom: inset 0 -3px var(--primary);
}

.weekend-summary__body {
    padding: 16px 20px;
}

.weekend-summary__copy {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 0;
}

.weekend-dates {
    flex: 1;
    min-width: 0;
}

.weekend-summary__copy .btn {
    flex: none;
}

.weekend-summary .btn:disabled {
    opacity: .5;
    cursor: default;
}

.th-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.mini-del {
    flex: none;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--muted);
    font-size: 12px;
    line-height: 1;
    padding: 4px 8px;
    cursor: pointer;
    transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}

.mini-del:hover {
    background: var(--danger-weak);
    border-color: var(--danger-border);
    color: var(--danger-text);
}

/* Bewegung reduzieren */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    * {
        transition: none !important;
    }

    .spinner {
        animation: none;
    }
}

/* Schmale Viewports */

@media (max-width: 640px) {
    .wrap {
        margin: 16px auto 48px;
    }

    .site-header {
        flex-direction: column;
        align-items: stretch;
        padding: 20px;
    }

    .site-header h1 {
        font-size: 22px;
    }

    .site-header .btn {
        align-self: flex-start;
    }

    .grid th,
    .grid td {
        padding: 8px 12px;
    }

    .form__actions {
        justify-content: stretch;
    }

    .form__actions .btn {
        flex: 1;
    }
}
