/* ======================================================
   RadioGopher — styles.css
   ====================================================== */

/* ---------- Reset / base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #0f1117;
  --color-surface: #1a1d27;
  --color-border: #2d3045;
  --color-primary: #4f9cf9;
  --color-primary-dark: #2d7dd2;
  --color-text: #e2e8f0;
  --color-muted: #8892a4;
  --color-score-high: #34d399;
  --color-score-mid: #fbbf24;
  --color-score-low: #f87171;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1.5rem 2rem;
  text-align: center;
}

header h1 {
  font-size: 2rem;
  letter-spacing: -0.5px;
}

header .tagline {
  color: var(--color-muted);
  margin-top: 0.25rem;
  font-size: 0.95rem;
}

/* ---------- Main ---------- */
main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ---------- Intro / landing copy ---------- */
.intro {
  max-width: 780px;
  margin: 0 auto 1.5rem;
  text-align: center;
  color: var(--color-muted);
}

.intro h2 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.5rem;
  letter-spacing: -0.2px;
}

.intro p {
  font-size: 0.9rem;
  line-height: 1.55;
}

.intro strong {
  color: var(--color-text);
  font-weight: 600;
}

/* ---------- Collection tabs ----------
   Pill-style quick-filter bar. Sits above the dense controls bar so the
   POTA shortcut is the first thing a user sees. The active pill uses a
   primary-tinted fill; inactive pills are surface-colored so the bar
   reads as a segmented control rather than a row of buttons. */
.collection-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.collection-tab {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 1.1rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.collection-tab:hover,
.collection-tab:focus-visible {
  color: var(--color-text);
  border-color: var(--color-primary);
  outline: none;
}

.collection-tab.is-active {
  background: rgba(79, 156, 249, 0.18);
  color: var(--color-primary);
  border-color: rgba(79, 156, 249, 0.55);
}

/* ---------- Controls (sticky) ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 0.75rem 0;
  background: var(--color-bg);
  /* Soft fade so cards don't appear to bump into the bar. */
  box-shadow: 0 8px 12px -8px rgba(0, 0, 0, 0.6);
}

.controls input,
.controls select {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 0.9rem;
  padding: 0.55rem 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.controls input {
  flex: 1 1 220px;
}

.controls select {
  flex: 0 1 180px;
}

.controls input:focus,
.controls select:focus {
  border-color: var(--color-primary);
}

.controls-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--color-muted);
  padding: 0.55rem 0.5rem;
  cursor: pointer;
  user-select: none;
}

.controls-checkbox input {
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* ---------- Summary ---------- */
.summary {
  color: var(--color-muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* ---------- Listings grid ---------- */
.listings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1.25rem;
}

.loading-msg {
  color: var(--color-muted);
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 0;
}

/* ---------- Listing card ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.card-image {
  width: 100%;
  height: 180px;
  object-fit: contain;
  background: #12141e;
  padding: 0.5rem;
}

.card-image-placeholder {
  width: 100%;
  height: 180px;
  background: #12141e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  color: var(--color-border);
}

.card-body {
  padding: 0.9rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-model {
  font-size: 0.78rem;
  color: var(--color-primary);
}

/* Category badge (e.g. "Amplifier"). Transceivers are the default and
   do not show a badge to keep the UI uncluttered. */
.category-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  margin-bottom: 0.25rem;
}

.category-amplifier {
  background: #3a2b1a;
  color: #f5b461;
  border: 1px solid #6b4a1e;
}

/* Sepia-toned badge for vintage / boatanchor listings. Visually distinct
   from the amber amplifier badge so users can scan a mixed grid quickly. */
.category-vintage {
  background: #2a1f15;
  color: #d4a574;
  border: 1px solid #5a4226;
}

/* Forest-green for antennas and a cooler teal for accessories. Picked
   to be distinct from amplifier amber and vintage sepia, and to feel
   "outdoorsy" alongside the POTA collection accent. */
.category-antenna {
  background: #15291e;
  color: #6ee7b7;
  border: 1px solid #1f4a37;
}

.category-accessory {
  background: #142934;
  color: #7dd3fc;
  border: 1px solid #1d4862;
}

/* Violet badge for antenna tuners (LDG, MFJ, Palstar, Elecraft, mAT). Distinct
   from accessory teal so a tuner card can't be mistaken for a generic accessory
   at a glance — the buying decision is genuinely different. */
.category-tuner {
  background: #241935;
  color: #c4b5fd;
  border: 1px solid #4b3771;
}

/* Holds zero or more category/collection badges in a row beneath the
   model line. Keeps the gap consistent regardless of which badges fire. */
.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  margin-bottom: 0.25rem;
}

.card-badges:empty {
  display: none;
}

/* Collection badge — orthogonal to category. Shares the pill geometry
   of `.deal-label` but uses the primary-blue palette to set it apart
   from the deal-quality and category-type signals. */
.collection-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.collection-pota {
  background: rgba(79, 156, 249, 0.18);
  color: var(--color-primary);
  border: 1px solid rgba(79, 156, 249, 0.5);
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 0.6rem;
}

