/* =====================================================================
   Vertretungsjournal – Stylesheet
   Farben zentral über CSS-Variablen; Farbnamen entsprechen config.php.
   ===================================================================== */

:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --border: #e3e7ef;
    --text: #1d2433;
    --muted: #6b7489;
    --primary: #3b5bdb;
    --primary-dark: #2f4ac0;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);

    --red: #e03131;     --red-bg: #fff0f0;
    --orange: #e8590c;  --orange-bg: #fff4e6;
    --yellow: #c08a00;  --yellow-bg: #fff9db;
    --green: #2f9e44;   --green-bg: #ebfbee;
    --teal: #0c8599;    --teal-bg: #e3fafc;
    --blue: #1c7ed6;    --blue-bg: #e7f5ff;
    --purple: #7048e8;  --purple-bg: #f3f0ff;
    --gray: #626b7f;    --gray-bg: #f1f3f5;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
[hidden] { display: none !important; }

.muted { color: var(--muted); font-weight: normal; }
.small { font-size: .85rem; }
.right { text-align: right; }
.hint { color: var(--muted); font-size: .85rem; margin: .25rem 0 1rem; }

/* ---------- Kopfzeile ---------- */
.topbar {
    background: #1d2433;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: .6rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-weight: normal; font-size: .75rem; color: #aab3c5; }
.brand-logo {
    background: var(--primary);
    border-radius: 8px;
    width: 34px; height: 34px;
    display: grid; place-items: center;
    font-size: .85rem;
}
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a { color: #cfd5e2; padding: .4rem .75rem; border-radius: 8px; }
.nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, .14); color: #fff; }
.quicksearch { margin-left: auto; }
.quicksearch input {
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .15);
    color: #fff;
    width: 240px;
}
.quicksearch input::placeholder { color: #aab3c5; }
.logout { color: #cfd5e2; font-size: 1.2rem; }

/* ---------- Layout ---------- */
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.page-head p { margin: .25rem 0 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .8rem; }
.card-head h2 { margin: 0; }
.actions-bar, .day-nav { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.page-head .actions-bar, .page-head .day-nav { margin-bottom: 0; }
.inline-form { display: inline; }
.day-nav input { width: auto; }
.day-title { border-bottom: 1px solid var(--border); padding-bottom: .3rem; }

/* ---------- Kennzahlen ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .9rem 1.1rem;
    box-shadow: var(--shadow);
}
.stat-value { display: block; font-size: 1.7rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .85rem; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .5rem .95rem;
    border-radius: 8px;
    border: 1px solid transparent;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--gray-bg); }
.btn-danger { background: var(--surface); color: var(--red); border-color: #f5c2c2; }
.btn-danger:hover { background: var(--red-bg); }
.btn-small { padding: .25rem .6rem; font-size: .8rem; }

/* ---------- Formulare ---------- */
.form label, .filter label {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    font-size: .85rem;
    font-weight: 500;
    margin-bottom: .9rem;
    flex: 1;
}
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row > label { min-width: 160px; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.form .checkbox { flex-direction: row; align-items: center; font-weight: normal; }
input, select, textarea {
    font: inherit;
    font-weight: normal;
    padding: .5rem .65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    width: 100%;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(59, 91, 219, .25); border-color: var(--primary); }
textarea { resize: vertical; }
.filter { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.filter label { margin-bottom: 0; flex: 0 1 180px; }
.login-card { max-width: 420px; margin: 3rem auto; }

/* ---------- Meldungen ---------- */
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; transition: opacity .6s; }
.alert-success { background: var(--green-bg); border-color: #b2f2bb; color: #1b5e2a; }
.alert-warning { background: var(--orange-bg); border-color: #ffd8a8; color: #8a3a00; }
.alert-error { background: var(--red-bg); border-color: #ffc9c9; color: #9b1c1c; }
.alert.fade { opacity: 0; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: .1rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-teal   { background: var(--teal-bg);   color: var(--teal); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-gray   { background: var(--gray-bg);   color: var(--gray); }

.kuerzel { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; }
.kuerzel-big {
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    padding: .1rem .5rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.arrow { color: var(--muted); }


/* ---------- Einträge (Umplanungen / Abwesenheiten) ---------- */
.item {
    display: grid;
    grid-template-columns: 90px minmax(0, 1fr) auto;
    gap: 1rem;
    padding: .8rem .9rem;
    border: 1px solid var(--border);
    border-left: 4px solid var(--gray);
    border-radius: 8px;
    margin-bottom: .6rem;
    background: #fff;
}
.item-red    { border-left-color: var(--red); }
.item-orange { border-left-color: var(--orange); }
.item-yellow { border-left-color: var(--yellow); }
.item-green  { border-left-color: var(--green); }
.item-teal   { border-left-color: var(--teal); }
.item-blue   { border-left-color: var(--blue); }
.item-purple { border-left-color: var(--purple); }
.item-date   { font-weight: 600; }
.item-period { color: var(--muted); font-size: .85rem; }
.item-head   { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.item-meta   { font-size: .85rem; color: var(--muted); margin-top: .25rem; }
.item-note   { font-size: .88rem; background: var(--gray-bg); border-radius: 6px; padding: .4rem .6rem; margin-top: .4rem; }
.item-actions { display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; }
.item-stamp  { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.reason { margin-top: .3rem; }
.reason-label {
    font-weight: 600;
    color: var(--muted);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.absence-ref { font-size: .85rem; }
.empty {
    color: var(--muted);
    text-align: center;
    padding: 1.25rem;
    border: 1px dashed var(--border);
    border-radius: 8px;
    margin-bottom: .6rem;
}

/* Zusammenfassung einer Umplanung (change_edit.php) */
/* Farbe kommt über die item-{farbe}-Klasse, hier nur die Breite */
.card.explain { border-left-width: 6px; }
.explain-head { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; font-size: 1.1rem; }
.explain-who { font-size: 1.05rem; margin: .6rem 0; }
.explain-reason { font-size: 1.15rem; margin: .4rem 0; }
.explain-absence { margin: .4rem 0; }

/* ---------- Kleine Listen, Notizen, Chips ---------- */
.mini-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .35rem 0;
    border-bottom: 1px solid var(--border);
    font-size: .88rem;
}
.mini-row:last-of-type { border-bottom: 0; }
.mini-date { color: var(--muted); min-width: 70px; font-size: .8rem; }
.mini-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.mini-link { margin-left: auto; }
.note { background: var(--yellow-bg); border-radius: 8px; padding: .6rem .8rem; margin-bottom: .6rem; }
.note-important { background: var(--red-bg); border-left: 4px solid var(--red); }
.note-foot { display: flex; justify-content: space-between; margin-top: .3rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: .3rem .8rem; }

/* ---------- Tabellen ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.table tr.inactive td { opacity: .55; }

/* ---------- Protokoll ---------- */
.log-entry { border-bottom: 1px solid var(--border); padding: .8rem 0; }
.log-entry:last-child { border-bottom: 0; }
.log-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.log-time { font-size: .82rem; color: var(--muted); min-width: 140px; }
.log-entity { font-weight: 600; }
.log-summary { margin-top: .25rem; }
.log-details summary { cursor: pointer; color: var(--primary); font-size: .85rem; margin-top: .3rem; }
.diff { border-collapse: collapse; margin-top: .5rem; font-size: .85rem; width: 100%; max-width: 760px; }
.diff th, .diff td { border: 1px solid var(--border); padding: .3rem .55rem; text-align: left; vertical-align: top; }
.diff th { background: var(--gray-bg); font-weight: 600; }
.diff td:first-child { color: var(--muted); width: 180px; }
.diff-old { background: var(--red-bg); text-decoration: line-through; text-decoration-color: rgba(224, 49, 49, .4); }
.diff-new { background: var(--green-bg); }
.pagination { display: flex; gap: 1rem; justify-content: center; align-items: center; }

/* ---------- Menü-Knopf, Filterbox, Scroll-Tabellen (Grundzustand) ---------- */
.topbar-menu { display: flex; align-items: center; gap: .75rem 1.5rem; flex: 1; min-width: 0; flex-wrap: wrap; }
.logout-label { display: none; }
.menu-toggle {
    display: none;
    margin-left: auto;
    width: 44px; height: 44px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
}
.menu-toggle span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; transition: transform .2s, opacity .2s; }
.menu-open .menu-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-open .menu-toggle span:nth-child(2) { opacity: 0; }
.menu-open .menu-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.filter-box > summary {
    cursor: pointer;
    font-weight: 600;
    list-style: none;
    display: flex;
    align-items: center;
    gap: .4rem;
}
.filter-box > summary::-webkit-details-marker { display: none; }
.filter-box > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
.filter-box[open] > summary::before { transform: rotate(90deg); }
.filter-box[open] > summary { margin-bottom: .9rem; }
.filter-count { color: var(--primary); font-weight: 500; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Tablet ---------- */
@media (max-width: 1000px) {
    .grid-2 { grid-template-columns: 1fr; }
    .page-head { align-items: flex-start; }
}

/* ---------- Handy (Teil 1: Kopfzeile, Layout, Bedienung) ---------- */
@media (max-width: 700px) {
    h1 { font-size: 1.3rem; }

    .topbar-inner {
        gap: .5rem;
        padding: .5rem max(.75rem, env(safe-area-inset-right)) .5rem max(.75rem, env(safe-area-inset-left));
    }
    .js .menu-toggle { display: flex; } /* ohne JS bleibt das Menü einfach offen */
    .topbar-menu {
        flex-direction: column;
        align-items: stretch;
        gap: .5rem;
        flex-basis: 100%;
        padding: .25rem 0 .5rem;
    }
    .js .topbar:not(.menu-open) .topbar-menu { display: none; }
    .nav { flex-direction: column; gap: .1rem; }
    .nav a { padding: .7rem .75rem; font-size: 1rem; }
    .quicksearch { margin-left: 0; }
    .quicksearch input { width: 100%; }
    .logout { padding: .6rem .75rem; font-size: 1rem; }
    .logout-label { display: inline; }

    .container { padding: 1rem max(.75rem, env(safe-area-inset-right)) 2rem max(.75rem, env(safe-area-inset-left)); }
    .card { padding: 1rem; border-radius: 10px; margin-bottom: 1rem; }
    .page-head { flex-direction: column; align-items: stretch; margin-bottom: 1rem; }
    .page-head > .btn { align-self: flex-start; }
    .card-head { flex-wrap: wrap; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; margin-bottom: 1rem; }
    .stat { padding: .7rem .85rem; }
    .stat-value { font-size: 1.4rem; }
    .hide-mobile { display: none; }

    /* Tagesnavigation: ‹ [Datum] Heute › */
    .day-nav { flex-wrap: nowrap; }
    .day-nav-date { flex: 1; min-width: 0; display: flex; justify-content: center; }
    .day-nav .day-nav-date input { width: 100%; }

    /* Bedienung per Finger; 16px verhindert Auto-Zoom unter iOS */
    input, select, textarea { font-size: 16px; }
    .btn { min-height: 42px; padding: .55rem .9rem; justify-content: center; }
    .btn-small { min-height: 36px; padding: .4rem .75rem; font-size: .85rem; }
}
/* ---------- Handy (Teil 2: Formulare, Einträge, Protokoll, Tabellen) ---------- */
@media (max-width: 700px) {
    .form-row { gap: 0 .75rem; }
    .form-row > label { min-width: 0; flex-basis: 100%; }
    .filter { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; align-items: end; }
    .filter label { flex: none; }
    .form-actions .btn { flex: 1 1 auto; }

    /* Speichern-Leiste bleibt am unteren Bildschirmrand */
    .form-actions-sticky {
        position: sticky;
        bottom: 0;
        z-index: 5;
        margin: .5rem -1rem -1rem;
        padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
        background: var(--surface);
        border-top: 1px solid var(--border);
        border-radius: 0 0 10px 10px;
        box-shadow: 0 -4px 12px rgba(16, 24, 40, .06);
    }

    /* Einträge: Datum/Stunde als Kopfzeile, Knöpfe darunter */
    .item { grid-template-columns: 1fr; gap: .4rem; padding: .7rem .8rem; }
    .item-when { display: flex; gap: .5rem; align-items: baseline; }
    .item-actions { flex-direction: row; align-items: center; flex-wrap: wrap; }
    .item-stamp { margin-left: auto; }

    /* Protokoll */
    .log-time { min-width: 0; flex-basis: 100%; }
    .diff td:first-child { width: auto; }
    .diff-compare thead { display: none; }
    .diff-compare, .diff-compare tbody, .diff-compare tr, .diff-compare td { display: block; width: 100%; }
    .diff-compare tr { border: 1px solid var(--border); border-radius: 6px; margin-bottom: .4rem; overflow: hidden; }
    .diff-compare td { border: 0; }
    .diff-compare td.diff-field { background: var(--gray-bg); font-weight: 600; color: var(--text); }
    .diff-compare td[data-label]::before { content: attr(data-label) ': '; color: var(--muted); font-size: .75rem; }

    /* Kollegium-Tabelle als Karten */
    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody { display: block; }
    .table-stack tr {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: .2rem .6rem;
        align-items: center;
        padding: .6rem 0;
        border-bottom: 1px solid var(--border);
    }
    .table-stack td { border: 0; padding: 0; }
    .table-stack .cell-note { grid-column: 1 / -1; font-size: .85rem; }
    .table-stack .cell-note:empty { display: none; }
    .table-stack .cell-actions { grid-row: 1; grid-column: 3; }

    .pagination { gap: .5rem; flex-wrap: wrap; }
    .login-card { margin: 1rem auto; }
}

@media (max-width: 380px) {
    .filter { grid-template-columns: 1fr; }
    .stat-value { font-size: 1.25rem; }
}

/* Touch-Geräte: keine hängenbleibenden Hover-Effekte */
@media (hover: none) {
    a:hover { text-decoration: none; }
    .nav a:hover { background: transparent; color: #cfd5e2; }
    .nav a.active:hover { background: rgba(255, 255, 255, .14); color: #fff; }
}

/* ---------- Druck ---------- */
@media print {
    .menu-toggle, .topbar, .footer, .actions-bar, .day-nav, .filter, .filter-box, .item-actions, .form, .btn { display: none !important; }
    body { background: #fff; }
    .card, .stat { box-shadow: none; border-color: #ccc; }
    .grid-2 { grid-template-columns: 1fr; }
}

