/* ═══════════════════════════════════════════════════════════════════════════
   Australian Rental Stress Predictor — Styles
   Dark theme with glassmorphism, inspired by modern data dashboards
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.85);
    --bg-card-hover: rgba(30, 41, 59, 0.9);
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;

    /* Stress colours */
    --stress-severe: #ef4444;
    --stress-high: #f97316;
    --stress-moderate: #eab308;
    --stress-low: #22c55e;
    --stress-unknown: #6b7280;

    /* Map choropleth */
    --choro-1: #1a9850;
    --choro-2: #91cf60;
    --choro-3: #d9ef8b;
    --choro-4: #fee08b;
    --choro-5: #fc8d59;
    --choro-6: #d73027;

    --sidebar-width: 380px;
    --topbar-height: 56px;
    --radius: 10px;
    --radius-sm: 6px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ─── Loading Screen ──────────────────────────────────────────────────────── */

#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.6s ease, visibility 0.6s ease;
}

#loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-content {
    text-align: center;
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 0.8s linear infinite;
}

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

.loader-content h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 8px;
}

#loading-status {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* ─── Top Bar ─────────────────────────────────────────────────────────────── */

#top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: rgba(10, 14, 26, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.top-bar-left h1 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

#sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    flex-direction: column;
    gap: 4px;
}

#sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: var(--transition);
}

/* Search */
.top-bar-center {
    flex: 1;
    max-width: 400px;
    margin: 0 20px;
}

.search-container {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

#search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

#search-input:focus {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.1);
}

#search-input::placeholder {
    color: var(--text-muted);
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    max-height: 320px;
    overflow-y: auto;
    display: none;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

.search-result-item:hover {
    background: var(--bg-card-hover);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-name {
    font-size: 0.85rem;
    font-weight: 500;
}

.search-result-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Metric selector */
.top-bar-right {
    flex-shrink: 0;
}

.metric-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.metric-selector label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

#metric-select {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 6px 10px;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
}

#metric-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ─── Main Layout ─────────────────────────────────────────────────────────── */

#main-content {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */

#sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    background: rgba(10, 14, 26, 0.95);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    padding: 16px;
    transition: transform var(--transition);
    z-index: 500;
}

#sidebar::-webkit-scrollbar {
    width: 5px;
}

#sidebar::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.sidebar-section {
    margin-bottom: 20px;
}

.sidebar-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.sidebar-section h4 {
    font-size: 0.8rem;
    font-weight: 600;
    margin: 16px 0 8px;
    color: var(--text-secondary);
}

.hidden {
    display: none !important;
}

/* About section */
.about-section {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(139, 92, 246, 0.08));
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.about-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    text-align: left;
}

.about-toggle-icon {
    font-size: 0.65rem;
    color: var(--accent);
    transition: transform var(--transition);
    flex-shrink: 0;
}

.about-section.collapsed .about-toggle-icon {
    transform: rotate(-90deg);
}

.about-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.about-body {
    margin-top: 10px;
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.3s ease;
    max-height: 500px;
    opacity: 1;
}

.about-section.collapsed .about-body {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

.about-text {
    font-size: 0.82rem;
    line-height: 1.65;
    color: var(--text-secondary);
}

.about-text.about-text-sm {
    font-size: 0.72rem;
    margin-top: 10px;
    color: var(--text-muted);
}

.about-text strong {
    color: var(--text-primary);
}

.about-list {
    list-style: none;
    margin: 10px 0;
    padding: 0;
}

.about-list li {
    font-size: 0.8rem;
    line-height: 1.55;
    color: var(--text-secondary);
    padding: 5px 0 5px 16px;
    position: relative;
}

.about-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 11px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}

.about-list li strong {
    color: var(--text-primary);
}

/* Stat grid */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    text-align: center;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
}

.stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    display: block;
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-card.stress-severe .stat-value { color: var(--stress-severe); }
.stat-card.stress-high .stat-value { color: var(--stress-high); }
.stat-card.stress-low .stat-value { color: var(--stress-low); }

/* Charts */
.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 12px;
}

.chart-container.small {
    height: 130px;
}

/* Detail panel */
.back-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    padding: 4px 0;
    margin-bottom: 8px;
    transition: color var(--transition);
}

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

.detail-subtitle {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.stress-badge-container {
    margin-bottom: 14px;
}

.stress-badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stress-badge.severe { background: rgba(239, 68, 68, 0.2); color: var(--stress-severe); }
.stress-badge.high { background: rgba(249, 115, 22, 0.2); color: var(--stress-high); }
.stress-badge.moderate { background: rgba(234, 179, 8, 0.2); color: var(--stress-moderate); }
.stress-badge.low { background: rgba(34, 197, 94, 0.2); color: var(--stress-low); }
.stress-badge.unknown { background: rgba(107, 114, 128, 0.2); color: var(--stress-unknown); }

.detail-metrics {
    margin: 12px 0;
}

.metric-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}

.metric-row span:first-child {
    color: var(--text-secondary);
}

.metric-row span:last-child {
    font-weight: 500;
}

.no-data-msg {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 20px;
}

/* Source list */
.sources-section {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.source-list {
    list-style: none;
}

.source-list li {
    margin-bottom: 8px;
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.source-list li a {
    color: var(--accent);
    text-decoration: none;
}

.source-list li a:hover {
    text-decoration: underline;
}

.source-list .source-name {
    color: var(--text-secondary);
    font-weight: 500;
}

/* ─── Map ─────────────────────────────────────────────────────────────────── */

#map-container {
    flex: 1;
    position: relative;
    min-width: 0;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
}

/* Leaflet overrides for dark theme */
.leaflet-container {
    background: var(--bg-primary) !important;
    font-family: 'Inter', sans-serif !important;
}

.leaflet-tile-pane {
    filter: brightness(0.7) contrast(1.1) saturate(0.3);
}

.leaflet-control-zoom {
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    overflow: hidden;
}

.leaflet-control-zoom a {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-bottom-color: var(--border) !important;
    width: 32px !important;
    height: 32px !important;
    line-height: 32px !important;
    font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-card-hover) !important;
}

.leaflet-control-attribution {
    background: rgba(10, 14, 26, 0.8) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a {
    color: var(--text-secondary) !important;
}

/* Map tooltip */
.leaflet-tooltip {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    color: var(--text-primary) !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 0.78rem !important;
    padding: 8px 12px !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
}

.leaflet-tooltip::before {
    border-top-color: var(--bg-secondary) !important;
}

.tooltip-name {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.tooltip-row .val {
    font-weight: 500;
    color: var(--text-primary);
}

/* Legend */
#map-legend {
    position: absolute;
    bottom: 24px;
    right: 16px;
    z-index: 800;
    background: rgba(10, 14, 26, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    min-width: 160px;
}

#map-legend h4 {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 16px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
    }

    #sidebar-toggle {
        display: flex;
    }

    #sidebar {
        position: fixed;
        top: var(--topbar-height);
        left: 0;
        bottom: 0;
        width: 100%;
        transform: translateX(-100%);
        z-index: 900;
    }

    #sidebar.open {
        transform: translateX(0);
    }

    .top-bar-center {
        max-width: 200px;
    }

    .metric-selector label {
        display: none;
    }

    #map-legend {
        bottom: 16px;
        right: 8px;
        left: 8px;
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .top-bar-left h1 {
        font-size: 0.9rem;
    }

    .subtitle {
        display: none;
    }

    .top-bar-center {
        max-width: 140px;
        margin: 0 8px;
    }
}
