/* Clash Royale Stats 3.1.0 - Trends screen (T4-002 / R-006).

   Screen-specific layout only. Every colour, radius, font and control surface
   comes from web/css/tokens.css + web/css/components.css (.card, .card-head,
   .card-title, .card-sub, .seg.views, .info-tip, .chip, .btn, .tag, .meter);
   nothing here redefines a token or a component class. Rules are scoped to
   `#trends-body` (the element web/screens/trends.js mounts into) so they can
   never reach the #trends-live slot, the shell, or another screen. The blocks
   Home shed (modes, charts, compare, ranked, push) were ported with their
   3.0.0 rules, `home-*` classes renamed `trends-*`.

   Layout ladder:
     <768      one column, 12px gap between cards; the sub-view tabs are full width
     768-1023  the same, with taller charts
     >=1024    sidebar layout: two-column card pairs; the Compare periods button
               lives in the shell's top-bar actions slot (the in-page chip is
               hidden)

   Type floor (R-002/R-005): 11px only for uppercase `.eyebrow`; every other
   string on this screen is >=12px. */

/* ---------- stack ---------- */

#trends-body .trends-grid { display: flex; flex-direction: column; gap: 12px; }
#trends-body .trends-stack,
#trends-body .trends-section { display: flex; flex-direction: column; gap: 12px; }

/* The tab control carries its own 16px bottom margin (components.css); inside
   this stack the gap does that job. */
#trends-body .trends-tabs .seg.views { margin-bottom: 0; }

#trends-body .trends-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#trends-body .trends-actions:empty { display: none; }

/* An empty window / a failed /overview, shared by Progress and Form: one block
   instead of a page of empty charts. */
#trends-body .trends-status {
  background: var(--s1);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px 20px;
  text-align: center;
  color: var(--ink-2);
}
#trends-body .trends-status .h2 { margin-bottom: 6px; display: block; }
#trends-body .trends-status .trends-error { align-items: center; }

/* The one failure shape: the endpoint's message in the app-wide red, then Retry. */
#trends-body .trends-error { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
#trends-body .trends-error .error-text { margin-top: 0; }

/* ---------- shared card furniture ---------- */

#trends-body .card-head { margin-bottom: 8px; }
#trends-body .trends-tip-slot { display: inline-flex; flex: none; }
#trends-body .trends-tip-slot:empty { display: none; }
#trends-body .trends-head-tool { flex: none; }
#trends-body .trends-head-tool.hidden { display: none; }

/* (No `.seg button` height rule here: components.css already floors every seg
   button at 36px and the view tabs at 40px - a more specific rule in this file
   would silently shrink the tabs.) */

#trends-body .trends-chart { position: relative; height: 180px; }
#trends-body .trends-chart.tall { height: 220px; }

#trends-body .trends-legend { display: flex; gap: 10px; font-size: 12px; color: var(--ink-2); flex: none; }
#trends-body .trends-legend .key { display: inline-flex; align-items: center; gap: 4px; }
#trends-body .trends-legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* CRUI.pctSpan output. `.good`/`.bad` come from components.css; the low-sample
   muting (grey + italic + the asterisk pctSpan already appends) is the honesty
   affordance and must win over both. */
#trends-body .pct { font-weight: 800; font-variant-numeric: tabular-nums; }
#trends-body .pct.low-sample,
#trends-body .pct.low-sample.good,
#trends-body .pct.low-sample.bad { color: var(--ink-3); font-style: italic; }

#trends-body .trends-skel-bar { height: 12px; border-radius: 6px; }
#trends-body .trends-skel-stack { display: flex; flex-direction: column; gap: 8px; }

/* ---------- trophy card (Progress) ---------- */

#trends-body .trends-figures {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 10px;
  min-width: 0;
  margin-bottom: 6px;
}
#trends-body .trends-trophy-value { font-size: 30px; }
#trends-body .trends-trophy-delta { display: inline-flex; align-items: center; gap: 3px; flex-wrap: wrap; }

