:root {
  --bg: #08080c;
  --bg-2: #0e0e16;
  --panel: #13131e;
  --panel-2: #1a1a28;
  --border: #2a2a40;
  --border-bright: #3d3d5a;
  --text: #e8e8f0;
  --text-dim: #6a6a7e;
  --text-faint: #404054;
  --accent: #ff0040;
  --accent-soft: rgba(255, 0, 64, 0.15);
  --red: #ff0040;
  --red-glow: rgba(255, 0, 64, 0.6);
  --cyan: #00f0ff;
  --cyan-glow: rgba(0, 240, 255, 0.6);
  --green: #00ff88;
  --yellow: #ffea00;
  --blue: #60a5fa;
  --orange: #ff6b00;
  --font-display: 'Bebas Neue', 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', monospace;
  --font-jp: 'Noto Sans JP', 'Noto Sans TC', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
}

/* ===== JDM atmosphere: grid + scanlines ===== */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(42, 42, 64, 0.22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 42, 64, 0.22) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
  mask-image: radial-gradient(ellipse at center top, black 0%, transparent 85%);
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent 0,
    rgba(255, 255, 255, 0.012) 1px,
    transparent 2px,
    transparent 4px
  );
  pointer-events: none;
  z-index: 1;
}
header, nav, section, footer, .modal, .gallery, .compare-bar { position: relative; z-index: 2; }

/* ===== JDM utility classes ===== */
.jp-accent {
  font-family: var(--font-jp);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--text-faint);
  margin-left: 8px;
}
.jp-accent-red  { color: rgba(255, 0, 64, 0.55); }
.jp-accent-cyan { color: rgba(0, 240, 255, 0.5); }

.side-rail {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-jp);
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 8px;
  writing-mode: vertical-rl;
  color: var(--text-faint);
  opacity: 0.4;
  z-index: 1;
  user-select: none;
  pointer-events: none;
}
.side-rail.left  { left: 4px; }
.side-rail.right { right: 4px; }
.side-rail span { color: var(--red); }
@media (max-width: 1200px) { .side-rail { display: none; } }

.stripe {
  position: fixed;
  top: 0;
  right: 32px;
  width: 80px;
  height: 4px;
  background: repeating-linear-gradient(-45deg, var(--red) 0, var(--red) 8px, transparent 8px, transparent 16px);
  z-index: 11;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: linear-gradient(180deg, rgba(255, 0, 64, 0.08) 0%, rgba(19, 19, 30, 0.72) 100%);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar::before {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, var(--red) 0%, transparent 30%, transparent 70%, var(--cyan) 100%);
  opacity: 0.6;
  pointer-events: none;
}
.brand-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: 14px;
  border-left: 3px solid var(--red);
  box-shadow: -3px 0 12px var(--red-glow);
}
.topbar h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 30px;
  letter-spacing: 4px;
  line-height: 1;
  background: linear-gradient(90deg, var(--text) 0%, var(--red) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px var(--red-glow);
}
.brand-sub {
  font-family: var(--font-jp);
  font-weight: 900;
  font-size: 10px;
  letter-spacing: 6px;
  color: var(--text-dim);
}
.topbar-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn-community {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 2px;
  text-decoration: none;
  color: var(--cyan);
  padding: 8px 16px;
  border: 1px solid var(--cyan);
  background: rgba(0, 240, 255, 0.06);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  transition: all .15s;
}
.btn-community:hover {
  background: var(--cyan);
  color: var(--bg);
  box-shadow: 0 0 18px var(--cyan-glow);
}
.btn-community.btn-sell-cta {
  color: var(--yellow);
  border-color: var(--yellow);
  background: rgba(255, 234, 0, 0.06);
}
.btn-community.btn-sell-cta:hover {
  background: var(--yellow);
  color: var(--bg);
  box-shadow: 0 0 18px rgba(255, 234, 0, 0.5);
}
.btn-community.btn-parts-cta {
  color: #c04cff;
  border-color: #c04cff;
  background: rgba(192, 76, 255, 0.06);
}
.btn-community.btn-parts-cta:hover {
  background: #c04cff;
  color: var(--bg);
  box-shadow: 0 0 18px rgba(192, 76, 255, 0.5);
}

/* Global inline icon used inside .btn / .btn-community / .cm-notif-btn etc.
   MUST live globally — without this, browsers render unsized inline SVG at
   the default 300x150 and the icon swallows the whole button. */
.btn-ic {
  display: inline-block;
  width: 16px; height: 16px;
  fill: none !important;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: square;
  stroke-linejoin: miter;
  vertical-align: -3px;
  margin-right: 6px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 4px currentColor);
}
.btn-ic * { vector-effect: non-scaling-stroke; }

/* ====== Landing hero with radar sweep ====== */
.hero {
  position: relative;
  height: 280px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}
