/* === WaterMonitor MD3 theme (KAN-9) === */

:root {
    --md-primary: #2563EB;
    --md-primary-hover: #1D4ED8;
    --md-surface: #FFFFFF;
    --md-background: #F3F7FC;
    --md-sidebar-start: #052767;
    --md-sidebar-end: #3a0647;
    --md-online: #16A34A;
    --md-alert: #F59E0B;
    --md-offline: #DC2626;
    --md-radius: 8px;
    --md-shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.06);
    --md-space-1: 8px;
    --md-space-2: 16px;
    --md-space-3: 24px;
    --wm-topbar-height: 64px;
    --navy: #0F172A;
    --navy-light: #1E293B;
    --steel: var(--md-primary);
    --steel-light: var(--md-primary-hover);
    --white: #ffffff;
    --gray-50: #F8FAFC;
    --gray-100: var(--md-background);
    --gray-200: #E2E8F0;
    --gray-300: #CBD5E1;
    --gray-600: #64748B;
    --green: var(--md-online);
    --amber: var(--md-alert);
    --red: var(--md-offline);
    --font-sans: "Inter", "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "Inter", "Roboto", ui-sans-serif, sans-serif;
}

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

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    color: #1E293B;
    background: var(--md-background);
}

h1, h2, h3, h4 {
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--navy);
    margin: 0 0 0.75rem 0;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; margin-top: 1.5rem; }

a { color: var(--steel); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Layout === */
.page.md-shell {
    display: grid;
    min-height: 100vh;
    grid-template-columns: 250px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "sidebar top"
        "sidebar main";
}
.page.md-shell.sidebar-collapsed {
    grid-template-columns: 76px 1fr;
}

.sidebar {
    --md-nav-bg: #F1F3F7;
    --md-nav-icon: #475569;
    --md-nav-selected-bg: #DDE3F1;
    --md-nav-selected: #152B55;
    grid-area: sidebar;
    width: auto;
    background: var(--md-nav-bg);
    color: var(--md-nav-icon);
    position: sticky;
    top: 0;
    height: 100vh;
    align-self: start;
    overflow: visible;
    border-right: 1px solid #E2E8F0;
    transition: width 0.2s ease;
}

.shell-top {
    grid-area: top;
}

.shell-main,
main.shell-main {
    grid-area: main;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.top-row {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    min-height: var(--wm-topbar-height);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 60;
}

.content {
    padding: 1.5rem;
    flex: 1;
}

.user-info {
    font-size: 0.85rem;
    color: var(--gray-600);
}

/* === Navigation === */
.navbar-brand {
    color: var(--white) !important;
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: bold;
    letter-spacing: 1px;
}

.nav-item { padding: 0.15rem 0; }
.nav-item:first-of-type { padding-top: 0.5rem; }

.nav-link {
    color: #b0bec5 !important;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.85rem;
    display: block;
    transition: background 0.15s;
}

.nav-link:hover { background: rgba(255,255,255,0.08); color: var(--white) !important; }
.nav-link.active { background: rgba(255,255,255,0.15); color: var(--white) !important; }

.navbar-toggler { display: none; }
.nav-scrollable { display: block; padding: 0 0.5rem; }
.top-row.ps-3.navbar { padding: 0.75rem 1rem; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--md-radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary { background: var(--md-primary); color: var(--white); }
.btn-primary:hover { background: var(--md-primary-hover); }

.btn-secondary { background: var(--gray-200); color: #333; }
.btn-secondary:hover { background: var(--gray-300); }

.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { background: #c82333; }

.btn-ok { background: var(--green); color: var(--white); }
.btn-ok:hover { background: #218838; }

.btn-warning { background: var(--amber); color: #333; }
.btn-warning:hover { background: #e0a800; }

.btn-logout { background: transparent; color: var(--gray-600); border: 1px solid var(--gray-300); }
.btn-logout:hover { background: var(--gray-100); }

.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: transparent;
    border: none;
    color: var(--steel);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.25rem 0;
    margin-bottom: 0.75rem;
}

.btn-back:hover {
    color: var(--steel-light);
}

.btn-back i {
    font-size: 1.25rem;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Tables === */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin: 0.75rem 0;
}

.data-table th {
    background: var(--navy);
    color: var(--white);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.6rem 0.75rem;
    text-align: left;
}

.data-table td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.85rem;
}

.data-table tbody tr:nth-child(even) { background: var(--gray-50); }
.data-table tbody tr:hover { background: #e8f0fe; }

.clickable-row { cursor: pointer; }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-ok { background: #d4edda; color: #155724; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-critical { background: #f8d7da; color: #721c24; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-unknown { background: var(--gray-200); color: var(--gray-600); }

/* === Connection Indicator === */
.connection-indicator {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--gray-600);
}

.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.dot-green { background: var(--green); }
.dot-yellow { background: var(--amber); }
.dot-red { background: var(--red); }

/* === Tank Cards === */
.tank-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--md-space-2);
    margin: var(--md-space-2) 0;
}

.switch-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--md-space-3);
    margin: var(--md-space-2) 0;
}

.switch-error {
    margin-top: 0.5rem;
    margin-bottom: 0;
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
}

/* === MD3 Devices cards (KAN-9) === */
.md-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--md-space-2);
    margin-bottom: var(--md-space-1);
}
.md-section-header h1,
.md-section-header h2 {
    margin: 0;
}
.md-add-device-btn {
    gap: 0.4rem;
    text-decoration: none;
}
a.md-add-device-btn:hover {
    text-decoration: none;
    color: var(--white);
}

.md-tank-card,
.md-switch-card {
    background: var(--md-surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--md-radius);
    box-shadow: var(--md-shadow);
    padding: var(--md-space-2);
    position: relative;
}

.md-tank-card {
    cursor: pointer;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.md-tank-card:hover {
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
}

.md-tank-card-top,
.md-switch-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--md-space-1);
    margin-bottom: var(--md-space-2);
}

.md-tank-identity,
.md-switch-identity {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    min-width: 0;
}

.md-icon-circle {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #EFF6FF;
    color: var(--md-primary);
}

.md-tank-titles,
.md-switch-titles {
    min-width: 0;
}
.md-device-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
    margin: 0 0 0.2rem;
}
.md-tank-titles h4,
.md-switch-titles h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}
.md-tank-desc {
    margin: 0;
    color: var(--gray-600);
    font-size: 0.8rem;
    line-height: 1.35;
}

.md-status-column {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
    margin-left: auto;
    flex-shrink: 0;
    text-align: right;
}
.md-status-column-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
}
.md-alert-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: #FEF3C7;
    color: #D97706;
    cursor: pointer;
}
.md-alert-icon-btn .lucide {
    pointer-events: none;
}
button.md-alert-icon-btn:hover {
    background: #FDE68A;
}
span.md-alert-icon-btn {
    cursor: help;
}

.md-status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    background: #F1F5F9;
    color: #475569;
}
.md-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94A3B8;
}
.md-status-chip.is-online { background: #DCFCE7; color: #166534; }
.md-status-chip.is-online .md-status-dot { background: var(--md-online); }
.md-status-chip.is-offline { background: #FEE2E2; color: #991B1B; }
.md-status-chip.is-offline .md-status-dot { background: var(--md-offline); }

.md-alert-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    height: 1.55rem;
    padding: 0 0.55rem;
    border: none;
    border-radius: 999px;
    background: #FEF3C7;
    color: #92400E;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
}
.md-alert-chip:hover { background: #FDE68A; }

.md-tank-viz {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 0.75rem;
    margin: var(--md-space-2) 0;
}
.md-tank-scale {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--gray-600);
    padding: 0.15rem 0;
}
.md-tank-container {
    width: 88px;
    height: 120px;
    border: 3px solid #94A3B8;
    border-radius: 0 0 14px 14px;
    border-top: none;
    position: relative;
    overflow: hidden;
    background: #F8FAFC;
}
.md-tank-container::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -8px;
    right: -8px;
    height: 6px;
    background: #94A3B8;
    border-radius: 2px;
}

.tank-water {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    transition: height 0.8s ease;
}
.level-ok .tank-water { background: linear-gradient(to top, #2563EB, #93C5FD); }
.level-critical .tank-water { background: linear-gradient(to top, #B91C1C, #F87171); }

.tank-wave {
    position: absolute;
    top: -4px;
    left: -10%;
    width: 120%;
    height: 8px;
    background: rgba(255,255,255,0.35);
    border-radius: 50%;
    animation: wave 2s ease-in-out infinite;
}
@keyframes wave {
    0%, 100% { transform: translateX(-5%); }
    50% { transform: translateX(5%); }
}

.tank-level-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: 700;
    font-size: 1rem;
    color: var(--navy);
    text-shadow: 0 0 4px rgba(255,255,255,0.95);
    z-index: 2;
}

.md-tank-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.md-tank-meta { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.md-actuator-chip {
    display: inline-flex;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: #DBEAFE;
    color: #1D4ED8;
    font-size: 0.75rem;
    font-weight: 600;
}
.md-tank-time {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--gray-600);
    font-size: 0.75rem;
}

.tank-edit-modal {
    max-width: 28rem;
    width: min(92vw, 28rem);
}

.md-switch-card {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.md-switch-state-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.25rem;
}
.md-material-switch {
    width: 46px;
    height: 28px;
    border-radius: 999px;
    border: none;
    background: #CBD5E1;
    padding: 3px;
    cursor: pointer;
    transition: background 0.15s ease;
}
.md-material-switch.is-on { background: var(--md-primary); }
.md-material-switch:disabled { opacity: 0.6; cursor: not-allowed; }
.md-material-switch-thumb {
    display: block;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
    transition: transform 0.15s ease;
}
.md-material-switch.is-on .md-material-switch-thumb { transform: translateX(18px); }
.md-switch-state-label {
    font-weight: 600;
    color: var(--navy);
}
.md-switch-id {
    margin: 0;
    color: var(--gray-600);
    font-size: 0.75rem;
    word-break: break-all;
}
/* Shell chrome — KAN-53 toolbar */
.md-top-row.tb-bar,
.tb-bar {
    display: flex !important;
    align-items: center;
    gap: 12px;
    background: #fff !important;
    border-bottom: 1px solid #e1e9f5;
    min-height: var(--wm-topbar-height);
    padding-top: 10px !important;
    padding-bottom: 10px !important;
    box-shadow: 0 7px 18px rgba(56, 90, 137, 0.06);
    position: sticky;
    top: 0;
    z-index: 60;
}
.tb-left,
.tb-right {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.tb-spacer { flex: 1; min-width: 8px; }
.tb-divider {
    width: 1px;
    height: 30px;
    background: #d8e3f1;
    flex: none;
}
.tb-relative { position: relative; flex: none; }
.tb-control {
    font: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #102349;
    border: 1px solid #d6e3f5;
    background: #f7f9fd;
    border-radius: 11px;
    height: 43px;
    padding: 0 12px;
    white-space: nowrap;
    max-width: min(340px, 42vw);
}
.tb-control:hover,
.tb-icon-btn:hover,
.tb-account:hover {
    background: #eff5ff;
}
.tb-control:focus-visible,
.tb-icon-btn:focus-visible,
.tb-account:focus-visible,
.tb-menu-item:focus-visible {
    outline: 3px solid #a9cbff;
    outline-offset: 2px;
}
.tb-control:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.tb-customer {
    justify-content: flex-start;
    gap: 10px;
}
.tb-customer-label { color: #435a78; font-size: 0.875rem; }
.tb-customer-value {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.tb-language { gap: 9px; }
.tb-lang-name { font-size: 0.875rem; }
.tb-flag,
.tb-flag-svg {
    width: 23px;
    height: 17px;
    display: block;
    border-radius: 2px;
    overflow: hidden;
    box-shadow: 0 0 0 1px rgba(16, 31, 61, 0.14);
    flex: none;
}
.tb-chev { color: #1a2e50; flex: none; }
.tb-icon-btn {
    position: relative;
    border: 0;
    background: transparent;
    border-radius: 10px;
    color: #1a2e50;
    width: 40px;
    height: 42px;
    display: inline-grid;
    place-items: center;
    text-decoration: none;
    flex: none;
}
.tb-icon-btn:hover { text-decoration: none; color: #1a2e50; }
.tb-notif-dot {
    position: absolute;
    right: 8px;
    top: 6px;
    width: 9px;
    height: 9px;
    background: #ef3344;
    border: 2px solid #fff;
    border-radius: 100%;
}
.tb-account {
    border: 0;
    background: transparent;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 3px 1px 3px 2px;
    border-radius: 22px;
    cursor: pointer;
    color: #1b3259;
}
.tb-avatar {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #2664f5;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 0 0 3px #eaf1ff;
}
.tb-menu {
    position: absolute;
    z-index: 50;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    padding: 6px;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #dae4f2;
    box-shadow: 0 14px 35px rgba(29, 53, 85, 0.18);
    text-align: left;
}
.tb-menu-left { left: 0; right: auto; }
.tb-menu-title {
    font-size: 11px;
    letter-spacing: 0.35px;
    color: #687c9a;
    padding: 11px 11px 7px;
    text-transform: uppercase;
}
.tb-account-name {
    padding: 2px 11px 4px;
    font-weight: 600;
    color: #1c3153;
}
.tb-account-role { padding: 0 11px 10px !important; }
.tb-menu-item {
    background: #fff;
    border: 0;
    width: 100%;
    height: 41px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
    padding: 0 11px;
    border-radius: 8px;
    font: inherit;
    color: #1c3153;
    cursor: pointer;
}
.tb-menu-item:hover,
.tb-menu-item.is-selected {
    background: #edf4ff;
}
.tb-menu-check {
    margin-left: auto;
    color: #2664f5;
    font-weight: 700;
}
.tb-menu-separator {
    height: 1px;
    background: #e7ecf4;
    margin: 5px 6px;
}
.tb-menu-muted {
    font-size: 12px;
    color: #647a98;
    padding: 4px 11px 10px;
}
.md-content { background: var(--md-background); }
.sensors-alert-success {
    background: #e8f6ef;
    border-color: #9fd5b5;
    color: #1f6b43;
}

@media (max-width: 720px) {
    .tb-customer-label,
    .tb-lang-name { display: none; }
    .tb-control { padding: 0 10px; max-width: min(200px, 46vw); }
    .tb-divider { display: none; }
}

/* Legacy aliases kept for older markup references */
.md-top-left,
.md-top-right,
.md-icon-btn,
.md-user-chip,
.md-avatar,
.md-customer-scope { /* no-op aliases */ }

/* Legacy - kept for compatibility */
.tank-level {
    width: 100%;
    height: 60px;
    background: var(--gray-100);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.level-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, var(--steel), var(--steel-light));
    transition: height 0.5s ease;
    border-radius: 0 0 4px 4px;
}

.tank-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.level-text {
    font-family: var(--font-mono);
    font-weight: bold;
    font-size: 1.1rem;
}

/* === Forms === */
.form-control {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 0.85rem;
    background: var(--white);
}

.form-control:focus {
    outline: none;
    border-color: var(--steel);
    box-shadow: 0 0 0 2px rgba(74, 111, 165, 0.2);
}

.form-control-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }

.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--gray-600);
}

.form-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.form-row label {
    font-size: 0.8rem;
    min-width: 100px;
    font-weight: 600;
    color: var(--gray-600);
}

.inline-form {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 1rem;
    margin: 1rem 0;
    max-width: 500px;
}

.rule-form-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
    gap: 1.25rem;
    align-items: start;
    margin: 1rem 0;
}

.rule-form-layout > .inline-form {
    margin: 0;
    max-width: none;
}

.rule-devices-panel {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 1rem;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

.rule-devices-panel h4 {
    margin: 0 0 0.35rem;
    font-size: 1rem;
}

.rule-devices-hint {
    margin: 0 0 0.85rem;
    font-size: 0.75rem;
    color: var(--gray-600);
    line-height: 1.35;
}

.rule-devices-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.rule-device-block {
    border: 1px solid var(--gray-200);
    border-left: 4px solid #64B5F6;
    border-radius: 6px;
    padding: 0.75rem;
    background: var(--gray-50, #f8f9fa);
}

.rule-device-block.rule-device-switch {
    border-left-color: #455A64;
}

.rule-device-block-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.rule-device-block-header h5 {
    margin: 0;
    font-size: 0.9rem;
    font-family: var(--font-mono);
}

.rule-device-level {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.55rem;
}

.rule-device-level-bar {
    width: 48px;
    height: 56px;
    border: 2px solid var(--navy-light, #334);
    border-radius: 0 0 8px 8px;
    background: #e8e8e8;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.rule-device-level-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, #42A5F5, #90CAF9);
}

.rule-device-level-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #111;
}

.rule-device-meta {
    font-size: 0.75rem;
    color: var(--gray-700);
    margin: 0;
}

.rule-device-parts {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.rule-device-chip {
    border: 1px solid var(--gray-300);
    background: var(--white);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.72rem;
    cursor: pointer;
    line-height: 1.3;
}

.rule-device-chip:hover {
    border-color: var(--navy-light, #334);
    background: #eef6ff;
}

.rule-device-chip.is-selected {
    border-color: #2e7d32;
    background: #e8f5e9;
}

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

    .rule-devices-panel {
        position: static;
        max-height: none;
    }
}

.rule-history-panel {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 1rem;
    margin: 1rem 0;
}

.rule-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.rule-history-header h3 {
    margin: 0;
}

/* === Filter Row === */
.filter-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.filter-row label {
    font-weight: 600;
    color: var(--gray-600);
}

/* === Date Range Filter === */
.date-range-filter {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
}

.date-range-filter label { font-weight: 600; color: var(--gray-600); }
.date-range-filter input { padding: 0.2rem 0.4rem; border: 1px solid var(--gray-300); border-radius: 4px; font-size: 0.8rem; }

/* === Pagination === */
.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0;
    font-size: 0.85rem;
}

/* === Detail Page === */
.detail-list {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0.3rem 1rem;
    margin-bottom: 1rem;
}

.detail-list dt { font-weight: 600; color: var(--gray-600); font-size: 0.85rem; }
.detail-list dd { margin: 0; font-size: 0.85rem; }

.live-level {
    background: #e8f5e9;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    margin: 0.75rem 0;
    font-family: var(--font-mono);
    font-size: 1.1rem;
}

/* === Actuator Toggle === */
.actuator-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0;
    font-size: 0.85rem;
}

/* === Report Summary === */
.report-summary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 1rem;
    text-align: center;
}

.stat-card h4 { font-size: 0.75rem; color: var(--gray-600); margin-bottom: 0.3rem; }
.stat-card .stat-value, .stat-card span { font-family: var(--font-mono); font-size: 1.4rem; font-weight: bold; color: var(--navy); display: block; }
.stat-card .stat-sub { font-size: 0.7rem; font-weight: normal; display: block; margin-top: 0.2rem; }

/* === Login === */
.login-container {
    max-width: 380px;
    margin: 4rem auto;
    background: var(--white);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.login-container h2 {
    text-align: center;
    margin-bottom: 1.5rem;
}

/* === Alerts === */
.alert {
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}

.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

/* === Loading Spinner === */
.loading-spinner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem;
    color: var(--gray-600);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--steel);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--gray-600); font-size: 0.85rem; }

/* === Error UI === */
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0,0,0,0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* === Dashboard Header === */
.dashboard-tanks-header {
    margin-top: 0;
    margin-bottom: 1rem;
}

.dashboard-tanks-header h1 {
    margin: 0;
    font-size: 1.75rem;
}

.dashboard-header {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
}

.dashboard-header h2 {
    margin: 0;
    font-size: 1.35rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1.5rem 0 1rem;
}

.section-header h2 {
    margin: 0;
}

/* === Summary Cards === */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.summary-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    transition: box-shadow 0.15s;
}

