/* ============================================
   VinFast Battery Swap Finder - Styles
   ============================================ */

:root {
    --primary: #00A859;
    --primary-dark: #008A47;
    --primary-light: #E6F7EF;
    --danger: #E53935;
    --warning: #F9A825;
    --info: #1E88E5;
    --bg: #F5F6FA;
    --surface: #FFFFFF;
    --text: #1A1A2E;
    --text-secondary: #6B7280;
    --text-light: #9CA3AF;
    --border: #E5E7EB;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --header-height: 56px;
    --search-height: 52px;
    --filter-height: 44px;
    --panel-min: 180px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    user-select: none;
    -webkit-user-select: none;
}

/* ============ SPLASH SCREEN ============ */
.splash-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #00A859 0%, #008A47 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.splash-screen.hide {
    opacity: 0;
    pointer-events: none;
}

.splash-content {
    text-align: center;
    color: white;
}

.splash-icon {
    width: 80px;
    height: 80px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 36px;
    animation: pulse 2s infinite;
}

.splash-content h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.splash-content p {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 24px;
}

.splash-loader {
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    margin: 0 auto;
    overflow: hidden;
}

.splash-loader::after {
    content: '';
    display: block;
    width: 40%;
    height: 100%;
    background: white;
    border-radius: 2px;
    animation: slide 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

@keyframes slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

/* ============ APP CONTAINER ============ */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
    background: var(--bg);
    box-shadow: var(--shadow-lg);
}

/* ============ HEADER ============ */
.app-header {
    height: var(--header-height);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 1px solid var(--border);
    z-index: 100;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
}

.logo-icon {
    font-size: 20px;
    color: var(--primary);
}

.header-right {
    display: flex;
    gap: 4px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 50%;
    font-size: 18px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.icon-btn:hover, .icon-btn:active {
    background: var(--bg);
}

.locate-btn {
    color: var(--primary);
}

.locate-btn.locating {
    animation: spin 1s linear infinite;
    color: var(--info);
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ============ SEARCH ============ */
.search-container {
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 99;
    flex-shrink: 0;
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 0 12px;
    height: var(--search-height);
    border: 2px solid transparent;
    transition: border-color var(--transition);
}

.search-box:focus-within {
    border-color: var(--primary);
    background: var(--surface);
}

.search-icon {
    color: var(--text-light);
    font-size: 16px;
    margin-right: 10px;
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    color: var(--text);
    outline: none;
    min-width: 0;
}

.search-box input::placeholder {
    color: var(--text-light);
}

.clear-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--border);
    border-radius: 50%;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 12px;
    right: 12px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    max-height: 240px;
    overflow-y: auto;
    z-index: 200;
}

.search-result-item {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background var(--transition);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover, .search-result-item:active {
    background: var(--primary-light);
}

.search-result-item i {
    color: var(--primary);
    font-size: 16px;
}

.search-result-item .result-info {
    flex: 1;
    min-width: 0;
}

.search-result-item .result-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-item .result-addr {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-item .result-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}

/* ============ FILTER CHIPS ============ */
.filter-container {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface);
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
    border-bottom: 1px solid var(--border);
}

.filter-container::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    padding: 7px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.filter-chip i {
    font-size: 12px;
}

.filter-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.filter-chip[data-filter="available"].active {
    background: #00A859;
    border-color: #00A859;
}

.filter-chip[data-filter="low"].active {
    background: var(--warning);
    border-color: var(--warning);
}

.filter-chip[data-filter="empty"].active {
    background: var(--danger);
    border-color: var(--danger);
}

/* ============ MAP ============ */
.map-container {
    flex: 1;
    min-height: 0;
    z-index: 1;
}

/* Custom Leaflet markers */
.custom-marker {
    width: 36px;
    height: 36px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}

.custom-marker::after {
    content: '';
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transform: rotate(45deg);
}

