/* ==========================================================================
   Trade dashboard (/trade): headline figures, server-rendered SVG charts and
   product bars. Builds on the tokens in site.css (ink #2A1B45, accent #6E42A6,
   Newsreader for headings, Inter for the rest).
   Flow colours, used for marks only (text stays in ink / muted):
     US exports  #6E42A6 (accent)   US imports  #1A9E8F (teal)
   The pair passes the dataviz palette checks (lightness band, colour-blind
   separation, 3:1 contrast on white).
   ========================================================================== */

.tr { --tr-exports: #6E42A6; --tr-imports: #1A9E8F; padding: var(--s-4) 0 var(--s-5); background: var(--paper); }
.tr-hero { --tr-exports: #6E42A6; --tr-imports: #1A9E8F; }
.tr-hero h1 { font-family: var(--font-serif); font-weight: 500; letter-spacing: -0.02em; }
.tr-checked { margin: var(--s-2) 0 0; font-size: 0.82rem; letter-spacing: 0.04em; color: var(--on-ink-muted); }
.tr-icon { display: inline-block; vertical-align: -2px; flex-shrink: 0; }
.tr-muted { color: var(--muted); font-weight: 400; }
.tr-h2 { margin: 0; font-family: var(--font-serif); font-weight: 500; font-size: clamp(1.45rem, 2.2vw, 1.85rem); letter-spacing: -0.01em; line-height: 1.2; color: var(--ink); }
.tr-section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.4rem 2rem; margin-bottom: var(--s-3); }
.tr-sub { margin: 0; font-size: 0.9rem; color: var(--muted); max-width: 56ch; }
.tr-section { padding: 0 0 var(--s-4); margin-bottom: var(--s-4); border-bottom: 1px solid var(--line); }

/* Swatches (legend and headline labels). */
.tr-sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0; }
.tr-sw-exports { background: var(--tr-exports); }
.tr-sw-imports { background: var(--tr-imports); }

/* ------------------------------------------------------------ Headline */

