/* Fecha Admin Dashboard Styles */
:root {
    --primary: #658864;
    --primary-hover: #527052;
    --primary-light: #e8f0e8;
    --secondary: #A7A77B;
    --danger: #AD4E4E;
    --danger-hover: #922B2B;
    --success: #658864;
    --warning: #E5C07B;
    --bg: #F6EEDF;
    --bg-cream: #EDE5D6;
    --card-bg: #ffffff;
    --text: #333333;
    --text-muted: #666666;
    --border: #E0E0E0;
    --sidebar-bg: #333333;
    --sidebar-text: #999999;
    --sidebar-active: #ffffff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Landing Page */
.landing {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.landing-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.landing-hero {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
}

.landing-hero h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.landing-hero p {
    font-size: 1.25rem;
    color: var(--text-muted);
    max-width: 600px;
    margin-bottom: 2rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

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

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

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--bg);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* Login Page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-card {
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    text-align: center;
    margin-bottom: 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group > label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    transition: border-color 0.15s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-check input {
    width: 1rem;
    height: 1rem;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    padding-right: 2.5rem;
}

/* Alert */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid #bbf7d0;
}

.alert-warning {
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fed7aa;
}

/* Dashboard Layout */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 1.5rem 0;
    flex-shrink: 0;
    /* Pin to viewport and let the nav scroll on its own when too long,
       so a long menu doesn't drag the page along with it. */
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar-logo {
    padding: 0 1.5rem;
    margin-bottom: 2rem;
}

.sidebar-logo a {
    color: white;
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-nav {
    list-style: none;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.15s ease;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--sidebar-active);
}

.sidebar-nav svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Numeric notification badge in sidebar nav items (unread support chats,
   open incidences, etc.). Sits at the right edge of the link. */
.sidebar-nav .nav-badge {
    margin-left: auto;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.25rem;
    text-align: center;
}

.sidebar-footer {
    padding: 1.5rem;
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Buttons inside the dark sidebar (Logout) — the global .btn-outline
   uses var(--text) which equals the sidebar background, so the label
   would be invisible. Override to keep readable contrast. */
.sidebar .btn-outline {
    color: var(--sidebar-text);
    border-color: rgba(255, 255, 255, 0.25);
}
.sidebar .btn-outline:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.45);
    color: #fff;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--sidebar-text);
    font-size: 0.875rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-x: auto;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.stat-card h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

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

th, td {
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

tr:hover td {
    background: var(--bg);
}

tr.clickable-row {
    cursor: pointer;
}

.table-actions {
    display: flex;
    gap: 0.5rem;
}

.table-compact th,
.table-compact td {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.table-compact th {
    font-size: 0.75rem;
}

.text-muted {
    color: var(--text-muted);
}

.cell-num {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.houses-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.houses-list li {
    padding: 0.25rem 0.625rem;
    border-radius: 0.375rem;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 0.875rem;
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-primary {
    background: #dbeafe;
    color: var(--primary);
}

.badge-success {
    background: #dcfce7;
    color: var(--success);
}

.badge-warning {
    background: #fef9c3;
    color: var(--warning);
}

.badge-danger {
    background: #fee2e2;
    color: var(--danger);
}

.badge-info {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-neutral {
    background: #e5e7eb;
    color: #374151;
}

/* Incidences list */
.inc-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.inc-tab {
    padding: 0.6rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-weight: 500;
    font-size: 0.9rem;
}
.inc-tab:hover { color: var(--text); }
.inc-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.inc-tab .count {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0 0.45rem;
    background: var(--surface-alt);
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.inc-tab.active .count { background: #dbeafe; color: var(--primary); }
.inc-row-stale { background: #fff7ed; }
.inc-row-stale td:first-child { box-shadow: inset 3px 0 0 #f97316; }
.inc-quick-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.inc-quick-actions form { margin: 0; }

/* Incidences list — card grid. Title goes at the top of each card so it
   can wrap freely; the rest sits below as a meta dl + action footer. */
.inc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
}
.inc-empty {
    grid-column: 1 / -1;
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
}
.inc-card {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    padding: 1rem 1.1rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.inc-card-stale {
    background: #fff7ed;
    border-color: #fdba74;
}
.inc-card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
}
.inc-card-title {
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.35;
    color: var(--primary);
    text-decoration: none;
    overflow-wrap: anywhere;
    flex: 1 1 100%;
}
.inc-card-title:hover { text-decoration: underline; }
.inc-card-location {
    flex: 1 1 100%;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.inc-card-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem 1rem;
    margin: 0;
}
.inc-card-field { min-width: 0; }
.inc-card-field-wide { grid-column: 1 / -1; }
.inc-card-field dt {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}
.inc-card-field dd {
    margin: 0;
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}
.inc-card-stale-tag {
    margin-left: 0.4rem;
    color: #c2410c;
    font-size: 0.75rem;
}
.inc-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px solid var(--border);
}
.inc-card-actions form { margin: 0; }
.inc-meta { color: var(--text-muted); font-size: 0.8rem; }
.inc-meta-icon {
    display: inline-block;
    margin-left: 0.35rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Incidence detail */
.inc-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.inc-detail-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
}
@media (max-width: 800px) {
    .inc-detail-grid { grid-template-columns: 1fr; }
}
.inc-status-actions {
    display: inline-flex;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 9999px;
    padding: 3px;
    gap: 2px;
}
.inc-status-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.45rem 0.9rem;
    border-radius: 9999px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.inc-status-btn:hover { color: var(--text); }
.inc-status-btn.active { color: var(--text); }
.inc-status-btn.active.info { background: #dbeafe; color: #1d4ed8; }
.inc-status-btn.active.warning { background: #fef9c3; color: var(--warning); }
.inc-status-btn.active.success { background: #dcfce7; color: var(--success); }

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #cbd5e1;
    border-radius: 24px;
    transition: all 0.15s ease;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: all 0.15s ease;
}

.toggle input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

/* Permission toggle list — row of label + .toggle, used in the user form */
.perm-toggle-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.5rem 1.5rem;
}

.perm-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.4rem 0;
}

.perm-toggle-label {
    font-size: 0.9rem;
    color: var(--text);
}

/* Access List */
.access-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.access-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border-radius: 0.5rem;
}

.access-item-info {
    display: flex;
    flex-direction: column;
}

.access-item-email {
    font-weight: 500;
}

.access-item-location {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state svg {
    width: 3rem;
    height: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -250px;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        padding: 1rem;
    }

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

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
}

/* Filters */
.filters {
    padding: 0.5rem 0;
}

.filter-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-group {
    flex: 0 0 auto;
    min-width: 0;
}

.filter-group > label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
}

.filter-group .form-control {
    font-size: 0.875rem;
}

/* User Edit Layout - Two Column */
.user-edit-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

.user-edit-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.user-edit-access {
    min-width: 0;
}

.form-row-2 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 1024px) {
    .user-edit-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .form-row-2,
    .form-row-3 {
        grid-template-columns: 1fr;
    }
}

/* Pill Toggle Filters */
.pill-group {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--card-bg);
}

.pill-input {
    display: none;
}

.pill-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 0.75rem;
    margin: -1px 0;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    border-right: 1px solid var(--border);
    border-top: 1px solid transparent;
    border-bottom: 1px solid transparent;
    white-space: nowrap;
    user-select: none;
}

.pill-label:first-of-type {
    margin-left: -1px;
    border-top-left-radius: 0.5rem;
    border-bottom-left-radius: 0.5rem;
    border-left: 1px solid transparent;
}

.pill-label:last-of-type {
    margin-right: -1px;
    border-right: 1px solid transparent;
    border-top-right-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}

.pill-label:hover {
    background: var(--bg);
}

.pill-input:checked + .pill-label {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Device Access in User Form */
.device-access-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.device-access-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border-radius: 0.5rem;
    border: 1px solid var(--border);
}

.device-access-info {
    display: flex;
    flex-direction: column;
}

.device-access-name {
    font-weight: 500;
}

.device-access-status {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* 3-State Toggle */
.state-toggle {
    display: inline-flex;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--card-bg);
}

.state-btn {
    padding: 0.3rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.state-btn:not(:last-child) {
    border-right: 1px solid var(--border);
}

.state-btn:hover {
    background: var(--bg);
}

.state-btn-default.active {
    background: var(--bg-cream);
    color: var(--text);
}

.state-btn-enabled.active {
    background: var(--success);
    color: white;
}

.state-btn-disabled.active {
    background: var(--danger);
    color: white;
}

.state-hint {
    font-size: 0.625rem;
}

.state-hint.hint-yes {
    color: var(--success);
}

.state-hint.hint-no {
    color: var(--danger);
}

.state-btn-default.active .state-hint.hint-yes {
    color: var(--success);
}

.state-btn-default.active .state-hint.hint-no {
    color: var(--danger);
}

/* HTMX Loading States */
.htmx-request {
    opacity: 0.5;
    pointer-events: none;
}

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

/* ========================================
   Network Health Page
   ======================================== */

/* Summary Cards */
.nh-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.nh-summary-card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.nh-summary-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.nh-summary-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.25rem;
}

.nh-summary-detail {
    font-size: 0.8125rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
}

/* Section Title */
.nh-section-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    margin-top: 0.5rem;
}

/* Status Dots */
.nh-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.nh-dot-online {
    background: var(--success);
    box-shadow: 0 0 0 2px rgba(101, 136, 100, 0.25);
}

.nh-dot-offline {
    background: var(--danger);
    box-shadow: 0 0 0 2px rgba(173, 78, 78, 0.25);
}

/* Color utility classes */
.nh-text-good { color: var(--success); }
.nh-text-warn { color: #b8960a; }
.nh-text-bad { color: var(--danger); }
.nh-text-muted { color: var(--text-muted); }

/* Gateway Grid */
.nh-gw-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.nh-gw-card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.nh-gw-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nh-gw-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
}

/* Gateway Metadata */
.nh-gw-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.375rem 1rem;
}

.nh-gw-meta-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.8125rem;
}

.nh-meta-label {
    color: var(--text-muted);
}

.nh-meta-value {
    font-weight: 500;
}

/* Gateway Stats */
.nh-gw-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.nh-gw-stat-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nh-stat-group-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.125rem;
}

