/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-light: #f8f9fa;
    --bg-dark: #1a1a1a;
    --surface-light: rgba(255, 255, 255, 0.95);
    --surface-dark: rgba(30, 30, 30, 0.95);
    --text-light: #202124;
    --text-dark: #e8eaed;
    --primary: #1a73e8;
    --primary-hover: #1557b0;
    --border-light: #dadce0;
    --border-dark: #3c4043;
    --shadow: 0 1px 2px rgba(0,0,0,0.1), 0 2px 6px rgba(0,0,0,0.15);
    --shadow-lg: 0 4px 8px rgba(0,0,0,0.12), 0 8px 24px rgba(0,0,0,0.2);
    --radius: 8px;
    --radius-lg: 12px;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    color: var(--text-light);
    background: var(--bg-light);
}

body.dark-mode {
    color: var(--text-dark);
    background: var(--bg-dark);
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

/* Header */
#header {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 1000;
    background: var(--surface-light);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 260px;
    max-width: 360px;
}

.dark-mode #header {
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
}

.header-link {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    text-decoration: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.header-link:hover {
    transform: translateX(4px);
    opacity: 0.8;
}

.header-link:active {
    transform: scale(0.98);
}

.logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    flex-shrink: 0;
}

.header-title {
    display: flex;
    flex-direction: column;
}

.brand-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-light);
    line-height: 1.2;
}

.dark-mode .brand-name {
    color: var(--text-dark);
}

.brand-subtitle {
    font-size: 10px;
    color: #5f6368;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dark-mode .brand-subtitle {
    color: #9aa0a6;
}

.header-right {
    display: flex;
    gap: 4px;
}

.header-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    transition: all 0.2s ease;
}

.header-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.dark-mode .header-btn {
    color: var(--text-dark);
}

.dark-mode .header-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.header-btn svg {
    width: 20px;
    height: 20px;
}

/* Search */
#searchContainer {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: 100%;
    max-width: 420px;
    padding: 0 12px;
}

#searchBox {
    background: var(--surface-light);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    padding: 10px 16px;
    gap: 12px;
}

.dark-mode #searchBox {
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
}

.search-icon {
    width: 20px;
    height: 20px;
    color: #5f6368;
    flex-shrink: 0;
}

.dark-mode .search-icon {
    color: #9aa0a6;
}

#searchInput {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    font-family: inherit;
    color: var(--text-light);
    outline: none;
}

.dark-mode #searchInput {
    color: var(--text-dark);
}

#searchInput::placeholder {
    color: #5f6368;
}

.dark-mode #searchInput::placeholder {
    color: #9aa0a6;
}

.clear-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    transition: all 0.2s ease;
}

.clear-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

.dark-mode .clear-btn {
    color: var(--text-dark);
    background: rgba(255, 255, 255, 0.1);
}

.dark-mode .clear-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.clear-btn svg {
    width: 16px;
    height: 16px;
}

.search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--surface-light);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-height: 300px;
    overflow-y: auto;
    padding: 6px;
}

.dark-mode .search-results {
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
}

.search-result-item {
    padding: 12px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s ease;
}

.search-result-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.dark-mode .search-result-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.search-result-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 2px;
}

.dark-mode .search-result-name {
    color: var(--text-dark);
}

.search-result-address {
    font-size: 12px;
    color: #5f6368;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dark-mode .search-result-address {
    color: #9aa0a6;
}

/* Map Controls */
#mapControls {
    position: absolute;
    bottom: 28px;
    right: 12px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group {
    background: var(--surface-light);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 2px;
}

.dark-mode .control-group {
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
}

.control-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    transition: all 0.15s ease;
}

.control-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.control-btn:active {
    background: rgba(0, 0, 0, 0.12);
}

.dark-mode .control-btn {
    color: var(--text-dark);
}

.dark-mode .control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.dark-mode .control-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.control-btn svg {
    width: 20px;
    height: 20px;
}

/* Route Panel */
.route-panel {
    position: absolute;
    bottom: 28px;
    left: 12px;
    z-index: 1000;
    background: var(--surface-light);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 320px;
    max-width: calc(100% - 24px);
}

