:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --border: #e3e5e9;
  --border-strong: #d3d6dc;
  --text: #1c1e21;
  --text-muted: #6b7280;
  --text-faint: #9aa0a9;

  --primary: #4f46e5;
  --primary-hover: #4338ca;

  --success: #16a34a;
  --danger: #dc2626;
  --danger-light: #fdecec;
  --danger-hover: #b91c1c;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(20, 21, 26, .06), 0 6px 16px -8px rgba(20, 21, 26, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 720px; margin: 0 auto; padding: 32px 20px 60px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.01em; }
.page-head .sub { margin: 0; color: var(--text-muted); font-size: 13px; }
.head-text { min-width: 0; }

.controls { display: flex; gap: 8px; align-items: center; }

#search {
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13.5px;
  width: 200px;
}
#search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

.btn {
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-2); border-color: #b8bcc4; }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn:disabled:hover { background: var(--surface); border-color: var(--border-strong); }
.btn:disabled:active { transform: none; }

/* No display rule on .picker, and an explicit [hidden] guard: an author `display` would
   otherwise beat the UA [hidden] rule (the .region-rail { display:flex } trap). */
.picker[hidden] { display: none; }

.modebar {
  display: inline-flex;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 12px;
}
.mode-btn {
  font-family: var(--font);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 550;
  padding: 7px 15px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active { background: var(--primary); color: #fff; }

.seg {
  display: inline-flex;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 8px;
}
.seg-btn {
  font-family: var(--font);
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 550;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--primary); color: #fff; }
.seg-btn.active .seg-count { color: rgba(255, 255, 255, .8); }
.seg-count { font-size: 10.5px; font-weight: 500; color: var(--text-faint); }

.region-rail {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.region-rail:empty { display: none; }
.region-chip {
  font-family: var(--font);
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  line-height: 1.3;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  text-align: left;
}
.region-chip:hover { background: var(--surface-2); }
.region-chip .city {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}
.region-chip.active .city { color: rgba(255, 255, 255, .85); }
.region-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
/* Compact variant for the chip-code group keys (name + count on one line). */
.region-chip.compact {
  flex-direction: row;
  align-items: baseline;
  gap: 7px;
  padding: 5px 12px;
  font-size: 12px;
}
.region-chip.compact .city { font-size: 10.5px; }
.region-chip.compact.active .city { color: rgba(255, 255, 255, .8); }

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(22, 163, 74, .5);
  animation: pulse 1.6s infinite;
}
.dot.stale { background: var(--danger); animation: none; box-shadow: none; }
/* chip database is not polled — keep the indicator steady */
.dot.static { animation: none; box-shadow: none; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(22, 163, 74, .45); }
  70%  { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

.error-box {
  display: none;
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-light);
  color: var(--danger-hover);
  font-size: 13px;
}

.notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.notice[hidden] { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); }
th {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 650;
  background: var(--surface-2);
}
th.right, td.right { text-align: right; }
tr:last-child td { border-bottom: none; }
td.amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.price-note {
  margin-left: 6px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
}
tr.divider td { padding: 0; border-bottom: none; height: 10px; background: transparent; }
.empty { color: var(--text-faint); font-size: 13px; padding: 20px 16px; }

/* chip database rows */
tr.row-head td {
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  padding: 8px 16px;
}
.sec-count {
  margin-left: 8px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-faint);
}
td.code { overflow-wrap: anywhere; }
.code-btn {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--text);
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
}
.code-btn:hover { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
.code-btn.copied { color: var(--success); }
.code-btn.copied::after {
  content: "✓ copied";
  margin-left: 6px;
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 600;
}
td.brand { color: var(--text-muted); font-size: 12.5px; }

@media (max-width: 520px) {
  .wrap { padding: 22px 14px 44px; }
  .page-head { align-items: flex-start; }
  .controls { width: 100%; }
  #search { flex: 1; width: auto; min-width: 0; }
  th, td { padding: 11px 12px; }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #141414;
  --border: #262626;
  --border-strong: #383838;
  --text: #f2f2f2;
  --text-muted: #9a9a9a;
  --text-faint: #6b6b6b;
  --danger-light: #2a0f10;
}