.summary-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.summary-card.card-warning { border-left: 3px solid var(--amber); }
.summary-card.card-critical { border-left: 3px solid var(--red); }

.summary-icon { font-size: 1.5rem; flex-shrink: 0; }
.summary-body { display: flex; flex-direction: column; }
.summary-value { font-family: var(--font-mono); font-size: 1.4rem; font-weight: bold; color: var(--navy); line-height: 1.2; }
.summary-label { font-size: 0.7rem; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.3px; }

/* === Timeline === */
.timeline {
    position: relative;
    padding-left: 24px;
    margin: 1rem 0;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--gray-200);
}

.timeline-item {
    position: relative;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    transition: box-shadow 0.15s;
}

.timeline-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }

.timeline-dot {
    position: absolute;
    left: -20px;
    top: 1rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--white);
    z-index: 1;
}

.timeline-success .timeline-dot { background: var(--green); }
.timeline-failure .timeline-dot { background: var(--red); }
.timeline-retrying .timeline-dot { background: var(--amber); }
.timeline-pending .timeline-dot { background: var(--gray-300); }

.timeline-header {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 0.3rem;
}

.timeline-body { font-size: 0.85rem; margin-bottom: 0.3rem; }
.timeline-body strong { font-family: var(--font-mono); font-size: 0.8rem; }
.timeline-message { margin: 0.2rem 0 0; color: var(--gray-600); font-size: 0.8rem; }

.timeline-time {
    display: flex;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--gray-600);
    font-family: var(--font-mono);
}

.badge-automation { background: #e3f2fd; color: #1565c0; }
.badge-manual { background: #f3e5f5; color: #7b1fa2; }
.badge-admin { background: #fff3e0; color: #e65100; }

/* === Demo Panel === */
.demo-panel {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.8rem;
    margin-right: auto;
}

.demo-panel.demo-active {
    background: #fff8e1;
    border: 1px solid var(--amber);
}

.demo-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.demo-label {
    font-weight: 600;
    color: var(--navy);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.demo-actions {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}

.demo-message {
    font-size: 0.75rem;
    color: var(--gray-600);
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--gray-300);
    transition: 0.3s;
    border-radius: 20px;
}

.slider::before {
    content: "";
    position: absolute;
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider { background-color: var(--green); }
input:checked + .slider::before { transform: translateX(16px); }

/* === SensorStatusBadge enhancements === */
.badge-ok::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    margin-right: 4px;
    animation: pulse-dot 2s ease-in-out infinite;
}

.badge-critical::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--red);
    margin-right: 4px;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* === Text Color Utilities === */
.text-critical { color: var(--red); }
.text-warning { color: #d4920a; }
.text-ok { color: var(--green); }

/* === Alert & Action Breakdown === */
.alert-breakdown, .action-breakdown {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin: 0.5rem 0;
}

.breakdown-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.breakdown-count {
    font-family: var(--font-mono);
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--navy);
}

/* === Responsive === */
@media (max-width: 768px) {
    .page.md-shell,
    .page.md-shell.sidebar-collapsed {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "top"
            "sidebar"
            "main";
    }

    .page.md-shell > .sidebar,
    .page.md-shell.sidebar-collapsed > .sidebar,
    .page.md-shell > .sidebar.is-collapsed {
        width: 100%;
        height: auto;
        position: sticky;
        top: var(--wm-topbar-height);
        z-index: 55;
        border-right: none;
        border-bottom: 1px solid #E2E8F0;
    }

    .page.md-shell .md-nav,
    .page.md-shell .md-nav.is-collapsed {
        flex-direction: row;
        align-items: center;
        min-height: 0;
        height: auto;
        padding: 6px 8px;
        gap: 4px;
    }

    .page.md-shell .md-nav-brand {
        display: none;
    }

    .page.md-shell .md-nav,
    .page.md-shell .sidebar {
        min-width: 0;
    }

    .page.md-shell .md-nav-list {
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
        overflow-y: hidden;
        flex: 1;
        min-width: 0;
        gap: 2px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .page.md-shell .md-nav-list::-webkit-scrollbar {
        display: none;
    }

    .page.md-shell .md-nav-item {
        width: auto;
        flex: none;
    }

    .page.md-shell .md-nav-link,
    .page.md-shell .md-nav.is-collapsed .md-nav-link {
        width: auto;
        min-width: 44px;
        min-height: 44px;
        padding: 0 12px;
        margin: 0;
        justify-content: center;
    }

    .page.md-shell .md-nav-label,
    .page.md-shell .md-nav.is-collapsed .md-nav-label {
        display: none;
    }

    .page.md-shell .md-nav.is-collapsed .md-nav-tooltip {
        display: none !important;
    }

    .md-top-row.tb-bar,
    .tb-bar,
    .top-row {
        min-width: 0;
        position: sticky;
        top: 0;
        z-index: 60;
        flex-wrap: nowrap;
        height: auto;
        min-height: var(--wm-topbar-height);
        padding: 0.5rem 1rem;
    }

    .tank-grid { grid-template-columns: 1fr; }
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
    .report-summary { grid-template-columns: repeat(2, 1fr); }
    .data-table { font-size: 0.8rem; }
    .data-table th, .data-table td { padding: 0.4rem; }
    .demo-panel { width: 100%; order: 10; margin-right: 0; }
    .demo-actions { flex-wrap: wrap; }
    .dashboard-header { flex-direction: column; gap: 0; }
    .filter-row { flex-wrap: wrap; }
    .timeline { padding-left: 20px; }
}

@media (max-width: 480px) {
    .summary-cards { grid-template-columns: 1fr; }
    .report-summary { grid-template-columns: 1fr; }
    .tank-container { width: 60px; height: 80px; }
    .tank-level-label { font-size: 0.85rem; }
}

/* === Trilingual fields === */
.trilingual-field {
    margin-bottom: 0.75rem;
}
.trilingual-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}
.trilingual-inputs {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.trilingual-row {
    margin: 0;
}
.lang-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.1rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--gray-600, #555);
    background: var(--gray-100, #f3f4f6);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 4px;
    padding: 0.15rem 0.35rem;
}

/* === Schema homepage (layered SVG) === */
.schema-page {
    max-width: 1280px;
    margin: 0 auto;
}
.schema-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.5rem;
}
.schema-readonly-hint {
    margin: 0 0 0.75rem;
    padding: 0.65rem 0.9rem;
    border-left: 3px solid var(--gray-400, #a0aec0);
    background: rgba(255, 255, 255, 0.72);
    color: #4a5568;
    font-size: 0.95rem;
}
.schema-empty {
    text-align: center;
    padding: 0.75rem 1rem;
}
.schema-stage-wrap {
    position: relative;
    width: 100%;
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    background: #1a1040;
}
.schema-stage-clickable {
    cursor: pointer;
}
.schema-stage-clickable:focus-visible {
    outline: 2px solid #3182ce;
    outline-offset: 2px;
}
.schema-svg-host {
    width: 100%;
    line-height: 0;
}
.schema-svg-host > svg {
    display: block;
    width: 100%;
    height: auto;
}
/* KAN-6: keep stage occupied while SVG mounts / on failure */
.schema-svg-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: min(52vh, 420px);
    padding: 1.5rem;
    background: #1a1040;
    text-align: center;
}
.schema-svg-host.is-pending {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.schema-svg-loader {
    color: #2f851e;
}
/* Tailwind animate-spin (cdn.tailwindcss.com); local fallback if CDN unavailable */
.animate-spin {
    animation: spin 1s linear infinite;
}
.schema-svg-error {
    margin: 0;
    max-width: 28rem;
    color: #f8fafc;
    font-size: 1rem;
    line-height: 1.45;
    font-weight: 600;
}
.schema-unbound-list {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px dashed var(--gray-300, #cbd5e0);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.7);
}
.schema-unbound-list h3 {
    margin: 0 0 0.4rem;
    font-size: 0.95rem;
}
.schema-unbound-list ul {
    margin: 0;
    padding-left: 1.2rem;
}
.schema-unbound-list code {
    font-weight: 700;
}

.pin-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.pin-modal {
    background: #fff;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
    width: min(360px, 92vw);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}
.pin-modal h4 { margin: 0 0 0.5rem; }
.pin-modal-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}
/* Distribution gauge arrow emphasis */
.schema-svg-host [data-bind="dist-arrow"].schema-flow-on {
    filter: drop-shadow(0 0 8px rgba(39, 174, 96, 0.75));
}
/* Pipe flow arrows blink while that side is feeding */
.schema-svg-host [data-bind="flow-arrows"].schema-flow-blink {
    animation: schema-flow-blink 1s ease-in-out infinite;
}
/* Offline level gauge: N/A blinks red */
.schema-svg-host .schema-pct-blink {
    animation: schema-flow-blink 1s ease-in-out infinite;
}
@keyframes schema-flow-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.15; }
}

/* === MD3 Sidebar (KAN-10) === */
.md-nav {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100vh;
    padding: 12px 10px 16px;
    background: #F1F3F7;
    color: #475569;
}
@media (max-width: 768px) {
    .md-nav {
        min-height: 0;
        height: auto;
    }
}
.md-nav-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 12px;
    padding: 0 4px;
}
.md-nav-logo {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
    color: #152B55;
    text-decoration: none;
    font-weight: 700;
}
.md-nav-logo:hover { text-decoration: none; color: #152B55; }
.md-nav-logo-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #DBEAFE;
    color: #2563EB;
}
.md-nav-logo-text {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.md-nav-collapse-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #475569;
    cursor: pointer;
}
.md-nav-collapse-btn:hover,
.md-nav-collapse-btn:focus-visible {
    background: #E5EAF3;
    color: #152B55;
    outline: none;
}
.md-nav-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    flex: 1;
}
.md-nav-item { width: 100%; }
.md-nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 8px;
    color: #475569;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}
