/* Country Analysis dashboard.
 *
 * Layered on tokens.css + app.css: the masthead, .btn, .cap, .note, .tick and
 * .source primitives are shared with the globe so the two pages read as one
 * product. Only what the dashboard adds lives here — a two-column shell with a
 * scrolling document of panels, and the table and chart furniture that goes
 * with it.
 *
 * The house rule from app.css carries over: figures that get compared share a
 * column width (tabular-nums, enforced last in this file).
 */

.layout.country { display: grid; grid-template-columns: 268px 1fr; flex: 1; min-height: 0; position: relative; }
/* Nothing to browse when the section is locked: the rail goes, and its column
 * with it (assets/js/ui/lockedPage.js). */
.layout.country.locked { grid-template-columns: 1fr; }

/* ---------- left rail ---------- */
.rail .search-box {
  display: flex; align-items: center; gap: var(--sp-6);
  border: 1px solid var(--line-strong); border-radius: var(--r); padding: 0 var(--sp-8);
  background: var(--panel-strong);
}
.rail .search-box .i { color: var(--ink-mute); flex: none; }
.rail .search-box input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font: 400 var(--fs) var(--font-ui); padding: 7px 0;
}
.rail .search-box input:focus { outline: none; }
.rail .search-box:focus-within { box-shadow: var(--focus-ring); }

.c-list { display: flex; flex-direction: column; overflow-y: auto; }
/* The group head does two jobs: it names the producer / non-producer split
 * that the rows below no longer spell out, and it labels the code column. */
.c-list .grp {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-8);
  padding: var(--sp-12) var(--sp-6) var(--sp-4);
  position: sticky; top: 0; background: var(--panel); z-index: 1;
  border-bottom: 1px solid var(--line);
}
.c-list .grp-lbl { min-width: 0; }
.c-list .grp-key { color: var(--ink-faint); white-space: nowrap; flex: none; }
.c-row {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--sp-8);
  line-height: 1.3;
  padding: var(--sp-6); border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--ink-dim); cursor: pointer; text-align: left;
  font: 400 var(--fs) var(--font-ui);
  transition: padding var(--dur-row) var(--ease-enter), background var(--dur-row) linear;
}
.c-row:hover { background: var(--bg-2); padding-left: var(--sp-12); color: var(--ink); }
.c-row.on { background: var(--ink); color: var(--bg); }
/* Names wrap rather than truncate. "Democratic Republic of the Congo" and
 * "Lao People's Democratic Republic" are the reason: an ellipsis on a
 * directory row hides exactly the words that tell two entries apart. */
.c-row .nm { min-width: 0; overflow-wrap: anywhere; }
.c-row .tag {
  font: 400 var(--fs-cap) var(--font-mono); color: var(--ink-mute);
  letter-spacing: 0.06em; white-space: nowrap; align-self: center;
}
/* An ISO code standing in where the registry holds no ICO code. */
.c-row .tag.sub { font-style: italic; opacity: 0.75; }
.c-row.on .tag { color: var(--bg); opacity: 0.7; }
/* A reporter that has stopped filing. The year it stopped replaces the ISO
 * code, because that is the fact a reader needs before opening it. */
.c-row .tag.stale { color: var(--gold); }
.stale-flag { color: var(--gold); text-transform: capitalize; }

/* ---------- producer / market nature ----------
 * One colour language for a country's role, matching the globe's own
 * encoding: origins are the warm family, importing markets the green one.
 * The dot rides every directory row (searching flattens the groups, so the
 * grouping alone cannot carry it); the chip sits beside the country name. */
.c-row { grid-template-columns: auto 1fr auto; }
.role-dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--ink-faint);
}
.c-row .role-dot { align-self: center; }
.role-dot.role-producer { background: var(--viz-origin); }
.role-dot.role-importer { background: var(--viz-importer); }
.role-dot.role-both { background: linear-gradient(135deg, var(--viz-origin) 50%, var(--viz-importer) 50%); }

.role-chip {
  display: inline-flex; align-items: center; gap: var(--sp-6);
  font: 500 var(--fs-cap) var(--font-mono); letter-spacing: 0.05em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; vertical-align: middle;
  border: 1px solid var(--line-strong); color: var(--ink-dim); white-space: nowrap;
}
.role-chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); }
.role-chip.role-producer::before { background: var(--viz-origin); }
.role-chip.role-importer::before { background: var(--viz-importer); }
.role-chip.role-both::before { background: linear-gradient(135deg, var(--viz-origin) 50%, var(--viz-importer) 50%); }
.c-title .role-chip { position: relative; top: -4px; }

