:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --accent: #2f6f4f;      /* Sophienhof-Grün */
    --accent-dark: #245a40;
    --danger: #b91c1c;
    --radius: 10px;
    --weekend: #f1f3f6;
    --today: #fff7e0;
}

* { box-sizing: border-box; }

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

.topbar {
    display: flex;
    align-items: center;
    gap: 32px;
    background: var(--card);
    padding: 14px 28px;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 30;
}
.brand { font-weight: 700; font-size: 20px; color: var(--accent); }
.brand span { color: var(--muted); font-weight: 500; }
.topbar nav { display: flex; gap: 6px; }
.topbar nav a {
    text-decoration: none;
    color: var(--muted);
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); color: var(--ink); }
.topbar nav a.active { background: var(--accent); color: #fff; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.container { max-width: 1280px; margin: 24px auto; padding: 0 20px; }
.container.wide { max-width: none; margin: 24px 24px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 18px;
}
h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 17px; margin: 0 0 14px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
}
input[type="color"] { padding: 3px; height: 40px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .col { flex: 1 1 160px; }

button {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: #eef0f2; color: var(--ink); }
button.secondary:hover { background: #e2e5e9; }
button.danger { background: var(--danger); }
button.link { background: none; color: var(--accent); padding: 4px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8faf9; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.legend .item { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.legend .swatch { width: 14px; height: 14px; border-radius: 4px; }

.pill { display: inline-block; width: 12px; height: 12px; border-radius: 4px; flex: 0 0 12px; }

/* Modal */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,.5);
    display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: #fff; border-radius: 14px; padding: 24px;
    width: 480px; max-width: calc(100vw - 32px); max-height: 92vh; overflow: auto;
    box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal h2 { margin-bottom: 14px; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 20px; }
.muted { color: var(--muted); font-size: 13px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; display: none; }
.flash.error { background: #fee2e2; color: var(--danger); display: block; }
.flash.ok { background: #dcfce7; color: #166534; display: block; }
.flash.info { background: #e0ecff; color: #1d4ed8; display: block; }

.total-preview {
    padding: 9px 11px; border-radius: 8px; background: #f0f5f2;
    font-weight: 700; color: var(--accent); font-size: 14px; white-space: nowrap;
}
.special-box {
    display: none; margin-top: 8px; padding: 10px 12px; border-radius: 8px;
    background: #fef9c3; border: 1px solid #fde68a; font-size: 13px;
}

/* Autocomplete */
.ac-wrap { position: relative; }
.ac-list {
    display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 60;
    background: #fff; border: 1px solid var(--line); border-radius: 8px;
    box-shadow: 0 10px 24px rgba(0,0,0,.12); max-height: 240px; overflow: auto;
}
.ac-item { padding: 9px 12px; font-size: 14px; cursor: pointer; }
.ac-item:hover { background: #f0f5f2; }

/* Zähler-Badge in der Navigation (offene Anfragen) */
.nav-badge {
    display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 5px;
    background: var(--danger); color: #fff; border-radius: 999px;
    font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
    vertical-align: middle;
}

/* Gäste-Chips (mehrere anwesende Gäste je Buchung) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: #eef2f7; color: #1f2937; border: 1px solid var(--line);
    border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 13px;
}
.chip button {
    background: #dbe2ea; color: #334155; border: none; cursor: pointer;
    width: 20px; height: 20px; border-radius: 50%; padding: 0;
    font-size: 15px; line-height: 1; display: inline-flex;
    align-items: center; justify-content: center;
}
.chip button:hover { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------------------
   Belegungsplan (Zeitleiste)
--------------------------------------------------------------------------- */
.tl-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.tl-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tl-controls input[type="date"] { width: 150px; padding: 8px 10px; }
.tl-controls select { width: auto; padding: 8px 10px; }

.tl-scroll { overflow: auto; max-height: calc(100vh - 200px); border-radius: var(--radius); }

.tl-months, .tl-days, .tl-row, .tl-free { display: flex; position: relative; }

.tl-sticky-left {
    position: sticky; left: 0; z-index: 5;
    background: var(--card);
    border-right: 2px solid var(--line);
}

.tl-months { position: sticky; top: 0; z-index: 10; background: var(--card); }
.tl-months .tl-corner { width: var(--labelw, 190px); flex: 0 0 var(--labelw, 190px); }
.tl-month {
    flex: 0 0 auto; padding: 8px 0 2px; text-align: center;
    font-size: 12px; font-weight: 700; color: var(--accent);
    border-left: 1px solid var(--line); white-space: nowrap; overflow: hidden;
}

.tl-days { position: sticky; top: 27px; z-index: 10; background: var(--card); border-bottom: 2px solid var(--line); }
.tl-days .tl-corner {
    width: var(--labelw, 190px); flex: 0 0 var(--labelw, 190px); display: flex; align-items: flex-end;
    padding: 4px 12px 6px; font-size: 11px; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: .04em; z-index: 11;
}
.tl-day {
    width: var(--cellw, 38px); flex: 0 0 var(--cellw, 38px); text-align: center; padding: 3px 0 5px;
    border-left: 1px solid var(--line); font-size: 11px;
}
.tl-day .wd { display: block; color: var(--muted); font-size: 10px; }
.tl-day .dn { display: block; font-weight: 700; font-size: 13px; }
.tl-day.weekend { background: var(--weekend); }
.tl-day.today { background: var(--today); box-shadow: inset 0 -3px 0 var(--accent); }

.tl-row { height: var(--rowh, 46px); border-bottom: 1px solid var(--line); }
.tl-row:nth-child(even) { background: #fbfcfd; }
.tl-roomlabel {
    width: var(--labelw, 190px); flex: 0 0 var(--labelw, 190px); display: flex; align-items: center; gap: 8px;
    padding: 0 12px; font-size: 13px; font-weight: 600;
}
.tl-roomlabel .rn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-cell {
    width: var(--cellw, 38px); flex: 0 0 var(--cellw, 38px); border-left: 1px solid var(--line);
    cursor: pointer;
}
.tl-cell:hover { background: rgba(47,111,79,.10); }
.tl-cell.weekend { background: var(--weekend); }
.tl-cell.weekend:hover { background: rgba(47,111,79,.12); }
.tl-cell.today { background: var(--today); }

.tl-bar {
    position: absolute;
    top: calc((var(--rowh, 46px) - var(--barh, 32px)) / 2);
    height: var(--barh, 32px);
    border-radius: calc(var(--barh, 32px) / 2);
    color: #fff; font-size: var(--barfs, 12px); font-weight: 600;
    display: flex; align-items: center; gap: 4px; padding: 0 10px;
    overflow: hidden; white-space: nowrap; cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,.25), inset 0 0 0 1px rgba(255,255,255,.25);
    z-index: 2;
}
.tl-bar span { overflow: hidden; text-overflow: ellipsis; }
.tl-bar:hover { filter: brightness(1.1); box-shadow: 0 4px 10px rgba(0,0,0,.35); z-index: 3; }
.tl-bar.cut-l { border-top-left-radius: 3px; border-bottom-left-radius: 3px; }
.tl-bar.cut-r { border-top-right-radius: 3px; border-bottom-right-radius: 3px; }
.tl-bar.ical {
    background-image: repeating-linear-gradient(45deg,
        rgba(255,255,255,.30) 0 6px, transparent 6px 12px);
}
.tl-noroom { background: #fef2f2 !important; }
.tl-noroom .tl-roomlabel { color: var(--danger); }

/* Blocker (Sperrzeiten) */
.tl-block {
    position: absolute;
    top: calc((var(--rowh, 46px) - var(--barh, 32px)) / 2);
    height: var(--barh, 32px);
    border-radius: 8px;
    color: #fff; font-size: var(--barfs, 12px); font-weight: 600;
    display: flex; align-items: center; padding: 0 10px;
    overflow: hidden; white-space: nowrap; cursor: pointer; z-index: 2;
    background-color: #64748b;
    background-image: repeating-linear-gradient(45deg,
        rgba(0,0,0,.22) 0 7px, transparent 7px 14px);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.tl-block span { overflow: hidden; text-overflow: ellipsis; }
.tl-block:hover { filter: brightness(1.08); }
.bar-info { flex: 0 0 auto; font-size: 11px; opacity: .9; }

.tl-free { border-top: 2px solid var(--line); background: var(--card); position: sticky; bottom: 0; z-index: 8; }
.tl-free .tl-roomlabel { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tl-freecell {
    width: var(--cellw, 38px); flex: 0 0 var(--cellw, 38px); text-align: center; padding: 7px 0;
    font-size: 12px; font-weight: 700; color: #15803d;
    border-left: 1px solid var(--line);
}
.tl-freecell.low { color: #b45309; }
.tl-freecell.none { color: var(--danger); background: #fee2e2; }
.tl-freecell.today { box-shadow: inset 0 3px 0 var(--accent); }

/* Zoom-Regler */
.zoom-ctrl { display: flex; align-items: center; gap: 6px; }
.zoom-ctrl input[type="range"] { width: 110px; padding: 0; }

/* Lexware-Office-Bereich im Buchungsdialog */
.lex-section {
    margin-top: 16px; padding: 12px 14px; border-radius: 8px;
    background: #f0f5f2; border: 1px solid #d7e5dd;
}
.lex-head { font-size: 12px; font-weight: 700; color: var(--accent);
    text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 700; }
.badge.ok { background: #dcfce7; color: #166534; }

/* Statistik-Kacheln */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 18px; margin-bottom: 18px; }
.stat-tile { text-align: center; margin-bottom: 0; }
.stat-num { font-size: 28px; font-weight: 800; color: var(--accent); }
.stat-cap { font-size: 12px; color: var(--muted); text-transform: uppercase;
    letter-spacing: .05em; margin-top: 4px; }

/* ---------------------------------------------------------------------------
   Mobil / iPhone (schmale Bildschirme)
--------------------------------------------------------------------------- */
@media (max-width: 720px) {
    /* Kopfleiste: Logo + Nutzer oben, Navigation als scrollbare Leiste darunter */
    .topbar { flex-wrap: wrap; gap: 8px 14px; padding: 10px 14px; position: static; }
    .brand { font-size: 18px; }
    .topbar-user { margin-left: auto; }
    .topbar nav {
        order: 3; width: 100%; overflow-x: auto; gap: 4px;
        -webkit-overflow-scrolling: touch; padding-bottom: 2px;
    }
    .topbar nav a { padding: 7px 12px; white-space: nowrap; }

    .container, .container.wide { margin: 14px 0; padding: 0 12px; }
    .card { padding: 16px; margin-bottom: 14px; }
    h1 { font-size: 19px; }
    h2 { font-size: 16px; }

    /* Formularzeilen untereinander statt nebeneinander */
    .row { flex-direction: column; gap: 10px; }
    .row > .col { flex: 1 1 auto !important; width: 100%; }

    /* Eingabefelder mind. 16px -> iPhone zoomt beim Antippen nicht rein */
    input, select, textarea { font-size: 16px; }

    /* Dialoge nutzen die volle Breite */
    .modal { width: 100% !important; padding: 18px; }
    .modal-actions { flex-wrap: wrap; gap: 8px; }
    .modal-actions button { flex: 1 1 auto; }

    /* Breite Tabellen seitlich scrollbar machen */
    .card > table { display: block; overflow-x: auto; white-space: nowrap; }

    /* Statistik-Kacheln zweispaltig */
    .stat-tiles { grid-template-columns: 1fr 1fr; gap: 12px; }
    .stat-num { font-size: 22px; }

    /* Belegungsplan-Werkzeugleiste kompakter; Suche volle Breite */
    .tl-toolbar { gap: 10px; }
    .tl-toolbar .ac-wrap { max-width: none !important; flex: 1 1 100% !important; }
    .tl-controls { gap: 6px; }
    .tl-controls button, .tl-controls select, .tl-controls input[type="date"] { font-size: 13px; padding: 8px 10px; }
    .zoom-ctrl input[type="range"] { width: 76px; }
    .tl-scroll { max-height: calc(100vh - 260px); }

    /* Schmale Zimmer-Spalte: Name umbricht (2 Zeilen) statt abgeschnitten */
    .tl-roomlabel { padding: 0 6px; gap: 5px; font-size: 11px; line-height: 1.15; }
    .tl-roomlabel .rn {
        white-space: normal; overflow: hidden;
        display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    }
    .tl-roomlabel .pill { width: 9px; height: 9px; flex: 0 0 9px; }
    .tl-days .tl-corner { padding: 4px 6px 6px; font-size: 10px; }
    .tl-free .tl-roomlabel { font-size: 10px; }
}
