/* CSS Variables */
:root {
    /* Light Theme */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    
    /* Brand Colors */
    --primary: #10b981;
    --primary-hover: #059669;
    --primary-light: #d1fae5;
    --secondary: #6366f1;
    --secondary-hover: #4f46e5;
    
    /* Status Colors */
    --available: #22c55e;
    --occupied: #eab308;
    --offline: #ef4444;
    
    /* Spacing */
    --header-height: 64px;
    --sidebar-width: 320px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border-color: #334155;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

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

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

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--header-height);
    padding: 12px 16px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    gap: 12px;
}

/* iOS safe area - using supports query for proper detection */
@supports (padding-top: constant(safe-area-inset-top)) {
    .header {
        padding-top: calc(12px + constant(safe-area-inset-top));
    }
}

@supports (padding-top: env(safe-area-inset-top)) {
    .header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

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

.company-logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

/* Mobile: Hide logo text, show only SV icon */
@media (max-width: 768px) {
    .company-logo {
        height: 32px;
        width: 50px;
    }
    .company-logo text:nth-child(3),
    .company-logo text:nth-child(4) {
        display: none;
    }
    
    .header-right {
        display: none;
    }
    
    .header {
        padding: 10px 15px;
        /* Fallback for iOS status bar - 44px is typical iPhone notch area */
        padding-top: 50px;
        gap: 10px;
    }
}

/* Very small screens: maximize search */
@media (max-width: 480px) {
    .header-left {
        display: none;
    }
    
    .header {
        padding: 10px 20px;
        /* Fixed padding for status bar on mobile */
        padding-top: 55px;
    }
    
    .header-center {
        max-width: 100%;
    }
}

/* Override with safe area if supported */
@media (max-width: 768px) {
    @supports (padding-top: env(safe-area-inset-top)) {
        .header {
            padding-top: calc(10px + env(safe-area-inset-top));
        }
    }
}

@media (max-width: 480px) {
    @supports (padding-top: env(safe-area-inset-top)) {
        .header {
            padding-top: calc(15px + env(safe-area-inset-top));
        }
    }
}

.header-center {
    flex: 1;
    max-width: 600px;
}

.search-container {
    position: relative;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    height: 48px;
    padding: 0 44px 0 48px;
    border: 2px solid var(--border-color);
    border-radius: 24px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all var(--transition-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.search-input::placeholder {
    color: var(--text-muted);
    text-align: left;
}

@media (max-width: 480px) {
    .search-input {
        height: 50px;
        font-size: 1rem;
        border-radius: 25px;
    }
    
    .search-input::placeholder {
        font-size: 0.95rem;
    }
}

.clear-search {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--bg-tertiary);
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.clear-search:hover {
    background: var(--border-color);
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Filter Section Styles */
.filter-section {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

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

.filter-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background var(--transition-fast);
}

.filter-checkbox:hover {
    background: var(--bg-tertiary);
}

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

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.status-dot.available, .legend-dot.available {
    background: var(--available);
}

.status-dot.occupied, .legend-dot.occupied {
    background: var(--occupied);
}

.status-dot.offline, .legend-dot.offline {
    background: var(--offline);
}

.power-slider {
    padding: 8px 0;
}

.power-slider input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
}

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

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

.power-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

#power-value {
    font-weight: 600;
    color: var(--primary);
}


/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-large {
    width: 100%;
    padding: 14px 24px;
    font-size: 1rem;
}

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

/* Map */
.map-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

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

/* Custom Leaflet Styles */
.leaflet-container {
    font-family: inherit;
}

.custom-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-fast);
}

.custom-marker:hover {
    transform: scale(1.15);
}

.custom-marker.available {
    background: var(--available);
}

.custom-marker.occupied {
    background: var(--occupied);
}

.custom-marker.offline {
    background: var(--offline);
}

.custom-marker svg {
    width: 18px;
    height: 18px;
    color: white;
}

.marker-cluster {
    background: var(--primary-light);
    border-radius: 50%;
}

.marker-cluster div {
    width: 36px;
    height: 36px;
    margin: 5px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
}

/* Map Controls */
.map-controls {
    position: absolute;
    right: 16px;
    top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 500;
}

.map-control-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
}

.map-control-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

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

/* Map Legend */
.map-legend {
    position: absolute;
    left: 16px;
    bottom: 90px;
    display: flex;
    gap: 16px;
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    z-index: 500;
}