.dark-mode .route-panel {
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
}

.route-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
}

.dark-mode .route-header {
    border-bottom-color: var(--border-dark);
}

.route-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-light);
}

.dark-mode .route-title {
    color: var(--text-dark);
}

.route-icon {
    width: 18px;
    height: 18px;
    color: var(--primary);
}

.close-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #5f6368;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.dark-mode .close-btn {
    color: #9aa0a6;
}

.dark-mode .close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.close-btn svg {
    width: 16px;
    height: 16px;
}

.route-content {
    padding: 12px 16px 16px;
}

.route-summary {
    display: flex;
    gap: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 12px;
}

.dark-mode .route-summary {
    border-bottom-color: var(--border-dark);
}

.summary-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.summary-icon {
    width: 20px;
    height: 20px;
    color: var(--primary);
}

.summary-text {
    display: flex;
    flex-direction: column;
}

.summary-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-light);
}

.dark-mode .summary-value {
    color: var(--text-dark);
}

.summary-label {
    font-size: 11px;
    color: #5f6368;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.dark-mode .summary-label {
    color: #9aa0a6;
}

.route-steps {
    max-height: 200px;
    overflow-y: auto;
}

.route-step {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}

.dark-mode .route-step {
    border-bottom-color: var(--border-dark);
}

.route-step:last-child {
    border-bottom: none;
}

.step-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.step-content {
    flex: 1;
}

.step-instruction {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 2px;
}

.dark-mode .step-instruction {
    color: var(--text-dark);
}

.step-distance {
    font-size: 12px;
    color: #5f6368;
}

.dark-mode .step-distance {
    color: #9aa0a6;
}

/* Loader */
.loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loader-text {
    margin-top: 16px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
}

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

/* Scale Bar */
#scaleBar {
    position: absolute;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

.mapboxgl-ctrl-scale {
    background: var(--surface-light) !important;
    border: 1px solid var(--border-light) !important;
    border-radius: 4px !important;
    padding: 4px 8px !important;
    font-size: 11px !important;
}

.dark-mode .mapboxgl-ctrl-scale {
    background: var(--surface-dark) !important;
    border-color: var(--border-dark) !important;
    color: var(--text-dark) !important;
}

/* Popup */
.mapboxgl-popup {
    z-index: 2000;
}

.mapboxgl-popup-content {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    font-family: inherit;
}

.mapboxgl-popup-close-button {
    padding: 6px;
    font-size: 16px;
    color: #5f6368;
}

.mapboxgl-popup-tip {
    width: 0;
    height: 0;
    border: 8px solid transparent;
}

.mapboxgl-popup-anchor-top .mapboxgl-popup-tip {
    border-bottom-color: white;
    border-top: none;
}

.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip {
    border-top-color: white;
    border-bottom: none;
}

/* Attribution */
.mapboxgl-ctrl-attrib {
    font-size: 10px !important;
    background: var(--surface-light) !important;
    padding: 6px 10px !important;
    border-radius: var(--radius) !important;
}

.dark-mode .mapboxgl-ctrl-attrib {
    background: var(--surface-dark) !important;
}

.mapboxgl-ctrl-attrib a {
    color: inherit !important;
}

/* Custom Markers */
.custom-marker {
    width: 0;
    height: 0;
    position: relative;
}

