/* Self-hosted IBM Plex fonts (file:// friendly). */
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../assets/fonts/IBMPlexSans-Regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../assets/fonts/IBMPlexSans-Medium.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../assets/fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
  font-style: normal;
  font-weight: 600 699;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("../assets/fonts/IBMPlexMono-Regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("../assets/fonts/IBMPlexMono-Medium.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

/* TriLumen Systems — Sales Ops Dashboard (light BI theme) */
:root {
  --bg: #f4f6f9;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-card-2: #f8fafc;
  --border: #d7dee8;
  --border-soft: #e4e9f0;
  --text: #1a2332;
  --text-dim: #5a6a80;
  --text-mute: #7a8799;
  --accent: #4C4272;
  --accent-2: #7C70B8;
  --accent-3: #d97706;
  --danger: #dc2626;
  --good: #059669;
  --warn: #ca8a04;
  --chip: #eef2f7;
  --row-hover: rgba(76, 66, 114, 0.06);
  --row-active: rgba(124, 112, 184, 0.08);
  --shadow: 0 1px 3px rgba(26, 35, 50, 0.06), 0 4px 16px rgba(26, 35, 50, 0.04);
  --radius: 10px;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

/* DataFlip-style redaction chrome */
.redact {
  display: inline-block;
  height: .82em;
  width: 4.8em;
  background: #000;
  border-radius: 1px;
  vertical-align: -.06em;
}
.redact-client { width: 12em; height: .92em; }
.redact-footer { width: 9em; height: .78em; }
.redact-loading { width: 8em; }
.associate-label { white-space: nowrap; }
.redact-name { margin-left: .3em; width: 4.2em; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-2); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand-block { display: flex; flex-direction: column; gap: 2px; min-width: 220px; }
.brand-kicker {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-mute);
}
.brand-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-sub { color: var(--text-dim); font-size: 11px; }

.topbar-center { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.breadcrumb {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text-dim);
}
.breadcrumb button {
  background: none; border: none; color: var(--accent-2);
  padding: 2px 4px; border-radius: 4px; font-size: 12px;
}
.breadcrumb button:hover { background: var(--chip); }
.breadcrumb button.current { color: var(--text); font-weight: 600; cursor: default; }
.breadcrumb .sep { color: var(--text-mute); }

.controls-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg {
  display: inline-flex; background: var(--bg-card-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 2px; gap: 2px;
}
.seg button {
  border: none; background: transparent; color: var(--text-dim);
  padding: 5px 12px; border-radius: 6px; font-size: 12px; font-weight: 500;
}
.seg button.active {
  background: #ffffff;
  color: var(--accent-2);
  box-shadow: 0 1px 2px rgba(26, 35, 50, 0.08);
  border: 1px solid var(--border-soft);
  font-weight: 600;
}
.badge-sample {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(217, 119, 6, 0.1);
  color: var(--accent-3);
  border: 1px solid rgba(217, 119, 6, 0.3);
  padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-sample::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-3);
}

.logo-wrap {
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}
.logo-wrap img {
  width: 180px;
  height: auto;
  max-height: 40px;
  display: block;
  object-fit: contain;
  object-position: right center;
}

/* Tabs */
.tabs {
  display: flex; gap: 2px; padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
  overflow-x: auto;
}
.tabs button {
  border: none; background: transparent; color: var(--text-dim);
  padding: 10px 14px; font-size: 12px; font-weight: 500;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Main */
.main {
  flex: 1;
  padding: 14px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 10px;
}
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 720px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-wrap: wrap; }
  .logo-wrap { order: -1; width: 100%; flex-direction: row; justify-content: flex-end; align-items: center; }
  .logo-wrap img { width: 160px; }
}

.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  min-height: 78px;
  display: flex; flex-direction: column; gap: 4px;
}
.kpi .label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-mute); font-weight: 600;
}
.kpi .value { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .delta {
  font-size: 11px; font-family: var(--mono); color: var(--text-dim);
  display: flex; gap: 6px; align-items: center;
}
.kpi .delta .up { color: var(--good); }
.kpi .delta .down { color: var(--danger); }
.kpi .delta .flat { color: var(--text-mute); }

.panel-row {
  display: grid;
  gap: 12px;
}
.panel-row.two { grid-template-columns: 1.2fr 1fr; }
.panel-row.three { grid-template-columns: 1fr 1fr 1fr; }
.panel-row.split-rank { grid-template-columns: 1fr 1fr; }
@media (max-width: 980px) {
  .panel-row.two, .panel-row.three, .panel-row.split-rank { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  min-height: 0;
}
.panel-hd {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-card-2);
  border-radius: var(--radius) var(--radius) 0 0;
}
.panel-hd h2 {
  margin: 0; font-size: 13px; font-weight: 600; letter-spacing: -0.01em;
}
.panel-hd .meta { color: var(--text-mute); font-size: 11px; }
.panel-bd { padding: 12px 14px; flex: 1; }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.chart-box.funnel { height: 300px; }

table.data {
  width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums;
}
table.data th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-mute); font-weight: 600;
  padding: 8px 8px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-elev); z-index: 1;
}
table.data th.num, table.data td.num { text-align: right; }
table.data td {
  padding: 7px 8px; border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}
