body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: #f6f8fb;
    color: #1b1f23;
    margin: 0;
}

.topbar {
    background: #0e1e2f;
    color: #fff;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    height: 36px;
}

.topnav a {
    color: #fff;
    text-decoration: none;
    margin-left: 16px;
    font-weight: 600;
}

.mobile-nav {
    display: none;
}

.content {
    max-width: 1100px;
    margin: 32px auto;
    background: #fff;
    padding: 24px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.flash {
    background: #e3f2fd;
    color: #0d47a1;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
}

.footer {
    text-align: center;
    padding: 16px;
    font-size: 14px;
    color: #667085;
}

form label {
    display: block;
    margin-bottom: 12px;
}

input[type="text"],
input[type="password"],
select {
    width: 100%;
    padding: 10px;
    border: 1px solid #dadfe9;
    border-radius: 6px;
    font-size: 16px;
}

button {
    background: #0057ff;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px 18px;
    font-size: 16px;
    cursor: pointer;
}

.btn,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease;
}

.btn .icon,
button .icon {
    font-size: 14px;
    margin-right: 4px;
}

.btn {
    background: #e4e7ec;
    color: #0f172a;
    padding: 9px 16px;
    border-radius: 6px;
}

.btn.primary,
button.primary {
    background: #0057ff;
    color: #fff;
}

.btn.secondary {
    background: #0f172a;
    color: #fff;
}

.btn.danger {
    background: #e11d48;
    color: #fff;
}

.btn.small {
    font-size: 13px;
    padding: 6px 10px;
}

table.table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

table.table th,
table.table td {
    border: 1px solid #e4e7ec;
    padding: 8px 10px;
    text-align: left;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    align-items: start;
}

.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 18px;
}

