/* ============================================================================
   ATLAS REDESIGN — Market Intelligence screen styles  ·  Phase 2
   Branch: atlas-redesign-2026-06-29

   Prefix: .rd-market. Tokens only (--r-*) so Calm (almanac) + Operator themes
   both work automatically. No hardcoded hex. Theme-specific selectors
   (html[data-rtheme="operator"] …) are used only where a token can't express
   the tweak (rare).
   ========================================================================== */

.rd-market {
  font-family: var(--r-font-body);
  color: var(--r-body);
  padding: var(--r-gutter);
  max-width: var(--r-page-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---- page header --------------------------------------------------------- */
.rd-mkt-head {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rd-mkt-eyebrow {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-eyebrow);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--r-clay);
}
.rd-mkt-h1 {
  font-family: var(--r-font-display);
  font-size: var(--r-fs-h1);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -.01em;
  color: var(--r-ink);
  margin: 0;
}
.rd-mkt-sub {
  margin: 2px 0 0;
  max-width: 640px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--r-muted);
}
.rd-mkt-sub-org {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-meta);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--r-faint);
  margin-left: 4px;
}

/* ---- KPI strip (4-up, joined rail) --------------------------------------- */
.rd-mkt-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-card);
  box-shadow: var(--r-shadow-card);
  overflow: hidden;
}
.rd-mkt-kpi {
  padding: 15px 18px;
  border-right: 1px solid var(--r-hairline);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: background var(--r-dur) var(--r-ease);
}
.rd-mkt-kpi:last-child { border-right: none; }
.rd-mkt-kpi:hover { background: var(--r-canvas-raised); }
.rd-mkt-kpi-label {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-eyebrow);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--r-faint);
}
.rd-mkt-kpi-value {
  font-family: var(--r-font-display);
  font-size: 24px;
  font-weight: 600;
  line-height: 1;
  color: var(--r-ink);
}
/* semantic highlight for a real fetched value (sold-over-asking, new listings
   this week) — never an invented trend/delta; see market.js load(). */
.rd-mkt-kpi-value[data-tone="good"] { color: var(--r-good); }
.rd-mkt-kpi-note {
  font-size: var(--r-fs-meta);
  color: var(--r-muted);
  line-height: 1.2;
}

/* ---- main grid (top markets | side) -------------------------------------- */
.rd-mkt-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  align-items: start;
  min-height: 0;
}

/* ---- shared card chrome -------------------------------------------------- */
.rd-mkt-card {
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-card);
  box-shadow: var(--r-shadow-card);
  padding: 20px 22px;
}
.rd-mkt-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.rd-mkt-card-title {
  margin: 0;
  font-family: var(--r-font-display);
  font-size: var(--r-fs-h2);
  font-weight: 600;
  color: var(--r-ink);
}
.rd-mkt-card-note {
  font-size: 12px;
  color: var(--r-muted);
}

/* ---- top markets list ---------------------------------------------------- */
.rd-mkt-rows {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  overflow: auto;
  max-height: calc(100vh - 360px);
}
.rd-mkt-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-top: 1px solid var(--r-hairline);
  border-radius: 8px;
  transition: background var(--r-dur) var(--r-ease);
}
.rd-mkt-row:first-child { border-top: none; }
.rd-mkt-row:hover { background: var(--r-canvas-raised); }
.rd-mkt-row-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--r-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rd-mkt-row-med {
  flex: 0 0 auto;
  font-family: var(--r-font-mono);
  font-size: 12px;
  color: var(--r-muted);
}
.rd-mkt-row-dom {
  flex: 0 0 48px;
  text-align: right;
  font-family: var(--r-font-mono);
  font-size: 12px;
  color: var(--r-muted);
}
.rd-mkt-row-vol {
  flex: 0 0 66px;
  text-align: right;
  font-family: var(--r-font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--r-ink);
}

/* honest dashed empty state */
.rd-mkt-empty {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-meta);
  letter-spacing: .03em;
  color: var(--r-faint);
  text-align: center;
  padding: 26px 12px;
  border: 1px dashed var(--r-border);
  border-radius: var(--r-radius-control);
  margin: 10px 0 4px;
}
.rd-mkt-kpis > .rd-mkt-empty {
  grid-column: 1 / -1;
}

/* ---- side column --------------------------------------------------------- */
.rd-mkt-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* median-price trend card */
.rd-mkt-trend-delta {
  font-size: 12px;
  font-weight: 600;
}
.rd-mkt-trend-delta[data-tone="good"]  { color: var(--r-good); }
.rd-mkt-trend-delta[data-tone="alert"] { color: var(--r-alert); }
.rd-mkt-trend-delta[data-tone="none"]  { color: var(--r-faint); }

.rd-mkt-spark {
  margin-top: 12px;
  display: block;
}
.rd-mkt-trend-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-family: var(--r-font-mono);
  font-size: 12px;
  color: var(--r-faint);
}
.rd-mkt-spark-empty {
  margin-top: 12px;
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-meta);
  letter-spacing: .03em;
  color: var(--r-faint);
  text-align: center;
  padding: 22px 10px;
  border: 1px dashed var(--r-border);
  border-radius: var(--r-radius-control);
}

