/* EMMCB — dashboard-specific surfaces
   The main matrix panel, the country strip, the bot console, the 3D frame. */

/* ---- Topbar contents ------------------------------------------------- */
.topbar__context { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.topbar__crumb {
  font-size: var(--fs-micro);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.topbar__title { font-size: var(--fs-md); font-weight: 600; letter-spacing: -0.012em; }
.topbar__spacer { flex: 1 1 auto; }

.topbar__status {
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s3);
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  font-size: var(--fs-tiny);
  color: var(--ink-2);
  white-space: nowrap;
}
.topbar__status .mono { color: var(--ink-3); }

.searchbox { position: relative; width: 240px; }
.searchbox .input { width: 100%; padding-left: 28px; }
.searchbox svg {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--ink-3); pointer-events: none;
}
.searchbox__results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  max-height: 320px; overflow: auto;
  padding: var(--s1);
}
.searchbox__result {
  display: block; width: 100%; text-align: left;
  padding: var(--s2) var(--s3);
  border: 0; background: none; border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
}
.searchbox__result:hover, .searchbox__result[data-active="true"] { background: var(--surface-2); }
.searchbox__result span { display: block; font-size: var(--fs-micro); color: var(--ink-3); }

/* ---- Filter bar ------------------------------------------------------ */
.filterbar { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; width: 100%; }
.filterbar__spacer { flex: 1 1 auto; }
.filterbar__chip {
  display: inline-flex; align-items: center; gap: var(--s2);
  height: 26px; padding: 0 var(--s2) 0 var(--s3);
  border: 1px solid var(--accent-line);
  background: var(--accent-wash);
  color: var(--accent-ink);
  border-radius: 13px;
  font-size: var(--fs-tiny); font-weight: 500;
}
.filterbar__chip button { border: 0; background: none; color: inherit; opacity: 0.65; font-size: 13px; line-height: 1; padding: 0 2px; }
.filterbar__chip button:hover { opacity: 1; }
.filterbar__divider { width: 1px; height: 20px; background: var(--line); flex: none; }

/* ---- Main Matrix panel ----------------------------------------------- */
/* The console centrepiece: business dimensions x operating regions, each cell
   a composite health score. This is the "what is happening" view. */
.matrix { display: flex; flex-direction: column; min-width: 0; }
.matrix__scroll { overflow: auto; min-width: 0; }
.matrix__grid {
  display: grid;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  min-width: 720px;
}
.matrix__corner,
.matrix__colhead,
.matrix__rowhead,
.matrix__cell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.matrix__corner { background: var(--surface-2); position: sticky; left: 0; z-index: 3; }
.matrix__colhead {
  background: var(--surface-2);
  padding: var(--s2) var(--s3);
  position: sticky; top: 0; z-index: 2;
}
.matrix__colhead b {
  display: block;
  font-size: var(--fs-tiny); font-weight: 600;
  letter-spacing: 0.02em;
}
.matrix__colhead span {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-micro); color: var(--ink-3);
}
.matrix__rowhead {
  background: var(--surface-2);
  padding: var(--s2) var(--s3);
  position: sticky; left: 0; z-index: 1;
  display: flex; flex-direction: column; justify-content: center;
}
.matrix__rowhead b { font-size: var(--fs-tiny); font-weight: 600; }
.matrix__rowhead span { font-size: var(--fs-micro); color: var(--ink-3); }