.md-nav-link:hover {
    background: #E5EAF3;
    color: #152B55;
    text-decoration: none;
}
.md-nav-link.active {
    background: #DDE3F1;
    color: #152B55;
    font-weight: 600;
}
.md-nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: inherit;
}
.md-nav-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.md-nav-tooltip {
    display: none;
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    z-index: 40;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    background: #0F172A;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
}
.md-nav.is-collapsed .md-nav-brand {
    flex-direction: column;
    align-items: center;
}
.md-nav.is-collapsed .md-nav-link {
    justify-content: center;
    padding: 0;
    width: 44px;
    margin: 0 auto;
}
.md-nav.is-collapsed .md-nav-link:hover .md-nav-tooltip,
.md-nav.is-collapsed .md-nav-link:focus-visible .md-nav-tooltip {
    display: block;
}
.md-nav.is-collapsed .md-nav-logo-text,
.md-nav.is-collapsed .md-nav-label {
    display: none;
}

/* === Misc overrides === */
.blazor-error-boundary { background: var(--red); padding: 1rem; color: white; border-radius: 4px; }
.blazor-error-boundary::after { content: "An error has occurred."; }
section { margin-bottom: 1.5rem; }

/* === Add Device form (KAN-12) === */
.adf-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 0 2rem;
}
.adf-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
.adf-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid #CBD5E1;
    border-radius: 8px;
    background: #fff;
    color: #152B55;
    cursor: pointer;
}
.adf-back:hover { background: #EFF6FF; border-color: #93C5FD; }
.adf-header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    background: #DBEAFE;
    color: #2563EB;
    flex-shrink: 0;
}
.adf-header-text h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    color: #152B55;
}
.adf-header-text p {
    margin: 2px 0 0;
    color: #64748B;
    font-size: 0.9rem;
}
.adf-card {
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.04);
}
.adf-field {
    display: grid;
    grid-template-columns: 28% 1fr;
    gap: 16px 24px;
    align-items: start;
}
.adf-label {
    padding-top: 12px;
    color: #152B55;
    font-weight: 600;
    font-size: 0.95rem;
}
.adf-required { color: #DC2626; margin-left: 2px; }
.adf-control { min-width: 0; }
.adf-divider {
    border: none;
    border-top: 1px solid #E2E8F0;
    margin: 20px 0;
}
.adf-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}
.adf-input-icon {
    position: absolute;
    left: 12px;
    display: inline-flex;
    color: #64748B;
    pointer-events: none;
    z-index: 1;
}
.adf-input {
    width: 100%;
    height: 44px;
    padding: 0 12px 0 44px;
    border: 1px solid #CBD5E1;
    border-radius: 8px;
    background: #fff;
    color: #152B55;
    font-size: 0.95rem;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}
.adf-input:hover { border-color: #94A3B8; }
.adf-input:focus {
    border-color: #2563EB;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.adf-input[readonly],
.adf-input:disabled,
.adf-select:disabled {
    background: #F1F5F9;
    color: #64748B;
    cursor: not-allowed;
}
.adf-select:disabled:hover { border-color: #CBD5E1; }
.adf-input-wrap.is-invalid .adf-input,
.adf-lang-group.is-invalid .adf-input {
    border-color: #DC2626;
}
.adf-select-native .adf-chevron {
    position: absolute;
    right: 12px;
    color: #64748B;
    pointer-events: none;
}
.adf-select-native .adf-input { padding-right: 40px; }
.adf-select-wrap { position: relative; }
.adf-select {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border: 1px solid #CBD5E1;
    border-radius: 8px;
    background: #fff;
    color: #152B55;
    cursor: pointer;
    text-align: left;
}
.adf-select:hover { border-color: #94A3B8; }
.adf-select:focus {
    border-color: #2563EB;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
    outline: none;
}
.adf-select-value {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}
.adf-chevron { color: #64748B; flex-shrink: 0; }
.adf-select-menu {
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    margin: 0;
    padding: 6px;
    list-style: none;
    background: #fff;
    border: 1px solid #CBD5E1;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}
.adf-select-menu li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    color: #152B55;
}
.adf-select-menu li:hover { background: #F1F5F9; }
.adf-select-menu li.is-selected { background: #EFF6FF; color: #1D4ED8; }
.adf-lang-group { display: flex; flex-direction: column; gap: 8px; }
.adf-lang-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
}
.adf-lang-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 28px;
    padding: 0 8px;
    border-radius: 999px;
    background: #F1F5F9;
    color: #64748B;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.adf-counter {
    min-width: 3.2rem;
    text-align: right;
    color: #64748B;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}
.adf-help {
    margin: 8px 0 0;
    color: #64748B;
    font-size: 0.82rem;
}
.adf-field-error,
.adf-form-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin: 8px 0 0;
    color: #DC2626;
    font-size: 0.85rem;
}
.adf-form-error {
    margin-top: 20px;
    padding: 12px 14px;
    background: #FEF2F2;
    border-radius: 8px;
}
.adf-actuators {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
}
.adf-actuator-card {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 14px;
    align-items: start;
    padding: 14px 16px;
    border: 1px solid #E2E8F0;
    border-radius: 10px;
    background: #F8FAFC;
}
.adf-actuator-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #EFF6FF;
    color: #1D4ED8;
    margin-top: 22px;
}
.adf-actuator-card-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    min-width: 0;
    padding-right: 24px;
}
.adf-actuator-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}
.adf-actuator-field-name {
    grid-column: 1 / -1;
}
.adf-actuator-field-label,
.adf-actuator-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #334155;
}
.adf-actuator-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #DC2626;
    cursor: pointer;
}
.adf-actuator-remove:hover { background: #FEE2E2; }
.adf-add-actuator {
    align-self: flex-start;
}
.adf-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 28px;
}
.adf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 48px;
    padding: 0 20px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.adf-btn:disabled { opacity: 0.65; cursor: not-allowed; }
.adf-btn-secondary {
    background: #F1F5F9;
    border-color: #CBD5E1;
    color: #152B55;
}
.adf-btn-secondary:hover:not(:disabled) { background: #E2E8F0; }
.adf-btn-primary {
    background: #2563EB;
    color: #fff;
}
.adf-btn-primary:hover:not(:disabled) { background: #1D4ED8; }
.adf-btn-primary:focus-visible,
.adf-btn-secondary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}
.adf-spin { animation: adf-spin 0.8s linear infinite; }
@keyframes adf-spin { to { transform: rotate(360deg); } }

@media (max-width: 768px) {
    .adf-field {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .adf-label { padding-top: 0; }
    .adf-lang-row {
        grid-template-columns: auto 1fr;
        gap: 12px;
    }
    .adf-counter {
        grid-column: 2;
        justify-self: end;
        margin-top: -4px;
    }
    .adf-actions { flex-wrap: wrap; }
    .adf-btn { flex: 1 1 auto; }
    .adf-actuator-card-fields { grid-template-columns: 1fr; }
    .adf-actuator-card-icon { margin-top: 0; }
}

/* === Sensors page (KAN-15) === */
.sensors-page { max-width: 100%; position: relative; }
.sensors-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
}
.sensors-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.sensors-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.sensors-header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    background: #DBEAFE;
    color: #2563EB;
    flex-shrink: 0;
}
.sensors-header h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    color: #152B55;
}
.sensors-header p {
    margin: 2px 0 0;
    color: #64748B;
    font-size: 0.9rem;
}
.sensors-add-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 48px;
    padding: 0 20px;
    border-radius: 8px;
    background: #2563EB;
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}
.sensors-add-btn:hover {
    background: #1D4ED8;
    color: #fff;
    text-decoration: none;
}
.sensors-add-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}
.sensors-toolbar {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.sensors-filters {
    display: grid;
    grid-template-columns: 1.42fr 1fr 1fr;
    gap: 16px;
    margin-bottom: 22px;
}
.sensors-search {
    position: relative;
    flex: 1 1 40%;
    min-width: 220px;
}
.sensors-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #64748B;
    display: inline-flex;
    pointer-events: none;
}
.sensors-search-input {
    width: 100%;
    height: 48px;
    padding: 0 14px 0 42px;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    background: #fff;
    color: #152B55;
    font-size: 0.95rem;
    outline: none;
}
.sensors-search-input:hover { border-color: #94A3B8; }
.sensors-search-input:focus {
    border-color: #2563EB;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.sensors-show-disabled {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 52px;
    padding: 0 14px;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    background: #fff;
    flex: 0 0 auto;
}
.sensors-show-disabled-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #152B55;
    white-space: nowrap;
}
.sensors-table tr.is-disabled {
    background: #F8FAFC;
}
/* Dim cells only — keep Actions (and its menu) fully interactive above the backdrop. */
.sensors-table tr.is-disabled > td:not(.sensors-col-actions) {
    opacity: 0.72;
}
.sensors-status-chip.is-disabled {
    background: #F1F5F9;
    color: #64748B;
}
.sensors-status-chip.is-disabled .sensors-status-dot {
    background: #94A3B8;
}
.sensors-select-field {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1 1 28%;
    min-width: 180px;
    height: 52px;
    padding: 0 40px 0 44px;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
}
.sensors-select-field:hover { border-color: #94A3B8; }
.sensors-select-field:focus-within {
    border-color: #2563EB;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.sensors-field-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    color: #64748B;
    pointer-events: none;
}
.sensors-select-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}
.sensors-select-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: #49678F;
    line-height: 1.1;
}
.sensors-select-value {
    color: #112B59;
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sensors-select,
.sensors-select-overlay {
    width: 100%;
    border: none;
    background: transparent;
    color: #152B55;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0;
    margin: 0;
    appearance: none;
    -webkit-appearance: none;
    outline: none;
    cursor: pointer;
}
.sensors-select-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}
.sensors-chevron {
    position: absolute;
    right: 14px;
    color: #64748B;
    pointer-events: none;
    z-index: 0;
}
.sensors-state {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.sensors-level-track {
    height: 7px;
    width: 110px;
    max-width: 65%;
    border-radius: 10px;
    background: #E5EAF1;
    overflow: hidden;
    flex: 1 1 auto;
}
.sensors-level-fill {
    height: 100%;
    border-radius: 10px;
    background: #43A7FC;
}
.sensors-level-fill.is-low { background: #FF7F94; }
.sensors-level-pct,
.sensors-state-word {
    font-size: 0.8rem;
    font-weight: 650;
    color: #4C6485;
    white-space: nowrap;
}
.sensors-switch-toggle {
    position: relative;
    width: 38px;
    height: 22px;
    border: 0;
    border-radius: 20px;
    background: #8DA6C9;
    flex: none;
    padding: 0;
    cursor: pointer;
}
.sensors-switch-toggle::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    height: 16px;
    width: 16px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(21, 41, 71, 0.33);
    transition: transform 0.15s ease;
}
.sensors-switch-toggle.is-on { background: #267DF8; }
.sensors-switch-toggle.is-on::before { transform: translateX(16px); }
.sensors-switch-toggle:disabled { opacity: 0.55; cursor: wait; }
.sensors-type-plain {
    color: #4A6384;
    font-weight: 550;
    font-size: 0.85rem;
}
.sensors-status-chip.is-alert {
    color: #F4941C;
    background: #FFF1DC;
}
.sensors-status-chip.is-alert .sensors-status-dot { background: currentColor; }
.sensors-table-devices th:nth-child(1) { width: 31%; }
.sensors-table-devices th:nth-child(2) { width: 19%; }
.sensors-table-devices th:nth-child(3) { width: 12%; }
.sensors-table-devices th:nth-child(4) { width: 13%; }
.sensors-table-devices th:nth-child(5) { width: 18%; }
.sensors-table-devices th:nth-child(6) { width: 7%; }
.sensors-table-card {
    background: #fff;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.04);
    overflow: hidden;
}
/* When an actions menu is open, let it escape the card and sit above the footer. */
.sensors-table-card:has(.sensors-action-menu) {
    overflow: visible;
}
.sensors-table-scroll { overflow-x: auto; }
.sensors-table-card:has(.sensors-action-menu) .sensors-table-scroll {
    overflow: visible;
    position: relative;
    z-index: 30;
}
.sensors-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 860px;
}
.sensors-table thead th {
    height: 48px;
    padding: 0 16px;
    background: #F1F5F9;
    color: #152B55;
    font-size: 0.78rem;
    font-weight: 700;
    text-align: left;
    letter-spacing: 0.02em;
    border-bottom: 1px solid #DCE5F1;
    white-space: nowrap;
}
.sensors-table tbody td {
    padding: 16px;
    border-bottom: 1px solid #E8EEF6;
    color: #152B55;
    vertical-align: middle;
}
.sensors-table tbody tr {
    height: 84px;
    cursor: pointer;
}
.sensors-table tbody tr:hover { background: #F8FBFF; }
.sensors-table tbody tr:last-child td { border-bottom: none; }
/* Elevate open-menu row above row borders and the menu backdrop (z-index 25). */
.sensors-table tbody tr:has(.sensors-action-menu) {
    position: relative;
    z-index: 40;
}
.sensors-col-actions { text-align: right; width: 72px; }
.sensors-name-cell {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.sensors-device-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    flex-shrink: 0;
}
.sensors-device-icon.is-level {
    background: #EFF6FF;
    color: #2563EB;
}
.sensors-device-icon.is-switch {
    background: #F5F3FF;
    color: #6D28D9;
}
.sensors-name-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.sensors-name-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}
.sensors-name {
    font-size: 14px;
    font-weight: 600;
    color: #152B55;
}
.sensors-hidden-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    padding: 0 8px;
    border-radius: 8px;
    background: #F1F3F7;
    color: #64748B;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    flex-shrink: 0;
}
.sensors-hidden-badge .lucide {
    color: #64748B;
    flex-shrink: 0;
}
.sensors-desc {
    font-size: 12px;
    color: #64748B;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
}
.sensors-type-cell,
.sensors-lastseen-cell {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #152B55;
    font-size: 0.9rem;
}
.sensors-type-cell .lucide,
.sensors-lastseen-cell .lucide { color: #64748B; flex-shrink: 0; }
.sensors-status-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 28px;
    padding: 0 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
}
.sensors-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: currentColor;
}
.sensors-status-chip.is-online {
    background: #DDF7E9;
    color: #087F48;
}
.sensors-status-chip.is-offline {
    background: #FDE8E8;
    color: #B42332;
}
.sensors-status-chip.is-unknown {
    background: #F1F5F9;
    color: #64748B;
}
.sensors-actions { position: relative; display: inline-flex; justify-content: flex-end; }
.sensors-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: #EEF2F7;
    color: #152B55;
    cursor: pointer;
}
.sensors-action-btn:hover { background: #E2E8F0; }
.sensors-action-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}
.sensors-action-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 40;
    min-width: 160px;
    padding: 6px;
    background: #fff;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}