/* Mobile: Push legend above filter button and browser URL bar */
@media (max-width: 768px) {
    .map-legend {
        left: 10px;
        bottom: 140px;
        gap: 10px;
        padding: 8px 12px;
        font-size: 0.75rem;
    }
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Floating Filter Button */
.floating-filter-btn {
    position: absolute;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 28px;
    background: var(--primary);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
    z-index: 500;
    transition: all var(--transition-fast);
}

/* Mobile: Push filter button above browser URL bar (typically 50-70px) */
@media (max-width: 768px) {
    .floating-filter-btn {
        bottom: 80px;
        padding: 12px 24px;
        font-size: 0.95rem;
    }
}

.floating-filter-btn:hover {
    background: var(--primary-hover);
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 6px 25px rgba(16, 185, 129, 0.5);
}

.floating-filter-btn:active {
    transform: translateX(-50%) scale(0.98);
}

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

.floating-filter-btn .filter-count {
    background: white;
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    margin-left: 4px;
}

/* Filter Modal */
.filter-modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.filter-modal-overlay {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: fadeIn var(--transition-normal);
}

.filter-modal-content {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    animation: fadeIn var(--transition-normal);
}

@media (min-width: 600px) {
    .filter-modal-content {
        width: 90%;
        max-width: 480px;
        height: auto;
        max-height: 85vh;
        border-radius: 20px;
        animation: scaleIn var(--transition-normal);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.filter-modal-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.filter-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.filter-modal-footer {
    display: flex;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.filter-modal-footer .btn {
    flex: 1;
    padding: 14px 20px;
    font-size: 1rem;
}

.filter-modal-footer .btn-primary {
    flex: 2;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 2000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: fadeIn var(--transition-normal);
}

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

.modal-content {
    position: relative;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    background: var(--bg-primary);
    border-radius: 24px 24px 0 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp var(--transition-normal);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    z-index: 10;
    transition: all var(--transition-fast);
}

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

.modal-close svg {
    width: 20px;
    height: 20px;
}

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

.operator-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.operator-logo {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    object-fit: contain;
    background: var(--bg-secondary);
    padding: 8px;
}

.operator-info h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.operator-name {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.station-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.station-status.available {
    background: rgba(34, 197, 94, 0.15);
    color: var(--available);
}

.station-status.occupied {
    background: rgba(234, 179, 8, 0.15);
    color: var(--occupied);
}

.station-status.offline {
    background: rgba(239, 68, 68, 0.15);
    color: var(--offline);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.detail-section {
    display: flex;
    gap: 16px;
    padding: 16px 24px;
}

.detail-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-radius: 10px;
    color: var(--primary);
    flex-shrink: 0;
}

.detail-icon svg {
    width: 20px;
    height: 20px;
}

.detail-content h4 {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 4px;
}

.detail-content p {
    font-size: 0.95rem;
    color: var(--text-primary);
}

.connector-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.connector-tag {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.amenities-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.amenity-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.amenity-item svg {
    width: 18px;
    height: 18px;
    color: var(--primary);
}

.modal-footer {
    padding: 16px 24px 24px;
    border-top: 1px solid var(--border-color);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    transition: opacity var(--transition-normal);
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    text-align: center;
}

.loading-spinner svg {
    width: 48px;
    height: 48px;
    color: var(--primary);
    margin-bottom: 16px;
}

.loading-spinner p {
    color: var(--text-secondary);
    font-size: 1rem;
}

.spin {
    animation: spin 1s linear infinite;
}

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

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

/* Responsive Design */
@media (max-width: 768px) {
    .header {
        padding: 0 12px;
    }
    
    .logo-text {
        display: none;
    }
    
    .header-center {
        max-width: none;
    }
    
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        transform: translateX(-100%);
        box-shadow: var(--shadow-xl);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-header .icon-btn {
        display: flex;
    }
    
    .filter-toggle-btn {
        display: flex;
    }
    
    .map-legend {
        left: 50%;
        transform: translateX(-50%);
        bottom: 16px;
    }
    
    .modal-content {
        max-height: 90vh;
        border-radius: 20px 20px 0 0;
    }
}

@media (min-width: 769px) {
    .modal {
        align-items: center;
    }
    
    .modal-content {
        max-height: 80vh;
        border-radius: 20px;
        margin: 24px;
    }
}

/* Leaflet Popup Override */
.leaflet-popup-content-wrapper {
    border-radius: 12px;
    padding: 0;
}

.leaflet-popup-content {
    margin: 0;
    min-width: 200px;
}

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

/* User Location Marker */
.user-location-marker {
    width: 20px;
    height: 20px;
    background: var(--secondary);
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 8px rgba(99, 102, 241, 0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(99, 102, 241, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
    }
}