.card-price {
  font-size: 1.1rem;
  font-weight: 700;
}

.card-condition {
  font-size: 0.75rem;
  color: var(--color-muted);
}

/* Score badge */
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  font-size: 0.78rem;
  font-weight: 700;
  color: #000;
  flex-shrink: 0;
}

.score-high  { background: var(--color-score-high); }
.score-mid   { background: var(--color-score-mid); }
.score-low   { background: var(--color-score-low); }

/* Deal label pill */
.deal-label {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid transparent;
}

.deal-great-deal {
  background: rgba(52, 211, 153, 0.15);
  color: var(--color-score-high);
  border-color: rgba(52, 211, 153, 0.4);
}

.deal-fair {
  background: rgba(79, 156, 249, 0.15);
  color: var(--color-primary);
  border-color: rgba(79, 156, 249, 0.4);
}

.deal-overpriced {
  background: rgba(251, 191, 36, 0.15);
  color: var(--color-score-mid);
  border-color: rgba(251, 191, 36, 0.4);
}

.deal-accessory,
.deal-parts-only {
  background: rgba(136, 146, 164, 0.15);
  color: var(--color-muted);
  border-color: rgba(136, 146, 164, 0.4);
}

/* Sold / active average line */
.card-avg {
  font-size: 0.72rem;
  color: var(--color-muted);
  margin-top: 0.15rem;
}

.card-avg-muted {
  opacity: 0.7;
  font-style: italic;
}

/* Card footer */
.card-footer {
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-end-time {
  font-size: 0.75rem;
  color: var(--color-muted);
}

.card-link {
  font-size: 0.8rem;
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 600;
}

.card-link:hover {
  color: var(--color-primary-dark);
  text-decoration: underline;
}

/* ---------- Footer ---------- */
footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  text-align: center;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--color-muted);
}

footer .affiliate-disclosure {
  max-width: 640px;
  margin: 0.5rem auto 0;
  font-size: 0.72rem;
  line-height: 1.5;
  opacity: 0.8;
}

footer .parent-brand {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  opacity: 0.7;
}

footer .parent-brand a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

footer .parent-brand a:hover {
  color: var(--color-text);
}

/* ---------- Reset button ---------- */
.controls-reset {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.55rem 0.9rem;
  transition: color 0.15s, border-color 0.15s;
}

.controls-reset:hover,
.controls-reset:focus-visible {
  color: var(--color-text);
  border-color: var(--color-primary);
  outline: none;
}

/* ---------- Score badge as button ----------
   The .score-high / .score-mid / .score-low rules above set the colour;
   we only need to strip default <button> chrome here. */
button.score-badge {
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}

button.score-badge:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------- Score breakdown panel ---------- */
.breakdown {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin-top 0.25s ease;
  margin-top: 0;
  border-top: 1px dashed transparent;
}

.card-expanded .breakdown {
  max-height: 400px;
  opacity: 1;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top-color: var(--color-border);
}

.breakdown-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.75rem;
  font-size: 0.78rem;
}

.breakdown-grid dt {
  color: var(--color-muted);
}

.breakdown-grid dd {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
}

.bd-pos  { color: var(--color-score-high); }
.bd-neg  { color: var(--color-score-low);  }
.bd-zero { color: var(--color-muted);      }

.breakdown-basis {
  font-size: 0.72rem;
  color: var(--color-muted);
  margin-top: 0.5rem;
  line-height: 1.4;
}

.breakdown-basis strong {
  color: var(--color-text);
  font-weight: 600;
}

/* ---------- Empty state ---------- */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.empty-reset {
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  transition: background 0.15s;
}

.empty-reset:hover,
.empty-reset:focus-visible {
  background: var(--color-primary-dark);
  outline: none;
}

/* ---------- Footer: data freshness indicator ---------- */
/*
 * Renders the "Last updated: <relative time> · refreshes every 4 hours"
 * line in the footer. Color reacts to data age via a [data-freshness]
 * attribute toggled in app.js. Thresholds match the RefreshStale
 * CloudWatch alarm (6h) so user-visible "stale" coincides with ops alarms.
 */
footer .data-freshness {
  font-size: 0.85rem;
  font-weight: 500;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
  align-items: baseline;
}

footer .data-freshness-cadence {
  opacity: 0.65;
  font-weight: 400;
}

#last-updated {
  cursor: help;
  border-bottom: 1px dotted currentColor;
  font-variant-numeric: tabular-nums;
}

footer .data-freshness[data-freshness="fresh"] { color: var(--color-score-high); }
footer .data-freshness[data-freshness="aging"] { color: var(--color-score-mid); }
footer .data-freshness[data-freshness="stale"] { color: var(--color-score-low); }

/* When stale, append a hint about possibly out-of-date prices. */
footer .data-freshness[data-freshness="stale"]::after {
  content: " — data may be out of date";
  display: block;
  width: 100%;
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.85;
  margin-top: 0.15rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  header h1 { font-size: 1.5rem; }
  .controls input, .controls select { flex: 1 1 100%; }
  .controls-reset { flex: 1 1 100%; }
  .listings-grid {
    grid-template-columns: 1fr;
  }
}
