/**
 * RoadMonitor Main Styles
 * Design system and component styles for desktop interface
 */

/* ===== DESIGN SYSTEM ===== */
:root {
    --bg-dark: #1a1a2e;
    --bg-panel: #16213e;
    --bg-card: rgba(255,255,255,0.97);
    --bg-hover: rgba(255,255,255,0.06);
    --accent: #4361ee;
    --accent-hover: #3651d4;
    --text-primary: #2b2d42;
    --text-secondary: #8d99ae;
    --text-light: #b0b8c8;
    --text-white: #edf2f4;
    --border: #e5e7eb;
    --border-dark: rgba(255,255,255,0.08);
    --good: #2dc653;
    --fair: #f2c230;
    --poor: #f77f00;
    --bad: #d62828;
    --shadow: 0 4px 24px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.18);
    --radius: 10px;
    --radius-sm: 6px;
    --transition: 0.25s ease;
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* ===== MAP ===== */
#map {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
}

/* ===== TOP BAR ===== */
#topbar {
    position: fixed;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: none;
}

#topbar > * {
    pointer-events: auto;
}

.topbar-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* Logo */
#logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    white-space: nowrap;
}

#logo-icon {
    width: 32px;
    height: 32px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
}

#logo-text {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
}

#logo-sub {
    font-size: 11px;
    color: var(--text-secondary);
    display: block;
}

/* Search */
#search-wrap {
    flex: 1;
    max-width: 420px;
    position: relative;
}

#search-input {
    width: 100%;
    padding: 11px 16px 11px 40px;
    border: none;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    background: transparent;
    outline: none;
}

#search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 16px;
    pointer-events: none;
}

#search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 320px;
    overflow-y: auto;
    display: none;
    z-index: 9999;
}

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

.search-item:hover {
    background: #f8f9fa;
}

.search-name {
    font-weight: 500;
    font-size: 13px;
}

.search-meta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Controls */
#controls {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.ctrl-btn {
    padding: 10px 14px;
    border: none;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    outline: none;
    transition: all var(--transition);
}

.ctrl-btn:hover {
    background: #f8f9fa;
}

.ctrl-btn.active {
    background: var(--accent);
    color: #fff;
}

.ctrl-select {
    padding: 10px 14px;
    border: none;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238d99ae' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

/* ===== LEGEND ===== */
#legend {
    position: fixed;
    bottom: 24px;
    left: 16px;
    z-index: 1000;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 18px;
    min-width: 180px;
}

.legend-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--text-primary);
}

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

.legend-label {
    flex: 1;
}

/* ===== ROAD CARD ===== */
#card-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 400px;
    height: 100vh;
    z-index: 1001;
    background: var(--bg-card);
    box-shadow: 4px 0 30px rgba(0,0,0,0.15);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
}

#card-overlay.open {
    transform: translateX(0);
}

#card-close {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: #f1f3f5;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.close-btn:hover {
    background: #e9ecef;
    color: var(--text-primary);
}

#card-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

#card-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

#card-body {
    padding: 20px;
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.metric-card {
    background: #f8f9fb;
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
    border: 1px solid var(--border);
}

.metric-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 6px;
}

.metric-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.metric-unit {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Status Badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-good {
    background: #e6f9ed;
    color: #1a8a42;
}

.status-good .status-dot {
    background: var(--good);
}

.status-fair {
    background: #fef6e0;
    color: #a68400;
}

.status-fair .status-dot {
    background: var(--fair);
}

.status-poor {
    background: #fff3e0;
    color: #c45600;
}

.status-poor .status-dot {
    background: var(--poor);
}

.status-bad {
    background: #fde8e8;
    color: #b91c1c;
}

.status-bad .status-dot {
    background: var(--bad);
}

.status-nodata {
    background: #f1f3f5;
    color: var(--text-secondary);
}

/* Section Headers */
.section-header {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-top: 20px;
}

.section-header:first-child {
    margin-top: 0;
}

/* Normatives Table */
.norm-table {
    width: 100%;
    font-size: 12px;
    margin-bottom: 20px;
    border-collapse: collapse;
}

.norm-table th {
    text-align: left;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

.norm-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #f1f3f5;
    color: var(--text-primary);
}

/* Survey List */
.survey-item {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.survey-item:hover {
    background: #f8f9fb;
    border-color: var(--accent);
}

.survey-date {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.survey-stats {
    display: flex;
    gap: 12px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.survey-stat-val {
    font-weight: 600;
    color: var(--text-primary);
}

/* Health Index */
.health-bar-bg {
    height: 8px;
    border-radius: 4px;
    background: #e9ecef;
    margin: 10px 0;
    overflow: hidden;
}

.health-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
}

.health-score {
    font-size: 36px;
    font-weight: 700;
    line-height: 1;
}

.health-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ===== LOADING OVERLAY ===== */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    transition: opacity 0.4s ease;
}

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

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    color: var(--text-white);
    font-size: 14px;
    font-weight: 500;
}

.loading-sub {
    color: var(--text-light);
    font-size: 12px;
}

/* ===== INFO BAR ===== */
#info-bar {
    position: fixed;
    bottom: 24px;
    right: 16px;
    z-index: 1000;
    display: flex;
    gap: 8px;
}

.info-chip {
    background: var(--bg-card);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== DASHBOARD ===== */
#dashboard-overlay {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    height: 100vh;
    z-index: 1002;
    background: var(--bg-card);
    box-shadow: -4px 0 30px rgba(0,0,0,0.15);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
}

#dashboard-overlay.open {
    transform: translateX(0);
}

/* ===== COMPARISON ===== */
#compare-result {
    margin-top: 16px;
}

.delta-positive {
    color: var(--bad);
    font-weight: 600;
}

.delta-negative {
    color: var(--good);
    font-weight: 600;
}

.delta-zero {
    color: var(--text-secondary);
}

/* ===== PROFILE CHART ===== */
.profile-container {
    margin: 16px 0;
}

#profile-canvas {
    width: 100%;
    height: 200px;
    background: #f8f9fb;
    border-radius: var(--radius-sm);
}

/* ===== LEAFLET OVERRIDES ===== */
.leaflet-container {
    font-family: 'Inter', -apple-system, sans-serif;
}

.leaflet-popup-content-wrapper {
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}

.leaflet-popup-content {
    font-size: 12px;
    margin: 8px 0;
}

.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: none !important;
}

.leaflet-control-zoom a:hover {
    background: #f8f9fa !important;
}
