* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --green: #22c55e;
    --yellow: #f59e0b;
    --red: #ef4444;
    --blue: #3b82f6;
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
header {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    flex-shrink: 0;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mode-tabs {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.mode-tab {
    flex: 1;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-tab.active {
    background: var(--yellow);
    color: var(--bg);
    border-color: var(--yellow);
    font-weight: 600;
}

.search-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.route-inputs {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.route-go-btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: none;
    background: var(--yellow);
    color: var(--bg);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    align-self: flex-end;
}

.route-clear-btn {
    padding: 8px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    align-self: flex-end;
}

.search-box {
    flex: 1;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 8px 32px 8px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    outline: none;
}

.search-box input:focus {
    border-color: var(--yellow);
}

.search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
}

.radius-selector select {
    padding: 8px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1001;
    display: none;
}

.search-result-item {
    padding: 10px 12px;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

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

.search-result-item:active {
    background: var(--bg);
}

header h1 {
    font-size: 18px;
    font-weight: 700;
}

header h1 span {
    color: var(--yellow);
}

/* Fuel type selector */
.fuel-selector {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.fuel-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
}

.fuel-btn.active {
    background: var(--yellow);
    color: var(--bg);
    border-color: var(--yellow);
    font-weight: 600;
}

/* Map */
#map {
    flex: 1;
    z-index: 1;
}

/* Station list panel */
.panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    z-index: 1000;
    transition: transform 0.3s ease;
    max-height: 60dvh;
    display: flex;
    flex-direction: column;
}

.panel.collapsed {
    transform: translateY(calc(100% - 48px));
}

.panel-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    user-select: none;
}

.panel-toggle:hover {
    background: rgba(255,255,255,0.03);
}

.panel-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 8px auto 0;
    flex-shrink: 0;
}

.panel-header {
    padding: 4px 16px 8px;
    font-size: 14px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.panel-chevron {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 12px;
    transition: transform 0.3s;
}

.panel.collapsed .panel-chevron {
    transform: translateY(-50%) rotate(180deg);
}

.station-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 12px 12px;
    flex: 1;
}

.station-card {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 6px;
    background: var(--bg);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
}

.station-card:active {
    background: #263248;
}

.station-price {
    font-size: 22px;
    font-weight: 700;
    min-width: 72px;
    text-align: center;
}

.station-price.cheapest { color: var(--blue); font-weight: 800; }
.station-price.cheap { color: var(--green); }
.station-price.mid { color: var(--yellow); }
.station-price.expensive { color: var(--red); }

.station-card.cheapest-card {
    border: 1px solid var(--blue);
    background: rgba(59, 130, 246, 0.1);
}

.cheapest-badge {
    font-size: 10px;
    font-weight: 700;
    color: var(--blue);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.station-info {
    flex: 1;
    margin-left: 12px;
    min-width: 0;
}

.station-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.station-address {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.station-distance {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 48px;
    text-align: right;
}

/* Station detail overlay */
.detail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 2000;
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.detail-overlay.active {
    display: flex;
}

.detail-card {
    background: var(--surface);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 80dvh;
    overflow-y: auto;
    padding: 20px;
}

.detail-card h2 {
    font-size: 20px;
    margin-bottom: 4px;
}

.detail-card .address {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 16px;
}

.detail-card .schedule {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.price-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.price-row:last-child {
    border-bottom: none;
}

.price-label {
    font-size: 14px;
}

.price-updated {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.price-value {
    font-size: 20px;
    font-weight: 700;
}

.detail-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    color: var(--text-muted);
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    margin-left: 8px;
    border: 2px solid var(--border);
    border-top-color: var(--yellow);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Locate me button */
.locate-btn {
    position: fixed;
    right: 12px;
    bottom: calc(60dvh + 12px);
    z-index: 999;
    height: 40px;
    border-radius: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px 0 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    white-space: nowrap;
}

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

.locate-btn::after {
    content: 'Mi ubicación';
}

.panel.collapsed ~ .locate-btn {
    bottom: 60px;
}

/* On mobile, icon only */
@media (max-width: 600px) {
    .locate-btn {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        padding: 0;
        justify-content: center;
    }
    .locate-btn::after {
        content: none;
    }
}

/* PWA install prompt */
@media (display-mode: standalone) {
    header { padding-top: env(safe-area-inset-top, 8px); }
}