.matrix__cell {
  /* Set per cell from JavaScript; declared here so the default is
     explicit and the property is discoverable in the stylesheet. */
  --cell-wash: 0;
  position: relative;
  min-height: 54px;
  padding: var(--s2) var(--s3);
  background: var(--surface);
  border-top: 0; border-left: 0;
  text-align: left;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  transition: box-shadow var(--dur-fast) var(--ease);
}
.matrix__cell:hover { box-shadow: inset 0 0 0 2px var(--accent); z-index: 4; }
.matrix__cell[data-selected="true"] { box-shadow: inset 0 0 0 2px var(--accent); z-index: 4; }
.matrix__cell::before {
  content: ""; position: absolute; inset: 0;
  background: currentColor; opacity: var(--cell-wash, 0); pointer-events: none;
}
.matrix__cell[data-state="ok"]       { color: var(--pos); }
.matrix__cell[data-state="watch"]    { color: var(--warn); }
.matrix__cell[data-state="risk"]     { color: var(--sev-high); }
.matrix__cell[data-state="critical"] { color: var(--neg); }
.matrix__cell[data-state="idle"]     { color: var(--ink-3); }
.matrix__score {
  position: relative;
  font-size: var(--fs-md); font-weight: 600;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
  color: var(--ink);
}
.matrix__trend { position: relative; font-size: var(--fs-micro); font-weight: 600; font-variant-numeric: tabular-nums; }
.matrix__flag {
  position: absolute; top: 5px; right: 5px;
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.matrix__cell[data-state="ok"] .matrix__flag { display: none; }

.matrix__legend {
  display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap;
  padding: var(--s3) var(--s5);
  border-top: 1px solid var(--line);
  font-size: var(--fs-tiny); color: var(--ink-2);
}
.matrix__legendkey { display: inline-flex; align-items: center; gap: 6px; }
.matrix__legendswatch { width: 11px; height: 11px; border-radius: 2px; border: 1px solid var(--line-strong); }

/* ---- Country strip --------------------------------------------------- */
.countries { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
.country {
  padding: var(--s4) var(--s5);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: none; border-top: 0; border-left: 0;
  text-align: left;
  display: flex; flex-direction: column; gap: 5px;
  transition: background var(--dur-fast) var(--ease);
  position: relative;
  min-width: 0;
}
.country:hover { background: var(--surface-2); }
.country[data-selected="true"] { background: var(--accent-wash); }
.country__head { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.country__flag {
  width: 20px; height: 14px; flex: none;
  border-radius: 2px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.country__name { font-size: var(--fs-xs); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.country__code { font-family: var(--font-mono); font-size: var(--fs-micro); color: var(--ink-3); margin-left: auto; }
.country__value { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.018em; font-variant-numeric: tabular-nums; }
.country__meta { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-micro); color: var(--ink-3); }

/* ---- Bot console ----------------------------------------------------- */
.botlist { display: flex; flex-direction: column; }
.bot {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: var(--s3);
  align-items: start;
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.bot:last-child { border-bottom: 0; }
.bot__glyph {
  width: 26px; height: 26px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: var(--surface-3);
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: var(--fs-micro); font-weight: 600;
}
.bot[data-state="firing"] .bot__glyph { background: var(--accent-wash); color: var(--accent-ink); }
.bot[data-state="alarm"]  .bot__glyph { background: var(--neg-wash); color: var(--neg); }
.bot[data-state="off"]    .bot__glyph { opacity: 0.5; }
.bot__body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.bot__name { font-size: var(--fs-sm); font-weight: 600; display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.bot__desc { font-size: var(--fs-xs); color: var(--ink-2); line-height: var(--lh-snug); }
.bot__rule {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  color: var(--ink-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px var(--s2);
  align-self: flex-start;
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
}
.bot__side { display: flex; flex-direction: column; align-items: flex-end; gap: var(--s2); }

/* Autonomy indicator — the honest statement of how a recommendation was made */
.autonomy {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-micro); font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink-2);
}
.autonomy__pip { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-2); }
.autonomy[data-mode="deterministic"] .autonomy__pip { background: var(--ink); }
.autonomy[data-mode="ai"] .autonomy__pip { background: var(--accent); }
.autonomy[data-mode="ai"] { color: var(--accent-ink); }
.autonomy[data-mode="degraded"] .autonomy__pip { background: var(--warn); }
.autonomy[data-mode="degraded"] { color: var(--warn); }

/* ---- 3D frame -------------------------------------------------------- */
.stage3d {
  position: relative;
  width: 100%;
  min-height: 420px;
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}
.stage3d canvas { display: block; width: 100%; height: 100%; }
.stage3d__overlay {
  position: absolute; left: var(--s4); top: var(--s4);
  display: flex; flex-direction: column; gap: var(--s2);
  pointer-events: none;
}
.stage3d__readout {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--s2) var(--s3);
  font-size: var(--fs-tiny);
  min-width: 172px;
  pointer-events: auto;
}
.stage3d__readout b { display: block; font-size: var(--fs-xs); font-weight: 600; margin-bottom: 2px; }
.stage3d__controls {
  position: absolute; right: var(--s4); top: var(--s4);
  display: flex; gap: var(--s2);
}
.stage3d__note {
  position: absolute; left: var(--s4); bottom: var(--s4);
  font-size: var(--fs-micro); color: var(--ink-3);
  font-family: var(--font-mono);
}
/* Shown until the map's first frame. The panel is never an empty rectangle,
   and never the near-black a WebGL canvas paints before it renders. */
.stage3d__loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  gap: var(--s3);
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: var(--fs-xs);
}
.stage3d__loadingdot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  animation: stage-pulse 1.2s var(--ease) infinite;
}
@keyframes stage-pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50%      { opacity: 1;    transform: scale(1.15); }
}

.stage3d__fallbackmsg {
  position: absolute; right: var(--s4); bottom: var(--s4);
  font-size: var(--fs-micro);
  color: var(--warn);
  background: var(--warn-wash);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px var(--s2);
}

/* ---- Report builder -------------------------------------------------- */
.reportgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s3); }
.reportopt {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.reportopt:hover { border-color: var(--line-strong); background: var(--surface-2); }
.reportopt input { margin: 2px 0 0; accent-color: var(--accent); }
.reportopt b { display: block; font-size: var(--fs-xs); font-weight: 600; }
.reportopt span { display: block; font-size: var(--fs-micro); color: var(--ink-3); line-height: var(--lh-snug); }
.reportopt:has(input:checked) { border-color: var(--accent-line); background: var(--accent-wash); }

/* ---- Misc page furniture -------------------------------------------- */
.zone { display: flex; flex-direction: column; gap: var(--s3); }
.zone__title {
  font-size: var(--fs-micro); font-weight: 600;
  letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--ink-3);
  display: flex; align-items: center; gap: var(--s3);
}
.zone__title::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--line); }

.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: var(--s5) var(--s6); }
.stat { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.stat__k { font-size: var(--fs-micro); letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); }
.stat__v { font-size: var(--fs-md); font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: var(--tracking-snug); }
.stat__n { font-size: var(--fs-micro); color: var(--ink-3); }

/* The page title is the largest type in the console and the only thing set
   at display scale. Everything else earns its size from hierarchy. */
.pagebar { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s5); }
.pagebar__lead { min-width: 0; }
.pagebar__lead h1 {
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  line-height: var(--lh-tight);
}
.pagebar__lead p {
  font-size: var(--fs-sm);
  color: var(--ink-2);
  margin-top: var(--s2);
  line-height: var(--lh-body);
  max-width: var(--measure);
}
