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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: #1A202C;
    background-color: #F7FAFC;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1B2951 0%, #2D3748 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
    color: #FFFFFF;
}

.app-logo {
    font-size: 48px;
    margin-bottom: 16px;
}

.app-title {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 32px;
    line-height: 1.2;
}

.app-title-logo {
    height: 256px;
    width: auto;
    margin-bottom: 32px;
    object-fit: contain;
}

.loading-text {
    font-size: 16px;
    font-weight: 500;
    opacity: 0.8;
}

/* Spinner Animation */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid #FF6B35;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

/* App Container */
.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #1B2951 0%, #2D3748 100%);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(26, 32, 44, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 20px;
    z-index: 1000;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-title-header {
    font-size: 20px;
    font-weight: 600;
    color: #1B2951;
}

.app-title-header-logo {
    height: 64px;
    width: auto;
    object-fit: contain;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 0 20px;
}

/* Search Components */
.search-container {
    position: relative;
    width: 100%;
    max-width: 400px;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: #FFFFFF;
    border: 2px solid #E2E8F0;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.search-input-wrapper:focus-within {
    border-color: #FF6B35;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.search-icon {
    position: absolute;
    left: 12px;
    color: #A0AEC0;
    pointer-events: none;
    z-index: 1;
}

.search-input {
    flex: 1;
    padding: 12px 16px 12px 40px;
    border: none;
    background: transparent;
    font-size: 16px;
    color: #1B2951;
    outline: none;
    min-height: 48px;
}

.search-input::placeholder {
    color: #A0AEC0;
}

.search-clear {
    position: absolute;
    right: 8px;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    border-radius: 8px;
    color: #A0AEC0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.search-clear:hover {
    background: #F7FAFC;
    color: #4A5568;
}

/* Search Suggestions */
.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #FFFFFF;
    border: 1px solid #E2E8F0;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(26, 32, 44, 0.15);
    margin-top: 4px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 2000;
}

.search-suggestion {
    padding: 16px 20px;
    font-size: 16px;
    color: #1B2951;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: background 0.2s ease;
    min-height: 48px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid #F7FAFC;
}

.search-suggestion:last-child {
    border-bottom: none;
}

.search-suggestion:hover,
.search-suggestion.highlighted {
    background: #F7FAFC;
}

.search-suggestion-icon {
    color: #A0AEC0;
    margin-top: 2px;
    flex-shrink: 0;
}

.search-suggestion-content {
    flex: 1;
    min-width: 0;
}

.search-suggestion-title {
    font-weight: 500;
    color: #1B2951;
    line-height: 1.3;
    word-wrap: break-word;
}

.search-suggestion-subtitle {
    font-size: 14px;
    color: #4A5568;
    margin-top: 2px;
    line-height: 1.3;
    word-wrap: break-word;
}

.search-loading {
    padding: 20px;
    text-align: center;
    color: #4A5568;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.search-loading .spinner {
    width: 16px;
    height: 16px;
    border-width: 2px;
    margin: 0;
}

.search-error {
    padding: 16px 20px;
    text-align: center;
    color: #E53E3E;
    font-size: 14px;
    background: #FED7D7;
    border-radius: 8px;
    margin: 8px;
}

.search-no-results {
    padding: 20px;
    text-align: center;
    color: #4A5568;
    font-size: 14px;
}

/* Map Container */
.map-container {
    flex: 1;
    position: relative;
}

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

