/* ===== CSS VARIABLES ===== */
:root {
    --primary-color: #005dab;
    --secondary-color: #009ac7;
    --accent-color: #ffd204;
    --success-color: #009f4a;
    --warning-color: #f37a22;
    --error-color: #e74c3c;

    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #e2e8f0;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    --shadow-light: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-heavy: 0 10px 15px rgba(0, 0, 0, 0.1);

    --border-radius: 8px;
    --border-radius-lg: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --header-height: 70px;
    --status-height: 40px;
    --z-loading: 10000;
    --z-modal: 9000;
    --z-header: 1000;
    --z-controls: 500;
    --z-legend: 400;
}

/* Dark theme variables */
[data-theme="dark"] {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --text-primary: #f7fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #a0aec0;
    --border-color: #4a5568;
    --shadow-light: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-medium: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-heavy: 0 10px 15px rgba(0, 0, 0, 0.4);
}

/* ===== RESET & BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    transition: var(--transition);
}

/* ===== LOADING SCREEN ===== */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-loading);
    transition: opacity 0.5s ease-out;
}

.loading-content {
    text-align: center;
    color: white;
    animation: fadeInUp 0.8s ease-out;
}

.loading-logo {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounce 2s infinite;
}

.loading-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 2rem;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 1s linear infinite;
}

.loading-content p {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* ===== MAIN APP ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    opacity: 0;
    transition: opacity 0.5s ease-in;
}

#app.loaded {
    opacity: 1;
}

/* ===== HEADER ===== */
.app-header {
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-light);
    z-index: var(--z-header);
    position: relative;
}

.header-content {
    height: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 2rem;
    animation: pulse 2s infinite;
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    line-height: 1.2;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

.header-controls {
    display: flex;
    gap: 0.5rem;
}

.control-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.1rem;
}

.control-btn:hover {
    background: var(--bg-tertiary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-medium);
}

/* ===== STATUS BAR ===== */
.status-bar {
    height: var(--status-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    font-size: 0.875rem;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success-color);
    animation: pulse 2s infinite;
}

.status-indicator.loading {
    background: var(--warning-color);
}

.status-indicator.error {
    background: var(--error-color);
}

/* ===== MAP CONTAINER ===== */
.map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ===== MAP CONTROLS ===== */
.map-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    z-index: var(--z-controls);
}

.map-control-btn {
    width: 44px;
    height: 44px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: var(--shadow-medium);
    transition: var(--transition);
}

.map-control-btn:hover {
    background: var(--bg-secondary);
    transform: scale(1.05);
}

.map-control-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Map Type Selector */
.map-selector {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 8px 12px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    width: 130px;
    box-shadow: var(--shadow-medium);
    transition: var(--transition);
    font-family: var(--font-family);
    text-align: left;
}

.map-selector:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
}

.map-selector:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-color: var(--primary-color);
}

.map-selector option {
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: 4px 8px;
}

/* ===== LEGEND ===== */
.legend {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-heavy);
    min-width: 200px;
    z-index: var(--z-legend);
    transition: var(--transition);
}

.legend-header {
    padding: 1rem 1rem 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.legend-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.legend-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-secondary);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: var(--transition);
}

.legend-toggle:hover {
    background: var(--bg-secondary);
}

.legend-content {
    padding: 0.5rem 1rem 1rem;
    transition: var(--transition);
}

.legend.collapsed .legend-content {
    display: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* ===== MODAL ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    padding: 1rem;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-heavy);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: var(--transition);
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-body {
    padding: 1rem 1.5rem 1.5rem;
}

.modal-body p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.modal-body h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.modal-body ul {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.modal-body li {
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.data-source {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 0 !important;
}

/* ===== NOTIFICATION SYSTEM ===== */
.update-notification,
.offline-notification {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-heavy);
    padding: 1rem;
    z-index: var(--z-modal);
    transition: var(--transition);
    max-width: 90vw;
    width: 400px;
}

.update-notification.show,
.offline-notification.show {
    top: calc(var(--header-height) + var(--status-height) + 1rem);
}

.notification-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}

.notification-content span:first-child {
    font-size: 1.2rem;
}

.notification-content button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
    margin-left: auto;
}

.notification-content button:hover {
    background: #004494;
    transform: translateY(-1px);
}

.notification-content button+button {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    margin-left: 0.5rem;
}

