:root {
  --canvas: #0c0e11;
  --panel: #13161b;
  --panel-raised: #1a1e24;
  --hairline: rgba(255, 255, 255, 0.075);
  --text-primary: #eceef1;
  --text-secondary: #8b929c;
  --text-tertiary: #5a616b;
  --signal: #d4ff3a;
  --cheap: #45e6a4;
  --mid: #f2c14e;
  --dear: #ff6a4d;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--text-primary);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }
#app { display: flex; flex-direction: column; height: 100vh; }

/* Topbar */
.topbar {
  height: 52px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--hairline);
  background: var(--canvas);
  z-index: 40;
}

.wordmark { display: flex; align-items: center; gap: 9px; font-size: 12px; font-weight: 800; letter-spacing: 0.08em; }
.wordmark-badge {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--signal); color: var(--canvas);
  display: grid; place-items: center;
}

.search-wrap {
  position: relative;
  width: min(380px, 42vw);
  height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 12px;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: 9px;
  transition: border-color .15s;
}
.search-wrap:focus-within { border-color: rgba(212, 255, 58, 0.55); }
.search-icon { color: var(--text-secondary); flex-shrink: 0; }
.search-wrap:focus-within .search-icon { color: var(--signal); }
.search-wrap input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  color: var(--text-primary); font-size: 13px; font-weight: 500; font-family: inherit;
}
.search-wrap input::placeholder { color: var(--text-secondary); }
.icon-btn {
  width: 24px; height: 24px; border: 0; background: transparent; color: var(--text-secondary);
  border-radius: 6px; cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }
.search-error {
  position: absolute; left: 0; top: 36px;
  font-size: 11px; font-weight: 500; color: var(--dear);
  background: var(--panel); padding: 4px 8px; border-radius: 6px; border: 1px solid var(--hairline);
  white-space: nowrap;
}

.refresh-cluster { display: flex; align-items: center; gap: 10px; }
.sources-wrap { position: relative; }
.sources-trigger {
  display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--text-secondary); font-size: 11.5px; font-weight: 500; cursor: pointer;
}
.sources-trigger:hover { background: var(--panel); border-color: var(--hairline); }
.source-dots { display: flex; gap: 4px; align-items: center; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-tertiary); }
.dot.ok { background: var(--cheap); }
.dot.loading { background: var(--mid); }
.dot.failed { background: var(--dear); }
.dot.needs_key { background: rgba(90, 97, 107, 0.55); }

.sources-popover {
  position: absolute; right: 0; top: 38px; width: 340px;
  background: rgba(19, 22, 27, 0.96); backdrop-filter: blur(18px);
  border: 1px solid var(--hairline); border-radius: 14px;
  padding: 14px 16px; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55); z-index: 60;
}
.eyebrow {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase;
  color: var(--text-tertiary);
}
.pop-row { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--hairline); }
.pop-row:last-of-type { border-bottom: 0; }
.pop-title { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.pop-sub { font-size: 10.5px; color: var(--text-secondary); margin-top: 2px; }
.pop-state { font-size: 10.5px; font-weight: 500; margin-top: 2px; }
.pop-state.ok { color: var(--cheap); }
.pop-state.failed { color: var(--dear); }
.pop-state.needs_key, .pop-state.idle { color: var(--text-tertiary); }

.refresh-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 14px;
  border: 0; border-radius: 999px; background: var(--signal); color: var(--canvas);
  font-size: 12px; font-weight: 700; cursor: pointer; transition: opacity .15s, transform .1s;
}
.refresh-btn:hover { opacity: 0.92; }
.refresh-btn:active { transform: scale(0.98); }
.refresh-btn:disabled { opacity: 0.65; cursor: wait; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Roadside Fuel Board */
.fuel-board {
  height: 76px;
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--hairline);
  background: var(--canvas);
  overflow-x: auto;
}
.fuel-tile {
  position: relative; width: 152px; flex-shrink: 0;
  padding: 0 14px 0 22px; border: 0; background: transparent;
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 4px;
  cursor: pointer; text-align: left;
  border-right: 1px solid var(--hairline);
}
.fuel-tile:hover { background: rgba(255, 255, 255, 0.02); }
.fuel-tile.active::after {
  content: ""; position: absolute; left: 22px; right: 10px; bottom: 0; height: 2px; background: var(--signal);
}
.fuel-head { display: flex; align-items: baseline; gap: 6px; }
.fuel-short { font-size: 12px; font-weight: 800; letter-spacing: 0.03em; color: var(--text-secondary); }
.fuel-tile.active .fuel-short { color: var(--signal); }
.fuel-long { font-size: 9px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-tertiary); }
.fuel-price { font-family: var(--mono); font-size: 24px; font-weight: 600; color: var(--text-secondary); line-height: 1; }
.fuel-tile.active .fuel-price { color: var(--text-primary); }
.fuel-unit { font-family: var(--sans); font-size: 11px; color: var(--text-tertiary); margin-left: 2px; }

