/* Raumbuchungssystem - Gestaltung
   Handgeschrieben und ohne externe Abhaengigkeiten, damit die Anwendung im LAN
   auch ohne Internetzugang vollstaendig funktioniert.
   Farben liegen als Custom Properties vor; der Dunkelmodus folgt der
   Systemeinstellung und laesst sich per Schalter uebersteuern. */

:root {
    color-scheme: light dark;

    --bg: #f5f6fa;
    --bg-accent: radial-gradient(1200px 500px at 80% -10%, #e8eaff 0%, transparent 60%);
    --surface: #ffffff;
    --surface-2: #f3f4f9;
    --surface-3: #eaecf4;
    --border: #e1e4ee;
    --border-strong: #c9cfe0;
    --text: #171a25;
    --text-muted: #616a80;
    --text-faint: #8b93a7;

    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: #eef1ff;
    --accent-on: #ffffff;

    --free: #14743a;
    --free-bg: #dcfce7;
    --free-border: #7fd7a0;
    --partial: #9a5b06;
    --partial-bg: #fdf0d5;
    --partial-border: #f0c264;
    --full: #b3261e;
    --full-bg: #fde8e6;
    --full-border: #f2a9a3;
    --off: #5b6273;
    --off-bg: #e8eaf0;
    --off-border: #cdd2df;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 12px 28px -18px rgba(16, 24, 40, .35);
    --shadow-lg: 0 2px 6px rgba(16, 24, 40, .07), 0 24px 48px -24px rgba(16, 24, 40, .4);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Dunkelmodus: Systemeinstellung ... */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f1117;
        --bg-accent: radial-gradient(1200px 500px at 80% -10%, #1c1f3a 0%, transparent 60%);
        --surface: #171a23;
        --surface-2: #1e222d;
        --surface-3: #262b38;
        --border: #2b303d;
        --border-strong: #3b4252;
        --text: #e8eaf2;
        --text-muted: #a2aabd;
        --text-faint: #7d8497;
        --accent: #7c7bf5;
        --accent-hover: #8f8ef7;
        --accent-soft: #23244a;
        --accent-on: #0f1117;
        --free: #6ee7a8;
        --free-bg: #123024;
        --free-border: #1f6b45;
        --partial: #f6c667;
        --partial-bg: #362a12;
        --partial-border: #7a5a1d;
        --full: #f79c94;
        --full-bg: #3a1a17;
        --full-border: #7d322b;
        --off: #9aa3b6;
        --off-bg: #232833;
        --off-border: #363d4d;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 12px 28px -18px rgba(0, 0, 0, .9);
        --shadow-lg: 0 2px 6px rgba(0, 0, 0, .5), 0 24px 48px -24px rgba(0, 0, 0, .95);
    }
}

/* ... und der Schalter, der sie in beide Richtungen uebersteuert. */
:root[data-theme="dark"] {
    --bg: #0f1117;
    --bg-accent: radial-gradient(1200px 500px at 80% -10%, #1c1f3a 0%, transparent 60%);
    --surface: #171a23;
    --surface-2: #1e222d;
    --surface-3: #262b38;
    --border: #2b303d;
    --border-strong: #3b4252;
    --text: #e8eaf2;
    --text-muted: #a2aabd;
    --text-faint: #7d8497;
    --accent: #7c7bf5;
    --accent-hover: #8f8ef7;
    --accent-soft: #23244a;
    --accent-on: #0f1117;
    --free: #6ee7a8;
    --free-bg: #123024;
    --free-border: #1f6b45;
    --partial: #f6c667;
    --partial-bg: #362a12;
    --partial-border: #7a5a1d;
    --full: #f79c94;
    --full-bg: #3a1a17;
    --full-border: #7d322b;
    --off: #9aa3b6;
    --off-bg: #232833;
    --off-border: #363d4d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 12px 28px -18px rgba(0, 0, 0, .9);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, .5), 0 24px 48px -24px rgba(0, 0, 0, .95);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    /* Die Seite selbst scrollt nie waagerecht - breite Inhalte bekommen
       ihren eigenen Scrollbereich. */
    overflow-x: hidden;
}

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background-color: var(--bg);
    background-image: var(--bg-accent);
    background-repeat: no-repeat;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
small { font-size: .82rem; }

/* ---------------------------------------------------------------- Layout */

.shell { max-width: 1240px; margin: 0 auto; padding: 0 1.25rem 4rem; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    backdrop-filter: blur(10px);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: .6rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: .55rem;
    font-weight: 700;
    font-size: 1.02rem;
    color: var(--text);
    letter-spacing: -.02em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 30px; height: 30px;
    border-radius: 9px;
    display: grid; place-items: center;
    background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #22d3ee));
    color: #fff; font-size: .95rem;
}

.nav { display: flex; gap: .2rem; flex-wrap: wrap; align-items: center; }
.nav a {
    color: var(--text-muted);
    padding: .4rem .7rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1 1 auto; }

.user-chip {
    display: flex; align-items: center; gap: .5rem;
    padding: .25rem .35rem .25rem .25rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
}
.avatar {
    width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent);
    font-size: .74rem; font-weight: 700; letter-spacing: .02em;
}

/* ----------------------------------------------------------------- Cards */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.15rem 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-head {
    display: flex; align-items: baseline; gap: .75rem;
    flex-wrap: wrap; margin-bottom: .9rem;
}
.card-head h2, .card-head h3 { margin: 0; }

.hero {
    margin: 1.6rem 0 1.15rem;
    display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
}
.hero h1 { margin: 0; font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.1rem); }
.hero .sub { color: var(--text-muted); margin: .2rem 0 0; }

