/* Sector Atlas — components. Light editorial: cream plane, serif page titles, sans for every figure. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.45 var(--font-sans); font-feature-settings: "kern";
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: inherit; text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: var(--focus); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: 6px 10px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: 12px; }
.mono { font-family: var(--font-mono); font-size: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.loading { padding: 40px; color: var(--muted); }
.noscript { padding: 20px; }

/* masthead ---------------------------------------------------------------------------------------- */
.masthead {
  display: flex; align-items: center; gap: 24px; padding: 10px 20px;
  border-bottom: 1px solid var(--hair); background: var(--page); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font: 26px/1 var(--font-serif); text-decoration: none; letter-spacing: 0.2px; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.3px; margin-top: 2px; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a { padding: 6px 10px; border-radius: var(--radius); text-decoration: none; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--ink); color: var(--page); }
.tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.tool { background: transparent; border: 1px solid var(--rule); border-radius: var(--radius); padding: 5px 10px; cursor: pointer; }
.tool:hover { background: var(--surface-2); }
kbd { font: 11px var(--font-mono); border: 1px solid var(--rule); border-radius: 3px; padding: 0 4px; color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); padding: 4px 8px; border-radius: 99px; background: var(--surface); border: 1px solid var(--hair); white-space: nowrap; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state="live"] .dot { background: #0ca30c; }
.status[data-state="stale"] .dot { background: #fab219; }
.status[data-state="offline"] .dot { background: #d03b3b; }
.status[data-state="delayed"] .dot { background: #fab219; }
.status[data-state="loading"] .dot { background: var(--muted); }
.banner { padding: 8px 20px 0; }
.banner[hidden] { display: none; }

main { flex: 1; padding: 16px 20px 24px; min-width: 0; outline: none; }
.foot { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; padding: 12px 20px; border-top: 1px solid var(--hair); color: var(--muted); font-size: 12px; }

/* page header -------------------------------------------------------------------------------------- */
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin: 0 0 12px; }
.page-head h1 { font: 34px/1.05 var(--font-serif); margin: 0; font-weight: 400; }
.page-head .sub { color: var(--muted); font-size: 13px; }
h2 { font: 22px/1.15 var(--font-serif); font-weight: 400; margin: 0 0 8px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-2); margin: 0 0 8px; font-weight: 600; }

/* stat tiles --------------------------------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.stat .label { font-size: 12px; color: var(--ink-2); }
.stat .value { font-size: 24px; font-weight: 600; letter-spacing: -0.3px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .delta { font-size: 12px; color: var(--ink-2); }
.seg { display: flex; height: 8px; border-radius: 4px; overflow: hidden; gap: var(--gap); margin-top: 6px; background: transparent; }
.seg > span { display: block; height: 100%; border-radius: 2px; }

/* controls ------------------------------------------------------------------------------------------ */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-bottom: 8px; }
.control { display: inline-flex; align-items: center; gap: 6px; }
.control > .clabel { font-size: 12px; color: var(--muted); }
.segmented { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.segmented button { border: 0; background: transparent; padding: 5px 10px; cursor: pointer; border-right: 1px solid var(--hair); font-size: 13px; }
.segmented button:last-child { border-right: 0; }
.segmented button:hover { background: var(--surface-2); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--page); }
select, input[type="search"], input[type="text"] { font: inherit; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); padding: 5px 8px; color: var(--ink); }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--rule); background: var(--surface); white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--page); border-color: var(--ink); }
.toggle { cursor: pointer; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.crumbs a { color: var(--ink-2); }
.crumbs .sep { color: var(--muted); }
.btn { border: 1px solid var(--rule); background: var(--surface); border-radius: var(--radius); padding: 5px 12px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--ink); color: var(--page); border-color: var(--ink); }
.linkbtn { border: 0; background: none; padding: 0; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; color: var(--ink-2); }

