/* ============================================================
   Zonde Monitor — Dashboard Styles
   ============================================================ */

/* --- Variables ------------------------------------------- */
:root {
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --bg-nav: #0d1117;
    --bg-hover: #1e2d4e;
    --text: #e0e0e0;
    --text-muted: #8892a4;
    --text-dim: #5a6577;
    --accent: #0f3460;
    --border: #1e2d4e;
    --green: #4caf50;
    --yellow: #ff9800;
    --red: #f44336;
    --blue: #2196f3;
    --purple: #9c27b0;
    --teal: #009688;
    --green-dim: rgba(76, 175, 80, 0.15);
    --yellow-dim: rgba(255, 152, 0, 0.15);
    --red-dim: rgba(244, 67, 54, 0.15);
    --blue-dim: rgba(33, 150, 243, 0.15);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.6);
    --nav-height: 56px;
}

/* --- Reset / Base ---------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    background: var(--bg-dark);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--blue);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* --- Top Navigation -------------------------------------- */
.nav {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--nav-height);
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 32px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-brand:hover {
    text-decoration: none;
    color: var(--text);
}

.nav-brand .brand-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
    flex-shrink: 0;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
    color: var(--text);
    background: var(--accent);
    text-decoration: none;
}

.nav-link.active {
    color: var(--text);
    background: var(--accent);
}

.nav-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text-dim);
}

/* --- Page layout ---------------------------------------- */
.page {
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px 24px;
}

.page-header {
    margin-bottom: 28px;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
}

.page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

/* --- Building Cards Grid --------------------------------- */
.buildings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.building-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
    text-decoration: none;
    display: block;
    color: var(--text);
}

.building-card:hover {
    border-color: var(--blue);
    box-shadow: var(--shadow-hover);
    transform: translateY(-1px);
    text-decoration: none;
    color: var(--text);
}

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

.building-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}

.building-card-location {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 3px;
}

.building-card-stats {
    display: flex;
    gap: 24px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.building-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.building-stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.building-stat-value.has-anomalies {
    color: var(--yellow);
}

.building-stat-value.critical-anomalies {
    color: var(--red);
}

.building-stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.building-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 12px;
}

/* --- Cards (generic) ------------------------------------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

/* --- Badges ---------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

.badge-critical {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid rgba(244, 67, 54, 0.3);
}

.badge-warning {
    background: var(--yellow-dim);
    color: var(--yellow);
    border: 1px solid rgba(255, 152, 0, 0.3);
}

.badge-info {
    background: var(--blue-dim);
    color: var(--blue);
    border: 1px solid rgba(33, 150, 243, 0.3);
}

.badge-success {
    background: var(--green-dim);
    color: var(--green);
    border: 1px solid rgba(76, 175, 80, 0.3);
}

/* Phase badges */
.badge-phase-backfill {
    background: rgba(156, 39, 176, 0.15);
    color: #ce93d8;
    border: 1px solid rgba(156, 39, 176, 0.3);
}

.badge-phase-baseline {
    background: rgba(33, 150, 243, 0.15);
    color: #64b5f6;
    border: 1px solid rgba(33, 150, 243, 0.3);
}

.badge-phase-calibration {
    background: rgba(255, 152, 0, 0.15);
    color: #ffb74d;
    border: 1px solid rgba(255, 152, 0, 0.3);
}

.badge-phase-live {
    background: rgba(76, 175, 80, 0.15);
    color: #81c784;
    border: 1px solid rgba(76, 175, 80, 0.3);
}

/* Building type badge */
.badge-type {
    background: var(--accent);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* Label badges */
.badge-label-real {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid rgba(244, 67, 54, 0.3);
}

.badge-label-noise {
    background: rgba(90, 101, 119, 0.2);
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.badge-label-normal {
    background: var(--green-dim);
    color: var(--green);
    border: 1px solid rgba(76, 175, 80, 0.3);
}

/* --- Health Indicator Dots ------------------------------- */
.health-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
    flex-shrink: 0;
    display: inline-block;
}

.health-dot.offline {
    background: var(--red);
    box-shadow: 0 0 6px var(--red);
}

.health-dot.warning {
    background: var(--yellow);
    box-shadow: 0 0 6px var(--yellow);
}

.health-dot.unknown {
    background: var(--text-dim);
    box-shadow: none;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    text-align: left;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid rgba(30, 45, 78, 0.6);
    transition: background 0.1s;
}

tbody tr:last-child {
    border-bottom: none;
}

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

tbody td {
    padding: 10px 12px;
    color: var(--text);
    vertical-align: middle;
}

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

td.mono {
    font-family: 'SF Mono', 'Fira Code', Menlo, monospace;
    font-size: 12px;
    color: var(--text-muted);
}

/* --- Anomaly List ---------------------------------------- */
.anomaly-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.anomaly-item {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-left: 3px solid var(--text-dim);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}

.anomaly-item.critical {
    border-left-color: var(--red);
}

.anomaly-item.warning {
    border-left-color: var(--yellow);
}

.anomaly-item.info {
    border-left-color: var(--blue);
}

.anomaly-item-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 5px;
}