.grid { display: grid; gap: 1rem; }
.grid-rooms { grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem 1rem;
    box-shadow: var(--shadow-sm);
}
.stat .value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat .label { color: var(--text-muted); font-size: .82rem; }

/* ------------------------------------------------------------ Raumkarten */

.room-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--off-border);
    border-radius: var(--radius);
    padding: .9rem 1rem;
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column; gap: .55rem;
    transition: box-shadow .15s ease, transform .15s ease;
}
.room-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.room-card.is-frei { border-left-color: var(--free-border); }
.room-card.is-teilweise { border-left-color: var(--partial-border); }
.room-card.is-belegt { border-left-color: var(--full-border); }

.room-card .row { display: flex; align-items: baseline; gap: .5rem; justify-content: space-between; }
.room-number { font-weight: 700; font-size: 1.08rem; letter-spacing: -.01em; }
.room-name { color: var(--text-muted); font-size: .88rem; }
.room-meta { color: var(--text-muted); font-size: .85rem; }

.badge {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .16rem .5rem;
    border-radius: 999px;
    font-size: .76rem; font-weight: 600;
    border: 1px solid var(--off-border);
    background: var(--off-bg); color: var(--off);
    white-space: nowrap;
}
.badge.frei { background: var(--free-bg); color: var(--free); border-color: var(--free-border); }
.badge.teilweise { background: var(--partial-bg); color: var(--partial); border-color: var(--partial-border); }
.badge.belegt { background: var(--full-bg); color: var(--full); border-color: var(--full-border); }
.badge.type { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.meter { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--free); }
.meter.teilweise > span { background: var(--partial); }
.meter.belegt > span { background: var(--full); }

/* --------------------------------------------------------------- Buttons */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .5rem .9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: inherit; font-weight: 600; font-size: .9rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--full); border-color: var(--full-border); background: var(--full-bg); }
.btn-danger:hover { background: color-mix(in srgb, var(--full-bg) 75%, var(--full)); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* --------------------------------------------------------------- Formular */

label { font-weight: 600; font-size: .86rem; display: block; margin-bottom: .25rem; }
.hint { color: var(--text-muted); font-size: .82rem; font-weight: 400; margin-top: .25rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], select, textarea {
    width: 100%;
    padding: .5rem .65rem;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible,
a:focus-visible, summary:focus-visible, .hotspot:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }

.field { margin-bottom: .85rem; }
.field-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 150px; margin-bottom: 0; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; font-size: .9rem; }
.check label, label.check { margin: 0; font-weight: 500; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 650; font-size: .9rem; padding: 0 .35rem; }