/* context bar + legend -------------------------------------------------------------------------- */
.context { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; margin: 4px 0 10px; font-size: 12px; color: var(--ink-2); }
.notice { display: inline-flex; gap: 6px; align-items: baseline; background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius-sm); padding: 3px 8px; font-size: 12px; }
.notice::before { content: "⚠"; }
.notice.info { background: var(--surface-2); color: var(--ink-2); }
.notice.info::before { content: "ⓘ"; }
.legend { display: inline-flex; align-items: center; gap: 6px; }
.legend .ramp { display: inline-flex; gap: 1px; }
.legend .ramp span { width: 18px; height: 10px; border-radius: 2px; display: inline-block; }
.legend .ends { display: inline-flex; gap: 8px; color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
.linekey { display: inline-block; width: 14px; height: 2px; border-radius: 1px; vertical-align: 3px; }

/* treemap board --------------------------------------------------------------------------------- */
.board-wrap { position: relative; }
.board { position: relative; width: 100%; height: max(480px, calc(100vh - 330px)); background: var(--page); border-radius: var(--radius); overflow: hidden; contain: layout paint; }
.board.fade { animation: fadein 200ms ease-out; }
@keyframes fadein { from { opacity: 0.35; transform: scale(0.985); } to { opacity: 1; transform: none; } }
.tile, .sector-head {
  position: absolute; border: 0; margin: 0; padding: 4px 6px; text-align: left; overflow: hidden; cursor: pointer;
  border-radius: 3px; transition: background-color 220ms linear, color 220ms linear; display: flex; flex-direction: column; justify-content: flex-start;
  font-size: 12px; line-height: 1.25;
}
.tile:hover, .sector-head:hover { filter: brightness(1.04) saturate(1.05); }
.tile:focus-visible, .sector-head:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; z-index: 3; }
.tile[aria-current="true"] { box-shadow: inset 0 0 0 2px var(--ink); }
.tile .t-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .t-value { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile .t-comp, .tile .t-issuer, .tile .t-weight { font-size: 11px; opacity: 0.88; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.big .t-name { font-size: 15px; }
.tile.big .t-value { font-size: 15px; }
.tile.xl .t-name { font-size: 18px; }
.tile.xl .t-value { font-size: 18px; }
.tile.novote .t-name::after { content: " ·"; opacity: 0.6; }
.tile.missing, .sector-head.missing { background-image: repeating-linear-gradient(45deg, rgba(26,36,32,0) 0 5px, rgba(26,36,32,0.09) 5px 6px); }
.board[hidden], [data-r="list"][hidden], .inspector[hidden] { display: none; }
.mapview .toolbar select { max-width: 200px; }
.sector-box { position: absolute; border-radius: 3px; background: transparent; pointer-events: none; }
.sector-head { padding: 3px 6px; display: flex; flex-direction: row; align-items: baseline; gap: 8px; font-weight: 600; pointer-events: auto; white-space: nowrap; }
.sector-head .h-name { overflow: hidden; text-overflow: ellipsis; }
.sector-head .h-value { font-variant-numeric: tabular-nums; margin-left: auto; }
.sector-head.small { font-size: 11px; padding: 2px 5px; }
.board-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

/* inspector -------------------------------------------------------------------------------------- */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.map-layout.with-inspector { grid-template-columns: minmax(0, 1fr) 340px; }
.inspector { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 12px 14px; align-self: start; position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.inspector .close { float: right; }
.inspector h2 { margin-bottom: 2px; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.kv div { background: var(--page); border-radius: var(--radius-sm); padding: 6px 8px; }
.kv .k { font-size: 11px; color: var(--muted); }
.kv .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kv .r { font-size: 11px; color: var(--muted); }

/* tables ------------------------------------------------------------------------------------------ */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; border-bottom: 1px solid var(--rule); padding: 6px 8px; white-space: nowrap; }
table.data th button { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; }
table.data th[aria-sort="descending"] button::after { content: " ↓"; }
table.data th[aria-sort="ascending"] button::after { content: " ↑"; }
table.data td { border-bottom: 1px solid var(--hair); padding: 6px 8px; vertical-align: middle; }
table.data tr.row-link { cursor: pointer; }
table.data tr.row-link:hover td { background: var(--surface-2); }
table.data tr.expanded td { background: var(--surface); }
.bar-cell { position: relative; min-width: 120px; }
.bar-cell .bar { position: absolute; top: 50%; height: 10px; margin-top: -5px; border-radius: 0 4px 4px 0; }
.bar-cell .bar.neg { border-radius: 4px 0 0 4px; }
.bar-cell .axis { position: absolute; top: 4px; bottom: 4px; width: 1px; background: var(--rule); }
.card { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 8px; font-size: 12px; }

/* tooltip ----------------------------------------------------------------------------------------- */
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; max-width: 340px; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-value { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip table { border-collapse: collapse; margin-top: 4px; }
.tooltip td { padding: 1px 8px 1px 0; font-variant-numeric: tabular-nums; }
.tooltip .reason { color: var(--ink-2); margin-top: 4px; }

/* dialogs ----------------------------------------------------------------------------------------- */
.dialog { border: 1px solid var(--rule); border-radius: 10px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dialog-wide { width: min(860px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(26, 36, 32, 0.28); }
.dialog .d-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--hair); }
.dialog .d-head h2 { margin: 0; }
.dialog .d-body { padding: 14px 16px; max-height: min(70vh, 720px); overflow: auto; }
.dialog .d-body p { margin: 0 0 10px; }
.dialog .d-body h3 { margin-top: 14px; }
.share-url { width: 100%; font-family: var(--font-mono); font-size: 12px; }
.results { list-style: none; margin: 10px 0 0; padding: 0; }
.results li a { display: flex; gap: 10px; padding: 6px 8px; border-radius: var(--radius-sm); text-decoration: none; }
.results li a:hover, .results li a:focus { background: var(--surface-2); }

/* charts ------------------------------------------------------------------------------------------ */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid line { stroke: var(--hair); stroke-width: 1; }
.chart .axis text, .chart text.tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .baseline { stroke: var(--rule); stroke-width: 1; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .crosshair { stroke: var(--ink-2); stroke-width: 1; }
.chart .endlabel { font-size: 11px; fill: var(--ink); font-weight: 600; }
.spark { display: block; }
.spark path { fill: none; stroke-width: 1.5; stroke: var(--ink-2); }
.heat { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--gap); }
.heat a { display: flex; flex-direction: column; justify-content: space-between; min-height: 58px; padding: 6px 7px; border-radius: 3px; text-decoration: none; font-size: 11px; transition: background-color 220ms linear; }
.heat a .code { font-weight: 700; font-size: 12px; letter-spacing: 0.4px; }
.heat a .hv { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 13px; }

/* flow ------------------------------------------------------------------------------------------ */
.badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.5px; padding: 2px 6px; border-radius: 3px; background: var(--warn-bg); color: var(--warn-ink); }
.badge.neutral { background: var(--surface-2); color: var(--ink-2); }
.sankey text { font-size: 11px; fill: var(--ink); }
.sankey .ribbon { fill: none; stroke: #8a8c84; stroke-opacity: 0.28; transition: stroke-opacity 120ms; cursor: help; }
.sankey .ribbon:hover, .sankey .ribbon:focus, .sankey .ribbon.hl { stroke-opacity: 0.6; outline: none; }
.sankey .ribbon.unm { stroke: url(#hatch); stroke-opacity: 0.55; }
.sankey .unmatched { fill: url(#hatch); stroke: var(--rule); stroke-width: 1; }
.flow-table .bar-cell { min-width: 110px; }
.flow-table tr.expanded td { white-space: normal; }
.sankey .node-src { fill: var(--down-mark); }
.sankey .node-dst { fill: var(--up-mark); }
.verify { font-size: 11px; color: var(--warn-ink); }

/* responsive -------------------------------------------------------------------------------------- */
@media (max-width: 1020px) {
  .map-layout.with-inspector { grid-template-columns: minmax(0, 1fr); }
  .inspector { position: static; max-height: none; }
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 850px) {
  .masthead { flex-wrap: wrap; gap: 8px 16px; padding: 8px 12px; }
  .tools { margin-left: 0; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .heat { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  main { padding: 12px; }
  .page-head h1 { font-size: 28px; }
  .grid3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .board { height: 70vh; }
  table.data.cards thead { display: none; }
  table.data.cards tr { display: grid; grid-template-columns: 1fr auto; border-bottom: 1px solid var(--hair); padding: 6px 0; }
  table.data.cards td { border: 0; padding: 2px 6px; }
  .heat { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .tools { flex-wrap: wrap; gap: 6px; width: 100%; }
  .tools .tool { padding: 4px 8px; font-size: 13px; }
  .tools kbd { display: none; }
  .stats { gap: 8px; }
  .stat { padding: 8px 10px; }
  .stat .value { font-size: 19px; }
  .stat .delta { font-size: 11px; }
}
@media (max-width: 470px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav a { padding: 5px 7px; }
  .brand-sub { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (forced-colors: active) {
  .tile, .sector-head, .heat a { forced-color-adjust: none; border: 1px solid CanvasText; }
  .tile.missing { background: repeating-linear-gradient(45deg, Canvas 0 4px, GrayText 4px 5px) !important; }
}
@media print {
  .masthead .tools, .toolbar, .foot { display: none; }
  .tile.missing { background: repeating-linear-gradient(45deg, #fff 0 4px, #999 4px 5px) !important; }
}
