/* =========================================================================
   TCGDash — Research Dashboard styles.

   Companion stylesheet to product-explorer.css. The Product Explorer
   stylesheet is loaded first by both the WordPress snippet and the local
   preview HTML, providing :root tokens and the .tcgd-* component classes
   the Research Dashboard reuses (filter bar, cards, drawer, stripe,
   pagination, tags, state, etc.).

   This file declares only:
     1. Root container styles for #tcgd-research-dashboard, mirroring what
        product-explorer.css declares for #tcgd-product-explorer so the
        Research mount behaves identically (font, padding, theme, mobile
        padding override).
     2. Genuinely new component rules — the recursive container tree.

   Do NOT redeclare tokens or duplicate component classes here. When a
   third dashboard arrives, the shared rules should be extracted into
   frontend/shared/tokens.css + frontend/shared/components.css.
   ========================================================================= */

/* ---------- root container ---------- */

#tcgd-research-dashboard,
#tcgd-research-dashboard * { box-sizing: border-box; }

#tcgd-research-dashboard {
  font-family: var(--tcgd-font);
  color: var(--tcgd-text);
  background: var(--tcgd-bg);
  font-size: 13.5px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;

  /* === Dashboard container system ===
     Same as the Product Explorer root (tokens defined once in
     product-explorer.css, the shared base): break out of WordPress's narrow
     centered content column to full viewport width, then cap + center content
     via the horizontal padding (max --tcgd-app-max, min --tcgd-app-gutter).
     App-width dashboard, not a marketing content page. */
  width: auto;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  padding: 20px max(var(--tcgd-app-gutter), (100vw - var(--tcgd-app-max)) / 2) 64px;
}

/* Theme overrides — match the explicit-dark/explicit-light selectors used
   for the Product Explorer so a host theme that flips data-theme on a
   wrapping element still toggles both dashboards in lockstep. */
[data-theme="dark"] #tcgd-research-dashboard,
.dark #tcgd-research-dashboard {
  color: var(--tcgd-text);
  background: var(--tcgd-bg);
}
[data-theme="light"] #tcgd-research-dashboard,
.light #tcgd-research-dashboard {
  color: var(--tcgd-text);
  background: var(--tcgd-bg);
}

/* ---------- recursive container tree ----------
   Container nodes nest visually via a thin left-rule + indent. Items
   inside a container sit one level deeper. The depth is applied as an
   inline padding-left from JS (`style="--depth: N"`) rather than per-level
   selectors, so unlimited nesting is free. */

/* Collapse/expand toolbar above the tree. */
.tcgd-tree-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}
.tcgd-btn-sm {
  height: 26px;
  padding: 0 10px;
  font-size: 12px;
}

.tcgd-tree {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
}

/* Collapse caret — a CSS chevron (square corner) that rotates with state.
   Points right (▸) when collapsed, down (▾) when expanded. The empty variant
   is a same-width spacer that keeps leaf rows aligned under collapsible ones. */
.tcgd-tree-caret {
  position: relative;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
}
.tcgd-tree-caret:not(.tcgd-tree-caret-empty)::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--tcgd-text-muted);
  border-bottom: 1.5px solid var(--tcgd-text-muted);
  transform: rotate(-45deg);          /* ▸ collapsed */
  transition: transform 120ms ease;
}
.tcgd-tree-caret.tcgd-open::before {
  transform: rotate(45deg);           /* ▾ expanded */
}

/* A collapsible container row is a button: pointer + hover + focus ring. */
.tcgd-tree-row-toggle {
  cursor: pointer;
  user-select: none;
}
.tcgd-tree-row-toggle:hover { border-color: var(--tcgd-accent); }
.tcgd-tree-row-toggle:hover .tcgd-tree-caret::before { border-color: var(--tcgd-text); }
.tcgd-tree-row-toggle:focus-visible {
  outline: 2px solid var(--tcgd-accent);
  outline-offset: 2px;
}

/* "N hidden" hint shown on a collapsed container row. */
.tcgd-tree-hidden {
  color: var(--tcgd-text-faint);
  font-variant-numeric: tabular-nums;
}
.tcgd-tree-node {
  /* Indentation step per nesting level — wide enough that container → pack →
     card reads unmistakably, narrow enough to stay minimal. */
  padding-left: calc(var(--depth, 0) * 18px);
}
.tcgd-tree-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--tcgd-border);
  border-radius: var(--tcgd-radius-sm);
  background: var(--tcgd-surface);
}
/* Container rows (cases, boxes, packs) anchor each group: tinted fill,
   firmer border, and a thin accent rule on the left edge. */