/* list-now opportunities callout (sits on the well surface) */
.rd-mkt-opp {
  background: var(--r-well);
  box-shadow: none;
}
.rd-mkt-opp-title {
  margin: 0;
  font-family: var(--r-font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--r-ink);
}
.rd-mkt-opp-body {
  margin: 7px 0 12px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--r-muted);
}
.rd-mkt-opp-cta {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  height: 38px;
  background: var(--r-primary);
  color: var(--r-primary-ink);
  border: none;
  border-radius: var(--r-radius-control);
  font-family: var(--r-font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--r-dur) var(--r-ease),
              transform var(--r-dur) var(--r-ease),
              box-shadow var(--r-dur) var(--r-ease);
}
.rd-mkt-opp-cta i { font-size: 15px; }
.rd-mkt-opp-cta:hover {
  filter: brightness(1.06);
  box-shadow: var(--r-shadow-hover);
  transform: translateY(-2px);
}
.rd-mkt-opp-cta:active { transform: translateY(0); }

/* ---- focus visibility (keyboard) ----------------------------------------- */
.rd-market .rd-mkt-opp-cta:focus-visible { outline: var(--r-focus); outline-offset: 2px; }

/* ---- theme-specific tweak: lift the joined KPI rail seam on dark ---------- */
html[data-rtheme="operator"] .rd-mkt-kpi { border-right-color: var(--r-hairline-2); }

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 980px) {
  .rd-mkt-grid { grid-template-columns: 1fr; }
  .rd-mkt-rows { max-height: 48vh; }
}
@media (max-width: 720px) {
  .rd-mkt-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* restore right borders on the new 2-up seams; clear the wrap-edge ones */
  .rd-mkt-kpi { border-right: 1px solid var(--r-hairline); border-bottom: 1px solid var(--r-hairline); }
  .rd-mkt-kpi:nth-child(2n) { border-right: none; }
  .rd-mkt-kpi:nth-child(3) ~ .rd-mkt-kpi { border-bottom: none; }
  .rd-mkt-kpi:nth-child(3) { border-bottom: none; }
}

/* ==== Market Pulse (P1-1, 2026-07-02) — toolbar · temperature · stat blocks ==
   The screen was rewired from a mock top-markets/trend layout to a real per-area
   stat panel driven by /api/cma/market-stats. Tokens only (--r-*) so both themes
   resolve. (The legacy .rd-mkt-grid / -rows / -trend / -row-* rules above are now
   unused by market.js but left in place — harmless, non-breaking dead styles.) */

/* 5-up KPI rail variant (the Active-market block carries 5 stats) */
.rd-mkt-kpis--5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

/* toolbar: area + period selectors + a market-temperature pill */
.rd-mkt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.rd-mkt-ctl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-control);
  box-shadow: var(--r-shadow-card);
  transition: border-color var(--r-dur) var(--r-ease), box-shadow var(--r-dur) var(--r-ease);
}
.rd-mkt-ctl:hover { border-color: var(--r-primary); }
.rd-mkt-ctl:focus-within {
  border-color: var(--r-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--r-primary) 18%, transparent);
}
.rd-mkt-ctl-lead { display: inline-flex; color: var(--r-clay); font-size: 15px; }
.rd-mkt-select {
  appearance: none;
  border: none;
  background: transparent;
  font-family: var(--r-font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--r-ink);
  cursor: pointer;
  padding-right: 6px;
  outline: none;
}
.rd-mkt-select:focus-visible { outline: var(--r-focus); outline-offset: 3px; border-radius: 4px; }

/* market-temperature pill (seller / balanced / buyer) — semantic color via dot */
.rd-mkt-temp {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 40px;
  padding: 0 16px;
  margin-left: auto;                 /* push to the right end of the toolbar */
  border-radius: 999px;
  border: 1px solid var(--r-border);
  background: var(--r-surface);
  box-shadow: var(--r-shadow-card);
  font-size: 13.5px;
}
.rd-mkt-temp-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--r-faint); }
.rd-mkt-temp-label { font-weight: 700; color: var(--r-ink); letter-spacing: .01em; }
.rd-mkt-temp-ms { font-family: var(--r-font-mono); font-size: 12px; color: var(--r-muted); }
.rd-mkt-temp[data-tone="good"]  .rd-mkt-temp-dot { background: var(--r-good); }
.rd-mkt-temp[data-tone="warn"]  .rd-mkt-temp-dot { background: var(--r-clay); }
.rd-mkt-temp[data-tone="alert"] .rd-mkt-temp-dot { background: var(--r-alert); }
.rd-mkt-temp[data-tone="good"]  .rd-mkt-temp-label { color: var(--r-good); }
.rd-mkt-temp[data-tone="alert"] .rd-mkt-temp-label { color: var(--r-alert); }