.anomaly-entity {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.anomaly-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 5px;
}

.anomaly-time {
    font-size: 11px;
    color: var(--text-dim);
}

.anomaly-explanation {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 4px;
}

.anomaly-values {
    display: flex;
    gap: 20px;
    margin-top: 8px;
}

.anomaly-value-item {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.anomaly-value-label {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.anomaly-value-num {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    font-family: 'SF Mono', 'Fira Code', Menlo, monospace;
}

/* --- Label actions -------------------------------------- */
.label-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.label-btn {
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--accent);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.label-btn:hover {
    color: var(--text);
    border-color: var(--blue);
    background: var(--bg-hover);
}

.label-btn.active-real {
    background: var(--red-dim);
    color: var(--red);
    border-color: rgba(244, 67, 54, 0.4);
}

.label-btn.active-normal {
    background: var(--green-dim);
    color: var(--green);
    border-color: rgba(76, 175, 80, 0.4);
}

.label-btn.active-noise {
    background: rgba(90, 101, 119, 0.2);
    color: var(--text-muted);
    border-color: var(--border);
}

/* --- Summary stats row ---------------------------------- */
.stats-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    min-width: 130px;
    flex: 1;
}

.stat-card-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-card-value.red    { color: var(--red); }
.stat-card-value.yellow { color: var(--yellow); }
.stat-card-value.green  { color: var(--green); }
.stat-card-value.blue   { color: var(--blue); }

.stat-card-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --- Building detail layout ----------------------------- */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 20px;
    align-items: start;
}

.detail-main {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

.detail-sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* --- Back link ------------------------------------------ */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
    transition: color 0.15s;
}

.back-link:hover {
    color: var(--text);
    text-decoration: none;
}

/* --- Section headers ------------------------------------ */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}

.section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.section-count {
    font-size: 11px;
    color: var(--text-dim);
    background: var(--accent);
    padding: 2px 8px;
    border-radius: 10px;
}

/* --- Config Summary ------------------------------------- */
.config-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.config-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 0;
    border-bottom: 1px solid rgba(30, 45, 78, 0.5);
    gap: 12px;
}

.config-row:last-child {
    border-bottom: none;
}

.config-key {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.config-value {
    font-size: 12px;
    color: var(--text);
    text-align: right;
    font-family: 'SF Mono', 'Fira Code', Menlo, monospace;
}

/* --- Sensor type group header --------------------------- */
.sensor-group-header td {
    padding: 6px 12px;
    background: rgba(15, 52, 96, 0.5);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

/* --- Empty / loading states ----------------------------- */
.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}

.loading-row {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
    margin: 40px auto;
    display: block;
}

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

.error-msg {
    padding: 12px 16px;
    background: var(--red-dim);
    border: 1px solid rgba(244, 67, 54, 0.3);
    border-radius: var(--radius-sm);
    color: var(--red);
    font-size: 13px;
}

/* --- Buttons -------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--accent);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    text-decoration: none;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--blue);
    text-decoration: none;
    color: var(--text);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-primary {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}

.btn-primary:hover {
    background: #1976d2;
    border-color: #1976d2;
    color: #fff;
}

/* --- Refresh indicator ---------------------------------- */
.refresh-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-dim);
}

/* --- Schedule table ------------------------------------- */
.schedule-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.schedule-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(30, 45, 78, 0.4);
    gap: 8px;
}

.schedule-row:last-child {
    border-bottom: none;
}

.schedule-day {
    color: var(--text-muted);
    min-width: 80px;
}

.schedule-time {
    color: var(--text);
    font-family: 'SF Mono', 'Fira Code', Menlo, monospace;
}

/* --- Building header info ------------------------------- */
.building-meta-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.building-meta-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

.building-meta-item strong {
    color: var(--text);
}

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

@media (max-width: 640px) {
    .nav {
        padding: 0 16px;
        gap: 12px;
    }

    .nav-link span {
        display: none;
    }

    .page {
        padding: 20px 16px;
    }

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

    .stats-row {
        gap: 10px;
    }

    .stat-card {
        min-width: 100px;
        padding: 12px 14px;
    }

    .stat-card-value {
        font-size: 20px;
    }

    .page-header-row {
        flex-direction: column;
    }

    .anomaly-item-header {
        flex-direction: column;
        align-items: flex-start;
    }
}
