:root {
  --bg: #fafafa;
  --card: #ffffff;
  --card-2: #f5f5f5;
  --border: #ececec;
  --border-strong: #d4d4d4;
  --text: #0f1115;
  --text-2: #1f2937;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --accent: #2563eb;
  --accent-weak: #dbeafe;
  --accent-soft: #eff6ff;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --warn-text: #92400e;
  --grid: #f1f1f1;
  --weekend: #fafafa;
  --cat-1: #2563eb;
  --cat-2: #0891b2;
  --cat-3: #059669;
  --cat-4: #d97706;
  --cat-5: #dc2626;
  --cat-6: #7c3aed;
  --cat-7: #db2777;
  --cat-8: #64748b;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-feature-settings: "cv11", "ss01";
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===================== TOP BAR ===================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  gap: 24px;
  box-shadow: 0 1px 0 rgba(0,0,0,.03);
}
.brand {
  display: flex; align-items: center; gap: 12px;
}
.brand-logo {
  display: flex; align-items: center; gap: 8px;
  height: 36px;
}
.brand-logo img {
  height: 36px; width: auto; display: block;
  object-fit: contain;
}
.brand-logo img.ocs { height: 28px; }   /* OCS wordmark is wider; shrink slightly to balance */
.brand-logo .sep {
  color: var(--muted-2);
  font-weight: 400;
  font-size: 16px;
  margin: 0 2px;
}
.brand-title {
  font-weight: 600; font-size: 14px; letter-spacing: -0.01em;
}
.brand-sub {
  color: var(--muted); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .05em;
}

.topbar-controls {
  display: flex; align-items: center; gap: 18px;
}

.seg {
  display: inline-flex;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}
.seg-btn {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 6px 14px;
  font: inherit;
  font-weight: 500;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

/* Exclusion group mirrors the .seg segmented-control look so all three control
   sets (Org / Exclude / Scope) visually read as matching pill groups. */
.excl-group {
  display: inline-flex;
  align-items: stretch;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 0;
}
.excl-label {
  display: inline-flex; align-items: center;
  color: var(--muted); font-size: 12px;
  padding: 0 10px 0 8px;
  border-right: 1px solid var(--border);
  margin-right: 3px;
  white-space: nowrap;
}
.excl-btn {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 6px 14px;
  font: inherit;
  font-weight: 500;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.excl-btn:hover { color: var(--text); }
.excl-btn.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.load-status {
  color: var(--muted); font-size: 12px; min-width: 210px; text-align: right;
  display: flex; flex-direction: column; gap: 1px;
}
.last-updated {
  font-size: 10.5px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}
.last-updated b { color: var(--text-2); font-weight: 600; }

/* ===================== MAIN ===================== */
main {
  max-width: none;
  margin: 0;
  padding: 22px 32px 60px;
}

.notice {
  display: flex; align-items: center; gap: 10px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 12.5px;
}
.notice strong { color: var(--warn-text); font-weight: 600; }

.chip-row {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 14px;
  align-items: center;
}
.chip-row .lbl {
  color: var(--muted); font-size: 12px; margin-right: 4px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--text-2);
}
.chip button {
  appearance: none; background: transparent; border: 0;
  color: var(--muted-2); cursor: pointer; font-size: 13px;
  padding: 0; line-height: 1;
}
.chip button:hover { color: var(--text); }
.chip-clear {
  color: var(--accent);
  font-size: 11.5px;
  background: transparent; border: 0; cursor: pointer; padding: 0 4px;
  margin-left: 2px;
}

/* ===================== KPI STRIP ===================== */
.kpi-strip {
  margin-bottom: 16px;
}
/* Consolidated headline block: one card containing lead + mini stats + mix. */
.kpi-head {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 2fr;
  grid-template-areas:
    "lead grid"
    "mix  mix";
  column-gap: 24px;
  row-gap: 14px;
  align-items: center;
}
.kpi-head .kpi-lead   { grid-area: lead; min-width: 0; }
.kpi-head .kpi-grid   {
  grid-area: grid;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  min-width: 0;
}
.kpi-head .kpi-mix-row {
  grid-area: mix;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.kpi-head .kpi-mix-row .kpi-label { margin: 0; white-space: nowrap; }
.kpi-head .kpi-lead .kpi-value { font-size: 30px; }
.kpi-head .kpi-mini { min-width: 0; }
.kpi-head .kpi-mini .kpi-value { font-size: 20px; }
@media (max-width: 900px) {
  .kpi-head {
    grid-template-columns: 1fr;
    grid-template-areas:
      "lead"
      "grid"
      "mix";
  }
}
@media (max-width: 520px) {
  .kpi-head { padding: 14px; column-gap: 12px; }
  .kpi-head .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-head .kpi-lead .kpi-value { font-size: 26px; }
  .kpi-head .kpi-mini .kpi-value { font-size: 16px; }
  .kpi-head .kpi-mix-row { padding-top: 8px; row-gap: 4px; }
}

.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px;
  min-height: 82px;
  min-width: 0;
  overflow: hidden;
}
.kpi-sub { overflow-wrap: anywhere; }
.kpi-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.kpi-value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
  color: var(--text);
}
.kpi-sub {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 2px;
}
.kpi-mix {
  display: flex; flex-wrap: wrap; gap: 4px 8px;
  font-size: 11.5px;
  margin-top: 4px;
}
.kpi-mix span { white-space: nowrap; }
.kpi-mix b { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.kpi-mix .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  vertical-align: middle; margin-right: 4px;
}