/* The pointer to Ranked (the Trophy Road blocks do not apply under that filter). */
#trends-body .trends-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 13px;
}
#trends-body .trends-note-link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 36px;
  color: var(--gold);
  font-weight: 800;
  font-size: 13px;
}
#trends-body .trends-pace { line-height: 1.45; }

/* A failed /trophy-push: one error block in the pace card; the two charts have
   nothing to draw. */
#trends-body .trends-section.is-error > .trends-push-chart { display: none; }

#trends-body .trends-retry { align-self: flex-start; }

/* ---------- KPI tiles (Ranked) ---------- */

#trends-body .trends-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
#trends-body .trends-tile {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  min-width: 0;
}
#trends-body .trends-tile .trends-tile-value { font-size: 24px; }
/* No colour here: the sub-line carries `.good`/`.bad`/`.muted` itself. */
#trends-body .trends-tile .trends-tile-sub {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
  min-width: 0;
}
/* W/L/D is always text + colour (R-005) and must never be clipped. */
#trends-body .trends-wld {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px 4px;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

/* ---------- more stats ---------- */

#trends-body .trends-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 12px;
}
#trends-body .trends-stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#trends-body .trends-stat .trends-stat-value {
  font-size: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#trends-body .trends-stat .trends-stat-sub {
  font-size: 12px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- modes ---------- */

#trends-body .trends-mode-list { display: flex; flex-direction: column; }
#trends-body .trends-mode-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
}
#trends-body .trends-mode-row:first-child { border-top: 0; }
#trends-body .trends-mode-row .tag { width: 104px; justify-content: center; flex: none; }
#trends-body .trends-mode-row .trends-mode-games {
  width: 44px;
  text-align: right;
  flex: none;
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
#trends-body .trends-mode-row .meter { flex: 1 1 auto; height: 6px; }
#trends-body .trends-mode-row .pct { width: 46px; text-align: right; flex: none; font-size: 12px; }
#trends-body .trends-mode-row .meter.is-good .fill { background: var(--good); }
#trends-body .trends-mode-row .meter.is-bad .fill { background: var(--bad); }
#trends-body .trends-mode-row .meter.is-low .fill { background: var(--ink-3); }

#trends-body .trends-mode-row .trends-mode-name {
  width: 104px;
  flex: none;
  font-size: 12px;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Raw (type, gameMode) rows sit under their category header. */
#trends-body .trends-mode-sub { padding-left: 12px; }
#trends-body .trends-mode-sub .trends-mode-name { width: 92px; color: var(--ink-3); }

/* ---------- compare ---------- */

/* The three presets are short words ("Month", "7 days", "30 days"; the full
   wording is each button's title), so the group is ONE row at any width. Its
   padding is 1px, not the 3px of a plain .seg: the 36px buttons keep their
   touch height and the whole control is 40px tall, a quiet secondary control
   under the panel header rather than a second set of view tabs. */
#trends-body .trends-compare-presets { margin-bottom: 10px; max-width: 100%; }
#trends-body .trends-compare-presets .seg { padding: 1px; max-width: 100%; }
#trends-body .trends-compare-presets .seg button { border-radius: 9px; }

/* The fourth button (90 days / Last month: trends.js sets `has-extra`) makes the row
   305px of buttons at their normal padding; the card's content is 254px wide on a 320px
   phone and 294px on a 360px one, so "Last month" stuck out of the pill, then the card,
   then the screen (T4-037). Below 375px the pill fills the card's content box and the
   four buttons share it: 4px of side padding is all the narrowest 320px needs, and any
   room beyond it is spread evenly, so the row is the card's width at every size down to
   ~308px, with no inner scroller (all four buttons are always on screen, none is faded
   or clipped). From 375px up the row is exactly what it was: a natural-width pill. */
