:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --accent: #0ea5e9;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --success: #10b981;
    --border: #334155;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, var(--surface) 0%, #182237 100%);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 1000;
}

.header-content {
    max-width: 100%;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 8px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.title-container {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
}

.subtitle {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin: 0;
    opacity: 0.8;
}

.province-filter {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    max-width: 600px;
}

.province-filter label {
    font-size: 0.875rem;
    color: var(--text);
    white-space: nowrap;
}

.province-filter select {
    flex: 1;
    padding: 0.5rem 1rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.province-filter select:hover {
    border-color: var(--accent);
    background: var(--surface-hover);
}

.province-filter select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.load-button {
    padding: 0.5rem 1.5rem;
    background: var(--primary);
    color: var(--text);
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.load-button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.load-button:active {
    transform: translateY(0);
}

.load-button:disabled {
    background: var(--secondary);
    cursor: not-allowed;
    transform: none;
}

.stats {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border-radius: 2rem;
    font-size: 0.875rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.main-container {
    height: calc(100vh - 81px);
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

/* Custom Leaflet popup styles */
.leaflet-popup-content-wrapper {
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.leaflet-popup-content {
    margin: 0;
    min-width: 300px;
}

.leaflet-popup-tip {
    background: var(--surface);
}

.camera-popup {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@media (min-width: 500px) {
    .camera-popup-content-wrapper {
        display: flex;
        gap: 1rem;
        align-items: flex-start;
    }

    .camera-image-container {
        flex: 1.5;
        min-width: 0;
        /* Prevent flex overflow */
    }

    .weather-widget {
        flex: 1;
        min-width: 180px;
    }
}

.camera-popup h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
    color: var(--accent);
}

.camera-popup p.location-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

/* Weather Widget Styles */
.weather-widget {
    background: var(--bg);
    border-radius: 8px;
    padding: 0.75rem;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.weather-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.weather-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-height: 80px;
    justify-content: center;
}

.weather-temp {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.weather-detail {
    font-size: 0.875rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.weather-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100px;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.weather-error {
    color: #ef4444;
    font-size: 0.75rem;
    text-align: center;
    padding: 1rem 0;
}

/* Weather Alerts */
.weather-alert {
    margin-top: 0.5rem;
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--bg);
}

.alert-green {
    background: #10b981;
    color: white;
}

.alert-yellow {
    background: #eab308;
    color: black;
}

.alert-orange {
    background: #f97316;
    color: white;
}

.alert-red {
    background: #ef4444;
    color: white;
}

.alert-icon {
    font-size: 1rem;
}

.camera-image-container {
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg);
    position: relative;
    min-height: 200px;
}

.camera-image {
    width: 100%;
    height: auto;
    display: block;
    transition: opacity 0.3s;
}

.camera-image.loading {
    opacity: 0.5;
}

.image-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 0.875rem;
}

.image-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.popup-buttons {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.refresh-button,
.fullscreen-button {
    flex: 1;
    padding: 0.5rem;
    background: var(--primary);
    color: var(--text);
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.fullscreen-button {
    background: var(--accent);
}

.refresh-button:hover,
.fullscreen-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.refresh-button:hover {
    background: var(--primary-hover);
}

.fullscreen-button:hover {
    background: #0284c7;
}

.refresh-button:active,
.fullscreen-button:active {
    transform: translateY(0);
}

/* Custom marker icon styles */
.camera-marker {
    background: var(--accent);
    border: 3px solid var(--text);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

.camera-marker:hover {
    transform: scale(1.2);
    box-shadow: 0 6px 12px rgba(14, 165, 233, 0.5);
}

/* Incident Marker Styles */
.incident-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    font-size: 1.25rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    transition: transform 0.2s;
    cursor: pointer;
}

.incident-marker:hover {
    transform: scale(1.2);
    z-index: 1000 !important;
}

/* Traffic Status Badge in Popup */
.traffic-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 0.25rem;
    width: fit-content;
}

.status-fluid {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-dense {
    background: rgba(234, 179, 8, 0.15);
    color: #facc15;
    border: 1px solid rgba(234, 179, 8, 0.3);
}

.status-congested {
    background: rgba(249, 115, 22, 0.15);
    color: #fb923c;
    border: 1px solid rgba(249, 115, 22, 0.3);
}

.status-closed {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.incident-popup h3 {
    margin-bottom: 0.25rem;
    font-size: 1rem;
}

.incident-popup p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay p {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 1rem;
}

/* Fullscreen modal styles */
.fullscreen-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 3000;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    backdrop-filter: blur(4px);
}

.fullscreen-content {
    position: relative;
    width: 95vw;
    max-width: 500px;
    background: var(--surface);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.fullscreen-body {
    padding: 1rem;
    overflow-y: auto;
    max-height: calc(90vh - 60px);
}

.fullscreen-content .camera-popup {
    padding: 0;
    /* Eliminar padding extra ya que lo tiene el body */
}

.fullscreen-close {
    width: 36px;
    height: 36px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fullscreen-close:hover {
    background: var(--primary);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.fullscreen-header {
    text-align: left;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.fullscreen-title-wrapper h2 {
    font-size: 1.1rem;
    color: var(--accent);
    margin: 0;
}

.fullscreen-image-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: 8px;
    overflow: hidden;
    min-height: 400px;
}

#fullscreen-image {
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: 4px;
}

.fullscreen-loading {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 1rem;
}



/* Info Button */
.info-button {
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.info-button:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--text-muted);
}

/* General Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--surface);
    width: 90%;
    max-width: 600px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(0);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal.hidden .modal-content {
    transform: translateY(20px);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: var(--text);
    font-size: 1.25rem;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-modal:hover {
    background: var(--bg);
    color: var(--text);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.6;
}

.modal-body ul {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.modal-body li {
    margin-bottom: 0.5rem;
}

.modal-body h4 {
    color: var(--accent);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.close-modal-btn {
    padding: 0.5rem 1.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.close-modal-btn:hover {
    background: var(--primary-hover);
}

/* Responsive design */
/* Responsive design */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
        align-items: stretch;
    }

    .logo-container {
        justify-content: center;
    }

    .province-filter {
        flex-direction: column;
        align-items: stretch;
        max-width: 100%;
        gap: 0.5rem;
    }

    .province-filter select {
        width: 100%;
    }

    .province-filter button {
        width: 100%;
        justify-content: center;
    }

    /* Make buttons in filter appear side-by-side if possible, or stacked */
    .province-filter {
        display: flex;
        flex-wrap: wrap;
    }

    #provinceSelect {
        flex-basis: 100%;
    }

    #loadButton,
    #infoButton {
        flex: 1;
    }

    .stats {
        width: 100%;
        justify-content: space-between;
        padding-top: 0.5rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    h1 {
        font-size: 1.25rem;
        text-align: center;
    }

    .subtitle {
        text-align: center;
    }

    .leaflet-popup-content {
        min-width: 260px !important;
        /* Force override for small screens */
        max-width: 300px;
    }

    .cookie-consent {
        bottom: 1rem;
        width: calc(100% - 1rem);
    }

    .cookie-content {
        padding: 1.25rem;
    }

    .cookie-header h3 {
        font-size: 1.125rem;
    }

    .cookie-buttons {
        flex-direction: column;
    }

    .main-container {
        height: calc(100vh - 160px);
        /* Adjust map height based on taller header */
    }
}

@media (max-width: 480px) {
    .leaflet-popup-content {
        min-width: 240px !important;
    }

    .camera-image-container {
        min-height: 150px;
    }
}