/* 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;
}

/* 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;
}

.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;
}

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

.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);
}

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

/* 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);
}

/* 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);
}

/* 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: 1;
    min-width: 150px;
}

.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;
}

/* 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;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* 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: v2/SF7 = green, v1/SF12 = red */
.nh-proto-v2 { border-color: var(--success) !important; background-color: #f0f7f0 !important; }
.nh-proto-v1 { border-color: var(--danger) !important; background-color: #fdf2f2 !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;
    }
}
