/* ============================================================
   Livestream-Steuerung – Design-System
   Hell/Dunkel folgt automatisch der Geräteeinstellung.
   ============================================================ */

:root {
    --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;

    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px -4px rgba(15, 23, 42, .10);
    --shadow-lift: 0 2px 4px rgba(15, 23, 42, .06), 0 12px 28px -8px rgba(15, 23, 42, .18);

    /* Bereichsfarben */
    --blue: #2563eb;   --blue-tint: #dbeafe;   --blue-glow: rgba(37, 99, 235, .35);
    --green: #16a34a;  --green-tint: #dcfce7;  --green-glow: rgba(22, 163, 74, .35);
    --amber: #d97706;  --amber-tint: #fef3c7;  --amber-glow: rgba(217, 119, 6, .35);
    --red: #dc2626;    --red-tint: #fee2e2;    --red-glow: rgba(220, 38, 38, .40);

    /* vollflächige Zustände, in beiden Modi gleich (guter Kontrast zu weißer Schrift) */
    --green-solid: #15803d;
    --red-solid: #dc2626;

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

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b0e14;
        --surface: #151a23;
        --surface-2: #1b212c;
        --text: #f1f5f9;
        --muted: #94a3b8;
        --border: #263041;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px -4px rgba(0, 0, 0, .5);
        --shadow-lift: 0 2px 4px rgba(0, 0, 0, .4), 0 12px 28px -8px rgba(0, 0, 0, .7);

        --blue: #3b82f6;   --blue-tint: rgba(59, 130, 246, .16);
        --green: #22c55e;  --green-tint: rgba(34, 197, 94, .16);
        --amber: #f59e0b;  --amber-tint: rgba(245, 158, 11, .16);
        --red: #ef4444;    --red-tint: rgba(239, 68, 68, .16);

        color-scheme: dark;
    }
}

/* ---------- Grundlayout ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0 16px calc(32px + env(safe-area-inset-bottom, 0px));
    background: var(--bg);
    color: var(--text);
    font: 400 18px/1.45 var(--font);
    text-align: left;
}

.page {
    max-width: 960px;
    margin: 0 auto;
}

br { display: none; }

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 600; }

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

.section-title {
    margin: 28px 4px 12px;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}

.muted { color: var(--muted); }
.hidden { display: none !important; }

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 -16px 8px;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.topbar__title { flex: 1; min-width: 0; }
.topbar__title h1 { font-size: 1.25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__title .muted { font-size: .85rem; }

.clock {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 1rem;
    color: var(--muted);
    white-space: nowrap;
}

.topbar__links { display: flex; gap: 8px; flex-wrap: wrap; }

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

button,
.btn,
input[type="submit"] {
    --btn-bg: var(--blue);
    --btn-fg: #ffffff;
    --btn-glow: var(--blue-glow);

    -webkit-appearance: none;
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    width: 100%;
    max-width: 640px;
    min-height: 64px;
    margin: 0 auto 12px;
    padding: 14px 22px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--btn-bg);
    color: var(--btn-fg);
    font: 650 1.1rem/1.2 var(--font);
    letter-spacing: .01em;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 6px 16px -6px var(--btn-glow);
    transition: transform .12s ease, box-shadow .2s ease, filter .2s ease, background-color .2s ease, border-color .2s ease;
}

button:hover, .btn:hover, input[type="submit"]:hover { filter: brightness(1.07); }
button:active, .btn:active, input[type="submit"]:active { transform: scale(.98); filter: brightness(.96); }
button:focus-visible, .btn:focus-visible, input[type="submit"]:focus-visible,
.tile:focus-visible {
    outline: 3px solid var(--btn-glow, var(--blue-glow));
    outline-offset: 3px;
}
button:disabled { opacity: .5; cursor: not-allowed; }

.btn svg, button svg { width: 1.3em; height: 1.3em; flex: none; }

/* Varianten (button2-4 bleiben für alte Templates erhalten) */
.btn-success, .button2 { --btn-bg: var(--green); --btn-glow: var(--green-glow); }
.btn-warning, .button3 { --btn-bg: var(--amber); --btn-glow: var(--amber-glow); }
.btn-danger,  .button4 { --btn-bg: var(--red);   --btn-glow: var(--red-glow); }

.btn-ghost {
    --btn-bg: var(--surface);
    --btn-fg: var(--text);
    border-color: var(--border);
    box-shadow: none;
}

.btn-sm {
    width: auto;
    min-height: 40px;
    margin: 0;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: .9rem;
}

.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.btn-row > * { flex: 1 1 220px; margin: 0; }

/* ---------- Kacheln (Startseite) ---------- */

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
    gap: 12px;
}

.tile {
    --accent: var(--blue);
    --accent-tint: var(--blue-tint);

    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 88px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    box-shadow: var(--shadow);
    -webkit-tap-highlight-color: transparent;
    transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease;
}

