/* ============================================================
   Kosmos+ Enterprise - analytics page extensions (P02, P03)
   Owned by Sonya. Layers on top of the shared styles.css (Johnny's
   shell + kit tokens). Only page-app layout, filter controls, charts,
   tabs, funnel, and required-state visuals live here. No brand colours
   are hard-coded: everything reads the kit tokens.
   ============================================================ */

/* The full-page frame (.app-header + .app-body) is owned by the shared
   styles.css (Johnny). This file only styles what lives INSIDE .main-body,
   plus the scope-bar controls. Nothing here defines the frame, so it never
   collides with the shared shell. */

/* page lede inside the working area */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 720; letter-spacing: -.01em; }
.page-head .route { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.page-head p.purpose { margin: 4px 0 0; color: var(--ink-2); font-size: 13.5px; max-width: 70ch; }

/* freshness line */
.fresh { display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--ink-3); }
.fresh .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.fresh.stale .dot { background: var(--warn); }

/* ---- filter / scope controls ---- */
.scope .ctl { position: relative; }
.scope select.ctl, .scope button.ctl {
  font: inherit; font-size: 12.5px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 6px 11px; cursor: pointer;
}
.scope button.ctl:hover, .scope select.ctl:hover { background: var(--surface-sunken); }
.scope button.ctl:focus-visible, .scope select.ctl:focus-visible, .scope .ms-menu label:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.scope button.ctl .caret { color: var(--ink-3); margin-left: 4px; }
.scope button.ctl .cnt { color: var(--brand); font-weight: 700; }

/* multi-select popover */
.ms { position: relative; }
.ms-menu {
  position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; min-width: 210px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r);
  box-shadow: var(--shadow-2); padding: 6px; display: none;
}
.ms.open .ms-menu { display: block; }
.ms-menu label { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.ms-menu label:hover { background: var(--surface-sunken); }
.ms-menu label input { accent-color: var(--brand); width: 15px; height: 15px; }
.ms-menu label .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.ms-menu .ms-actions { display: flex; gap: 8px; padding: 6px 8px 2px; border-top: 1px solid var(--border); margin-top: 4px; }
.ms-menu .ms-actions button { font: inherit; font-size: 12px; color: var(--link); background: none; border: 0; cursor: pointer; padding: 2px; }

/* ---- toolbar row (measure toggle, group-by) ---- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-sm); overflow: hidden; }
.seg button { font: inherit; font-size: 12.5px; font-weight: 600; padding: 6px 13px; background: var(--surface); color: var(--ink-2); border: 0; border-left: 1px solid var(--border); cursor: pointer; }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); }
.seg button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
label.inline { font-size: 12.5px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 7px; }
label.inline select { font: inherit; font-size: 12.5px; padding: 5px 9px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); cursor: pointer; }

/* ---- charts ---- */
.panel.wide { grid-column: 1 / -1; }
.chartbox { position: relative; }
.chartbox svg { display: block; width: 100%; height: auto; overflow: visible; }
.chartbox .gridline { stroke: var(--border); stroke-width: 1; }
.chartbox .axislbl { font-family: var(--mono); font-size: 9px; fill: var(--ink-3); }
.chartbox rect.seg-rect, .chartbox rect.hbar, .chartbox circle.pt { transition: opacity .12s; }
.chartbox .col:hover rect.seg-rect { opacity: .82; }
.chartbox rect.hit { fill: transparent; cursor: pointer; }
.tip {
  position: absolute; pointer-events: none; z-index: 30; background: var(--k-navy-900); color: var(--k-ink-on-dark);
  border: 1px solid var(--k-navy-600); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow-2);
  min-width: 150px; opacity: 0; transform: translateY(2px); transition: opacity .1s; }
.tip.show { opacity: 1; transform: none; }
.tip .th { font-weight: 700; margin-bottom: 5px; font-size: 12.5px; }
.tip .tr { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 2px 0; }
.tip .tr .lbl { display: inline-flex; align-items: center; gap: 6px; color: var(--k-ink-on-dark-2); }
.tip .tr .lbl i { width: 9px; height: 9px; border-radius: 2px; }
.tip .tr .v { font-variant-numeric: tabular-nums; font-weight: 650; }
.tip .tt { border-top: 1px solid var(--k-navy-600); margin-top: 5px; padding-top: 5px; }

