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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    overflow: hidden;
}

/* Layout */
#app {
    position: relative;
    width: 100vw;
    height: 100vh;
}

/* Fullscreen Map */
#map {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

/* Control Panel - Top Left */
#control-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 250px;
    max-width: 300px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #e0e0e0;
}

.panel-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #007AFF;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.icon-btn:hover {
    background: rgba(0, 122, 255, 0.1);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

label {
    font-weight: 500;
    font-size: 0.85rem;
    color: #666;
}

select {
    padding: 0.6rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.9rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

select:hover {
    border-color: #007AFF;
}

.btn {
    background: #007AFF;
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    width: 100%;
}

.btn:hover {
    background: #0056CC;
}

.btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.status {
    font-size: 0.85rem;
    padding: 0.6rem;
    border-radius: 8px;
    margin-top: 0.5rem;
}

.status.error {
    background: #FFE6E6;
    color: #CC0000;
    border: 1px solid #FFB3B3;
}

.status.success {
    background: #E6F7E6;
    color: #006600;
    border: 1px solid #B3E6B3;
}

.results-info {
    margin-top: 0.75rem;
    padding: 0.6rem;
    background: rgba(0, 122, 255, 0.1);
    border-radius: 8px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    color: #007AFF;
}

/* Legend Panel - Bottom Left */
#legend-panel {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 220px;
}

#legend-panel h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #333;
}

.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: 50%;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f0f0f0;
    border-top: 4px solid #007AFF;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

.loading {
    opacity: 0.7;
    pointer-events: none;
}

/* MapKit Popup Styling */
.mapkit-popup {
    max-width: 300px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.popup-content {
    padding: 1rem;
    background: white;
}

.popup-title {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: #333;
}

.popup-description {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.popup-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.popup-link {
    display: inline-block;
    background: #007AFF;
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background-color 0.2s;
    flex: 1;
    text-align: center;
}

.popup-link:hover {
    background: #0056CC;
}

.popup-nav-link {
    display: inline-block;
    background: #34C759;
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.popup-nav-link:hover {
    background: #28A745;
}

.popup-distance {
    font-size: 0.8rem;
    color: #999;
    margin-top: 0.5rem;
}

.popup-help-needed {
    background: #FFF3CD;
    border-left: 3px solid #FF8C00;
    padding: 0.75rem;
    margin: 0.75rem 0;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #856404;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #999;
    transition: color 0.2s;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 1;
}

.modal-close:hover {
    color: #333;
}

.modal-content h2 {
    color: #007AFF;
    margin-bottom: 1rem;
    font-size: 1.75rem;
}

.modal-content h3 {
    color: #333;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-size: 1.25rem;
}

.modal-content p {
    color: #666;
    margin-bottom: 1rem;
    line-height: 1.6;
}

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

.modal-content li {
    color: #666;
    margin-bottom: 0.5rem;
}

.modal-content a {
    color: #007AFF;
    text-decoration: none;
}

.modal-content a:hover {
    text-decoration: underline;
}

.modal-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid #e0e0e0;
    text-align: center;
    font-size: 0.9rem;
    color: #999;
}

/* Responsive Design */
@media (max-width: 768px) {
    #control-panel {
        top: 10px;
        left: 10px;
        right: auto;
        min-width: auto;
        max-width: calc(100vw - 20px);
        padding: 0.75rem;
    }

    .panel-header {
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .panel-header h1 {
        font-size: 1.1rem;
    }

    .icon-btn {
        font-size: 1.25rem;
    }

    .control-group {
        margin-bottom: 0.5rem;
    }

    label {
        font-size: 0.75rem;
    }

    select {
        padding: 0.5rem;
        font-size: 0.85rem;
    }

    .btn {
        padding: 0.6rem;
        font-size: 0.85rem;
    }

    .status {
        font-size: 0.75rem;
        padding: 0.5rem;
    }

    .results-info {
        padding: 0.5rem;
        font-size: 0.75rem;
        margin-top: 0.5rem;
    }

    #legend-panel {
        bottom: 10px;
        left: 10px;
        right: auto;
        min-width: auto;
        max-width: 200px;
        padding: 0.75rem;
    }

    #legend-panel h3 {
        font-size: 0.85rem;
        margin-bottom: 0.5rem;
    }

    .legend-item {
        font-size: 0.75rem;
        margin-bottom: 0.4rem;
        gap: 0.5rem;
    }

    .legend-color {
        width: 12px;
        height: 12px;
    }

    .modal-content {
        padding: 1.5rem;
        width: 95%;
    }
}

@media (max-width: 480px) {
    #control-panel {
        max-width: 180px;
    }

    .panel-header h1 {
        font-size: 1rem;
    }

    #legend-panel {
        max-width: 160px;
    }

    #legend-panel h3 {
        font-size: 0.8rem;
    }

    .legend-item {
        font-size: 0.7rem;
    }

    .legend-color {
        width: 10px;
        height: 10px;
    }
}