.device-card {
    border: 1px solid #dfe5ec;
    border-radius: 14px;
    background: #fff;
    padding: 20px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.device-card.is-online { border-color: #acd9bf; }
.device-card.is-offline { border-color: #d4dce4; }

.device-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.device-card-header h2 {
    margin: 7px 0 2px;
    font-size: 21px;
    letter-spacing: 0.04em;
}

.device-card-header p { margin: 0; color: #64748b; font-size: 12px; }

.status-pill,
.assignment-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.status-pill.online { background: #dcfce7; color: #166534; }
.status-pill.offline { background: #f1f5f9; color: #475569; }
.assignment-badge.assigned { background: #dbeafe; color: #1d4ed8; }
.assignment-badge.waiting { background: #fff7ed; color: #c2410c; }

.device-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 16px;
    margin: 0 0 18px;
}

.device-facts div { min-width: 0; }
.device-facts dt { color: #64748b; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.device-facts dd { margin: 3px 0 0; font-weight: 600; overflow-wrap: anywhere; }

.current-assignment {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-bottom: 14px;
    padding: 12px;
    border-radius: 10px;
    background: #eff6ff;
    color: #1e3a8a;
}

.current-assignment span { font-size: 11px; text-transform: uppercase; }

.device-assign-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 10px;
}

.device-assign-form label { display: flex; flex-direction: column; gap: 5px; }
.device-assign-form label span { font-size: 12px; font-weight: 700; }
.device-assign-form select { width: 100%; }

.empty-state {
    padding: 34px;
    border: 1px dashed #cbd5e1;
    border-radius: 14px;
    text-align: center;
    background: #f8fafc;
}

@media (max-width: 640px) {
    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    .device-grid { grid-template-columns: 1fr; }
    .device-card-header { flex-direction: column; }
    .device-facts { grid-template-columns: 1fr; }
    .device-assign-form { grid-template-columns: 1fr; }
}

/* Door access groups and local mode schedule */
.access-config-trigger {
    white-space: normal;
}

.access-config-trigger.is-active {
    border-color: #76aee9;
    background: #e7f1fc;
    color: #0b4e93;
    font-weight: 750;
}

.door-access-workspace {
    margin: 0 0 24px;
    overflow: hidden;
    border: 1px solid #b9cee1;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(20, 50, 78, 0.1);
}

.door-access-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 20px 22px;
    border-bottom: 1px solid #cdddea;
    background: #f3f8fc;
}

.door-access-identity {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 16px;
}

.door-access-code {
    display: grid;
    flex: 0 0 auto;
    min-width: 76px;
    min-height: 54px;
    place-items: center;
    padding: 8px 12px;
    border-radius: 12px;
    background: #153651;
    color: #fff;
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
    font-size: 20px;
    letter-spacing: .03em;
}

.door-access-header h2,
.door-access-section h3 {
    margin: 0;
}

.door-access-header p,
.door-access-section-header p {
    margin: 5px 0 0;
    color: #536779;
}

.door-access-scope {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 12px 22px;
    background: #e8f2fc;
    color: #24465f;
    font-size: 13px;
}

.door-access-scope strong {
    color: #0c3557;
    font-size: 15px;
}

.door-access-section {
    padding: 22px;
}

.door-access-section + .door-access-section {
    border-top: 1px solid #dbe5ed;
}

.door-access-section.door-schedule-workspace {
    margin-top: 0;
    padding-top: 22px;
    border-top: 1px solid #dbe5ed;
}

.door-access-section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.door-access-section-header > a {
    color: #0b5cab;
    font-size: 14px;
    font-weight: 700;
    text-underline-offset: 3px;
}

.door-access-form {
    margin: 0;
}

.door-access-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.door-access-actions span {
    color: #536779;
    font-size: 13px;
}

.door-window-count {
    flex: 0 0 auto;
    padding: 7px 10px;
    border-radius: 999px;
    background: #e5edf4;
    color: #314c62;
    font-size: 12px;
    font-weight: 750;
}

.access-group-empty {
    margin: 0;
    color: #64748b;
}

.access-group-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.access-group-set {
    min-width: 0;
    margin: 0;
    padding: 16px;
    border: 1px solid #dbe3ef;
    border-radius: 14px;
}

.access-group-set legend {
    padding: 0 6px;
    color: #0f172a;
    font-size: 16px;
    font-weight: 700;
}

.access-group-set > p,
.door-schedule-workspace > p,
.door-schedule-workspace > small {
    color: #64748b;
}

.door-schedule-workspace {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

.mode-window-list {
    display: grid;
    gap: 8px;
    margin: 16px 0;
}

.mode-window-row {
    display: grid;
    grid-template-columns: minmax(170px, 1fr) minmax(110px, auto) minmax(190px, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 8px 10px;
    border-bottom: 1px solid #e2e8f0;
}

.mode-window-form {
    display: grid;
    grid-template-columns: minmax(170px, 1fr) 120px 120px minmax(210px, 1fr) auto;
    align-items: end;
    gap: 10px;
    margin-top: 16px;
}

.mode-window-form label,
.temporary-open-form label {
    display: grid;
    gap: 6px;
    margin: 0;
    color: #334155;
    font-size: 13px;
    font-weight: 650;
}

.mode-window-form input,
.mode-window-form select,
.temporary-open-form input {
    box-sizing: border-box;
    width: 100%;
    min-height: 44px;
    padding: 9px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #0f172a;
    font: inherit;
}

.temporary-open-control {
    display: flex;
    align-items: end;
    gap: 12px;
    margin-top: 20px;
    padding: 14px 0;
    border-top: 1px solid #e2e8f0;
}

.temporary-open-control > div {
    display: grid;
    gap: 3px;
    margin-right: auto;
}

.temporary-open-control > div span {
    color: #64748b;
    font-size: 13px;
}

.temporary-open-form {
    display: flex;
    align-items: end;
    gap: 8px;
}

.temporary-open-form input {
    width: 90px;
}

.mode-window-form :focus-visible,
.temporary-open-form :focus-visible,
.access-group-set input:focus-visible {
    outline: 3px solid rgba(0, 87, 255, 0.28);
    outline-offset: 2px;
}

@media (max-width: 820px) {
    .door-access-header,
    .door-access-identity,
    .door-access-section-header,
    .door-access-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .door-access-header .btn,
    .door-access-actions .btn {
        width: 100%;
    }

    .door-access-scope {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .door-access-section,
    .door-access-header,
    .door-access-scope {
        padding-right: 16px;
        padding-left: 16px;
    }

    .access-group-columns,
    .mode-window-form {
        grid-template-columns: 1fr;
    }

    .mode-window-row {
        grid-template-columns: 1fr auto;
    }

    .mode-window-row > span:last-of-type {
        grid-column: 1 / -1;
    }

    .temporary-open-control,
    .temporary-open-form {
        align-items: stretch;
        flex-direction: column;
    }

    .temporary-open-form input,
    .temporary-open-control .btn,
    .mode-window-form .btn {
        width: 100%;
        min-height: 44px;
    }
}

.inline {
    display: inline-block;
}

textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #dadfe9;
    border-radius: 6px;
    font-size: 14px;
}

.section-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.section-header.between {
    justify-content: space-between;
}

.section-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.filters input[type="text"],
.filters select {
    width: auto;
    min-width: 180px;
}

.table-wrapper {
    overflow-x: auto;
}

.doors-overview-wrapper {
    overflow-x: hidden;
}

table.doors-overview-table {
    table-layout: fixed;
    font-size: 11px;
}

table.doors-overview-table th,
table.doors-overview-table td {
    padding: 4px;
    vertical-align: top;
    overflow-wrap: anywhere;
    line-height: 1.2;
}

.doors-overview-table .door-col-code { width: 4%; }
.doors-overview-table .door-col-name { width: 9%; }
.doors-overview-table .door-col-timers { width: 8%; }
.doors-overview-table .door-col-mode { width: 24%; }
.doors-overview-table .door-col-inputs { width: 18%; }
.doors-overview-table .door-col-relays { width: 13%; }
.doors-overview-table .door-col-status { width: 6%; }
.doors-overview-table .door-col-actions { width: 18%; }

.doors-overview-table .actions .btn.small,
.doors-overview-table .quick-actions .btn.small {
    padding: 3px 5px;
    font-size: 10px;
}

.doors-overview-table .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 3px;
}

.doors-overview-table .actions .btn.small,
.doors-overview-table .actions .inline-form,
.doors-overview-table .actions .inline-form .btn.small {
    width: 100%;
}

.doors-overview-table .actions .btn.small {
    min-height: 24px;
    justify-content: center;
}

.doors-page > .section-header {
    align-items: center;
    margin-bottom: 8px;
}

.doors-page > .section-header h1,
.doors-page > .section-header p {
    margin-top: 0;
    margin-bottom: 2px;
}

.doors-page > .filters {
    gap: 6px;
    margin-bottom: 8px;
}

.doors-page > .filters input,
.doors-page > .filters select,
.doors-page > .filters .btn {
    min-height: 32px;
    padding-top: 5px;
    padding-bottom: 5px;
}

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

.timers-compact span {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2px;
    padding: 3px 4px;
    border-radius: 5px;
    background: #f8fafc;
    white-space: nowrap;
    font-size: 9px;
}

.timers-compact b {
    color: #64748b;
    font-size: 8px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.inline-form {
    display: inline-block;
}

.door-mode-cell {
    min-width: 0;
}

.relay-control-cell {
    min-width: 0;
}

.input-control-cell {
    min-width: 0;
}

.input-status-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
}

.input-mini-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    padding: 3px 2px;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    background: #f8fafc;
}

.input-mini-state > strong {
    color: #334155;
    font-size: 9px;
    line-height: 1;
}

.input-state-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
}

.input-state-copy strong {
    color: #334155;
    font-size: 10px;
    white-space: nowrap;
}

.input-state-copy small {
    color: #64748b;
    font-size: 10px;
}

.input-state-dot {
    width: 7px;
    height: 7px;
    flex: 0 0 7px;
    border-radius: 50%;
    background: #94a3b8;
}

.input-mini-state.is-ok { border-color: #bbf7d0; background: #f0fdf4; }
.input-mini-state.is-ok .input-state-dot { background: #22c55e; }
.input-mini-state.is-alert { border-color: #fecaca; background: #fef2f2; }
.input-mini-state.is-alert .input-state-dot { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, .13); }
.input-mini-state.is-active { border-color: #bfdbfe; background: #eff6ff; }
.input-mini-state.is-active .input-state-dot { background: #2563eb; }
.input-mini-state.is-idle .input-state-dot { background: #94a3b8; }
.input-mini-state.is-unknown { opacity: .65; }

.input-report-state {
    margin-top: 4px;
    color: #64748b;
    font-size: 10px;
}

.input-health-error {
    color: #b91c1c;
    font-weight: 700;
}

.relay-status-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
}

.relay-mini-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    padding: 3px 2px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    color: #64748b;
    font-size: 10px;
    line-height: 1;
}

.relay-mini-state strong {
    color: #334155;
    font-size: 9px;
}

.relay-state-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: #94a3b8;
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.15);
}

.relay-mini-state.is-on,
.relay-system-state.is-on,
.relay-actual-state.is-on {
    border-color: #86efac;
    background: #f0fdf4;
    color: #15803d;
}

.relay-mini-state.is-on .relay-state-dot,
.relay-system-state.is-on .relay-state-dot,
.relay-actual-state.is-on .relay-state-dot,
.relay-device-health.is-live .relay-state-dot {
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.16);
}

.relay-mini-state.is-off .relay-state-dot,
.relay-system-state.is-off .relay-state-dot,
.relay-actual-state.is-off .relay-state-dot {
    background: #64748b;
}

.relay-report-state {
    margin-top: 4px;
    color: #64748b;
    font-size: 10px;
}

.relay-health-error {
    color: #b91c1c;
    font-weight: 700;
}

.access-sync-status {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
    margin-top: 6px;
}

.access-sync-item {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 1px;
    padding: 5px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    background: #f8fafc;
}

.access-sync-item.is-download {
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.access-sync-item small {
    color: #64748b;
    font-size: 9px;
    line-height: 1.2;
}

.access-sync-item strong {
    color: #334155;
    font-size: 10px;
    line-height: 1.2;
}

.mode-primary-row {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.mode-primary-row .state-badge {
    padding: 3px 7px;
    font-size: 9px;
    white-space: nowrap;
}

.mode-primary-row .quick-actions {
    gap: 3px;
}

.door-lock-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 2px 5px;
    border-radius: 6px;
    background: #fff7ed;
    color: #9a3412;
    font-size: 9px;
    line-height: 1.25;
}

.door-lock-line strong {
    color: #7c2d12;
    font-size: 9px;
}

.door-lock-line span {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.door-network-line {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    margin-top: 4px;
    padding: 3px 5px;
    border-radius: 6px;
    background: #f8fafc;
    color: #64748b;
    font-size: 9px;
}

.door-network-line strong {
    color: #334155;
    font-size: 10px;
}

.door-network-line.is-stale {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #b91c1c;
}

.signal-widget.compact {
    gap: 4px;
}

.signal-widget.compact .signal-meter {
    width: 46px;
    height: 5px;
}

.signal-widget.compact .signal-text {
    font-size: 9px;
}

.door-sync-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
    margin-top: 4px;
}

.sync-chip {
    min-width: 0;
    padding: 3px 4px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    color: #475569;
    font-size: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sync-chip b {
    display: block;
    color: #64748b;
    font-size: 7px;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.sync-chip.is-ok {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #15803d;
}

.sync-chip.is-warning {
    border-color: #fed7aa;
    background: #fff7ed;
    color: #c2410c;
}

.door-sync-details {
    margin-top: 3px;
    color: #64748b;
    font-size: 9px;
}

.door-sync-details > summary {
    cursor: pointer;
    list-style-position: inside;
    user-select: none;
}

.door-sync-details-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3px 8px;
    margin-top: 4px;
    padding: 5px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
}

.door-sync-details-grid span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.door-sync-details-grid b {
    display: block;
    color: #334155;
    font-size: 8px;
    text-transform: uppercase;
}

.relay-workspace {
    margin-top: 34px;
    scroll-margin-top: 20px;
}

.relay-empty-state {
    padding: 36px 24px;
    border: 1px dashed #cbd5e1;
    border-radius: 16px;
    background: #f8fafc;
    text-align: center;
    color: #64748b;
}

.relay-empty-state h2 {
    margin: 10px 0 6px;
    color: #0f172a;
}

.relay-empty-icon {
    display: inline-flex;
    width: 48px;
    height: 48px;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 24px;
}

.relay-workspace-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 24px;
    border-radius: 18px;
    color: #fff;
    background:
        radial-gradient(circle at 90% 10%, rgba(59, 130, 246, 0.35), transparent 35%),
        linear-gradient(135deg, #0f172a, #172554);
    box-shadow: 0 16px 34px rgba(15, 23, 42, 0.16);
}

.relay-workspace-header h2 {
    margin: 0;
    font-size: 27px;
}

.relay-workspace-header .eyebrow {
    color: #93c5fd;
}

.relay-door-code {
    margin: 6px 0 0;
    color: #cbd5e1;
    font-size: 13px;
}

.relay-device-health {
    min-width: 220px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 15px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 13px;
    background: rgba(255, 255, 255, 0.08);
}

.relay-device-health.is-error .relay-state-dot {
    background: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18);
}

.relay-device-health small {
    display: block;
    margin-top: 3px;
    color: #cbd5e1;
    font-size: 11px;
}

.relay-system-strip {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0;
    padding: 14px;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    background: #f8fafc;
}

.relay-system-copy {
    min-width: 175px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.relay-system-copy span {
    color: #64748b;
    font-size: 11px;
}

.relay-system-state {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    color: #64748b;
    font-size: 11px;
}

.relay-system-state b {
    color: inherit;
}

.relay-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(315px, 1fr));
    gap: 16px;
}

.relay-card {
    padding: 17px;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 7px 22px rgba(15, 23, 42, 0.06);
}

.relay-card.is-energized {
    border-color: #86efac;
    box-shadow: 0 8px 24px rgba(34, 197, 94, 0.1);
}

.relay-card-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 11px;
}

.relay-number {
    display: inline-flex;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 800;
}

.relay-card-title h3 {
    margin: 0 0 3px;
    overflow: hidden;
    color: #0f172a;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.relay-card-title span {
    color: #64748b;
    font-size: 11px;
}

.relay-actual-state {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 9px;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    color: #475569;
    font-size: 10px;
    font-weight: 700;
}

.relay-sync-note {
    margin-top: 12px;
    padding: 8px 10px;
    border-radius: 8px;
    background: #fff7ed;
    color: #9a3412;
    font-size: 11px;
}

.relay-sync-note.is-schedule {
    background: #eff6ff;
    color: #1d4ed8;
}

.relay-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-top: 16px;
}

.relay-quick-action,
.relay-settings {
    margin: 0;
}

.relay-action {
    width: 100%;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    box-sizing: border-box;
    border: 1px solid #dbe3ef;
    border-radius: 10px;
    background: #f8fafc;
    color: #334155;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
}

.relay-action::-webkit-details-marker {
    display: none;
}

.relay-action.on:hover,
.relay-action.on.is-selected {
    border-color: #86efac;
    background: #dcfce7;
    color: #15803d;
}

.relay-action.off:hover,
.relay-action.off.is-selected {
    border-color: #fca5a5;
    background: #fef2f2;
    color: #b91c1c;
}

.relay-action.settings:hover,
.relay-settings[open] > .relay-action.settings {
    border-color: #93c5fd;
    background: #eff6ff;
    color: #1d4ed8;
}

.relay-action-icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(100, 116, 139, 0.12);
    font-size: 10px;
    font-weight: 900;
}

.relay-settings[open] {
    grid-column: 1 / -1;
}

.relay-settings-form {
    margin-top: 12px;
    padding-top: 15px;
    border-top: 1px solid #e2e8f0;
}

.relay-mode-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin: 14px 0;
    padding: 0;
    border: 0;
}

.relay-mode-picker legend {
    grid-column: 1 / -1;
    margin-bottom: 7px;
    color: #334155;
    font-size: 13px;
    font-weight: 600;
}

.relay-mode-option {
    margin: 0;
    cursor: pointer;
}

.relay-mode-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.relay-mode-option span {
    display: flex;
    min-height: 52px;
    flex-direction: column;
    justify-content: center;
    padding: 8px;
    border: 1px solid #dbe3ef;
    border-radius: 10px;
    background: #fff;
    text-align: center;
}

.relay-mode-option input:checked + span {
    border-color: #60a5fa;
    background: #eff6ff;
    color: #1d4ed8;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.relay-mode-option small {
    margin-top: 2px;
    color: #64748b;
    font-size: 9px;
}

.relay-schedule-fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
    padding: 12px;
    border-radius: 12px;
    background: #f8fafc;
}