.hero[hidden] { display: none; }
.hero-bg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end; padding-right: 40px; opacity: 0.7; pointer-events: none; }
.hero-radar { width: 320px; height: 320px; max-width: 70%; max-height: 90%; }
.hero-sweep { transform-origin: 200px 200px; animation: hero-sweep 4.5s linear infinite; }
@keyframes hero-sweep { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.hero-bg::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at left center, rgba(8,8,12,1) 0%, transparent 80%);
}
.hero-bg::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 50%, var(--bg-2) 100%);
}
.hero-content {
  position: relative; z-index: 2;
  padding: 36px 32px 24px;
  display: flex; flex-direction: column; gap: 6px;
  max-width: 700px;
}
.hero-tag {
  font-family: 'Noto Sans JP', sans-serif;
  font-weight: 900; font-size: 10px; letter-spacing: 6px;
  color: var(--cyan); text-shadow: 0 0 6px var(--cyan-glow);
  padding-bottom: 4px;
  position: relative; padding-left: 14px;
}
.hero-tag::before { content: ''; position: absolute; left: 0; top: 50%; width: 8px; height: 1px; background: var(--cyan); }
.hero-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 64px; letter-spacing: 8px; line-height: 0.9;
  background: linear-gradient(180deg, var(--text) 0%, var(--red) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 40px rgba(255,0,64,.4);
  margin: 0;
  padding-left: 18px; border-left: 3px solid var(--red);
  box-shadow: -3px 0 16px var(--red-glow);
}
.hero-sub {
  font-family: 'Noto Sans TC', sans-serif;
  font-weight: 700; font-size: 14px; letter-spacing: 4px;
  color: var(--text-dim); padding-left: 22px;
}
.hero-stats {
  display: flex; gap: 0; margin-top: 18px;
  padding-left: 22px;
}
.hs-cell {
  padding: 8px 22px 4px 0; margin-right: 22px;
  border-right: 1px solid var(--border);
}
.hs-cell:last-child { border-right: none; margin-right: 0; }
.hs-n {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700; font-size: 22px; letter-spacing: -0.5px;
  color: var(--text); line-height: 1;
}
.hs-l {
  font-family: 'Noto Sans JP', sans-serif;
  font-weight: 900; font-size: 9px; letter-spacing: 3px;
  color: var(--text-faint); margin-top: 4px;
}
@media (max-width: 720px) {
  .hero { height: auto; }
  .hero-title { font-size: 44px; letter-spacing: 4px; }
  .hero-bg { display: none; }
  .hero-content { padding: 24px 20px 18px; }
  .hero-stats { gap: 12px; flex-wrap: wrap; }
}

/* "USER 刊登" badge that appears on radar cards backed by user listings */
.user-listing-badge {
  position: absolute; top: 8px; right: 50px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; letter-spacing: 2px; font-weight: 700;
  background: var(--cyan); color: var(--bg); padding: 3px 8px;
  box-shadow: 0 0 10px var(--cyan-glow); z-index: 3;
}
#currency-select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
}

/* === target picker (collapsible categorized dropdown) === */
.target-bar {
  background: linear-gradient(180deg, rgba(8, 8, 12, 0.72) 0%, rgba(14, 14, 22, 0.78) 100%);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 124px;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 16px;
}
.target-bar::before {
  content: '鎖定車型 ターゲット';
  font-family: var(--font-jp);
  font-weight: 900;
  font-size: 10px;
  letter-spacing: 4px;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan-glow);
  padding-right: 16px;
  border-right: 1px solid var(--border);
  align-self: stretch;
  display: flex;
  align-items: center;
}
.target-bar.hidden-by-tab { display: none; }
.target-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 0;
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 2px;
  font-weight: 400;
  cursor: pointer;
  min-width: 320px;
  text-align: left;
  transition: all .15s;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  box-shadow: none;
}
.target-picker-btn:hover {
  border-color: var(--cyan);
  background: var(--panel-2);
  color: var(--cyan);
  box-shadow: 0 0 18px var(--cyan-glow);
}
.target-picker-label { flex: 1; }
.target-picker-meta { color: var(--text-dim); font-family: var(--font-mono); font-size: 11px; font-weight: 400; letter-spacing: 0; }
.target-picker-arrow {
  color: var(--text-dim);
  font-size: 13px;
  transition: transform .15s;
}
.target-picker-btn[aria-expanded="true"] .target-picker-arrow { transform: rotate(180deg); }

.target-picker-popover {
  position: absolute;
  top: calc(100% - 4px);
  left: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .5);
  width: min(540px, calc(100vw - 48px));
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  z-index: 100;
}
.target-picker-popover[hidden] { display: none; }
#target-picker-search {
  background: var(--bg);
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  font-size: 14px;
  outline: none;
  border-radius: 8px 8px 0 0;
}
#target-picker-search:focus { background: var(--panel-2); }