.tr-kpis { padding: 0 0 var(--s-4); margin-bottom: var(--s-4); border-bottom: 1px solid var(--line); }
.tr-kpi-grid { margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 var(--s-3); border-top: 2px solid var(--ink); }
.tr-kpi { padding: var(--s-2) 0 0; min-width: 0; }
.tr-kpi dt { display: flex; align-items: center; gap: 0.45rem; font-size: 0.76rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.tr-kpi dd { margin: 0; }
.tr-kpi-value { margin-top: 0.45rem !important; font-size: clamp(1.9rem, 3.2vw, 2.6rem); font-weight: 600; line-height: 1.05; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.tr-kpi-note { margin-top: 0.5rem !important; font-size: 0.86rem; line-height: 1.5; color: var(--text); }
.tr-kpi-change { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tr-kpi-balance .tr-kpi-note strong { color: var(--ink); }

/* -------------------------------------------------------------- Charts */

.tr-chart { margin: 0; }
.tr-chart-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.4rem 1.5rem; margin-bottom: 0.75rem; }
.tr-chart-title { margin: 0; font-size: 1rem; font-weight: 600; color: var(--ink); }
.tr-chart-sub { margin: 0; font-size: 0.84rem; color: var(--muted); flex-basis: 100%; }
.tr-chart-note { margin: 0.4rem 0 0; font-size: 0.8rem; color: var(--muted); }
.tr-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 0.84rem; color: var(--text); }
.tr-legend li { display: inline-flex; align-items: center; gap: 0.45rem; }

.tr-plot { position: relative; }
.tr-svg { display: none; width: 100%; height: auto; overflow: visible; font-family: var(--font); }
.tr-svg-s { display: block; }
@media (min-width: 600px) { .tr-svg-s { display: none; } .tr-svg-m { display: block; } }
@media (min-width: 980px) { .tr-svg-m { display: none; } .tr-svg-l { display: block; } }

.tr-grid { stroke: #ECE8F1; stroke-width: 1; }
.tr-base { stroke: #B9B2C6; stroke-width: 1; }
.tr-xtick { stroke: #B9B2C6; stroke-width: 1; }
.tr-tick { font-size: 12px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.tr-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.tr-line-exports { stroke: var(--tr-exports); }
.tr-line-imports { stroke: var(--tr-imports); }
.tr-dot, .tr-end { stroke: #fff; stroke-width: 2; }
.tr-dot-exports { fill: var(--tr-exports); }
.tr-dot-imports { fill: var(--tr-imports); }
.tr-dot, .tr-guide { opacity: 0; }
.tr-guide { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; }
.tr-col:hover .tr-dot, .tr-col:hover .tr-guide, .tr-col.is-active .tr-dot, .tr-col.is-active .tr-guide { opacity: 1; }
.tr-hit { fill: transparent; }
.tr-endlabel { font-size: 12px; font-weight: 600; fill: var(--ink); }
.tr-endvalue { font-size: 12px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.tr-bar-exports { fill: var(--tr-exports); background: var(--tr-exports); }
.tr-bar-imports { fill: var(--tr-imports); background: var(--tr-imports); }
.tr-bar.is-partial { fill-opacity: 0.45; }
.tr-col:hover .tr-hit, .tr-col.is-active .tr-hit { fill: rgba(42, 27, 69, 0.04); }

/* Tooltip (public/assets/js/trade.js). */
.tr-tip {
  position: absolute; z-index: 5; pointer-events: none; max-width: 16rem; padding: 0.5rem 0.7rem; border-radius: 4px;
  background: var(--ink); color: #fff; font-size: 0.8rem; line-height: 1.45; white-space: pre-line; box-shadow: 0 10px 26px -12px rgba(20, 10, 40, 0.6);
}
.tr-tip[hidden] { display: none; }
.tr-tip strong { display: block; font-weight: 600; }

/* Data tables. */
.tr-data { margin-top: 0.75rem; font-size: 0.88rem; }
.tr-data > summary { cursor: pointer; font-weight: 600; color: var(--accent-dark); width: max-content; }
.tr-data > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tr-table-wrap { max-height: 24rem; overflow: auto; margin-top: 0.6rem; border: 1px solid var(--line); }
.tr-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tr-table th, .tr-table td { padding: 0.4rem 0.7rem; text-align: left; border-bottom: 1px solid var(--line); font-weight: 400; }
.tr-table thead th { position: sticky; top: 0; background: var(--mist); font-weight: 600; color: var(--ink); }
.tr-table tbody th { font-weight: 500; color: var(--ink); }
.tr-table .num { text-align: right; white-space: nowrap; }

/* ------------------------------------------------------- Top goods bars */

.tr-goods-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s-4); }
.tr-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; counter-reset: tr; }
.tr-bars-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.2rem; padding: 0.15rem 0.3rem; border-radius: 2px; }
.tr-bars-row:hover { background: var(--mist); }
.tr-bars-label { font-size: 0.88rem; line-height: 1.3; color: var(--text); }
.tr-bars-track { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.tr-bars-bar { display: block; height: 12px; min-width: 2px; border-radius: 0 4px 4px 0; flex-shrink: 0; max-width: calc(100% - 8.5rem); }
.tr-bars-value { font-size: 0.84rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------------------------------------------- Downloads, method */

.tr-downloads { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem; margin: 0 0 var(--s-4); font-size: 0.88rem; }
.tr-downloads a { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 600; color: var(--accent-dark); text-decoration: none; }
.tr-downloads a:hover { text-decoration: underline; }
.tr-downloads .tr-muted { flex-basis: 100%; font-size: 0.8rem; }
.tr-method { max-width: 52rem; padding: var(--s-3) var(--s-3) var(--s-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); background: var(--mist); }
.tr-method .tr-h2 { font-size: 1.35rem; margin-bottom: 0.6rem; }
.tr-method ul { margin: 0.6rem 0; padding-left: 1.1rem; font-size: 0.93rem; line-height: 1.6; }
.tr-method li { margin: 0.4rem 0; }
.tr-source { margin: 0; font-size: 0.93rem; line-height: 1.55; }
.tr-source strong { font-weight: 600; color: var(--ink); }
.tr-links { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin: 0.8rem 0 0.4rem; font-size: 0.88rem; }
.tr-links a { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--accent-dark); font-weight: 600; }

/* --------------------------------------------------------------- Empty */

.tr-empty { max-width: 44rem; margin: 0 auto var(--s-4); padding: var(--s-4) 0 var(--s-2); text-align: center; }
.tr-empty-icon { display: inline-grid; place-items: center; width: 4rem; height: 4rem; margin-bottom: 0.8rem; border-radius: 50%; background: var(--mist); color: var(--accent); }
.tr-kicker { margin: 0 0 0.4rem; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--accent-dark); }
.tr-empty h2 { margin: 0 0 0.6rem; font-family: var(--font-serif); font-weight: 500; font-size: clamp(1.6rem, 2.8vw, 2.2rem); color: var(--ink); }
.tr-empty p { color: var(--muted); line-height: 1.6; }
.tr-empty a { color: var(--accent-dark); font-weight: 600; }

@media (max-width: 960px) {
  .tr-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tr-kpi:nth-child(n + 3) { border-top: 1px solid var(--line); margin-top: var(--s-2); }
  .tr-goods-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .tr-kpi-grid { grid-template-columns: minmax(0, 1fr); }
  .tr-kpi:nth-child(n + 2) { border-top: 1px solid var(--line); margin-top: var(--s-2); }
  .tr-method { padding: var(--s-2); }
  .tr-table th, .tr-table td { padding: 0.35rem 0.5rem; }
}
@media print {
  .tr-downloads, .tr-tip { display: none; }
  .tr-data { display: none; }
  .tr-svg-s, .tr-svg-m { display: none !important; }
  .tr-svg-l { display: block !important; }
}
@media (forced-colors: active) {
  .tr-line-exports, .tr-line-imports { stroke: CanvasText; }
  .tr-line-imports { stroke-dasharray: 6 4; }
  .tr-bar-exports, .tr-bar-imports, .tr-bars-bar, .tr-sw { forced-color-adjust: none; }
}