/* stat block: a labeled header above a KPI rail */
.rd-mkt-block { display: flex; flex-direction: column; gap: 10px; }
.rd-mkt-block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.rd-mkt-block-title {
  margin: 0;
  font-family: var(--r-font-display);
  font-size: var(--r-fs-h2);
  font-weight: 600;
  color: var(--r-ink);
}
.rd-mkt-block-note {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-meta);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--r-faint);
}

/* responsive: collapse the 5-up rail + un-pin the temperature pill */
@media (max-width: 980px) {
  .rd-mkt-kpis--5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rd-mkt-temp { margin-left: 0; }
}
@media (max-width: 720px) {
  .rd-mkt-kpis--5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rd-mkt-kpis--5 .rd-mkt-kpi { border-right: 1px solid var(--r-hairline); border-bottom: 1px solid var(--r-hairline); }
  .rd-mkt-kpis--5 .rd-mkt-kpi:nth-child(2n) { border-right: none; }
}

/* ==== Recent sales feed (P2-B, 2026-07-02) — browsable closed sales ==========
   A clickable list of GAMLS-closed sales for the selected market. Tokens only so
   Calm + Operator resolve; ≥56px rows for a comfortable tap target; readable
   contrast (--r-ink / --r-muted, not --r-faint); keyboard focus ring. */
.rd-mkt-sales {
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-card);
  box-shadow: var(--r-shadow-card);
  overflow: hidden;
}
.rd-mkt-sale-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 18px;
  min-height: 56px;
  border-top: 1px solid var(--r-hairline);
  cursor: pointer;
  transition: background var(--r-dur) var(--r-ease);
}
.rd-mkt-sale-row:first-child { border-top: none; }
.rd-mkt-sale-row:hover { background: var(--r-canvas-raised); }
.rd-mkt-sale-row:focus-visible { outline: var(--r-focus); outline-offset: -2px; }
.rd-mkt-sale-main { flex: 1 1 auto; min-width: 0; }
.rd-mkt-sale-addr {
  font-size: 14px;
  font-weight: 600;
  color: var(--r-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* meta chips: date · DOM · specs as individually-aligned pieces, not a
   run-on string — a middot separates each real, present chip. */
.rd-mkt-sale-meta {
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 10px;
  font-size: 12.5px;
  color: var(--r-muted);
}
.rd-mkt-sale-chip { white-space: nowrap; }
.rd-mkt-sale-chip + .rd-mkt-sale-chip::before { content: "·"; margin-right: 10px; color: var(--r-faint); }
.rd-mkt-sale-chip--dash { color: var(--r-faint); }
.rd-mkt-sale-right {
  flex: 0 0 auto;
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-end;
}
.rd-mkt-sale-price {
  font-family: var(--r-font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--r-ink);
  font-variant-numeric: tabular-nums;
}
.rd-mkt-sale-s2l { font-family: var(--r-font-mono); font-size: 12px; color: var(--r-muted); }
.rd-mkt-sale-s2l[data-tone="good"] { color: var(--r-good); font-weight: 600; }
/* chevron affordance — appears on hover/keyboard focus to signal the row
   opens a detail slide-over (RDRecordPanel). Decorative only. */
.rd-mkt-sale-chevron {
  flex: none;
  font-size: 14px;
  color: var(--r-faint);
  opacity: 0;
  transform: translateX(-3px);
  transition: opacity var(--r-dur) var(--r-ease), transform var(--r-dur) var(--r-ease);
}
.rd-mkt-sale-row:hover .rd-mkt-sale-chevron,
.rd-mkt-sale-row:focus-visible .rd-mkt-sale-chevron { opacity: 1; transform: none; }
.rd-mkt-sales-more { margin-top: 12px; text-align: center; }
.rd-mkt-sales-morebtn {
  appearance: none;
  height: 40px;
  padding: 0 22px;
  background: var(--r-surface);
  color: var(--r-ink);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-control);
  font-family: var(--r-font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--r-dur) var(--r-ease), border-color var(--r-dur) var(--r-ease);
}
.rd-mkt-sales-morebtn:hover { background: var(--r-canvas-raised); border-color: var(--r-primary); }
.rd-mkt-sales-morebtn:focus-visible { outline: var(--r-focus); outline-offset: 2px; }
@media (max-width: 720px) {
  .rd-mkt-sale-row { padding: 12px 14px; }
  .rd-mkt-sale-addr { white-space: normal; }
}

/* ==== entrance motion (respects reduced-motion) =========================== */
.rd-mkt-toolbar, .rd-mkt-block, .rd-mkt-card { animation: rdMktIn .28s var(--r-ease); }
@keyframes rdMktIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .rd-mkt-toolbar, .rd-mkt-block, .rd-mkt-card { animation: none; }
  .rd-mkt-opp-cta:hover, .rd-mkt-sales-morebtn:hover { transform: none; }
  .rd-mkt-sale-chevron { transition: none; }
}

/* ==== mobile (390px) ======================================================= */
@media (max-width: 480px) {
  .rd-mkt-kpi-value { font-size: 20px; }
  .rd-mkt-ctl { flex: 1 1 auto; }
  .rd-mkt-temp { margin-left: 0; width: 100%; justify-content: center; }
}