.target-picker-modes {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.tp-mode {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .5px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-family: inherit;
  transition: color .12s, border-color .12s, background .12s;
}
.tp-mode:hover { color: var(--text); background: var(--panel-2); }
.tp-mode.active {
  color: var(--text);
  border-bottom-color: var(--accent, #6cf);
}

.target-picker-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  scrollbar-width: thin;
}
.target-picker-list::-webkit-scrollbar { width: 8px; }
.target-picker-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.tp-category {
  margin: 0;
}
.tp-category-header {
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  font-family: inherit;
}
.tp-category-header:hover { background: var(--panel-2); color: var(--text); }
.tp-category-chevron {
  display: inline-block;
  transition: transform .15s;
  font-size: 12px;
}
.tp-category.collapsed .tp-category-chevron { transform: rotate(-90deg); }
.tp-category.collapsed .tp-items { display: none; }

.tp-items { display: flex; flex-direction: column; }
.tp-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 8px 28px;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: background .1s;
}
.tp-item:hover { background: var(--panel-2); }
.tp-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.tp-item-count {
  background: var(--bg);
  color: var(--text-dim);
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.tp-item.active .tp-item-count {
  background: var(--accent);
  color: white;
}

.tp-empty {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 20px;
}
#last-updated {
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
#last-updated::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--green);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
button {
  background: var(--red);
  color: white;
  border: 1px solid var(--red);
  padding: 8px 16px;
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 2px;
  border-radius: 0;
  cursor: pointer;
  font-weight: 400;
  position: relative;
  overflow: hidden;
  transition: all .15s;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  box-shadow: 0 0 12px var(--red-glow);
}
button:hover { background: #ff2a5a; box-shadow: 0 0 22px var(--red-glow); }
button:disabled { background: var(--border); border-color: var(--border); cursor: wait; box-shadow: none; }
button.btn-secondary, .btn-secondary {
  background: transparent;
  border: 1px solid var(--border-bright);
  color: var(--text-dim);
  box-shadow: none;
  text-shadow: none;
  font-family: var(--font-display);
  letter-spacing: 1.5px;
  font-size: 12px;
  padding: 6px 12px;
}
button.btn-secondary:hover, .btn-secondary:hover {
  background: rgba(0, 240, 255, .05);
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 12px var(--cyan-glow);
  text-shadow: 0 0 4px var(--cyan);
}

.tabs {
  display: flex;
  gap: 0;
  background: rgba(14, 14, 22, 0.72);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  /* Sits directly below the topbar (topbar is now ~76px tall with brand-sub). */
  position: sticky;
  top: 76px;
  z-index: 9;
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 14px 20px;
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 2px;
  font-weight: 400;
  cursor: pointer;
  transition: color .15s;
  white-space: nowrap;
  clip-path: none;
  box-shadow: none;
}
.tab:hover { color: var(--text); background: transparent; }
.tab.active {
  color: var(--red);
  border-bottom-color: var(--red);
  background: transparent;
  box-shadow: 0 4px 16px -4px var(--red-glow);
}
.tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  color: var(--red);
  opacity: 0.55;
  transition: opacity .15s, filter .15s, transform .15s;
  vertical-align: -3px;
}
.tab-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: square;
  stroke-linejoin: miter;
  overflow: visible;
}
.tab:hover .tab-icon {
  opacity: 1;
  transform: translateY(-1px);
  color: #ff5577;
  filter:
    drop-shadow(0 0 4px var(--red))
    drop-shadow(0 0 10px var(--red-glow))
    drop-shadow(0 0 18px rgba(255, 0, 64, 0.4));
}
.tab:hover .tab-icon svg { stroke-width: 1.7; }
.tab.active .tab-icon {
  opacity: 1;
  filter:
    drop-shadow(0 0 3px #fff)
    drop-shadow(0 0 8px var(--red))
    drop-shadow(0 0 20px var(--red-glow));
  animation: icon-pulse 2.4s ease-in-out infinite;
}
.tab.active .tab-icon svg { stroke-width: 1.7; }
@keyframes icon-pulse {
  0%, 100% { filter: drop-shadow(0 0 3px #fff) drop-shadow(0 0 8px var(--red)) drop-shadow(0 0 20px var(--red-glow)); }
  50%      { filter: drop-shadow(0 0 4px #fff) drop-shadow(0 0 14px var(--red)) drop-shadow(0 0 28px var(--red-glow)); }
}
.tab-count {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  margin-left: 4px;
  background: var(--accent);
  color: white;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}
.tab-count:empty { display: none; }
.tab:not(.active) .tab-count { background: var(--text-dim); color: var(--bg); }

/* === Star button on cards === */
.btn-star {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(8, 8, 12, 0.78);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.18);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  z-index: 2;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  clip-path: none;
}
.btn-star svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: square;
  stroke-linejoin: miter;
}
.btn-star:hover {
  transform: scale(1.1);
  border-color: var(--yellow);
  color: var(--yellow);
  box-shadow: 0 0 14px rgba(255, 234, 0, 0.5);
}
.btn-star.starred {
  background: linear-gradient(135deg, #ffb700 0%, #ffea00 100%);
  border-color: #ffea00;
  color: #1a1400;
  box-shadow: 0 0 14px rgba(255, 234, 0, 0.6);
}
.btn-star.starred:hover { transform: scale(1.1); }

/* === Alerts tab === */
.alerts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
}
.alerts-header h2 { margin: 0; font-size: 18px; }

#alerts-list { padding: 0 24px 24px; display: flex; flex-direction: column; gap: 12px; }
.alert-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.alert-card-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.alert-card-conds {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.alert-cond-pill {
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.alert-card-body { flex: 1; }
.alert-card-count {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.alert-card-delete {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.alert-card-delete:hover { color: #ef4444; border-color: #ef4444; }

#alert-form-wrap { padding: 0 24px 24px; }
#alert-form-wrap h3 { margin: 16px 0 12px; }
.alert-form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.alert-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-dim);
}
.alert-form input, .alert-form select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
}
.alert-form-row { grid-column: 1 / -1; display: flex; gap: 16px; flex-wrap: wrap; }
.alert-form-actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }

#starred-summary { color: var(--text-dim); font-size: 13px; }

#map-region {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
}
.map-popup {
  font-size: 12px;
  line-height: 1.5;
}
.map-popup a { color: var(--accent); text-decoration: none; font-weight: 600; }
.map-popup strong { display: block; margin-bottom: 4px; }
.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--text);
}
.leaflet-popup-tip { background: var(--panel); }

/* === Photo gallery lightbox === */
.gallery {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery[hidden] { display: none; }
.gallery-img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}
.gallery-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 28px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.gallery-close:hover { background: rgba(255, 255, 255, 0.25); }
.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border: none;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 32px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.gallery-nav:hover { background: rgba(255, 255, 255, 0.25); }
.gallery-nav-prev { left: 24px; }
.gallery-nav-next { right: 24px; }
.gallery-counter {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: white;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.65);
  padding: 6px 14px;
  border-radius: 14px;
}

