:root {
    --bg: #f3f5f7;
    --surface: #ffffff;
    --text: #414d55;
    --muted: #8a96a1;
    --border: #d9dde3;
    --primary: #0b6bcb;
    --primary-text: #ffffff;
    --danger: #c62828;

    /* Farben der WebUntis-Oberfläche */
    --ut-text: #414d55;
    --ut-muted: #8a96a1;
    --ut-secondary: #67747e;
    --ind-cancelled: #ff4040;
    --ind-exam: #ffd615;
    --ind-change: #199c5f;
    --ind-moved: #7b61ff;
    --ind-event: #5180f9;
    --ind-draft: #e07b00;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    color: var(--text);
    background: var(--bg);
}

a {
    color: var(--primary);
}

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- Kopfzeile ---------- */

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem 1.5rem;
    padding: .35rem 1rem;
    background: #263238;
    color: #fff;
}

.brand {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

.nav {
    display: flex;
    gap: 1rem;
}

.nav a {
    color: #cfd8dc;
    text-decoration: none;
    padding: .2rem 0;
    border-bottom: 2px solid transparent;
}

.nav a.active,
.nav a:hover {
    color: #fff;
    border-bottom-color: #ff6033;
}

.logout {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .6rem;
}

.who {
    color: #cfd8dc;
    font-size: .9rem;
}

.main {
    padding: .6rem 1rem;
    max-width: 1600px;
    margin: 0 auto;
}

/* ---------- Bausteine ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem;
    margin-bottom: 1rem;
    overflow-x: auto;
}

.card.narrow {
    max-width: 420px;
    margin: 2rem auto;
}

.btn {
    display: inline-block;
    padding: .45rem .8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover { background: #eef1f4; }
.btn-small { padding: .2rem .55rem; font-size: .88rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: #0958a8; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a61f1f; }
.topbar .btn { background: transparent; color: #fff; border-color: #607d8b; }

.form {
    display: flex;
    flex-direction: column;
    gap: .8rem;
}

.form-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .8rem;
}

.form label {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    font-size: .9rem;
    color: var(--muted);
}

input[type=text], input[type=password], input[type=search], input[type=date], input[type=time], select, textarea {
    padding: .45rem .55rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    color: var(--text);
    background: #fff;
}

textarea { resize: vertical; }

.check {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    white-space: nowrap;
}

.inline {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    align-items: center;
    margin: 0;
}

.alert {
    padding: .7rem .9rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    border: 1px solid;
}

.alert-error { background: #fdecea; border-color: #f5c2bd; color: #8a1c12; }
.alert-success { background: #e8f5e9; border-color: #b9dfbc; color: #1b5e20; }
.alert-info { background: #e8f1fb; border-color: #bcd5f2; color: #0b3d75; }
.alert-warning { background: #fff8e1; border-color: #ffe08a; color: #6d4c00; }

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

.table th, .table td {
    text-align: left;
    padding: .5rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.badge { padding: .1rem .5rem; border-radius: 10px; font-size: .85rem; }
.badge-ok { background: #e8f5e9; color: #1b5e20; }
.badge-noright { background: #fff8e1; color: #6d4c00; }
.badge-error { background: #fdecea; color: #8a1c12; }

.hint { color: var(--muted); font-size: .9rem; }

/* ---------- Wochenplan (Aufbau angelehnt an WebUntis) ---------- */

.tt-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .4rem 1rem;
    margin-bottom: .4rem;
}

.tt-title h1 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--ut-text);
}

.tt-range {
    color: var(--ut-muted);
    font-weight: 600;
}

.tt-controls {
    --tb-h: 36px;
    flex: 1 1 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem .6rem;
}

.tt-controls > * { flex-shrink: 0; }

/* Gruppen mit gemeinsamem Rahmen (Klassenwahl, Datumsnavigation) */
.tb-group {
    display: inline-flex;
    align-items: stretch;
    height: var(--tb-h);
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(0, 5, 10, .05);
}

.tb-group:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(11, 107, 203, .15);
}

.tb-group > * + * { border-left: 1px solid var(--border); }

.tb-group input,
.tb-group select {
    height: 100%;
    padding: 0 .6rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    outline: none;
}

.tb-search {
    display: inline-flex;
    align-items: center;
    padding-left: .6rem;
    color: var(--ut-muted);
}

.tb-search input { width: 9.5rem; padding-left: .4rem; }
.tb-search input::placeholder { color: var(--ut-muted); }

#klasse {
    max-width: 20rem;
    padding-right: 2rem;
    appearance: none;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%238a96a1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M4 6l4 4 4-4'/%3E%3C/svg%3E") no-repeat right .6rem center / 12px;
    font-weight: 600;
    cursor: pointer;
}