.nh-stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8125rem;
}

.nh-stat-label {
    color: var(--text-muted);
}

.nh-stat-value {
    font-weight: 500;
}

.nh-gw-no-status {
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0.75rem 0;
    border-top: 1px solid var(--border);
}

/* Device Cards Grid */
.nh-dev-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.nh-dev-card {
    background: var(--card-bg);
    border-radius: 0.5rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
}

.nh-dev-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}

.nh-dev-name {
    font-weight: 500;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 0.5rem;
}

.nh-dev-stats {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    flex-wrap: nowrap;
    white-space: nowrap;
}

/* Success Rate Bar */
.nh-rate-bar-track {
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
}

.nh-rate-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.nh-bar-good { background: var(--success); }
.nh-bar-warn { background: var(--warning); }
.nh-bar-bad { background: var(--danger); }
.nh-bar-empty { background: var(--border); }

.nh-rate-text {
    font-size: 0.8125rem;
    font-weight: 600;
}

/* Network Topology Canvas */
.nh-topology-container {
    margin-bottom: 1.5rem;
}

.nh-topology {
    position: relative;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
    min-height: 300px;
}

.nh-topology-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
}

.nh-topology-nodes {
    position: relative;
}

.nh-topo-node {
    position: absolute;
    z-index: 1;
}