@media (max-width: 374px) {
  #trends-body .trends-compare-presets.has-extra .seg { display: flex; width: 100%; }
  #trends-body .trends-compare-presets.has-extra .seg button {
    flex: 1 1 auto;
    justify-content: center;
    padding-left: 4px;
    padding-right: 4px;
  }
}
#trends-body .trends-compare-deltas { display: flex; flex-direction: column; }
/* Dates and game counts of the two windows: the panel's footnote. */
#trends-body .trends-compare-caption { margin-top: 10px; line-height: 1.4; }
#trends-body .trends-compare-caption:empty { display: none; }
/* The panel's in-flight / failed state (F2R2-02): one line of text, and on
   failure the Retry button under it - this panel has no other trigger, so the
   button is the only way back from a dropped request. */
#trends-body .trends-compare-status {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 4px 0;
}
#trends-body .trends-compare-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
#trends-body .trends-compare-row:first-child { border-top: 0; }
#trends-body .trends-compare-label { flex: 1 1 auto; color: var(--ink-2); font-weight: 700; }
#trends-body .trends-compare-val { flex: none; color: var(--ink); font-variant-numeric: tabular-nums; }
#trends-body .trends-delta-chip {
  flex: none;
  min-width: 62px;
  text-align: right;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
#trends-body .trends-delta-chip.good { color: var(--good); }
#trends-body .trends-delta-chip.bad { color: var(--bad); }

/* The desktop compare button lives in the shell's top-bar actions slot; this
   rule matches nothing but that one button (it is hidden while the in-page chip
   is the one on screen). */
#topbar-actions .trends-compare-btn { display: none; }

/* Compare periods, PRESSED: a quiet gold outline with gold text and a faint
   wash - never the solid gold fill the active view tab and the preset seg use,
   so three "on" controls do not stack within one screen of a phone. Covers both
   places the toggle lives (the phone's in-page chip and the desktop top-bar
   button). */
#trends-body .trends-actions .chip[aria-pressed="true"],
#topbar-actions .trends-compare-btn[aria-pressed="true"] {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
}

/* ---------- empty charts / scope lines ---------- */

/* ONE muted line standing in for a chart that has nothing to plot. */
#trends-body .trends-chart-empty { padding: 18px 0 6px; line-height: 1.45; }

/* What a view's numbers cover (Ranked: "Path of Legends only · 30 days"); it
   sits tight above the figures it describes. */
#trends-body .trends-scope { margin-bottom: -4px; line-height: 1.4; }

/* ---------- 768-1023: taller charts ---------- */

@media (min-width: 768px) {
  #trends-body .trends-chart { height: 200px; }
  #trends-body .trends-chart.tall { height: 240px; }
  #trends-body .trends-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- >=1024: sidebar layout ---------- */

@media (min-width: 1024px) {
  /* The shell pads `.content` (16px under the top bar); the screen adds no top
     offset of its own, or it would double. */
  #trends-body .trends-grid { gap: 16px; }
  #trends-body .trends-compare-deltas,
  #trends-body .trends-compare-caption { max-width: 640px; }
  #trends-body .trends-scope { margin-bottom: -6px; }
  #trends-body .trends-stack,
  #trends-body .trends-section {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
  }
  #trends-body .trends-stack > *,
  #trends-body .trends-section > .trends-span-full { grid-column: 1 / -1; }
  
  #trends-body .trends-chart { height: 220px; }
  #trends-body .trends-chart.tall { height: 260px; }
  #trends-body .trends-trophy-value { font-size: 34px; }
  #trends-body .trends-stats { grid-template-columns: repeat(6, minmax(0, 1fr)); }

  /* The in-page compare chip is the phone's; the top bar carries it here. */
  #trends-body .trends-actions { display: none; }
  #topbar-actions .trends-compare-btn { display: inline-flex; }

  #trends-body .trends-tiles .trends-tile {
    background: var(--s1);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px 16px;
    gap: 6px;
    justify-content: center;
  }
  #trends-body .trends-tiles .trends-tile-value { font-size: 34px; }
}
