:root {
    color-scheme: dark;
    --bg: #0c1118;
    --panel: #141d29;
    --panel2: #192536;
    --text: #eef4ff;
    --muted: #95a6bb;
    --line: rgba(255,255,255,.12);
    --good: #78e39a;
    --bad: #ff7272;
    --warn: #ffd16b;
    --accent: #74b7ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top left, #1b3554, var(--bg) 42rem);
    color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem clamp(1rem, 4vw, 3rem);
    border-bottom: 1px solid var(--line);
    background: rgba(12,17,24,.82);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar nav { display: flex; gap: 1rem; }
.container { width: min(1180px, calc(100% - 2rem)); margin: 1.5rem auto 4rem; }
.container.narrow { width: min(720px, calc(100% - 2rem)); }
.panel, .login-card {
    background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.02)), var(--panel);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 1.25rem;
    box-shadow: 0 18px 60px rgba(0,0,0,.22);
}
.hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
h1, h2 { margin: 0 0 .4rem; line-height: 1.1; }
p { color: var(--muted); }
.status-pill, .ac-state {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .55rem .85rem;
    color: var(--muted);
    white-space: nowrap;
}
.ac-state.on { color: var(--good); border-color: rgba(120,227,154,.45); }
.ac-state.off { color: var(--warn); border-color: rgba(255,209,107,.45); }
.device-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.1rem; }
.device-card { display: flex; flex-direction: column; gap: 1rem; }
.device-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.serial, .small, .muted { color: var(--muted); font-size: .92rem; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
.metric { background: var(--panel2); border: 1px solid var(--line); border-radius: 18px; padding: .9rem; min-width: 0; }
.metric span { display: block; color: var(--muted); font-size: .86rem; }
.metric strong { display: block; font-size: clamp(1.4rem, 3vw, 2rem); margin: .25rem 0; }
.field { display: block; color: var(--muted); font-size: .72rem; overflow-wrap: anywhere; }
.field.missing { color: var(--warn); }
.actions { display: flex; flex-wrap: wrap; gap: .7rem; }
button {
    border: 0;
    border-radius: 14px;
    padding: .8rem 1rem;
    font-weight: 750;
    cursor: pointer;
    color: #07111d;
    background: var(--accent);
}
button.secondary { background: var(--good); }
button.danger { background: var(--bad); color: #250000; }
button:disabled { opacity: .5; cursor: not-allowed; }
.alert { border-radius: 16px; padding: .8rem 1rem; margin: .8rem 0; background: rgba(255,209,107,.12); border: 1px solid rgba(255,209,107,.35); color: var(--warn); }
.alert.error { background: rgba(255,114,114,.12); border-color: rgba(255,114,114,.35); color: var(--bad); }
.alert.success { background: rgba(120,227,154,.12); border-color: rgba(120,227,154,.35); color: var(--good); }
.login-body { display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(440px, 100%); }
.login-card.wide { width: min(620px, 100%); }
label { display: block; color: var(--muted); margin: .9rem 0 .35rem; }
input {
    display: block;
    width: 100%;
    border: 1px solid var(--line);
    background: #0b121c;
    color: var(--text);
    border-radius: 14px;
    padding: .8rem .9rem;
    margin-top: .35rem;
}
.raw summary { cursor: pointer; color: var(--accent); font-weight: 700; }
.table-wrap { overflow: auto; max-height: 420px; border: 1px solid var(--line); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; font-size: .83rem; }
th, td { border-bottom: 1px solid var(--line); padding: .5rem; text-align: left; vertical-align: top; }
td { color: var(--muted); overflow-wrap: anywhere; }
.skeleton { color: var(--muted); }
@media (max-width: 740px) {
    .hero, .device-head { flex-direction: column; align-items: stretch; }
    .metrics { grid-template-columns: 1fr; }
    .topbar { align-items: flex-start; gap: .75rem; flex-direction: column; }
}
.hero-side { display: flex; flex-direction: column; gap: .7rem; align-items: flex-end; }
.group-actions { display: flex; gap: .55rem; flex-wrap: wrap; justify-content: flex-end; }
.small-button { padding: .62rem .82rem; border-radius: 12px; font-size: .9rem; }
@media (max-width: 740px) {
    .hero-side { align-items: stretch; }
    .group-actions { justify-content: flex-start; }
}
.secret-inline { margin-bottom: 1.25rem; }
.secret-choice { display: flex; flex-wrap: wrap; gap: .8rem 1.2rem; margin: .8rem 0 1rem; }
.radio-line { display: flex; align-items: center; gap: .5rem; margin: .35rem 0; color: var(--muted); }
.radio-line input { width: auto; margin: 0; }
.secret-status-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin: 1rem 0; }
.secret-form { margin-top: 1rem; }
.secret-actions { margin-top: 1rem; }
.secret-actions form { margin: 0; }
code { background: rgba(255,255,255,.08); border: 1px solid var(--line); border-radius: 8px; padding: .1rem .35rem; }
@media (max-width: 740px) {
    .secret-status-grid { grid-template-columns: 1fr; }
}

/* V10: Verbundene Stream Einheit als ein Speicher */
.device-grid { grid-template-columns: 1fr; }
.storage-card { display: flex; flex-direction: column; gap: 1.1rem; }
.storage-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.unit-metrics .metric { min-height: 132px; }
.unit-actions { margin-top: .15rem; }
.ac-indicator {
    border-radius: 20px;
    padding: .85rem 1rem;
    min-width: 190px;
    text-align: center;
    font-weight: 900;
    letter-spacing: .04em;
    border: 2px solid rgba(255,255,255,.18);
    background: #05070a;
    color: #f7f7f7;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.ac-indicator span { display: inline-flex; align-items: center; gap: .45rem; }
.ac-indicator span::before { content: "■"; font-size: .9rem; }
.ac-indicator.on {
    background: linear-gradient(180deg, #ffd970, #b77c16);
    color: #140d00;
    border-color: #ffe9a4;
    box-shadow: 0 0 0 1px rgba(255,233,164,.55), 0 0 26px rgba(255,204,82,.42);
}
.ac-indicator.off {
    background: #030507;
    color: #ffffff;
    border-color: rgba(255,255,255,.45);
}
.ac-indicator.mixed {
    background: repeating-linear-gradient(135deg, #ffd970 0 14px, #030507 14px 28px);
    color: #ffffff;
    text-shadow: 0 1px 2px #000;
    border-color: #ffe9a4;
}
.ac-indicator.unknown {
    background: #131923;
    color: var(--warn);
    border-color: rgba(255,209,107,.55);
}
.subdevices-accordion { border-top: 1px solid var(--line); padding-top: .7rem; }
.subdevices-accordion > summary { cursor: pointer; color: var(--accent); font-weight: 800; font-size: 1.02rem; }
.subdevices-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 1rem; margin-top: 1rem; }
.subdevice {
    background: rgba(255,255,255,.035);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1rem;
}
.subdevice h3 { margin: 0 0 .35rem; font-size: 1.18rem; }
.compact-head { align-items: center; margin-bottom: .85rem; }
.ac-badge {
    border-radius: 999px;
    padding: .45rem .7rem;
    font-weight: 900;
    letter-spacing: .03em;
    border: 1px solid var(--line);
    background: #05070a;
    color: #fff;
}
.ac-badge.on { background: #ffd970; color: #140d00; border-color: #ffe9a4; box-shadow: 0 0 16px rgba(255,204,82,.35); }
.ac-badge.off { background: #05070a; color: #fff; border-color: rgba(255,255,255,.42); }
.ac-badge.unknown { background: #131923; color: var(--warn); border-color: rgba(255,209,107,.45); }
.mini-metrics { display: grid; grid-template-columns: 1fr; gap: .55rem; margin: .8rem 0; }
.mini-metrics > div { background: rgba(25,37,54,.74); border: 1px solid var(--line); border-radius: 14px; padding: .7rem; }
.mini-metrics span { display: block; color: var(--muted); font-size: .82rem; }
.mini-metrics strong { display: block; font-size: 1.15rem; margin: .15rem 0; }
.compact-actions button { padding: .6rem .75rem; border-radius: 12px; font-size: .86rem; }
@media (max-width: 740px) {
    .storage-head { flex-direction: column; align-items: stretch; }
    .ac-indicator { min-width: 0; }
    .unit-actions button { width: 100%; }
}

/* V12: vier Kennzahlen und Leistungs Finder */
.unit-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.raw h4 { margin: 1rem 0 .4rem; }
@media (max-width: 1080px) {
    .unit-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 740px) {
    .unit-metrics { grid-template-columns: 1fr; }
}

/* V19: vier Kennzahlen, Steckdosen nur Status und Steuerung */
.unit-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.changed-row td {
    background: rgba(255,209,107,.13);
    color: var(--text);
    font-weight: 700;
}
@media (max-width: 1200px) {
    .unit-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 740px) {
    .unit-metrics { grid-template-columns: 1fr; }
}

/* V22: 60 Sekunden Sicherheitssperre fuer Steckdosen */
.switch-lock {
    border: 1px solid var(--line);
    background: rgba(255,255,255,.045);
    color: var(--muted);
    border-radius: 14px;
    padding: .7rem .85rem;
    font-size: .92rem;
}
.switch-lock.active {
    border-color: rgba(255,209,107,.65);
    background: rgba(255,209,107,.13);
    color: var(--warn);
    font-weight: 750;
}
.switch-lock strong { color: #fff; }