/* === TCO === */
.tco-controls {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 12px 14px;
  background: var(--panel-2);
  border-radius: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.tco-controls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
}
.tco-controls input {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  width: 90px;
}
#tco-tier {
  margin-left: auto;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}
.tco-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.tco-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.tco-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.tco-table tr.tco-subtotal td { background: var(--panel-2); font-weight: 700; color: var(--accent); }
.tco-table tr.tco-total td { background: var(--accent-soft); font-weight: 700; color: var(--accent); font-size: 15px; }
.tco-disclaimer {
  background: var(--panel-2);
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
}
/* legacy individual button rules removed — unified via .card-actions button */

/* === Compare button on cards === */
.btn-compare {
  position: absolute;
  top: 8px;
  left: 48px;
  background: rgba(8, 8, 12, 0.78);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.18);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  z-index: 2;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  clip-path: none;
}
.btn-compare svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: square;
  stroke-linejoin: miter;
}
.btn-compare:hover {
  transform: scale(1.1);
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 14px var(--cyan-glow);
}
.btn-compare.checked {
  background: var(--red);
  border-color: var(--red);
  color: white;
  box-shadow: 0 0 14px var(--red-glow);
}
.btn-compare.checked:hover {
  transform: scale(1.1);
  border-color: var(--red);
  color: white;
  box-shadow: 0 0 18px var(--red-glow);
}

.compare-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 30px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(230, 57, 70, .4);
  z-index: 99;
}
.compare-bar[hidden] { display: none; }
#compare-bar-summary { color: var(--text); font-weight: 600; font-size: 14px; }
#compare-bar-open { padding: 6px 14px; font-size: 13px; border-radius: 16px; }
#compare-bar-clear { padding: 6px 12px; font-size: 13px; border-radius: 16px; }

.compare-modal-inner { width: min(1200px, 96vw); }
.compare-table { width: 100%; border-collapse: collapse; }
.compare-table th, .compare-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 13px;
}
.compare-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  background: var(--panel-2);
  white-space: nowrap;
  position: sticky;
  left: 0;
  z-index: 1;
}
.compare-table td.compare-winner { color: #4ade80; font-weight: 700; }
.compare-table .compare-image {
  width: 100%;
  aspect-ratio: 16/10;
  background: var(--panel-2) center / cover no-repeat;
  border-radius: 6px;
}
.compare-table .compare-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 12px;
}
.compare-table .compare-link:hover { text-decoration: underline; }
.tab:hover { color: var(--text); }

.kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.kpi {
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  padding: 20px 22px;
  text-align: left;
  position: relative;
  overflow: hidden;
  transition: background .15s;
}
.kpi:last-child { border-right: none; }
.kpi:hover { background: var(--panel); }
.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px;
  height: 0;
  background: var(--red);
  transition: height .25s ease;
}
.kpi:hover::before { height: 100%; box-shadow: 0 0 12px var(--red-glow); }
.kpi-num {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -1px;
  line-height: 1;
}
.kpi-label {
  font-family: var(--font-jp);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--text-dim);
  margin-top: 0;
  margin-bottom: 8px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.filters label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}
.filters select, .filters input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
}
.filter-count { margin-left: auto; color: var(--text-dim); font-size: 13px; }

/* === Toggle switch === */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: var(--text-dim);
}
.toggle-switch input { display: none; }
.toggle-track {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: background .15s, border-color .15s;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform .15s, background .15s;
}
.toggle-switch input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-switch input:checked + .toggle-track::after {
  background: white;
  transform: translateX(16px);
}
.toggle-switch input:checked ~ .toggle-text {
  color: var(--text);
  font-weight: 600;
}

.charts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 20px 24px;
}
.chart-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  min-height: 280px;
}
.chart-box h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.chart-box canvas { max-height: 260px; }