/* keyboard-accessible equivalent data table under each chart */
.data-toggle { font: inherit; font-size: 12px; font-weight: 600; color: var(--link); background: none; border: 0; cursor: pointer; padding: 4px 0; }
.data-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.chart-data { margin-top: 10px; }
.chart-data table { border-collapse: collapse; width: 100%; font-size: 12px; }
.chart-data caption { text-align: left; font-size: 11.5px; color: var(--ink-3); padding-bottom: 6px; }
.chart-data th, .chart-data td { padding: 5px 8px; border-bottom: 1px solid var(--border); text-align: right; font-variant-numeric: tabular-nums; }
.chart-data th:first-child, .chart-data td:first-child { text-align: left; }
.chart-data thead th { color: var(--ink-3); font-weight: 600; }

/* ---- ranking / adoption-by-team horizontal bars (inline, non-svg) ---- */
.hbars { display: flex; flex-direction: column; gap: 9px; }
.hbars .row { display: grid; grid-template-columns: 130px 1fr auto; gap: 10px; align-items: center; font-size: 12.5px; }
.hbars .row .nm { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbars .track { background: var(--surface-sunken); border-radius: 5px; height: 16px; overflow: hidden; }
.hbars .fill { height: 100%; background: var(--brand); border-radius: 5px 0 0 5px; }
.hbars .val { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 650; }

/* ---- rollout funnel ---- */
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel .step { display: grid; grid-template-columns: 150px 1fr; gap: 12px; align-items: center; }
.funnel .step .lab { font-size: 12.5px; color: var(--ink-2); }
.funnel .step .lab small { display: block; color: var(--ink-3); font-size: 11px; }
.funnel .bar { position: relative; height: 34px; background: var(--surface-sunken); border-radius: 6px; overflow: hidden; }
.funnel .bar .fv { height: 100%; background: linear-gradient(90deg, var(--brand), color-mix(in srgb, var(--brand) 62%, var(--k-cyan))); display: flex; align-items: center; padding-left: 12px; color: var(--on-brand); font-weight: 700; font-size: 13px; }
.funnel .step .pct { font-size: 11.5px; color: var(--ink-3); }

/* ---- tabs (usage views) ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tabs button { font: inherit; font-size: 13px; font-weight: 600; color: var(--ink-3); background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px; cursor: pointer; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
.tabs button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tabpanel[hidden] { display: none; }

/* expandable table rows */
table.et tr.exp-row td { background: var(--surface-sunken); padding: 0; }
table.et .sub-tbl { width: 100%; border-collapse: collapse; }
table.et .sub-tbl td { border-bottom: 1px dashed var(--border); font-size: 12px; padding: 7px 12px; white-space: nowrap; }
table.et .caret-btn { background: none; border: 0; cursor: pointer; color: var(--ink-3); font-size: 12px; padding: 0 6px 0 0; }
table.et .share { display: inline-flex; align-items: center; gap: 8px; }
table.et .share .mini { width: 46px; height: 6px; background: var(--surface-sunken); border-radius: 3px; overflow: hidden; }
table.et .share .mini i { display: block; height: 100%; background: var(--brand); }
.tblbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.tblbar input.search { font: inherit; font-size: 13px; padding: 7px 11px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); min-width: 200px; }
.tblbar .spacer { flex: 1; }

/* ---- required states ---- */
.state-strip { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stateblock { border: 1px dashed var(--border-strong); border-radius: var(--r); padding: 22px; text-align: center; color: var(--ink-2); background: var(--surface); }
.stateblock .st-h { font-weight: 650; font-size: 14px; color: var(--ink); margin-bottom: 4px; display: inline-flex; align-items: center; gap: 8px; }
.stateblock p { margin: 4px auto 0; font-size: 12.5px; max-width: 52ch; }
.stateblock.partial { text-align: left; border-style: solid; border-color: var(--warn-line); background: var(--warn-bg); }
.skel { background: linear-gradient(90deg, var(--surface-sunken) 25%, #e9eef6 37%, var(--surface-sunken) 63%); background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: 6px; }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.skel-val { height: 26px; width: 70%; margin: 6px 0; }
.skel-line { height: 12px; width: 100%; margin: 5px 0; }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }

/* small helpers */
.muted { color: var(--ink-3); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.rowflex { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.notegrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
@media (max-width: 900px) { .funnel .step, .hbars .row { grid-template-columns: 110px 1fr; } }

/* clickable metric cards (every card needs a click destination, brief section 3) */
a.metric { color: inherit; text-decoration: none; cursor: pointer; }
a.metric:hover { box-shadow: var(--shadow-2); border-color: var(--border-strong); }
a.metric:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.metric .drill { color: var(--ink-3); font-size: 13px; opacity: .5; line-height: 1; }
a.metric:hover .drill, a.metric:focus-visible .drill { color: var(--brand); opacity: 1; }