/* ---------- document ---------- */
.doc { position: relative; overflow-y: auto; background: var(--bg); scroll-behavior: smooth; }
#content > * { max-width: 1180px; margin: 0 auto; }
/* The locked stand-in (assets/js/ui/lockedPage.js) is a standalone message,
 * not a document panel: hold it to a readable measure. The rule above is
 * id-specific, so this one has to be too. */
#content > .locked-panel { max-width: 52ch; }

.c-title {
  display: flex; align-items: baseline; gap: var(--sp-12); flex-wrap: wrap;
  padding: var(--sp-24) var(--sp-24) var(--sp-16);
  border-bottom: 1px solid var(--line-strong);
}
.c-title h2 { margin: 0; font: 300 var(--fs-display)/1 var(--font-ui); letter-spacing: -0.02em; }
.c-title .meta {
  font: 400 var(--fs-cap) var(--font-mono); letter-spacing: var(--track-cap);
  text-transform: uppercase; color: var(--ink-mute);
}

.panel { padding: var(--sp-24); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: var(--sp-12); }
.panel-head { display: flex; flex-direction: column; gap: var(--sp-4); }
.panel-head .cap { font-size: var(--fs-cap-lg); color: var(--ink); }
/* Title and its download sit on one baseline; the title takes the slack so the
 * button stays hard right, and wraps under on a narrow column. */
.panel-title { display: flex; align-items: baseline; gap: var(--sp-12); flex-wrap: wrap; }
.panel-title .cap { flex: 1 1 auto; margin: 0; }
.btn.sm { padding: 3px var(--sp-8); font-size: var(--fs-cap-xs); }
.cap.sub { color: var(--ink-dim); letter-spacing: var(--track-cap); margin: 0 0 var(--sp-6); font-weight: 400; }
.cap.sub2 { color: var(--ink-mute); margin-top: var(--sp-8); }
.note.warn { color: var(--danger); }

/* ---------- headline stats ---------- */
.headline { padding: var(--sp-20) var(--sp-24); background: var(--panel-strong); border-bottom: 1px solid var(--line-strong); }
/* Dividers are drawn INSIDE each tile rather than by a 1px gap over a coloured
 * container: the tile count varies by country (an importer has no production
 * or export tile), and gap-as-border leaves the unfilled cells of the last row
 * showing as solid blocks. */
.hstats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
}
.hstat {
  padding: var(--sp-12) var(--sp-12) var(--sp-10);
  box-shadow: inset -1px 0 0 var(--line), inset 0 -1px 0 var(--line);
}
.hstat .k { font: 400 var(--fs-cap-xs) var(--font-mono); letter-spacing: var(--track-cap); text-transform: uppercase; color: var(--ink-mute); }
.hstat .v { font: 300 var(--fs-display-sm)/1.1 var(--font-ui); letter-spacing: -0.01em; margin-top: var(--sp-4); }
.hstat .s { font: 400 var(--fs-cap) var(--font-mono); color: var(--ink-mute); margin-top: var(--sp-4); min-height: 1.2em; }
.hstat.warn .v { color: var(--gold); }
.hstat.alarm .v { color: var(--danger); }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }
.est, .vint { color: var(--ink-faint); font-style: italic; }

/* ---------- specification grid ---------- */
.spec-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
}
.spec-row { background: var(--panel); padding: var(--sp-8) var(--sp-12); display: flex; gap: var(--sp-12); align-items: baseline; }
.spec-row .k {
  font: 400 var(--fs-cap-xs) var(--font-mono); letter-spacing: var(--track-cap); text-transform: uppercase;
  color: var(--ink-mute); flex: none; width: 128px;
}
.spec-row .v { font-size: var(--fs); color: var(--ink-dim); }

/* ---------- charts ---------- */
.chart { width: 100%; }
.chart svg { display: block; overflow: visible; }
.chart .tick-lbl { font: 400 var(--fs-cap-sm) var(--font-mono); letter-spacing: 0.04em; }
.two-up { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: var(--sp-24); }
.chart-block { min-width: 0; display: flex; flex-direction: column; }