.listings {
  padding: 16px 24px 24px;
  /* topbar (~76) + tabs (~50) + target-bar (~75) = ~201px; pad slightly more */
  scroll-margin-top: 210px;
}
/* === Pagination === */
.listing-pagination {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px 16px 8px;
  margin-top: 16px;
  border-top: 1px solid var(--border);
}
.pg-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  min-width: 36px;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 1px;
  cursor: pointer;
  border-radius: 0;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  box-shadow: none;
  transition: all .12s;
}
.pg-btn:hover {
  background: var(--panel-2);
  border-color: var(--red);
  color: var(--red);
  box-shadow: 0 0 12px var(--red-glow);
}
.pg-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: white;
  font-weight: 700;
  box-shadow: 0 0 14px var(--red-glow);
}
.pg-btn.active:hover { color: white; }
.pg-btn.disabled,
.pg-btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
}
.pg-btn.pg-edge { letter-spacing: 0; font-size: 14px; }
.pg-gap {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 0 4px;
  user-select: none;
}
.listings h2 {
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: 3px;
  margin: 0 0 16px;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.listings h2 .jp-accent { color: var(--red); font-weight: 900; font-size: 10px; letter-spacing: 4px; opacity: 0.75; }
.listings small { color: var(--text-dim); font-weight: normal; font-size: 12px; font-family: var(--font-mono); margin-left: auto; }

/* Same treatment for other section headings */
.diff-section h2, .alerts-header h2 {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 3px;
  margin: 0 0 12px;
}
.chart-box h3 {
  font-family: var(--font-jp);
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 3px;
}
.listing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}
.listing-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  position: relative;
}
.listing-card-linked { cursor: pointer; }
.listing-card-linked:hover {
  transform: translateY(-2px);
  border-color: var(--red);
  box-shadow: 0 8px 28px rgba(255, 0, 64, .25);
}

/* "Seen" — dim cards user has clicked through */
.listing-card.listing-seen {
  opacity: 0.5;
  filter: saturate(0.7);
}
.listing-card.listing-seen:hover {
  opacity: 1;
  filter: none;
}
.listing-card.listing-seen .listing-thumb::after {
  content: '已看過';
  position: absolute;
  top: 8px;
  right: 44px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

/* Price-change spotlight — glow the whole card so it's unmissable */
.listing-card.card-price-down {
  border-color: #22c55e;
  box-shadow: 0 0 0 1px #14532d inset, 0 4px 14px rgba(74, 222, 128, .25);
}
.listing-card.card-price-down:hover {
  border-color: #4ade80;
  box-shadow: 0 0 0 1px #14532d inset, 0 6px 22px rgba(74, 222, 128, .45);
}
.listing-card.card-price-up {
  border-color: #f59e0b;
  box-shadow: 0 0 0 1px #78350f inset, 0 4px 14px rgba(251, 191, 36, .22);
}
.listing-card.card-price-up:hover {
  border-color: #fbbf24;
  box-shadow: 0 0 0 1px #78350f inset, 0 6px 22px rgba(251, 191, 36, .4);
}

/* Inline mini sparkline on the thumbnail */
.card-spark-wrap {
  position: absolute;
  left: 6px;
  bottom: 6px;
  background: rgba(0, 0, 0, 0.72);
  padding: 3px 6px;
  border-radius: 4px;
  pointer-events: none;
  backdrop-filter: blur(4px);
}
.card-sparkline {
  display: block;
  width: 80px;
  height: 24px;
}
.listing-card-linked:hover .external-arrow { opacity: 1; transform: translate(0, 0); }
.listing-thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--panel-2) center / cover no-repeat;
  position: relative;
}
.external-arrow {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, .65);
  color: white;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  transform: translate(4px, -4px);
  transition: opacity .15s, transform .15s;
  pointer-events: none;
}
.listing-meta-bottom {
  margin-top: 8px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.listing-info {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
  flex: 1;
}
.card-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.listing-source { color: var(--blue); font-size: 11px; }
.dup-badge {
  font-size: 10px;
  background: rgba(96, 165, 250, .15);
  color: #60a5fa;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 700;
  cursor: help;
}
/* Unified style for ALL card action buttons (🇹🇼 💰 📊 🔍) */
.card-actions button {
  background: var(--bg-2);
  border: 1px solid var(--border-bright);
  color: var(--text);
  width: 30px;
  height: 28px;
  padding: 0;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  font-weight: normal;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  margin: 0;
  box-shadow: none;
  transition: all .15s;
  clip-path: none;
}
.card-actions button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: square;
  stroke-linejoin: miter;
  opacity: 0.85;
}
.card-actions button:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--panel-2);
  box-shadow: 0 0 12px var(--red-glow);
}
.card-actions button:hover svg {
  opacity: 1;
  filter:
    drop-shadow(0 0 3px var(--red))
    drop-shadow(0 0 8px var(--red-glow));
  stroke-width: 1.6;
}
.card-actions button:disabled { opacity: 0.5; cursor: wait; box-shadow: none; }
.listing-body { padding: 12px; flex: 1; }
.listing-title {
  font-size: 13px;
  margin: 0 0 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.listing-title a { color: var(--text); text-decoration: none; }
.listing-title a:hover { color: var(--accent); }
.listing-meta { font-size: 12px; color: var(--text-dim); display: flex; flex-wrap: wrap; gap: 8px; }
.listing-price {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--red);
  margin: 8px 0;
  letter-spacing: -0.5px;
  text-shadow: 0 0 10px rgba(255, 0, 64, .35);
}
.listing-price small { font-family: 'Inter', sans-serif; font-size: 11px; color: var(--text-dim); font-weight: normal; }
.live-auction-prefix {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  background: rgba(251, 191, 36, .15);
  color: #fbbf24;
  padding: 2px 7px;
  border-radius: 10px;
  margin-right: 6px;
  vertical-align: middle;
  cursor: help;
}
.listing-badge {
  font-size: 10px;
  background: var(--green);
  color: black;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
  font-weight: 700;
}
.listing-badge-gone { background: var(--text-dim); color: var(--bg); }
.listing-badge-price-down { background: var(--green); color: black; }
.listing-badge-price-up { background: var(--yellow); color: black; }
.gen-badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  border-radius: 3px;
  margin-right: 4px;
  font-weight: 700;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.country-badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  background: var(--panel-2);
  color: var(--text-dim);
  border-radius: 3px;
}