table.data tr { cursor: pointer; transition: background .12s; }
table.data tbody tr:hover { background: var(--row-hover); }
table.data tbody tr.active { background: var(--row-active); }
table.data .rank {
  width: 28px; color: var(--text-mute); font-family: var(--mono); font-size: 11px;
}
table.data .entity { font-weight: 550; }
table.data .sub { color: var(--text-mute); font-size: 11px; display: block; }
.delta-pill {
  display: inline-block; padding: 1px 6px; border-radius: 999px;
  font-size: 11px; font-family: var(--mono);
}
.delta-pill.up { background: rgba(5, 150, 105, 0.12); color: var(--good); }
.delta-pill.down { background: rgba(220, 38, 38, 0.1); color: var(--danger); }
.delta-pill.flat { background: var(--chip); color: var(--text-mute); }

.scroll-table { max-height: 420px; overflow: auto; }

.funnel-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.funnel-step {
  display: grid; grid-template-columns: 90px 1fr 100px; gap: 10px; align-items: center;
}
.funnel-step .name { color: var(--text-dim); font-size: 12px; font-weight: 600; }
.funnel-bar-track {
  height: 28px; background: #eef2f7; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--border-soft); position: relative;
}
.funnel-bar-fill {
  height: 100%; border-radius: 6px;
  display: flex; align-items: center; padding-left: 10px;
  font-size: 11px; font-weight: 600; color: #ffffff;
  transition: width .35s ease;
}
.funnel-step:nth-child(1) .funnel-bar-fill { background: linear-gradient(90deg, #7C70B8, #A399C9); }
.funnel-step:nth-child(2) .funnel-bar-fill { background: linear-gradient(90deg, #4C4272, #7C70B8); }
.funnel-step:nth-child(3) .funnel-bar-fill { background: linear-gradient(90deg, #059669, #10b981); }
.funnel-step .val { text-align: right; font-family: var(--mono); font-size: 12px; }
.funnel-rates {
  display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px;
  padding-top: 12px; border-top: 1px dashed var(--border);
}
.funnel-rates .metric {
  background: var(--chip); border-radius: 8px; padding: 8px 12px; min-width: 120px;
  border: 1px solid var(--border-soft);
}
.funnel-rates .metric .l { font-size: 10px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .06em; }
.funnel-rates .metric .v { font-size: 16px; font-weight: 600; margin-top: 2px; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px;
}
.toolbar input[type="search"], .toolbar select {
  background: #ffffff; border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 7px 10px; font-size: 12px; outline: none;
}
.toolbar input[type="search"] { min-width: 220px; }
.toolbar input[type="search"]:focus, .toolbar select:focus {
  border-color: var(--accent-2); box-shadow: 0 0 0 2px rgba(124, 112, 184, 0.15);
}
.btn {
  background: #ffffff; border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 7px 12px; font-size: 12px; font-weight: 500;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary {
  background: linear-gradient(180deg, #4C4272, #3A3358);
  border-color: #3A3358; color: #ffffff;
}

.pager { display: flex; gap: 8px; align-items: center; color: var(--text-dim); font-size: 12px; }

/* Drawer */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(26, 35, 50, 0.35);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 80;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(420px, 100%);
  background: var(--bg-elev); border-left: 1px solid var(--border);
  box-shadow: -8px 0 28px rgba(26, 35, 50, 0.12);
  transform: translateX(105%); transition: transform .25s ease;
  z-index: 90; display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-hd {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  background: var(--bg-card-2);
}
.drawer-hd h3 { margin: 0; font-size: 15px; }
.drawer-hd .id { font-family: var(--mono); color: var(--accent-3); font-size: 13px; margin-top: 4px; }
.drawer-close {
  background: var(--chip); border: 1px solid var(--border); color: var(--text);
  width: 32px; height: 32px; border-radius: 8px; font-size: 16px;
}
.drawer-bd { padding: 16px 18px; overflow: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin-bottom: 16px; }
.kv .k { color: var(--text-mute); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.kv .v { font-weight: 500; }
.line-items { width: 100%; border-collapse: collapse; }
.line-items th, .line-items td { padding: 6px 8px; border-bottom: 1px solid var(--border-soft); }
.line-items th { font-size: 10px; color: var(--text-mute); text-transform: uppercase; text-align: left; }
.line-items td.num { text-align: right; font-family: var(--mono); font-size: 12px; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
}
.status.ok { background: rgba(5, 150, 105, 0.12); color: var(--good); }
.status.ret { background: rgba(220, 38, 38, 0.1); color: var(--danger); }

.loading {
  display: flex; align-items: center; justify-content: center;
  min-height: 60vh; color: var(--text-dim); gap: 12px; flex-direction: column;
}
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hint {
  color: var(--text-mute); font-size: 11px; margin-top: 6px;
}
.footer-note {
  text-align: center; color: var(--text-mute); font-size: 10px;
  padding: 8px 18px 16px; letter-spacing: 0.04em;
}

.empty {
  padding: 28px; text-align: center; color: var(--text-mute);
}

.cat-legend {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px;
}
.cat-legend span {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-dim);
}
.cat-legend i {
  width: 10px; height: 10px; border-radius: 2px; display: inline-block;
}

#drawerBody { display: flex; flex-direction: column; height: 100%; min-height: 0; }
#drawerBody .drawer-bd { flex: 1; overflow: auto; }

/* Embed mode (?embed=1): hide TriLumen wordmark + footer; unstick chrome */
html.embed .logo-wrap,
html.embed .footer-note { display: none !important; }
html.embed .topbar { position: static !important; top: auto !important; backdrop-filter: none; background: #fff; }
html.embed .app { min-height: 0; }
html.embed body { overflow: hidden; }