/* Serving from a mirror rather than the trade line of truth. Amber, not red:
 * the figures are usable, they are just not the published copy. */
.source.warn .s { color: var(--gold); }
.source.warn { color: var(--gold); }

/* Chart tooltip. Fixed, not absolute: the charts sit in a scrolling document,
 * and the pointer event already reports viewport coordinates. One node is
 * shared by every chart on the page. */
.chart-tip {
  position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none;
  min-width: 172px; max-width: 260px;
  background: var(--panel-tooltip); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r);
  padding: var(--sp-8) var(--sp-10); box-shadow: var(--shadow-tooltip);
  /* No fade. A readout that tracks the cursor should not lag it, and — the
   * reason this is a rule rather than a preference — a transition does not
   * advance in a document that is not being rendered, so a faded-in tooltip
   * can be stuck at opacity 0 with its content already correct. Same failure
   * mode as an opacity entrance animation on a table row. */
  visibility: hidden;
}
.chart-tip.show { visibility: visible; }
.chart-tip .t-name {
  font: 500 var(--fs) var(--font-ui); margin-bottom: var(--sp-6);
  padding-bottom: var(--sp-4); border-bottom: 1px solid var(--line);
}
.chart-tip .t-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-12);
  font-size: var(--fs-sm); color: var(--ink-dim); line-height: 1.7;
}
.chart-tip .t-row.muted { color: var(--ink-mute); }
.chart-tip .t-row span { display: inline-flex; align-items: center; gap: var(--sp-6); }
.chart-tip .t-row i { width: 10px; height: 3px; border-radius: 1px; display: block; flex: none; }
.chart-tip .t-row b { color: var(--ink); font: 500 var(--fs-sm) var(--font-mono); white-space: nowrap; }
.chart-tip .t-row.muted b { color: var(--ink-dim); font-weight: 400; }

.chart .hover-catch { cursor: crosshair; }
/* The focus target is the chart's HTML host, not the SVG rect — SVG elements
 * take focus but never fire focus/blur, so the ring belongs out here. */
.chart:focus { outline: none; }
.chart:focus-visible { outline: 2px solid var(--bean); outline-offset: 3px; border-radius: var(--r-sm); }

.sw-legend { display: flex; flex-wrap: wrap; gap: var(--sp-12); font-size: var(--fs-sm); color: var(--ink-dim); margin-top: var(--sp-6); }
.sw-row { display: inline-flex; align-items: center; gap: var(--sp-6); }
.sw-row i { width: 12px; height: 3px; border-radius: 1px; display: block; }
.sw-row b { font: 500 var(--fs-cap-lg) var(--font-mono); color: var(--ink-dim); }

.callout {
  margin: 0; padding: var(--sp-10) var(--sp-12); font-size: var(--fs);
  background: var(--panel-strong); border-left: 2px solid var(--bean); border-radius: 0 var(--r) var(--r) 0;
  color: var(--ink-dim);
}
.conc { display: flex; gap: var(--sp-16); font: 400 var(--fs-cap) var(--font-mono); color: var(--ink-mute); margin-bottom: var(--sp-8); }
.conc b { color: var(--ink); font-weight: 500; }

/* ---------- bar list ---------- */
/* Entrance motion here NEVER touches opacity — unlike app.css's `riseIn`,
 * which is fine over a globe but not over a table of figures. An animation
 * whose timeline does not advance (a backgrounded tab, a pane that is not
 * compositing, an engine that drops the frame) would leave `opacity: 0`
 * standing and the numbers simply absent. Translation alone degrades to the
 * finished state, so the data is legible whether or not the motion plays. */
@keyframes riseShift { from { transform: translateY(6px); } to { transform: none; } }