.weekday-picker { display: flex; gap: .4rem; flex-wrap: wrap; }
.weekday-picker input { position: absolute; opacity: 0; pointer-events: none; }
.weekday-picker label {
    margin: 0; cursor: pointer;
    min-width: 46px; text-align: center;
    padding: .4rem .5rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-weight: 600; font-size: .85rem;
    user-select: none;
}
.weekday-picker input:checked + label {
    background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
}
.weekday-picker input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.weekday-picker input:disabled + label { opacity: .45; cursor: not-allowed; }

/* Filterleiste über Startseite, Grundriss und Raumdetail */
.filterbar {
    display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem 1rem;
    box-shadow: var(--shadow-sm);
}
.filterbar .field { margin: 0; }
.filterbar .field { flex: 0 1 auto; }
.filterbar select, .filterbar input[type="date"] { min-width: 9.5rem; }

/* ------------------------------------------------------------- Meldungen */

.flashes { margin: 1rem 0 0; display: grid; gap: .5rem; }
.flash {
    display: flex; gap: .6rem; align-items: flex-start;
    padding: .7rem .9rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    font-size: .92rem;
}
.flash .icon { font-weight: 700; line-height: 1.4; }
.flash.success { background: var(--free-bg); border-color: var(--free-border); color: var(--free); }
.flash.error { background: var(--full-bg); border-color: var(--full-border); color: var(--full); }
.flash.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent); }

.notice {
    padding: .8rem 1rem;
    border-radius: var(--radius);
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    color: var(--text-muted);
    font-size: .92rem;
}

/* -------------------------------------------------------------- Grundriss */

.plan-wrap {
    /* Eigener Scrollbereich: der Grundriss darf breiter sein als der Bildschirm,
       ohne dass die Seite waagerecht scrollt. */
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    -webkit-overflow-scrolling: touch;
}
.plan {
    position: relative;
    width: 100%;
    min-width: 780px;
    line-height: 0;
}
.plan img { width: 100%; height: auto; display: block; }
.plan svg { position: absolute; inset: 0; width: 100%; height: 100%; }

