/* Profin data-page components (window.Profin builders).
 *
 * The metrics/ownership/coverage pages are CHILDREN OF /explorer: they load style.css first
 * (shared tokens, nav, fonts) and this file layers on the data-specific components. Everything
 * here uses the shipped warm palette — paper #f6f3ee, terracotta --accent, rounded corners,
 * soft shadows — so a new page looks like the Data Explorer. See docs/STYLE_GUIDE.md.
 *
 * Tokens come from style.css; only the few the Explorer added (audit badges, wash tints) plus a
 * shared soft-shadow are declared here.
 */

:root {
  --accent-wash: #f3e4d5;
  --accent-wash-border: #e6cbae;
  --gaap-color: #3d6a8a;
  --gaap-bg: #e4edf2;
  --gaap-border: #cddce4;
  --ext-color: #b04a3a;
  --ext-bg: #f5e2da;
  --ext-border: #e8c4b4;
  --shadow-soft: 0 18px 40px -26px rgba(40, 30, 15, 0.35);
}

/* The `hidden` attribute must win over our flex/grid `display` rules (a flex/grid display
 * otherwise overrides the UA `[hidden] { display: none }`). */
[hidden] { display: none !important; }

/* numbers are always tabular */
.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- page shell + masthead (matches the Explorer hero) ---------- */

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 32px 72px;
}

.masthead-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
}

.masthead h1 {
  margin: 6px 0 0;
  font-weight: 800;
  font-size: 36px;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.masthead-meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--mono-muted);
  text-align: right;
  line-height: 1.7;
}

/* single hairline rule under the masthead (the Explorer's rule, not a ledger double rule) */
.rule-double {
  margin-top: 16px;
  border-top: 1px solid var(--border-tint-rule);
}

.lede {
  margin: 16px 0 0;
  max-width: 640px;
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--ink-body);
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 34px 0 18px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 8px;
}
.section-head .n { font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--accent); }
.section-head h2 { margin: 0; font-weight: 800; font-size: 21px; letter-spacing: -0.015em; }

.micro {
  font-family: var(--font-mono);
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--mono-muted);
}

/* ---------- ticker chip ---------- */

.ticker-chip {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  background: var(--ink);
  color: var(--bg-page);
  padding: 3px 9px;
  border-radius: 7px;
}

/* ---------- segmented control ---------- */

.segmented {
  display: inline-flex;
  border: 1.5px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
}
.segmented button {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  padding: 8px 16px;
  border: none;
  border-right: 1px solid var(--border-strong);
  background: var(--bg-page);
  color: var(--ink-soft);
  cursor: pointer;
}
.segmented button:last-child { border-right: none; }
.segmented button.on { background: var(--accent); color: #fff; }
.segmented button:hover:not(.on) { background: var(--bg-badge); }

.btn-inverse {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--bg-page);
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
}
.btn-inverse:hover { opacity: 0.88; }

/* ---------- status chips (STYLE_GUIDE §7) ---------- */
/* Distinguished by glyph + label + border, never color alone (warm palette). */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 3px 7px;
  border-radius: 6px;
  white-space: nowrap;
}
.chip .glyph { font-size: 9px; line-height: 1; }

.chip-ok { color: var(--ink-soft); background: transparent; border: 1px solid var(--border-strong); }
.chip-approx { color: var(--ext-color); background: var(--ext-bg); border: 1px solid var(--ext-border); }
.chip-na { color: var(--ink-soft); background: var(--bg-badge); border: 1.5px solid var(--border-strong); }
.chip-nm { color: var(--ink-soft); background: transparent; border: 1.5px dashed var(--mono-muted); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-tint);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.legend-item { display: flex; align-items: center; gap: 7px; }
.legend-item .desc { font-size: 11px; color: var(--ink-soft); }

/* ---------- metric card ---------- */