.relay-settings-heading {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    color: #334155;
    font-size: 12px;
}

.relay-settings-heading span {
    color: #64748b;
    font-size: 10px;
}

.relay-schedule-fields .form-field {
    margin: 0;
    font-size: 11px;
}

.relay-schedule-fields textarea {
    min-height: 64px;
    box-sizing: border-box;
    font-size: 11px;
    resize: vertical;
}

.relay-settings-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

@media (max-width: 760px) {
    .relay-workspace-header,
    .relay-system-strip {
        align-items: stretch;
        flex-direction: column;
    }

    .relay-device-health {
        min-width: 0;
    }

    .relay-system-state {
        justify-content: flex-start;
    }

    .relay-grid {
        grid-template-columns: 1fr;
    }

    .relay-card-header {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .relay-actual-state {
        grid-column: 1 / -1;
        justify-self: start;
    }

    .relay-schedule-fields {
        grid-template-columns: 1fr;
    }

    .relay-settings-heading {
        flex-direction: column;
    }
}

.mode-summary {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.door-mode-overview {
    display: grid;
    gap: 7px;
}

.door-current-mode {
    display: grid;
    gap: 3px;
    padding: 8px 9px;
    border: 1px solid #b9d7f2;
    border-radius: 10px;
    background: #eef7ff;
    color: #113e64;
}

.door-current-mode.mode-open-alarm {
    border-color: #efcb91;
    background: #fff6e7;
    color: #743b06;
}

.door-current-mode.mode-open {
    border-color: #e5b76e;
    background: #fff2dc;
    color: #6d3504;
}

.door-current-mode.mode-closed {
    border-color: #cbd5df;
    background: #eef2f5;
    color: #243444;
}

.door-current-mode.mode-restricted {
    border-color: #c9c3ef;
    background: #f3f1ff;
    color: #403879;
}

.door-current-mode-label {
    color: currentColor;
    font-size: 9px;
    font-weight: 850;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.door-current-mode strong {
    font-size: 13px;
    line-height: 1.2;
}

.door-current-mode p {
    margin: 0;
    color: currentColor;
    font-size: 10px;
    line-height: 1.35;
}

.door-mode-source {
    width: fit-content;
    margin-top: 2px;
    padding: 3px 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .72);
    color: currentColor;
    font-size: 9px;
    font-weight: 750;
}

.door-mode-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
}

.door-mode-actions-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
}

.door-mode-actions-heading strong {
    color: #25394a;
    font-size: 10px;
}

.door-mode-actions-heading span {
    color: #607283;
    font-size: 8px;
    text-align: right;
}

.door-mode-form {
    display: block;
    min-width: 0;
    margin: 0;
}

.door-mode-form.mode-form-3 {
    grid-column: 1 / -1;
}

.door-mode-action {
    display: flex;
    width: 100%;
    min-width: 0;
    min-height: 39px;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    padding: 5px 7px;
    border: 1px solid #cbd6df;
    border-radius: 8px;
    background: #fff;
    color: #24384a;
    text-align: left;
}

.door-mode-action > span {
    display: grid;
    min-width: 0;
    gap: 1px;
}

.door-mode-action strong {
    font-size: 9px;
    line-height: 1.2;
}

.door-mode-action small {
    color: #5d6f7f;
    font-size: 8px;
    line-height: 1.2;
}

.door-mode-action b {
    flex: 0 0 auto;
    padding: 2px 4px;
    border-radius: 999px;
    background: #e6edf3;
    color: #405467;
    font-size: 7px;
    line-height: 1.2;
}

.door-mode-action:hover:not(:disabled) {
    border-color: #6e9bc2;
    background: #f6faff;
}

.door-mode-action.is-current {
    border-color: #276da9;
    background: #e9f3fc;
    color: #124f82;
}

.door-mode-action.is-current b {
    background: #1766a8;
    color: #fff;
}

.door-mode-action:disabled {
    cursor: default;
    opacity: 1;
}

.door-mode-override-clear button,
.door-active-alarm-action button {
    width: 100%;
    min-height: 36px;
    padding: 7px 9px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 800;
}

.door-mode-override-clear button {
    border: 1px solid #91b8df;
    background: #edf6ff;
    color: #134f83;
}

.door-active-alarm-action button {
    border: 1px solid #b4232f;
    background: #b4232f;
    color: #fff;
}

.mode-name small {
    display: block;
    color: #475467;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.btn.ghost {
    background: #fff;
    border: 1px solid #cbd5f5;
    color: #0f172a;
}

.btn.ghost.danger {
    border-color: #fecaca;
    color: #b91c1c;
}

.state-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.state-badge.mode-auto {
    background: #e0f2fe;
    color: #0369a1;
}

.state-badge.mode-open-alarm {
    background: #fff1dc;
    color: #8d4006;
}

.state-badge.mode-open {
    background: #dcfce7;
    color: #15803d;
}

.state-badge.mode-closed {
    background: #e2e8f0;
    color: #0f172a;
}

.state-badge.mode-restricted {
    background: #ede9fe;
    color: #5b21b6;
}

.wifi-info {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
    color: #475467;
    align-items: center;
}