.tb-star {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: 0 .75rem;
    border: 0;
    border-radius: 0 7px 7px 0;
    background: transparent;
    color: var(--ut-secondary);
    font: inherit;
    font-size: .9rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.tb-star svg { fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }
.tb-star:hover { background: #f3f5f7; color: var(--ut-text); }
.tb-star.is-active { color: #9c6b00; background: #fff8e6; }
.tb-star.is-active svg { fill: #f2b01e; stroke: #d99a0b; }

.tb-date input[type=date] {
    width: 9.2rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

.tb-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tb-h);
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ut-secondary);
    cursor: pointer;
}

.tb-icon:first-child { border-radius: 7px 0 0 7px; }
.tb-icon:last-child { border-radius: 0 7px 7px 0; }
.tb-icon:hover { background: #f3f5f7; color: var(--ut-text); }

/* Einfache Schaltflächen */
.tb-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    height: var(--tb-h);
    padding: 0 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(0, 5, 10, .05);
    color: var(--ut-text);
    font: inherit;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.tb-btn:hover { background: #f3f5f7; }
.tb-btn:focus-visible, .tb-star:focus-visible, .tb-icon:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.tb-btn-primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.tb-btn-primary:hover { background: #0958a8; }
.tb-btn-warn { border-color: var(--ind-draft); background: var(--ind-draft); color: #fff; }
.tb-btn-warn:hover { background: #c46b00; }
.tb-btn[hidden],
.tb-star[hidden] { display: none; }

.tb-actions {
    display: inline-flex;
    gap: .5rem;
    margin-left: auto;
}

/* Schalter statt Checkbox */
.tb-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    height: var(--tb-h);
    padding: 0 .3rem;
    color: var(--ut-secondary);
    font-size: .9rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.tb-switch input { position: absolute; opacity: 0; pointer-events: none; }

.tb-switch-track {
    position: relative;
    flex: 0 0 34px;
    height: 20px;
    border-radius: 999px;
    background: #cfd6dc;
    transition: background .15s;
}

.tb-switch-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
    transition: transform .15s;
}

.tb-switch input:checked + .tb-switch-track { background: var(--primary); }
.tb-switch input:checked + .tb-switch-track::after { transform: translateX(14px); }
.tb-switch:has(input:checked) { color: var(--ut-text); }
.tb-switch input:focus-visible + .tb-switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    .tb-switch-track, .tb-switch-track::after { transition: none; }
}

.week-status { color: var(--ut-muted); font-size: .9rem; }
.week-status:empty { display: none; }
.week-status.is-error { color: var(--danger); }

.week-grid {
    display: grid;
    grid-template-columns: 60px repeat(var(--days, 7), minmax(135px, 1fr));
    column-gap: 16px;
    padding: 0 16px 0 8px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 5, 10, .08);
    overflow-x: auto;
}

.week-grid[aria-busy=true] { opacity: .55; }

.wg-corner, .wg-dayhead {
    position: sticky;
    top: 0;
    z-index: 5;
    height: 40px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: #fff;
}

.wg-dayhead-label {
    margin-top: 6px;
    padding: 4px 14px;
    border-radius: 17px;
    color: var(--ut-muted);
    font-weight: 600;
    white-space: nowrap;
}

.wg-dayhead.is-today .wg-dayhead-label {
    color: #fff;
    background: var(--ut-text);
}

.wg-times, .wg-day {
    position: relative;
}

.wg-time {
    position: absolute;
    left: 0;
    right: 0;
    line-height: 1px;
    color: var(--ut-muted);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}

.wg-now-label {
    position: absolute;
    left: 5px;
    z-index: 6;
    width: 50px;
    height: 22px;
    margin-top: -11px;
    border-radius: 4px;
    background: var(--ut-text);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    line-height: 22px;
    text-align: center;
}

.wg-line {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px solid #e3e8ec;
}

.wg-now-line {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 4;
    height: 3px;
    margin-top: -1px;
    background: var(--ut-text);
    pointer-events: none;
}

.wg-holiday {
    position: absolute;
    left: -4px;
    right: -4px;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 8px;
    border-radius: 4px;
    background: rgba(190, 218, 237, .7);
    color: var(--ut-text);
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    pointer-events: none;
}

.wg-holiday-title {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Stundenkarte */

.lesson-card {
    position: absolute;
    z-index: 1;
    display: flex;
    overflow: hidden;
    padding: 5px 6px;
    border: 0;
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 -8px 16px -4px rgba(0, 5, 10, .05), 0 16px 32px -8px rgba(0, 5, 10, .24), 0 2px 8px rgba(0, 5, 10, .08);
    color: var(--ut-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.lesson-card:hover, .lesson-card:focus-visible {
    z-index: 4;
    outline: 2px solid var(--ut-muted);
    outline-offset: 0;
}

.lesson-card[draggable=true] { cursor: grab; }
.lesson-card.is-dragging { opacity: .4; }

.lc-time {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-width: 26px;
    margin-left: -3px;
    margin-right: 4px;
    font-size: 10px;
    line-height: 12px;
    color: var(--ut-muted);
}

.lc-bar {
    --color: #bfc8cf;
    flex: 0 0 4px;
    border-radius: 2px;
    background: var(--color);
}

.lc-bar-striped {
    --color: var(--ind-event);
    background: repeating-linear-gradient(-30deg, var(--color), var(--color) 8px, #f3f5f7 8px, #f3f5f7 16px);
}

.lc-inner {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    margin-left: 8px;
    overflow: hidden;
    font-size: 12px;
    font-weight: 500;
    line-height: 16px;
}

.lc-row {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.lc-top {
    font-size: 13px;
    font-weight: 600;
    line-height: 17px;
}

/* Kurze Karten: nur Zeit, erste Zeile und Kennzeichnungen */
.lesson-card.is-compact { padding-top: 2px; padding-bottom: 2px; }
.lesson-card.is-compact .lc-row:not(.lc-top) { display: none; }
.lesson-card.is-compact .lc-inner { flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 4px; }
.lesson-card.is-compact .lc-inds { margin-top: 0; padding-top: 0; }
.lesson-card.is-compact .lc-time { justify-content: center; }
.lesson-card.is-compact .lc-time span:last-child { display: none; }

.lc-inds {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: auto;
    padding-top: 2px;
}

.lc-ind {
    padding: 0 3px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    line-height: 14px;
    text-transform: uppercase;
    white-space: nowrap;
}

.ind-cancelled { color: var(--ind-cancelled); background: rgba(255, 64, 64, .12); }
.ind-exam { color: #9c8206; background: rgba(255, 214, 21, .16); }
.ind-change { color: var(--ind-change); background: #dff6eb; }
.ind-moved { color: var(--ind-moved); background: rgba(123, 97, 255, .12); }
.ind-event { color: var(--ind-event); background: rgba(81, 128, 249, .16); }
.ind-draft { color: var(--ind-draft); background: rgba(224, 123, 0, .14); }

.lesson-card.is-past { background: #f3f5f7; color: #67747e; }
.lesson-card.is-cancelled { opacity: .6; }
.lesson-card.is-cancelled .lc-time,
.lesson-card.is-cancelled .lc-row { text-decoration: line-through; }
.lesson-card.is-moved { box-shadow: inset 0 0 0 2px var(--ind-moved); }
.lesson-card.is-moved.is-draft { box-shadow: inset 0 0 0 2px var(--ind-draft); }
.lesson-card.has-warning { box-shadow: inset 0 0 0 2px var(--ind-cancelled); }
.lesson-card.is-ghost {
    background: #f1f5f8;
    box-shadow: none;
    border: 1.5px dashed var(--ut-muted);
    opacity: .75;
}

.wg-drop {
    position: absolute;
    left: 1px;
    right: 1px;
    z-index: 6;
    padding: .1rem .3rem;
    border: 2px dashed var(--ind-moved);
    border-radius: 4px;
    background: rgba(123, 97, 255, .1);
    color: var(--ind-moved);
    font-size: .75rem;
    font-weight: 600;
    pointer-events: none;
}

/* Legende */

.tt-footer {
    display: flex;
    justify-content: center;
    margin: .6rem 0 .2rem;
}

.tt-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 5px;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 4px 16px rgba(65, 77, 85, .25);
}

.tt-legend .lg {
    display: inline-flex;
    align-items: center;
    padding: .1rem .7rem .1rem .45rem;
    border-radius: 999px;
    background: var(--ut-secondary);
    color: #fff;
    font-size: .78rem;
    font-weight: 600;
}

.ind-shape {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 8px;
    border: 2px solid #fff;
    border-radius: 3px;
    background: currentColor;
}

.ind-shape.ind-cancelled { color: var(--ind-cancelled); }
.ind-shape.ind-exam { color: var(--ind-exam); }
.ind-shape.ind-change { color: var(--ind-change); }
.ind-shape.ind-moved { color: var(--ind-moved); }
.ind-shape.ind-event { color: var(--ind-event); }
.ind-shape.ind-draft { color: var(--ind-draft); }

/* ---------- Dialoge ---------- */

.dialog {
    border: 0;
    border-radius: 8px;
    padding: 0;
    width: min(560px, 94vw);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}

.dialog::backdrop { background: rgba(0, 0, 0, .35); }
.dialog-body { padding: 1.2rem; margin: 0; }
.dialog-body h2 { margin-top: 0; }

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .5rem;
    margin-top: 1rem;
}

.details {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: .3rem .9rem;
    margin: 0;
}

.details dt { color: var(--muted); }
.details dd { margin: 0; }

.conflicts { padding-left: 1.2rem; color: #8a1c12; }

.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 20;
    max-width: min(480px, 92vw);
    padding: .8rem 1rem;
    border-radius: 6px;
    background: #263238;
    color: #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
}

.toast-error { background: var(--danger); }

@media (max-width: 700px) {
    .logout { margin-left: 0; }
    .tb-klasse { flex: 1 1 100%; }
    .tb-klasse #klasse { flex: 1; min-width: 0; }
    .tt-controls { min-width: 0; width: 100%; }
    .tb-klasse { min-width: 0; flex-shrink: 1; }
    .tb-search { flex: 0 1 auto; min-width: 0; }
    .tb-search input { width: 6.5rem; min-width: 0; }
    .tb-star-label { display: none; }
    .week-grid { grid-template-columns: 3.4rem repeat(var(--days, 5), minmax(120px, 1fr)); }
}

/* ---------- Systemseite: WebUntis-Daten laden ---------- */

#untis-loader [hidden] { display: none; }
#loader-progress { width: 100%; height: 1rem; }