.notification-content button+button:hover {
    background: var(--border-color);
}

.offline-notification {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

[data-theme="dark"] .offline-notification {
    background: #7f1d1d;
    border-color: #991b1b;
    color: #fecaca;
}

/* ===== ENHANCED ERROR HANDLING ===== */
.error-boundary {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-primary);
    border: 1px solid var(--error-color);
    border-radius: var(--border-radius-lg);
    padding: 2rem;
    text-align: center;
    box-shadow: var(--shadow-heavy);
    z-index: var(--z-modal);
    max-width: 90vw;
    width: 400px;
}

.error-boundary h2 {
    color: var(--error-color);
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.error-boundary p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.error-boundary button {
    background: var(--error-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
}

.error-boundary button:hover {
    background: #c53030;
    transform: translateY(-1px);
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-10px);
    }

    60% {
        transform: translateY(-5px);
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    :root {
        --header-height: 60px;
        --status-height: 35px;
    }

    .header-content {
        padding: 0 0.75rem;
    }

    .logo-text h1 {
        font-size: 1.1rem;
    }

    .subtitle {
        font-size: 0.7rem;
    }

    .control-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .status-bar {
        padding: 0 0.75rem;
        font-size: 0.8rem;
    }

    .map-controls {
        top: 0.75rem;
        right: 0.75rem;
        gap: 0.4rem;
    }

    .map-control-btn {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    .map-selector {
        width: 110px;
        font-size: 12px;
        padding: 6px 8px;
    }

    .legend {
        bottom: 0.75rem;
        left: 0.75rem;
        min-width: 180px;
        font-size: 0.85rem;
    }

    .legend-header {
        padding: 0.75rem 0.75rem 0.4rem;
    }

    .legend-content {
        padding: 0.4rem 0.75rem 0.75rem;
    }

    .legend-item {
        font-size: 0.8rem;
        gap: 0.6rem;
    }

    .modal {
        padding: 0.5rem;
    }

    .modal-header {
        padding: 1rem 1rem 0.75rem;
    }

    .modal-body {
        padding: 0.75rem 1rem 1rem;
    }
}

@media (max-width: 480px) {
    .logo-section {
        gap: 0.5rem;
    }

    .logo-icon {
        font-size: 1.75rem;
    }

    .logo-text h1 {
        font-size: 1rem;
    }

    .subtitle {
        font-size: 0.65rem;
    }

    .control-btn {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    .legend {
        min-width: 160px;
    }

    .map-control-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
button:focus-visible,
.control-btn:focus-visible,
.map-control-btn:focus-visible,
.legend-toggle:focus-visible,
.modal-close:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ===== LEAFLET CUSTOMIZATIONS ===== */
.leaflet-popup-content-wrapper {
    border-radius: var(--border-radius) !important;
    box-shadow: var(--shadow-heavy) !important;
}

.leaflet-popup-tip {
    background: var(--bg-primary) !important;
}

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

.leaflet-control-zoom a {
    background-color: var(--bg-primary) !important;
    border-bottom: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
}

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

.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.8) !important;
    border-radius: var(--border-radius) !important;
    font-size: 0.7rem !important;
}

/* ===== PRINT STYLES ===== */
@media print {

    #loading-screen,
    .app-header,
    .status-bar,
    .map-controls,
    .legend,
    .modal {
        display: none !important;
    }

    #map {
        height: 100vh !important;
    }
}

/* ===== MOBILE POPUP ENHANCEMENTS ===== */
.leaflet-popup-content-wrapper {
    border-radius: var(--border-radius) !important;
    box-shadow: var(--shadow-heavy) !important;
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    max-width: 90vw !important;
}

.leaflet-popup-content {
    margin: 1rem !important;
    font-family: 'Inter', sans-serif !important;
    line-height: 1.5 !important;
}

.leaflet-popup-content h3 {
    color: var(--primary-color) !important;
    font-weight: 600 !important;
    margin-bottom: 0.5rem !important;
    font-size: 1.1rem !important;
}

.leaflet-popup-content p,
.leaflet-popup-content div {
    color: var(--text-secondary) !important;
    font-size: 0.9rem !important;
    margin-bottom: 0.25rem !important;
}

.leaflet-popup-content strong {
    color: var(--text-primary) !important;
    font-weight: 600 !important;
}

.leaflet-popup-tip {
    background: var(--bg-primary) !important;
    border: 1px solid var(--border-color) !important;
}

.leaflet-popup-close-button {
    color: var(--text-secondary) !important;
    font-size: 1.2rem !important;
    padding: 0.25rem !important;
    width: 24px !important;
    height: 24px !important;
    border-radius: 4px !important;
    background: transparent !important;
    transition: var(--transition) !important;
}

.leaflet-popup-close-button:hover {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

/* ===== MOBILE TOUCH ENHANCEMENTS ===== */
@media (max-width: 768px) {
    .leaflet-popup-content-wrapper {
        max-width: 85vw !important;
        min-width: 280px !important;
    }

    .leaflet-popup-content {
        margin: 0.75rem !important;
        font-size: 0.9rem !important;
    }

    .leaflet-popup-content h3 {
        font-size: 1rem !important;
    }

    .leaflet-popup-content p,
    .leaflet-popup-content div {
        font-size: 0.85rem !important;
    }
}

/* ===== TOUCH-FRIENDLY CONTROLS ===== */
@media (hover: none) and (pointer: coarse) {
    .map-control-btn {
        width: 48px !important;
        height: 48px !important;
        font-size: 1.3rem !important;
    }

    .control-btn {
        width: 44px !important;
        height: 44px !important;
        font-size: 1.2rem !important;
    }

    .legend-toggle {
        width: 32px !important;
        height: 32px !important;
        font-size: 1.4rem !important;
    }
}

/* ===== HIGH DPI DISPLAY SUPPORT ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .leaflet-control-zoom a {
        border-color: var(--border-color) !important;
    }
}

/* ===== LANDSCAPE MOBILE OPTIMIZATION ===== */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --header-height: 50px;
        --status-height: 30px;
    }

    .logo-text h1 {
        font-size: 0.95rem !important;
    }

    .subtitle {
        display: none !important;
    }

    .status-bar {
        font-size: 0.75rem !important;
        padding: 0 0.5rem !important;
    }

    .legend {
        bottom: 0.5rem !important;
        left: 0.5rem !important;
        max-height: 50vh !important;
        overflow-y: auto !important;
    }

    .map-controls {
        top: 0.5rem !important;
        right: 0.5rem !important;
    }
}