/* Map Controls */
.map-controls {
    position: absolute;
    top: 80px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

/* Control Buttons */
.control-button {
    width: 48px;
    height: 48px;
    background: #FFFFFF;
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(26, 32, 44, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #1B2951;
    transition: all 0.2s ease;
    cursor: pointer;
}

.control-button:hover {
    background: #F7FAFC;
    transform: scale(1.05);
}

.control-button:active {
    transform: scale(0.95);
}

/* Context Menu */
.context-menu {
    position: absolute;
    background: #FFFFFF;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(26, 32, 44, 0.2);
    border: 1px solid rgba(26, 32, 44, 0.1);
    min-width: 200px;
    padding: 8px 0;
    z-index: 2000;
}

.context-menu-item {
    padding: 16px 20px;
    font-size: 16px;
    color: #1B2951;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: background 0.2s ease;
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.context-menu-item:hover {
    background: #F7FAFC;
}

/* Action Bar */
.action-bar {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    gap: 16px;
    z-index: 1000;
}

/* Button Components */
.btn-primary {
    background: #FF6B35;
    color: #FFFFFF;
    border: none;
    border-radius: 12px;
    padding: 16px 24px;
    font-size: 18px;
    font-weight: 600;
    min-height: 48px;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
    transition: all 0.2s ease;
    cursor: pointer;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary:hover:not(:disabled) {
    background: #E55A2B;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 107, 53, 0.4);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
}

.btn-primary:disabled {
    background: #CBD5E0;
    color: #A0AEC0;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background: #FFFFFF;
    color: #1B2951;
    border: 2px solid #1B2951;
    border-radius: 12px;
    padding: 14px 22px;
    font-size: 16px;
    font-weight: 500;
    min-height: 48px;
    transition: all 0.2s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-secondary:hover {
    background: #1B2951;
    color: #FFFFFF;
}

.btn-secondary:active {
    transform: scale(0.98);
}

/* Bottom Panel */
.bottom-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #FFFFFF;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(26, 32, 44, 0.1);
    padding: 24px;
    max-height: 60vh;
    overflow-y: auto;
    transform: translateY(0);
    transition: transform 0.3s ease;
    z-index: 999;
}

.bottom-panel.collapsed {
    transform: translateY(100%);
}

.bottom-panel.collapsed .route-summary,
.bottom-panel.collapsed .route-actions {
    display: none;
}

.panel-handle {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 6px;
    background: #CBD5E0;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.panel-handle:hover {
    background: #A0AEC0;
}

.panel-content {
    margin-top: 20px;
}

/* Route Summary */
.route-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #1B2951 0%, #2D3748 100%);
    color: #FFFFFF;
    padding: 20px 24px;
    border-radius: 12px;
    margin-bottom: 20px;
}

.route-stat {
    text-align: center;
    flex: 1;
}

.route-stat-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
}

.route-stat-label {
    font-size: 14px;
    opacity: 0.8;
    margin-top: 4px;
}

/* Route Actions */
.route-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 100px;
}

.export-option {
    background: #FFFFFF;
    border: 2px solid #E2E8F0;
    border-radius: 12px;
    padding: 16px 20px;
    font-size: 16px;
    font-weight: 500;
    color: #1B2951;
    transition: all 0.2s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
}

.export-option:hover {
    border-color: #FF6B35;
    background: #FFF5F2;
    color: #FF6B35;
}

.export-option:active {
    transform: scale(0.98);
}

/* Instruction Text */
.instruction-text {
    text-align: center;
    color: #4A5568;
    font-size: 16px;
    font-weight: 500;
    padding: 20px;
    background: #F7FAFC;
    border-radius: 12px;
    border: 2px dashed #CBD5E0;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    max-width: 400px;
    z-index: 4000;
    pointer-events: none;
}

.toast {
    background: #FFFFFF;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(26, 32, 44, 0.3);
    padding: 18px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
    transform: translateY(-100px);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: auto;
    font-size: 16px;
    font-weight: 500;
    min-height: 56px; /* Ensure minimum touch target size */
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* High contrast colors for outdoor visibility */
.toast.success {
    background: #2D6A3E;
    color: #FFFFFF;
    border: 2px solid #38A169;
}

.toast.error {
    background: #C53030;
    color: #FFFFFF; 
    border: 2px solid #E53E3E;
}

.toast.warning {
    background: #D69E2E;
    color: #1A202C;
    border: 2px solid #FFD23F;
}

.toast.info {
    background: #2B6CB0;
    color: #FFFFFF;
    border: 2px solid #4299E1;
}

/* Undo button styling for gloves */
.toast-undo-btn {
    background: rgba(255, 255, 255, 0.2);
    color: inherit;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-width: 48px;
    min-height: 48px; /* Minimum touch target for gloves */
    margin-left: auto;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.toast-undo-btn:hover,
.toast-undo-btn:focus {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.8);
}

.toast-undo-btn:active {
    transform: scale(0.95);
}

/* Mobile optimization */
@media (max-width: 768px) {
    .toast-container {
        top: 10px;
        width: calc(100% - 20px);
    }
    
    .toast {
        padding: 20px 24px;
        font-size: 17px; /* iOS recommended size */
    }
    
    .toast-undo-btn {
        min-width: 60px;
        min-height: 52px;
        padding: 14px 24px;
        font-size: 15px;
    }
}

/* Custom Map Markers */
.marker-start {
    background: #38A169;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 3px solid #FFFFFF;
    box-shadow: 0 2px 8px rgba(56, 161, 105, 0.4);
}

.marker-end {
    background: #E53E3E;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 3px solid #FFFFFF;
    box-shadow: 0 2px 8px rgba(229, 62, 62, 0.4);
}

.marker-waypoint {
    background: #FF6B35;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #FFFFFF;
    box-shadow: 0 2px 6px rgba(255, 107, 53, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    font-weight: bold;
    font-size: 12px;
    line-height: 1;
}

/* Responsive Design */
@media (max-width: 767px) {
    .header-center {
        padding: 0 8px;
    }
    
    .search-container {
        max-width: none;
    }
    
    .app-title-header {
        font-size: 18px;
    }
    
    .app-title-header-logo {
        height: 48px;
    }
    
    .header-left,
    .header-right {
        flex-shrink: 0;
    }
}

@media (min-width: 768px) {
    .action-bar {
        bottom: 40px;
        left: 40px;
        right: 40px;
    }
    
    .map-controls {
        top: 100px;
        right: 40px;
    }
    
    .bottom-panel {
        left: 40px;
        right: 40px;
        border-radius: 16px;
        bottom: 40px;
    }
    
    .bottom-panel.collapsed {
        transform: translateY(200%);
    }
}

@media (min-width: 1024px) {
    .bottom-panel {
        position: fixed;
        top: 80px;
        bottom: auto;
        right: 40px;
        left: auto;
        width: 350px;
        max-height: calc(100vh - 120px);
        transform: none;
        border-radius: 16px;
    }
    
    .bottom-panel.collapsed {
        transform: translateY(-110%);
    }
    
    .action-bar {
        bottom: 40px;
        left: 40px;
        right: 390px;
    }
}

/* Accessibility & Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .bottom-panel,
    .toast,
    .control-button,
    .btn-primary,
    .btn-secondary,
    .export-option {
        transition: none;
    }
    
    .spinner {
        animation: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .app-header {
        background: rgba(26, 32, 44, 0.95);
        border-bottom-color: rgba(255, 255, 255, 0.1);
    }
    
    .app-title-header {
        color: #FFFFFF;
    }
    
    .control-button {
        background: #2D3748;
        color: #FFFFFF;
    }
    
    .control-button:hover {
        background: #4A5568;
    }
    
    .search-input-wrapper {
        background: #2D3748;
        border-color: #4A5568;
    }
    
    .search-input {
        color: #FFFFFF;
    }
    
    .search-input::placeholder {
        color: #718096;
    }
    
    .search-suggestions {
        background: #2D3748;
        border-color: #4A5568;
    }
    
    .search-suggestion {
        color: #FFFFFF;
        border-bottom-color: #4A5568;
    }
    
    .search-suggestion:hover,
    .search-suggestion.highlighted {
        background: #4A5568;
    }
    
    .search-suggestion-title {
        color: #FFFFFF;
    }
    
    .search-suggestion-subtitle {
        color: #A0AEC0;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .btn-primary {
        border: 2px solid #000000;
    }
    
    .control-button {
        border: 2px solid #000000;
    }
    
    .context-menu {
        border: 2px solid #000000;
    }
}