/* === Condition / risk flag chips === */
.flag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.flag-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: help;
}
.flag-bad   { background: #2d1b1b; color: #ef4444; box-shadow: 0 0 0 1px #7f1d1d inset; }
.flag-warn  { background: #2d2418; color: #fbbf24; box-shadow: 0 0 0 1px #78350f inset; }
.flag-good  { background: #0f2c1f; color: #4ade80; box-shadow: 0 0 0 1px #14532d inset; }
.flag-info  { background: var(--panel-2); color: var(--text-dim); box-shadow: 0 0 0 1px var(--border) inset; }

.cp-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 8px;
  vertical-align: middle;
  letter-spacing: 0.3px;
}
.cp-great   { background: #14532d; color: #4ade80; box-shadow: 0 0 0 1px #166534 inset; }
.cp-good    { background: #1c2c1f; color: #a3e635; box-shadow: 0 0 0 1px #365314 inset; }
.cp-neutral { background: var(--panel-2); color: var(--text-dim); box-shadow: 0 0 0 1px var(--border) inset; }
.cp-warn    { background: #2d2418; color: #fbbf24; box-shadow: 0 0 0 1px #78350f inset; }
.cp-bad     { background: #2d1b1b; color: #ef4444; box-shadow: 0 0 0 1px #7f1d1d inset; }
.cp-badge { cursor: help; }
.cp-badge:hover { filter: brightness(1.2); }

.cp-explain {
  margin-bottom: 16px;
}
.cp-explain-summary {
  background: var(--panel-2);
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
}
.cp-explain-summary .cp-headline {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}
.cp-explain-summary .cp-vs {
  color: var(--text-dim);
  font-size: 12px;
}

.cp-rows { display: flex; flex-direction: column; gap: 8px; }
.cp-row {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  background: var(--panel-2);
  border-radius: 6px;
  border-left: 4px solid var(--border);
}
.cp-row-label {
  font-weight: 700;
  color: var(--text);
  font-size: 13px;
}
.cp-row-text {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
}
.cp-row-val {
  font-weight: 700;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cp-row.cp-row-good { border-left-color: #4ade80; }
.cp-row.cp-row-good .cp-row-val { color: #4ade80; }
.cp-row.cp-row-bad  { border-left-color: #ef4444; }
.cp-row.cp-row-bad  .cp-row-val { color: #ef4444; }
.cp-row.cp-row-neu  { border-left-color: var(--text-dim); }
.cp-row.cp-row-neu  .cp-row-val { color: var(--text); }

.diff-controls { padding: 16px 24px; background: var(--panel); border-bottom: 1px solid var(--border); display: flex; gap: 16px; align-items: center; }
.diff-controls label { color: var(--text-dim); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.diff-controls select { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 4px 8px; border-radius: 4px; font-size: 13px; }
#diff-summary { color: var(--text-dim); font-size: 13px; }
.diff-section { padding: 16px 24px; }
.diff-section h2 { font-size: 16px; margin: 0 0 12px; }
.diff-section h2 small { color: var(--text-dim); font-weight: normal; font-size: 13px; margin-left: 6px; }

.price-changes { width: 100%; border-collapse: collapse; }
.price-changes th, .price-changes td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.price-changes th { color: var(--text-dim); font-weight: 500; }
.price-changes a { color: var(--text); text-decoration: none; }
.price-changes a:hover { color: var(--accent); }
.delta-up { color: var(--yellow); }
.delta-down { color: var(--green); }

.quicklinks-group { margin-bottom: 16px; padding: 0 24px; }
.quicklinks-group h3 { font-size: 14px; color: var(--text-dim); margin-bottom: 8px; }
.quicklinks-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}
.quicklink {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  transition: border-color .15s, background .15s;
}
.quicklink:hover { border-color: var(--accent); background: var(--panel-2); }
.quicklink-name { font-weight: 600; }
.quicklink-note { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.db-stats { margin: 16px 24px; border-collapse: collapse; }
.db-stats td { padding: 6px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.db-stats td:first-child { color: var(--text-dim); }
#last-scrape-result { margin: 0 24px; }
#last-scrape-result table { width: 100%; border-collapse: collapse; }
#last-scrape-result th, #last-scrape-result td { padding: 6px 12px; border-bottom: 1px solid var(--border); font-size: 13px; text-align: left; }
#last-scrape-result th { color: var(--text-dim); }
.scrape-ok { color: var(--green); }
.scrape-fail { color: var(--accent); }

#health-summary {
  margin: 0 24px 12px;
  padding: 10px 14px;
  background: var(--panel-2);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-dim);
}
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 6px;
  padding: 0 24px 24px;
}
.health-cell {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}
.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
}
.health-green .health-dot { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.health-yellow .health-dot { background: #fbbf24; box-shadow: 0 0 6px #fbbf24; }
.health-red .health-dot { background: #ef4444; box-shadow: 0 0 6px #ef4444; }
.health-label { color: var(--text); }
.health-count { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.health-error {
  grid-column: 1 / -1;
  color: #fca5a5;
  font-size: 11px;
  margin-top: 4px;
  word-break: break-word;
}

.fb-warning { margin: 24px; padding: 16px; background: var(--panel); border-left: 4px solid var(--yellow); border-radius: 6px; }
.fb-warning h3 { margin-top: 0; color: var(--yellow); }
.fb-warning p { color: var(--text-dim); font-size: 13px; }
.fb-warning code { background: var(--bg); padding: 1px 4px; border-radius: 3px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; z-index: 100; overflow-y: auto; padding: 20px; }
.modal[hidden] { display: none; }
.modal-inner { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 20px; width: min(720px, 90vw); position: relative; max-height: 90vh; overflow-y: auto; }
.modal-inner.modal-wide { width: min(820px, 95vw); }
.modal-inner h3 { margin: 0 0 12px; padding-right: 30px; }
.modal-inner canvas { max-height: 320px; }
#modal-close, #import-modal-close { position: absolute; top: 10px; right: 12px; background: transparent; color: var(--text-dim); font-size: 28px; padding: 0 8px; line-height: 1; }
#modal-close:hover, #import-modal-close:hover { color: var(--accent); }
#modal-meta { margin-top: 16px; color: var(--text-dim); font-size: 13px; }
.hist-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.hist-stats > div {
  background: var(--panel-2);
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.hist-stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.hist-stat-val {
  display: block;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
}
.hist-stat-low { color: #4ade80; }
.hist-stat-high { color: #ef4444; }

/* === Taiwan import badge on cards === */
.tw-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.3px;
  cursor: help;
}
.tw-ok        { background: #0f2c1f; color: #4ade80; box-shadow: 0 0 0 1px #14532d inset; }
.tw-restricted{ background: #2d2418; color: #fbbf24; box-shadow: 0 0 0 1px #78350f inset; }
.tw-blocked   { background: #2d1b1b; color: #ef4444; box-shadow: 0 0 0 1px #7f1d1d inset; }
.tw-domestic  { background: #1e2840; color: #93c5fd; box-shadow: 0 0 0 1px #1e3a8a inset; }

.btn-tw {
  margin-left: 4px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 28px;
  height: 24px;
  padding: 0;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  font-weight: normal;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-tw:hover { border-color: var(--accent); color: var(--accent); background: var(--panel-2); }

/* === Taiwan import modal === */
#import-verdict {
  font-size: 18px;
  font-weight: 700;
  margin: 8px 0 16px;
  padding: 12px 16px;
  border-radius: 6px;
}
#import-verdict.verdict-ok { background: #0f2c1f; color: #4ade80; border-left: 4px solid #4ade80; }
#import-verdict.verdict-restricted { background: #2d2418; color: #fbbf24; border-left: 4px solid #fbbf24; }
#import-verdict.verdict-blocked { background: #2d1b1b; color: #ef4444; border-left: 4px solid #ef4444; }
#import-verdict .verdict-sub { display: block; font-size: 13px; font-weight: normal; color: var(--text); margin-top: 4px; }

#import-barriers { margin-bottom: 16px; }
.barrier-item {
  background: #2d1b1b;
  border-left: 4px solid #ef4444;
  padding: 10px 14px;
  border-radius: 4px;
  margin-bottom: 8px;
}
.barrier-item-title { font-weight: 700; color: #fca5a5; margin-bottom: 4px; }
.barrier-item-detail { font-size: 13px; color: var(--text); line-height: 1.6; }

.import-breakdown { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.import-breakdown td { padding: 7px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.import-breakdown td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.import-breakdown tr.row-divider td { font-weight: 700; background: var(--panel-2); color: var(--accent); }
.import-breakdown tr.row-total td { font-weight: 700; background: var(--accent-soft); color: var(--accent); font-size: 15px; border-bottom: none; }

#import-notes { margin-bottom: 16px; }
.note-item {
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 13px;
  border-left: 3px solid var(--border);
}
.note-info { background: var(--panel-2); border-left-color: var(--blue); color: var(--text); }
.note-warn { background: #2d2418; border-left-color: #fbbf24; color: #fde68a; }

.import-disclaimer {
  background: var(--panel-2);
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 14px;
}
#import-actions { display: flex; justify-content: flex-end; gap: 8px; }
#import-actions a {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 8px 16px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
#import-actions a:hover { filter: brightness(1.1); }

footer { padding: 24px; text-align: center; color: var(--text-dim); border-top: 1px solid var(--border); }

/* === Tablet (≤ 900px) === */
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); padding: 12px 16px; }
  .charts { grid-template-columns: 1fr; padding: 12px 16px; }
  .topbar { padding: 10px 16px; }
  .topbar h1 { font-size: 18px; }
  .target-bar { padding: 10px 16px; }
  .target-picker-btn { min-width: 0; width: 100%; }
  .target-picker-popover { left: 16px; right: 16px; width: auto; }
  .tabs { padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 12px 14px; font-size: 13px; flex-shrink: 0; }
  .filters { padding: 10px 16px; gap: 8px; }
  .listings { padding: 0 16px 16px; }
  .listing-grid { grid-template-columns: 1fr; gap: 10px; padding: 0 16px; }
  .listing-grid:not(.gallery) { padding: 0; }
  .listings .listing-grid { padding: 0; }
  .modal { padding: 12px; }
  .modal-inner { padding: 16px; width: 100% !important; max-height: 92vh; }
  .modal-inner h3 { font-size: 16px; }
  .compare-bar { left: 12px; right: 12px; transform: none; bottom: 12px; flex-wrap: wrap; padding: 10px 14px; }
  #compare-bar-summary { width: 100%; text-align: center; }
  .compare-table { font-size: 12px; }
  .compare-table th, .compare-table td { padding: 6px 8px; }
  #map-container { height: 420px; margin: 0 16px; }
  .alerts-header, #alerts-list, #alert-form-wrap, .diff-controls, .diff-section { padding-left: 16px; padding-right: 16px; }
  .alert-form { grid-template-columns: 1fr; padding: 14px; }
  .health-grid { padding: 0 16px 16px; }
  .gallery-nav-prev { left: 8px; }
  .gallery-nav-next { right: 8px; }
  .gallery-nav { width: 44px; height: 44px; font-size: 24px; }
  #scatter-subtitle { font-size: 10px; }
}

/* === Phone (≤ 600px) === */
@media (max-width: 600px) {
  .topbar { flex-direction: column; gap: 8px; align-items: stretch; padding: 8px 12px; }
  .topbar h1 { font-size: 16px; text-align: center; }
  .topbar-meta { justify-content: center; gap: 6px; }
  .topbar-meta button { padding: 6px 10px; font-size: 12px; }
  #last-updated { display: none; }
  .target-bar { top: auto; position: relative; padding: 8px 12px; }
  .tabs { top: 0; padding: 0 6px; }
  .tab { padding: 10px 10px; font-size: 12px; }
  .filters { flex-direction: column; align-items: stretch; padding: 8px 12px; }
  .filters label { width: 100%; justify-content: space-between; }
  .filters select, .filters input { flex: 1; min-width: 0; }
  .filter-count { margin-left: 0; text-align: right; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 10px 12px; }
  .kpi { padding: 10px 8px; }
  .kpi-num { font-size: 20px; }
  .kpi-label { font-size: 10px; }
  .chart-box { padding: 12px; min-height: 220px; }
  .chart-box h3 { font-size: 12px; }
  .chart-box canvas { max-height: 200px; }
  .listing-card { border-radius: 6px; }
  .listing-thumb { aspect-ratio: 16 / 9; }
  .listing-title { font-size: 12px; }
  .listing-price { font-size: 16px; }
  .listing-meta { font-size: 11px; gap: 6px; }
  .btn-star, .btn-compare { width: 28px; height: 28px; }
  .external-arrow { width: 22px; height: 22px; font-size: 12px; }
  .card-spark-wrap { display: none; } /* sparkline visible by tapping into history */
  .flag-row { gap: 3px; }
  .flag-chip { font-size: 10px; padding: 1px 5px; }
  .cp-badge, .tw-badge { font-size: 10px; padding: 1px 5px; }
  .modal-inner { padding: 12px; }
  .modal-inner h3 { font-size: 15px; padding-right: 36px; }
  #modal-close, #import-modal-close, #compare-modal-close, #tco-modal-close, #cp-modal-close { font-size: 24px; }
  .hist-stats { grid-template-columns: 1fr 1fr; gap: 6px; }
  .hist-stats > div { padding: 8px 10px; }
  .hist-stat-val { font-size: 13px; }
  .alert-card { flex-direction: column; align-items: stretch; padding: 12px; }
  .alert-card-count, .alert-card-delete { width: 100%; text-align: center; }
  .compare-table th { font-size: 11px; }
  .compare-table { display: block; overflow-x: auto; }
  .compare-table .compare-image { aspect-ratio: 4/3; }
  .tco-controls { flex-direction: column; align-items: stretch; }
  .tco-controls input { width: 100%; }
  .tco-controls label { justify-content: space-between; }
  #tco-tier { margin-left: 0; text-align: center; }
  .cp-row { grid-template-columns: 1fr; }
  .cp-row-val { text-align: right; }
  .target-group-chips { flex-wrap: wrap; }
  .health-cell { font-size: 11px; }
  .diff-controls { flex-direction: column; align-items: stretch; padding: 12px; }
  .target-picker-popover { left: 12px; right: 12px; }
  #target-picker-search { font-size: 14px; }
  footer { font-size: 11px; padding: 14px 12px; }
  .gallery-img { max-width: 96vw; max-height: 75vh; }
}

/* Very small phones — collapse further */
@media (max-width: 380px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .topbar h1 { font-size: 15px; }
  .topbar-meta button { font-size: 11px; padding: 5px 8px; }
}