.card-grid {
  display: grid;
  /* Responsive, but capped at 4 columns: each column is at least the larger of 240px or the
     width that yields exactly 4 across (accounting for the 3 gaps), so wide pages top out at 4
     and narrower ones fall back to 3/2/1 fluidly. */
  grid-template-columns: repeat(auto-fill, minmax(max(240px, (100% - 3 * 16px) / 4), 1fr));
  gap: 16px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.metric-card.na { background: var(--bg-tint); box-shadow: none; }

.metric-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.metric-name { font-weight: 600; font-size: 14px; line-height: 1.25; }

.metric-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 26px;
  letter-spacing: -0.01em;
  line-height: 1;
  color: var(--ink);
}
.metric-value.drained { color: var(--mono-muted); font-size: 20px; }

.metric-basis {
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--mono-muted);
}

.metric-note {
  font-size: 11px;
  line-height: 1.4;
  color: var(--ink-soft);
  border-left: 2px solid var(--ext-border);
  padding-left: 8px;
}

/* intra-year quarterly sparkline (FY cards) */
.spark-wrap { display: flex; align-items: center; gap: 8px; }
.spark { display: block; overflow: visible; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--accent); }
.spark-label {
  font-family: var(--font-mono);
  font-size: 8.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mono-muted);
}

/* ---------- provenance / "show your work" ---------- */

.provenance { margin-top: 2px; }
.provenance summary {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
}
.provenance summary::-webkit-details-marker { display: none; }
.provenance summary::before { content: "+ "; }
.provenance[open] summary::before { content: "\2212 "; }
.provenance[open] summary { color: var(--accent-ink); }
.provenance-body {
  margin-top: 8px;
  padding: 12px 14px;
  background: var(--bg-tint);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-body);
}
.provenance-body dt {
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--mono-muted);
  margin-top: 8px;
}
.provenance-body dt:first-child { margin-top: 0; }
.provenance-body dd { margin: 2px 0 0; font-family: var(--font-mono); }

/* source badges (reset display/margin so style.css's marketing .badge can't leak in) */
.badge {
  display: inline-block;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 1px 6px;
  border-radius: 5px;
}
.badge-gaap { color: var(--gaap-color); background: var(--gaap-bg); border: 1px solid var(--gaap-border); }
.badge-ext { color: var(--ext-color); background: var(--ext-bg); border: 1px solid var(--ext-border); }

/* ---------- disclosure / data-notes ---------- */

.disclosure {
  margin-top: 28px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  padding: 14px 18px;
}
.disclosure summary {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  cursor: pointer;
  list-style: none;
}
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary::before { content: "+ "; }
.disclosure[open] summary::before { content: "\2212 "; }
.disclosure ul { margin: 12px 0 0; padding-left: 18px; }
.disclosure li { font-size: 12.5px; line-height: 1.55; color: var(--ink-body); margin-bottom: 7px; }

/* ---------- search bar ---------- */

.searchbar { display: flex; gap: 8px; align-items: stretch; }
.searchbar input {
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 10px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-page);
  color: var(--ink);
  min-width: 220px;
}
.searchbar input:focus { outline: none; border-color: var(--accent); }
.searchbar input::placeholder { color: var(--mono-muted); }

/* ---------- shared states ---------- */

.state {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 24px;
  background: var(--bg-tint);
}
.state-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}
.state-title.err { color: var(--ext-color); }
.state-copy { margin-top: 8px; font-size: 14px; line-height: 1.5; color: var(--ink-body); max-width: 560px; }

.state-loading .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 8px;
  animation: profinPulse 1s ease-in-out infinite;
}
@keyframes profinPulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
.shimmer {
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--border-strong) 0, var(--bg-card) 200px, var(--border-strong) 400px);
  background-size: 600px;
  animation: profinShimmer 1.1s linear infinite;
  margin-top: 12px;
}
@keyframes profinShimmer { 0% { background-position: -420px 0; } 100% { background-position: 420px 0; } }
.cold-note { margin-top: 14px; font-family: var(--font-mono); font-size: 11px; color: var(--mono-muted); }

.http-code { font-family: var(--font-mono); font-weight: 600; letter-spacing: 0.08em; color: var(--ext-color); }
.recovery-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* ---------- footer (renamed to avoid the marketing .site-footer in style.css) ---------- */

