:root {
    --bg: #eef1f6;
    --header-bg: #131a2e;
    --header-bg-2: #1f2748;
    --card-bg: #ffffff;
    --text: #1c2233;
    --muted: #8890a0;
    --muted-light: #aab1c4;
    --border: #e8eaf0;

    --blue: #3b6bf5;
    --blue-bg: #e8eeff;
    --orange: #e8632f;
    --orange-bg: #fdece0;
    --yellow: #b9860a;
    --yellow-bg: #fdf6db;
    --green: #2e9e6b;
    --purple: #7c5cf0;

    --radius-lg: 20px;
    --radius: 16px;
    --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: 88px;
    position: relative;
}
/* Handy-Rahmen-Optik nur auf breiteren Bildschirmen (Desktop/Tablet-Vorschau) -
   auf echten Handy-Viewports (auch breiteren) soll die App randlos sein. */
@media (min-width: 500px) {
    body { max-width: 480px; }
}

/* Eigenes Pull-to-Refresh (assets/app.js) statt des nativen Browser-Gestus */
#pull-refresh-indicator {
    position: fixed;
    top: -50px; left: 0; right: 0;
    height: 50px;
    display: flex; align-items: center; justify-content: center;
    background: var(--header-bg);
    color: #fff;
    font-size: 12.5px;
    font-weight: 600;
    z-index: 60;
    transition: transform 0.2s ease-out;
    pointer-events: none;
}
#pull-refresh-indicator.dragging { transition: none; }

a { color: var(--blue); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ---------- Header ---------- */
.app-header {
    background: var(--header-bg);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    padding: 18px 18px 16px;
    color: #fff;
}
.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.header-kicker {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted-light);
    margin: 0 0 2px;
}
.header-title {
    font-size: 21px;
    font-weight: 700;
    margin: 0;
}
.header-settings {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.date-nav {
    background: var(--header-bg-2);
    border-radius: 14px;
    padding: 10px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}
.date-nav-arrow {
    color: #fff;
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-size: 22px;
    flex-shrink: 0;
}
.date-nav-arrow:hover, .date-nav-arrow:active { background: rgba(255,255,255,0.12); }
.date-nav-center { text-align: center; flex: 1; cursor: pointer; }
.date-nav-title { color: #fff; font-weight: 600; font-size: 24.5px; }
.header-date-input-hidden {
    position: absolute;
    left: 50%; top: 50%;
    width: 1px; height: 1px;
    opacity: 0;
    border: 0; padding: 0;
    pointer-events: none;
}

/* ---------- Content ---------- */
main { padding: 16px; }

.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 18px;
}
.stat-card {
    border-radius: var(--radius);
    padding: 12px 14px;
    background: var(--card-bg);
    border: 1px solid var(--border);
}
.stat-card.active { background: var(--orange-bg); border-color: transparent; }
.stat-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 0 0 4px;
}
.stat-card.active .stat-label { color: var(--orange); }
.stat-value { font-size: 21px; font-weight: 700; margin: 0 0 2px; }
.stat-sub { font-size: 11.5px; color: var(--muted); }

.section-title-row {
    display: flex; align-items: center; justify-content: space-between;
    margin: 4px 0 10px;
}
.section-title { font-weight: 700; font-size: 15px; }
.section-link { font-size: 13px; color: var(--blue); font-weight: 600; background: none; border: none; padding: 0; }

