@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;500;600;700&family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* CSS Variables */
:root {
    --sidebar-width: 320px;
    --primary-color: #2DD4BF;
    --primary-hover: #14B8A6;
    --bg-dark: #0A0A0A;
    --bg-sidebar: #161616;
    --bg-section: #111111;
    --bg-elevated: #1A1A1A;
    --text-primary: #EDEDED;
    --text-secondary: #888888;
    --text-muted: #555555;
    --border-color: #1F1F1F;
    --border-light: #333333;
    --success-color: #10B981;
    --error-color: #EF4444;
    --warning-color: #FBBF24;
}

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

html, body {
    height: 100%;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    background-color: var(--bg-dark);
    color: var(--text-primary);
}

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

/* Sidebar Styles */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
}

/* Home Button */
.home-button {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 16px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    transition: all 0.2s;
}

.home-button:hover {
    color: white;
    background: rgba(0, 0, 0, 0.3);
    transform: translateX(-2px);
}

.home-logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: contain;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-sidebar);
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.sidebar-header .subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.sidebar-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-section h2 {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Form Styles */
.form-group {
    margin-bottom: 12px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

input[type="text"],
input[type="date"],
input[type="time"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    background-color: var(--bg-section);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(252, 76, 2, 0.15);
}

textarea {
    resize: vertical;
    min-height: 60px;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a0aec0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Pace Input */
.pace-input-group input {
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 1rem;
    text-align: center;
}

/* Range Slider */
input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-section);
    border-radius: 3px;
    outline: none;
    margin: 8px 0;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Stats Section */
.stats-section {
    background-color: var(--bg-section);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.stat-item {
    text-align: center;
    padding: 8px;
    background-color: var(--bg-sidebar);
    border-radius: 6px;
}

.stat-label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-value {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}

/* Stat loading spinner (small inline) */
.stat-item {
    position: relative;
}

.stat-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    position: absolute;
    top: 6px;
    right: 6px;
}

.stat-spinner.hidden {
    display: none;
}

.stat-item.loading .stat-value {
    opacity: 0.5;
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 14px 20px;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(252, 76, 2, 0.3);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Status Message */
.status-message {
    padding: 12px 20px;
    font-size: 0.8rem;
    text-align: center;
}

.status-message.hidden {
    display: none;
}

.status-message.success {
    background-color: rgba(72, 187, 120, 0.1);
    color: var(--success-color);
}

.status-message.error {
    background-color: rgba(252, 129, 129, 0.1);
    color: var(--error-color);
}

.status-message.warning {
    background-color: rgba(246, 173, 85, 0.1);
    color: var(--warning-color);
}

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

#map {
    flex: 1;
    z-index: 1;
}

/* Map Controls */
.map-controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    display: flex;
    gap: 8px;
    z-index: 1000;
}

.btn-control {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background-color: white;
    border: none;
    border-radius: 6px;
    color: #333;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: background-color 0.2s, transform 0.2s;
}

.btn-control:hover {
    background-color: #f5f5f5;
    transform: translateY(-1px);
}

.btn-control:active {
    transform: translateY(0);
}

.btn-control svg {
    flex-shrink: 0;
}

/* Prominent Snap to Roads button */
.btn-snap-roads {
    background: linear-gradient(135deg, #3182ce 0%, #2c5282 100%);
    color: white;
    font-weight: 600;
    padding: 12px 18px;
}

.btn-snap-roads:hover {
    background: linear-gradient(135deg, #2b6cb0 0%, #2a4365 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(49, 130, 206, 0.4);
}

.btn-snap-roads:active {
    transform: translateY(0);
}

.btn-snap-roads.aligning {
    opacity: 0.7;
    cursor: wait;
}

.toggle-control {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background-color: white;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    color: #333;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

.toggle-control input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(26, 26, 46, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 2000;
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loading-text {
    color: var(--text-primary);
    font-size: 0.9rem;
}

/* Leaflet Customizations */
.leaflet-control-geocoder {
    border-radius: 8px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
}

.leaflet-control-geocoder-form input {
    font-size: 14px !important;
}

.leaflet-routing-container {
    display: none !important;
}

/* Custom Waypoint Markers */
.waypoint-marker {
    background-color: var(--primary-color);
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: white;
}

.waypoint-marker.start {
    background-color: var(--success-color);
}

.waypoint-marker.end {
    background-color: #e53e3e;
}

/* User Account Section */
.user-account {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.auth-view.hidden {
    display: none;
}

.btn-login {
    display: inline-block;
    padding: 10px 20px;
    background: var(--primary-color);
    color: #0A0A0A;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-login:hover {
    background: var(--primary-hover);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.user-email {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.credit-balance {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    background: rgba(45, 212, 191, 0.15);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
}

.user-actions {
    display: flex;
    gap: 8px;
}

.btn-buy-credits {
    flex: 1;
    padding: 8px 12px;
    background: rgba(72, 187, 120, 0.9);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-buy-credits:hover {
    background: rgba(72, 187, 120, 1);
}

.btn-logout {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Credit Cost Info */
.credit-cost-info {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

/* Mobile Scroll Indicator - hidden on desktop */
.mobile-scroll-indicator {
    display: none;
}

/* Map Section Header - hidden on desktop */
.map-section-header {
    display: none;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease-out;
}

.modal-overlay.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-container {
    background: var(--bg-sidebar);
    border-radius: 12px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideIn 0.2s ease-out;
    border: 1px solid var(--border-color);
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

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

.modal-body {
    padding: 24px;
}

.modal-body p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.modal-footer {
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    justify-content: flex-end;
}

.modal-btn {
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.modal-btn-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.modal-btn-cancel:hover {
    background: rgba(255, 255, 255, 0.15);
}

.modal-btn-confirm {
    background: var(--primary-color);
    color: white;
}

.modal-btn-confirm:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(252, 76, 2, 0.3);
}

/* Responsive Design - Tablet */
@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
        min-width: 280px;
    }

    .sidebar-section {
        padding: 14px 16px;
    }
}

/* Responsive Design - Mobile */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        max-height: none;
        height: auto;
        border-right: none;
        border-bottom: none;
        overflow-y: visible;
        flex-shrink: 0;
    }

    .sidebar-header {
        padding: 16px;
        position: relative;
    }

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

    .sidebar-section {
        padding: 12px 16px;
    }

    .map-container {
        min-height: 70vh;
        height: 70vh;
        flex-shrink: 0;
        position: relative;
    }

    #map {
        height: 100%;
    }

    .map-controls {
        position: absolute;
        top: auto;
        left: 12px;
        right: 12px;
        bottom: 12px;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        z-index: 1000;
    }

    .btn-control {
        flex: 1 1 auto;
        min-width: 0;
        justify-content: center;
        padding: 12px 16px;
        font-size: 0.8rem;
        font-weight: 600;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }

    .btn-snap-roads {
        flex: 1 1 100%;
        order: -1;
        padding: 14px 20px;
        font-size: 0.85rem;
    }

    .toggle-control {
        flex: 1 1 auto;
        justify-content: center;
        padding: 12px 16px;
        font-size: 0.8rem;
        font-weight: 500;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }

    .user-account {
        margin-top: 12px;
        padding-top: 12px;
    }

    .user-info {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        flex-wrap: wrap;
    }

    .user-email {
        max-width: 120px;
    }

    .modal-container {
        width: 95%;
        max-width: none;
        margin: 10px;
    }

    .modal-header {
        padding: 16px 20px;
    }

    .modal-body {
        padding: 20px;
    }

    .modal-footer {
        padding: 16px 20px;
        flex-direction: column;
    }

    .modal-btn {
        width: 100%;
    }

    /* Mobile Scroll Indicator */
    .mobile-scroll-indicator {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 16px 20px;
        background: linear-gradient(135deg, var(--bg-section) 0%, var(--bg-sidebar) 100%);
        color: var(--text-secondary);
        font-size: 0.85rem;
        font-weight: 500;
        border-top: 1px solid var(--border-color);
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-scroll-indicator svg {
        animation: bounce 2s infinite;
        opacity: 0.7;
    }

    @keyframes bounce {
        0%, 20%, 50%, 80%, 100% {
            transform: translateY(0);
        }
        40% {
            transform: translateY(4px);
        }
        60% {
            transform: translateY(2px);
        }
    }

    /* Map Section Header */
    .map-section-header {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 16px 20px;
        background: var(--primary-color);
        color: white;
    }

    .map-section-header h2 {
        margin: 0;
        font-size: 1rem;
        font-weight: 600;
    }

    .map-section-header span {
        font-size: 0.75rem;
        opacity: 0.9;
        margin-top: 4px;
    }

}

/* Responsive Design - Small Phone */
@media (max-width: 480px) {
    .sidebar-header h1 {
        font-size: 1rem;
    }

    .sidebar-header .subtitle {
        font-size: 0.7rem;
    }

    .form-row {
        flex-direction: column;
        gap: 8px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .map-container {
        min-height: 65vh;
        height: 65vh;
    }

    .map-controls {
        left: 10px;
        right: 10px;
        bottom: 10px;
        gap: 6px;
    }

    .btn-control {
        padding: 10px 12px;
        font-size: 0.75rem;
    }

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

    .btn-snap-roads {
        padding: 12px 16px;
        font-size: 0.8rem;
    }

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

    .toggle-control {
        padding: 10px 12px;
        font-size: 0.75rem;
    }

    .user-actions {
        flex-direction: column;
        width: 100%;
    }

    .btn-buy-credits,
    .btn-logout {
        width: 100%;
    }
}