/* Last rows open upward so the menu is not covered by pagination. */
.sensors-table tbody tr:nth-last-child(-n+2) .sensors-action-menu {
    top: auto;
    bottom: calc(100% + 4px);
}
.sensors-action-menu button {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #152B55;
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
}
.sensors-action-menu button:hover { background: #F1F5F9; }
.sensors-action-menu button.is-danger { color: #B42332; }
.sensors-action-menu button.is-danger:hover { background: #FEF2F2; }
.sensors-empty {
    text-align: center !important;
    color: #64748B !important;
    padding: 40px 16px !important;
    height: auto !important;
}
.sensors-table-footer {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    min-height: 72px;
    padding: 0 16px;
    border-top: 1px solid #E8EEF6;
    background: #fff;
    border-radius: 0 0 8px 8px;
    flex-wrap: wrap;
}
.sensors-range {
    color: #64748B;
    font-size: 0.875rem;
}
.sensors-pager { display: inline-flex; align-items: center; gap: 6px; }
.sensors-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    background: #fff;
    color: #152B55;
    cursor: pointer;
    font-weight: 600;
}
.sensors-page-btn:hover:not(:disabled) { background: #F8FBFF; }
.sensors-page-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.sensors-page-btn.is-active {
    background: #EFF6FF;
    border-color: #2563EB;
    color: #2563EB;
}
.sensors-page-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}
.sensors-alert {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-radius: 8px;
    background: #FEF2F2;
    color: #B42332;
}
@media (max-width: 768px) {
    .sensors-toolbar { flex-direction: column; }
    .sensors-filters {
        grid-template-columns: 1fr;
        gap: 9px;
    }
    .sensors-search,
    .sensors-show-disabled,
    .sensors-select-field {
        flex: 1 1 auto;
        width: 100%;
        min-width: 0;
    }
}

/* === Device alerts modal (KAN-27) === */
.device-alerts-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.45);
}
.device-alerts-modal {
    display: flex;
    flex-direction: column;
    width: 980px;
    max-width: 95vw;
    max-height: 85vh;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #DCE5F1;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.18);
    overflow: hidden;
    color: #152B55;
}
.device-alerts-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 24px 24px 16px;
    border-bottom: 1px solid #DCE5F1;
}
.device-alerts-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}
.device-alerts-title-row h2 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: #152B55;
}
.device-alerts-title-icon {
    display: inline-flex;
    color: #2563EB;
}
.device-alerts-device {
    display: flex;
    align-items: center;
    gap: 12px;
}
.device-alerts-device-name {
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.device-alerts-device-meta {
    font-size: 0.85rem;
    color: #64748B;
    margin-top: 2px;
}
.device-alerts-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #64748B;
    cursor: pointer;
}
.device-alerts-icon-btn:hover { background: #F1F5F9; color: #152B55; }
.device-alerts-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 24px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #FEF2F2;
    color: #B42332;
    font-size: 0.875rem;
}
.device-alerts-body {
    display: grid;
    grid-template-columns: 35% 65%;
    gap: 16px;
    padding: 16px 24px;
    min-height: 0;
    flex: 1;
    overflow: hidden;
}
.device-alerts-list-panel,
.device-alerts-detail-panel {
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    background: #fff;
    min-height: 280px;
    max-height: 52vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.device-alerts-list {
    list-style: none;
    margin: 0;
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}
.device-alerts-list-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    border-radius: 8px;
    padding: 12px 10px;
    cursor: pointer;
    color: #152B55;
}
.device-alerts-list-item:hover { background: #F8FBFF; }
.device-alerts-list-item.is-selected { background: #DBEAFE; }
.device-alerts-sev-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
}
.device-alerts-sev-icon.is-critical { background: #FDE8E8; color: #DC2626; }
.device-alerts-sev-icon.is-warning { background: #FFF4D6; color: #D97706; }
.device-alerts-list-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.device-alerts-list-title {
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.3;
}
.device-alerts-list-date {
    font-size: 0.78rem;
    color: #64748B;
}
.device-alerts-load-more {
    display: flex;
    justify-content: center;
    padding: 8px;
}
.device-alerts-load-more-btn {
    border: none;
    background: transparent;
    color: #2563EB;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.device-alerts-detail-panel { padding: 20px; overflow-y: auto; }
.device-alerts-detail-head {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}
.device-alerts-detail-head h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: #152B55;
}
.device-alerts-full-message {
    margin: 0 0 16px;
    color: #152B55;
    line-height: 1.45;
}
.device-alerts-fields {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-bottom: 16px;
}
.device-alerts-field {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    color: #152B55;
}
.device-alerts-field .lucide { color: #64748B; flex-shrink: 0; margin-top: 2px; }
.device-alerts-field-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: #64748B;
    margin-bottom: 2px;
}
.device-alerts-ack {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid #E8EEF6;
    font-weight: 600;
}
.device-alerts-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 100%;
    min-height: 220px;
    color: #64748B;
    text-align: center;
    padding: 24px;
}
.device-alerts-empty p { margin: 0; }
.device-alerts-footer {
    display: flex;
    justify-content: flex-end;
    padding: 16px 24px 24px;
    border-top: 1px solid #DCE5F1;
}
.device-alerts-back {
    display: none;
    align-items: center;
    gap: 4px;
    margin-bottom: 12px;
    border: none;
    background: transparent;
    color: #2563EB;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}
.device-alerts-skeleton-list,
.device-alerts-skeleton-detail {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
}
.device-alerts-skeleton-item,
.device-alerts-skeleton-line {
    height: 56px;
    border-radius: 8px;
    background: linear-gradient(90deg, #F1F5F9 25%, #E8EEF6 50%, #F1F5F9 75%);
    background-size: 200% 100%;
    animation: device-alerts-shimmer 1.2s ease-in-out infinite;
}
.device-alerts-skeleton-line { height: 16px; }
.device-alerts-skeleton-line.wide { height: 28px; width: 70%; }
@keyframes device-alerts-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.device-alerts-spin { animation: device-alerts-spin 0.8s linear infinite; }
@keyframes device-alerts-spin {
    to { transform: rotate(360deg); }
}
@media (max-width: 767px) {
    .device-alerts-modal {
        width: 100%;
        max-width: 100vw;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }
    .device-alerts-body {
        grid-template-columns: 1fr;
        max-height: none;
        flex: 1;
    }
    .device-alerts-list-panel,
    .device-alerts-detail-panel {
        max-height: none;
        flex: 1;
    }
    .device-alerts-body:not(.is-detail) .device-alerts-detail-panel { display: none; }
    .device-alerts-body.is-detail .device-alerts-list-panel { display: none; }
    .device-alerts-back { display: inline-flex; }
}

/* === Alerts page (KAN-26 / KAN-58) === */
.alerts-page .sensors-alert { margin-bottom: 16px; }
.alerts-filters {
    background: #fff;
    border: 1px solid #e2e9f2;
    border-radius: 12px;
    padding: 18px 20px;
    box-shadow: 0 2px 12px rgba(35, 59, 90, 0.035);
    margin-bottom: 16px;
}
.alerts-filter-grid {
    display: grid;
    grid-template-columns: 1.3fr 1fr 1fr 1fr;
    gap: 16px;
    align-items: end;
}
.alerts-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}
.alerts-field-label {
    font-size: 12px;
    font-weight: 600;
    color: #576983;
    padding-left: 4px;
    line-height: 1.2;
    white-space: nowrap;
}
.alerts-field-control {
    width: 100%;
    height: 48px;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid #cbd7e6;
    background: #f8faff;
    color: #263b5d;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.alerts-field-control:hover {
    background: #f0f5fe;
    border-color: #829bc5;
}
.alerts-field:focus-within .alerts-field-control {
    outline: 3px solid #a8c7fa;
    outline-offset: 2px;
    border-color: #829bc5;
}
.alerts-field-leading {
    display: inline-flex;
    color: #42639b;
    flex-shrink: 0;
}
.alerts-field-caret {
    color: #42639b;
    flex-shrink: 0;
    margin-left: auto;
    pointer-events: none;
}
.alerts-select {
    appearance: none;
    flex: 1;
    min-width: 0;
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.95rem;
    cursor: pointer;
}
.alerts-date-control {
    padding-right: 10px;
}
.alerts-datepicker {
    appearance: none;
    width: 100%;
    height: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.95rem;
    color-scheme: light;
    cursor: pointer;
}
.alerts-datepicker::-webkit-calendar-picker-indicator {
    opacity: 0.7;
    cursor: pointer;
    width: 18px;
    height: 18px;
}
.alerts-filter-validation {
    margin: 12px 2px 0;
    font-size: 12px;
    color: #a04148;
}
.alerts-table-card { padding-top: 4px; }
.alerts-table { min-width: 1040px; table-layout: fixed; }
.alerts-table tbody tr {
    cursor: default;
    height: auto;
    min-height: 64px;
}
.alerts-table tbody td {
    color: #36528c;
    font-size: 0.875rem;
    white-space: nowrap;
    padding-top: 12px;
    padding-bottom: 12px;
}
.alerts-col-severity { width: 13.5%; }
.alerts-col-message { width: 31.75%; }
.alerts-col-device { width: 25.15%; }
.alerts-col-created { width: 17.55%; }
.alerts-col-ack { width: 12.05%; }
.alerts-th-ack { text-align: center !important; font-weight: 400 !important; }
.alerts-sort-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    border: 0;
    background: none;
    padding: 8px 0;
    color: inherit;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}
.alerts-sort-triangle {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 8px solid #173770;
    transform: translateY(2px);
}
.alerts-sort-triangle.is-asc {
    transform: translateY(0) rotate(180deg);
}
.alerts-severity-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 28px;
    padding: 0 10px 0 9px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    width: max-content;
}
.alerts-severity-pill.is-critical {
    background: #ffedef;
    color: #bc1019;
}
.alerts-severity-pill.is-warning {
    background: #fff7df;
    color: #bd7800;
}
.alerts-severity-pill.is-info {
    background: #eff6ff;
    color: #2563eb;
}
.alerts-severity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}
.alerts-severity-pill.is-critical .alerts-severity-dot { background: #ca0c1b; }
.alerts-severity-pill.is-warning .alerts-severity-dot { background: #e7a000; }
.alerts-message {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}
.alerts-device-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.alerts-device-pictogram {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}
.alerts-device-pictogram svg {
    width: 22px;
    height: 26px;
}
.alerts-device-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}
.alerts-device-name {
    font-weight: 700;
    color: #10234D;
    font-size: 14px;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
}
.alerts-created {
    font-size: 0.875rem;
    color: #36528c;
}
.alerts-ack-cell { text-align: center; }
.alerts-ack-switch.is-on { background: #1478ff; }
.alerts-footer {
    justify-content: flex-end;
    gap: 12px;
}
.alerts-svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}
.sensors-status-chip.is-critical {
    background: #FDE8E8;
    color: #B42332;
}
.sensors-status-chip.is-warning {
    background: #FFF7E0;
    color: #B54708;
}
.sensors-status-chip.is-info {
    background: #EFF6FF;
    color: #2563EB;
}
@media (max-width: 920px) {
    .alerts-filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 640px) {
    .alerts-filters { padding: 14px; gap: 12px; }
    .alerts-filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }
    .alerts-filter-grid > .alerts-field:first-child,
    .alerts-filter-grid > .alerts-field:last-of-type {
        grid-column: span 2;
    }
    .alerts-field-control { padding: 0 10px; }
}

