  /* ============================================================
     FG Dashboard Standards v1.0 — TAM dashboard
     CSS colors are set by updateTheme() via --c-* custom
     properties. Components reference var(--c-token) only.
     ============================================================ */
  :root {
    --c-bg: #f4f5f8;
    --c-panel: #ffffff;
    --c-text: #6b7080;
    --c-text-main: #1a1c24;
    --c-border: rgba(0,0,0,0.08);
    --c-grid: rgba(0,0,0,0.06);
    --c-surface: #ffffff;
    --c-primary: #01696f;
    --c-primary-soft: rgba(1,105,111,0.12);
    --c-gold: #d19900;
    --c-success: #437a22;
    --c-error: #a13544;
    --c-purple: #7a39bb;
    --c-orange: #da7101;
    /* filter-code palette — reuse semantic tokens */
    --c-f-pd: var(--c-orange);
    --c-f-hv: var(--c-error);
    --c-f-ba: var(--c-primary);
    --c-f-s:  var(--c-success);
    --c-f-dash: #8a909e;
    --c-heat-lo: rgba(1,105,111,0.08);
    --c-heat-hi: #01696f;
  }
  /* Dark palette — applied when the user explicitly overrides to dark */
  html[data-theme="dark"] {
    --c-bg: #131620;
    --c-panel: #1c1f26;
    --c-text: #8b90a0;
    --c-text-main: #e2e4ea;
    --c-border: rgba(255,255,255,0.07);
    --c-grid: rgba(255,255,255,0.05);
    --c-surface: #1c1f26;
    --c-primary: #4f98a3;
    --c-primary-soft: rgba(79,152,163,0.14);
    --c-gold: #e8af34;
    --c-success: #6daa45;
    --c-error: #dd6974;
    --c-purple: #a86fdf;
    --c-orange: #fdab43;
    --c-f-pd: var(--c-orange);
    --c-f-hv: var(--c-error);
    --c-f-ba: var(--c-primary);
    --c-f-s:  var(--c-success);
    --c-f-dash: #5b6170;
    --c-heat-lo: rgba(79,152,163,0.10);
    --c-heat-hi: #4f98a3;
  }
  /* OS auto-dark: only applies when the user has NOT chosen a manual
     override. :not([data-theme]) guards against the manual light/dark
     attributes clobbering the OS preference. */
  @media (prefers-color-scheme: dark) {
    html:not([data-theme]) {
      --c-bg: #131620;
      --c-panel: #1c1f26;
      --c-text: #8b90a0;
      --c-text-main: #e2e4ea;
      --c-border: rgba(255,255,255,0.07);
      --c-grid: rgba(255,255,255,0.05);
      --c-surface: #1c1f26;
      --c-primary: #4f98a3;
      --c-primary-soft: rgba(79,152,163,0.14);
      --c-gold: #e8af34;
      --c-success: #6daa45;
      --c-error: #dd6974;
      --c-purple: #a86fdf;
      --c-orange: #fdab43;
      --c-f-pd: var(--c-orange);
      --c-f-hv: var(--c-error);
      --c-f-ba: var(--c-primary);
      --c-f-s:  var(--c-success);
      --c-f-dash: #5b6170;
      --c-heat-lo: rgba(79,152,163,0.10);
      --c-heat-hi: #4f98a3;
    }
  }

  * { box-sizing: border-box; }
  html, body {
    margin: 0; padding: 0;
    background: var(--c-bg); color: var(--c-text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px; line-height: 1.45;
  }
  .wrap { max-width: 1400px; margin: 0 auto; padding: 20px 24px 80px; }

  /* Banner */
  #fetch-error-banner {
    display: none;
    background: var(--c-error); color: #fff;
    padding: 10px 14px; border-radius: 6px;
    font-size: 13px; margin-bottom: 14px;
  }

  /* Header */
  header.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
  header.top h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.2px; }
  header.top .sub { color: var(--c-text); font-size: 12px; margin-top: 4px; }
  .toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .btn {
    background: var(--c-panel); border: 1px solid var(--c-border); color: var(--c-text-main);
    padding: 6px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; font-family: inherit;
  }
  .btn:hover { border-color: var(--c-primary); color: var(--c-primary); }
  .btn.primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
  .btn.primary:hover { filter: brightness(1.08); color: #fff; }

  /* View switcher in header toolbar */
  .nav-tabs { display: inline-flex; gap: 0; border: 1px solid var(--c-border); border-radius: 6px; overflow: hidden; }
  .nav-tabs .nav-btn {
    background: var(--c-panel); color: var(--c-text); border: 0; border-right: 1px solid var(--c-border);
    padding: 6px 12px; font-size: 12px; cursor: pointer; font-family: inherit;
  }
  .nav-tabs .nav-btn:last-child { border-right: 0; }
  .nav-tabs .nav-btn:hover { color: var(--c-primary); }
  .nav-tabs .nav-btn.active { background: var(--c-primary); color: #fff; }

  /* ----- Tab loading indicator -----
     Applied by _tabLoadStart / _tabLoadEnd in app.js while a DuckDB query
     is in flight for SQL / CIP Docs / Services tabs. Two signals:
       1. A small spinner glyph appears to the right of the nav label so
          the user sees the clicked tab is working.
       2. The section's table host is dimmed via [aria-busy="true"] so
          the user can see the data is stale/loading (not frozen). */
  .nav-tabs .nav-btn.is-loading { padding-right: 26px; position: relative; }
  .nav-tabs .nav-btn.is-loading::after {
    content: "";
    position: absolute;
    right: 9px;
    top: 50%;
    width: 10px; height: 10px;
    margin-top: -5px;
    border: 1.5px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    opacity: 0.75;
    animation: cip-spin 0.7s linear infinite;
  }
  @keyframes cip-spin { to { transform: rotate(360deg); } }

  /* Dim the table host (and any descendants) while a query is running.
     Scoped to sections that opt into aria-busy so we don't affect other
     views. pointer-events:none prevents interactions on stale data. */
  section[aria-busy="true"] .tabulator {
    opacity: 0.55;
    transition: opacity 120ms ease-in;
    pointer-events: none;
  }
  section[aria-busy="true"] .tabulator .tabulator-tableholder::before {
    content: "";
    position: absolute; inset: 0;
    background: transparent;
    z-index: 2;
  }

  /* Report view */
  /* Every top-level tab view is data-active toggled; only the active one
     renders. #view-dashboard is the lone holdout — legacy code sets its
     inline `display` property directly (see showView() in app.js). */
  #view-overview, #view-report, #view-cipproc, #view-sam,
  #view-cipdoc, #view-services, #view-sql { display: none; }
  #view-overview[data-active="1"], #view-report[data-active="1"],
  #view-cipproc[data-active="1"], #view-sam[data-active="1"],
  #view-cipdoc[data-active="1"], #view-services[data-active="1"],
  #view-sql[data-active="1"] { display: block; }
  /* CIP Process page styles */
  .cipproc-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 12px 0 16px; }
  .cipproc-toolbar input[type="search"] { padding: 6px 10px; min-width: 240px; border: 1px solid var(--c-border); border-radius: 4px; background: var(--c-surface); color: var(--c-text-main); }
  .cipproc-toolbar select { padding: 6px 10px; border: 1px solid var(--c-border); border-radius: 4px; background: var(--c-surface); color: var(--c-text-main); }
  .stage-pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; white-space: nowrap; }
  .stage-tam { background: #437a22; color: #fff; }
  .stage-sam { background: #1e4a10; color: #fff; }
  .stage-norm { background: #01696f; color: #fff; }
  .stage-qa { background: #4f98a3; color: #fff; }
  .stage-pp { background: #d19900; color: #1a1c24; }
  .stage-gc { background: #da7101; color: #fff; }
  .stage-pr { background: #7a39bb; color: #fff; }
  .stage-fnd { background: #6b7080; color: #fff; }
  .stage-blank { background: rgba(125,125,125,0.25); color: var(--c-text-main); }
  .gap-summary { display: flex; gap: 14px; flex-wrap: wrap; margin: 0 0 12px; }
  .gap-summary .gs-card { padding: 10px 14px; border: 1px solid var(--c-border); border-radius: 6px; background: var(--c-surface); min-width: 140px; }
  .gap-summary .gs-label { font-size: 11px; color: var(--c-text); text-transform: uppercase; letter-spacing: .04em; }
  .gap-summary .gs-value { font-size: 22px; font-weight: 700; color: var(--c-text-main); }
  /* ==== Tabulator theme override -- align with dashboard vars ==== */
  .tabulator {
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    color: var(--c-text-main);
    font-size: 13px;
  }
  .tabulator .tabulator-header {
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    color: var(--c-text-main);
    font-weight: 600;
  }
  .tabulator .tabulator-header .tabulator-col {
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
  }
  .tabulator .tabulator-header .tabulator-col.tabulator-sortable:hover {
    background: rgba(125,125,125,0.12);
  }
  .tabulator .tabulator-header .tabulator-col .tabulator-col-content {
    padding: 6px 10px;
  }
  .tabulator .tabulator-header .tabulator-col .tabulator-col-content .tabulator-col-title {
    font-weight: 600;
    white-space: normal;
  }
  /* Header filter inputs/selects */
  .tabulator .tabulator-header .tabulator-header-filter input,
  .tabulator .tabulator-header .tabulator-header-filter select {
    background: var(--c-bg);
    color: var(--c-text-main);
    border: 1px solid var(--c-border);
    border-radius: 3px;
    padding: 3px 6px;
    font-size: 12px;
    width: 100%;
  }
  .tabulator-row { background: var(--c-panel); border-bottom: 1px solid var(--c-border); }
  .tabulator-row.tabulator-row-even { background: var(--c-surface); }
  .tabulator-row:hover { background: rgba(125,125,125,0.08) !important; }
  .tabulator-row .tabulator-cell {
    border-right: 1px solid var(--c-border);
    padding: 6px 10px;
    color: var(--c-text-main);
  }
  .tabulator-row .tabulator-cell.num { text-align: right; font-variant-numeric: tabular-nums; }
  /* Footer / pagination */
  .tabulator .tabulator-footer {
    background: var(--c-surface);
    border-top: 1px solid var(--c-border);
    color: var(--c-text);
  }
  .tabulator .tabulator-footer .tabulator-page {
    background: var(--c-bg); color: var(--c-text-main);
    border: 1px solid var(--c-border); border-radius: 3px;
  }
  .tabulator .tabulator-footer .tabulator-page.active {
    background: var(--c-primary, #2f6ddb); color: #fff; border-color: transparent;
  }
  /* Sort arrow visibility tweaks */
  .tabulator .tabulator-header .tabulator-col.tabulator-sortable .tabulator-col-sorter {
    opacity: 0.55;
  }
  .tabulator .tabulator-header .tabulator-col[aria-sort="ascending"] .tabulator-col-sorter,
  .tabulator .tabulator-header .tabulator-col[aria-sort="descending"] .tabulator-col-sorter {
    opacity: 1;
  }
  .report-toolbar {
    display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 12px;
    position: sticky; top: 0; background: var(--c-bg); padding: 6px 0; z-index: 5;
  }
  .report-body {
    background: var(--c-panel); border: 1px solid var(--c-border); border-radius: 8px;
    padding: 24px 32px; max-width: 920px; margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.55; color: var(--c-text-main); font-size: 14px;
  }
  .report-body h1 { font-size: 22px; margin: 0 0 4px; }
  .report-body h2 { font-size: 17px; margin: 24px 0 8px; border-bottom: 1px solid var(--c-border); padding-bottom: 4px; }
  .report-body h3 { font-size: 14px; margin: 18px 0 6px; color: var(--c-text); }
  .report-body table { border-collapse: collapse; margin: 8px 0; font-size: 12px; }
  .report-body th, .report-body td { border: 1px solid var(--c-border); padding: 4px 10px; text-align: left; }
  .report-body th { background: var(--c-bg); font-weight: 600; }
  .report-body td.num, .report-body th.num { text-align: right; font-family: 'JetBrains Mono', monospace; }
  .report-body code {
    background: var(--c-bg); padding: 1px 5px; border-radius: 3px;
    font-family: 'JetBrains Mono', monospace; font-size: 12px;
  }
  .report-body p { margin: 6px 0; }
  .report-body ul { margin: 6px 0; padding-left: 22px; }
  .report-body .callout {
    border-left: 3px solid var(--c-primary); background: var(--c-bg);
    padding: 8px 12px; margin: 10px 0; font-size: 13px;
  }
  .report-body .muted { color: var(--c-text); font-size: 12px; }
  select, input[type=text] {
    background: var(--c-panel); color: var(--c-text-main); border: 1px solid var(--c-border);
    border-radius: 6px; padding: 6px 8px; font-size: 12px; font-family: inherit;
  }
  select[disabled] { opacity: 0.55; cursor: not-allowed; }
  label.lbl { font-size: 11px; color: var(--c-text); text-transform: uppercase; letter-spacing: 0.04em; margin-right: 4px; }

  .pill {
    display: inline-block; padding: 1px 7px;
    background: var(--c-primary-soft); color: var(--c-primary);
    border-radius: 8px; font-size: 11px; font-weight: 500;
    margin-left: 4px;
  }

  /* Week-chip filter (multi-select) */
  .wk-chips {
    display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  }
  .wk-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 14px; font-size: 11px;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--c-panel); color: var(--c-text); cursor: pointer;
    border: 1px solid var(--c-border);
    transition: all 0.12s ease;
    user-select: none;
  }
  .wk-chip:hover { border-color: var(--c-primary); color: var(--c-primary); }
  .wk-chip.on {
    background: var(--c-primary); color: #fff; border-color: var(--c-primary);
    font-weight: 600;
  }
  .wk-chip.preset {
    font-family: inherit; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.04em;
    background: transparent; border-style: dashed;
  }
  .wk-chip.preset:hover { border-style: solid; }

  /* Category chips (wraps wide — reuses .wk-chip look) */
  .cat-chips {
    display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
    max-width: 100%;
  }

  /* Active-filters chip bar (sticky at top of dashboard) */
  .active-filter-bar {
    position: sticky; top: 0; z-index: 40;
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    padding: 8px 10px;
    margin: 0 0 12px 0;
    display: none;                 /* toggled to flex when any filter is active */
    gap: 8px; flex-wrap: wrap; align-items: center;
    backdrop-filter: blur(6px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  }
  .active-filter-bar.on { display: flex; }
  .active-filter-bar .afb-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--c-text); opacity: 0.75;
    padding-right: 4px; border-right: 1px solid var(--c-border);
    margin-right: 4px;
  }
  .active-filter-bar .afb-chip {
    display: inline-flex; align-items: center; gap: 6px;
    font-family: inherit; font-size: 11px;
    padding: 3px 4px 3px 8px;
    border: 1px solid var(--c-primary);
    background: var(--c-primary);
    color: #fff;
    border-radius: 12px;
    cursor: default; user-select: none;
    white-space: nowrap;
  }
  .active-filter-bar .afb-chip .afb-axis {
    opacity: 0.85; font-weight: 500;
  }
  .active-filter-bar .afb-chip .afb-axis::after { content: ": "; }
  .active-filter-bar .afb-chip .afb-val { font-weight: 600; }
  .active-filter-bar .afb-chip .afb-x {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px;
    margin-left: 2px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    cursor: pointer;
    font-size: 13px; line-height: 1;
    transition: background 0.12s ease;
  }
  .active-filter-bar .afb-chip .afb-x:hover { background: rgba(255,255,255,0.45); }
  .active-filter-bar .afb-clear {
    margin-left: auto;
    font-family: inherit; font-size: 11px;
    padding: 4px 10px;
    background: transparent; color: var(--c-text);
    border: 1px solid var(--c-border); border-radius: 4px;
    cursor: pointer;
    text-transform: uppercase; letter-spacing: 0.04em;
  }
  .active-filter-bar .afb-clear:hover {
    border-color: var(--c-primary); color: var(--c-primary);
  }

  /* =====================================================
     GLOBAL FILTER CHROME — above nav tabs, every page
     ===================================================== */
  .global-filter-chrome {
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    margin: 0 0 14px 0;
  }
  .global-filter-chrome .gfc-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px; flex-wrap: wrap;
  }
  .global-filter-chrome .gfc-toggle {
    font-family: inherit; font-size: 11px;
    padding: 4px 10px;
    background: transparent; color: var(--c-text);
    border: 1px solid var(--c-border); border-radius: 4px;
    cursor: pointer;
    text-transform: uppercase; letter-spacing: 0.04em;
    display: inline-flex; align-items: center; gap: 6px;
  }
  .global-filter-chrome .gfc-toggle:hover {
    border-color: var(--c-primary); color: var(--c-primary);
  }
  .global-filter-chrome .gfc-toggle .gfc-chev {
    display: inline-block; transition: transform 0.15s ease;
  }
  .global-filter-chrome.expanded .gfc-toggle .gfc-chev { transform: rotate(90deg); }
  .global-filter-chrome .gfc-count {
    font-size: 11px; color: var(--c-text); opacity: 0.7;
    padding: 0 4px;
  }
  .global-filter-chrome .gfc-chips {
    display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 auto;
    align-items: center;
  }
  .global-filter-chrome .gfc-chip {
    display: inline-flex; align-items: center; gap: 6px;
    font-family: inherit; font-size: 11px;
    padding: 3px 4px 3px 8px;
    border: 1px solid var(--c-primary);
    background: var(--c-primary);
    color: #fff;
    border-radius: 12px;
    cursor: default; user-select: none;
    white-space: nowrap;
    max-width: 320px;
  }
  .global-filter-chrome .gfc-chip .gfc-axis { opacity: 0.85; font-weight: 500; }
  .global-filter-chrome .gfc-chip .gfc-axis::after { content: ": "; }
  .global-filter-chrome .gfc-chip .gfc-val {
    font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 260px;
  }
  .global-filter-chrome .gfc-chip .gfc-x {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px;
    margin-left: 2px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    cursor: pointer;
    font-size: 13px; line-height: 1;
    transition: background 0.12s ease;
  }
  .global-filter-chrome .gfc-chip .gfc-x:hover { background: rgba(255,255,255,0.45); }
  .global-filter-chrome .gfc-clear {
    font-family: inherit; font-size: 11px;
    padding: 4px 10px;
    background: transparent; color: var(--c-text);
    border: 1px solid var(--c-border); border-radius: 4px;
    cursor: pointer;
    text-transform: uppercase; letter-spacing: 0.04em;
  }
  .global-filter-chrome .gfc-clear:hover {
    border-color: var(--c-primary); color: var(--c-primary);
  }
  .global-filter-chrome .gfc-panel {
    display: none;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--c-border);
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px 14px;
  }
  .global-filter-chrome.expanded .gfc-panel { display: grid; }
  .global-filter-chrome .gfc-field { display: flex; flex-direction: column; gap: 4px; }
  .global-filter-chrome .gfc-field label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--c-text); opacity: 0.7;
  }

  /* =====================================================
     TOM SELECT THEME — map to dashboard CSS vars
     ===================================================== */
  .ts-wrapper.single .ts-control,
  .ts-wrapper.multi .ts-control {
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    color: var(--c-text);
    border-radius: 6px;
    font-family: inherit;
    font-size: 12px;
    min-height: 32px;
    padding: 4px 8px;
  }
  .ts-wrapper.focus .ts-control {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 2px rgba(var(--c-primary-rgb, 80 120 200), 0.12);
  }
  .ts-wrapper .ts-control input,
  .ts-wrapper .ts-control input::placeholder {
    color: var(--c-text); opacity: 0.85;
    font-family: inherit; font-size: 12px;
  }
  .ts-wrapper.multi .ts-control > div {
    background: var(--c-primary);
    color: #fff;
    border: 1px solid var(--c-primary);
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 600;
    margin: 1px 3px 1px 0;
  }
  .ts-wrapper.multi .ts-control > div.active {
    background: var(--c-text);
    border-color: var(--c-text);
  }
  .ts-wrapper.multi .ts-control > div .remove {
    color: #fff; border-left: 1px solid rgba(255,255,255,0.35);
    padding-left: 4px; margin-left: 6px;
  }
  .ts-dropdown {
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    color: var(--c-text);
    font-family: inherit; font-size: 12px;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.16);
  }
  .ts-dropdown .option {
    padding: 5px 10px; color: var(--c-text);
  }
  .ts-dropdown .option:hover,
  .ts-dropdown .active {
    background: var(--c-primary); color: #fff;
  }
  .ts-dropdown .option.selected {
    background: var(--c-border); color: var(--c-text);
  }
  .ts-dropdown .option.selected.active {
    background: var(--c-primary); color: #fff;
  }
  /* Inline header-filter Tom Select — tighter */
  .tabulator .tabulator-header-filter .ts-wrapper .ts-control {
    min-height: 24px; padding: 2px 6px; font-size: 11px;
  }
  .tabulator .tabulator-header-filter .ts-wrapper.multi .ts-control > div {
    font-size: 10px; padding: 0 6px;
  }

  .cat-chips .wk-chip {
    font-family: inherit; font-size: 11px; text-transform: none; letter-spacing: 0;
  }

  /* Filter row lets the Category group span wider for the chips */
  .filters .group.wide { grid-column: span 2; min-width: 320px; }
  .group.wide .cat-chips { margin-top: 2px; }

  /* KPI row */
  .kpis { display: grid; grid-template-columns: repeat(6,1fr); gap: 12px; margin-bottom: 18px; }
  .kpi {
    background: var(--c-panel); border: 1px solid var(--c-border); border-radius: 8px; padding: 12px 14px;
  }
  .kpi .label { color: var(--c-text); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
  .kpi .value {
    font-size: 20px; font-weight: 600; margin-top: 4px; letter-spacing: -0.3px;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-variant-numeric: tabular-nums;
  }
  @media (max-width:1100px) { .kpis { grid-template-columns: repeat(3,1fr); } }
  @media (max-width:640px)  { .kpis { grid-template-columns: repeat(2,1fr); } }

  /* Panels */
  .grid { display: grid; gap: 14px; }
  .grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
  @media (max-width:900px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }
  .panel {
    background: var(--c-panel); border: 1px solid var(--c-border); border-radius: 8px;
    padding: 14px 16px; margin-bottom: 14px;
  }
  .panel { position: relative; }
  .panel h2 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
  .panel .desc { color: var(--c-text); font-size: 11px; margin-bottom: 10px; }

  /* CSV export button — injected top-right of any panel */
  .csv-btn {
    position: absolute; top: 10px; right: 12px; z-index: 3;
    font: 500 10.5px/1 'JetBrains Mono', ui-monospace, monospace;
    text-transform: uppercase; letter-spacing: 0.04em;
    padding: 3px 7px; border-radius: 4px;
    background: var(--c-bg); border: 1px solid var(--c-border);
    color: var(--c-text); cursor: pointer; opacity: 0.55;
    transition: opacity 0.12s, color 0.12s, border-color 0.12s;
  }
  .csv-btn:hover { opacity: 1; color: var(--c-text-main); border-color: var(--c-primary); }
  .csv-btn.flashed { opacity: 1; color: var(--c-success, var(--c-primary)); border-color: var(--c-success, var(--c-primary)); }

  /* Report CSV dropdown */
  .csv-menu { position: relative; display: inline-block; }
  .csv-menu-list {
    display: none; position: absolute; top: calc(100% + 4px); right: 0; z-index: 10;
    background: var(--c-panel); border: 1px solid var(--c-border); border-radius: 6px;
    min-width: 240px; padding: 4px; box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  }
  .csv-menu.open .csv-menu-list { display: block; }
  .csv-menu-list button {
    display: block; width: 100%; text-align: left; background: none; border: 0;
    padding: 7px 10px; border-radius: 4px; font-size: 12px; color: var(--c-text-main);
    cursor: pointer;
  }
  .csv-menu-list button:hover { background: var(--c-primary-soft); }

  .chart-wrap { position: relative; height: 280px; }
  .panel.tall  .chart-wrap { height: 420px; }
  .panel.short .chart-wrap { height: 220px; }
  .chart-loading {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--c-text); font-size: 12px; font-style: italic;
    pointer-events: none;
  }

  /* Filters panel */
  .filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
  .filters .group { display: flex; align-items: center; gap: 6px; }

  /* Tables */
  table { width: 100%; border-collapse: collapse; font-size: 12px; }
  thead th {
    text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--c-border);
    color: var(--c-text); font-weight: 500; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.04em; cursor: pointer; user-select: none;
    background: var(--c-panel);
  }
  thead th:hover { color: var(--c-text-main); }
  thead th.sorted::after { content: " ▾"; color: var(--c-primary); }
  thead th.sorted.asc::after { content: " ▴"; color: var(--c-primary); }
  tbody td { padding: 7px 8px; border-bottom: 1px solid var(--c-border); }
  tbody tr:hover { background: var(--c-primary-soft); }
  td.num, th.num {
    text-align: right;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-variant-numeric: tabular-nums;
  }
  td.mono {
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11.5px; color: var(--c-text);
  }
  .table-scroll {
    max-height: 440px; overflow: auto;
    border: 1px solid var(--c-border); border-radius: 6px;
  }
  .bar-cell {
    display: inline-block; height: 8px; background: var(--c-primary);
    border-radius: 2px; vertical-align: middle; margin-right: 6px;
  }

  /* Heatmap */
  .heat-scroll {
    overflow: auto; max-height: 640px;
    border: 1px solid var(--c-border); border-radius: 6px;
  }
  table.heat { font-size: 11px; }
  table.heat th, table.heat td {
    padding: 4px 6px; border: 1px solid var(--c-border); white-space: nowrap;
  }
  table.heat thead th {
    position: sticky; top: 0; background: var(--c-panel); z-index: 2; font-size: 10px;
  }
  table.heat tbody th {
    position: sticky; left: 0; background: var(--c-panel); z-index: 1;
    text-align: left; font-weight: 500; max-width: 240px;
    overflow: hidden; text-overflow: ellipsis;
  }
  table.heat td.cell {
    text-align: right;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-variant-numeric: tabular-nums;
  }
  table.heat td.cell.zero { color: var(--c-text); }
  .legend {
    display: flex; align-items: center; gap: 8px;
    font-size: 11px; color: var(--c-text);
  }
  .legend .grad {
    width: 140px; height: 10px; border-radius: 2px;
    background: linear-gradient(90deg, var(--c-heat-lo), var(--c-heat-hi));
  }

  /* ============================================================
     Assistant (floating helper, bottom-right)
     ============================================================ */
  #asst-bubble {
    position: fixed; right: 24px; bottom: 24px;
    width: 52px; height: 52px; border-radius: 50%;
    background: var(--c-primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; border: none; z-index: 9998;
    box-shadow: 0 4px 14px rgba(0,0,0,0.18);
    font-size: 22px; font-weight: 600;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
  }
  #asst-bubble:hover { transform: scale(1.06); box-shadow: 0 6px 18px rgba(0,0,0,0.24); }
  #asst-bubble.hidden { display: none; }

  #asst-popout-indicator {
    position: fixed; right: 18px; bottom: 18px; z-index: 998;
    padding: 8px 14px; border-radius: 20px;
    background: var(--c-panel); color: var(--c-text-main);
    border: 1px solid var(--c-border); cursor: pointer;
    font-size: 12px; font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.14);
    display: none;
  }
  #asst-popout-indicator:hover { border-color: var(--c-primary); color: var(--c-primary); }
  #asst-bubble .badge {
    position: absolute; top: -4px; right: -4px;
    width: 14px; height: 14px; border-radius: 50%;
    background: #e76f51; border: 2px solid #fff;
    display: none;
  }

  #asst-panel {
    position: fixed; right: 24px; bottom: 24px;
    width: 400px; height: 600px; max-height: calc(100vh - 48px);
    background: #fff; border: 1px solid var(--c-border);
    border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.20);
    z-index: 9999; display: none;
    flex-direction: column; overflow: hidden;
    font-size: 13px;
  }
  #asst-panel.open { display: flex; }
  @media (max-width: 520px) {
    #asst-panel { right: 12px; left: 12px; width: auto; bottom: 12px; height: calc(100vh - 24px); }
  }

  .asst-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    background: var(--c-primary); color: #fff;
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
  }
  .asst-header h3 { margin: 0; font-size: 14px; font-weight: 600; }
  .asst-header .asst-header-right { display: flex; gap: 4px; }
  .asst-icon-btn {
    background: transparent; border: none; color: #fff;
    cursor: pointer; padding: 4px 8px; border-radius: 4px;
    font-size: 16px; line-height: 1;
  }
  .asst-icon-btn:hover { background: rgba(255,255,255,0.15); }
  .asst-icon-btn[title]:hover::after { content: none; }

  .asst-body {
    flex: 1 1 auto; overflow-y: auto;
    padding: 14px; display: flex; flex-direction: column;
    gap: 10px; background: #fafafa;
  }
  .asst-body.centered { justify-content: center; align-items: stretch; }

  /* Setup / Unlock screens */
  .asst-screen {
    display: flex; flex-direction: column; gap: 12px;
    padding: 8px; max-width: 340px; margin: auto; width: 100%;
  }
  .asst-screen h4 { margin: 0; font-size: 14px; color: var(--c-text-strong); }
  .asst-screen p { margin: 0; color: var(--c-text); line-height: 1.5; font-size: 12px; }
  .asst-screen label { font-size: 12px; color: var(--c-text-strong); display: block; margin-bottom: 4px; }
  .asst-screen input[type="text"],
  .asst-screen input[type="password"] {
    width: 100%; padding: 8px 10px; font-size: 13px;
    border: 1px solid var(--c-border); border-radius: 4px;
    box-sizing: border-box; font-family: inherit;
  }
  .asst-screen .asst-actions {
    display: flex; gap: 8px; margin-top: 4px;
  }
  .asst-screen .asst-error {
    color: #c0392b; font-size: 12px; min-height: 16px;
  }
  .asst-screen .asst-hint { color: var(--c-text); font-size: 11px; }
  .asst-screen .btn { flex: 1; }

  /* Chat transcript */
  .asst-msg {
    padding: 8px 12px; border-radius: 8px; max-width: 90%;
    line-height: 1.45; font-size: 13px; word-wrap: break-word;
    white-space: pre-wrap;
  }
  .asst-msg.user {
    background: var(--c-primary); color: #fff; align-self: flex-end;
  }
  .asst-msg.bot {
    background: #fff; border: 1px solid var(--c-border);
    color: var(--c-text-strong); align-self: flex-start;
  }
  .asst-msg.bot strong { font-weight: 600; }
  .asst-msg.bot code {
    background: #f0f0f0; padding: 1px 4px; border-radius: 3px;
    font-size: 12px;
  }
  .asst-msg.error {
    background: #fdecea; border: 1px solid #f5c6cb; color: #721c24;
    align-self: stretch;
  }
  .asst-msg .ctx-badge {
    display: inline-block; font-size: 10px; background: rgba(255,255,255,0.25);
    padding: 1px 6px; border-radius: 10px; margin-left: 6px;
    vertical-align: middle;
  }
  .asst-msg.bot .ctx-badge { background: #e8f0f0; color: var(--c-primary); }

  .asst-empty {
    color: var(--c-text); font-size: 12px; text-align: center;
    padding: 20px 12px;
  }
  .asst-empty h4 { margin: 0 0 6px 0; color: var(--c-text-strong); font-size: 13px; }
  .asst-suggestions {
    display: flex; flex-direction: column; gap: 6px; margin-top: 14px;
  }
  .asst-suggest {
    text-align: left; padding: 8px 10px; border-radius: 6px;
    background: #fff; border: 1px solid var(--c-border); color: var(--c-text-strong);
    cursor: pointer; font-size: 12px; font-family: inherit;
    transition: background 0.12s;
  }
  .asst-suggest:hover { background: #f0f7f7; border-color: var(--c-primary); }

  .asst-typing {
    display: inline-flex; gap: 3px; padding: 8px 12px;
  }
  .asst-typing span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--c-primary); opacity: 0.4;
    animation: asstTyping 1.2s infinite;
  }
  .asst-typing span:nth-child(2) { animation-delay: 0.15s; }
  .asst-typing span:nth-child(3) { animation-delay: 0.3s; }
  @keyframes asstTyping {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
  }

  .asst-input-row {
    flex-shrink: 0; padding: 10px 12px; border-top: 1px solid var(--c-border);
    background: #fff;
  }
  .asst-input-ctrls {
    display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
    font-size: 11px; color: var(--c-text);
  }
  .asst-input-ctrls label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
  .asst-input-row textarea {
    width: 100%; box-sizing: border-box;
    padding: 8px 10px; border: 1px solid var(--c-border); border-radius: 4px;
    font-family: inherit; font-size: 13px; resize: none;
    min-height: 38px; max-height: 120px; line-height: 1.4;
  }
  .asst-input-row textarea:focus { outline: none; border-color: var(--c-primary); }
  .asst-send-row {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 6px; gap: 8px;
  }
  .asst-send-row .asst-token-hint { color: var(--c-text); font-size: 10px; }
  .asst-settings-panel {
    padding: 12px; background: #fff;
    border-top: 1px solid var(--c-border);
    font-size: 12px;
  }
  .asst-settings-panel h5 { margin: 0 0 8px 0; font-size: 12px; color: var(--c-text-strong); }
  .asst-settings-panel .row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
  .asst-settings-panel .muted { color: var(--c-text); font-size: 11px; }

  /* Markdown rendering inside bot messages */
  .asst-msg.bot p { margin: 0 0 8px 0; }
  .asst-msg.bot p:last-child { margin-bottom: 0; }
  .asst-msg.bot ul { margin: 4px 0 8px 0; padding-left: 20px; }
  .asst-msg.bot li { margin: 2px 0; line-height: 1.4; }
  .asst-msg.bot em { font-style: italic; }
  .asst-msg.bot strong { font-weight: 600; }
  .asst-msg.bot code {
    background: #f0f0f0; padding: 1px 4px; border-radius: 3px; font-size: 12px;
  }

  /* Copy button on bot messages */
  .asst-msg-wrap { position: relative; align-self: flex-start; max-width: 90%; display: flex; }
  .asst-msg-wrap .asst-msg { max-width: none; flex: 1; }
  .asst-copy-btn {
    position: absolute; top: 4px; right: 4px;
    background: #fff; border: 1px solid var(--c-border); color: var(--c-text);
    border-radius: 4px; font-size: 10px; padding: 2px 6px;
    cursor: pointer; opacity: 0; transition: opacity 0.15s;
    font-family: inherit; z-index: 1;
  }
  .asst-msg-wrap:hover .asst-copy-btn { opacity: 1; }
  .asst-copy-btn:hover { background: #f0f7f7; border-color: var(--c-primary); }
  .asst-copy-btn.copied { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

  /* Scope selector + new-thread link */
  .asst-scope-sel {
    margin-left: 4px; padding: 1px 4px; font-size: 11px;
    border: 1px solid var(--c-border); border-radius: 3px; background: #fff;
    font-family: inherit;
  }
  .asst-linkbtn {
    background: transparent; border: none; color: var(--c-primary);
    text-decoration: underline; cursor: pointer; font-size: 11px;
    padding: 0; margin-left: auto; font-family: inherit;
  }
  .asst-linkbtn:hover { color: var(--c-text-strong); }
  .asst-input-ctrls { flex-wrap: wrap; row-gap: 4px; }
  .asst-send-btns { display: flex; gap: 6px; }

  /* CIP Docs filter row */
  .cipdoc-filters {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
    margin: 8px 0 4px 0;
  }
  .cipdoc-filters label {
    display: flex; gap: 6px; align-items: center;
    font-size: 12px; color: var(--c-text);
  }
  .cipdoc-filters label.grow { flex: 1 1 260px; }
  .cipdoc-filters label > span {
    font-weight: 600; color: var(--c-text-strong); white-space: nowrap;
  }
  .cipdoc-filters select,
  .cipdoc-filters input[type="text"] {
    font: 12px 'JetBrains Mono', monospace;
    padding: 3px 6px; border: 1px solid var(--c-border);
    border-radius: 3px; background: #fff; color: var(--c-text);
  }
  .cipdoc-filters label.grow input[type="text"] { flex: 1; min-width: 0; }
  .cipdoc-filters select:focus,
  .cipdoc-filters input[type="text"]:focus {
    outline: none; border-color: var(--c-primary);
  }

  /* Footer */
  footer { color: var(--c-text); font-size: 11px; margin-top: 24px; text-align: center; }

  /* Footer refresh button */
  .footer-btn {
    font: 11px 'JetBrains Mono', monospace;
    padding: 2px 8px; margin-left: 2px;
    border: 1px solid var(--c-border); border-radius: 3px;
    background: #fff; color: var(--c-text); cursor: pointer;
  }
  .footer-btn:hover { border-color: var(--c-primary); color: var(--c-primary); }
  .footer-btn:disabled { opacity: 0.6; cursor: wait; }
  .footer-status { margin-left: 8px; font-size: 11px; color: var(--c-text); }
  .footer-status[data-tone="ok"]   { color: #0a7a3b; }
  .footer-status[data-tone="err"]  { color: #b31b1b; }
  .footer-status[data-tone="busy"] { color: var(--c-primary); }

  /* Bootstrap progress bar (shown only during initial DuckDB load).
     Sits right under #sub-header; width animates from 0 -> 100%. Hidden
     with display:none by app.js once DATA is populated. */
  .boot-progress {
    margin-top: 6px;
    max-width: 520px;
    height: 14px;
    background: var(--c-border, #e5e7eb);
    border-radius: 7px;
    overflow: hidden;
    position: relative;
    font: 10px 'JetBrains Mono', monospace;
    line-height: 14px;
  }
  .boot-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #0e7490, #0891b2);
    transition: width 180ms ease-out;
  }
  .boot-progress-label {
    position: absolute;
    inset: 0;
    text-align: center;
    color: var(--c-text, #111);
    mix-blend-mode: difference;
    color: #fff;
    padding: 0 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
  }
  .boot-progress.done { display: none; }