.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-color: var(--accent); }
.tile:active { transform: scale(.985); }

.tile__icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: var(--accent-tint);
    color: var(--accent);
}
.tile__icon svg { width: 26px; height: 26px; }

.tile__text { flex: 1; min-width: 0; }
.tile__label { display: block; font-weight: 650; font-size: 1.05rem; }
.tile__sub { display: block; font-size: .875rem; color: var(--muted); }

.tile__chevron { flex: none; width: 20px; height: 20px; color: var(--muted); }

.tile--green { --accent: var(--green); --accent-tint: var(--green-tint); }
.tile--amber { --accent: var(--amber); --accent-tint: var(--amber-tint); }
.tile--red   { --accent: var(--red);   --accent-tint: var(--red-tint); }

/* ---------- Karten / YouTube-Info ---------- */

.card, .info-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin: 0 0 12px;
    color: var(--text);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: 12px;
}
.card-grid > * { margin: 0; }

.info-box { border-left: 6px solid var(--border); transition: border-color .3s, background-color .3s; }
.info-box.is-live    { border-left-color: var(--red);   background: var(--red-tint); }
.info-box.is-testing { border-left-color: var(--green); background: var(--green-tint); }
.info-box.is-ready   { border-left-color: var(--blue); }

.event__church { font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.event__title  { margin: 4px 0 10px; font-size: 1.15rem; font-weight: 650; }
.event__meta   { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: .9rem; color: var(--muted); }
.event__empty  { margin-top: 4px; color: var(--muted); }
.event__link   { font-weight: 600; text-decoration: none; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.badge--live    { background: var(--red);   border-color: var(--red);   color: #fff; }
.badge--testing { background: var(--green); border-color: var(--green); color: #fff; }
.badge--live::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #fff;
    animation: pulse 1.4s ease-in-out infinite;
}

/* ---------- Statusanzeigen (LEDs) ---------- */

.status-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px 8px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: .95rem;
    font-weight: 600;
    box-shadow: var(--shadow);
}

.led, .ping {
    flex: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 4px var(--green-tint);
}
.led.on {
    background: var(--red);
    box-shadow: 0 0 0 4px var(--red-tint), 0 0 12px var(--red);
    animation: pulse 1.4s ease-in-out infinite;
}

/* Zustand unbekannt (z. B. Kamera nicht erreichbar): grau */
.led.led-unknown { background: var(--border); box-shadow: 0 0 0 4px var(--surface-2); animation: none; }

/* Ambo-Mikro: Pegelanzeige -60 … 0 dB (grün bis -18, gelb bis -6, dann rot) */
.meter {
    position: relative;
    flex: none;
    width: 140px;
    height: 12px;
    border-radius: 999px;
    background: var(--surface-2);
    box-shadow: inset 0 0 0 1px var(--border);
    overflow: hidden;
}
.meter__bar {
    position: absolute; inset: 0 auto 0 0;
    width: 0;
    background: linear-gradient(90deg, var(--green) 0 70%, var(--amber) 70% 90%, var(--red) 90%);
    background-size: 140px 100%;
    opacity: .55;
    transition: width .1s linear;
}
.meter.on .meter__bar { opacity: 1; }
.meter__peak, .meter__mark { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; }
.meter__peak { left: 0; background: var(--text); opacity: 0; transition: left .1s linear; }
.meter__mark { left: 33.3%; background: var(--muted); opacity: .7; }
.meter.is-offline { opacity: .4; }
.meter + span { font-variant-numeric: tabular-nums; }

/* alte Struktur (LED direkt im Container) */
.led-container, .led-container2 { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; margin: 12px 0; }

/* ---------- Kamera-Presets ---------- */

#button-container,
.preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
    gap: 10px;
    margin: 8px 0 16px;
}

#button-container > button,
.preset-grid > button {
    --btn-bg: var(--surface);
    --btn-fg: var(--text);
    --btn-glow: var(--blue-glow);

    position: relative;
    max-width: none;
    min-height: 88px;
    margin: 0;
    padding: 22px 12px 18px;
    border: 2px solid var(--border);
    font-size: 1rem;
    letter-spacing: .02em;
    box-shadow: var(--shadow);
}

#button-container > button:hover,
.preset-grid > button:hover { filter: none; border-color: var(--blue); }

/* Angewählt: gedrückt, Kamera fährt das Preset an (grün) */
#button-container > button.pressed,
.preset-grid > button.pressed {
    --btn-bg: var(--green-solid);
    --btn-fg: #fff;
    --btn-glow: var(--green-glow);
    border-color: var(--green-solid);
    color: #fff;
    animation: pending-green 1.1s ease-in-out infinite;
}

/* Aktiv: Kamera steht auf diesem Preset (rot) */
#button-container > button.active,
.preset-grid > button.active {
    --btn-bg: var(--red-solid);
    --btn-fg: #fff;
    --btn-glow: var(--red-glow);
    z-index: 1;
    border-color: #fff;
    color: #fff;
    transform: scale(1.04);
    box-shadow: 0 0 0 3px var(--red-solid), 0 0 0 7px var(--red-tint), 0 10px 28px -6px var(--red-glow);
    animation: none;
}

/* Hinweis-Badge oben im Button */
#button-container > button.pressed::before,
.preset-grid > button.pressed::before,
#button-container > button.active::before,
.preset-grid > button.active::before {
    position: absolute;
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .22);
    font-size: .62rem;
    font-weight: 800;
    letter-spacing: .1em;
    white-space: nowrap;
}
#button-container > button.pressed::before,
.preset-grid > button.pressed::before { content: "FÄHRT AN …"; }
#button-container > button.active::before,
.preset-grid > button.active::before { content: "● AKTIV"; background: rgba(255, 255, 255, .28); }