.custom-marker.available { background: #00A859; }
.custom-marker.low { background: #F9A825; }
.custom-marker.empty { background: #E53935; }

.marker-pin {
    width: 30px;
    height: 30px;
    border-radius: 50% 50% 50% 0;
    background: #00A859;
    position: absolute;
    transform: rotate(-45deg);
    left: 50%;
    top: 50%;
    margin: -20px 0 0 -15px;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.marker-pin::after {
    content: '';
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
}

/* Leaflet overrides */
.leaflet-control-zoom {
    margin-right: 12px !important;
    margin-bottom: 20px !important;
    border-radius: var(--radius-sm) !important;
    overflow: hidden;
    box-shadow: var(--shadow) !important;
    border: none !important;
}

.leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
    color: var(--text) !important;
}

.leaflet-popup-content-wrapper {
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-lg) !important;
    padding: 0 !important;
}

.leaflet-popup-content {
    margin: 0 !important;
    min-width: 220px;
}

.leaflet-popup-close-button {
    padding: 8px !important;
    font-size: 20px !important;
    color: var(--text-secondary) !important;
    z-index: 10;
}

.popup-content {
    padding: 16px;
}

.popup-content h4 {
    font-size: 15px;
    margin-bottom: 8px;
    color: var(--text);
}

.popup-content .popup-addr {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    line-height: 1.4;
}

.popup-stats {
    display: flex;
    gap: 12px;
}

.popup-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    font-weight: 600;
}

.popup-stat.avail { color: #00A859; }
.popup-stat.total { color: var(--text-secondary); }

/* ============ BOTTOM PANEL ============ */
.bottom-panel {
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
    z-index: 50;
    flex-shrink: 0;
    max-height: 140px; /* Chỉ hiện 1-2 trạm mặc định */
    display: flex;
    flex-direction: column;
    transition: max-height 0.3s ease;
    overflow: hidden;
}

.bottom-panel.expanded {
    max-height: 55vh; /* Kéo lên mới thấy nhiều */
}

.panel-handle {
    width: 48px;
    height: 5px;
    background: #ccc;
    border-radius: 3px;
    margin: 8px auto 4px;
    cursor: grab;
    flex-shrink: 0;
    position: relative;
}

.panel-handle::after {
    content: '';
    position: absolute;
    inset: -12px -20px;
    /* Larger touch target */
}

.panel-handle:active {
    cursor: grabbing;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 16px 6px;
    flex-shrink: 0;
}

.panel-header h3 {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.station-count {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-light);
    padding: 2px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}

.station-list {
    overflow-y: auto;
    padding: 0 10px 8px;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.station-card {
    display: flex;
    gap: 10px;
    padding: 10px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    cursor: pointer;
    transition: all var(--transition);
    border: 1.5px solid transparent;
}

/* Highlight: station currently centered on map */
.station-card.highlight {
    border-color: var(--primary);
    background: var(--primary-light);
}

.station-card:hover, .station-card:active {
    border-color: var(--primary);
}

.station-card .card-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    color: white;
}

.station-card .card-icon.available { background: #00A859; }
.station-card .card-icon.low { background: #F9A825; }
.station-card .card-icon.empty { background: #E53935; }

.station-card .card-info {
    flex: 1;
    min-width: 0;
}

.station-card .card-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.station-card .card-addr {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.station-card .card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 12px;
    align-items: center;
}

.station-card .card-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.station-card .card-meta .meta-avail { color: #00A859; font-weight: 600; }
.station-card .card-meta .meta-dist { color: var(--text-secondary); }

.station-card .card-arrow {
    display: flex;
    align-items: center;
    color: var(--text-light);
    font-size: 14px;
    flex-shrink: 0;
}

/* ============ MODAL ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 20px 16px 24px;
    animation: slideUp 0.3s ease;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg);
    border-radius: 50%;
    font-size: 16px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.btn {
    flex: 1;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover, .btn-primary:active {
    background: var(--primary-dark);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

/* Modal detail styles */
.detail-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}

.detail-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
    flex-shrink: 0;
}

.detail-icon.available { background: #00A859; }
.detail-icon.low { background: #F9A825; }
.detail-icon.empty { background: #E53935; }

.detail-title h3 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 4px;
}

.detail-title .detail-addr {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.detail-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.detail-stat-card {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
}

.detail-stat-card .stat-value {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 2px;
}

.detail-stat-card .stat-value.green { color: #00A859; }
.detail-stat-card .stat-value.orange { color: #F9A825; }
.detail-stat-card .stat-value.red { color: #E53935; }

.detail-stat-card .stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.detail-info-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.detail-info-row i {
    width: 20px;
    color: var(--text-light);
    text-align: center;
}

.detail-info-row:last-child {
    border-bottom: none;
}

/* ============ TOAST ============ */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    z-index: 400;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.3s ease;
    white-space: nowrap;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ============ LOADING OVERLAY ============ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.7);
    z-index: 350;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ============ NO RESULTS ============ */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 48px;
    color: var(--border);
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 14px;
}

/* ============ ANIMATIONS ============ */
@keyframes gps-pulse {
    0% { transform: scale(0.5); opacity: 0.8; }
    100% { transform: scale(2); opacity: 0; }
}

/* ============ REFRESH TIMER ============ */
.refresh-timer {
    font-size: 13px;
    font-weight: 700;
    color: #00A859;
    background: #E6F7EF;
    padding: 4px 10px;
    border-radius: 12px;
    margin-right: 6px;
    min-width: 42px;
    text-align: center;
    letter-spacing: -0.3px;
    transition: all 0.3s ease;
}

.refresh-timer.warning { color: #F9A825; background: #FFF3E0; }
.refresh-timer.danger { color: #E53935; background: #FFEBEE; }

body.dark .refresh-timer { background: rgba(0,168,89,0.2); }
body.dark .refresh-timer.warning { background: rgba(249,168,37,0.2); }
body.dark .refresh-timer.danger { background: rgba(229,57,53,0.2); }
.gps-prompt {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.gps-prompt-content {
    background: white;
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    text-align: center;
    max-width: 320px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.gps-prompt-content i.fa-location-crosshairs {
    font-size: 48px;
    color: var(--primary);
    margin-bottom: 12px;
}

.gps-prompt-content h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.gps-prompt-content p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* ============ RESPONSIVE ============ */
@media (min-width: 481px) {
    .app-container {
        border-radius: var(--radius-lg);
        margin-top: 10px;
        height: calc(100vh - 20px);
        height: calc(100dvh - 20px);
    }
}

@media (max-width: 380px) {
    .filter-chip {
        padding: 6px 10px;
        font-size: 12px;
    }
}

/* ============ DARK MODE ============ */
body.dark {
    --bg: #1a1a2e;
    --surface: #16213e;
    --text: #e8e8e8;
    --text-secondary: #a0a0b0;
    --text-light: #707080;
    --border: #2a2a4a;
    --primary-light: #0a3d2a;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    background: #0f0f23;
}

body.dark .app-header { border-color: var(--border); }
body.dark .search-container { border-color: var(--border); }
body.dark .filter-container { border-color: var(--border); }
body.dark .search-box { background: rgba(255,255,255,0.05); }
body.dark .search-box input { color: #e8e8e8; }
body.dark .filter-chip { border-color: var(--border); color: #a0a0b0; }
body.dark .filter-chip.active { color: white; }
body.dark .filter-chip:not(.active) { background: var(--surface); }
body.dark .bottom-panel { box-shadow: 0 -4px 20px rgba(0,0,0,0.4); }
body.dark .station-card { background: rgba(255,255,255,0.03); }
body.dark .station-card:hover { background: rgba(255,255,255,0.06); }
body.dark .detail-stat-card { background: rgba(255,255,255,0.05); }
body.dark .icon-btn { color: #a0a0b0; }
body.dark .icon-btn:hover { background: rgba(255,255,255,0.1); }
body.dark .search-result-item:hover { background: rgba(255,255,255,0.05); }
body.dark .clear-btn { background: rgba(255,255,255,0.1); color: #a0a0b0; }
body.dark .modal-overlay { background: rgba(0,0,0,0.7); }
body.dark .modal-close { background: rgba(255,255,255,0.1); }
body.dark .detail-info-row { border-color: var(--border); }
body.dark .leaflet-control-zoom a { background: #1a1a2e !important; color: #e8e8e8 !important; border-color: #2a2a4a !important; }
body.dark .leaflet-control-zoom a:hover { background: #2a2a4a !important; }
body.dark .leaflet-control-attribution { background: rgba(26,26,46,0.8) !important; color: #888 !important; }
body.dark .leaflet-control-attribution a { color: #aaa !important; }
body.dark .leaflet-popup-content-wrapper { background: #16213e; color: #e8e8e8; box-shadow: 0 4px 24px rgba(0,0,0,0.5); }
body.dark .leaflet-popup-tip { background: #16213e; }
body.dark .leaflet-popup-close-button { color: #aaa !important; }
body.dark .leaflet-popup-close-button:hover { color: #fff !important; }
body.dark .popup-content h4 { color: #e8e8e8; }
body.dark .popup-content .popup-addr { color: #a0a0b0; }
body.dark .panel-handle { background: #555; }
body.dark .station-count { background: rgba(0,168,89,0.2); }
body.dark .gps-prompt-content { background: #16213e; color: #e8e8e8; }
body.dark .map-container { background: #0f0f23; }