.bar-list { display: flex; flex-direction: column; }
.bar-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'lbl val' 'track pct';
  gap: 2px var(--sp-8); padding: var(--sp-6) 0; border-bottom: 1px solid var(--line);
  animation: riseShift var(--dur-row) var(--ease-panel) both; animation-delay: calc(var(--i, 0) * 16ms);
}
.bar-row:last-child { border-bottom: 0; }
.bar-row .lbl { grid-area: lbl; font-size: var(--fs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { grid-area: val; font: 400 var(--fs-cap-lg) var(--font-mono); color: var(--ink-dim); }
.bar-row .track { grid-area: track; height: 4px; background: var(--line); border-radius: 1px; overflow: hidden; align-self: center; }
.bar-row .track i { display: block; height: 100%; border-radius: 1px; }
.bar-row .pct { grid-area: pct; font: 400 var(--fs-cap-sm) var(--font-mono); color: var(--ink-mute); }

.share-bar { height: 8px; border-radius: var(--r-sm); overflow: hidden; display: flex; margin-top: var(--sp-4); }
.share-bar i { display: block; height: 100%; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font: 400 var(--fs-cap-lg) var(--font-mono); }
table.grid th, table.grid td { padding: var(--sp-6) var(--sp-8); text-align: right; white-space: nowrap; }
table.grid thead th {
  font: 400 var(--fs-cap-xs) var(--font-mono); letter-spacing: var(--track-cap); text-transform: uppercase;
  color: var(--ink-mute); border-bottom: 1px solid var(--line-strong); vertical-align: bottom;
}
table.grid th.lbl { text-align: left; }
table.grid tbody th.lbl { font-weight: 500; color: var(--ink); }
table.grid tbody tr { border-bottom: 1px solid var(--line); }
table.grid tbody tr:hover { background: var(--bg-2); }
table.grid td { color: var(--ink-dim); }
table.grid td.est { font-style: italic; color: var(--ink-mute); }
table.grid td.neg { color: var(--danger); }
table.grid td.pos { color: var(--ok); }
table.grid tr.partial th.lbl { color: var(--ink-mute); }
table.grid .flag {
  margin-left: var(--sp-6); font-size: var(--fs-cap-xs); color: var(--gold);
  border: 1px solid currentColor; border-radius: var(--r-sm); padding: 0 3px;
}

/* ---------- year bar ---------- */
.year-strip { display: flex; gap: var(--sp-4); overflow-x: auto; scrollbar-width: none; padding-bottom: var(--sp-4); }
.year-strip::-webkit-scrollbar { display: none; }
.year-strip .tick {
  flex: none; font: 400 var(--fs-cap) var(--font-mono); padding: 3px var(--sp-6);
  border: 1px solid transparent; border-radius: var(--r-sm); background: transparent;
  color: var(--ink-mute); cursor: pointer; letter-spacing: 0.04em;
}
.year-strip .tick:hover { color: var(--ink); border-color: var(--line-strong); }
.year-strip .tick.on { background: var(--ink); color: var(--bg); }
.year-strip .tick.gap { color: var(--gold); }

/* ---------- caveats ---------- */
.caveats { margin: 0; padding-left: var(--sp-16); display: flex; flex-direction: column; gap: var(--sp-6); }
.caveat { font-size: var(--fs-sm); line-height: 1.55; color: var(--ink-mute); }
.caveat b { color: var(--ink-dim); font-weight: 500; text-transform: capitalize; }
.caveat code { font: 400 var(--fs-cap-lg) var(--font-mono); color: var(--ink-dim); }
.caveat.negative_closing_stocks b, .caveat.basis_mismatch b { color: var(--danger); }
.caveat.partial_year b, .caveat.stocks_chained b { color: var(--gold); }
.caveat.split_reporter b, .caveat.stale_reporter b, .caveat.negative_consumption b { color: var(--danger); }

/* ---------- responsive ----------
 * Same 960px breakpoint as the globe (app.css), which is also where
 * `.rail-toggle` becomes visible. They used to disagree — between 901 and
 * 960px the rail was hidden with no button to bring it back. */
@media (max-width: 960px) {
  .layout.country { grid-template-columns: 1fr; }
  .rail.country-rail { display: none; }
  /* Absolute inside .layout.country, not fixed under a 56px header: the
   * masthead wraps at this width, so its height is no longer a constant. */
  .rail.country-rail.open { display: flex; position: absolute; inset: 0; z-index: 40; }
  .panel, .headline, .c-title { padding-left: var(--sp-16); padding-right: var(--sp-16); }
}

/* MUST be last — the `font:` shorthand resets font-variant-numeric. */
.hstat .v, .hstat .s, .bar-row .val, .bar-row .pct, table.grid, .conc, .year-strip .tick,
.c-title .meta, .spec-row .v, .sw-row b {
  font-variant-numeric: tabular-nums;
}