.room-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    margin-bottom: 14px;
}
.room-chip {
    display: flex; align-items: center; gap: 6px;
    background: var(--header-bg);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    opacity: 1;
    transition: opacity .15s;
}
.room-chip.inactive { opacity: 0.35; }
.room-chip .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.segmented {
    display: flex;
    background: #e3e6ee;
    border-radius: 12px;
    padding: 3px;
    margin-bottom: 16px;
}
.segmented button {
    flex: 1;
    border: none;
    background: transparent;
    padding: 9px 0;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--muted);
}
.segmented button.active {
    background: #fff;
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.segmented a {
    flex: 1;
    text-align: center;
    text-decoration: none;
    padding: 9px 0;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--muted);
}
.segmented a.active {
    background: #fff;
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ---------- Zeitstrahl (Räume-Seite) ---------- */
.timeline-row { margin-bottom: 18px; }
.timeline-row-label {
    display: flex; align-items: center; gap: 6px;
    font-weight: 700; font-size: 13px; margin-bottom: 6px;
}
.timeline-row-label .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.timeline-track {
    position: relative;
    height: 30px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.timeline-hour-labels {
    display: flex; justify-content: space-between;
    font-size: 10px; color: var(--muted);
    margin-bottom: 3px;
}
.timeline-segment {
    position: absolute;
    top: 3px; bottom: 3px;
    border-radius: 5px;
    cursor: pointer;
}
.timeline-segment.orange { background: #f5a23c; }
.timeline-segment.red { background: #e8632f; }
.timeline-segment.pending {
    background: transparent;
    border: 2px dashed #f5a23c;
}
.timeline-segment.pending.red { border-color: #e8632f; }
.timeline-now-line {
    position: absolute;
    top: 0; bottom: 0;
    width: 2px;
    background: var(--blue);
}
.timeline-week-grid {
    display: flex;
    gap: 4px;
    position: relative;
}
.timeline-week-cell {
    flex: 1;
    height: 30px;
    border-radius: 6px;
    background: #eceef3;
    cursor: pointer;
}
.timeline-week-cell.occupied { background: #9aa1b0; }
.timeline-week-cell.pending {
    background: transparent;
    border: 2px dashed #9aa1b0;
}
.timeline-week-day-labels {
    display: flex; gap: 4px;
    font-size: 10.5px; color: var(--muted);
    margin-bottom: 4px;
}
.timeline-week-day-labels span { flex: 1; text-align: center; }
.timeline-legend {
    display: flex; gap: 16px;
    font-size: 11.5px; color: var(--muted);
    margin-bottom: 16px;
}
.timeline-legend span { display: flex; align-items: center; gap: 5px; }
.timeline-legend .swatch { width: 10px; height: 10px; border-radius: 3px; }
.timeline-legend .swatch-dashed { background: transparent; border: 2px dashed #9aa1b0; }

/* Period list (Heizperioden) */
.period-item {
    display: flex;
    gap: 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
}
.period-time {
    display: flex; flex-direction: column; align-items: center;
    width: 46px; flex-shrink: 0;
    position: relative;
}
.period-time .t1 { font-weight: 700; font-size: 12.5px; }
.period-time .t2 { color: var(--muted); font-size: 11.5px; margin-top: auto; }
.period-time .bar { width: 3px; flex: 1; border-radius: 2px; margin: 4px 0; min-height: 18px; }
.period-body { flex: 1; min-width: 0; }
.period-room { font-weight: 700; font-size: 14px; }
.period-sub { color: var(--muted); font-size: 12.5px; margin: 1px 0 6px; }
.period-pill {
    display: inline-block;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.03em;
    padding: 3px 8px;
    border-radius: 999px;
    margin-right: 6px;
    vertical-align: middle;
}
.period-pill.now { background: var(--orange-bg); color: var(--orange); }
.period-pill.upcoming { background: var(--blue-bg); color: var(--blue); }
.period-meta { font-size: 11.5px; color: var(--muted); vertical-align: middle; }
.period-temp { font-weight: 700; font-size: 15px; flex-shrink: 0; align-self: flex-start; }

/* "Sonstige Termine": Sicherheitsnetz für (noch) nicht zugeordnete ChurchTools-Termine */
.section-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 22px 0 12px;
}
.section-divider::before,
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.section-divider-title {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}
.period-item.dashed-card {
    border-style: dashed;
    border-color: #9aa1b0;
    background: transparent;
}

/* Room list (Raumstatus) */
.room-item {
    display: flex; align-items: center; gap: 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
}
.room-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 11px;
    flex-shrink: 0;
}
.room-item-body { flex: 1; min-width: 0; }
.room-item-title { font-weight: 700; font-size: 14px; }
.room-item-sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.room-chevron { color: var(--muted); font-size: 18px; }

.empty-hint {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    padding: 24px 12px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    width: 100%;
    max-width: 480px;
    background: #fff;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
}
.nav-item {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    background: none; border: none;
}
.nav-item.active { color: var(--header-bg); }
.nav-item .icon { font-size: 19px; }
.nav-add {
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 12px 18px;
    font-weight: 700;
    font-size: 13.5px;
    display: flex; align-items: center; gap: 6px;
    flex-shrink: 0;
}

/* ---------- Modal / bottom sheet ---------- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(10,14,26,0.5);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 50;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
    background: #fff;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 22px 22px 0 0;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
    position: relative;
}
.modal-close {
    position: absolute;
    top: 18px; right: 18px;
    width: 32px; height: 32px;
    border-radius: 50%;
    background: #f0f1f5;
    border: none;
    font-size: 15px;
    color: var(--text);
}
.modal-kicker {
    font-size: 11px;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 0 0 2px;
}
.modal-title { font-size: 19px; font-weight: 700; margin: 0 0 16px; }

.modal-section-kicker {
    font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
    text-transform: uppercase; color: var(--muted); margin: 0 0 8px;
}
.simple-row {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13.5px;
    margin-bottom: 8px;
}
.simple-row .time { font-weight: 700; margin-right: 6px; }
.simple-row .title { color: var(--muted); }

.toggle-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 4px 4px;
    margin-top: 8px;
    border-top: 1px solid var(--border);
}
.toggle-row .label { font-weight: 600; font-size: 14px; }
.toggle-btn {
    border: none;
    border-radius: 999px;
    padding: 7px 16px;
    font-weight: 700;
    font-size: 12.5px;
    background: #eceef3;
    color: var(--muted);
}
.toggle-btn.on { background: var(--orange); color: #fff; }

/* Solltemperatur-Regler im Raumdetail (angelehnt an die Tuya-App) */
.temp-adjust-card {
    background: linear-gradient(160deg, #f4a53f, #e8632f);
    border-radius: var(--radius);
    padding: 22px 18px 18px;
    text-align: center;
    color: #fff;
    margin-bottom: 18px;
}
.temp-adjust-pill {
    display: inline-block;
    background: rgba(255,255,255,0.25);
    color: #fff;
    font-weight: 700;
    font-size: 11.5px;
    letter-spacing: 0.03em;
    padding: 6px 14px;
    border-radius: 999px;
    margin-bottom: 14px;
    border: none;
}
.temp-adjust-value { font-size: 44px; font-weight: 800; line-height: 1; }
.temp-adjust-value sup { font-size: 18px; font-weight: 700; margin-left: 2px; }
.temp-adjust-current { font-size: 12.5px; opacity: 0.9; margin-top: 6px; }
.temp-adjust-controls {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 20px;
}
.temp-adjust-btn {
    width: 46px; height: 46px;
    border-radius: 50%;
    background: rgba(255,255,255,0.22);
    border: none;
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.temp-adjust-btn:active { background: rgba(255,255,255,0.38); }

/* Form elements (Termin-Modal, Räume, Einstellungen) */
.field { margin-bottom: 16px; }
.field-label {
    display: block;
    font-size: 11px; font-weight: 700; letter-spacing: 0.05em;
    text-transform: uppercase; color: var(--muted);
    margin-bottom: 7px;
}
.field input[type=text], .field input[type=time], .field input[type=date], .field input[type=number] {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 12px;
    font-size: 14px;
    background: #fbfbfd;
}
.field input:disabled { background: #eceef3; color: var(--muted); }
.room-select-grid.locked .room-select-btn { pointer-events: none; opacity: 0.75; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.room-select-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.room-select-btn {
    display: flex; align-items: center; gap: 8px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: #fff;
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text);
}
.room-select-btn .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.room-select-btn.selected { border-color: var(--blue); background: var(--blue-bg); }
.room-select-btn .check { margin-left: auto; color: var(--blue); font-weight: 700; visibility: hidden; }
.room-select-btn.selected .check { visibility: visible; }

.stepper-row {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 0;
}
.stepper-icon {
    width: 34px; height: 34px; border-radius: 50%;
    background: #f0f1f5;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stepper-body { flex: 1; }
.stepper-label { font-size: 13px; color: var(--muted); }
.stepper-value { font-size: 16px; font-weight: 700; }
.stepper-btn {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: #fff;
    font-weight: 700;
    font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stepper-btn.filled { background: #1c2233; border-color: #1c2233; color: #fff; }

.callout {
    display: flex; gap: 10px;
    border-radius: var(--radius);
    padding: 12px 14px;
    margin: 6px 0 18px;
}
.callout.peach { background: var(--orange-bg); }
.callout.yellow { background: var(--yellow-bg); }
.callout .icon { font-size: 18px; flex-shrink: 0; }
.callout .title { font-weight: 700; font-size: 13.5px; margin: 0 0 2px; }
.callout.peach .title { color: var(--orange); }
.callout .text { font-size: 12.5px; color: var(--muted); margin: 0; }

.btn-primary {
    width: 100%;
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px;
    font-weight: 700;
    font-size: 14.5px;
    display: flex; align-items: center; justify-content: center; gap: 6px;
}

/* Rooms / settings pages */
.back-link { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 14px; margin-bottom: 14px; }
.page-title { font-size: 21px; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 18px; }
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card-title { font-weight: 700; font-size: 14.5px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }

/* install_prompt.php ("Als App installieren") */
.install-steps { margin: 0 0 4px; padding-left: 20px; font-size: 14px; line-height: 1.7; }
.install-steps li { margin-bottom: 2px; }

/* stats.php (Admin-Nutzungsstatistik) */
.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; padding: 4px 6px 6px; border-bottom: 1px solid var(--border); }
.stats-table td { padding: 6px; border-bottom: 1px solid var(--border); }
.stats-table tr:last-child td { border-bottom: none; }
.color-swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); flex-shrink: 0; }
.color-options { display: flex; gap: 8px; margin-top: 8px; }
.color-options button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; }
.color-options button.selected { border-color: var(--text); }
.btn-secondary {
    background: var(--header-bg); color: #fff; border: none;
    border-radius: var(--radius-sm); padding: 9px 14px;
    font-weight: 600; font-size: 13px;
}
.small-muted { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.delete-link { color: var(--orange); font-size: 12.5px; font-weight: 600; background: none; border: none; padding: 0; }

/* Login page */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: var(--header-bg);
    max-width: none;
}
.login-box {
    background: #fff;
    padding: 28px 24px;
    border-radius: var(--radius-lg);
    display: flex; flex-direction: column; gap: 12px;
    width: 100%; max-width: 320px;
    margin: 16px;
}
.login-box h1 { font-size: 19px; margin: 0 0 4px; }
.login-box input { padding: 11px 12px; font-size: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.login-box .error { color: var(--orange); font-size: 13px; }
.login-box button { background: var(--blue); color: #fff; border: none; border-radius: var(--radius-sm); padding: 12px; font-weight: 700; }

/* ---------- ChurchTools: Badges, Bestätigen/Ablehnen, dezenter Sync-Link ---------- */
.source-badge {
    display: inline-block;
    font-size: 10px; font-weight: 700;
    color: var(--muted);
    background: #eceef3;
    border-radius: 999px;
    padding: 2px 7px;
    margin-left: 4px;
    vertical-align: middle;
}
.status-badge {
    display: inline-block;
    font-size: 10.5px; font-weight: 700;
    border-radius: 999px;
    padding: 3px 9px;
}
.status-badge.pending { background: var(--yellow-bg); color: var(--yellow); }
.status-badge.rejected { background: #eceef3; color: var(--muted); }
.period-item.is-rejected { opacity: 0.55; }

.pending-row { margin-top: 8px; }
.pending-actions { display: flex; gap: 8px; margin-top: 8px; }
.pending-actions .btn-secondary { padding: 7px 12px; font-size: 12.5px; }
.pending-actions .reject-heating {
    background: #eceef3; color: var(--muted); border: none;
    border-radius: var(--radius-sm); padding: 7px 12px; font-weight: 600; font-size: 12.5px;
}
.suggestion-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--blue-bg);
    color: var(--blue);
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    margin-top: 8px;
    line-height: 1.4;
}