.board-summary {
  margin-left: auto; padding: 0 22px;
  display: flex; align-items: center; gap: 26px; flex-shrink: 0;
}
.sum-item { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.sum-val { font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--text-primary); }
.sum-val.sans { font-family: var(--sans); }

/* Workspace */
.workspace { flex: 1; min-height: 0; display: flex; }

.list-panel {
  width: 405px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column; min-height: 0;
}
.list-header { padding: 15px 18px 13px; border-bottom: 1px solid var(--hairline); display: flex; flex-direction: column; gap: 11px; }
.list-title-row { display: flex; align-items: baseline; justify-content: space-between; }
.count-num { font-family: var(--mono); font-size: 20px; font-weight: 600; }
.count-word { font-size: 12px; color: var(--text-secondary); margin-left: 5px; }
.brand-select {
  background: transparent; border: 0; color: var(--text-secondary);
  font-size: 11.5px; font-weight: 600; cursor: pointer; outline: 0; text-align: right;
}
.brand-select.filtered { color: var(--signal); }
.brand-select option { background: var(--panel); color: var(--text-primary); }

.controls-row { display: flex; justify-content: space-between; gap: 8px; }
.seg {
  display: inline-flex; gap: 2px; padding: 2px;
  background: var(--canvas); border: 1px solid var(--hairline); border-radius: 8px;
}
.seg-btn {
  border: 0; background: transparent; color: var(--text-secondary);
  font-size: 11px; font-weight: 500; padding: 0 9px; height: 22px; border-radius: 6px; cursor: pointer;
}
.seg-btn.active { background: var(--text-primary); color: var(--canvas); font-weight: 600; }

.station-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.station-list::-webkit-scrollbar { width: 6px; }
.station-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

.st-row {
  position: relative; width: 100%; border: 0; background: transparent; color: inherit;
  display: flex; align-items: center; gap: 12px; padding: 10px 18px;
  cursor: pointer; text-align: left; transition: background .12s;
}
.st-row:hover { background: rgba(26, 30, 36, 0.55); }
.st-row.selected { background: var(--panel-raised); }
.st-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 2.5px; }
.st-rank { font-family: var(--mono); font-size: 10px; color: var(--text-tertiary); width: 18px; flex-shrink: 0; }
.st-row.selected .st-rank { color: var(--signal); }