/* ===================== CARDS ===================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 14px;
}
.card-wide { /* full-width now that main is fluid; nothing extra needed */ }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}
.card-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text);
}
.head-right { display: flex; align-items: center; gap: 14px; }
.card-sub {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 400;
}

.chart-wrap { width: 100%; overflow: hidden; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 0;
}
.grid-2 .card { margin-bottom: 14px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* Usage-by-user heatmap needs more horizontal room than the leaderboard it
   sits next to — give the heatmap roughly two-thirds of the row on desktop. */
.grid-heat-lb {
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}
@media (max-width: 900px) {
  .grid-heat-lb { grid-template-columns: 1fr; }
}

/* ===================== SVG CHART PRIMITIVES ===================== */
svg { display: block; font-family: inherit; }
svg text { fill: var(--muted); font-size: 10.5px; }
svg .axis-line { stroke: var(--border); }
svg .grid-line { stroke: var(--grid); }
svg .bar-rect { fill: var(--accent); transition: opacity .12s; }
svg .bar-stack { opacity: 0; pointer-events: none; transition: opacity .12s; }
svg .bar-group.hover .bar-rect { opacity: 0; }
svg .bar-group.hover .bar-stack { opacity: 1; }
svg .bar-label { fill: var(--text); font-size: 10.5px; font-variant-numeric: tabular-nums; }
svg .bar-value { fill: var(--text); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
svg .weekend-band { fill: var(--weekend); }
svg .line { stroke: var(--cat-3); stroke-width: 1.4; fill: none; }
svg .h-bar { fill: var(--accent); }
svg .h-bar-bg { fill: var(--card-2); }
svg .h-bar-value { fill: var(--text); font-variant-numeric: tabular-nums; }
svg .h-bar-label { fill: var(--text-2); }
svg .h-bar-sub { fill: var(--muted); font-size: 10px; }
svg .heat-cell { stroke: var(--card); stroke-width: 1; }
svg .heat-row-label { fill: var(--text-2); font-size: 10.5px; }
svg .heat-col-label { fill: var(--muted-2); font-size: 9.5px; }

/* Usage-by-user heatmap must always span the full container width, both on
   desktop and phone, and must never require horizontal scroll. */
#heatmap { overflow: hidden; width: 100%; }
#heatmap svg { display: block; width: 100%; min-width: 0; height: auto; }

/* ===================== LEADERBOARD ===================== */
.leaderboard { display: flex; flex-direction: column; }
.lb-row {
  display: grid;
  grid-template-columns: 28px 1fr 110px 80px 26px;
  align-items: center;
  gap: 10px;
  padding: 10px 6px;
  border-bottom: 1px solid var(--border);
}
.lb-row:last-child { border-bottom: 0; }
.lb-row:hover { background: var(--card-2); }
.lb-row:hover .lb-excl { opacity: 1; }
.lb-rank {
  color: var(--muted-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.lb-who { overflow: hidden; }
.lb-name {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lb-meta {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.lb-spark { height: 22px; }
.lb-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 13px;
}
.lb-count small { color: var(--muted); font-weight: 400; font-size: 10.5px; display: block; }
.lb-excl {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted-2);
  width: 22px; height: 22px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, color .12s, border-color .12s;
  line-height: 1; padding: 0;
  font-size: 14px;
}
.lb-excl:hover {
  color: var(--text);
  border-color: var(--border-strong);
}
.lb-row.excluded {
  opacity: .55;
}
.lb-row.excluded .lb-excl { opacity: 1; color: var(--accent); border-color: var(--accent-weak); background: var(--accent-soft); }

/* ===================== FOOTER ===================== */
.foot {
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.foot code {
  background: var(--card-2); padding: 1px 6px; border-radius: 4px;
  font-size: 11px;
}

/* ===================== DRAWER ===================== */
.drawer { position: fixed; inset: 0; z-index: 100; }
.drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 17, 21, .32);
  backdrop-filter: blur(2px);
  animation: fadeIn .15s ease-out;
}
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(780px, 96vw);
  background: var(--card);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  box-shadow: -8px 0 24px rgba(0,0,0,.12);
  animation: slideIn .18s ease-out;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideIn { from { transform: translateX(16px); opacity: 0 } to { transform: none; opacity: 1 } }

.drawer-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 {
  margin: 0; font-size: 14px; font-weight: 600;
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.drawer-close, .drawer-back {
  appearance: none; background: transparent; border: 0;
  color: var(--muted); cursor: pointer;
  padding: 6px 10px; border-radius: 6px;
  font: inherit; font-size: 12px;
}
.drawer-close:hover, .drawer-back:hover { background: var(--card-2); color: var(--text); }
.drawer-body {
  flex: 1; overflow-y: auto;
  padding: 14px 18px;
}

.item-list { display: flex; flex-direction: column; gap: 6px; }
.item-list .item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.item-list .item:hover {
  border-color: var(--border-strong);
  background: var(--card-2);
}
.item-list .item .t { font-weight: 500; color: var(--text); }
.item-list .item .m { color: var(--muted); font-size: 11.5px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.item-list .item .pill {
  display: inline-block; margin-left: 6px;
  padding: 1px 7px; font-size: 10.5px;
  border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); background: var(--card-2);
}

/* conversation view inside drawer */
.convo-hdr {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.convo-hdr .title { font-size: 15px; font-weight: 600; }
.convo-hdr .meta { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.convo-summary {
  background: var(--card-2);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 12px;
  margin-bottom: 14px;
}
.msg { display: flex; gap: 10px; margin-bottom: 16px; }
.msg .avatar {
  flex: 0 0 26px; width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: #fff;
  background: var(--accent);
}
.msg.human .avatar { background: var(--cat-3); }
.msg-body { flex: 1; min-width: 0; }
.msg-meta { font-size: 10.5px; color: var(--muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .04em; }
.msg-bubble {
  background: var(--card-2);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.msg.human .msg-bubble { background: #eff6ff; border-color: #dbeafe; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { font-size: 13.5px; font-weight: 600; margin: 8px 0 4px; }
.msg-bubble p { margin: 6px 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin: 6px 0; }
.msg-bubble code { background: #f3f4f6; padding: 1px 4px; border-radius: 3px; font-size: 11.5px; font-family: ui-monospace, monospace; }
.msg-bubble pre { background: #f3f4f6; padding: 8px 10px; border-radius: 6px; overflow-x: auto; font-size: 11.5px; }
.tool-block {
  margin: 6px 0; border: 1px solid #fde68a; background: #fffbeb; border-radius: 6px;
  font-size: 11.5px;
}
.tool-head {
  padding: 6px 10px; cursor: pointer; display: flex; justify-content: space-between;
  color: #92400e; font-weight: 500;
}
.tool-head .chev { transition: transform .1s; display: inline-block; margin-right: 4px; }
.tool-block.open .tool-head .chev { transform: rotate(90deg); }
.tool-body {
  display: none; padding: 8px 10px; border-top: 1px solid #fde68a;
  font-family: ui-monospace, monospace; white-space: pre-wrap; word-wrap: break-word;
  max-height: 320px; overflow-y: auto; font-size: 11px;
}
.tool-block.open .tool-body { display: block; }

.h-bar-hit { cursor: pointer; }
.h-bar-hit:hover { fill: rgba(37, 99, 235, .04); }

/* ===================== COMPARE VIEW ===================== */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
@media (max-width: 900px) { .compare-grid { grid-template-columns: 1fr; } }
.compare-header {
  display: flex; align-items: baseline; gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.compare-header .org-name { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.compare-header .org-sub { color: var(--muted); font-size: 11.5px; }
.compare-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.compare-kpis .kpi { min-height: 64px; padding: 10px 12px; }
.compare-kpis .kpi-value { font-size: 18px; }

.overlay-legend {
  display: flex; gap: 14px; font-size: 11px; color: var(--muted);
  margin-bottom: 8px;
}
.overlay-legend span { display: inline-flex; align-items: center; gap: 6px; }
.overlay-legend i {
  display: inline-block; width: 12px; height: 2px; border-radius: 1px;
}

/* "title only" items no longer click through */
.item-list .item[data-title-only="true"] { cursor: default; }
.item-list .item[data-title-only="true"]:hover { background: var(--card); border-color: var(--border); }

/* ===================== FLOATING TOOLTIP ===================== */
.tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: #0f172a;
  color: #fff;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11.5px;
  min-width: 180px;
  max-width: 300px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  font-variant-numeric: tabular-nums;
}
.tip .tip-title { font-weight: 600; font-size: 12px; margin-bottom: 6px; color: #fff; }
.tip .tip-sub { color: #94a3b8; font-size: 10.5px; margin-bottom: 6px; }
.tip table { width: 100%; border-collapse: collapse; }
.tip td { padding: 2px 0; font-size: 11px; }
.tip td.n { text-align: right; color: #fff; font-weight: 500; padding-left: 12px; }
.tip td.u { color: #cbd5e1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.tip .tip-foot { color: #64748b; font-size: 10px; margin-top: 6px; text-align: center; }

svg [data-tip] { cursor: pointer; }

/* ===================== USAGE TABLE ===================== */
.usage-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.usage-table th, .usage-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}
.usage-table th {
  background: var(--card-2);
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  cursor: pointer;
  position: sticky;
  top: 0;
  z-index: 1;
  user-select: none;
}
.usage-table th:hover { color: var(--text); }
.usage-table th.sorted { color: var(--accent); }
.usage-table th .sort-ind { opacity: .6; margin-left: 2px; }
.usage-table th[data-align="left"],
.usage-table td[data-align="left"] { text-align: left; }
.usage-table tbody tr { cursor: pointer; }
.usage-table tbody tr:hover td { background: rgba(37, 99, 235, .04); }
.usage-table tbody tr:last-child td { border-bottom: 0; }
.usage-table .name-cell {
  text-align: left;
  font-weight: 500;
  color: var(--text);
}
.usage-table .email-cell {
  text-align: left;
  color: var(--muted);
  font-size: 11px;
}
.usage-table .badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 500;
}
.usage-table .badge.power   { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-weak); }
.usage-table .badge.regular { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.usage-table .badge.explorer{ background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.usage-table .badge.dormant { background: #f3f4f6; color: #4b5563; border: 1px solid #e5e7eb; }

.sub-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted);
  cursor: pointer;
}
.sub-toggle input { accent-color: var(--accent); cursor: pointer; }
.copy-grp { display: inline-flex; gap: 4px; }
.copy-btn {
  appearance: none;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  font: inherit; font-size: 11px; color: var(--muted);
  cursor: pointer;
}
.copy-btn:hover { border-color: var(--border-strong); color: var(--text); }
.copy-btn.ok { color: var(--cat-3); border-color: var(--cat-3); }

/* ===================== ADOPTION FUNNEL ===================== */
.funnel { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.funnel .stage {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  position: relative;
  min-width: 0;
  overflow: hidden;
}
.funnel .stage .lbl {
  font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  margin-bottom: 4px;
}
.funnel .stage .n {
  font-size: 24px; font-weight: 600; letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.funnel .stage .pct { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.funnel .stage.clickable { cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .06s; }
.funnel .stage.clickable:hover { box-shadow: 0 1px 4px rgba(0,0,0,.08); border-color: var(--border-strong); }
.funnel .stage.clickable:active { transform: scale(0.995); }
.funnel .stage.invited  { border-color: #cbd5e1; }
.funnel .stage.joined   { border-color: #bfdbfe; background: #eff6ff; }
.funnel .stage.active   { border-color: #bbf7d0; background: #f0fdf4; }
.funnel .stage.engaged  { border-color: #fde68a; background: #fffbeb; }

/* Compare split funnel: each stage box shows Navillus and OCS side-by-side
   so "Engaged: 7 vs 6" reads as a direct within-box comparison. Each column
   gets a translucent brand tint (blue for Navillus, green for OCS) so the
   org identity is unambiguous at a glance. */
.funnel-split .stage { padding: 14px 10px; background: var(--card); }
.funnel-split .split-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: stretch;
  margin-top: 6px;
}
.funnel-split .split-col {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 0;
  padding: 8px 6px;
  border-radius: 8px;
}
.funnel-split .split-col.navillus {
  background: rgba(37, 99, 235, 0.10);
  border: 1px solid rgba(37, 99, 235, 0.18);
}
.funnel-split .split-col.ocs {
  background: rgba(5, 150, 105, 0.10);
  border: 1px solid rgba(5, 150, 105, 0.20);
}
.funnel-split .split-col .n { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.funnel-split .split-col .pct { color: var(--muted); font-size: 11px; margin-top: 2px; }
.funnel-split .split-dot { width: 8px; height: 8px; border-radius: 50%; margin-bottom: 4px; }
.funnel-split .split-sep {
  display: flex; align-items: center;
  color: var(--muted-2); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
}

.invitee-list {
  display: flex; flex-direction: column; max-height: 480px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px;
}
.invitee-row {
  display: grid;
  grid-template-columns: 1fr 100px 90px 120px;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  transition: background .08s;
}
.invitee-row:last-child { border-bottom: 0; }
.invitee-row .n { font-weight: 500; color: var(--text); }
.invitee-row .e { color: var(--muted); font-size: 11px; display: block; }
.invitee-row .s { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Status colour coding: green = active, blue = joined-but-not-using, red = not joined */
.invitee-row.status-active    { background: rgba(16, 185, 129, 0.09); }
.invitee-row.status-active:hover  { background: rgba(16, 185, 129, 0.16); cursor: pointer; }
.invitee-row.status-joined    { background: rgba(37, 99, 235, 0.08); }
.invitee-row.status-joined:hover { background: rgba(37, 99, 235, 0.14); cursor: pointer; }
.invitee-row.status-not-joined { background: rgba(220, 38, 38, 0.06); }
.invitee-row.status-not-joined .n { color: var(--muted); }
.invitee-row.status-not-joined:hover { background: rgba(220, 38, 38, 0.09); cursor: default; }

@media (max-width: 900px) {
  .funnel { grid-template-columns: repeat(2, 1fr); }
  .invitee-row { grid-template-columns: 1fr auto; gap: 4px; }
  .invitee-row .s { font-size: 10.5px; }
}

/* ===================== DIVIDER ===================== */
.card-divider {
  border: 0;
  height: 1px;
  background: var(--border);
  margin: 16px 0 14px;
}

/* ===================== ENTRY GATE ===================== */
#entryGate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}
#entryGate .gate-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
}
#entryGate .gate-logo {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
  margin-bottom: 18px;
}
#entryGate h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
  color: var(--text);
}
#entryGate p {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 22px;
}
#entryGate form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#entryGate input[type="password"] {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  background: var(--card-2);
  color: var(--text);
  outline: none;
  transition: border-color 0.12s, background 0.12s;
}
#entryGate input[type="password"]:focus {
  border-color: var(--accent);
  background: var(--card);
}
#entryGate button {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.12s;
}
#entryGate button:hover { opacity: 0.92; }
#entryGate .gate-err {
  color: #dc2626;
  font-size: 12px;
  margin-top: 10px;
  min-height: 16px;
}

/* Short-label toggle: desktop shows full labels, phone shows compact. */
.lbl-short { display: none; }

/* Mobile: slot below concentration notice where the exclusion buttons relocate. */
.mobile-excl-slot { display: none; }
.mobile-excl-slot:empty { display: none !important; }
@media (max-width: 720px) {
  .mobile-excl-slot:not(:empty) {
    display: flex;
    width: 100%;
    margin: 4px 0 10px;
  }
  .mobile-excl-slot .excl-group {
    width: 100%;
    justify-content: stretch;
    gap: 4px;
    align-items: center;
  }
}

/* ===================== MOBILE ===================== */
@media (max-width: 720px) {
  .lbl-full { display: none; }
  .lbl-short { display: inline; }

  main { padding: 12px 10px 48px; }

  /* Topbar stacks: brand row, then all controls in their own row. Keep it
     compact so the sticky header doesn't dominate the viewport on phones. */
  .topbar {
    padding: 8px 10px;
    flex-direction: column;
    align-items: stretch !important;
    justify-content: flex-start;
    gap: 6px;
  }
  .topbar > * { width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }
  .topbar-controls { max-width: 100%; min-width: 0; overflow: hidden; }
  .topbar-controls > * { max-width: 100%; min-width: 0; }
  .topbar-brand { gap: 8px; }
  .brand-title { font-size: 15px; }
  .brand-sub { display: none; }
  .topbar-logo { height: 26px; }

  .topbar-controls {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .seg, .excl-group { width: 100%; display: flex; box-sizing: border-box; }
  /* Key fix: segmented controls must flex to fit the container width, not overflow it. */
  .seg { flex-wrap: nowrap; display: flex; }
  .seg-btn {
    padding: 6px 6px;
    font-size: 11px;
    white-space: nowrap;
    flex: 1 1 0;        /* all buttons share width equally */
    min-width: 0;
    text-align: center;
  }
  .excl-group { justify-content: stretch; gap: 4px; flex-wrap: nowrap; align-items: center; }
  .excl-label { font-size: 10.5px; flex-shrink: 0; color: var(--muted); }
  .excl-btn { padding: 4px 6px; font-size: 11px; white-space: nowrap; flex: 1 1 0; min-width: 0; text-align: center; }

  .load-status {
    text-align: left;
    font-size: 11.5px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
  }
  .last-updated { font-size: 10.5px; }
  #loadStatus { line-height: 1.4; }

  /* KPI strip is a single consolidated card on phone (see .kpi-head). */

  .grid-2 { grid-template-columns: 1fr; gap: 10px; }

  .card { padding: 12px; max-width: 100%; overflow: hidden; min-width: 0; }
  main > *, main > .card, #singleView, #singleView > * { max-width: 100%; min-width: 0; }
  /* Use overflow-x: clip on the root so horizontal bleed is prevented without
     breaking the scroll container — `hidden` on html/body makes position:sticky
     unreliable on iOS Safari, so the topbar wouldn't actually stick. */
  html, body { width: 100%; max-width: 100vw; overflow-x: clip; overflow-y: visible; }
  main { width: 100%; max-width: 100vw; overflow-x: clip; }
  .card-head { flex-direction: column; align-items: flex-start; gap: 6px; }
  .card-head .head-right { width: 100%; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; }

  /* Funnel: 2x2 on phone, tighter. */
  .funnel { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .funnel .stage { padding: 8px; }
  .funnel .stage .n { font-size: 20px; }

  /* Invitee list on phone: name (truncates) + first badge only. Msg count
     and last-active date are hidden — the name tells you who, the badge
     tells you their status. Full data still available on desktop. */
  .invitee-list { grid-template-columns: 1fr; }
  .invitee-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 8px 10px;
  }
  .invitee-row .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; }
  .invitee-row .e { display: none; }
  .invitee-row .s { font-size: 10.5px; white-space: nowrap; text-align: right; }
  /* Hide the 2nd and 3rd .s (msg count + date). Keep only the badge. */
  .invitee-row .s ~ .s { display: none; }
  .invitee-row .badge { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }

  /* Leaderboard: drop sparkline + meta, keep rank / name / count. */
  .lb-row {
    grid-template-columns: 20px minmax(0, 1fr) auto 22px;
    gap: 8px;
    padding: 8px 4px;
  }
  .lb-spark, .lb-meta { display: none; }
  .lb-name { font-size: 13px; }
  .lb-count { font-size: 12.5px; }
  .lb-count small { font-size: 10px; }
  .lb-excl { opacity: 1; width: 20px; height: 20px; font-size: 12px; }

  /* Charts: let the bar charts actually fit the phone. Only the heatmap and
     usage table scroll horizontally — the rest should render at container width. */
  .chart-wrap { overflow: hidden; }
  .card svg { min-width: 0; }
  /* Keep the day/hour/active-user charts readable; they use meet aspect-ratio
     so narrow viewports were shrinking them vertically. */
  #chartByDay svg, #chartByHour svg, #chartActiveUsers svg { height: 210px !important; }
  /* The SVGs intrinsically render at 900-1600 wide; when scaled down to the
     phone viewport the baked-in font-size shrinks too. Bump axis labels so
     they remain legible after scaling. */
  #chartByDay svg text,
  #chartByHour svg text,
  #chartActiveUsers svg text { font-size: 18px; }
  .usage-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* Heatmap ("Usage by user") expands to full phone width rather than scrolling —
     the SVG sizes itself to the container via clientWidth, so no min-width clamp. */
  #heatmap { overflow: hidden; }
  #heatmap svg { min-width: 0; width: 100%; }
  /* Allow the heatmap card to break out of .card padding so the grid uses the
     entire viewport horizontally on phones. */
  .card-wide.card-bleed { padding-left: 0; padding-right: 0; }
  .card-wide.card-bleed > .card-head { padding-left: 12px; padding-right: 12px; }
  .card-wide.card-bleed > #heatmap { padding-left: 4px; padding-right: 4px; }
  .usage-table { min-width: 640px; font-size: 11.5px; }

  /* Horizontal bar charts (tasks, plugins): tighten label widths via JS opts
     isn't easy, so just scale the labels down for readability. */
  svg .h-bar-label { font-size: 10px; }
  svg .h-bar-value { font-size: 11px; }
  svg .h-bar-sub { font-size: 9.5px; }
}

@media (max-width: 440px) {
  .funnel { grid-template-columns: 1fr 1fr; }
  .card { padding: 10px; }
  .card-head h3 { font-size: 14px; }
}