/* ===== LOADING ANIMATION IMPROVEMENTS ===== */
.leaflet-control-zoom a {
    transition: var(--transition) !important;
}

.leaflet-control-zoom a:hover {
    transform: scale(1.05) !important;
}

/* ===== PERFORMANCE OPTIMIZATION ===== */
.leaflet-zoom-anim .leaflet-zoom-animated {
    will-change: transform !important;
}

.leaflet-moving .leaflet-marker-icon,
.leaflet-moving .leaflet-marker-shadow {
    transform: translateZ(0) !important;
}

/* ===== DARK MODE ENHANCEMENTS ===== */
[data-theme="dark"] .leaflet-popup-content-wrapper {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
}

[data-theme="dark"] .leaflet-popup-tip {
    background: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .leaflet-control-zoom a {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .leaflet-control-attribution {
    background: rgba(45, 55, 72, 0.9) !important;
    color: var(--text-secondary) !important;
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
@media (prefers-contrast: high) {
    .legend-color {
        border: 2px solid var(--text-primary) !important;
    }

    .status-indicator {
        border: 2px solid var(--bg-primary) !important;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a202c;
        --bg-secondary: #2d3748;
        --bg-tertiary: #4a5568;
        --text-primary: #f7fafc;
        --text-secondary: #e2e8f0;
        --text-muted: #a0aec0;
        --border-color: #4a5568;
    }
}

/* ===== MAP ELEMENT INTERACTION OVERRIDES ===== */
/* Ensure no hover effects on map elements */
.leaflet-interactive,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-clickable {
    transition: none !important;
    transform: none !important;
}

.leaflet-interactive:hover,
.leaflet-marker-icon:hover,
.leaflet-marker-shadow:hover,
.leaflet-clickable:hover {
    transform: none !important;
    scale: none !important;
    cursor: pointer !important;
}

/* ===== PERFORMANCE OPTIMIZATION ===== */
.leaflet-zoom-anim .leaflet-zoom-animated {
    will-change: transform !important;
}

.leaflet-moving .leaflet-marker-icon,
.leaflet-moving .leaflet-marker-shadow {
    transform: translateZ(0) !important;
}