:root {
  --bg: #0f1419;
  --panel: #161b22;
  --panel-alt: #1c2230;
  --grid: #1c2230;
  --accent: #388bfd;
  --text: #e6edf3;
  --muted: #7d8590;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --img-bg: #0a0d12;
}
[data-theme="light"] {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-alt: #f0f2f5;
  --grid: #d8dce2;
  --accent: #1868c9;
  --text: #1c2128;
  --muted: #57606a;
  --good: #1a8a4a;
  --warn: #b3690a;
  --bad: #cf3030;
  --img-bg: #eef1f5;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--grid);
}
.topbar-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.topbar h1 { font-size: 20px; }
.topbar h1 .sub { color: var(--muted); font-size: 12px; font-weight: 400; display: block; margin-top: 4px; }

.compare-tray {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}
button {
  font-family: inherit;
  font-size: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--grid); }
button:hover { filter: brightness(1.1); }
/* Segmented Day/Night/System control -- follows the ~/github/lamida/tsdb-explorer
   idiom (src/web/ui/theme.ts) rather than a single emoji-cycling button. A fixed-
   width group anchored inside .topbar-main so it sits next to the title instead
   of drifting to the middle of a 3-child space-between row. */
.themetoggle {
  display: flex; gap: 2px; flex-shrink: 0;
  border: 1px solid var(--grid); border-radius: 6px; padding: 2px;
  background: var(--bg);
}
.themetoggle button {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-family: inherit; font-size: 11px; padding: 5px 9px; border-radius: 4px;
}
.themetoggle button:hover { filter: none; color: var(--text); }
.themetoggle button[aria-pressed="true"] {
  background: var(--panel-alt); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--grid);
}

main { flex: 1; padding: 20px 24px 40px; max-width: 1200px; width: 100%; margin: 0 auto; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.filters input, .filters select {
  font-family: inherit;
  font-size: 13px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 8px 10px;
}
#search { flex: 1; min-width: 200px; }

.result-count { color: var(--muted); font-size: 12px; margin-bottom: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}
.card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: var(--img-bg);
  border-radius: 8px;
}
.img-placeholder {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--img-bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  opacity: 0.35;
}
.card .brand { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.card .model { font-size: 15px; font-weight: 700; }
.card .price { font-size: 16px; color: var(--accent); font-weight: 700; }
.card .price .price-sgd { font-size: 12px; color: var(--muted); font-weight: 400; }
.card .meta { font-size: 11px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge.available { background: rgba(63,185,80,0.15); color: var(--good); }
.badge.preorder { background: rgba(210,153,34,0.15); color: var(--warn); }
.badge.upcoming { background: rgba(56,139,253,0.15); color: var(--accent); }
.badge.discontinued { background: rgba(248,81,73,0.15); color: var(--bad); }

.card .actions { display: flex; gap: 8px; margin-top: auto; align-items: center; }
.card .actions label { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.card .details-btn { flex: 1; }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto; z-index: 10;
}
.overlay[hidden] { display: none; }
.overlay-panel {
  background: var(--panel); border: 1px solid var(--grid); border-radius: 12px;
  padding: 24px; max-width: 1000px; width: 100%; position: relative;
}
.overlay-close {
  position: absolute; top: 12px; right: 12px; background: transparent; color: var(--muted);
  border: 1px solid var(--grid); border-radius: 6px; padding: 4px 8px;
}

table.compare { width: 100%; border-collapse: collapse; font-size: 12px; }
table.compare th, table.compare td {
  border: 1px solid var(--grid); padding: 8px 10px; text-align: left; vertical-align: top;
}
table.compare th { background: var(--img-bg); color: var(--muted); font-weight: 700; white-space: nowrap; }
table.compare img, table.compare .img-placeholder { width: 120px; aspect-ratio: 4/3; object-fit: contain; background: var(--img-bg); border-radius: 6px; font-size: 24px; }
table.compare tr.label-row td:first-child { color: var(--muted); }

.detail-grid { display: flex; gap: 20px; flex-wrap: wrap; }
.detail-grid img, .detail-grid .img-placeholder { width: 260px; aspect-ratio: 4/3; object-fit: contain; background: var(--img-bg); border-radius: 8px; }
.detail-body { flex: 1; min-width: 260px; }
.detail-body h2 { font-size: 20px; margin-bottom: 4px; }
.detail-body ul { margin: 8px 0 0 18px; font-size: 13px; }
.detail-body .spec-list { margin-top: 12px; font-size: 12px; color: var(--muted); }
.detail-body .spec-list div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--grid); padding: 4px 0; }
.detail-body .sources { margin-top: 12px; font-size: 11px; }
.detail-body .sources a { color: var(--accent); }

footer { text-align: center; font-size: 11px; color: var(--muted); padding: 16px; border-top: 1px solid var(--grid); }
footer p { margin: 0; }
footer p + p { margin-top: 6px; }
footer a { color: var(--muted); }
.footer-credit a { color: var(--accent); text-decoration: none; }
.footer-credit a:hover { text-decoration: underline; }