.main-marker .marker-pin {
    position: absolute;
    width: 28px;
    height: 40px;
    background: linear-gradient(135deg, #1a73e8 0%, #1557b0 100%);
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    left: -14px;
    top: -40px;
    box-shadow: 0 4px 12px rgba(26, 115, 232, 0.4);
    border: 2px solid white;
}

.main-marker .marker-pin::before {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.main-marker .marker-shadow {
    position: absolute;
    width: 20px;
    height: 6px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    left: -10px;
    top: 0;
    filter: blur(2px);
}

.main-marker.animate .marker-pin {
    animation: markerDrop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes markerDrop {
    from {
        opacity: 0;
        transform: rotate(-45deg) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: rotate(-45deg) translateY(0);
    }
}

/* Route Markers */
.route-marker {
    width: 0;
    height: 0;
    position: relative;
}

.route-marker .marker-number {
    position: absolute;
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #34a853 0%, #2d9e4a 100%);
    border-radius: 50%;
    left: -14px;
    top: -28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(52, 168, 83, 0.4);
    border: 2px solid white;
}

.route-marker.route-marker-2 .marker-number {
    background: linear-gradient(135deg, #ea4335 0%, #d93325 100%);
    box-shadow: 0 2px 8px rgba(234, 67, 53, 0.4);
}

.route-marker .marker-ring {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 2px solid rgba(26, 115, 232, 0.3);
    border-radius: 50%;
    left: -20px;
    top: -34px;
}

.route-marker.route-marker-2 .marker-ring {
    border-color: rgba(234, 67, 53, 0.3);
}

.route-marker.animate .marker-number {
    animation: markerBounce 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes markerBounce {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Popup moderno */
.popup-modern .maplibregl-popup-content,
.mapboxgl-popup-content {
    padding: 0 !important;
    border-radius: 14px !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.18), 0 1px 4px rgba(0,0,0,0.12) !important;
    overflow: hidden;
    border: none !important;
    min-width: 210px;
}

.popup-modern .maplibregl-popup-tip,
.mapboxgl-popup-tip { display: none !important; }

.popup-modern .maplibregl-popup-close-button,
.mapboxgl-popup-close-button {
    top: 8px !important;
    right: 10px !important;
    font-size: 20px !important;
    color: #bbb !important;
    background: none !important;
    border: none !important;
    line-height: 1 !important;
    z-index: 1;
}
.popup-modern .maplibregl-popup-close-button:hover { color: #666 !important; }

.popup-card {
    padding: 16px 18px 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
}

.popup-card-title {
    font-size: 15px;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1.3;
    margin-bottom: 6px;
    padding-right: 20px;
}

.popup-card-desc {
    font-size: 13px;
    color: #5f6368;
    margin-bottom: 6px;
    line-height: 1.4;
}

.popup-card-address {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #5f6368;
    margin-bottom: 5px;
}

.popup-card-coords {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #9aa0a6;
    margin-bottom: 10px;
    font-variant-numeric: tabular-nums;
}

.popup-route-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #1a73e8;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
.popup-route-btn:hover { background: #1557b0; }

/* Dark mode popup */
.dark-mode .popup-card-title { color: #e8eaed; }
.dark-mode .maplibregl-popup-content,
.dark-mode .mapboxgl-popup-content {
    background: #2d2d2d !important;
}
.dark-mode .popup-card-desc,
.dark-mode .popup-card-address { color: #9aa0a6; }
.dark-mode .popup-modern .maplibregl-popup-close-button { color: #666 !important; }
.dark-mode .popup-modern .maplibregl-popup-close-button:hover { color: #aaa !important; }

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-result-item {
    animation: fadeIn 0.2s ease forwards;
}

/* Mobile Responsive */
@media (max-width: 640px) {
    #header {
        max-width: none;
        right: 12px;
    }

    #searchContainer {
        max-width: none;
    }

    .route-panel {
        width: calc(100% - 24px);
        left: 12px;
        right: 12px;
    }

    #mapControls {
        bottom: 20px;
        right: 8px;
    }
}

/* Scrollbar */
.search-results::-webkit-scrollbar {
    width: 6px;
}

.search-results::-webkit-scrollbar-track {
    background: transparent;
}

.search-results::-webkit-scrollbar-thumb {
    background: #dadce0;
    border-radius: 3px;
}

.dark-mode .search-results::-webkit-scrollbar-thumb {
    background: #3c4043;
}

.route-steps::-webkit-scrollbar {
    width: 4px;
}

.route-steps::-webkit-scrollbar-track {
    background: transparent;
}

.route-steps::-webkit-scrollbar-thumb {
    background: #dadce0;
    border-radius: 2px;
}

.dark-mode .route-steps::-webkit-scrollbar-thumb {
    background: #3c4043;
}
