:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #5b9cff;
  --green: #3dd68c;
  --red: #f07178;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
header h1 { margin: 0; font-size: 1.35rem; font-weight: 600; }
.sub { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.9rem; }

.sync-active-banner {
  margin: 0.5rem 0 0;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: rgba(91, 156, 255, 0.12);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 0.85rem;
}

.sync-error-banner {
  margin: 0.5rem 0 0;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: rgba(240, 113, 120, 0.15);
  border: 1px solid var(--red);
  color: #ffc9c9;
  font-size: 0.85rem;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  max-width: 22rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 1000;
}
.toast-visible { opacity: 1; pointer-events: auto; }
.toast-error { border-color: var(--red); }
.toast-info { border-color: var(--accent); }

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
.tab:hover { color: var(--text); background: rgba(91, 156, 255, 0.1); }
.tab.active {
  color: var(--accent);
  border-color: var(--border);
  background: var(--bg);
}

main { padding: 1.25rem 1.5rem; max-width: 1400px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}
.stat-card .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .value { font-size: 1.5rem; font-weight: 600; margin-top: 0.25rem; }

.bestbuys-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.thesis-tag {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.35rem;
  margin: 0.1rem 0.15rem 0.1rem 0;
  border-radius: 4px;
  background: rgba(91, 156, 255, 0.15);
  color: var(--accent);
  border: 1px solid rgba(91, 156, 255, 0.25);
}

.thesis-line {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
  max-width: 280px;
}

.set-cards-panel {
  margin: 1.25rem 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.subhead {
  font-size: 1rem;
  margin: 1.5rem 0 0.75rem;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: center;
}
.toolbar input, .toolbar select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
}
.toolbar label { font-size: 0.9rem; color: var(--muted); display: flex; align-items: center; gap: 0.35rem; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 0.55rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; }
tr:hover td { background: rgba(91, 156, 255, 0.06); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: rgba(61, 214, 140, 0.15);
  color: var(--green);
}

.log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  overflow-x: auto;
  white-space: pre-wrap;
}

dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  max-width: 720px;
  width: 95%;
}
dialog.wide {
  max-width: min(1200px, 96vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.65); }
dialog article { padding: 0; }
dialog header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
dialog header h2 { margin: 0; font-size: 1.1rem; }
#modalClose {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}
#modalBody { padding: 1.25rem; max-height: 70vh; overflow-y: auto; font-size: 0.9rem; }

.muted { color: var(--muted); font-weight: normal; font-size: 0.85em; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
h3.subhead { font-size: 0.9rem; color: var(--muted); margin: 1.25rem 0 0.5rem; }

.progress-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.coverage-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}
.coverage-card h3 {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 500;
}
.coverage-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  margin-bottom: 0.35rem;
}
.progress-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 0.35rem;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #7eb8ff);
  border-radius: 4px;
  transition: width 0.4s ease;
}
.progress-bar-fill.warn { background: linear-gradient(90deg, #e8a838, #f07178); }
.progress-bar-fill.ok { background: linear-gradient(90deg, var(--green), #5ddea8); }

.progress-columns {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 900px) {
  .progress-columns { grid-template-columns: 1fr; }
}

.card-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: 520px; overflow-y: auto; }
.card-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.card-item:hover {
  border-color: var(--accent);
  background: rgba(91, 156, 255, 0.08);
}
.card-item .title { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.25rem; }
.card-item .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.card-item .meta strong { color: var(--text); font-weight: 500; }
.badge-warn {
  background: rgba(240, 113, 120, 0.15);
  color: var(--red);
}
.badge-muted {
  background: rgba(139, 156, 179, 0.15);
  color: var(--muted);
}

.filter-list { display: flex; flex-direction: column; gap: 0.4rem; }
.filter-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.85rem;
  padding: 0.45rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.filter-row .name { color: var(--text); }
.filter-row .pct { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 4rem; text-align: right; }
.filter-row .pct.fail { color: var(--red); }

.modal-filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.35rem;
  margin-top: 0.75rem;
}
.filter-chip {
  font-size: 0.75rem;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.filter-chip.pass { background: rgba(61, 214, 140, 0.12); color: var(--green); }
.filter-chip.fail { background: rgba(240, 113, 120, 0.12); color: var(--red); }
.filter-chip.skip { background: rgba(139, 156, 179, 0.1); color: var(--muted); }

tr.clickable { cursor: pointer; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sorted { color: var(--accent); }

.psa-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
  min-width: 7rem;
}
.psa-pair .sub { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.psa-pair .val { font-variant-numeric: tabular-nums; }
.psa-pair .val.zero { color: var(--muted); opacity: 0.5; }
.pop-pair .val { font-weight: 600; }

dialog { max-width: 960px; }

.modal-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1.25rem 0;
  border-bottom: 1px solid var(--border);
}
.modal-tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.4rem 0.75rem;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  font-size: 0.88rem;
}
.modal-tab:hover { color: var(--text); }
.modal-tab.active {
  color: var(--accent);
  background: rgba(91, 156, 255, 0.08);
}

.ebay-listings-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.ebay-listings-section h2 { margin-top: 0; }

.table-wrap-tall {
  max-height: 520px;
  overflow-y: auto;
}

.toolbar .btn-secondary {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
}
.toolbar .btn-secondary:hover {
  border-color: var(--accent);
}
.psa-history-wrap { margin-top: 1rem; }
.psa-history-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.psa-history-toolbar select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
}