/* === Threshold Rules (KAN-33) === */
.thresholds-page .sensors-add-btn {
    border: none;
    cursor: pointer;
    font: inherit;
}
.thresholds-page .sensors-alert { margin-bottom: 16px; }
.thresholds-page .sensors-table-scroll { overflow-x: hidden; }
.thresholds-table {
    width: 100%;
    table-layout: fixed;
}
.thresholds-table tbody tr { cursor: default; height: auto; min-height: 84px; }
.thresholds-table tbody td {
    vertical-align: middle;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.thresholds-col-name { width: 16%; }
.thresholds-table th:nth-child(2),
.thresholds-table td:nth-child(2) { width: 12%; }
.thresholds-table th:nth-child(3),
.thresholds-table td:nth-child(3) { width: 10%; }
.thresholds-table th:nth-child(4),
.thresholds-table td:nth-child(4) { width: 20%; }
.thresholds-col-summary { width: 28%; }
.thresholds-name {
    font-size: 14px;
    font-weight: 700;
    color: #10234D;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
}
.thresholds-kind {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 650;
    white-space: nowrap;
}
.thresholds-kind.is-local {
    background: #E8F1FF;
    color: #1764C7;
}
.thresholds-kind.is-multi {
    background: #F0EBFF;
    color: #7048B8;
}
.thresholds-auto {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.thresholds-auto-switch.is-on { background: #12A75C; }
.thresholds-auto-label {
    font-size: 12px;
    font-weight: 610;
    color: #64748B;
    white-space: nowrap;
}
.thresholds-auto-label.is-on { color: #148149; }
.thresholds-sync-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}
.thresholds-sync {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    width: max-content;
    padding: 7px 9px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 690;
    white-space: nowrap;
}
.thresholds-sync.is-synced {
    background: #DEF7E9;
    color: #168453;
}
.thresholds-sync.is-na {
    background: #F0F3F7;
    color: #728197;
}
.thresholds-sync.is-pending {
    background: #FFF7E0;
    color: #B54708;
}
.thresholds-sync.is-failed {
    background: #FDE8E8;
    color: #B42332;
}
.thresholds-details-toggle {
    border: none;
    background: transparent;
    color: #2563EB;
    font-size: 11px;
    font-weight: 650;
    padding: 0;
    cursor: pointer;
    border-radius: 8px;
}
.thresholds-details-toggle:hover { text-decoration: underline; }
.thresholds-sync-error {
    font-size: 11px;
    color: #64748B;
    max-width: 100%;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.thresholds-sync-error.is-expanded {
    display: block;
    -webkit-line-clamp: unset;
    overflow: visible;
}
.thresholds-retry {
    border: none;
    background: transparent;
    color: #2563EB;
    font-size: 11px;
    font-weight: 650;
    padding: 0;
    cursor: pointer;
    border-radius: 8px;
}
.thresholds-retry:hover { text-decoration: underline; }
.thresholds-sync-hint {
    margin: 4px 0 0;
    font-size: 11px;
    line-height: 1.4;
    color: #92400E;
    max-width: 220px;
}
.thresholds-summary {
    font-size: 12px;
    line-height: 1.5;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
}
.thresholds-condition { color: #324968; }
.thresholds-actionline {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 3px;
    font-weight: 700;
    color: #123D84;
}
.thresholds-arrow {
    color: #2278ED;
    font-weight: 800;
}
.thresholds-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: nowrap;
}
.thresholds-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid #DCE5F1;
    background: #fff;
    color: #152B55;
    cursor: pointer;
    text-decoration: none;
    flex: none;
}
.thresholds-icon-btn:hover {
    background: #F8FBFF;
    border-color: #93C5FD;
    color: #152B55;
    text-decoration: none;
}
.thresholds-icon-btn.is-delete {
    border-color: #FECACA;
    color: #B42332;
    background: #FEF2F2;
}
.thresholds-icon-btn.is-delete:hover {
    background: #FEE2E2;
    border-color: #FECACA;
    color: #B42332;
}
.thresholds-icon-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}
.thresholds-footer {
    justify-content: space-between;
}
.thresholds-table .sensors-col-actions {
    width: 148px;
    min-width: 148px;
    max-width: 148px;
    white-space: nowrap;
}

/* === Threshold Rule Form (KAN-34) === */
.trf-page {
    max-width: 1390px;
    margin: 0 auto;
}
.trf-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 8px;
}
.trf-header-icon {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #e2edff;
    color: #1970fa;
    flex-shrink: 0;
}
.trf-header h1 {
    margin: 0 0 6px;
    font-size: 1.75rem;
    font-weight: 750;
    letter-spacing: -0.4px;
    color: #11234e;
}
.trf-header p {
    margin: 0;
    color: #607497;
    font-size: 1rem;
}
.trf-back {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0 18px;
    border: 0;
    background: #e9eef9;
    color: #24447d;
    padding: 12px 18px;
    font-weight: 650;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
}
.trf-back:hover { background: #dce6f7; }
.trf-card {
    border: 1px solid #dae5f5;
    background: #fff;
    border-radius: 8px;
    padding: 22px 24px 24px;
    box-shadow: 0 2px 8px rgba(15, 43, 89, 0.02);
}
.trf-card h2 {
    margin: 0 0 16px;
    font-size: 1.35rem;
    color: #11234e;
    letter-spacing: -0.2px;
}
.trf-section {
    border: 1px solid #dae5f5;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 16px;
}
.trf-section-heading {
    background: linear-gradient(180deg, #f3f7fe 0%, #ecf3fd 100%);
    padding: 12px 18px;
}
.trf-section-heading h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: #11234e;
}
.trf-hint {
    margin: 4px 0 0;
    color: #607497;
    font-size: 0.875rem;
}
.trf-hint-inline {
    margin: 6px 0 0;
    color: #607497;
    font-size: 0.75rem;
    line-height: 1.35;
}
.trf-section-body { padding: 16px 18px 18px; }
.trf-general {
    display: grid;
    grid-template-columns: 1.2fr 0.94fr 1fr 0.77fr;
    align-items: start;
    column-gap: 20px;
    row-gap: 14px;
}
.trf-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}
.trf-field > label,
.trf-field-label {
    font-size: 0.875rem;
    color: #3d5385;
    font-weight: 650;
}
.trf-required { color: #e33c43; }
.trf-input,
.trf-select {
    width: 100%;
    min-width: 0;
    height: 44px;
    color: #111c37;
    border-radius: 8px;
    border: 1px solid #cbdaf0;
    padding: 0 14px;
    background: #fff;
    font: inherit;
}
.trf-input::placeholder { color: #667899; opacity: 0.9; }
.trf-input:focus,
.trf-select:focus {
    outline: none;
    border-color: #2361f2;
    box-shadow: 0 0 0 3px rgba(147, 184, 255, 0.55);
}
.trf-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 36px;
}
.trf-select-wrap {
    position: relative;
    min-width: 0;
}
.trf-select-caret {
    pointer-events: none;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #102247;
}
.trf-check {
    height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.trf-check input {
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: #2361f2;
}
.trf-check label {
    white-space: nowrap;
    font-weight: 600;
    color: #11234e;
    cursor: pointer;
}
.trf-rows {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.trf-condition-row {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) 94px minmax(120px, 1fr) 44px;
    align-items: center;
    gap: 14px;
}
.trf-label-row {
    display: flex;
    gap: 14px;
    margin-bottom: -8px;
}
.trf-label-row .trf-col-label {
    font-size: 10.5px;
    font-weight: 650;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6b7a9c;
    min-width: 0;
}
.trf-label-cond {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) 94px minmax(120px, 1fr) 44px;
}
.trf-label-act > .trf-col-label:nth-child(1) { flex: 1.4 1 180px; }
.trf-label-act > .trf-col-label:nth-child(2) { flex: 0.8 1 120px; }
.trf-label-act > .trf-col-label:nth-child(3),
.trf-label-act > .trf-col-label:nth-child(4) { flex: 0 0 110px; }
.trf-label-act > .trf-col-label:nth-child(5) { flex: 0 0 44px; }
.trf-label-win > .trf-col-label:nth-child(1),
.trf-label-win > .trf-col-label:nth-child(2) { flex: 1 1 140px; }
.trf-label-win > .trf-col-label:nth-child(3) { flex: 0 0 180px; }
.trf-action-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.trf-action-row > .trf-select-wrap:nth-child(1) { flex: 1.4 1 180px; min-width: 0; }
.trf-action-row > .trf-select-wrap:nth-child(2) { flex: 0.8 1 120px; min-width: 0; }
.trf-action-row > input[type="number"].trf-select { flex: 0 0 110px; min-width: 0; }
.trf-action-row > input[type="time"].trf-select { flex: 1 1 140px; min-width: 0; }
.trf-action-row > .trf-delete { flex: 0 0 44px; }
.trf-op { max-width: 94px; }
.trf-value-wrap {
    display: flex;
    min-width: 0;
    height: 44px;
}
.trf-value-wrap .trf-input {
    border-radius: 8px 0 0 8px;
    flex: 1;
    width: 0;
}
.trf-suffix {
    width: 52px;
    border: 1px solid #dae5f5;
    border-left: 0;
    background: #eef3f9;
    border-radius: 0 8px 8px 0;
    display: grid;
    place-items: center;
    font-weight: 600;
    color: #394975;
}
.trf-delete {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 8px;
    background: #ef3030;
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    flex-shrink: 0;
}
.trf-delete:hover:not(:disabled) { background: #ce2020; }
.trf-delete:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.trf-add {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    border-radius: 8px;
    background: #eaf0fa;
    color: #294779;
    padding: 12px 16px;
    font-weight: 650;
    margin-top: 12px;
    cursor: pointer;
    font: inherit;
}
.trf-add:hover { background: #dce6f7; }
.trf-footer {
    display: flex;
    gap: 12px;
    padding-top: 4px;
    flex-wrap: wrap;
}
.trf-primary,
.trf-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 48px;
    padding: 0 24px;
    font-weight: 650;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
}
.trf-primary {
    background: #2361f2;
    color: #fff;
    min-width: 120px;
}
.trf-primary:hover:not(:disabled) { background: #1355d9; }
.trf-secondary {
    background: #e7edf8;
    color: #254477;
    min-width: 110px;
}
.trf-secondary:hover:not(:disabled) { background: #dce6f7; }
.trf-primary:disabled,
.trf-secondary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.trf-alert {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #FEF2F2;
    color: #B42332;
    margin-bottom: 14px;
}
@media (max-width: 1080px) {
    .trf-general { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .trf-condition-row {
        grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) 86px minmax(100px, 0.8fr) 42px;
        gap: 10px;
    }
}
@media (max-width: 700px) {
    .trf-header { gap: 12px; }
    .trf-header-icon { width: 52px; height: 52px; }
    .trf-header h1 { font-size: 1.4rem; }
    .trf-card { padding: 16px 12px; }
    .trf-general { grid-template-columns: 1fr; }
    .trf-condition-row,
    .trf-action-row {
        gap: 8px;
        padding-bottom: 12px;
        border-bottom: 1px solid #e4ebf6;
    }

    .trf-action-row > input[type="number"].trf-select { flex-basis: 90px; }
    .trf-op { max-width: none; }
}

/* Mobile: rows become stacked cards instead of overflowing grids.
   Placed after the 1080px/700px blocks so it wins the cascade on small screens. */
@media (max-width: 640px) {
    .trf-label-row { display: none; }

    .trf-condition-row,
    .trf-action-row {
        display: grid;
        grid-template-columns: 84px minmax(0, 1fr) 42px;
        gap: 10px;
        padding: 12px;
        border: 1px solid #dbe5f2;
        border-radius: 12px;
        background: #f8fafc;
    }
    .trf-condition-row > *,
    .trf-action-row > * { min-width: 0; }

    /* First two controls span the full card width */
    .trf-condition-row > :nth-child(1),
    .trf-condition-row > :nth-child(2),
    .trf-action-row > :nth-child(1),
    .trf-action-row > :nth-child(2) {
        grid-column: 1 / -1;
    }

    /* Rows without a delete button (active window) stack fully */
    .trf-action-row:not(:has(> .trf-delete)) > * {
        grid-column: 1 / -1;
    }

    .trf-condition-row .trf-select,
    .trf-condition-row .trf-input,
    .trf-action-row .trf-select {
        width: 100%;
    }
    .trf-op { max-width: none; }
    .trf-value-wrap .trf-input { width: auto; }
}


/* ===== Action History (KAN-37) ===== */
.ah-page { max-width: 100%; }
.ah-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.ah-header-left { display: flex; align-items: center; gap: 12px; }
.ah-header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: #EFF6FF;
    color: #2563EB;
}
.ah-header h1 { margin: 0; font-size: 1.5rem; color: #152B55; }
.ah-header p { margin: 4px 0 0; color: #64748B; font-size: 0.9rem; }
.ah-device-select,
.ah-select-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    min-width: 160px;
    padding: 0 36px 0 12px;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    background: #fff;
    position: relative;
    cursor: pointer;
}
.ah-device-select:focus-within,
.ah-select-field:focus-within {
    border-color: #6D9DE0;
    box-shadow: 0 0 0 2px #DBE9FF;
}
.ah-field-icon { color: #64748B; flex-shrink: 0; }
.ah-select-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ah-select-label { font-size: 11px; font-weight: 600; color: #49678F; line-height: 1.2; }
.ah-select-value {
    color: #112B59;
    font-weight: 700;
    font-size: 14px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ah-select {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    border: none;
    background: transparent;
    appearance: none;
    -webkit-appearance: none;
    z-index: 1;
}
.ah-chevron {
    position: absolute;
    right: 12px;
    color: #64748B;
    pointer-events: none;
    z-index: 0;
}
.ah-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
}
.ah-datetime-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 10px;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    background: #fff;
}
.ah-input {
    border: none;
    outline: none;
    font-size: 13px;
    color: #152B55;
    background: transparent;
}
.ah-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 14px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.ah-btn-primary { background: #2563EB; color: #fff; }
.ah-btn-secondary { background: #EEF2F7; color: #152B55; }
.ah-alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    background: #FEF2F2;
    color: #B42332;
}
.ah-empty { color: #64748B; padding: 24px 8px; }
.ah-timeline { position: relative; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.ah-timeline::before {
    content: "";
    position: absolute;
    left: 5px;
    top: 36px;
    bottom: 12px;
    width: 2px;
    background: #DCE5F1;
}
.ah-timeline.is-table::before { display: none; }
.ah-timeline.is-table { padding-left: 0; }
.ah-timeline-header {
    display: none;
    grid-template-columns: 12% 20% 18% 21% 13% 12% 4%;
    gap: 8px;
    padding: 0 16px 8px 28px;
    font-size: 12px;
    font-weight: 700;
    color: #64748B;
}
@media (min-width: 1200px) {
    .ah-timeline-header { display: grid; }
}
.ah-card {
    position: relative;
    background: #fff;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(21, 43, 85, 0.04);
    transition: box-shadow 160ms ease;
}
.ah-card:hover { box-shadow: 0 2px 8px rgba(21, 43, 85, 0.08); }
.ah-card-main { position: relative; padding: 12px 16px; }
.ah-dot {
    position: absolute;
    left: -16px;
    top: 22px;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: #94A3B8;
    border: 2px solid #F3F7FC;
}
.ah-timeline.is-table .ah-dot { display: none; }
.ah-card.is-success .ah-dot { background: #087F48; }
.ah-card.is-failed .ah-dot { background: #B42332; }
.ah-card.is-pending .ah-dot { background: #B54708; }
.ah-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
@media (min-width: 1200px) {
    .ah-grid {
        grid-template-columns: 12% 20% 18% 21% 13% 12% 4%;
        align-items: center;
        gap: 8px;
    }
}
.ah-cell { min-width: 0; }
.ah-datetime { display: flex; flex-direction: column; gap: 2px; }
.ah-date { font-weight: 700; color: #152B55; font-size: 13px; }
.ah-time { color: #64748B; font-size: 12px; }
.ah-origin, .ah-device {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.ah-origin-icon, .ah-device-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    flex-shrink: 0;
}
.ah-origin-icon.is-automation { background: #DBEAFE; color: #2563EB; }
.ah-origin-icon.is-user { background: #EDE9FE; color: #6D28D9; }
.ah-origin-icon.is-system { background: #F1F5F9; color: #64748B; }
.ah-origin-text, .ah-device > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ah-origin-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    height: 20px;
    padding: 0 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
}
.ah-origin-badge.is-automation { background: #DBEAFE; color: #1D4ED8; }
.ah-origin-badge.is-user { background: #EDE9FE; color: #6D28D9; }
.ah-origin-badge.is-system { background: #F1F5F9; color: #64748B; }
.ah-origin-name, .ah-device-name { font-weight: 600; color: #152B55; font-size: 13px; }
.ah-origin-details, .ah-device-meta { color: #64748B; font-size: 12px; }
.ah-action { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ah-action-label { font-weight: 600; color: #152B55; font-size: 13px; }
.ah-state {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
}
.ah-state.is-on { background: #DDF7E9; color: #087F48; }
.ah-state.is-off { background: #F1F5F9; color: #64748B; }
.ah-arrow { color: #64748B; }
.ah-result-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
}
.ah-result-chip.is-success { background: #DDF7E9; color: #087F48; }
.ah-result-chip.is-failed { background: #FEE4E2; color: #B42332; }
.ah-result-chip.is-pending { background: #FEF0C7; color: #B54708; }
.ah-result-chip.is-unknown { background: #F1F5F9; color: #64748B; }
.ah-duration {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #152B55;
    font-size: 13px;
}
.ah-expand { display: flex; justify-content: flex-end; }
.ah-expand-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: #EEF2F7;
    color: #152B55;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.ah-details {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 0 16px 16px;
    border-top: 1px solid #E8EEF6;
}
@media (min-width: 900px) {
    .ah-details { grid-template-columns: 1fr 1fr; }
}
.ah-detail-panel {
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}
.ah-detail-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #F1F5F9;
    color: #152B55;
    font-size: 13px;
    font-weight: 700;
}
.ah-detail-list {
    display: grid;
    grid-template-columns: minmax(120px, 36%) 1fr;
    gap: 8px 12px;
    margin: 0;
    padding: 12px;
    font-size: 13px;
}
.ah-detail-list dt { color: #64748B; font-weight: 600; }
.ah-detail-list dd { margin: 0; color: #152B55; word-break: break-word; }
.ah-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}
.ah-range { color: #64748B; font-size: 13px; }
.ah-pager { display: inline-flex; align-items: center; gap: 6px; }
.ah-page-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    background: #fff;
    color: #152B55;
    cursor: pointer;
}
.ah-page-btn.is-active { background: #2563EB; color: #fff; border-color: #2563EB; }
.ah-page-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* === Users page (KAN-38) === */
.users-page .sensors-alert { margin-bottom: 16px; }
.users-toolbar {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}
.users-search {
    flex: 1 1 auto;
    max-width: 420px;
    min-width: 220px;
}
.users-filter-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 220px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #41536B;
}
.users-filter-field .form-control {
    min-height: 48px;
}
.sensors-alert.is-success {
    background: #DDF7E9;
    color: #087F48;
}
.users-form-card {
    margin-bottom: 16px;
    padding: 20px;
    background: #fff;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
}
.users-form-card h4 { margin: 0 0 16px; color: #152B55; }
.users-form-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.users-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.users-avatar {
    background: #EEF2F7;
    color: #152B55;
}
.users-pin-chip {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
}
.users-pin-chip.is-set {
    background: #E8EEF6;
    color: #152B55;
}
.users-pin-chip.is-unset {
    background: #F1F5F9;
    color: #64748B;
}
.users-menu-item {
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
}

/* === PIN settings (KAN-39) === */
.pin-settings-page {
    max-width: 640px;
}
.pin-settings-stack {
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.pin-card {
    background: #fff;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
    padding: 24px;
}
.pin-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.pin-card-header h2 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    color: #152B55;
}
.pin-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #EEF2F7;
    color: #152B55;
    flex-shrink: 0;
}
.pin-card-intro {
    margin: 0 0 16px;
    color: #64748B;
    font-size: 0.9rem;
}
.pin-info {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #F1F5F9;
    color: #475569;
    font-size: 0.875rem;
    line-height: 1.4;
}
.pin-info .lucide { flex-shrink: 0; margin-top: 1px; color: #2563EB; }
.pin-field {
    display: grid;
    grid-template-columns: 140px 1fr;
    align-items: center;
    gap: 12px 16px;
    margin-bottom: 16px;
}
.pin-field label {
    margin: 0;
    color: #152B55;
    font-size: 0.9rem;
    font-weight: 600;
}
.pin-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.pin-input {
    width: 100%;
    height: 44px;
    padding: 0 44px 0 12px;
    border: 1px solid #DCE5F1;
    border-radius: 8px;
    background: #fff;
    color: #152B55;
    font-size: 0.95rem;
}
.pin-input:focus {
    outline: none;
    border-color: #2563EB;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}
.pin-visibility-btn {
    position: absolute;
    right: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #64748B;
    cursor: pointer;
}
.pin-visibility-btn:hover { background: #F1F5F9; color: #152B55; }
.pin-primary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    padding: 0 20px;
    border: none;
    border-radius: 8px;
    background: #2563EB;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.pin-primary-btn:hover { background: #1D4ED8; }
.pin-primary-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.pin-alert {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
}
.pin-alert.is-error { background: #FEF2F2; color: #B42332; }
.pin-alert.is-success { background: #DDF7E9; color: #087F48; }
@media (max-width: 640px) {
    .pin-field {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}

/* === Reports analytics (KAN-40) === */
.reports-page { display: flex; flex-direction: column; gap: 24px; }
.reports-toolbar {
    display: flex; flex-direction: column; gap: 12px;
    padding: 16px; background: #fff; border: 1px solid #DCE5F1; border-radius: 8px;
}
.reports-toolbar-filters {
    display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end;
}
.reports-field { display: flex; flex-direction: column; gap: 6px; min-width: 160px; }
.reports-field span { font-size: 12px; font-weight: 600; color: #64748B; }
.reports-select, .reports-input {
    height: 44px; padding: 0 12px; border: 1px solid #DCE5F1; border-radius: 8px;
    background: #fff; color: #152B55; font-size: 0.95rem;
}
.reports-select.sm { height: 36px; min-width: 140px; }
.reports-toolbar-actions {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.reports-btn {
    display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px;
    border: 1px solid #DCE5F1; border-radius: 8px; background: #fff; color: #152B55;
    font-weight: 600; cursor: pointer; transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.reports-btn-spinner {
    display: inline-flex; width: 16px; height: 16px; flex-shrink: 0;
    visibility: hidden;
}
.reports-btn-spinner.is-visible { visibility: visible; }
.reports-btn:hover:not(:disabled) { background: #F1F5F9; border-color: #94A3B8; }
.reports-btn.is-primary { background: #2563EB; border-color: #2563EB; color: #fff; }
.reports-btn.is-primary:hover:not(:disabled) { background: #1D4ED8; border-color: #1D4ED8; color: #fff; }
.reports-btn.is-outline { background: #fff; border-color: #2563EB; color: #2563EB; }
.reports-btn.is-outline:hover:not(:disabled) { background: #EFF6FF; border-color: #1D4ED8; color: #1D4ED8; }
.reports-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.reports-info-banner {
    display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px;
    background: #EFF6FF; border: 1px solid #BFDBFE; border-radius: 8px; color: #1E3A8A;
}
.reports-info-banner strong { display: block; margin-bottom: 4px; }
.reports-info-banner p { margin: 0; color: #1E40AF; font-size: 0.9rem; }
.reports-icon-btn {
    margin-left: auto; border: none; background: transparent; color: inherit; cursor: pointer;
    width: 32px; height: 32px; border-radius: 6px; transition: background-color 0.15s ease;
}
.reports-icon-btn:hover { background: rgba(37, 99, 235, 0.12); }
.reports-select:hover, .reports-input:hover { border-color: #94A3B8; }
.reports-link:hover { text-decoration: underline; }
.reports-kpi-grid {
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px;
}
.reports-kpi-card {
    display: flex; gap: 12px; padding: 16px; background: #fff; border: 1px solid #DCE5F1;
    border-radius: 8px; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.reports-kpi-icon {
    width: 40px; height: 40px; border-radius: 999px; background: #EEF2F7; color: #2563EB;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.reports-kpi-icon.tint-blue { background: #E3F0FD; color: #2563EB; }
.reports-kpi-icon.tint-orange { background: #FDEBD8; color: #E8862D; }
.reports-kpi-icon.tint-gray { background: #EEF1F4; color: #7A8699; }
.reports-kpi-title { font-size: 12px; font-weight: 600; color: #64748B; }
.reports-kpi-value { font-size: 1.5rem; font-weight: 700; color: #152B55; line-height: 1.2; }
.reports-kpi-trend { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; margin-top: 4px; color: #64748B; }
.reports-kpi-trend.up { color: #087F48; }
.reports-kpi-trend.down { color: #B42332; }
.reports-charts-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.reports-card {
    background: #fff; border: 1px solid #DCE5F1; border-radius: 8px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04); padding: 16px;
}
.reports-card-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px;
}
.reports-card-header h2 {
    margin: 0; display: inline-flex; align-items: center; gap: 8px;
    font-size: 1rem; color: #152B55;
}
.reports-card-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.reports-chart-canvas { position: relative; height: 280px; }
.reports-empty { color: #64748B; text-align: center; padding: 48px 16px; }
.reports-caption { margin: 8px 0 0; color: #64748B; font-size: 12px; }
.reports-link {
    border: none; background: transparent; color: #2563EB; font-weight: 600; cursor: pointer;
}
.reports-insights-grid {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px;
}
.reports-insight {
    padding: 12px; border-radius: 8px; background: #F8FAFC; border: 1px solid #E8EEF6;
}
.reports-insight-label { font-size: 12px; color: #64748B; font-weight: 600; }
.reports-insight-value { font-size: 1.1rem; font-weight: 700; color: #152B55; margin-top: 4px; }
.reports-insight-detail { font-size: 12px; color: #64748B; margin-top: 4px; }
.hidden { display: none !important; }
.spin { animation: wm-spin 1s linear infinite; }
@keyframes wm-spin { to { transform: rotate(360deg); } }
@media (max-width: 1199px) {
    .reports-kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .reports-charts-row { grid-template-columns: 1fr 1fr; }
    .reports-insights-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
    .reports-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .reports-kpi-card { flex-direction: column; gap: 8px; padding: 12px; }
    .reports-kpi-icon { width: 34px; height: 34px; }
    .reports-kpi-value { font-size: 1.25rem; }
    .reports-charts-row, .reports-insights-grid { grid-template-columns: 1fr; }
    .reports-toolbar-actions { width: 100%; }
}
@media (max-width: 380px) {
    .reports-kpi-grid { grid-template-columns: 1fr; }
}

/* === Customers management (KAN-42) === */
.customers-toolbar {
    display: flex; flex-wrap: wrap; gap: 16px; align-items: center;
    padding: 16px; margin-bottom: 24px;
    background: #fff; border: 1px solid #DCE5F1; border-radius: 8px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.customers-search {
    position: relative; flex: 1 1 45%; min-width: 220px;
}
.customers-search-icon {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    color: #64748B; display: inline-flex; pointer-events: none;
}
.customers-search-input {
    width: 100%; height: 48px; padding: 0 14px 0 42px;
    border: 1px solid #DCE5F1; border-radius: 8px; background: #fff;
    color: #152B55; font-size: 0.95rem;
}
.customers-search-input:hover { border-color: #94A3B8; }
.customers-status-field {
    position: relative; flex: 0 0 220px; max-width: 100%;
}
.customers-status-select {
    width: 100%; height: 48px; padding: 0 40px 0 14px;
    border: 1px solid #DCE5F1; border-radius: 8px; background: #fff;
    color: #152B55; font-size: 0.95rem; appearance: none; cursor: pointer;
}
.customers-status-chevron {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    color: #64748B; pointer-events: none; display: inline-flex;
}
.customers-form-card {
    margin-bottom: 24px; padding: 20px; background: #fff;
    border: 1px solid #DCE5F1; border-radius: 8px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.customers-form-card h4 { margin: 0 0 16px; color: #152B55; }
.customers-form-actions {
    display: flex; justify-content: space-between; gap: 12px; margin-top: 16px;
}
.customers-org-icon {
    width: 40px; height: 40px; border-radius: 999px; background: #E4F0FF; color: #2563EB;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.customers-table tbody tr { height: 84px; }
.customers-table thead th { background: #F1F5F9; height: 48px; }
.customers-sort-btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: none; background: transparent; color: inherit;
    font: inherit; font-weight: 600; cursor: pointer; padding: 0;
}
.customers-status-chip {
    display: inline-flex; align-items: center; gap: 8px;
    height: 28px; padding: 0 12px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
}
.customers-status-chip.is-active { background: #DDF7E9; color: #087F48; }
.customers-status-chip.is-disabled { background: #FDE8E8; color: #B42332; }
.customers-status-dot {
    width: 8px; height: 8px; border-radius: 999px; background: currentColor;
}
.customers-table .sensors-col-actions {
    width: auto;
    min-width: 240px;
    white-space: nowrap;
}
.customers-row-actions {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
}
.customers-edit-btn, .customers-disable-btn, .customers-enable-btn {
    display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
    border-radius: 8px; font-weight: 600; cursor: pointer; background: #fff;
}
.customers-edit-btn {
    border: 1px solid #DCE5F1; color: #152B55;
}
.customers-edit-btn:hover:not(:disabled) { background: #F8FBFF; border-color: #93C5FD; }
.customers-disable-btn {
    border: 1px solid #FECACA; color: #B42332; background: #FEF2F2;
}
.customers-disable-btn:hover:not(:disabled) { background: #FEE2E2; }
.customers-disable-btn.solid { background: #B42332; border-color: #B42332; color: #fff; }
.customers-enable-btn {
    border: 1px solid #A7F3D0; color: #087F48; background: #ECFDF5;
}
.customers-enable-btn:hover:not(:disabled) { background: #D1FAE5; }
.customers-enable-btn.solid { background: #087F48; border-color: #087F48; color: #fff; }
.customers-table-footer {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    min-height: 72px; padding: 0 16px; border-top: 1px solid #E8EEF6; flex-wrap: wrap;
}
.customers-retry {
    margin-left: 12px; border: none; background: transparent;
    color: #2563EB; font-weight: 600; cursor: pointer;
}
.customers-skeleton {
    height: 16px; border-radius: 6px; background: linear-gradient(90deg, #E2E8F0, #F8FAFC, #E2E8F0);
    background-size: 200% 100%; animation: customers-shimmer 1.2s linear infinite;
}
.customers-skeleton.sm { width: 96px; }
.customers-skeleton-row td { vertical-align: middle; }
@keyframes customers-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.customers-modal-backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.35); z-index: 40;
}
.customers-modal {
    position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: min(440px, calc(100vw - 32px)); padding: 24px; background: #fff;
    border: 1px solid #DCE5F1; border-radius: 8px; z-index: 41;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
}
.customers-modal-icon {
    width: 44px; height: 44px; border-radius: 999px; background: #FEF3C7; color: #B45309;
    display: inline-flex; align-items: center; justify-content: center; margin-bottom: 12px;
}
.customers-modal h3 { margin: 0 0 8px; color: #152B55; font-size: 1.15rem; }
.customers-modal p { margin: 0 0 20px; color: #64748B; font-size: 0.95rem; line-height: 1.45; }
.customers-modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
@media (max-width: 767px) {
    .customers-status-field { width: 100%; margin-left: 0; }
    .customers-table .sensors-col-actions { min-width: 0; white-space: normal; }
    .customers-row-actions { justify-content: flex-start; flex-wrap: wrap; }
}

/* === Sensor Detail Page (Material Design 3 inspired) === */

.page-titles {
    flex: 1 1 420px;
    min-width: 0;
}

.label-sm {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.sensor-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.sensor-detail-card {
    background: var(--md-surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--md-radius);
    padding: 20px 24px;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--md-radius);
    background: #E0E7FF;
    color: var(--md-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-icon svg {
    width: 20px;
    height: 20px;
}

.card-title {
    font-size: 16px;
    font-weight: 500;
    margin: 0;
    color: var(--navy);
}

.sensor-props {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 32px;
    margin: 0;
}

.sensor-props .prop {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 0;
    border-top: 1px solid var(--gray-200);
    min-width: 0;
}

.sensor-props .prop:nth-child(-n+2) {
    border-top: none;
}

.sensor-props .prop dt {
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-600);
    letter-spacing: 0.5px;
}

.sensor-props .prop dd {
    margin: 0;
    font-size: 16px;
    overflow-wrap: anywhere;
}

.mono {
    font-family: var(--font-mono);
    font-size: 13px;
}

.raw {
    font-family: var(--font-mono);
    font-size: 12.5px;
    background: var(--gray-100);
    color: var(--gray-600);
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

.level-card {
    background: linear-gradient(135deg, #DBEAFE 0%, #E0E7FF 100%);
    border: 1px solid var(--gray-200);
    border-radius: var(--md-radius);
    padding: 20px 24px;
    display: flex;
    gap: 20px;
    align-items: center;
    color: #1E3A8A;
}

.level-card.level-error {
    background: linear-gradient(135deg, #FEE2E2 0%, #FECACA 100%);
    color: #991B1B;
}

.tank-graphic {
    position: relative;
    width: 76px;
    height: 128px;
    border-radius: 14px 14px 18px 18px;
    border: 3px solid currentColor;
    overflow: hidden;
    flex: none;
    opacity: 0.95;
}

.tank-water {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, #60A5FA 0%, #3B82F6 100%);
    transition: height 0.8s cubic-bezier(0.2, 0, 0, 1);
}

.tank-water.water-error {
    background: linear-gradient(180deg, #F87171 0%, #DC2626 100%);
}

.tank-water::before {
    content: "";
    position: absolute;
    left: -50%;
    top: -6px;
    width: 200%;
    height: 12px;
    border-radius: 45%;
    background: #60A5FA;
    animation: wave 4s linear infinite;
}

.tank-water.water-error::before {
    background: #F87171;
}

@keyframes wave {
    to { transform: translateX(25%); }
}

.tank-ticks {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        to top,
        transparent 0 24.2px,
        rgba(30, 58, 138, 0.35) 24.2px 25.6px
    );
    pointer-events: none;
}

.level-card.level-error .tank-ticks {
    background: repeating-linear-gradient(
        to top,
        transparent 0 24.2px,
        rgba(153, 27, 27, 0.35) 24.2px 25.6px
    );
}

.level-info {
    flex: 1;
    min-width: 0;
}

.level-label {
    font-size: 14px;
    font-weight: 500;
    opacity: 0.85;
    margin-bottom: 4px;
}

.level-big {
    font-size: 57px;
    line-height: 64px;
    font-weight: 400;
    letter-spacing: -0.025em;
    margin-bottom: 8px;
}

.level-big .level-unit {
    font-size: 28px;
}

.level-trend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    margin-bottom: 4px;
}

.level-trend svg {
    width: 18px;
    height: 18px;
}

.level-reported {
    font-size: 12px;
    opacity: 0.8;
}

.chip-assist {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 12px;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--navy);
    background: transparent;
}

.chip-assist svg {
    width: 16px;
    height: 16px;
}

.actuator-state {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.actuator-state svg {
    width: 16px;
    height: 16px;
    color: var(--gray-600);
}

.actions-cell {
    text-align: right;
}

.section-header .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* ===== M3 section head + table card (sensor detail) ===== */
.section-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 32px 0 12px;
    flex-wrap: wrap;
}

.section-head h2 {
    margin: 0;
    font-size: 22px;
    line-height: 28px;
    font-weight: 400;
    color: var(--navy);
}

.section-head > svg.lucide {
    width: 20px;
    height: 20px;
    color: var(--gray-600);
}

.section-head .count {
    margin-left: auto;
}

.table-card {
    border: 1px solid var(--md-outline-variant, var(--gray-200));
    border-radius: var(--md-radius);
    overflow: hidden;
    background: var(--white);
}

.table-card .data-table {
    margin: 0;
    box-shadow: none;
    border-radius: 0;
}

.table-card .data-table th {
    background: var(--md-surface-container, #ECEEF4);
    color: var(--gray-600);
    font-family: var(--font-sans, inherit);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.1px;
    text-transform: none;
    padding: 14px 16px;
    white-space: nowrap;
}

.table-card .data-table td {
    padding: 12px 16px;
    height: 52px;
    border-bottom: none;
    border-top: 1px solid var(--md-outline-variant, var(--gray-200));
    font-size: 14px;
    vertical-align: middle;
}

.table-card .data-table tbody tr:nth-child(even) {
    background: transparent;
}

.table-card .data-table tbody tr:hover {
    background: color-mix(in srgb, var(--md-on-surface, #191C20) 5%, transparent);
}

.table-card .data-table th.actions-cell,
.table-card .data-table td.actions-cell {
    text-align: right;
    width: 1%;
}

.readings-table tbody tr.reading-latest td {
    background: rgba(37, 99, 235, 0.06);
}

.reading-timestamp .timestamp-stack {
    display: flex;
    flex-direction: column;
}

.timestamp-relative {
    font-size: 12px;
    color: var(--gray-600);
}

.badge-latest {
    display: inline-block;
    margin-left: 8px;
    font-size: 11px;
    font-weight: 500;
    line-height: 16px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--md-primary);
    color: white;
    vertical-align: 1px;
}

.reading-level .level-display {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 160px;
}

.level-value-text {
    width: 48px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.level-bar {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--gray-200);
    overflow: hidden;
    min-width: 60px;
}

.level-bar-fill {
    display: block;
    height: 100%;
    border-radius: 2px;
    background: var(--md-primary);
}

.level-bar.level-bar-error .level-bar-fill {
    background: var(--md-offline);
}

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

@media (max-width: 767px) {
    .section-header .actions {
        width: 100%;
    }

    .section-header .actions .btn {
        flex: 1 1 auto;
    }

    .section-header .actions .btn-refresh {
        flex-basis: 100%;
    }

    .sensor-detail-grid {
        gap: 12px;
    }

    .sensor-detail-card {
        padding: 16px;
    }

    .sensor-props {
        grid-template-columns: 1fr;
    }

    .sensor-props .prop:nth-child(2) {
        border-top: 1px solid var(--gray-200);
    }

    .level-card {
        padding: 16px;
    }

    .level-big {
        font-size: 45px;
        line-height: 52px;
    }

    .level-big .level-unit {
        font-size: 22px;
    }

    .readings-table thead {
        display: none;
    }

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

    .readings-table tr {
        padding: 12px 16px;
        border-top: 1px solid var(--gray-200);
    }

    .readings-table tbody tr:first-child {
        border-top: none;
    }

    .readings-table td {
        border: none;
        height: auto;
        padding: 4px 0;
    }

    .readings-table td.reading-timestamp {
        margin-bottom: 8px;
    }

    .readings-table tr.reading-latest {
        background: rgba(37, 99, 235, 0.06);
    }

    .readings-table tr.reading-latest td {
        background: transparent;
    }

    .badge-latest {
        display: none;
    }

    .readings-table tr.reading-latest .timestamp-relative::before {
        content: "Latest · ";
        color: var(--md-primary);
        font-weight: 500;
    }

    .reading-level .level-display {
        min-width: 0;
        max-width: 100%;
    }
}

/* ===== Tank Detail Page Option A (KAN-xxx) ===== */

.tank-detail-header {
    margin-bottom: var(--md-space-3);
}

.tank-detail-header .label-sm {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.tank-desc {
    font-size: 1rem;
    line-height: 1.5;
    color: var(--gray-600);
    margin-top: 0.5rem;
}

/* Hero panel */
.tank-hero {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: var(--md-space-3);
    align-items: center;
    padding: var(--md-space-3);
    border-radius: var(--shape-l);
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
    margin-bottom: var(--md-space-2);
    box-shadow: var(--md-shadow);
}

.tank-hero.level-critical {
    background: var(--md-error-container);
    color: var(--md-on-error-container);
}

.tank-hero.level-stale {
    background: var(--md-surface-container-high);
    color: var(--md-on-surface);
}

.tank-graphic-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.tank-visual {
    position: relative;
    width: 96px;
    height: 156px;
    border-radius: 16px 16px 20px 20px;
    border: 3px solid currentColor;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.1);
    flex: none;
}

.tank-water {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, #5C9BD1, #33618D);
    transition: height 0.8s cubic-bezier(0.2, 0, 0, 1);
}

.tank-water::before {
    content: '';
    position: absolute;
    left: -50%;
    top: -6px;
    width: 200%;
    height: 12px;
    border-radius: 45%;
    background: #5C9BD1;
    animation: wave 4s linear infinite;
}

.tank-visual.crit .tank-water {
    background: linear-gradient(180deg, #E57373, #BA1A1A);
}

.tank-visual.crit .tank-water::before {
    background: #E57373;
}

.tank-visual.stale .tank-water {
    filter: grayscale(1);
    opacity: 0.55;
}

.tank-ticks {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        to top,
        transparent 0 calc(25% - 1.5px),
        color-mix(in srgb, currentColor 30%, transparent) calc(25% - 1.5px) 25%
    );
    pointer-events: none;
}

@keyframes wave {
    to {
        transform: translateX(25%);
    }
}

.hero-label {
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.15px;
    margin-bottom: 0.25rem;
}

.hero-level {
    display: flex;
    align-items: baseline;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.hero-level .level-value {
    font-size: 57px;
    line-height: 64px;
    font-weight: 400;
    letter-spacing: -0.25px;
}

.hero-level .level-unit {
    font-size: 28px;
    line-height: 36px;
}

.crit-text {
    color: var(--md-error) !important;
}

.hero-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.875rem;
    line-height: 1.25rem;
    letter-spacing: 0.25px;
}

.meta-sep {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.6;
}

.hero-note {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.625rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.hero-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(120px, 1fr));
    gap: var(--md-space-1);
    min-width: 0;
}

.hero-stat {
    background: color-mix(in srgb, var(--md-surface) 70%, transparent);
    color: var(--md-on-surface);
    border-radius: var(--shape-m);
    padding: 0.75rem 1rem;
}

.stat-label {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--md-on-surface-variant);
    font-size: 0.75rem;
    line-height: 1rem;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 22px;
    line-height: 28px;
    margin-top: 0.25rem;
}

.stat-value small {
    font-size: 0.875rem;
    color: var(--md-on-surface-variant);
}

/* Offline banner */
.tank-offline-banner {
    display: flex;
    gap: var(--md-space-1);
    align-items: flex-start;
    padding: 0.75rem 1rem;
    border-radius: var(--shape-m);
    background: var(--md-error-container);
    color: var(--md-on-error-container);
    font-size: 0.875rem;
    line-height: 1.25rem;
    margin-bottom: var(--md-space-2);
}

/* Grid layout */
.tank-grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--md-space-2);
    margin: var(--md-space-2) 0;
}

/* Cards */
.tank-card {
    border-radius: var(--shape-m);
    background: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    box-shadow: var(--md-shadow);
    overflow: hidden;
}

.tank-card-header {
    display: flex;
    align-items: center;
    gap: var(--md-space-1);
    padding: 1rem 1rem 0.5rem 1.5rem;
    min-height: 64px;
}

.tank-card-header .card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--shape-m);
    display: grid;
    place-items: center;
    background: var(--md-secondary-container);
    color: var(--md-on-secondary-container);
    flex: none;
}

.card-title {
    flex: 1;
    font-size: 22px;
    line-height: 28px;
    font-weight: 400;
    margin: 0;
}

.card-count {
    color: var(--md-on-surface-variant);
    font-weight: 400;
}

.card-empty {
    padding: 1.5rem;
    color: var(--md-on-surface-variant);
    text-align: center;
}

/* Actuator list */
.actuator-list,
.rule-list {
    list-style: none;
    margin: 0;
    padding: 0 0 0.5rem;
}

.actuator-item,
.rule-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem 0.75rem 1.5rem;
    min-height: 72px;
}

.actuator-item + .actuator-item,
.rule-item + .rule-item {
    border-top: 1px solid var(--md-outline-variant);
}

.actuator-icon,
.rule-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--shape-m);
    display: grid;
    place-items: center;
    background: var(--md-secondary-container);
    color: var(--md-on-secondary-container);
    flex: none;
}

.actuator-icon.active {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
}

.rule-icon.local {
    background: var(--md-tertiary-container);
    color: var(--md-on-tertiary-container);
}

.actuator-info,
.rule-info {
    flex: 1;
    min-width: 0;
}

.actuator-name,
.rule-name {
    font-size: 1rem;
    line-height: 1.5rem;
    letter-spacing: 0.5px;
    overflow-wrap: anywhere;
}

.actuator-meta,
.rule-meta {
    font-size: 0.875rem;
    line-height: 1.25rem;
    letter-spacing: 0.25px;
    color: var(--md-on-surface-variant);
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.625rem;
    align-items: center;
}

.actuator-actions,
.rule-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: none;
}

.actuator-state-chip,
.sensor-state-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    height: 28px;
    padding: 0 0.625rem 0 0.5rem;
    border-radius: var(--shape-s);
    font: 500 13px/18px var(--font-sans);
    letter-spacing: 0.1px;
    white-space: nowrap;
    background: var(--md-surface-container-highest);
    color: var(--md-on-surface-variant);
}

.actuator-state-chip.state-active,
.sensor-state-chip.chip-active {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
}

.sensor-state-chip.chip-neutral {
    background: var(--md-surface-container-highest);
    color: var(--md-on-surface-variant);
}

.state-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.btn-actuator {
    gap: 0.5rem;
}

.rule-state {
    font-size: 0.875rem;
    font-weight: 500;
    width: 28px;
    text-align: right;
    color: var(--md-on-surface-variant);
}

.rule-state.on {
    color: var(--md-primary);
}

.syncing {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--md-primary);
}

.spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* M3 Switch (for rules) */
.m3-switch {
    position: relative;
    width: 52px;
    height: 32px;
    border-radius: 16px;
    border: 2px solid var(--md-outline);
    background: var(--md-surface-container-highest);
    cursor: pointer;
    padding: 0;
    flex: none;
    transition: background 0.2s, border-color 0.2s;
}

.m3-switch .m3-switch-thumb {
    position: absolute;
    top: 50%;
    left: 6px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--md-outline);
    transform: translateY(-50%);
    transition: all 0.25s cubic-bezier(0.2, 0, 0, 1);
    display: grid;
    place-items: center;
}

.m3-switch .m3-switch-thumb svg {
    width: 16px;
    height: 16px;
    opacity: 0;
    color: var(--md-on-primary-container);
    stroke-width: 3;
}

.m3-switch[aria-checked="true"] {
    background: var(--md-primary);
    border-color: var(--md-primary);
}

.m3-switch[aria-checked="true"] .m3-switch-thumb {
    left: 22px;
    width: 24px;
    height: 24px;
    background: var(--md-on-primary);
}

.m3-switch[aria-checked="true"] .m3-switch-thumb svg {
    opacity: 1;
    color: var(--md-primary);
}

.m3-switch.pending {
    opacity: 0.55;
    pointer-events: none;
}

.m3-switch:hover .m3-switch-thumb {
    box-shadow: 0 0 0 8px color-mix(in srgb, var(--md-on-surface) 8%, transparent);
}

/* Rule legend */
.rule-legend {
    display: grid;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem 1rem;
    border-top: 1px solid var(--md-outline-variant);
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--md-on-surface-variant);
}

.legend-item {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

/* Sensors table */
.sensors-card {
    margin-top: var(--md-space-2);
}

.sensors-card .tank-card-header {
    padding-bottom: 0.75rem;
}

.table-wrap {
    overflow-x: auto;
}

.sensors-table {
    width: 100%;
    border-collapse: collapse;
}

.sensors-table th {
    text-align: left;
    font: 500 14px/20px var(--font-sans);
    letter-spacing: 0.1px;
    color: var(--md-on-surface-variant);
    background: var(--md-surface-container);
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.sensors-table td {
    padding: 0.625rem 1rem;
    height: 56px;
    border-top: 1px solid var(--md-outline-variant);
    font-size: 0.875rem;
    line-height: 1.25rem;
    letter-spacing: 0.25px;
    vertical-align: middle;
}

.sensors-table th:first-child,
.sensors-table td:first-child {
    padding-left: 1.5rem;
}

.sensors-table tbody tr:hover {
    background: color-mix(in srgb, var(--md-on-surface) 4%, transparent);
}

.sensors-table .actions-col {
    text-align: right;
    white-space: nowrap;
}

.sensors-table .actions-col .btn + .btn {
    margin-left: 0.5rem;
}

.name-cell {
    cursor: pointer;
}

.sensor-name-link {
    color: var(--md-primary);
    font-weight: 500;
    text-decoration: none;
}

.sensor-name-link:hover {
    text-decoration: underline;
}

.sensor-type {
    font-size: 0.75rem;
    color: var(--md-on-surface-variant);
    margin-top: 0.125rem;
}

.sensor-status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.sensor-status-chip.chip-disabled {
    background: var(--md-surface-container-highest);
    color: var(--md-on-surface-variant);
}

.level-cell {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 150px;
}

.level-cell .level-value {
    width: 52px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.level-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--md-secondary-container);
    overflow: hidden;
    flex: 1;
    max-width: 120px;
}

.level-bar > i {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: var(--md-primary);
    transition: width 0.6s cubic-bezier(0.2, 0, 0, 1);
}

.level-bar.crit > i {
    background: var(--md-error);
}

.level-bar.stale > i {
    background: var(--md-outline);
}

.chip-neutral {
    background: var(--md-surface-container-highest);
    color: var(--md-on-surface-variant);
}

.chip-active {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
}

/* Button variants */
.btn-outlined {
    border: 1px solid var(--md-outline);
    background: transparent;
    color: var(--md-primary);
}

.btn-outlined:hover {
    background: color-mix(in srgb, var(--md-primary) 8%, transparent);
}

.btn-outlined.danger {
    border-color: var(--md-error);
    color: var(--md-error);
}

.btn-outlined.danger:hover {
    background: color-mix(in srgb, var(--md-error) 8%, transparent);
}

.btn-filled {
    background: var(--md-primary);
    color: var(--md-on-primary);
}

.btn-filled:hover {
    box-shadow: var(--elev-1);
}

.btn-tonal {
    background: var(--md-secondary-container);
    color: var(--md-on-secondary-container);
}

.btn-tonal:hover {
    box-shadow: var(--elev-1);
}

.btn-sm {
    height: 32px;
    padding: 0 0.75rem;
    font-size: 0.8125rem;
}

/* Form */
.inline-form {
    padding: 1.5rem;
    border-top: 1px solid var(--md-outline-variant);
    background: var(--md-surface-container-low);
}

.inline-form h4 {
    margin-bottom: 1rem;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Responsive */
@media (max-width: 1000px) {
    .tank-hero {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .hero-stats {
        grid-column: 1 / -1;
    }

    .tank-grid-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 700px) {
    .tank-hero {
        padding: 1.25rem;
        gap: 1rem 1.25rem;
    }

    .tank-visual {
        width: 72px;
        height: 120px;
    }

    .hero-level .level-value {
        font-size: 45px;
        line-height: 52px;
    }

    .hero-stats {
        gap: 0.5rem;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .stat-label {
        font-size: 10.5px;
        letter-spacing: 0.3px;
    }

    .stat-label svg {
        display: none;
    }

    .stat-value {
        font-size: 18px;
        line-height: 24px;
    }

    .stat-value small {
        display: block;
        font-size: 0.75rem;
        line-height: 1rem;
    }

    .hero-stat {
        padding: 0.625rem 0.75rem;
    }

    .actuator-actions,
    .rule-actions {
        flex-direction: column;
        align-items: flex-end;
        gap: 0.5rem;
    }

    .rule-item .rule-actions {
        flex-direction: row;
    }

    .rule-legend {
        padding: 0.75rem 1rem 1rem;
    }

    /* Responsive table to list */
    .sensors-table {
        min-width: 0;
    }

    .sensors-table thead {
        display: none;
    }

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

    .sensors-table tr {
        padding: 0.75rem 1rem;
        border-top: 1px solid var(--md-outline-variant);
    }

    .sensors-table td {
        border: none;
        height: auto;
        padding: 0.25rem 0 !important;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
    }

    .sensors-table td::before {
        content: attr(data-label);
        font: 500 12px/16px var(--font-sans);
        letter-spacing: 0.5px;
        color: var(--md-on-surface-variant);
    }

    .sensors-table td.name-cell::before,
    .sensors-table td.actions-col::before {
        content: none;
    }

    .sensors-table td.name-cell {
        font-size: 1rem;
    }

    .sensors-table td.actions-col {
        justify-content: flex-end;
        padding-top: 0.5rem !important;
    }

    .level-cell {
        min-width: 0;
    }
}

/* Devices table: flex rows on narrow/tablet widths (existing card layout handles phones) */
@media (min-width: 768px) and (max-width: 960px) {
    .sensors-table-devices {
        display: block;
        min-width: 0;
    }
    .sensors-table-devices tbody {
        display: block;
    }
    .sensors-table-devices thead {
        display: none;
    }
    .sensors-table-devices tbody tr {
        display: flex;
        align-items: center;
        gap: 10px;
        height: auto;
        padding: 10px 12px;
        max-width: 100%;
        border-bottom: 1px solid #E4EBF6;
    }
    .sensors-table-devices tbody td {
        display: block;
        height: auto;
        padding: 4px 0;
        border-bottom: none;
        white-space: normal;
    }
    .sensors-table-devices tbody tr:last-child {
        border-bottom: none;
    }
    .sensors-table-devices th:nth-child(3),
    .sensors-table-devices td:nth-child(3),
    .sensors-table-devices th:nth-child(5),
    .sensors-table-devices td:nth-child(5) {
        display: none;
    }
    .sensors-table-devices tbody td:nth-child(1) {
        flex: 1 1 auto;
        min-width: 0;
    }
    .sensors-table-devices tbody td:nth-child(2) {
        flex: 0 0 auto;
        min-width: 80px;
    }
    .sensors-table-devices tbody td:nth-child(4) {
        flex: 0 0 auto;
        margin-left: auto;
    }
    .sensors-table-devices tbody td:nth-child(6) {
        flex: 0 0 auto;
    }
    .sensors-table-devices tbody td[colspan] {
        flex: 1 1 100%;
        text-align: center;
    }
}

/* Devices table phone tweak: free row height so stacked cells don't overlap,
   and drop per-cell borders — only the row separator remains. */
@media (max-width: 768px) {
    .sensors-table tbody tr {
        height: auto;
    }
    .sensors-table tbody td {
        border-bottom: none;
    }
    .sensors-table tbody tr {
        border-top: 1px solid #E4EBF6;
    }
    .sensors-table tbody tr:first-child {
        border-top: none;
    }
}

/* Action history — real table view */
.ah-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #DCE5F2;
    border-radius: 10px;
    background: #fff;
}
.ah-table {
    width: 100%;
    min-width: 640px;
    border-collapse: collapse;
    font-size: 12px;
}
.ah-table th {
    background: #F1F5F9;
    color: #536984;
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .04em;
    text-align: left;
    padding: 8px 10px;
    white-space: nowrap;
}
.ah-table td {
    padding: 8px 10px;
    border-top: 1px solid #E8EEF6;
    vertical-align: middle;
    color: #152B55;
}
.ah-table .ah-date { display: block; font-weight: 600; white-space: nowrap; }
.ah-table .ah-time { display: block; color: #64748B; font-size: 10px; }
.ah-table .ah-origin-name { display: block; color: #64748B; font-size: 10px; }
.ah-table .ah-device-name { font-weight: 600; }
.ah-table .ah-device-meta { display: block; color: #64748B; font-size: 10px; }
.ah-table .ah-td-expand { text-align: right; }
.ah-details-row > td { padding: 0; background: #F8FAFF; }
.ah-details-row .ah-details { padding: 10px; }

@media (max-width: 768px) {
    .ah-table { min-width: 560px; }
    .ah-table td, .ah-table th { padding: 6px 8px; }
}

.alerts-filter-actions { display: flex; margin-top: 12px; }
.alerts-btn-ack-all {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border: none; border-radius: 8px;
    background: #2563EB; color: #fff;
    font-size: 13px; font-weight: 600; cursor: pointer;
}
.alerts-btn-ack-all:hover:not(:disabled) { background: #1D4ED8; }
.alerts-btn-ack-all:disabled { opacity: .6; cursor: not-allowed; }

.login-card { max-width: 420px; margin: 60px auto; padding: 28px; background: var(--white, #fff); border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.login-error { color: #C62828; font-size: 14px; margin-bottom: 12px; }
.login-success { color: #2E7D32; font-size: 14px; margin-bottom: 12px; }
.login-forgot { margin-top: 12px; text-align: center; }
.login-forgot a { color: #2563EB; font-size: 13px; }
