/* PULSE · trends.css: the Trends view (js/views/trends.js) and "Make a graphic"
   (js/story.js). Builds on pulse.css tokens and components (.hero, .block,
   .badge, .chip, .segmented, .method, .empty, .kv, .chart); everything here
   is prefixed tr- (view) or story- (dialog). */

/* ------------------------------------------------------------------ view frame */

.tr, .tr-main, .tr-body { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.tr-chart { min-width: 0; }
.tr-block { display: flex; flex-direction: column; gap: 8px; }
.tr-seg { align-self: flex-start; box-shadow: none; }
.tr-sub { margin: 6px 0 0; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.tr-kvs { display: flex; flex-direction: column; }
.tr-kvs .kv-value .badge { margin-left: 2px; }
.tr-kvs .kv-key { flex: none; white-space: nowrap; }
.tr-kvs .kv-value { min-width: 0; }

/* Actions under a chart: "Make a graphic" as a quiet outlined button. */
.tr-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.tr-graphic {
  display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 4px 11px 4px 9px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: #fff;
  color: var(--navy); font-size: 12.5px; font-weight: 600;
}
.tr-graphic svg { fill: var(--pulse); }
.tr-graphic:hover { border-color: var(--navy); background: var(--wash); }

/* Same-month block: a month picker above the bars. */
.tr-samemonth { display: flex; flex-direction: column; gap: 8px; }
.tr-inline { display: flex; align-items: center; gap: 8px; }
.tr-inline-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.tr-select {
  appearance: none; min-height: 30px; padding: 4px 28px 4px 10px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: #fff url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 8l5 5 5-5' fill='none' stroke='%2355646c' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 7px center/14px;
  color: var(--ink); font-size: 12.5px; font-weight: 600;
}
.tr-select:hover { border-color: var(--navy); }
/* A member counter watched for a possible measurement change: said under the
   change and record line (and in the hero), with the comparison without it. */
.tr-watch-note { margin: 0; padding-left: 8px; border-left: 2px solid var(--line-strong); color: var(--ink-soft); font-size: 12px; line-height: 1.45; }
.hero-sub.tr-watch-note { margin-top: 6px; }

/* ------------------------------------------------------------------ All: the index hero */

.tr-trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 2px; }
.tr-trio-cell { display: flex; flex-direction: column; gap: 1px; padding-top: 7px; border-top: 3px solid var(--mode-c, var(--navy)); min-width: 0; }
.tr-trio-fig { color: var(--navy); font-size: 40px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.05; font-variant-numeric: tabular-nums; }
/* Names wrap rather than clip, so wider text spacing (WCAG 1.4.12) loses nothing. */
.tr-trio-mode { color: var(--ink); font-size: 12.5px; font-weight: 700; overflow-wrap: anywhere; }
.tr-trio-when { color: var(--muted); font-size: 11.5px; }
.tr-trio-cell .badge { align-self: flex-start; margin-top: 5px; }

/* Mode cards: the whole card opens that mode's trends. */
.tr-cards { display: flex; flex-direction: column; gap: 8px; }
.tr-card {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-left: 4px solid var(--mode-c, var(--navy)); border-radius: 10px; background: #fff;
}
.tr-card:hover { border-color: var(--line-strong); border-left-color: var(--mode-c, var(--navy)); background: var(--wash); }
.tr-card-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 9px 4px 9px 11px; border: 0; background: none; text-align: left; }
.tr-card-main::after { content: ""; position: absolute; inset: 0; border-radius: 10px; }
.tr-card-main:focus-visible { outline: none; }
.tr-card-main:focus-visible::after { outline: 3px solid var(--accent); outline-offset: 2px; }
.tr-card-head { display: flex; align-items: center; gap: 6px; }
.tr-card-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mode-c, var(--navy)); }
.tr-card-mode { color: var(--ink); font-size: 12.5px; font-weight: 700; }
.tr-card-fig { color: var(--navy); font-size: 22px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tr-card-text { color: var(--ink-soft); font-size: 12px; line-height: 1.35; }
.tr-card-change { color: var(--ink); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tr-card-go { margin-top: 2px; color: var(--accent); font-size: 12px; font-weight: 600; }
.tr-card:hover .tr-card-go { text-decoration: underline; }
.tr-card-spark { padding-right: 10px; pointer-events: none; }
.tr-card-spark .chart-spark { display: block; }

/* ------------------------------------------------------------------ ranked lists (TEAM's .rank-list) */

.tr-rank { display: flex; flex-direction: column; gap: 1px; margin: 0; padding: 0; list-style: none; counter-reset: rank; }
.tr-rank li { counter-increment: rank; }
.tr-rank-row {
  display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; grid-template-areas: "n name meta" "n bar bar" "n reason reason";
  column-gap: 8px; width: 100%; padding: 6px 6px; border: 0; border-radius: 8px; background: none; color: inherit; text-align: left; font-size: 12.5px;
}
button.tr-rank-row:hover { background: var(--wash); }
.tr-rank-row::before { content: counter(rank); grid-area: n; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; line-height: 1.6; }
.tr-rank.is-unranked .tr-rank-row::before { content: "–"; }
.tr-rank-name { grid-area: name; min-width: 0; color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.tr-rank-meta { grid-area: meta; color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tr-rank-bar { grid-area: bar; height: 5px; margin: 4px 0 1px; background: var(--track); border-radius: 2px; overflow: hidden; }
.tr-rank-fill { display: block; height: 100%; background: var(--fill, var(--navy)); border-radius: 0 3px 3px 0; }
.tr-rank-reason { grid-area: reason; margin-top: 1px; color: var(--muted); font-size: 11.5px; }
.tr-movers { display: flex; flex-direction: column; gap: 4px; }

.tr-details { border-top: 1px solid var(--line); padding-top: 6px; }
.tr-details > summary { cursor: pointer; color: var(--accent); font-size: 12.5px; font-weight: 600; }
.tr-details > summary:hover { color: var(--navy); }
.tr-details[open] > summary { margin-bottom: 6px; color: var(--ink); }
.tr-plain { display: flex; flex-direction: column; gap: 4px; margin: 0; padding-left: 16px; color: var(--ink-soft); font-size: 12px; line-height: 1.4; }
.tr-plain strong { color: var(--ink); font-weight: 600; }

/* ------------------------------------------------------------------ selected place */

.tr-selected { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 12px; border: 1px solid var(--line); border-left: 3px solid var(--pulse); border-radius: 10px; background: #fcfcfb; }
.tr-selected-head .eyebrow { color: var(--pulse-ink); }
.tr-selected-title { margin: 0; color: var(--navy); font-size: 16px; line-height: 1.25; }

/* ------------------------------------------------------------------ Make a graphic */

.story {
  width: min(1120px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); padding: 0;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); color: var(--ink); overflow: hidden;
}
.story[open] { display: flex; flex-direction: column; }
.story::backdrop { background: rgba(12, 12, 72, 0.45); }
.story-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 12px 22px; border-bottom: 1px solid var(--line); }
.story-head .eyebrow { color: var(--pulse-ink); }
.story-head h2 { margin: 0; color: var(--navy); font-size: 20px; line-height: 1.2; }
.story-sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.story-body { display: grid; grid-template-columns: 340px minmax(0, 1fr); flex: 1 1 auto; min-height: 0; }
.story-controls { display: flex; flex-direction: column; gap: 14px; min-height: 0; padding: 16px 18px 18px 22px; overflow-y: auto; overscroll-behavior: contain; border-right: 1px solid var(--line); }
.story-preview { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-width: 0; min-height: 0; margin: 0; padding: 18px; background: var(--wash); }
.story-stage { display: grid; place-items: center; width: 100%; min-height: 0; flex: 1 1 auto; }
.story-image { display: block; width: auto; height: auto; max-width: 100%; max-height: calc(100dvh - 32px - 70px - 76px); aspect-ratio: 4 / 5; background: #fff; box-shadow: 0 2px 14px rgba(12, 12, 72, 0.14); }
.story-caption { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.story-preview .empty { max-width: 360px; }

.story-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.story-label { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.01em; }
.story-hint { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.story-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.story-slot { min-width: 0; }
.story-look { display: flex; flex-wrap: wrap; gap: 12px 18px; }
.story-look .story-field { flex: 0 1 auto; }
.story-select, .story-input {
  width: 100%; min-height: 34px; padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink); font: inherit; font-size: 13px;
}
.story-select {
  appearance: none; padding-right: 28px; font-weight: 600;
  background: #fff url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 8l5 5 5-5' fill='none' stroke='%2355646c' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 8px center/14px;
}
.story-select:hover, .story-input:hover { border-color: var(--navy); }
.story-input:focus-visible, .story-select:focus-visible { outline-offset: 0; }
.story-textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
.story-words { display: flex; flex-direction: column; gap: 10px; }
.story-rewrite { align-self: flex-start; min-height: 24px; padding: 2px 0; font-size: 12.5px; }
.story-seg { align-self: flex-start; box-shadow: none; }
.story-seg button { padding: 4px 9px; font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.story-check { font-size: 12.5px; color: var(--ink-soft); }

.story-templates { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.story-template {
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; padding: 8px 4px 7px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: #fff; color: var(--ink-soft); font-size: 11.5px; font-weight: 600; line-height: 1.2; text-align: center;
}
.story-template:hover { border-color: var(--navy); color: var(--navy); }
.story-template[aria-checked="true"] { border-color: var(--navy); background: var(--navy); color: #fff; }
.story-template svg { display: block; }
.story-template .is-grey { fill: #c3c8c6; }
.story-template .is-accent { fill: var(--pulse); }
.story-template .is-grey-line { fill: none; stroke: #b3bab8; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.story-template .is-accent-line { fill: none; stroke: var(--pulse); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.story-template[aria-checked="true"] .is-grey { fill: rgba(255, 255, 255, 0.45); }
.story-template[aria-checked="true"] .is-grey-line { stroke: rgba(255, 255, 255, 0.5); }
.story-template[aria-checked="true"] .is-accent { fill: #ff6a6a; }
.story-template[aria-checked="true"] .is-accent-line { stroke: #ff6a6a; }
.story-template-label { max-width: 100%; overflow-wrap: anywhere; }

.story-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.story-button {
  min-height: 36px; padding: 7px 14px; border: 1px solid var(--line-strong); border-radius: 9px; background: #fff;
  color: var(--navy); font-size: 13px; font-weight: 700;
}
.story-button:hover { border-color: var(--navy); background: var(--wash); }
.story-button.is-primary { border-color: var(--navy); background: var(--navy); color: #fff; }
.story-button.is-primary:hover { background: #1b1b66; }
.story-button:disabled { opacity: 0.6; cursor: progress; }
.story-status { min-height: 1.45em; }

/* ------------------------------------------------------------------ small screens */

@media (max-width: 900px) {
  .story-body { grid-template-columns: 300px minmax(0, 1fr); }
}

@media (max-width: 760px) {
  .tr-trio-fig { font-size: 34px; }
  .story { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .story-head { padding: 12px 12px 10px 16px; }
  .story-body { display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; }
  .story-preview { order: -1; flex: 0 0 auto; padding: 12px; }
  .story-image { max-height: 46dvh; }
  .story-controls { flex: 0 0 auto; padding: 14px 16px 22px; overflow: visible; border-right: 0; }
  .story-select, .story-input { font-size: 16px; }
}