.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
  font-size: 12px; font-weight: 800; letter-spacing: 0.02em;
}
.brand-mark.has-img { background: #fff; padding: 3px; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; border-radius: 6px; }
.brand-mark.lg { width: 42px; height: 42px; border-radius: 11px; font-size: 14px; }

.st-info { flex: 1; min-width: 0; }
.st-name { font-size: 12.5px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-sub { font-size: 11px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.st-right { text-align: right; flex-shrink: 0; }
.st-price { font-family: var(--mono); font-size: 17px; font-weight: 600; color: var(--text-primary); }
.move { font-family: var(--mono); font-size: 10px; font-weight: 500; margin-top: 2px; }
.move.up { color: var(--dear); }
.move.down { color: var(--cheap); }
.move.flat, .move.unknown { color: var(--text-tertiary); }

.empty-state {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px; text-align: center; gap: 12px;
}
.empty-title { font-size: 14px; font-weight: 600; }
.empty-copy { font-size: 11.5px; color: var(--text-secondary); line-height: 1.5; max-width: 290px; }
.city-pills { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 4px; }
.city-pill {
  height: 25px; padding: 0 11px; border-radius: 999px;
  background: var(--panel-raised); border: 1px solid var(--hairline);
  color: var(--text-primary); font-size: 11px; font-weight: 600; cursor: pointer;
}
.city-pill:hover { border-color: var(--signal); color: var(--signal); }

/* Map + Floating Insight Panel */
.map-stage { position: relative; flex: 1; min-width: 0; background: #090b0e; }
#map { width: 100%; height: 100%; background: #090b0e; }
.leaflet-container { background: #090b0e; font-family: var(--sans); }
.leaflet-control-attribution { background: rgba(12,14,17,0.75) !important; color: var(--text-tertiary) !important; font-size: 9.5px !important; }
.leaflet-control-attribution a { color: var(--text-secondary) !important; }

.price-pin {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px 0 6px; border-radius: 999px;
  background: rgba(12, 14, 17, 0.92); color: var(--text-primary);
  border: 1px solid rgba(255,255,255,0.2);
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  box-shadow: 0 4px 10px rgba(0,0,0,0.45);
  white-space: nowrap; transform: translate(-50%, -100%);
}
.price-pin.selected {
  height: 27px; padding: 0 9px; background: var(--signal); color: var(--canvas);
  border-color: transparent; font-size: 12.5px; z-index: 900;
}
.pin-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.center-pulse {
  width: 12px; height: 12px; border-radius: 50%; background: var(--signal);
  border: 2px solid var(--canvas); box-shadow: 0 0 0 6px rgba(212, 255, 58, 0.22);
}

.insight-panel {
  position: absolute; left: 18px; right: 18px; bottom: 18px;
  max-width: 940px; height: 236px; margin: 0 auto; z-index: 500;
  background: rgba(15, 18, 23, 0.84); backdrop-filter: blur(22px);
  border: 1px solid rgba(255,255,255,0.08); border-radius: 20px;
  padding: 18px 20px; box-shadow: 0 18px 46px rgba(0,0,0,0.5);
  display: flex; gap: 24px;
}
.insight-left { width: 260px; flex-shrink: 0; display: flex; flex-direction: column; }
.insight-delta { font-family: var(--mono); font-size: 30px; font-weight: 600; margin-top: 8px; }
.insight-verdict { font-size: 11.5px; color: var(--text-secondary); line-height: 1.45; margin-top: 6px; }
.insight-stats { margin-top: auto; display: flex; gap: 18px; }
.stat-val { font-family: var(--mono); font-size: 14px; font-weight: 600; margin-top: 3px; }
.insight-right { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.insight-right-head { display: flex; justify-content: space-between; align-items: center; }
.chart-wrap { flex: 1; min-height: 0; position: relative; }
.chart-empty {
  height: 100%; border: 1px dashed var(--hairline); border-radius: 12px;
  display: grid; place-items: center; color: var(--text-tertiary); font-size: 11.5px; text-align: center; padding: 12px;
}

.st-detail-top { display: flex; align-items: center; gap: 11px; }
.close-btn {
  margin-left: auto; width: 24px; height: 24px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,0.07); color: var(--text-secondary); cursor: pointer; font-weight: 700;
}
.st-detail-price-row { display: flex; align-items: baseline; justify-content: space-between; margin-top: 10px; }
.st-detail-price { font-family: var(--mono); font-size: 32px; font-weight: 600; }
.st-detail-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dir-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 10px;
  border-radius: 999px; background: var(--signal); color: var(--canvas);
  font-size: 11px; font-weight: 700; text-decoration: none;
}

@media (max-width: 960px) {
  .workspace { flex-direction: column; }
  .list-panel { width: 100%; height: 42vh; border-right: 0; border-bottom: 1px solid var(--hairline); }
  .insight-panel { flex-direction: column; height: auto; max-height: 260px; }
  .insight-left { width: 100%; }
  .board-summary { display: none; }
}
