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

:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #253349;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #38bdf8;
    --primary-dim: #0c4a6e;
    --green: #4ade80;
    --green-dim: #052e16;
    --red: #f87171;
    --red-dim: #450a0a;
    --amber: #fbbf24;
    --radius: 12px;
    --radius-sm: 8px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

body {
    min-height: 100dvh;
    padding-bottom: calc(16px + var(--safe-bottom));
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 600px;
    margin: 0 auto;
}

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

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--primary);
    flex-shrink: 0;
}

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

.subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

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

/* ── Main ────────────────────────────────────────────────────────────────── */
main {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 12px;
}

/* ── Tab navigation ──────────────────────────────────────────────────────── */
.tab-nav {
    display: flex;
    gap: 4px;
    padding: 12px 0 8px;
    position: sticky;
    top: 57px;
    z-index: 50;
    background: var(--bg);
}

.tab {
    flex: 1;
    padding: 10px 0;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.tab.active {
    background: var(--primary-dim);
    border-color: var(--primary);
    color: var(--primary);
}

.tab:active {
    transform: scale(0.97);
}

.tab-content { display: none; padding: 8px 0 16px; }
.tab-content.active { display: block; }

/* ── Price cards ─────────────────────────────────────────────────────────── */
.price-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.station-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: border-color 0.2s;
}

.station-card:active {
    border-color: var(--primary);
}

.station-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.station-name {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
}

.station-brand {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.brand-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 6px;
    background: var(--primary-dim);
    color: var(--primary);
    white-space: nowrap;
}

.fuel-prices {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
}

.fuel-item {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    padding: 10px;
    text-align: center;
}

.fuel-type {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.fuel-price {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.fuel-price .unit {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
}

.fuel-item.cheapest {
    background: var(--green-dim);
    border: 1px solid rgba(74, 222, 128, 0.3);
}

.fuel-item.cheapest .fuel-price {
    color: var(--green);
}

.last-updated {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    padding: 12px 0;
}

/* ── Compare tab ─────────────────────────────────────────────────────────── */
.filter-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.select-input {
    flex: 1;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
}

.compare-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.compare-row {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    gap: 12px;
}

.compare-rank {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
}

.rank-1 { background: var(--green-dim); color: var(--green); }
.rank-2 { background: var(--primary-dim); color: var(--primary); }
.rank-3 { background: var(--surface-hover); color: var(--text-muted); }

.compare-info { flex: 1; min-width: 0; }

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

.compare-updated {
    font-size: 11px;
    color: var(--text-muted);
}

.compare-price {
    font-size: 20px;
    font-weight: 700;
    flex-shrink: 0;
}

.compare-diff {
    font-size: 12px;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

.diff-cheapest {
    background: var(--green-dim);
    color: var(--green);
}

.diff-more {
    background: var(--red-dim);
    color: var(--red);
}

/* ── History tab ─────────────────────────────────────────────────────────── */
.chart-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
    position: relative;
    height: 260px;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.stats-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.stat-station {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

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

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 18px;
    font-weight: 700;
    margin-top: 2px;
}

.stat-value.low { color: var(--green); }
.stat-value.avg { color: var(--amber); }
.stat-value.high { color: var(--red); }

/* ── Loading state ───────────────────────────────────────────────────────── */
.loading-state {
    text-align: center;
    padding: 40px 0;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 13px;
}

/* ── Responsive tweaks ───────────────────────────────────────────────────── */
@media (min-width: 480px) {
    .fuel-prices {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (prefers-color-scheme: light) {
    /* Override if user wants light mode (optional future support) */
}