.app-footer {
  max-width: 1040px;
  margin: 56px auto 0;
  padding: 18px 32px 0;
  border-top: 1px solid var(--border-tint-rule);
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.app-footer a {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--accent);
  text-decoration: none;
}
.app-footer a:hover { color: var(--accent-hover); }
.app-footer .tagline { font-family: var(--font-mono); font-size: 11px; color: var(--mono-muted); margin-left: auto; }

/* ---------- Plot charts (Phase 5, vendored Observable Plot — STYLE_GUIDE §6) ----------
 *
 * Every Profin.* Plot builder (divergingBars today; more land alongside it) returns a DOM node
 * wrapped the same way: a mono eyebrow title, a horizontally-scrollable body holding Plot's own
 * SVG, and an honesty caption. Card chrome matches .trend-chart's (bg-tint, soft border, rounded)
 * so a chart never looks like a foreign widget dropped onto the page.
 */

.plot-chart {
  margin: 4px 0 22px;
  padding: 16px 18px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
}
.plot-chart-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin: 0 0 10px;
}
/* Plot renders a fixed-width SVG (width/height attributes, not a scaling viewBox); scroll it
 * inside its own box on narrow viewports rather than distorting it with max-width or letting it
 * overflow the page body. */
.plot-chart-body { overflow-x: auto; }
.plot-chart-body svg { display: block; }
.plot-chart-caption {
  margin: 12px 2px 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--mono-muted);
}
.plot-chart-note {
  margin: 4px 2px 0;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--mono-muted);
}

/* ---------- composition chart + concentration stat tiles (Phase 5.1/5.2) ---------- */

.composition-block {
  margin-bottom: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(136px, 1fr));
  gap: 12px;
}
.stat-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-tile-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--mono-muted);
}
.stat-tile-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.stat-tile-note { font-size: 10.5px; line-height: 1.4; color: var(--ink-soft); }

/* Plot returns a bare <svg> sized to its own width/height attrs; scale it to the card via CSS
   (aspect ratio preserved -- Plot's default viewBox keeps the bars proportional, never
   stretched). #composition-chart-mount / #holders-chart-mount are the innerHTML placeholders
   manager.js / company.js append the Plot-backed compositionBars() fragment into -- each of its
   two nodes is its own chartCard() root (`.plot-chart`), so no dedicated outer-card class is
   needed here. */
#composition-chart-mount:empty, #holders-chart-mount:empty { display: none; }
.composition-bars svg { display: block; width: 100%; height: auto; }

/* Part-to-whole strip: one 100%-stacked bar, ordered top-1/top-2-5/top-6-10/other bands with a
   2px surface gap between them (the flex `gap` shows --bg-page through, and the container's
   overflow:hidden + border-radius keeps the ends visually rounded without rounding every
   segment). Direct labels sit inside a band when there's room; otherwise they move to the
   outside legend below -- never clipped (Phase 5 polish: composition redesign). */
.composition-strip-bar {
  display: flex;
  gap: 2px;
  height: 40px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-page);
}
.composition-strip-seg {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  min-width: 2px;
}
.composition-strip-seg-label {
  /* Standardized chart typography (matches the diverging chart's rows): mono 10.5px. */
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 10px;
}
.composition-strip-outside {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 10px 2px 0;
}
.composition-strip-outside-item {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.composition-strip-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
  flex: 0 0 auto;
}

/* ---------- paginated table (client-side pager, Profin.paginatedTable) ---------- */

.table-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin: 10px 2px 0;
}
.pager-btn {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  padding: 5px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  color: var(--ink-soft);
  cursor: pointer;
}
.pager-btn:hover:not(:disabled) { background: var(--bg-badge); }
.pager-btn:disabled { opacity: 0.4; cursor: default; }
.pager-label { font-family: var(--font-mono); font-size: 10.5px; color: var(--mono-muted); }

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .page { padding: 12px 20px 56px; }
  .masthead h1 { font-size: 28px; }
  .masthead-meta { text-align: left; }
  .card-grid { grid-template-columns: 1fr; }
  .app-footer .tagline { margin-left: 0; }
}