.signal-widget {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.signal-meter {
    position: relative;
    width: 120px;
    height: 8px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.signal-meter .signal-bar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    background: linear-gradient(90deg, #60a5fa, #2563eb);
    width: 0;
}

.signal-meter.level-weak .signal-bar {
    background: linear-gradient(90deg, #facc15, #f97316);
}

.signal-meter.level-poor .signal-bar {
    background: linear-gradient(90deg, #f87171, #dc2626);
}

.signal-meter.level-good .signal-bar {
    background: linear-gradient(90deg, #4ade80, #16a34a);
}

.signal-meter.level-none .signal-bar {
    background: #cbd5f5;
}

.signal-text {
    font-size: 12px;
    color: #475467;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-danger {
    background: #fee2e2;
    color: #b91c1c;
}

.badge-muted {
    background: #e2e8f0;
    color: #475569;
}

.badge-info {
    background: #e0f2fe;
    color: #0c4a6e;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    margin: 0 6px 4px 0;
    background: #e4e7ec;
    color: #0f172a;
}

.chip-light {
    background: #f1f5f9;
    color: #475467;
}

.chip-in {
    background: #dbeafe;
    color: #1d4ed8;
}

.chip-out {
    background: #fef3c7;
    color: #92400e;
}

.chip-success {
    background: #dcfce7;
    color: #15803d;
}

.chip-warning {
    background: #fef3c7;
    color: #92400e;
}

.form-card {
    background: #f9fafb;
    border: 1px solid #e4e7ec;
    border-radius: 10px;
    padding: 20px;
    margin-top: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
    align-items: flex-start;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    font-size: 14px;
    color: #475467;
}

.form-field span {
    font-weight: 600;
    color: #0f172a;
}

.field-hint {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 400;
}

.field-hint.inline {
    display: block;
    text-align: right;
    margin-top: 4px;
}

.checkbox-field {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding-top: 24px;
}

.section-note {
    margin: 4px 0 14px;
    font-size: 14px;
    color: #64748b;
}

.form-section {
    border-top: 1px solid #e4e7ec;
    padding-top: 12px;
    margin-top: 12px;
}

.form-section:first-of-type {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}

.form-section h3 {
    margin: 0 0 12px;
    font-size: 16px;
    color: #0f172a;
}

.grid-two {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin: 16px 0;
}

.text-center {
    text-align: center;
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.form-toggle {
    margin-top: 20px;
}

.form-toggle summary {
    list-style: none;
    cursor: pointer;
    margin-bottom: 12px;
}

.form-toggle summary::-webkit-details-marker {
    display: none;
}

.form-toggle > summary .btn {
    width: auto;
}

.form-toggle[open] > summary .btn::after,
.form-toggle > summary .btn::after {
    content: attr(data-label-closed);
    display: none;
}

.form-toggle summary .btn::after {
    content: attr(data-label-open);
    margin-left: 8px;
    font-weight: 400;
    font-size: 12px;
}

.inline-form form,
.inline-form {
    display: inline-block;
}

.chart-grid {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.onewire-section {
    margin: 1.5rem 0;
}

.onewire-sensor-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin: 1rem 0 1.5rem;
}

.onewire-sensor-card {
    display: grid;
    gap: 0.65rem;
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
}

.onewire-sensor-state {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.onewire-sensor-card code {
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.onewire-sensor-card small {
    color: #64748b;
}

.onewire-rename-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 0.75rem;
}

.onewire-rename-form label,
.onewire-rename-form input {
    width: 100%;
}

.chart-card {
    background: #f9fafb;
    border: 1px solid #e4e7ec;
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

.chart-card.wifi-chart {
    border-color: #c7d7fe;
    background: #f8fbff;
}

.chart-card header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.chart-card h2 {
    margin: 0;
    font-size: 20px;
}

.chart-card p {
    margin: 2px 0 0;
    color: #475467;
    font-size: 14px;
}

.chart-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: #475467;
    text-align: right;
}

.chart-svg {
    width: 100%;
    height: auto;
}

.chart-axis {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #94a3b8;
}

.chart-empty {
    padding: 40px 0;
    text-align: center;
    color: #94a3b8;
    border: 1px dashed #e4e7ec;
    border-radius: 10px;
    background: #fff;
}

.chart-summary {
    margin: 0 0 16px;
    font-size: 15px;
    color: #475467;
}

.sensor-status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.sensor-status-card {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    background: #f8fafc;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.sensor-status-card h3 {
    margin: 0 0 8px;
    font-size: 15px;
    color: #0f172a;
}

.sensor-status-card ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 14px;
    color: #475467;
}

.sensor-status-card li strong {
    color: #0f172a;
}

.sensor-connectivity-card {
    grid-column: span 2;
    background: linear-gradient(145deg, #f8fafc 0%, #fff 100%);
}

.sensor-connectivity-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 14px;
}

.sensor-connectivity-header h3 {
    margin: 0;
    font-size: 17px;
}

.sensor-connectivity-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: 10px;
    margin: 0;
}

.sensor-connectivity-grid > div {
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
}

.sensor-connectivity-grid dt {
    margin-bottom: 4px;
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.sensor-connectivity-grid dd {
    margin: 0;
    overflow-wrap: anywhere;
    color: #0f172a;
    font-size: 14px;
    font-weight: 650;
}

.sensor-connectivity-grid dd small {
    color: #64748b;
    font-weight: 500;
}

.sensor-connectivity-seen {
    margin: 11px 0 0;
    color: #64748b;
    font-size: 12px;
}

.signal-strong,
.signal-good {
    color: #15803d !important;
}

.signal-weak {
    color: #c2410c !important;
}

.signal-poor {
    color: #b91c1c !important;
}

.signal-unknown {
    color: #64748b !important;
}

@media (max-width: 880px) {
    .sensor-connectivity-card {
        grid-column: 1 / -1;
    }

    .sensor-connectivity-grid {
        grid-template-columns: repeat(2, minmax(140px, 1fr));
    }
}

@media (max-width: 520px) {
    .sensor-connectivity-grid {
        grid-template-columns: 1fr;
    }
}

.chart-visual {
    display: flex;
    gap: 12px;
    align-items: stretch;
    width: 100%;
}

.chart-y-axis {
    position: relative;
    width: 80px;
    font-size: 12px;
    color: #475467;
    padding-right: 8px;
}

.chart-y-axis span {
    position: absolute;
    right: 0;
    transform: translateY(-50%);
    white-space: nowrap;
}

.chart-svg-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.chart-gridline {
    stroke: rgba(148, 163, 184, 0.4);
    stroke-width: 1;
    stroke-dasharray: 4 4;
}

.chart-gridline-vertical {
    stroke: rgba(148, 163, 184, 0.35);
    stroke-width: 1;
    stroke-dasharray: 4 4;
}

.chart-comfort {
    fill: rgba(52, 211, 153, 0.15);
}

.chart-comfort-line {
    stroke: rgba(16, 185, 129, 0.8);
    stroke-width: 1.5;
    stroke-dasharray: 6 3;
}

.chart-axis-time {
    position: relative;
    margin-top: 6px;
    min-height: 18px;
    font-size: 12px;
    color: #475467;
    padding: 0 18px;
    width: 100%;
    box-sizing: border-box;
}

.chart-axis-time span {
    position: absolute;
    transform: translateX(-50%);
    white-space: nowrap;
}

.chart-svg {
    width: 100%;
    height: 100%;
    display: block;
}

.chart-time-label {
    fill: #475467;
    font-size: 11px;
}

.chart-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    list-style: none;
    padding: 0;
    margin: 0 0 8px;
}

.chart-legend li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #475467;
}

.chart-legend .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.chart-legend li.level-poor .dot {
    background: #dc2626;
}

.chart-legend li.level-weak .dot {
    background: #f97316;
}

.chart-legend li.level-good .dot {
    background: #22c55e;
}

.chart-legend li.level-strong .dot {
    background: #0ea5e9;
}

.chart-legend small {
    display: block;
    color: #94a3b8;
    font-size: 11px;
}

.wifi-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 12px;
    border: 1px solid #dbeafe;
    border-radius: 10px;
    background: linear-gradient(90deg, rgba(59,130,246,0.08), rgba(59,130,246,0.02));
}

.wifi-status p {
    margin: 0;
    font-size: 12px;
    color: #475467;
}

.wifi-status strong {
    font-size: 20px;
    color: #0f172a;
}

.wifi-quality {
    display: flex;
    flex-direction: column;
    font-weight: 600;
    font-size: 14px;
    color: #0f172a;
}

.wifi-quality small {
    font-weight: 400;
    color: #475467;
}

.wifi-quality.level-poor {
    color: #dc2626;
}

.wifi-quality.level-weak {
    color: #f97316;
}

.wifi-quality.level-good {
    color: #16a34a;
}

.wifi-quality.level-strong {
    color: #0ea5e9;
}

.wifi-timestamp {
    font-size: 13px;
    color: #475467;
}

.chart-visual-wifi .chart-y-axis {
    width: 90px;
}

.chart-svg-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.wifi-bands {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.wifi-band {
    position: absolute;
    left: 0;
    width: 100%;
    opacity: 0.22;
    border-top: 1px dashed rgba(255, 255, 255, 0.35);
}

.wifi-band em {
    position: absolute;
    left: 12px;
    top: 6px;
    font-style: normal;
    font-size: 11px;
    color: #111827;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
}

.chart-svg {
    width: 100%;
    height: 100%;
    display: block;
    position: relative;
    z-index: 2;
}

.chart-latest-dot {
    fill: #0ea5e9;
    stroke: #fff;
    stroke-width: 2;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    margin-top: 12px;
}

.pagination span {
    font-size: 14px;
    color: #475467;
}

.events-wrapper {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.events-tabs {
    display: inline-flex;
    gap: 8px;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 999px;
    align-self: flex-start;
}

.events-tabs .tab {
    padding: 8px 16px;
    border-radius: 999px;
    text-decoration: none;
    color: #475467;
    font-weight: 600;
}

.events-tabs .tab.active {
    background: #0f172a;
    color: #fff;
}

.events-filters {
    background: #fff;
    border: 1px solid #e4e7ec;
    border-radius: 16px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.events-filters .filter-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.events-filters label {
    font-size: 14px;
    color: #475467;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.events-filters input[type="text"],
.events-filters select {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
}

.events-filters input[type="datetime-local"] {
    width: 100%;
    max-width: 230px;
    min-height: 38px;
    padding: 6px 10px;
    border: 1px solid #d0d5dd;
    border-radius: 10px;
    background: #fff;
    font-size: 14px;
    color: #0f172a;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.filter-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.events-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #e4e7ec;
    border-radius: 16px;
    overflow: hidden;
}

.events-table th {
    background: #f8fafc;
    text-align: left;
    padding: 12px 14px;
    font-size: 13px;
    color: #475467;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.events-table td {
    padding: 12px 14px;
    border-top: 1px solid #e4e7ec;
    vertical-align: top;
    font-size: 14px;
}

.events-table tr:nth-child(even) td {
    background: #fcfdff;
}

.mono {
    font-family: 'Fira Code', Consolas, monospace;
    font-size: 13px;
}

.payload {
    max-height: 160px;
    overflow: auto;
    background: #0f172a;
    color: #e2e8f0;
    padding: 10px;
    border-radius: 10px;
    font-size: 12px;
}

.muted {
    color: #94a3b8;
}

.per-page-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pager-links {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* Person detail */
.person-directory {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.person-search-panel {
    display: grid;
    grid-template-columns: minmax(280px, 1.4fr) minmax(420px, 1fr);
    gap: 20px;
    align-items: end;
    padding: 18px;
    border: 1px solid #dbe3ef;
    border-radius: 16px;
    background: linear-gradient(135deg, #f8fafc 0%, #fff 70%);
}

.person-search-panel label {
    display: flex;
    flex-direction: column;
    gap: 7px;
    color: #344054;
    font-size: 13px;
    font-weight: 600;
}

.person-search-panel input,
.person-search-panel select {
    width: 100%;
}

.person-search-main input {
    min-height: 46px;
    border-color: #94a3b8;
    font-size: 15px;
}

.person-search-main small {
    color: #64748b;
    font-weight: 400;
}

.person-search-filters {
    display: grid;
    grid-template-columns: repeat(3, minmax(120px, 1fr)) auto;
    gap: 10px;
    align-items: end;
}

.person-directory-summary {
    display: flex;
    align-items: baseline;
    gap: 7px;
    color: #64748b;
    font-size: 14px;
}

.person-directory-summary strong {
    color: #0f172a;
    font-size: 21px;
}

.person-directory-table table {
    min-width: 860px;
}

.person-directory-table td {
    vertical-align: middle;
}

.person-card-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 360px;
}

.person-card-chip {
    display: inline-flex;
    flex-direction: column;
    gap: 1px;
    padding: 5px 9px;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    background: #f8fafc;
    color: #334155;
    font-family: 'Fira Code', Consolas, monospace;
    font-size: 12px;
    line-height: 1.25;
}

.person-card-chip small {
    color: #64748b;
    font-size: 10px;
}

.person-empty-state {
    padding: 48px 20px !important;
    text-align: center;
}

.person-empty-state strong,
.person-empty-state span {
    display: block;
}

.person-empty-state span {
    margin-top: 5px;
    color: #64748b;
}

.person-detail {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.person-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.person-header .badge {
    margin-right: 6px;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 12px;
    color: #94a3b8;
    margin: 0 0 6px;
}

.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-panel {
    border: 1px solid #e4e7ec;
    border-radius: 16px;
    padding: 20px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.card-panel.light {
    background: #fdfdfd;
}

.card-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.card-panel-desc {
    color: #64748b;
    font-size: 14px;
    margin: 4px 0 0;
}

.person-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.person-create-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.8fr);
    gap: 20px;
}

.person-form-section {
    box-shadow: none;
}

.person-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
}

.pill-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid #cbd5f5;
    background: #f8fafc;
    font-size: 14px;
}

.pill input {
    margin: 0;
}

.card-slots {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
}

.card-slot-card {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 14px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.card-slot-card.is-active {
    border-color: #86efac;
    box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.08);
}

.card-slot-card header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.slot-label {
    font-weight: 600;
    color: #0f172a;
}

.card-slot-card input,
.card-slot-card select {
    width: 100%;
}

.form-actions.between {
    justify-content: space-between;
    width: 100%;
}

.extra-card-slots {
    margin-top: 14px;
    border-top: 1px solid #e2e8f0;
    padding-top: 12px;
}

.extra-card-slots summary {
    cursor: pointer;
    color: #475569;
    font-size: 14px;
    font-weight: 600;
}

.extra-card-slots[open] summary {
    margin-bottom: 14px;
}

.person-editor-actions {
    position: sticky;
    bottom: 10px;
    z-index: 4;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 13px 16px;
    border: 1px solid #dbe3ef;
    border-radius: 13px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(8px);
}

.hint {
    font-size: 13px;
    color: #94a3b8;
}

.access-table td {
    vertical-align: top;
}

.checkbox.switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding-top: 26px;
}

@media (max-width: 1050px) {
    .person-search-panel,
    .person-create-layout {
        grid-template-columns: 1fr;
    }

    .person-search-filters {
        grid-template-columns: repeat(3, minmax(130px, 1fr)) auto;
    }
}

@media (max-width: 720px) {
    .person-header,
    .person-editor-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .person-search-filters {
        grid-template-columns: 1fr;
    }

    .person-search-filters .btn,
    .person-editor-actions .section-actions,
    .person-editor-actions .btn {
        width: 100%;
    }
}

/* Administrators */
.admins-directory,
.admin-editor {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.superadmin-notice {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 15px 18px;
    border: 1px solid #fdba74;
    border-radius: 14px;
    background: linear-gradient(120deg, #fff7ed 0%, #fffbeb 100%);
    color: #7c2d12;
}

.superadmin-notice p {
    margin: 3px 0 0;
    color: #9a3412;
    font-size: 14px;
}

.superadmin-icon {
    display: grid;
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 11px;
    background: #ea580c;
    color: #fff;
}

.admins-filters {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(150px, 0.3fr) minmax(150px, 0.3fr) auto;
    gap: 12px;
    align-items: end;
    padding: 16px;
    border: 1px solid #dbe3ef;
    border-radius: 16px;
    background: #f8fafc;
}

.admins-filters label {
    display: flex;
    flex-direction: column;
    gap: 7px;
    color: #344054;
    font-size: 13px;
    font-weight: 600;
}

.admins-filters input,
.admins-filters select {
    width: 100%;
}

.admins-search input {
    min-height: 44px;
}

.admins-summary {
    display: flex;
    align-items: baseline;
    gap: 6px;
    color: #64748b;
}

.admins-summary strong {
    color: #0f172a;
    font-size: 21px;
}

.admins-table {
    min-width: 850px;
}

.admins-table td {
    vertical-align: middle;
}

.admins-table tr.is-superadmin td {
    background: #fffaf3;
}

.admin-identity {
    display: flex;
    align-items: center;
    gap: 11px;
}

.admin-avatar {
    display: grid;
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 10px;
    background: #e2e8f0;
    color: #334155;
    font-weight: 700;
}

.admin-avatar.protected {
    background: #ffedd5;
    color: #c2410c;
}

.admin-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 3px;
    color: #64748b;
    font-size: 12px;
}

.admin-meta span + span::before {
    content: '·';
    margin-right: 5px;
}

.admin-protected-label {
    color: #c2410c;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.admin-empty-state {
    padding: 44px 20px !important;
    color: #64748b;
    text-align: center;
}

.admin-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.admin-form-section {
    padding: 18px;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    background: #fdfdfd;
}

.admin-form-grid {
    display: grid;
    grid-template-columns: minmax(240px, 1.2fr) minmax(260px, 1fr) minmax(190px, 0.6fr);
    gap: 18px;
    align-items: end;
}

.admin-form-grid.two-columns {
    grid-template-columns: repeat(2, minmax(240px, 1fr));
}

.admin-active-switch {
    min-height: 42px;
    padding-top: 0 !important;
}

@media (max-width: 980px) {
    .admins-filters,
    .admin-form-grid,
    .admin-form-grid.two-columns {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 640px) {
    .admins-filters,
    .admin-form-grid,
    .admin-form-grid.two-columns {
        grid-template-columns: 1fr;
    }

    .superadmin-notice {
        align-items: flex-start;
    }
}

@media (max-width: 900px) {
    .topbar {
        align-items: stretch;
        flex-wrap: wrap;
        padding: 12px max(14px, env(safe-area-inset-right)) 12px max(14px, env(safe-area-inset-left));
    }

    .desktop-nav {
        display: none;
    }

    .mobile-nav {
        display: block;
        margin-left: auto;
    }

    .mobile-nav summary {
        min-width: 76px;
        min-height: 44px;
        box-sizing: border-box;
        padding: 11px 14px;
        border: 1px solid rgba(255, 255, 255, 0.35);
        border-radius: 8px;
        cursor: pointer;
        font-weight: 700;
        list-style: none;
        text-align: center;
    }

    .mobile-nav summary::-webkit-details-marker {
        display: none;
    }

    .mobile-nav[open] {
        width: 100%;
        margin-top: 10px;
    }

    .mobile-nav[open] summary {
        margin-left: auto;
    }

    .mobile-nav nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 4px;
        margin-top: 10px;
    }

    .mobile-nav a {
        display: flex;
        min-height: 44px;
        align-items: center;
        padding: 7px 10px;
        border-radius: 7px;
        color: #fff;
        text-decoration: none;
        font-weight: 600;
    }

    .mobile-nav a:focus-visible,
    .mobile-nav summary:focus-visible {
        outline: 3px solid #93c5fd;
        outline-offset: 2px;
    }

    .content {
        width: auto;
        margin: 12px;
        padding: 16px;
        border-radius: 8px;
    }

    .doors-overview-table,
    .doors-overview-table tbody,
    .doors-overview-table tr,
    .doors-overview-table td {
        display: block;
        width: auto !important;
    }

    .doors-overview-table thead {
        display: none;
    }

    .doors-overview-table tr {
        margin-bottom: 14px;
        padding: 12px;
        border: 1px solid #dbe3ef;
        border-radius: 14px;
        background: #fff;
        box-shadow: 0 8px 22px rgba(15, 23, 42, 0.07);
    }

    table.doors-overview-table td {
        padding: 10px 0;
        border: 0;
        border-bottom: 1px solid #eef2f7;
        font-size: 13px;
    }

    .doors-overview-table td::before {
        display: block;
        margin-bottom: 6px;
        color: #64748b;
        font-size: 11px;
        font-weight: 700;
    }

    .doors-overview-table td:nth-child(1)::before { content: 'Kod'; }
    .doors-overview-table td:nth-child(2)::before { content: 'Drzwi'; }
    .doors-overview-table td:nth-child(3)::before { content: 'Timery'; }
    .doors-overview-table td:nth-child(4)::before { content: 'Tryb i sieć'; }
    .doors-overview-table td:nth-child(5)::before { content: 'Wejścia DI'; }
    .doors-overview-table td:nth-child(6)::before { content: 'Przekaźniki'; }
    .doors-overview-table td:nth-child(7)::before { content: 'Status'; }
    .doors-overview-table td:nth-child(8)::before { content: 'Akcje'; }

    table.doors-overview-table td:last-child {
        border-bottom: 0;
    }

    .doors-overview-table .actions,
    .doors-overview-table .quick-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .doors-overview-table .actions .btn.small,
    .doors-overview-table .quick-actions .btn.small {
        min-height: 44px;
        padding: 8px 10px;
        font-size: 13px;
    }
}

.push-notifications {
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.push-notifications[aria-pressed="true"] {
    border-color: #86efac;
    color: #bbf7d0;
}

.push-notifications:disabled {
    cursor: wait;
    opacity: 0.6;
}

.push-notifications:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

@media (max-width: 900px) {
    .push-notifications {
        order: 3;
        width: 100%;
        min-height: 44px;
        margin-top: 8px;
    }
}

@media (max-width: 480px) {
    .app-name {
        display: none;
    }

    .mobile-nav nav {
        grid-template-columns: 1fr;
    }

    .content {
        margin: 8px;
        padding: 12px;
    }
}

/* Operational application shell and mobile incident center */
:root {
    --kd-ink: #17212b;
    --kd-muted: #5f6f7e;
    --kd-canvas: #eef2f5;
    --kd-surface: #ffffff;
    --kd-line: #d8e0e7;
    --kd-navy: #10283c;
    --kd-navy-soft: #1b3a50;
    --kd-blue: #1463d6;
    --kd-blue-dark: #0d4fae;
    --kd-green: #167449;
    --kd-green-soft: #e5f5ed;
    --kd-amber: #a65308;
    --kd-amber-soft: #fff1dc;
    --kd-red: #b4232f;
    --kd-red-dark: #861922;
    --kd-red-soft: #fde8e9;
    --kd-radius: 14px;
    --kd-shadow: 0 14px 40px rgba(16, 40, 60, 0.09);
}

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

html {
    background: var(--kd-canvas);
    color-scheme: light;
    scroll-behavior: smooth;
}

body {
    min-width: 320px;
    min-height: 100dvh;
    background: var(--kd-canvas);
    color: var(--kd-ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.45;
}

::selection {
    background: #bed8ff;
    color: #0a2440;
}

a,
button,
input,
select,
summary {
    -webkit-tap-highlight-color: rgba(20, 99, 214, 0.16);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
    outline: 3px solid #68a7ff;
    outline-offset: 3px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: 68px;
    padding: 12px max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
    background: var(--kd-navy);
    box-shadow: 0 8px 24px rgba(8, 27, 42, 0.18);
}

.logo-title {
    min-width: 0;
}

.logo {
    width: auto;
    height: 32px;
}

.app-name {
    color: #dbe9f3;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .025em;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-shell {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    width: min(1600px, 100%);
    min-height: calc(100dvh - 68px);
    margin: 0 auto;
}

.side-navigation {
    padding: 28px 16px 40px;
    border-right: 1px solid var(--kd-line);
    background: #f7f9fb;
}

.side-navigation nav {
    position: sticky;
    top: 94px;
    display: grid;
    gap: 3px;
}

.nav-group-title {
    margin: 20px 12px 6px;
    color: #758494;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.nav-group-title:first-child {
    margin-top: 0;
}

.side-navigation a {
    display: flex;
    min-height: 42px;
    align-items: center;
    padding: 9px 12px;
    border-radius: 10px;
    color: #33475a;
    font-size: 14px;
    font-weight: 650;
    text-decoration: none;
}

.side-navigation a:hover {
    background: #e8eef3;
    color: var(--kd-navy);
}

.side-navigation a[aria-current="page"] {
    background: #dce9f8;
    color: #0b4e93;
    font-weight: 800;
}

.content {
    width: min(1320px, calc(100% - 48px));
    max-width: none;
    min-width: 0;
    margin: 26px auto 48px;
    padding: 28px;
    border: 1px solid rgba(205, 216, 225, .8);
    border-radius: var(--kd-radius);
    background: var(--kd-surface);
    box-shadow: var(--kd-shadow);
}

.footer {
    padding-bottom: 28px;
}

h1,
h2,
h3,
p {
    overflow-wrap: anywhere;
}

h1 {
    margin: 0 0 8px;
    color: #101b25;
    font-size: clamp(27px, 3vw, 38px);
    line-height: 1.12;
    letter-spacing: -.025em;
}

h2 {
    color: #17212b;
    line-height: 1.2;
}

.section-header,
.person-header,
.relay-workspace-header,
.card-panel-header {
    gap: 18px;
}

.section-header > div:first-child > p,
.person-header > div:first-child > p {
    max-width: 68ch;
    color: var(--kd-muted);
}

.btn,
button,
input,
select,
textarea {
    min-height: 44px;
    border-radius: 10px;
}

.btn,
button {
    font: inherit;
    transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, transform 120ms ease;
}

.btn:active,
button:active {
    transform: scale(.985);
}

.btn.primary,
button.primary {
    background: var(--kd-blue);
}

.btn.primary:hover,
button.primary:hover {
    background: var(--kd-blue-dark);
}

.btn.danger,
button.danger {
    background: var(--kd-red);
}

.btn.small {
    min-height: 38px;
    padding: 8px 11px;
    font-size: 13px;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #bfcbd5;
    background: #fff;
    color: var(--kd-ink);
    font: inherit;
}

input::placeholder,
textarea::placeholder {
    color: #6a7886;
    opacity: 1;
}

.flash {
    border: 1px solid #b9d6fb;
    border-radius: 10px;
    background: #eaf3ff;
    color: #123d70;
    font-weight: 650;
}

.mobile-bottom-navigation {
    display: none;
}

.side-navigation a.nav-critical {
    color: #9f2430;
}

.side-navigation a.nav-critical[aria-current="page"] {
    background: var(--kd-red-soft);
    color: var(--kd-red-dark);
}

.mobile-nav a.nav-critical {
    color: #ffd9dd;
}

.mobile-nav a.nav-critical[aria-current="page"] {
    background: #64313a;
    color: #fff;
}

/* Alert center */
.alert-center,
.incident-detail {
    max-width: 980px;
    margin: 0 auto;
}

.alert-center-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 22px;
    margin-bottom: 24px;
}

.alert-center-header p {
    margin: 0;
    color: var(--kd-muted);
    font-size: 16px;
}

.alert-open-count {
    display: flex;
    min-width: 118px;
    min-height: 72px;
    flex-direction: column;
    justify-content: center;
    padding: 10px 16px;
    border-radius: 12px;
    background: #edf1f4;
    color: #566675;
    text-align: center;
}

.alert-open-count.has-alerts.severity-critical {
    background: var(--kd-red-soft);
    color: var(--kd-red-dark);
}

.alert-open-count.has-alerts.severity-warning,
.alert-open-count.has-alerts.severity-attention {
    background: var(--kd-amber-soft);
    color: #7c3b06;
}

.alert-open-count strong {
    font-size: 28px;
    line-height: 1;
}

.alert-open-count span {
    margin-top: 5px;
    font-size: 12px;
    font-weight: 750;
}

.alert-filters {
    display: inline-grid;
    grid-template-columns: repeat(3, auto);
    gap: 4px;
    margin-bottom: 22px;
    padding: 4px;
    border-radius: 12px;
    background: #e9eef2;
}

.alert-filters a {
    min-height: 40px;
    padding: 10px 15px;
    border-radius: 9px;
    color: #405364;
    font-size: 14px;
    font-weight: 750;
    text-decoration: none;
}

.alert-filters a.active {
    background: #fff;
    color: #113d68;
    box-shadow: 0 3px 10px rgba(16, 40, 60, .11);
}

.alert-list {
    display: grid;
    gap: 12px;
}

.alert-card {
    display: grid;
    grid-template-columns: 16px minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    min-height: 112px;
    padding: 18px 20px;
    border: 1px solid var(--kd-line);
    border-radius: 14px;
    background: #fff;
    color: var(--kd-ink);
    text-decoration: none;
    box-shadow: 0 7px 22px rgba(16, 40, 60, .06);
    transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
}

.alert-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 30px rgba(16, 40, 60, .1);
}

.alert-card-symbol {
    width: 14px;
    height: 52px;
    border-radius: 7px;
    background: var(--kd-amber);
}

.alert-card.severity-critical .alert-card-symbol {
    background: var(--kd-red);
}

.alert-card.severity-warning .alert-card-symbol {
    background: #dd6b12;
}

.alert-card.is-handled {
    background: #f6f8f9;
    box-shadow: none;
    opacity: .78;
}

.alert-card-main {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.alert-card-title {
    color: var(--kd-red-dark);
    font-size: 13px;
    font-weight: 850;
    letter-spacing: .025em;
    text-transform: uppercase;
}

.severity-attention .alert-card-title {
    color: var(--kd-amber);
}

.severity-warning .alert-card-title {
    color: #9a4607;
}

.alert-card-main strong {
    font-size: 20px;
    line-height: 1.2;
}

.alert-card-summary {
    color: var(--kd-muted);
    font-size: 14px;
}

.alert-card-meta {
    display: grid;
    min-width: 145px;
    justify-items: end;
    gap: 6px;
    color: var(--kd-muted);
    font-size: 12px;
}

.repeat-count,
.handled-label,
.open-label {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    padding: 5px 9px;
    border-radius: 8px;
    background: #edf1f4;
    color: #4c5f70;
    font-weight: 750;
}

.open-label {
    background: #dceafb;
    color: #0b519a;
}

.alert-refresh-note,
.state-freshness {
    margin: 18px 0 0;
    color: #6a7886;
    font-size: 12px;
    text-align: center;
}

.alert-empty-state {
    padding: 54px 24px;
    border: 1px solid var(--kd-line);
    border-radius: 14px;
    background: #f7faf8;
    text-align: center;
}

.alert-empty-symbol {
    width: 42px;
    height: 42px;
    margin: 0 auto 18px;
    border: 10px solid #cce8d9;
    border-radius: 50%;
    background: var(--kd-green);
}

.alert-empty-state h2 {
    margin: 0 0 7px;
    font-size: 22px;
}

.alert-empty-state p {
    margin: 0;
    color: var(--kd-muted);
}

/* Incident detail */
.incident-back {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    margin-bottom: 18px;
    color: #174f82;
    font-weight: 750;
    text-decoration: none;
}

.incident-hero {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 20px;
    padding: 28px;
    border-radius: 16px;
    background: var(--kd-amber-soft);
}

.severity-critical .incident-hero {
    background: var(--kd-red-soft);
}

.severity-warning .incident-hero {
    background: #fff0df;
}

.incident-symbol {
    width: 18px;
    min-height: 112px;
    border-radius: 9px;
    background: var(--kd-amber);
}

.severity-critical .incident-symbol {
    background: var(--kd-red);
}

.severity-warning .incident-symbol {
    background: #dd6b12;
}

.incident-priority {
    margin: 0 0 9px;
    color: var(--kd-red-dark);
    font-size: 13px;
    font-weight: 900;
    letter-spacing: .06em;
}

.severity-attention .incident-priority {
    color: var(--kd-amber);
}

.severity-warning .incident-priority {
    color: #8d4006;
}

.incident-hero h1 {
    font-size: clamp(31px, 5vw, 48px);
}

.incident-summary {
    max-width: 60ch;
    margin: 10px 0 0;
    color: #3c4e5e;
    font-size: 18px;
}

.incident-location {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 22px 6px;
    border-bottom: 1px solid var(--kd-line);
}

.incident-location span,
.incident-location time {
    color: var(--kd-muted);
    font-size: 13px;
}

.incident-location strong {
    font-size: 20px;
}

.live-door-state {
    padding: 24px 0;
}

.live-door-state h2 {
    margin: 0 0 14px;
    font-size: 19px;
}

.live-state-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.live-state-item {
    display: grid;
    gap: 4px;
    min-height: 82px;
    align-content: center;
    padding: 13px;
    border-radius: 12px;
    background: #edf1f4;
}

.live-state-item span {
    color: #647484;
    font-size: 12px;
    font-weight: 700;
}

.live-state-item strong {
    font-size: 15px;
}

.live-state-item.state-ok {
    background: var(--kd-green-soft);
    color: #125e3d;
}

.live-state-item.state-ok span {
    color: #266448;
}

.live-state-item.state-danger {
    background: var(--kd-red-soft);
    color: var(--kd-red-dark);
}

.live-state-item.state-danger span {
    color: #7e2630;
}

.live-state-item.state-unknown span {
    color: #4d5d6c;
}

.incident-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 22px;
    border-radius: 14px;
    background: #f3f6f8;
}

.incident-actions form {
    margin: 0;
}

.incident-action {
    width: 100%;
    min-height: 60px;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 850;
}

.primary-action {
    background: var(--kd-blue);
}

.open-action {
    background: var(--kd-green);
}

.silence-action {
    background: var(--kd-red);
}

.incident-open-form {
    display: grid;
    gap: 8px;
}

.incident-open-form label {
    margin: 0;
    color: #536575;
    font-size: 13px;
    font-weight: 750;
}

.incident-open-form > div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(118px, .55fr);
    gap: 8px;
}

.incident-handled,
.incident-readonly {
    display: grid;
    gap: 4px;
    padding: 20px;
    border-radius: 14px;
    background: var(--kd-green-soft);
    color: #125e3d;
}

.incident-readonly {
    background: #edf1f4;
    color: #435565;
}

.incident-secondary-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 22px;
    margin-top: 20px;
}

.incident-secondary-actions a {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    color: #174f82;
    font-weight: 750;
}

.technical-details {
    margin-top: 10px;
}

.technical-details summary {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    color: #526575;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
}

@media (max-width: 900px) {
    .app-shell {
        display: block;
        min-height: auto;
    }

    .side-navigation {
        display: none;
    }

    .topbar {
        min-height: 62px;
        flex-wrap: nowrap;
        align-items: center;
    }

    .topbar-actions {
        margin-left: auto;
    }

    .mobile-nav {
        order: initial;
        margin-left: 0;
    }

    .mobile-nav[open] {
        position: fixed;
        z-index: 45;
        inset: 62px 10px auto;
        width: auto;
        max-height: calc(100dvh - 138px);
        margin: 0;
        padding: 10px;
        overflow-y: auto;
        border: 1px solid #2c485e;
        border-radius: 14px;
        background: var(--kd-navy);
        box-shadow: 0 18px 48px rgba(4, 20, 32, .35);
    }

    .mobile-nav[open] summary {
        margin-left: auto;
    }

    .mobile-nav nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .mobile-nav a[aria-current="page"] {
        background: #274a63;
    }

    .push-notifications {
        order: initial;
        width: auto;
        min-height: 44px;
        margin: 0;
        padding: 9px 11px;
        font-size: 12px;
    }

    .content {
        width: auto;
        margin: 12px 10px calc(92px + env(safe-area-inset-bottom));
        padding: 18px;
        border-radius: 14px;
    }

    .mobile-bottom-navigation {
        position: fixed;
        z-index: 35;
        right: 0;
        bottom: 0;
        left: 0;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        padding: 6px max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
        border-top: 1px solid #c7d2dc;
        background: rgba(255, 255, 255, .98);
        box-shadow: 0 -8px 28px rgba(16, 40, 60, .12);
    }

    .mobile-bottom-navigation a {
        display: flex;
        min-width: 0;
        min-height: 50px;
        align-items: center;
        justify-content: center;
        padding: 6px 3px;
        border-radius: 10px;
        color: #536575;
        font-size: 11px;
        font-weight: 750;
        line-height: 1.15;
        text-align: center;
        text-decoration: none;
    }

    .mobile-bottom-navigation a[aria-current="page"] {
        background: #dce9f8;
        color: #0b4e93;
    }

    .mobile-bottom-navigation a.nav-critical {
        color: #8f2832;
    }

    .mobile-bottom-navigation a.nav-critical[aria-current="page"] {
        background: var(--kd-red-soft);
        color: var(--kd-red-dark);
    }

    .footer {
        display: none;
    }

    .section-header.between,
    .person-header,
    .relay-workspace-header,
    .card-panel-header {
        align-items: stretch;
        flex-direction: column;
    }

    .section-actions,
    .form-actions,
    .person-editor-actions {
        width: 100%;
    }

    .section-actions .btn,
    .form-actions .btn,
    .form-actions button {
        flex: 1 1 auto;
    }

    .live-state-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .app-name {
        display: none;
    }

    .logo {
        width: 122px;
        height: auto;
    }

    .topbar {
        padding-right: max(10px, env(safe-area-inset-right));
        padding-left: max(10px, env(safe-area-inset-left));
    }

    .topbar-actions {
        gap: 6px;
    }

    .push-notifications {
        flex: 0 0 96px;
        width: 96px;
        max-width: 96px;
        padding-right: 8px;
        padding-left: 8px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .content {
        margin-right: 6px;
        margin-left: 6px;
        padding: 16px 14px;
        border-right: 0;
        border-left: 0;
        box-shadow: 0 8px 26px rgba(16, 40, 60, .07);
    }

    h1 {
        font-size: 28px;
    }

    .alert-center-header {
        align-items: stretch;
        flex-direction: column;
        gap: 14px;
    }

    .alert-open-count {
        min-height: 58px;
        flex-direction: row;
        align-items: center;
        gap: 9px;
        text-align: left;
    }

    .alert-open-count span {
        margin: 0;
    }

    .alert-filters {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
    }

    .alert-filters a {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 8px 5px;
        font-size: 12px;
        text-align: center;
    }

    .alert-card {
        grid-template-columns: 10px minmax(0, 1fr);
        gap: 12px;
        padding: 16px 14px;
    }

    .alert-card-symbol {
        width: 10px;
        height: 100%;
        min-height: 70px;
    }

    .alert-card-main strong {
        font-size: 19px;
    }

    .alert-card-meta {
        grid-column: 2;
        grid-template-columns: minmax(0, 1fr) auto;
        width: 100%;
        min-width: 0;
        justify-items: start;
        align-items: center;
        margin-top: 4px;
    }

    .alert-card-meta .repeat-count {
        display: none;
    }

    .open-label,
    .handled-label {
        justify-self: end;
    }

    .incident-hero {
        grid-template-columns: 12px minmax(0, 1fr);
        gap: 14px;
        padding: 20px 16px;
    }

    .incident-detail {
        display: flex;
        flex-direction: column;
    }

    .incident-back { order: 1; }
    .incident-hero { order: 2; }
    .incident-location { order: 3; }
    .incident-actions,
    .incident-handled,
    .incident-readonly { order: 4; }
    .live-door-state { order: 5; }
    .incident-secondary-actions { order: 6; }

    .incident-actions {
        margin-top: 18px;
    }

    .incident-symbol {
        width: 10px;
        min-height: 130px;
    }

    .incident-hero h1 {
        font-size: 33px;
    }

    .incident-summary {
        font-size: 17px;
    }

    .incident-location {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .incident-location strong {
        font-size: 21px;
    }

    .incident-actions {
        grid-template-columns: 1fr;
        padding: 14px;
    }

    .incident-action {
        min-height: 64px;
        font-size: 18px;
    }

    .incident-secondary-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .mobile-nav nav {
        grid-template-columns: 1fr;
    }

    .events-table,
    .events-table tbody,
    .events-table tr,
    .events-table td {
        display: block;
        width: 100%;
    }

    .events-table thead {
        display: none;
    }

    table.events-table tr {
        margin-bottom: 14px;
        padding: 10px 14px;
        border: 1px solid var(--kd-line);
        border-radius: 12px;
        background: #fff;
    }

    table.events-table td {
        padding: 9px 0;
        border: 0;
        border-bottom: 1px solid #e6ecf1;
    }

    table.events-table td:last-child {
        border-bottom: 0;
    }

    .events-table td::before {
        display: block;
        margin-bottom: 3px;
        color: #677887;
        font-size: 11px;
        font-weight: 800;
        text-transform: uppercase;
    }

    .events-table-bell td:nth-child(1)::before,
    .events-table-alarms td:nth-child(1)::before,
    .events-table-actions td:nth-child(1)::before { content: 'Data'; }
    .events-table-bell td:nth-child(2)::before,
    .events-table-alarms td:nth-child(2)::before,
    .events-table-actions td:nth-child(2)::before { content: 'Drzwi'; }
    .events-table-bell td:nth-child(3)::before { content: 'Zgłoszenie'; }
    .events-table-alarms td:nth-child(3)::before { content: 'Komunikat'; }
    .events-table-alarms td:nth-child(4)::before { content: 'Szczegóły'; }
    .events-table-actions td:nth-child(3)::before { content: 'Firma'; }
    .events-table-actions td:nth-child(4)::before { content: 'Pracownik'; }
    .events-table-actions td:nth-child(5)::before { content: 'Karta'; }
    .events-table-actions td:nth-child(6)::before { content: 'Dostęp'; }
    .events-table-actions td:nth-child(7)::before { content: 'Zdarzenie'; }
    .events-table-actions td:nth-child(8)::before { content: 'ESP'; }
    .events-table-actions td:nth-child(9)::before { content: 'Offline'; }

    .events-table .payload {
        max-height: 210px;
        overflow: auto;
        white-space: pre-wrap;
    }

    .mobile-card-table,
    .mobile-card-table tbody,
    .mobile-card-table tr,
    .mobile-card-table td {
        display: block;
        width: 100%;
    }

    .mobile-card-table thead {
        display: none;
    }

    table.mobile-card-table tr {
        margin-bottom: 14px;
        padding: 10px 14px;
        border: 1px solid var(--kd-line);
        border-radius: 12px;
        background: #fff;
    }

    table.mobile-card-table td {
        padding: 9px 0;
        border: 0;
        border-bottom: 1px solid #e6ecf1;
    }

    table.mobile-card-table td:last-child {
        border-bottom: 0;
    }

    .mobile-card-table td::before {
        display: block;
        margin-bottom: 3px;
        color: #677887;
        font-size: 11px;
        font-weight: 800;
        text-transform: uppercase;
    }

    .companies-table td:nth-child(1)::before,
    .categories-table td:nth-child(1)::before { content: 'Nazwa'; }
    .companies-table td:nth-child(2)::before,
    .locations-table td:nth-child(3)::before,
    .categories-table td:nth-child(3)::before,
    .persons-table td:nth-child(4)::before,
    .admins-table td:nth-child(3)::before { content: 'Status'; }
    .companies-table td:nth-child(3)::before,
    .locations-table td:nth-child(4)::before,
    .admins-table td:nth-child(4)::before { content: 'Utworzono'; }
    .companies-table td:nth-child(4)::before,
    .locations-table td:nth-child(5)::before,
    .categories-table td:nth-child(4)::before,
    .persons-table td:nth-child(5)::before,
    .admins-table td:nth-child(5)::before { content: 'Akcje'; }
    .locations-table td:nth-child(1)::before { content: 'Nazwa'; }
    .locations-table td:nth-child(2)::before { content: 'Adres'; }
    .categories-table td:nth-child(2)::before { content: 'Opis'; }
    .persons-table td:nth-child(1)::before { content: 'Osoba'; }
    .persons-table td:nth-child(2)::before { content: 'Firma'; }
    .persons-table td:nth-child(3)::before { content: 'Karty'; }
    .admins-table td:nth-child(1)::before { content: 'Konto'; }
    .admins-table td:nth-child(2)::before { content: 'Rola'; }

    .mobile-card-table .actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .mobile-card-table .actions .btn,
    .mobile-card-table .actions button {
        width: 100%;
        min-height: 44px;
    }
}

@media (max-width: 900px) {
    .doors-overview-table tr[id^="door-"] {
        scroll-margin-top: 76px;
    }

    .doors-overview-table td.door-mode-cell::before {
        display: none;
    }

    table.doors-overview-table td.door-mode-cell {
        padding-top: 14px;
        padding-bottom: 14px;
    }

    .door-mode-overview {
        gap: 12px;
    }

    .door-current-mode {
        gap: 5px;
        padding: 15px;
        border-radius: 13px;
    }

    .door-current-mode-label {
        font-size: 11px;
    }

    .door-current-mode strong {
        font-size: 21px;
        letter-spacing: -.015em;
    }

    .door-current-mode p {
        max-width: 42ch;
        font-size: 14px;
        line-height: 1.4;
    }

    .door-mode-source {
        margin-top: 3px;
        padding: 5px 8px;
        font-size: 11px;
    }

    .door-mode-actions {
        gap: 9px;
    }

    .door-mode-actions-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .door-mode-actions-heading strong {
        font-size: 16px;
    }

    .door-mode-actions-heading span {
        font-size: 12px;
        text-align: left;
    }

    .door-mode-action {
        min-height: 66px;
        padding: 10px 11px;
        border-radius: 11px;
    }

    .door-mode-action strong {
        font-size: 14px;
    }

    .door-mode-action small {
        font-size: 11px;
    }

    .door-mode-action b {
        padding: 4px 6px;
        font-size: 9px;
    }

    .door-mode-override-clear button,
    .door-active-alarm-action button {
        min-height: 52px;
        padding: 11px 14px;
        border-radius: 11px;
        font-size: 14px;
    }

    .door-lock-line {
        padding: 8px 10px;
        font-size: 11px;
    }

    .door-lock-line strong {
        font-size: 11px;
    }
}

@media (pointer: coarse) {
    .door-mode-action {
        min-height: 66px;
    }
}

@media (max-width: 360px) {
    .logo {
        width: 108px;
    }

    .push-notifications {
        flex-basis: 90px;
        width: 90px;
        max-width: 90px;
        font-size: 11px;
    }

    .incident-hero h1 {
        overflow-wrap: normal;
        font-size: 28px;
        word-break: normal;
    }

    .door-mode-actions {
        grid-template-columns: 1fr;
    }

    .door-mode-form.mode-form-3 {
        grid-column: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0s !important;
        transition-duration: 0s !important;
    }
}
