:root {
  --primary: #16a34a;
  --primary-light: #dcfce7;
  --primary-dark: #15803d;
  --secondary: #2563eb;
  --bg: #f3f4f6;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --gazole: #d97706;
  --sp95: #2563eb;
  --sp98: #7c3aed;
  --e10: #0891b2;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --tab-h: 68px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --card: #1e293b;
    --border: #334155;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --primary-light: #052e16;
    --shadow: 0 1px 3px rgba(0,0,0,.3);
  }
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: var(--tab-h);
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.app-title { font-size: 1.1rem; font-weight: 700; }

.origin-select {
  font-size: .8rem;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  max-width: 160px;
}

/* ── Tab bar ── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  height: var(--tab-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px 8px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 500;
  gap: 2px;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn .icon { font-size: 1.5rem; line-height: 1; }
.tab-btn.active { color: var(--primary); }

/* ── Views ── */
.view { display: none; padding: 12px 16px 4px; }
.view.active { display: block; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.filter-row { display: flex; gap: 6px; flex-wrap: wrap; }

.filter-group {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
}

.filter-btn {
  border: none;
  background: none;
  padding: 7px 13px;
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
}

/* ── Search row ── */
.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.search-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: .9rem;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { outline: none; border-color: var(--primary); }

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { background: var(--primary-dark); }
.btn-icon {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:disabled { opacity: .4; }
.btn-icon.spinning { animation: spin .7s linear infinite; display: inline-block; }

/* ── Status bar ── */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: .75rem;
  color: var(--muted);
}

/* ── Loading ── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 20px;
  gap: 14px;
  color: var(--muted);
}
.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; }

/* ── Station cards ── */
.station-list { display: flex; flex-direction: column; gap: 10px; }

.station-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.station-card.is-fav { border-left: 3px solid #f59e0b; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.station-name {
  font-weight: 700;
  font-size: .95rem;
  line-height: 1.3;
}
.station-addr {
  font-size: .78rem;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.4;
}
.distance-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: .7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 4px;
  white-space: nowrap;
}

.card-top-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .68rem;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary);
  white-space: nowrap;
  flex-shrink: 0;
}
.brand-badge.brand-highway {
  background: #fef3c7;
  color: #92400e;
}
.brand-icon {
  font-size: 1rem;
  flex-shrink: 0;
  line-height: 1;
}

.station-card.is-highway {
  border-left: 3px solid #f59e0b;
}

.fav-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  color: var(--muted);
  padding: 2px 4px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.fav-btn.active { color: #f59e0b; }

/* ── Prices grid ── */
.prices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.price-cell {
  background: var(--bg);
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
}
.price-lbl {
  font-size: .65rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 3px;
}
.price-val {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.price-val.gazole { color: var(--gazole); }
.price-val.sp95   { color: var(--sp95); }
.price-val.sp98   { color: var(--sp98); }
.price-val.e10    { color: var(--e10); }
.price-val.na     { color: var(--muted); font-size: .85rem; }

/* ── Card footer ── */
.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-meta { font-size: .72rem; color: var(--muted); }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  background: var(--secondary);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn:active { opacity: .85; }

/* ── Settings ── */
.settings-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}
.settings-title {
  font-size: .72rem;
  color: var(--muted);
  padding: 12px 16px 4px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}
.settings-row {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.settings-row label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.settings-input {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: .9rem;
}
.settings-input:focus { outline: none; border-color: var(--primary); }
.settings-input::placeholder { color: var(--muted); }

.save-btn-row { padding: 0 0 16px; }

/* ── History charts ── */
.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.chart-title {
  font-size: .9rem;
  font-weight: 700;
  margin-bottom: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-svg { width: 100%; display: block; }
.chart-line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-lbl { font-size: 9px; fill: var(--muted); font-family: -apple-system, sans-serif; }
.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: .75rem;
  color: var(--text);
}
.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(var(--tab-h) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #1f2937;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: .85rem;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Section header ── */
.view-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
}

/* ── About ── */
.about-text {
  font-size: .82rem;
  color: var(--muted);
  line-height: 1.6;
}
.about-text strong { color: var(--text); }