/* Legende unter den Presets */
.preset-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 18px;
    margin: 4px 0 8px;
    font-size: .85rem;
    color: var(--muted);
}
.preset-legend span { display: inline-flex; align-items: center; gap: 6px; }
.preset-legend i { width: 14px; height: 14px; border-radius: 4px; }
.preset-legend .is-pressed { background: var(--green-solid); }
.preset-legend .is-active  { background: var(--red-solid); }

/* ---------- Mixer ---------- */

.channel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px 20px;
    margin: 0 0 12px;
}

.channel__head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 14px;
}
.channel__head label { margin: 0; font-size: 1rem; font-weight: 650; color: var(--text); }

.db-value {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--amber);
    white-space: nowrap;
}
.db-value::after { content: " dB"; font-weight: 500; color: var(--muted); }

button.muted {
    --btn-bg: var(--red);
    --btn-glow: var(--red-glow);
}
button.is-pending { animation: pending 1.2s ease-in-out infinite; }

details.debug { margin-top: 20px; color: var(--muted); font-size: .85rem; }
details.debug summary { cursor: pointer; }

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    width: 100%;
    height: 10px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--border);
    outline: none;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fff;
    border: 4px solid var(--amber);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
    transition: transform .15s ease;
}
input[type="range"]::-moz-range-thumb {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #fff;
    border: 4px solid var(--amber);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 6px var(--amber-glow); }

/* ---------- Formulare ---------- */

form {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px 20px;
    margin: 8px auto 16px;
    max-width: 640px;
}

label {
    display: block;
    margin: 0 0 6px;
    font-size: .9rem;
    font-weight: 650;
    color: var(--muted);
}

input:not([type="range"]):not([type="submit"]),
select {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    width: 100%;
    min-height: 54px;
    margin: 0 0 18px;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: 500 1.05rem/1.3 var(--font);
    transition: border-color .15s ease, box-shadow .15s ease;
}

select {
    padding-right: 44px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

input:not([type="range"]):not([type="submit"]):focus,
select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 4px var(--blue-tint);
}

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

.flash-messages { display: grid; gap: 8px; margin: 12px auto; max-width: 640px; padding: 0; list-style: none; }
.flash-message, .flash-messages li {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--blue-tint);
    color: var(--text);
    font-size: .95rem;
    font-weight: 500;
}
.flash-message.error, .flash-messages li.error { background: var(--red-tint); }
.flash-message.success, .flash-messages li.success { background: var(--green-tint); }

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

.login {
    max-width: 440px;
    margin: 12vh auto 0;
}
.login__brand { text-align: center; margin-bottom: 20px; }
.login__brand img { display: block; width: 100%; max-width: 260px; height: auto; margin: 0 auto; border-radius: 14px; box-shadow: var(--shadow); }
.login__brand h1 { margin-top: 14px; font-size: 1.3rem; }
.login__brand p { margin: 4px 0 0; color: var(--muted); font-size: .95rem; }
.login__foot { margin-top: 16px; text-align: center; color: var(--muted); font-size: .85rem; }

/* ---------- Liste eingeloggter Benutzer ---------- */

.user-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.user-list li {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: .9rem;
    font-weight: 600;
}
.user-list li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

/* ---------- Video ---------- */

.iframe-container {
    display: flex;
    justify-content: center;
    margin: 16px 0;
}
.iframe-container iframe,
.iframe-container video {
    width: 100%;
    max-width: 640px;
    aspect-ratio: 5 / 4;
    height: auto;
    border: 0;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: #000;
}

/* ---------- Animationen ---------- */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .45; }
}
@keyframes pending-green {
    0%, 100% { box-shadow: 0 0 0 0 var(--green-glow); }
    50% { box-shadow: 0 0 0 9px rgba(22, 163, 74, 0); }
}
@keyframes pending {
    0%, 100% { box-shadow: 0 0 0 0 var(--blue-glow); }
    50% { box-shadow: 0 0 0 8px rgba(37, 99, 235, 0); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
.iframe-container video { aspect-ratio: 16 / 9; }