.hotspot { cursor: pointer; transition: fill-opacity .12s ease; }
.hotspot rect { stroke-width: 2.5; }
.hotspot .fill { fill-opacity: .42; }
.hotspot:hover .fill { fill-opacity: .62; }
.hotspot.frei rect { fill: #22c55e; stroke: #15803d; }
.hotspot.teilweise rect { fill: #f59e0b; stroke: #b45309; }
.hotspot.belegt rect { fill: #ef4444; stroke: #b91c1c; }
.hotspot.gesperrt rect { fill: #94a3b8; stroke: #64748b; }
.hotspot.gesperrt { cursor: default; }
.hotspot.gesperrt .fill { fill-opacity: .3; }
.hotspot text {
    font-family: var(--font);
    font-weight: 700;
    fill: #10161f;
    paint-order: stroke;
    stroke: rgba(255, 255, 255, .85);
    stroke-width: 3px;
    text-anchor: middle;
    pointer-events: none;
}
.hotspot.selected rect { stroke-width: 5; stroke: var(--accent); }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .75rem; font-size: .85rem; color: var(--text-muted); }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend i { width: 13px; height: 13px; border-radius: 4px; display: inline-block; border: 1px solid rgba(0,0,0,.18); }

/* ----------------------------------------------------------- Stundenraster */

.grid-table-wrap { overflow-x: auto; }
.hour-grid { border-collapse: separate; border-spacing: 3px; width: 100%; min-width: 640px; }
.hour-grid th { font-size: .76rem; color: var(--text-muted); font-weight: 600; padding: 0 0 .2rem; }
.hour-grid th.desk-col { text-align: left; min-width: 8.5rem; }
.hour-grid td.desk-col { text-align: left; font-weight: 600; font-size: .88rem; white-space: nowrap; }
.slot {
    height: 34px;
    border-radius: 6px;
    border: 1px solid var(--free-border);
    background: var(--free-bg);
    text-align: center;
    font-size: .7rem;
    color: var(--free);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 .2rem;
}
.slot.taken { background: var(--full-bg); border-color: var(--full-border); color: var(--full); }
.slot.mine { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.slot.closed { background: var(--off-bg); border-color: var(--off-border); color: var(--off); }

/* -------------------------------------------------------------- Tabellen */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 560px; }
table.data th, table.data td { padding: .55rem .6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 700; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .actions { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }

.booking-row { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap;
    padding: .75rem .9rem; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); box-shadow: var(--shadow-sm); }
.booking-row .when { font-weight: 650; min-width: 11rem; }
.booking-row .where { color: var(--text-muted); }
.booking-row .grow { flex: 1 1 auto; }
.stack { display: grid; gap: .6rem; }

/* ------------------------------------------------------------ Login-Seite */

.auth-page {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 2rem 1.25rem;
}
.auth-card {
    width: 100%; max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.9rem 1.75rem;
}
.auth-card .brand { justify-content: center; margin-bottom: 1.25rem; font-size: 1.15rem; }

/* ------------------------------------------------------------- Adminbereich */

.admin-nav { display: flex; gap: .3rem; flex-wrap: wrap; margin: 1rem 0 1.25rem;
    padding: .35rem; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius); }
.admin-nav a { padding: .4rem .75rem; border-radius: var(--radius-sm); color: var(--text-muted);
    font-weight: 600; font-size: .88rem; }
.admin-nav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.admin-nav a.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

.admin-tag {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
    background: var(--accent); color: var(--accent-on);
    padding: .1rem .4rem; border-radius: 4px; font-weight: 700;
}

details.inline > summary { cursor: pointer; font-weight: 600; font-size: .88rem; color: var(--accent); list-style: none; }
details.inline > summary::-webkit-details-marker { display: none; }
details.inline > summary::before { content: "▸ "; }
details.inline[open] > summary::before { content: "▾ "; }
details.inline > div { margin-top: .6rem; padding: .8rem; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: var(--radius); }

.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .85rem; }
.muted { color: var(--text-muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 1rem; }
.mt-lg { margin-top: 1.75rem; }
.mb0 { margin-bottom: 0; }

/* --------------------------------------------------------------- Kleiner */

@media (max-width: 720px) {
    .topbar-inner { padding: .55rem .9rem; gap: .6rem; }
    .shell { padding: 0 .9rem 3rem; }
    /* Navigation als eine scrollbare Zeile statt drei umgebrochener */
    .nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: .2rem; }
    .user-chip .name { display: none; }
    .booking-row .when { min-width: 100%; }

    /* Die Filterleiste wird zum zweispaltigen Raster: Datum und Aktionen über
       die volle Breite, Von/Bis nebeneinander. */
    .filterbar {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .65rem .7rem;
        align-items: end;
    }
    .filterbar > .field { min-width: 0; }
    .filterbar > .field-wide,
    .filterbar > .field-actions { grid-column: 1 / -1; }
    .filterbar > .field-actions > label { display: none; }
    .filterbar > .spacer { display: none; }
    .filterbar .btn-row .btn { flex: 1 1 auto; }
    .filterbar select, .filterbar input[type="date"] { min-width: 0; }
}

@media print {
    .topbar, .filterbar, .btn, .admin-nav { display: none !important; }
    body { background: #fff; }
}
