* { margin: 0; padding: 0; box-sizing: border-box; }
@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600&display=swap');

:root {
  --bg: #faf9f6; --surface: #fff; --surface2: #f5f3ef;
  --border: #e8e5de; --border-light: #f0ede6;
  --text: #1a1a1a; --text-muted: #6b6560; --text-dim: #a39e96;
  --accent: #c4520a; --accent-light: #fff3eb;
  --up: #c4520a; --down: #1a7a4c;
  --radius: 10px; --serif: 'Instrument Serif', Georgia, serif;
  --sans: 'DM Sans', -apple-system, sans-serif;
  --chart-grid: #f0ede6;
}

[data-theme="dark"] {
  --bg: #0e0e0e; --surface: #171717; --surface2: #1e1e1e;
  --border: #2a2a2a; --border-light: #222;
  --text: #e5e5e5; --text-muted: #8a8580; --text-dim: #5a5550;
  --accent: #e8762a; --accent-light: rgba(232,118,42,0.1);
  --up: #e87e4a; --down: #3ecf8e; --chart-grid: #222;
}

/* ─── Loading screen ──────────────────────────────── */

.loading-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 60vh; gap: 12px;
}
.loading-spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loading-text { font-size: 13px; color: var(--text-muted); }
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px;
  padding: 12px 16px; margin-bottom: 16px; display: flex;
  align-items: center; justify-content: space-between; gap: 12px;
  font-size: 13px; color: #991b1b;
}
.error-banner button {
  background: #991b1b; color: #fff; border: none; border-radius: 6px;
  padding: 6px 14px; cursor: pointer; font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
[data-theme="dark"] .error-banner { background: #2d1b1b; border-color: #5c2020; color: #fca5a5; }
[data-theme="dark"] .error-banner button { background: #7f1d1d; }

body {
  font-family: var(--sans); background: var(--bg); color: var(--text);
  min-height: 100dvh; -webkit-font-smoothing: antialiased;
}
.container { max-width: 720px; margin: 0 auto; padding: 0 20px; }

/* ─── Header ──────────────────────────────────────── */

.header {
  padding: 20px 0 0; display: flex; align-items: center; justify-content: space-between;
}
.header .logo {
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  text-decoration: none; letter-spacing: 0.06em; text-transform: uppercase;
}
.theme-btn {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 10px; cursor: pointer; font-size: 13px; line-height: 1;
}

/* ─── Hero ────────────────────────────────────────── */

.hero { padding: 28px 0 20px; border-bottom: 1px solid var(--border); }
.hero-eyebrow {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim); margin-bottom: 6px;
}
.hero-headline {
  font-family: var(--serif); font-size: 34px; line-height: 1.1;
  color: var(--text); margin-bottom: 6px; font-weight: 400;
}
.hero-sub { font-size: 14px; color: var(--text-muted); line-height: 1.5; }

.stat-row {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 1px; margin-top: 20px;
  background: var(--border); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.stat-card { background: var(--surface); padding: 14px; text-align: center; }
.stat-value { font-family: var(--serif); font-size: 26px; color: var(--text); line-height: 1.2; }
.stat-value.big { font-size: 30px; }
.stat-value.accent { color: var(--accent); }
.stat-unit { font-size: 11px; color: var(--text-dim); }
.stat-label { font-size: 10px; color: var(--text-dim); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ─── Section shared ──────────────────────────────── */

.section { padding: 20px 0; border-bottom: 1px solid var(--border); }
.section-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.section-title { font-family: var(--serif); font-size: 18px; color: var(--text); font-weight: 400; }
.section-sub { font-size: 11px; color: var(--text-dim); }

/* ─── Purchasing power ────────────────────────────── */

.pp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.pp-card {
  background: var(--surface); border: 1px solid var(--border-light);
  border-radius: 8px; padding: 12px; text-align: center;
}
.pp-emoji { font-size: 24px; margin-bottom: 4px; }
.pp-name { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.pp-now { font-family: var(--serif); font-size: 22px; color: var(--text); }
.pp-history {
  display: flex; flex-direction: column; gap: 1px;
  margin-top: 6px; font-size: 10px; color: var(--text-dim);
}
.pp-history .current { color: var(--accent); font-weight: 600; }
.pp-lost {
  margin-top: 4px; font-size: 10px; font-weight: 600; color: var(--up);
  background: var(--accent-light); border-radius: 4px; padding: 2px 6px;
  display: inline-block;
}

/* ─── City comparison ─────────────────────────────── */

.city-compare { margin-top: 16px; }
.cc-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px; }

.cc-row { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 12px; }
.cc-city { width: 80px; color: var(--text-muted); font-size: 11px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-city.hl { color: var(--text); font-weight: 600; }
.cc-bar-wrap { flex: 1; height: 14px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.cc-bar { height: 100%; background: var(--text-dim); border-radius: 3px; transition: width 0.4s; }
.cc-bar.hl { background: var(--accent); }
.cc-val { min-width: 40px; text-align: right; font-weight: 600; color: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.cc-val.hl { color: var(--accent); }

/* ─── Country comparison ──────────────────────────── */

.country-grid { display: flex; flex-direction: column; gap: 5px; }

.country-row {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
  padding: 4px 0;
}
.country-flag { font-size: 16px; width: 22px; text-align: center; }
.country-name { width: 100px; color: var(--text-muted); font-size: 12px; }
.country-name.highlight { color: var(--text); font-weight: 600; }
.country-bar-wrap {
  flex: 1; height: 16px; background: var(--surface2); border-radius: 4px; overflow: hidden;
}
.country-bar {
  height: 100%; background: var(--text-dim); border-radius: 4px;
  transition: width 0.5s ease;
}
.country-bar.highlight { background: var(--accent); }
.country-val {
  min-width: 42px; text-align: right; font-size: 12px; font-weight: 600;
  color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.country-val.highlight { color: var(--accent); }

.country-food-sub {
  margin-top: 10px; font-size: 11px; color: var(--text-dim);
  padding: 8px 12px; background: var(--surface2); border-radius: 6px;
}
.country-food-label { font-weight: 600; }

/* ─── Movers ──────────────────────────────────────── */

.movers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.movers-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px; }

.mover-row {
  display: flex; align-items: baseline; gap: 6px;
  padding: 5px 0; border-bottom: 1px solid var(--border-light); font-size: 13px;
}
.mover-name { flex: 1; color: var(--text); }
.mover-price { color: var(--text-dim); font-size: 11px; }
.mover-change { font-weight: 600; font-size: 12px; min-width: 50px; text-align: right; font-variant-numeric: tabular-nums; }
.mover-change.up { color: var(--up); }
.mover-change.down { color: var(--down); }

/* ─── City bar ────────────────────────────────────── */

.city-bar { padding: 16px 0 4px; }
.city-scroll { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.city-scroll::-webkit-scrollbar { display: none; }

.city-btn {
  background: transparent; border: 1px solid var(--border); border-radius: 20px;
  padding: 5px 14px; color: var(--text-muted); font-size: 12px; font-weight: 500;
  cursor: pointer; font-family: var(--sans); white-space: nowrap; transition: all 0.15s;
}
.city-btn:hover { border-color: var(--text-dim); }
.city-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-light); font-weight: 600; }

/* ─── Basket ──────────────────────────────────────── */

.basket-list { display: flex; flex-direction: column; gap: 2px; }

.basket-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px;
  cursor: pointer; transition: background 0.1s;
}
.basket-item:hover { background: var(--surface2); }
.basket-item.active { background: var(--accent-light); }

.bi-emoji {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--surface2); display: flex; align-items: center;
  justify-content: center; font-size: 18px; flex-shrink: 0;
}
.bi-body { flex: 1; min-width: 0; }
.bi-name { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bi-row { display: flex; align-items: baseline; gap: 4px; }
.bi-price { font-family: var(--serif); font-size: 20px; color: var(--text); }
.bi-unit { font-size: 10px; color: var(--text-dim); }
.bi-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.bi-change { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bi-change.up { color: var(--up); }
.bi-change.down { color: var(--down); }
.bi-spark { height: 20px; width: 56px; }

/* ─── Charts ──────────────────────────────────────── */

.chart-box {
  background: var(--surface); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 10px;
}
.chart-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.chart-title { font-family: var(--serif); font-size: 16px; color: var(--text); }
.chart-sub { font-size: 11px; color: var(--text-dim); }

/* ─── All products table ──────────────────────────── */

.product-search-wrap { margin-bottom: 10px; }
.product-search {
  width: 100%; padding: 8px 12px; font-size: 13px; font-family: var(--sans);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); outline: none;
}
.product-search::placeholder { color: var(--text-dim); }
.product-search:focus { border-color: var(--accent); }

.products-list { border: 1px solid var(--border-light); border-radius: 8px; overflow: hidden; }

.product-row {
  display: grid; grid-template-columns: 1fr 64px 48px 56px;
  gap: 4px; padding: 7px 12px; font-size: 12px;
  border-bottom: 1px solid var(--border-light);
  align-items: center;
}
.product-row:last-child { border-bottom: none; }
.product-row:hover { background: var(--surface2); }
.product-row.header {
  font-weight: 600; color: var(--text-dim); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--surface2); position: sticky; top: 0; z-index: 1;
}
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--accent); }

.pr-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.pr-price { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.pr-unit { text-align: center; color: var(--text-dim); font-size: 11px; }
.pr-change { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; font-size: 11px; }
.pr-change.up { color: var(--up); }
.pr-change.down { color: var(--down); }

/* ─── Footer ──────────────────────────────────────── */

.footer {
  padding: 24px 0 40px; font-size: 11px; color: var(--text-dim);
  text-align: center;
}
.footer a { color: var(--text-muted); text-decoration: none; }

/* ─── Responsive ──────────────────────────────────── */

@media (max-width: 640px) {
  .hero-headline { font-size: 24px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .movers-grid { grid-template-columns: 1fr; }
  .pp-grid { grid-template-columns: repeat(2, 1fr); }
}