.nh-topo-gw .nh-topo-gw-inner {
    background: var(--card-bg);
    color: var(--text);
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.625rem 0.75rem;
    font-size: 0.8125rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.nh-topo-gw .nh-topo-gw-inner.nh-offline {
    opacity: 0.6;
}

.nh-topo-gw-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
}

.nh-topo-gw-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.nh-gw-bar-label {
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 0.375rem;
    margin-bottom: 0.125rem;
}

.nh-gw-stacked-bar {
    display: flex;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--border);
}

.nh-bar-seg { min-width: 2px; }
.nh-bar-tx { background: #5b9bd5; }
.nh-bar-rx { background: #70ad47; }
.nh-bar-ok { background: #70ad47; }
.nh-bar-fail { background: var(--danger); }
.nh-bar-reconn { background: var(--warning); }
.nh-bar-empty { background: var(--border); }

.nh-gw-bar-legend {
    display: flex;
    gap: 0.5rem;
    font-size: 0.625rem;
    margin-top: 0.125rem;
    color: var(--text-muted);
}

.nh-legend-tx { color: #4a7fb5; }
.nh-legend-rx { color: #5a9137; }
.nh-legend-ok { color: #5a9137; }
.nh-legend-fail { color: var(--danger); }
.nh-legend-reconn { color: #c68a30; }

.nh-gw-mqtt-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-top: 0.375rem;
    font-size: 0.625rem;
    color: var(--text-muted);
}

.nh-topo-gw-fw {
    font-size: 0.625rem;
    opacity: 0.6;
    font-family: monospace;
}

.nh-topo-door .nh-topo-door-inner {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Protocol version colors: both green cards, only badge color differs */
.nh-proto-v2 { border-color: var(--success) !important; background-color: #f0f7f0 !important; }
.nh-proto-v1 { border-color: var(--success) !important; background-color: #f0f7f0 !important; }

.nh-proto-badge {
    font-size: 0.625rem;
    font-weight: 700;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    background: var(--bg);
    color: var(--text-muted);
}

.nh-proto-v2 .nh-proto-badge { color: var(--success); background: rgba(101,136,100,0.12); }
.nh-proto-v1 .nh-proto-badge { color: var(--danger); background: rgba(173,78,78,0.12); }

/* Responsive */
@media (max-width: 768px) {
    .nh-summary {
        grid-template-columns: 1fr;
    }

    .nh-gw-grid {
        grid-template-columns: 1fr;
    }

    .nh-gw-meta {
        grid-template-columns: 1fr;
    }

    .nh-gw-stats {
        grid-template-columns: 1fr;
    }

    .nh-dev-grid {
        grid-template-columns: 1fr 1fr;
    }

    .nh-rate-bar-track {
        min-width: 50px;
    }
}

/* ACK missing warning: orange border + subtle orange tint */
.nh-ack-missing { border-color: #e67e22 !important; background-color: #fef5e7 !important; }
