:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-strong: #f9fafb;
    --ink: #121820;
    --muted: #5d6876;
    --line: #d8dee7;
    --danger: #b42318;
    --danger-strong: #8f1d15;
    --danger-soft: #fff1f0;
    --amber: #b7791f;
    --blue: #1d4ed8;
    --teal: #0f766e;
    --green: #15803d;
    --shadow: 0 18px 48px rgba(18, 24, 32, 0.12);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        linear-gradient(180deg, rgba(180, 35, 24, 0.06), transparent 260px),
        var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: wait;
    opacity: 0.66;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 76px;
    padding: 14px max(20px, env(safe-area-inset-left)) 14px max(20px, env(safe-area-inset-right));
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(18px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.brand img {
    flex: 0 0 auto;
    border-radius: 8px;
    box-shadow: 0 8px 22px rgba(180, 35, 24, 0.18);
}

.brand span {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.brand strong {
    overflow: hidden;
    font-size: 18px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand small,
.section-heading p,
.alert-meta,
.event-list,
.device-list,
.empty-state {
    color: var(--muted);
}

.topbar-status {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.pill,
.status-dot,
.receiver-state {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    background: var(--surface);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.pill.danger {
    border-color: rgba(180, 35, 24, 0.24);
    color: var(--danger);
    background: var(--danger-soft);
}

.status-dot.online {
    border-color: rgba(21, 128, 61, 0.28);
    color: var(--green);
    background: #f0fdf4;
}

.status-dot.error {
    border-color: rgba(180, 35, 24, 0.28);
    color: var(--danger);
    background: var(--danger-soft);
}

.layout {
    width: min(1180px, calc(100% - 32px));
    margin: 22px auto 48px;
}

.setup-panel,
.command-surface,
.status-surface {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.setup-panel {
    max-width: 720px;
    margin: 56px auto;
    padding: 28px;
}

.dashboard {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
    gap: 18px;
    align-items: start;
}

.command-surface {
    grid-row: span 3;
    padding: 24px;
}

.status-surface {
    padding: 18px;
}

.section-heading {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 18px;
}

.section-heading.compact {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 40px;
    margin-bottom: 12px;
}

.section-heading h1,
.section-heading h2,
.section-heading p {
    margin: 0;
}

.section-heading h1 {
    font-size: 28px;
    line-height: 1.15;
}

.section-heading h2 {
    font-size: 17px;
    line-height: 1.2;
}

.setup-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.setup-form label {
    display: grid;
    gap: 7px;
    min-width: 0;
}

.setup-form label:first-child,
.setup-form button {
    grid-column: 1 / -1;
}

label span {
    font-size: 13px;
    font-weight: 800;
}

input,
select {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    color: var(--ink);
    background: var(--surface-strong);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    outline: none;
}

input:focus,
select:focus,
button:focus-visible {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

.alarm-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.alarm-button,
.tap-button,
.primary-action,
.quiet-button,
.icon-button {
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-weight: 850;
    letter-spacing: 0;
}

.alarm-button,
.tap-button {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 10px;
    min-height: 218px;
    padding: 22px;
    text-align: center;
    overflow-wrap: anywhere;
}

.alarm-button {
    grid-column: 1 / -1;
    color: #ffffff;
    background: linear-gradient(180deg, #d92d20, var(--danger));
    box-shadow: 0 18px 48px rgba(180, 35, 24, 0.32);
}

.alarm-button span {
    font-size: 30px;
    line-height: 1.1;
}

.alarm-button small {
    max-width: 360px;
    color: rgba(255, 255, 255, 0.86);
    font-size: 14px;
    line-height: 1.35;
}

.tap-button {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: rgba(180, 35, 24, 0.18);
}

.tap-button span {
    font-size: 22px;
}

.tap-button small {
    color: var(--danger-strong);
    font-size: 18px;
}

.primary-action,
.quiet-button,
.icon-button {
    min-height: 46px;
    padding: 10px 14px;
}

.primary-action {
    color: #ffffff;
    background: var(--danger);
}

.quiet-button,
.icon-button {
    color: var(--ink);
    background: var(--surface-strong);
    border-color: var(--line);
}

.quiet-button.light {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.35);
}

.quiet-button.attention {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: rgba(180, 35, 24, 0.32);
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 42px;
    padding: 0;
    font-size: 20px;
}

.empty-state {
    display: grid;
    place-items: center;
    min-height: 86px;
    padding: 18px;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    background: var(--surface-strong);
    text-align: center;
}

.alert-list,
.device-list,
.event-list {
    display: grid;
    gap: 10px;
}

.alert-card,
.device-row,
.event-row {
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-strong);
}

.alert-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    border-left: 5px solid var(--danger);
}

.alert-id,
.device-row strong {
    display: block;
    overflow-wrap: anywhere;
}

.alert-meta,
.event-row,
.device-row p {
    margin: 4px 0 0;
    font-size: 13px;
    line-height: 1.4;
}

.alert-map {
    display: inline-flex;
    margin-top: 8px;
    color: var(--blue);
    font-weight: 800;
    text-decoration: none;
}

.alert-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    min-width: 112px;
    align-content: start;
}

.device-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
}

.device-role {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    color: var(--teal);
    background: #effdf9;
    border: 1px solid rgba(15, 118, 110, 0.2);
    font-size: 12px;
    font-weight: 850;
}

.event-list {
    max-height: 280px;
    overflow: auto;
    padding-right: 2px;
}

.event-row {
    border-left: 4px solid var(--amber);
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 50;
    max-width: min(360px, calc(100% - 36px));
    padding: 14px 16px;
    color: #ffffff;
    background: #172033;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.toast.error {
    background: var(--danger-strong);
}

.alarm-overlay {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 24px;
    color: #ffffff;
    background:
        linear-gradient(135deg, rgba(143, 29, 21, 0.96), rgba(23, 32, 51, 0.92));
}

.alarm-overlay[hidden] {
    display: none;
}

.alarm-overlay-inner {
    display: grid;
    gap: 18px;
    width: min(560px, 100%);
    padding: 28px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.10);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.alarm-overlay strong {
    font-size: 30px;
    line-height: 1.1;
}

.alarm-overlay p {
    margin: 0;
    line-height: 1.5;
}

.overlay-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

@media (max-width: 900px) {
    .dashboard {
        grid-template-columns: 1fr;
    }

    .command-surface {
        grid-row: auto;
    }
}

@media (max-width: 680px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        min-height: auto;
    }

    .topbar-status {
        justify-content: flex-start;
        width: 100%;
    }

    .layout {
        width: min(100% - 20px, 1180px);
        margin-top: 12px;
    }

    .setup-panel,
    .command-surface,
    .status-surface {
        padding: 16px;
    }

    .setup-form,
    .alarm-grid,
    .alert-card,
    .device-row {
        grid-template-columns: 1fr;
    }

    .alarm-button,
    .tap-button {
        min-height: 150px;
    }

    .alarm-button span {
        font-size: 25px;
    }

    .alert-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        min-width: 0;
    }
}