.tcgd-tree-row-container {
  background: var(--tcgd-surface-2);
  border-color: var(--tcgd-border-strong);
  border-left: 2px solid var(--tcgd-accent);
}
.tcgd-tree-row-container .tcgd-tree-name { font-weight: 600; }

/* Child item rows read as subordinate to the pack above them: a faint
   left connector rule, lighter type, smaller thumb. */
.tcgd-tree-row:not(.tcgd-tree-row-container) {
  border-left: 2px solid var(--tcgd-border-strong);
}
.tcgd-tree-row:not(.tcgd-tree-row-container) .tcgd-tree-name {
  font-weight: 500;
  color: var(--tcgd-text-soft);
  font-size: 12.5px;
}
.tcgd-tree-thumb {
  width: 28px; height: 28px;
  border-radius: 4px;
  background: var(--tcgd-surface-3);
  overflow: hidden;
  flex: 0 0 28px;
  display: flex; align-items: center; justify-content: center;
}
.tcgd-tree-row:not(.tcgd-tree-row-container) .tcgd-tree-thumb {
  width: 24px; height: 24px; flex-basis: 24px;
}
.tcgd-tree-thumb img { width: 100%; height: 100%; object-fit: contain; }
.tcgd-tree-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tcgd-tree-name {
  font-weight: 500;
  color: var(--tcgd-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tcgd-tree-sub {
  font-size: 12px;
  color: var(--tcgd-text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tcgd-tree-side {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--tcgd-text-soft);
  white-space: nowrap;
}
.tcgd-tree-side .tcgd-tree-price { color: var(--tcgd-text); font-weight: 500; }
/* Free-text note from opening_container.notes / opening_item.notes —
   sits to the left of the price on the side line. Faintest of the three
   tiers (price/weights/note), reads as a quiet footer annotation. */
.tcgd-tree-side .tcgd-tree-note { color: var(--tcgd-text-faint); font-weight: 400; }

/* ---------- session list rows ----------
   Sessions render as a vertical list of clickable rows rather than the
   card grid the Product Explorer uses — each session is a richer object
   with multiple metadata facets, and a row layout reads better. */

.tcgd-session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.tcgd-session-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  background: var(--tcgd-surface);
  border: 1px solid var(--tcgd-border);
  border-radius: var(--tcgd-radius);
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
.tcgd-session-row:hover {
  border-color: var(--tcgd-border-strong);
  box-shadow: var(--tcgd-shadow-hover);
}
.tcgd-session-row:focus-visible {
  outline: 2px solid var(--tcgd-accent);
  outline-offset: 2px;
}
.tcgd-session-thumb {
  width: 56px; height: 56px;
  border-radius: var(--tcgd-radius-sm);
  background: var(--tcgd-surface-3);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.tcgd-session-thumb img { width: 100%; height: 100%; object-fit: contain; }
.tcgd-session-thumb .tcgd-noimage {
  font-size: 11px; color: var(--tcgd-text-faint);
}
.tcgd-session-main { min-width: 0; }
.tcgd-session-title {
  font-weight: 600;
  color: var(--tcgd-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tcgd-session-sub {
  font-size: 12.5px;
  color: var(--tcgd-text-muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.tcgd-session-meta {
  text-align: right;
  font-size: 12px;
  color: var(--tcgd-text-soft);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  white-space: nowrap;
}
/* Research snapshot in the session card: EV headline + packs/spread subline
   + faint date. Deterministic numbers only. */
.tcgd-session-meta .tcgd-session-ev {
  font-variant-numeric: tabular-nums;
  color: var(--tcgd-text);
  font-weight: 600;
  font-size: 14px;
}
.tcgd-session-meta .tcgd-session-snap {
  font-variant-numeric: tabular-nums;
  color: var(--tcgd-text-soft);
  font-size: 12px;
}
.tcgd-session-meta .tcgd-session-date {
  color: var(--tcgd-text-faint);
  font-size: 11.5px;
}
/* "BREAKDOWN VALUE" caption above the EV number — same micro-cap treatment
   the stripe stat labels use, kept tiny so the card height barely moves. */
.tcgd-session-meta .tcgd-session-ev-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--tcgd-text-faint);
}

/* One-line session summary beneath the card's metadata ("Opened 4 booster
   packs. 48 items logged."). Truncates with ellipsis instead of wrapping
   so cards keep their compact height even when the sentence gets long. */
.tcgd-session-summary {
  margin-top: 4px;
  font-size: 12px;
  color: var(--tcgd-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Overview tab: image carousel ----------
   Large product image at the top of the Overview, answering "what was
   opened" at a glance before any text. One slide per UNIQUE top-level
   product — duplicates collapse into a single image with an ×N quantity
   caption. Nav (prev/next arrows + dots) only appears when n > 1.

   Class names are prefixed .tcgd-rd-* (research-dashboard) to avoid the
   .tcgd-overview / .tcgd-overview-image collision with Product Explorer,
   which uses the same names for its 200px-wide left-rail product card. */
.tcgd-rd-overview {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
/* Two-column header — image left (fixed rail), notes + stripe right (1fr).
   Mirrors Product Explorer's Overview layout. Collapses to a single column
   on narrow viewports so mobile readers don't get a 240px squeeze. */
.tcgd-rd-overview-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  align-items: start;
}
.tcgd-rd-overview-right {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;     /* allow the right column to shrink past its intrinsic */
}
/* Inside the grid the carousel + sections are stacked by the parent gap,
   so neutralise the legacy bottom margin. */
.tcgd-rd-overview-grid .tcgd-overview-carousel { margin: 0; }
.tcgd-rd-overview-right .tcgd-section { margin-top: 0; }
.tcgd-overview-carousel { margin: 4px 0 22px; }
.tcgd-rd-overview-image {
  width: 100%;
  height: 300px;
  background: var(--tcgd-surface-2);
  border: 1px solid var(--tcgd-border);
  border-radius: var(--tcgd-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
@media (max-width: 720px) {
  .tcgd-rd-overview-grid { grid-template-columns: 1fr; }
}
.tcgd-rd-overview-image img,
.tcgd-overview-image-link {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tcgd-overview-image-link img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tcgd-rd-overview-image img { object-fit: contain; }
.tcgd-rd-overview-image .tcgd-noimage {
  color: var(--tcgd-text-faint);
  font-size: 13px;
}
.tcgd-overview-caption {
  margin-top: 10px;
  text-align: center;
  font-size: 13px;
  color: var(--tcgd-text);
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 2px;
  flex-wrap: wrap;
}
.tcgd-overview-caption-qty {
  font-weight: 600;
  color: var(--tcgd-text);
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}
.tcgd-overview-caption-name {
  color: var(--tcgd-text-muted);
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tcgd-overview-carousel-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
}
.tcgd-overview-carousel-arrow {
  width: 26px;
  height: 26px;
  border: 1px solid var(--tcgd-border);
  border-radius: 50%;
  background: var(--tcgd-surface);
  color: var(--tcgd-text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--tcgd-font);
  font-size: 16px;
  line-height: 1;
  padding: 0;
}
.tcgd-overview-carousel-arrow:hover {
  color: var(--tcgd-text);
  border-color: var(--tcgd-border-strong);
}
.tcgd-overview-carousel-dots {
  display: flex;
  gap: 7px;
  align-items: center;
}
.tcgd-overview-carousel-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--tcgd-border-strong);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background 100ms ease;
}
.tcgd-overview-carousel-dot:hover { background: var(--tcgd-text-muted); }
.tcgd-overview-carousel-dot.tcgd-active { background: var(--tcgd-accent); }

/* "View Original Source ↗" link — same affordance as the .tcgd-kv anchors
   but with a hair more weight so the action reads as a verb. */
.tcgd-overview-source-link {
  color: var(--tcgd-accent-text);
  text-decoration: none;
  font-weight: 500;
}
.tcgd-overview-source-link:hover { text-decoration: underline; }

/* ---------- key-value list (drawer Overview / Notes) ----------
   Simple two-column dl/dt/dd. Label left-muted, value right-aligned and
   tabular-num where it makes sense. Used in the Overview and Notes tabs
   for session metadata. */

.tcgd-kv {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 20px;
  row-gap: 6px;
  align-items: baseline;
}
.tcgd-kv dt {
  color: var(--tcgd-text-muted);
  font-size: 12.5px;
}
.tcgd-kv dd {
  margin: 0;
  color: var(--tcgd-text);
  word-break: break-word;
}
.tcgd-kv dd a {
  color: var(--tcgd-accent-text);
  text-decoration: none;
}
.tcgd-kv dd a:hover { text-decoration: underline; }

/* ---------- Research Metrics tab (Layer 2) ----------
   Dense label/value list. Calm and analytical — no charts, no color
   coding, no callouts dressed up as "insights". Just the numbers. */

.tcgd-metric-basis {
  font-size: 12px;
  color: var(--tcgd-text-muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}
.tcgd-metric-list {
  display: flex;
  flex-direction: column;
}
.tcgd-metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
  border-bottom: 1px solid var(--tcgd-divider);
}
.tcgd-metric:last-child { border-bottom: none; }
.tcgd-metric-label {
  font-size: 12.5px;
  color: var(--tcgd-text-soft);
}
.tcgd-metric-value {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--tcgd-text);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.tcgd-metric-note {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--tcgd-surface-2);
  border: 1px solid var(--tcgd-border);
  border-radius: var(--tcgd-radius);
  font-size: 13px;
  line-height: 1.5;
  color: var(--tcgd-text);
  font-variant-numeric: tabular-nums;
}
.tcgd-metric-foot {
  margin-top: 14px;
  font-size: 11.5px;
  color: var(--tcgd-text-faint);
  line-height: 1.5;
}

/* ---------- Metrics tab — section rhythm ----------
   The Metrics tab is the densest stack of sections in the drawer; the
   shared small-caps section heading reads smaller than the body text it
   introduces, so topics blend together. Scoped under .tcgd-metrics so the
   rest of the drawer (Overview, Notes, Contents → Loose items) keeps the
   existing micro-cap treatment. Tokens are shared with the rest of the
   site — divider colour, type scale, spacing — so the effect feels like
   part of the design system, not a one-off. */
.tcgd-metrics .tcgd-section { margin-top: 0; }
.tcgd-metrics .tcgd-section + .tcgd-section {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--tcgd-divider);
}
.tcgd-metrics .tcgd-section > h3 {
  font-size: 14px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--tcgd-text);
  margin: 0 0 12px 0;
}
/* Drop the basis line a touch farther from the topbar tab strip so it
   doesn't crowd the first section header. */
.tcgd-metrics .tcgd-metric-basis { margin-bottom: 16px; }

/* Empty-section note — keeps the 7-section structure consistent when a
   section can't be computed yet. */
.tcgd-metric-empty {
  font-size: 12.5px;
  color: var(--tcgd-text-faint);
  padding: 6px 0;
}

/* Lightweight weight-distribution histogram. Muted track + subtle accent
   bar; no chart library. Bins are weight ranges, bar length = pack count. */
.tcgd-hist {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 8px;
}
.tcgd-hist-row {
  display: grid;
  grid-template-columns: 96px 1fr 28px;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--tcgd-text-muted);
  font-variant-numeric: tabular-nums;
}
.tcgd-hist-track {
  height: 10px;
  background: var(--tcgd-surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.tcgd-hist-bar {
  display: block;
  height: 100%;
  min-width: 1px;
  background: var(--tcgd-accent);
  opacity: 0.55;
  border-radius: 3px;
}
.tcgd-hist-count { text-align: right; color: var(--tcgd-text-soft); }

/* Card-name affiliate links (TCGplayer). Quiet by default — inherits the
   name's colour with a faint underline so it reads as text but signals it's
   clickable — then resolves to the accent on hover/focus. */
.tcgd-card-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: var(--tcgd-border-strong);
  cursor: pointer;
}
.tcgd-card-link:hover,
.tcgd-card-link:focus-visible {
  color: var(--tcgd-accent-text);
  text-decoration-color: currentColor;
}

/* Hover-to-zoom popup for Contents-tree thumbnails. Body-level fixed-pos
   element (singleton, created in JS on first hover) so it escapes the
   drawer's scroll clip. pointer-events:none so it never steals hover from
   the thumbnail underneath — that would cause a flicker loop. Uses the
   same surface/border/shadow tokens as the drawer for visual continuity. */
.tcgd-thumb-popup {
  position: fixed;
  z-index: 9999;
  width: 240px;
  height: 320px;
  padding: 8px;
  background: var(--tcgd-surface);
  border: 1px solid var(--tcgd-border);
  border-radius: var(--tcgd-radius);
  box-shadow: var(--tcgd-shadow-drawer);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms ease;
}
.tcgd-thumb-popup.tcgd-open { opacity: 1; }
.tcgd-thumb-popup img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Deterministic observations — plain statements, muted. */
.tcgd-obs {
  margin: 4px 0 0;
  padding-left: 18px;
}
.tcgd-obs li {
  color: var(--tcgd-text-soft);
  font-size: 12.5px;
  line-height: 1.5;
  margin: 5px 0;
}

/* ---------- mobile padding override ----------
   Mirrors the Product Explorer's mobile-first padding tightening at
   720px. */
@media (max-width: 720px) {
  #tcgd-research-dashboard { padding: 12px 12px 48px; }

  .tcgd-session-row {
    grid-template-columns: 48px 1fr;
    grid-template-rows: auto auto;
  }
  .tcgd-session-thumb { width: 48px; height: 48px; }
  .tcgd-session-meta {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    text-align: left;
  }
}
