/* =========================================================================
   screens.css: per-screen fixes (layer `screens`, beats `shell` and all
   legacy rules). Grouped by screen in the order of the audit report.
   ========================================================================= */
@layer screens {

  /* ---- Messages ---------------------------------------------------------
     One neutral surface in both themes (was hard-coded black), no header
     stacking on phones, friendly error state for bridge logs. */
  .msg-view, .msg-split, .msg-right-pane, .msg-thread-pane, .msg-bubble-stream {
    background: var(--bg-app);
    color: var(--text-primary);
  }
  .msg-left-pane {
    background: var(--bg-sidebar);
    color: var(--text-primary);
    border-right: 1px solid var(--border);
  }
  .msg-left-header, .msg-thread-header, .msg-tabs-bar, .msg-status-bar {
    background: var(--bg-app);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .msg-search {
    background: var(--bg-elev);
    color: var(--text-primary);
    border: 1px solid var(--border);
  }
  .msg-search::placeholder { color: var(--text-tertiary); }
  .msg-thread-row { background: transparent; color: var(--text-primary); border-bottom: 1px solid var(--border); }
  .msg-thread-row:hover { background: var(--bg-hover); }
  .msg-thread-name, .msg-thread-name-big { color: var(--text-primary); }
  .msg-thread-preview, .msg-thread-time, .msg-date-sep, .msg-bubble-foot { color: var(--text-tertiary); }
  .msg-thread-header-avatar, .msg-thread-avatar { background: var(--bg-elev); color: var(--text-secondary); }
  .msg-empty, .msg-empty-large, .msg-empty-title { color: var(--text-tertiary); }

  .msg-bubble-in .msg-bubble { background: var(--bg-elev); color: var(--text-primary); }
  .msg-bubble-out .msg-bubble { background: var(--accent); color: var(--on-accent); }
  .msg-bubble-foot-failed { color: var(--st-danger, #D93025); }

  .msg-composer { background: var(--bg-app); border-top: 1px solid var(--border); }
  .msg-composer-input { background: var(--bg-elev); color: var(--text-primary); border: 1px solid var(--border); }
  .msg-composer-send { background: var(--accent); color: var(--on-accent); }

  /* bridge/server log posted into a thread: status pill + collapsible details */
  .msg-bubble-in .msg-bubble.msg-bubble-syslog,
  .msg-bubble-out .msg-bubble.msg-bubble-syslog,
  .msg-bubble.msg-bubble-syslog {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    font-size: var(--t-12);
  }
  .msg-status-pill {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 var(--sp-2);
    border-radius: var(--r-pill);
    font-size: var(--t-10);
    font-weight: 600;
    background: var(--bg-elev);
    color: var(--text-secondary);
  }
  .msg-status-pill--error { background: color-mix(in srgb, var(--st-danger, #D93025) 14%, transparent); color: var(--st-danger, #D93025); }
  .msg-syslog-details summary { cursor: pointer; color: var(--accent-text); font-size: var(--t-11); }
  .msg-syslog-log {
    margin-top: 6px;
    white-space: pre-wrap;
    word-break: break-word;
    font: var(--fs-11)/1.4 "JetBrains Mono", ui-monospace, monospace;
    color: var(--text-tertiary);
  }

  @media (max-width: 820px) {
    /* one pane up to 820px, the same cut the JS uses (isMobileMsgLayout).
       768-820 used to keep the 2-column grid; at exactly 768 a legacy rule
       also hid the thread pane, leaving a blank right half, and 769-820
       showed the list beside the thread while the JS made the list inert. */
    body.route-messages .msg-split.msg-split-2col { display: flex; flex-direction: column; }
    body.route-messages .msg-split > .msg-left-pane { width: 100%; border-right: 0; }
    body.route-messages:not(.msg-mobile-thread) .msg-split > .msg-thread-pane { display: none; }
    body.route-messages.msg-mobile-thread .msg-split > .msg-left-pane { display: none; }
    body.route-messages.msg-mobile-thread .msg-split > .msg-thread-pane { display: flex; flex: 1 1 auto; min-height: 0; }
    /* list view: start below the slim top bar */
    body.route-messages:not(.msg-mobile-thread) #main-content { padding-top: 56px; }
    /* thread view: the thread header is the only top bar; tabs and app
       chrome step aside so nothing stacks or collides */
    body.msg-mobile-thread .mobile-topnav,
    body.msg-mobile-thread .gl-tabbar,
    body.msg-mobile-thread .msg-tabs-bar,
    body.msg-mobile-thread .ty-agent-tabs { display: none; }
    body.msg-mobile-thread #main-content { padding-top: 0; padding-bottom: 0; }
    body.msg-mobile-thread .msg-thread-header {
      position: sticky;
      top: 0;
      z-index: var(--z-sticky);
      padding-top: max(10px, env(safe-area-inset-top, 0px));
    }
    /* campaign gear: neutral icon button; list-level only, so it steps
       aside inside a thread instead of colliding with the thread header */
    /* round 3: same shape, fill and baseline as the pencil (compose) next to it */
    body.route-messages .msg-settings-btn {
      background: rgba(118, 118, 128, 0.24);
      color: var(--text-primary);
      border: 0;
      border-radius: 50%;
      top: 10px;
    }
    body.route-messages .msg-settings-btn:hover { background: rgba(118, 118, 128, 0.36); }
    body.msg-mobile-thread .msg-settings-btn { display: none; }
    body.route-messages .msg-view.is-settings-open .msg-tabs-bar {
      background: var(--bg-card);
      border-color: var(--border);
      box-shadow: var(--shadow-lg, 0 16px 48px rgba(0,0,0,.25));
    }
    body.route-messages .msg-view.is-settings-open .msg-tabs-bar::before,
    body.route-messages .msg-view.is-settings-open .msg-tab-settings { color: var(--text-tertiary); }
  }
}

/* ======================================================================
   Phase C: per-screen fixes, in audit-report order. Every rule here uses
   the canonical tokens, so light and dark both follow from tokens.css.
   ====================================================================== */
@layer screens {

  /* ---- shared: popovers and dropdown menus on the token surface ---- */
  .dr-dd-menu,
  .gfp-kebab-menu,
  .route-period-menu {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    backdrop-filter: none;
  }
  .dr-dd-menu *, .gfp-kebab-menu *, .route-period-menu * { color: inherit; }

  /* ---- shared: Ask suggestion chips, tab labels, floating Ask pill ---- */
  .chat-suggest-chip { color: var(--text-secondary); background: var(--bg-elev); border-color: var(--border); }
  .chat-suggest-chip:hover { color: var(--text-primary); }
  .ty-tab-label { color: var(--text-primary); }
  #floating-chat .fc-icon{ color: var(--text-primary); }
  .sidebar .footer-org-avatar-initials { color: var(--text-primary); }

  /* ---- Login / Signup / Forgot / Reset ---- */
  .auth-card, .auth-card--glass {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    backdrop-filter: none;
  }
  .auth-title { color: var(--text-primary); }
  .auth-sub, .auth-divider, .auth-card label, .auth-card label span { color: var(--text-secondary); }
  .auth-link, .auth-link-muted { color: var(--accent-text); }
  .auth-card input {
    background: var(--bg-app);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
  }
  .auth-card input::placeholder { color: var(--text-tertiary); }
  .auth-primary-btn { background: var(--accent); color: var(--on-accent, var(--c-white)); border: 0; }
  .auth-primary-btn:hover { background: var(--accent-hover); }
  .auth-primary-btn, .auth-primary-btn * { color: var(--on-accent, var(--c-white)); }

  /* ---- Chat history ---- */
  .chats-empty { color: var(--text-secondary); }

  /* ---- Messages ---- */
  .msg-empty-sub, .msg-preview-prefix, .msg-day-sep, .msg-day-sep span { color: var(--text-tertiary); }
  .msg-thread-link { color: var(--accent-text); }
  .msg-thread-close { color: var(--text-secondary); }
  .msg-outreach-count { background: var(--bg-elev); color: var(--text-secondary); }
  .msg-syslog-details summary { color: var(--text-secondary); }

  /* ---- Overview (/dashboard) ---- */
  .panel-title, .ov-page h3 { color: var(--text-primary); }
  .eyebrow { color: var(--text-tertiary); }
  .qa-btn { background: var(--bg-elev); color: var(--text-primary); border: 1px solid var(--border); }

  /* ---- Dashboards / Sales (BI) ---- */
  .bi-card-title { color: var(--text-secondary); }
  .bi-kpi-value { color: var(--text-primary); }
  .bi-heatmap-empty { color: var(--text-secondary); }
  .bi-refresh-btn { background: var(--bg-elev); color: var(--text-primary); border: 1px solid var(--border); }

  /* ---- Divisions / Division sales ---- */
  .gdpp { color: var(--text-secondary); }
  .gdpp[aria-pressed="true"], .gdpp.is-active, .gdpp.active { background: var(--accent); color: var(--on-accent, var(--c-white)); }

  /* ---- Route (call list) ---- */
  .route-stat-num { color: var(--text-primary); }
  .route-stat-lbl { color: var(--text-tertiary); }
  .route-empty-state__title { color: var(--text-primary); }

  /* ---- SuperViz ---- */
  .gl-floating-pill {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    backdrop-filter: none;
  }
  .sv-tab { color: var(--text-secondary); }
  .sv-fresh { color: var(--text-tertiary); }

  /* ---- Predictions / Model Lab ---- */
  .pred-math-link { color: var(--accent-text); }
  .pred-tool { color: var(--text-primary); background: var(--bg-elev); border: 1px solid var(--border); }

  /* ---- Phoenix map: neutral info notice instead of a blue tint ---- */
  .phx-fallback-banner {
    padding: var(--sp-2) var(--sp-3);
    margin: 0 0 var(--sp-2);
    border-radius: var(--r-md);
    font-size: var(--t-11);
    background: var(--bg-elev);
    color: var(--text-secondary);
    border: 1px solid var(--border);
  }

  /* ---- Automations / iMessage flow ---- */
  .imsg-section-title, .imsg-dd-palette-title, .imsg-inspector-empty-icon { color: var(--text-tertiary); }
  .stl-tab-pill { color: var(--text-secondary); }

  /* ---- Connectors ---- */
  .connectors-category-chip { color: var(--text-secondary); background: var(--bg-elev); border: 1px solid var(--border); }
  .connectors-category-chip[aria-pressed="true"], .connectors-category-chip.is-active, .connectors-category-chip.active {
    background: var(--accent); color: var(--on-accent, var(--c-white)); border-color: var(--accent);
  }

  /* ---- Settings / Projects / Devices ---- */
  .settings-view .srl-title { color: var(--text-secondary); }
  .settings-view .srl-value { color: var(--text-primary); }
  .settings-view .settings-row-muted,
  .settings-view .settings-promo-sub,
  .settings-view .settings-glass-toggle-label { color: var(--text-tertiary); }
  .settings-view .settings-sep { color: var(--text-tertiary); }
  .settings-view .settings-outline-btn {
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
  }
  .settings-view .settings-inline-link { color: var(--accent-text); }

  /* ---- Analyst ---- */
  .superset-tab { color: var(--text-secondary); }

  /* ---- Admin ---- */
  .apm-card {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    backdrop-filter: none;
  }
  .apm-sub, .apm-split-key, .apm-empty-mini, .apm-card th { color: var(--text-tertiary); }

  /* ---- SuperViz: header actions wrap instead of crushing on phones ---- */
  .sv-chrome .page-head-actions { flex-wrap: wrap; gap: var(--sp-2); }
  .sv-chrome .page-head-actions > * { flex: 0 0 auto; }

  /* ---- Route: the collapse toggle gets its own lane, no overlap ---- */
  .route-hdr { position: relative; }
  .route-hdr-row1 { padding-right: 48px; }
  .route-hdr-collapse-btn { color: var(--text-secondary); background: var(--bg-elev); border: 1px solid var(--border); }
  .route-period-btn { color: var(--text-primary); }

  /* ---- No colored left stripes, no tinted cards: neutral rows, status
     shown as a small dot/pill instead (owner: stripes look "AI made") ---- */

  .bd-boundary,
  .stl-kill-note,
  .sv-page .toast,
  .sc-warning {
    border: 1px solid var(--border);
    border-left: 1px solid var(--border);
    background-color: var(--bg-card);
    border-radius: var(--r-md);
  }
  .sc-warning { background-color: var(--bg-elev); color: var(--text-secondary); }
  .msg-bubble.msg-assistant { border-left: 0; }
  .pti-pill-detail,
  .rt-crm-notes-collapse-body,
  .rsm-tries-history-list { border-left: 1px solid var(--border); }
  .sv-page .cat { border-left: 0; }
  .sv-page .cat.active { background: var(--bg-hover); color: var(--text-primary); border-left: 0; font-weight: 600; }
  .sidebar-quick-item.active { border-left-color: transparent; }
  .rt-leg--start { border-left-color: var(--border); }

  /* calendar blocks: neutral card; selected = solid accent */
  .rt-cal-block { background: var(--bg-elev); border: 1px solid var(--border); border-left: 1px solid var(--border); color: var(--text-primary); }
  .rt-cal-block.is-selected { background: var(--accent); border-color: var(--accent); color: var(--on-accent, var(--c-white)); }

  /* call outcomes + held stops: status dot instead of a stripe */
  .rt-compact-row.is-hold,
  [class*="rt-try-opt--"] {
    border-left: 1px solid var(--border);
    --status-dot: var(--st-neutral, #9CA3AF);
    background-image: radial-gradient(circle at 10px 50%, var(--status-dot) 3.5px, transparent 4px);
    background-repeat: no-repeat;
    padding-left: 22px;
  }
  .rt-compact-row.is-hold { --status-dot: var(--st-warning, #E5A83D); }
  .rt-try-opt--gave_pitch { --status-dot: var(--accent); }
  .rt-try-opt--call_back { --status-dot: var(--st-warning, #E5A83D); }
  .rt-try-opt--made_sale { --status-dot: var(--st-success, #10B981); }
  .rt-try-opt--not_interested { --status-dot: var(--st-danger, #EF4444); }
  .rt-try-opt--not_home,
  .rt-try-opt--never_knock { --status-dot: var(--st-neutral, #9CA3AF); }

  /* Settings upsell: plain card, not a blue wash */
  .settings-view .settings-promo,
  .settings-view .settings-promo--glass {
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: none;
  }

  /* floating Ask pill: token surface (was a fixed charcoal chip in light) */
  .floating-chat-toggle {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    backdrop-filter: none;
  }
  .apm-card .apm-num, .apm-card .apm-title { color: var(--text-primary); }
  .apm-card .apm-sub { color: var(--text-tertiary); }

  /* ---- light-only surfaces that stayed white in dark mode ---- */
  .cust-empty { background: var(--bg-card); color: var(--text-secondary); border: 1px solid var(--border); }
  .bi-kpi-card, .bi-card { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-primary); }
  .phx-fallback-canvas { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-md); }
  .pred-badge--warm {
    background: color-mix(in srgb, var(--st-warning, #E5A83D) 16%, transparent);
    color: var(--text-primary);
  }

  .bi-kpi-eyebrow { color: var(--text-tertiary); }
  .bi-kpi-delta { color: var(--text-secondary); }
  .hood-addr-search { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
  .imsg-dd-palette-item { color: var(--text-primary); }

  /* wrap-up regressions */
  .floating-chat-panel .chat-empty, .floating-chat-panel .chat-empty * { color: var(--text-secondary); }
  .sidebar .footer-org-avatar { background: var(--bg-elev); }
  .sv-tab[aria-selected="true"] { color: var(--c-white); }
  .stl-tab-pill--active { color: var(--c-white); }
  /* contrast >= 4.5:1 */
  .route-repmode-opt.is-active, .route-repmode-opt.is-active * { color: var(--text-primary); }
  .imsg-inspector-empty, .imsg-inspector-empty * { color: var(--text-secondary); }
  .msg-date-sep, .msg-date-sep * { color: var(--text-secondary); }
}

/* Sharpen2 7: Dashboards + Division tiles empty states */
@layer screens {
  /* Overview body stacked sections with no gap: "Division health" sat flush on the alert
     banner and "Headline KPIs" flush on the empty line above it. */
  .ov-body { display: flex; flex-direction: column; gap: var(--sp-6); }
  .ov-section { gap: var(--sp-2); }
  .ov-section-title { font-size: var(--t-11); letter-spacing: 0.06em; color: var(--text-secondary); }
  .ov-chart-empty { min-height: 160px; color: var(--text-secondary); }
  /* Overview "glass" tokens followed the OS scheme (slate-blue tinted cards in dark, and even
     under an explicit light app theme on a dark OS). Point them at the theme's card tokens. */
  :root {
    --gl-glass-bg: var(--bg-card); --gl-glass-bg-strong: var(--bg-card);
    --gl-glass-border: var(--border); --gl-glass-border-hover: var(--border-strong);
    --gl-glass-shadow: none; --gl-glass-shadow-hover: var(--shadow-sm);
  }

  /* Unavailable division tile: was "— (warn)" over a second big "—" and an empty axis.
     Show one muted "Data unavailable" line with the warning icon instead. */
  .gl-dash-tile.gdt-unavail .gdt-title { font-size: 0; letter-spacing: 0; display: flex; align-items: center; gap: var(--sp-1); color: var(--status-warn); }
  .gl-dash-tile.gdt-unavail .gdt-warn { display: inline-flex; }
  .gl-dash-tile.gdt-unavail .gdt-title::after { content: "Data unavailable"; font-size: var(--t-12); font-weight: 500; text-transform: none; color: var(--text-secondary); }
  .gl-dash-tile.gdt-unavail .gdt-value,
  .gl-dash-tile.gdt-unavail .gdt-chart { display: none; }
  .gl-dash-tile.gdt-unavail:hover { transform: none; box-shadow: none; }
  /* Phones: one column of 160px rows made a pack of unavailable tiles ~2,800px tall. */
  @media (max-width: 600px) {
    .gl-dash-pack { grid-auto-rows: auto; }
    .gl-dash-tile.gdt-unavail { min-height: 0; }
    .gl-dash-tile.gdt-unavail .gdt-foot { margin-top: var(--sp-2); }
  }
}

/* Sharpen2 8: auth pages */
@layer screens {
  /* The login view shrink-wrapped to its content inside the flex main (card 261px wide while
     signup was 360px). Let the view fill so every auth card is the same 360px. */
  .auth-view { flex: 1 1 auto; min-width: 0; }
  .auth-card, .auth-card.auth-card--glass { width: 100%; box-shadow: var(--shadow-sm); }
  /* Primary button carried a 28px black drop shadow (a glow under the button in light mode). */
  .auth-primary-btn, .auth-card--glass .auth-primary-btn,
  .auth-primary-btn:hover, .auth-card--glass .auth-primary-btn:hover { box-shadow: none; }
  /* Phones: the card is meant to be the whole screen (mobile-v2), but a 360px cap left it
     pinned left with a 30px gutter on the right. Make it a plain full-bleed page. */
  @media (max-width: 600px) {
    body.is-auth-page .auth-card, body.is-auth-page .auth-card.auth-card--glass {
      max-width: none; border: 0; border-radius: 0; box-shadow: none; background: var(--bg-app);
    }
  }
}

/* Sharpen2 9: My Hood */
@layer screens {
  /* Settings FAB was a near-black disc with a text-primary icon: invisible in light mode. */
  .hood-settings-fab {
    background: var(--bg-card); color: var(--text-primary);
    border: 1px solid var(--border-strong); box-shadow: var(--shadow-sm);
  }
  .hood-settings-fab:hover { background: var(--bg-card-hover, var(--bg-card)); }
  /* Map-unavailable empty state: a bare line of text in a void. Give it an icon and hierarchy. */
  .hood-map-error { gap: var(--sp-2); }
  .hood-map-error::before {
    content: ""; width: 44px; height: 44px; margin-bottom: var(--sp-2); border-radius: var(--r-pill);
    background-color: var(--text-secondary);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-6 -6 36 36' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14.1 5.1 9.9 3 3 5.6v15.4l6.9-2.6 4.2 2.1 6.9-2.6V2.5z'/%3E%3Cpath d='M9.9 3v15.4M14.1 5.1v15.9'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-6 -6 36 36' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14.1 5.1 9.9 3 3 5.6v15.4l6.9-2.6 4.2 2.1 6.9-2.6V2.5z'/%3E%3Cpath d='M9.9 3v15.4M14.1 5.1v15.9'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
    box-shadow: none;
  }
  .hood-map-error-title { font-size: var(--t-15); color: var(--text-primary); }
  .hood-map-error-hint { color: var(--text-secondary); }
  /* Phones: the map runs under the tab bar, so the locate button (bottom:24px) sat 12px
     behind it. Lift it above the bar. */
  @media (max-width: 820px) {
    .hood-locate-fab { bottom: calc(var(--tabbar-h, 56px) + env(safe-area-inset-bottom, 0px) + var(--sp-4)); }
  }
}

/* Sharpen2 10: phone touch targets (>=44px) */
@layer screens {
  @media (max-width: 820px) {
    /* Inline text links keep their line box; an invisible pseudo-element extends the hit area. */
    .settings-inline-link, .auth-link, .auth-link-muted { position: relative; }
    .settings-inline-link::after, .auth-link::after, .auth-link-muted::after {
      content: ""; position: absolute; left: -4px; right: -4px; top: 50%;
      height: 44px; transform: translateY(-50%);
    }
    .settings-outline-btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
    #cp-primary { height: 44px; }
    /* Auth fields: 44px tall and 16px text (13px text makes iOS Safari zoom the page on focus). */
    .auth-card input:not([type="checkbox"]):not([type="radio"]) { min-height: 44px; font-size: var(--t-16); }
    .auth-check { min-height: 44px; display: inline-flex; align-items: center; }
  }
}

/* ── Round 3, step 1: compact empty states on dashboards ──────────────────
   Empty charts rendered as 200px-tall blank cards with one grey line in the
   middle. Collapse them to a short, centred state with a small chart glyph so
   the page reads "no data yet" instead of "broken layout". */
@layer screens {
  .ov-chart-empty,
  .bi-heatmap-empty {
    flex: 0 0 auto; min-height: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: var(--sp-2); padding: var(--sp-5, 20px) var(--sp-4);
    color: var(--text-secondary); font-size: var(--t-13); line-height: 1.45; text-align: center;
  }
  .ov-chart-empty::before,
  .bi-heatmap-empty::before {
    content: ""; width: 20px; height: 20px; flex: none;
    background-color: var(--text-tertiary, var(--text-secondary));
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v18h18'/%3E%3Cpath d='M8 17v-4M13 17V8M18 17v-7'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v18h18'/%3E%3Cpath d='M8 17v-4M13 17V8M18 17v-7'/%3E%3C/svg%3E") center / contain no-repeat;
  }
  /* A card holding only an empty state drops the 300px chart floor; beside a
     filled chart it still stretches to the row height with the message centred. */
  .ov-card:has(> .ov-chart-empty) { min-height: 0; }
  .ov-card > .ov-chart-empty { flex: 1 1 auto; }
  /* Inline "unavailable" lines get the same quiet treatment as other helper text. */
  .ov-tl-empty, .ov-kpi-empty, .bi-kpi-empty { color: var(--text-secondary); font-size: var(--t-13); }
}

/* ── Round 3, step 2: slider hit areas on touch screens ───────────────────
   Range inputs were 4px (Beaded generator) and 16px (notification volume)
   tall, so the thumb was hard to grab. Grow the box to 44px with transparent
   padding; the painted track stays the same thin line. */
@layer screens {
  @media (max-width: 820px), (pointer: coarse) {
    .beaded-gen-slider {
      box-sizing: content-box; height: 4px; padding-block: 20px;
      background-clip: content-box; touch-action: pan-y;
    }
    .settings-sounds-slider-wrap input[type="range"] { height: 44px; margin-block: 0; touch-action: pan-y; }
    .settings-sounds-slider-wrap { min-height: 44px; }
  }
  /* Phones: the two bead sliders wrapped into a ragged "Size ━ Gap / ━" pair.
     Lay them out as label + full-width slider rows. */
  @media (max-width: 600px) {
    .beaded-gen-sliders {
      display: grid; grid-template-columns: auto minmax(0, 1fr);
      column-gap: var(--sp-3); row-gap: 0; align-items: center; width: 100%;
    }
    .beaded-gen-slider { width: auto; min-width: 0; }
  }
}

/* ── Round 3, audit: Division dashboards (Sales + per-division BI) ────────
   1. Empty SVG charts ("No data" text inside a 200-unit viewBox, or a blank
      donut) left 240px voids. Hide the empty SVG and show the same compact
      empty state used on Overview.
   2. Sales KPI strip: 5 cards sat in an 8-column grid, leaving a hole on the
      right. Let the strip fill the row.
   3. Sales leaderboard: the table was clipped at the right edge (ACTIVE RATE
      hidden) and the table area was a nested vertical scroller (max-height
      340px). Give the table the wider column, let rep names wrap, and drop the
      inner vertical scroll. Horizontal overflow stays as the last resort. */
@layer screens {
  .bi-card > svg.bi-hero-svg:empty,
  .bi-card > svg.bi-hero-svg:has(> text:only-child) { display: none; }
  .bi-card:has(> svg.bi-hero-svg:empty)::after,
  .bi-card:has(> svg.bi-hero-svg > text:only-child)::after {
    content: "No data for this period."; order: 3;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: var(--sp-5) var(--sp-4) var(--sp-3);
    color: var(--text-secondary); font-size: var(--t-13); line-height: 1.45; text-align: center;
  }
  .bi-card:has(> svg.bi-hero-svg:empty)::before,
  .bi-card:has(> svg.bi-hero-svg > text:only-child)::before {
    content: ""; display: block; order: 2; width: 20px; height: 20px; margin: var(--sp-4) auto 0; flex: none;
    background-color: var(--text-tertiary, var(--text-secondary));
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v18h18'/%3E%3Cpath d='M8 17v-4M13 17V8M18 17v-7'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v18h18'/%3E%3Cpath d='M8 17v-4M13 17V8M18 17v-7'/%3E%3C/svg%3E") center / contain no-repeat;
  }

  .bi-card:has(> svg.bi-hero-svg:empty),
  .bi-card:has(> svg.bi-hero-svg > text:only-child) { display: flex; flex-direction: column; }
  .bi-kpi-strip[aria-label^="Sales"] { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  /* Phones gave the strip 12px of its own padding, so KPI cards sat inset from
     the chart cards below them. */
  .bi-kpi-strip { padding: 0; }
  /* The sales trend card stretched to the leaderboard's height, leaving a void
     under the chart. */
  .bi-kpi-strip[aria-label^="Sales"] + .bi-hero-grid { align-items: start; }
  /* BI tables were light-only: white sticky header and near-black cells, so in
     dark mode the header was a white bar and the rows were unreadable. */
  .bi-table thead { background: var(--bg-card); }
  .bi-table th { color: var(--text-secondary); border-bottom-color: var(--border); }
  .bi-table td { color: var(--text-primary); border-bottom-color: var(--border-subtle, var(--border)); }
  /* Chart labels are drawn with hard-coded light-only (rgba(60,64,67,…)) or
     dark-only (rgba(255,255,255,…), #E3E1DD) fills, so axis ticks and legends
     vanished in one theme or the other. CSS beats SVG presentation attributes;
     re-point them at theme text colours. Labels already using var() and the
     terra target marker keep their own fill. */
  :is(.bi-card, .ov-card) svg text:not([fill^="var("]):not([fill="#A84B2F"]) { fill: var(--text-secondary); }
  :is(.bi-card, .ov-card) svg text[fill="#E3E1DD"] { fill: var(--text-primary); }

  .bi-table-wrap { max-height: none; overflow-y: visible; }
  @media (min-width: 901px) {
    .bi-kpi-strip[aria-label^="Sales"] + .bi-hero-grid { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
  }
  .bi-table-card .bi-table td:first-child { white-space: normal; min-width: 9em; }
}

/* ── Round 3, audit: Overview (#/dashboards) on the Totaly palette ─────────
   Overview shipped its own teal / terra / dark-teal chart palette and tinted
   alert rows. Re-point it at the shared tokens: data series in Totaly blue,
   good/bad in the status colours, alerts as neutral rows with a status icon. */
@layer screens {
  :root {
    --tot-green: var(--status-ok); --tot-red: var(--status-bad); --tot-yellow: var(--status-warn);
    --tot-chart-1: var(--accent); --tot-chart-2: var(--status-bad); --tot-chart-3: var(--accent-hover);
    --tot-border: var(--border);
  }
  .ov-card svg [stroke="#20808D"], .ov-kpi-card svg [stroke="#20808D"] { stroke: var(--accent); }
  .ov-card svg [fill="#20808D"], .ov-kpi-card svg [fill="#20808D"] { fill: var(--accent); }
  .ov-card svg [fill="#1B474D"] { fill: var(--accent-hover); }
  .ov-card svg [stroke="#A84B2F"], .ov-kpi-card svg [stroke="#A84B2F"] { stroke: var(--status-bad); }
  .ov-card svg [fill="#A84B2F"], .ov-kpi-card svg [fill="#A84B2F"] { fill: var(--status-bad); }
  .ov-alert--red, .ov-alert--yellow, .ov-alert--warn {
    background: var(--bg-card); border-color: var(--border); color: var(--text-primary);
  }
  .ov-alert--red .ov-alert-icon { background: var(--status-bad); color: var(--c-white, #fff); }
  .ov-alert--yellow .ov-alert-icon, .ov-alert--warn .ov-alert-icon { background: var(--status-warn); color: var(--c-white, #fff); }
  .ov-tl-pill--red .ov-tl-dot { box-shadow: none; }
  .ov-tl-pill--yellow .ov-tl-dot { box-shadow: none; }
  .ov-tl-pill--green .ov-tl-dot { box-shadow: none; }
  .ov-kpi-card--violated { border-color: color-mix(in srgb, var(--status-bad) 45%, var(--border)); }
}

/* ── Round 3, audit: Ask composer on phones ────────────────────────────────
   mobile-v2.css adds a flex:1 ::before spacer to the composer toolbar (from
   when the left cluster was hidden). With .rc-left present it splits the
   free space and shoves +/web/model ~28px right of the placeholder text. */
@layer screens {
  .ai-view .rich-composer .rc-toolbar:has(> .rc-left)::before { content: none; }
}

/* ── Round 3, audit: Admin / Business definitions failure states ───────────
   Load failures rendered as a bare <p role=alert> with the raw exception and
   an unstyled link. Give them the shared error-card shape: status icon, a
   plain-language heading, the detail in secondary text, and a real button. */
@layer screens {
  .bd-page > p[role="alert"],
  .admin-page > p[role="alert"] {
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr);
    column-gap: var(--sp-3, 12px);
    row-gap: var(--sp-1, 4px);
    align-items: start;
    max-width: 560px;
    margin: var(--sp-4, 16px) 0 0;
    padding: var(--sp-4, 16px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card, 8px);
    color: var(--text-secondary);
    font-size: var(--t-13);
    line-height: 1.45;
    overflow-wrap: anywhere;
  }
  .bd-page > p[role="alert"]::before,
  .admin-page > p[role="alert"]::before {
    content: "!";
    grid-column: 1; grid-row: 1 / span 2;
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--status-bad); color: var(--c-white, #fff);
    font-size: var(--t-12); font-weight: 700; line-height: 1;
  }
  .admin-page > p[role="alert"]::before { background: var(--status-info, var(--accent)); content: "i"; }
  .bd-page > p[role="alert"]::after {
    content: "Couldn’t load business definitions";
    grid-column: 2; grid-row: 1;
    color: var(--text-primary); font-size: var(--t-15); font-weight: 600;
  }
  .admin-page > p[role="alert"] { align-items: center; color: var(--text-primary); }
  .bd-page > p[role="alert"] + a {
    display: inline-flex; align-items: center; min-height: 36px;
    margin-top: var(--sp-3, 12px); padding: 0 var(--sp-4, 16px);
    border: 1px solid var(--border); border-radius: var(--r-md, 8px);
    background: var(--bg-card); color: var(--text-primary);
    font-size: var(--t-13); font-weight: 500; text-decoration: none;
  }
  .bd-page > p[role="alert"] + a:hover { background: var(--bg-card-hover, var(--bg-card)); }
  @media (max-width: 820px), (pointer: coarse) {
    .bd-page > p[role="alert"] + a { min-height: 44px; }
  }
}

/* ── Round 3, audit: Admin tools (product metrics, errors) ─────────────────
   - Errors: the selected level/since chip (.ae-filter-chip--on) had no style
     at all, so the active filter was invisible. Selected = filled accent.
   - Errors: page sat flush at the top with no max width, unlike its sibling
     admin pages (product metrics / chat eval / business definitions).
   - Product metrics: Refresh was a near-black slab in light mode. */
@layer screens {
  .ae-filter-chip.ae-filter-chip--on {
    background: var(--accent); border-color: var(--accent); color: var(--c-white, #fff);
  }
  .ae-filter-chip.ae-filter-chip--on:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--c-white, #fff); }
  @media (min-width: 821px) {
    .ae-page { max-width: 1180px; margin-inline: auto; padding: 28px 24px 64px; }
  }
  .apm-refresh-btn {
    background: var(--bg-card); color: var(--text-primary); border-color: var(--border);
  }
  .apm-refresh-btn:hover { background: var(--bg-card-hover, var(--bg-card)); }
}

/* ── Round 3, audit: SuperViz section head ─────────────────────────────────
   Both the layout actions and the Refresh CTA carried margin-left:auto, so
   the wrapped second row split its free space: "Edit layout" + freshness
   floated in the middle of the row. Actions now lead the row; the Refresh
   CTA alone is pushed right. Edit mode keeps its full-width action bar. */
@layer screens {
  .de-root:not(.de-editing) > .sv-section-head > .de-head-actions { margin-left: 0; }
}

/* ── Round 3, audit: Route + Hood ──────────────────────────────────────────
   - Route (phones): the sticky header kept margin-inline:-10px from an old
     full-bleed treatment but lost the matching padding/width, so the whole
     filter block sat 10px left of the page gutter (6px left / 26px right).
   - Hood: the address search text was hard-coded #16181A, so typed text and
     placeholder were invisible in dark.
   - Hood (desktop): closed side sheets sit off-canvas but still cast their
     shadow onto the map edge; the locate button sat under the floating Ask
     pill and could not be tapped. */
@layer screens {
  @media (max-width: 820px) {
    .route-view > .route-hdr { margin-inline: 0; }
    /* collapse toggle sits in its own lane at the end of row 1: same top and
       height as the row (44px), 6px clear of "All reps" */
    .route-hdr > .route-hdr-collapse-btn { top: 0; }
    .route-hdr > .route-hdr-row1 { padding-right: 56px; }
    /* collapsed: the toggle covered "AI Optimize"; give it the same lane */
    .route-hdr.route-hdr--collapsed > .route-hdr-collapse-btn { top: 5px; }
    .route-hdr.route-hdr--collapsed > .route-viewbar { width: auto; max-width: calc(100% - 52px); margin-right: 52px; }
  }
  @media (max-width: 389px) {
    /* ...and on small phones tighten the segments so "AI Optimize" still fits */
    .route-hdr.route-hdr--collapsed .route-viewswitch { gap: 2px; }
    .route-hdr.route-hdr--collapsed .route-viewswitch .route-viewbtn { padding-inline: 5px; }
  }
  /* Route view switch on phones: 2px side padding made the active segment a
     44px circle clipping "Call". Text-only segments with real padding, and
     the bar spans the row instead of stopping short. */
  @media (max-width: 480px) {
    .route-view .route-viewbar { margin-inline: 0; padding-inline: 0; }
    .route-viewbar > .route-viewswitch { width: 100%; }
    .route-viewswitch > .route-viewbtn { flex: 1 0 auto; padding-inline: var(--sp-2, 8px); }
    .route-viewswitch > .route-viewbtn > svg { display: none; }
  }
  .hood-addr-search-input { color: var(--text-primary); }
  .hood-addr-search-input::placeholder { color: var(--text-tertiary, var(--text-secondary)); }
  @media (min-width: 769px) {
    body.route-hood .hood-sheet:not(.is-open),
    body.route-hood .hood-settings:not(.is-open) { box-shadow: none; }
    body.route-hood .hood-locate-fab { bottom: 80px; }
  }
}

/* ── Round 3, audit: division card Report buttons ──────────────────────────
   On touch screens the absolute "Report" button is always shown at the card's
   top-right. Over an empty card it sat on top of "No table data for this
   period."; there is also nothing to report on. Hide it on empty cards, and
   keep long card titles from running underneath it elsewhere. */
@layer screens {
  .bi-card:has(> .bi-kpi-empty) > .rb-btn,
  .bi-card:has(> svg.bi-hero-svg:empty) > .rb-btn,
  .bi-card:has(> svg.bi-hero-svg > text:only-child) > .rb-btn { display: none; }
  .bi-card:has(> .rb-btn) > .bi-card-title { padding-right: 88px; }
}

/* ── Round 4: division Report buttons on phones ────────────────────────────
   At <=600px the button is always visible (no hover), and as a 75x44
   "REPORT" pill it covered the KPI eyebrow ("TOTAL ACTIVE S…") and the
   chart's top y-axis value. On phones it becomes a 36px icon button with a
   44px hit area, and the eyebrow / card title reserve room for it. */
@layer screens {
  @media (max-width: 600px) {
    /* the division body is a flex item of .bi-page: without min-width:0 it
       grows to its widest child (KPI strip, routes table) and the whole
       page scrolls sideways */
    .dr-bi-page > .bi-body { min-width: 0; max-width: 100%; }
    .bi-kpi-card > .rb-btn,
    .bi-card > .rb-btn {
      top: 6px; right: 6px;
      width: 36px; height: 36px; min-width: 36px; min-height: 36px;
      padding: 0; justify-content: center;
    }
    .bi-kpi-card > .rb-btn::before,
    .bi-card > .rb-btn::before { content: ""; position: absolute; inset: -4px; }
    .bi-kpi-card > .rb-btn .rb-btn-label,
    .bi-card > .rb-btn .rb-btn-label { display: none; }
    .bi-kpi-card:has(> .rb-btn) > .bi-kpi-eyebrow {
      padding-right: 34px; min-height: 2.6em;
      white-space: normal; overflow: hidden; text-overflow: clip;
      display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; letter-spacing: 0.04em; overflow-wrap: anywhere;
    }
    .bi-card:has(> .rb-btn) > .bi-card-title { padding-right: 40px; min-height: 30px; }
  }
}

/* ── Round 4: SuperViz empty charts ──
   A chart with no rows kept the full 180–300px chart height, so an empty
   board was a wall of tall "No data" boxes. Empty cards size to the message;
   a card sharing a row with a real chart still stretches to that row. */
@layer screens {
  .sv-card-body:has(> .sv-empty) { min-height: 0; }
  .sv-card-body > .sv-empty { min-height: 112px; }
}

/* ── Round 4: admin Product metrics / Errors labels ──
   Labels are hard-coded in caps in JS. Fixed-wording labels become sentence
   case (lowercase + capital first letter); anything with acronyms or live
   values (subs, table heads, chips, drawer keys) keeps caps, just lighter. */
@layer screens {
  .apm-title, .apm-empty-mini, .apm-forbidden-title,
  .ae-empty-title, .ae-forbidden-title, .ae-filter-label {
    text-transform: lowercase; letter-spacing: 0;
  }
  .apm-title::first-letter, .apm-empty-mini::first-letter, .apm-forbidden-title::first-letter,
  .ae-empty-title::first-letter, .ae-forbidden-title::first-letter, .ae-filter-label::first-letter {
    text-transform: uppercase;
  }
  .apm-title, .ae-empty-title, .apm-forbidden-title, .ae-forbidden-title { font-weight: 600; }
  .apm-empty-mini, .ae-filter-label { font-weight: 500; }
  .ae-filter-label { display: inline-block; font-size: 12px; color: var(--text-secondary); }
  .apm-sub, .apm-card th, .ae-drawer-key, .ae-table th,
  .apm-refresh-btn, .ae-refresh-btn, .ae-filter-chip { font-weight: 500; letter-spacing: 0.04em; }
}

/* ── Round 4: division fallback charts (bar + donut) ──
   The renderer hard-codes a rainbow (green/amber/purple/red/cyan) as SVG
   fill attributes and dark-grey axis text. CSS beats presentation
   attributes, so map each hue onto a Totaly-blue + neutral ramp and give the
   axis/legend text theme colours (it was unreadable in dark). */
@layer screens {
  .bi-hero-svg { --hc-2: #0D47A1; --hc-3: #90CAF9; --hc-5: #BBDEFB; --hc-6: #1565C0; }
  [data-app-theme="dark"] .bi-hero-svg { --hc-2: #BBDEFB; --hc-3: #64B5F6; --hc-5: #1E3A5F; }
  @media (prefers-color-scheme: dark) {
    :root:not([data-app-theme]) .bi-hero-svg { --hc-2: #BBDEFB; --hc-3: #64B5F6; --hc-5: #1E3A5F; }
  }
  .bi-hero-svg [fill="#10B981" i], .bi-hero-svg [fill="#43A047" i] { fill: var(--hc-2); }
  .bi-hero-svg [fill="#F59E0B" i], .bi-hero-svg [fill="#F57C00" i] { fill: var(--hc-3); }
  .bi-hero-svg [fill="#A855F7" i], .bi-hero-svg [fill="#AB47BC" i] { fill: var(--text-tertiary, #8A8F9C); }
  .bi-hero-svg [fill="#EF4444" i] { fill: var(--hc-5); }
  .bi-hero-svg [fill="#06B6D4" i], .bi-hero-svg [fill="#00ACC1" i] { fill: var(--hc-6); }
  .bi-hero-svg text { fill: var(--text-secondary); }
  .bi-hero-svg line[stroke^="rgba(60,64,67"] { stroke: var(--border); }
}

/* ── Round 4: Overview KPI grid, 400–480px ──
   Single column ran 13 full-width cards down large phones; two columns fit
   every card from 400px. Below 400 stays one column. */
@layer screens {
  @media (min-width: 400px) and (max-width: 480px) {
    .ov-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    /* a label that wraps grows its own card; the 1-line neighbour's label
       absorbs the slack so values, deltas and sparklines line up across the row */
    .ov-kpi-card > .ov-kpi-eyebrow { flex: 1 0 auto; }
  }
}

/* ── Round 4: Route row 1 on small phones (<390px) ──
   Three equal columns cut the period button to "This m…". Give the period
   column a little more room and drop the decorative icons from the two
   crew toggles (their words carry the meaning). */
@layer screens {
  @media (max-width: 389px) {
    .route-hdr-row1 { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr); }
    .route-hdr-row1 .route-repmode-opt > svg { display: none; }
  }
}

/* Ask on phones: the app bar and agent tabs are in normal flow now, so the
   old fixed-header padding left an empty band under the tabs and let the page
   scroll past the composer. Size the chat to the space left in the viewport. */
@layer screens {
  @media (max-width: 820px) {
    body.route-ask #main {
      height: var(--vv-h, 100dvh);
      min-height: 0;
      padding-bottom: 0;
      overflow: hidden;
    }
    body.route-ask #main-content {
      flex: 1 1 auto;
      min-height: 0;
      height: auto;
      padding-top: 0;
      padding-bottom: 0;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
    body.route-ask #main-content > .ai-view {
      flex: 1 1 auto;
      width: 100%;
      height: auto;
      min-height: 0;
      max-height: none;
    }
  }
}

/* Ask: user messages had white text on a light grey fill in light mode, and on
   phones the always-visible edit pencil hung off the left edge. Use the normal
   text colour with a hairline border, and leave a gutter for the pencil. */
@layer screens {
  .ai-messages .msg-bubble.msg-user,
  .floating-chat-messages .msg-bubble.msg-user {
    color: var(--text-primary);
    border: 1px solid var(--border);
  }
  @media (max-width: 820px) {
    .ai-messages .msg-bubble.msg-user:has(> .msg-edit-btn) { margin-left: 28px; }
  }
}

/* SuperViz on phones: no grey backdrop panel behind the header and filters,
   header actions in an even two-column grid, filters share one row. */
@layer screens {
  @media (max-width: 480px) {
    .sv-page { background: transparent; }
    .sv-chrome .page-head { background: transparent; padding: 0 0 var(--sp-3); border: 0; box-shadow: none; }
    .sv-chrome .page-head-actions {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: var(--sp-2);
      width: 100%;
    }
    .sv-chrome .page-head-actions > .btn { justify-content: center; min-width: 0; }
    .sv-chrome .page-head-actions > .icon-btn {
      width: 100%;
      height: 44px;
      border: 1px solid var(--border-strong);
      border-radius: 8px;
      background: var(--bg-elev);
      color: var(--text-primary);
    }
    [data-app-theme="dark"] .sv-chrome .page-head-actions > .icon-btn { border-color: var(--border); }
  }
  @media (max-width: 480px) and (prefers-color-scheme: dark) {
    :root:not([data-app-theme]) .sv-chrome .page-head-actions > .icon-btn { border-color: var(--border); }
  }
  @media (max-width: 480px) {
    .sv-chrome .sh-toolbar { padding-inline: 0; }
    .sv-chrome .sh-toolbar > .search { flex: 1 1 100%; }
    .sv-chrome .sh-toolbar > .select { flex: 1 1 calc(50% - var(--sp-2)); min-width: 0; height: 44px; }
    .sv-chrome .sh-toolbar > .btn-ghost { margin-left: auto; }
    .sv-chrome .sh-toolbar > .select select { min-width: 0; flex: 1 1 auto; }
    .sv-chrome .sh-toolbar > .select .sh-menu-label { padding: 0 6px 0 0; }
  }
}

/* Status marks readable in both themes: the "!" badges take the page colour
   (white on red in light, near-black on the lighter red in dark), violated KPI
   cards keep a neutral border and rely on the badge, and the division tile
   unit/flag/skeleton colours come from tokens instead of fixed light-mode ink. */
@layer screens {
  .ov-alert--red .ov-alert-icon,
  .ov-alert--yellow .ov-alert-icon,
  .ov-alert--warn .ov-alert-icon,
  .ov-kpi-flag { color: var(--bg-app); }
  .ov-kpi-flag { background: var(--status-bad); }
  .ov-kpi-card--violated { border-color: var(--border); }
  .gl-dash-tile .gdt-value .gdt-unit { color: var(--text-tertiary); }
  .gl-dash-tile .gdt-title .gdt-flag { color: var(--st-danger); }
  .gl-dash-tile.gdt-skeleton .gdt-value { color: var(--text-faint); }
  .gl-dash-tile.gdt-redflag { box-shadow: none; }
}

/* Small link pills (back links, "how it's calculated") and pager numbers were
   29-31px: give them a comfortable 36px touch size on phones. */
@layer screens {
  @media (max-width: 820px) {
    a.gl-dash-pack-back,
    a.bi-back-link { padding-block: 8px; }
    a.pred-math-link { min-height: 44px; align-items: center; }
    .cust-pager .cust-pager-num { min-width: 36px; }
    .bi-header .bi-period-sel { height: 44px; }
  }
  /* the "Math & lab" link sits next to neutral tool buttons: match them
     instead of a blue-tinted chip; the dashboard period select matches the
     Refresh pill beside it */
  a.pred-math-link { background: var(--bg-elev); border-color: var(--border); color: var(--accent-text); }
  /* 11px blue on the grey chip was 4.2:1 in light; a deeper blue clears 4.5 */
  html:not([data-app-theme="dark"]) a.pred-math-link { color: color-mix(in srgb, var(--accent-text) 82%, #000); }
  .bi-header .bi-period-sel { background-color: var(--bg-elev); border-color: var(--border); }
  /* the back arrow only showed in dark mode; show it in both, like "← Divisions" */
  .bi-back-link::before { content: "\2190"; display: inline; margin-right: 0.2rem; }
}

/* Neutral controls and empty states:
   - Messages: the filter button gets the same grey circle as the pencil and
     gear beside it (accent only while the filter panel is open).
   - Prediction-style cards (Predictions, Model lab, Phoenix map, Connectors):
     flat, no grey gradient wash; Predictions' refresh/model-lab tools share
     one 8px-rounded shape.
   - Chats: "New chat" is white on blue in both themes (light had near-black
     text, dark was a grey button), and the empty
     state is plain text in a hairline box instead of a grey dashed panel.
   - Route: empty-state "Pick date / Pick rep" are neutral buttons, not
     blue-tinted pills. */
@layer screens {
  @media (max-width: 820px) {
    body.route-messages .msg-filter-toggle {
      background: rgba(118, 118, 128, 0.24);
      color: var(--text-primary);
      border: 0;
      border-radius: 50%;
    }
    body.route-messages .msg-filter-toggle:hover { background: rgba(118, 118, 128, 0.36); }
    body.route-messages .msg-filter-toggle[aria-expanded="true"] { background: var(--accent); color: var(--on-accent, #fff); }
  }
  .pred-card { background: var(--bg-card); border-color: var(--border); }
  .predictions-view .pred-tool { border-radius: 8px; }
  .chats-new-btn { background: var(--accent); color: var(--on-accent, #fff); border-color: transparent; }
  .chats-empty { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
  .route-empty-state__btn {
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
  }
}

/* Settings account actions: an even 2x2 grid on phones instead of three
   buttons and an orphan. Admin "who can edit" note: a neutral status pill,
   not a blue-tinted chip. */
@layer screens {
  @media (max-width: 480px) {
    .settings-account-actions {
      display: grid;
      width: 100%;
      align-self: stretch;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: var(--sp-2);
    }
    .settings-account-actions > .settings-outline-btn { width: 100%; justify-content: center; }
  }
  .bd-badge { background: var(--bg-elev); color: var(--text-secondary); border: 1px solid var(--border); border-radius: var(--r-pill, 999px); }
}

/* SuperViz card titles: wrap to two lines before truncating, so long chart names stay readable. */
@layer screens {
  .sv-card-head .sv-card-title { flex: 1 1 auto; min-width: 0; white-space: normal;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
}

/* Phoenix map "Hide low-confidence hexes" option: a full-height tap row and an 18px checkbox on phones. */
@layer screens {
  @media (max-width: 820px) {
    body.route-phoenix-map #main-content label:has(> input[type="checkbox"]) { min-height: 44px; }
    body.route-phoenix-map #main-content label > input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
  }
}

/* Predictions section heads: on phones the eyebrow sits above its blurb instead of squeezing beside it. */
@layer screens {
  @media (max-width: 480px) {
    .pred-section-head { flex-direction: column; align-items: flex-start; gap: var(--sp-1); }
    .pred-section-head .pred-section-blurb { margin: 0; }
  }
}

/* ===== Round five: one page frame on desktop =====
   Every scrolling screen gets the same gutter and top space from the frame
   (tokens --page-gutter / --page-top); view roots drop their own side and top
   padding and centre at a shared max width. Ask, Messages, the full-bleed
   map and auth pages own their frame. */
@layer screens {
  @media (min-width: 821px) {
    body:not(.route-ask):not(.route-messages):not(.route-hood):not(.is-auth-page) #main-content {
      padding-top: var(--page-top);
      padding-left: var(--page-gutter);
      padding-right: var(--page-gutter);
    }
    body:not(.route-ask):not(.route-messages):not(.route-hood):not(.is-auth-page) #main-content > * {
      padding-top: 0;
      padding-left: 0;
      padding-right: 0;
      margin-top: 0;
      margin-left: auto;
      margin-right: auto;
      max-width: var(--content-max);
    }
    body:not(.route-ask):not(.route-messages):not(.route-hood):not(.is-auth-page) #main-content > :is(.settings-view, .route-view, .gl-divisions-view, .chats-view) { max-width: var(--content-narrow); }
    body:not(.route-ask):not(.route-messages):not(.route-hood):not(.is-auth-page) #main-content > .admin-page { max-width: var(--content-mid); }
  }
}

/* Page headers line up with the frame: no extra inset on the left/top of
   the first row, so header, title and content share one left edge. */
@layer screens {
  .bi-page > .bi-header { padding-top: 0; padding-left: 0; padding-right: 0; }
  .bi-page > .bi-body { padding-left: 0; padding-right: 0; }
  .sv-page .page-head { padding-top: 0; padding-left: 0; padding-right: 0; }
  .sv-page .sh-toolbar { padding-left: 0; padding-right: 0; }
  .imsg-flow-view > .imsg-flow-topbar { padding-top: 0; padding-left: 0; padding-right: 0; }
  .route-view > .route-hdr { margin-top: 0; margin-left: 0; margin-right: 0; }
}
/* SuperViz sits on the page like every other screen: no grey panel or white header band. */
@layer screens {
  .sv-page, .sv-page .page-head { background: transparent; }
}

/* Top-right "more" menu (kebab): the same neutral sheet as the top-left nav
   menu. It was a near-black panel with dark text in light mode, and from
   768-820px it had no styles at all, so it sat open inside the app bar. */
@layer screens {
  @media (max-width: 820px) {
    .mobile-topnav .mt-menu {
      position: absolute;
      top: calc(56px + env(safe-area-inset-top, 0px) + var(--sp-1));
      right: var(--sp-2);
      left: auto;
      bottom: auto;
      display: flex;
      flex-direction: column;
      gap: 2px;
      width: min(260px, calc(100vw - 2 * var(--sp-2)));
      min-width: 0;
      max-width: none;
      margin: 0;
      padding: var(--sp-1);
      color: var(--text-primary);
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: var(--r-lg);
      box-shadow: var(--shadow-md);
      backdrop-filter: none;
      -webkit-backdrop-filter: none;
      opacity: 1;
      transform: none;
      transition: none;
      z-index: var(--z-dropdown);
    }
    .mobile-topnav .mt-menu:not(.is-open) { display: none; }
    .mobile-topnav .mt-menu .mt-menu-item {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap: var(--sp-3);
      width: 100%;
      min-height: 44px;
      margin: 0;
      padding: 0 var(--sp-3);
      border: 0;
      border-radius: var(--r-md);
      background: transparent;
      color: var(--text-secondary);
      font: 500 var(--t-15)/1.2 var(--font-body);
      text-align: left;
    }
    .mobile-topnav .mt-menu .mt-menu-item:hover,
    .mobile-topnav .mt-menu .mt-menu-item:active { background: var(--bg-elev); color: var(--text-primary); }
    .mobile-topnav .mt-menu .mt-menu-item > svg { width: 20px; height: 20px; flex: 0 0 20px; color: currentColor; }
    .mobile-topnav .mt-menu .mt-menu-sep { height: 1px; margin: var(--sp-1) 0; background: var(--border); }
  }
}

/* App bar follows the page gutter, so the menu glyph lines up with the
   content edge at tablet widths too (12px on phones as before, 20px at 641-820). */
@layer screens {
  @media (max-width: 820px) {
    nav.mobile-topnav {
      padding-left: max(calc(var(--page-gutter) - 4px), env(safe-area-inset-left, 0px));
      padding-right: max(calc(var(--page-gutter) - 4px), env(safe-area-inset-right, 0px));
    }
  }
}

/* first rows sit on the page frame's top edge, with no extra local offset */
@layer screens {
  .cust-view > .cust-search:first-child { margin-top: 0; }
  @media (max-width: 820px) {
    .route-view > .route-hdr { padding-top: 0; }
  }
}

/* Card padding: one value for section cards (16px phone / 20px desktop) and
   one for compact stat tiles (12px). Replaces 9.75 / 11.25 / 12.75 / 15 /
   16.5 / 18.75px leftovers from the old 15px-rem scale. */
@layer screens {
  :is(.ov-card, .bi-card, .settings-block, .apm-card, .superset-empty-card,
      .bd-layer-detail, .bd-recommendations, .bd-editor, .bd-explainer, .bd-lineage),
  .pred-card:not(:has(.phx-fallback-canvas, .sv-card)) {
    padding: var(--card-pad);
  }
  :is(.ov-kpi-card, .bi-kpi-card) { padding: var(--card-pad-sm); }
  .chats-empty { padding: var(--sp-8) var(--card-pad); }
}

/* Gaps: card grids use --grid-gap (12px phone / 16px desktop); stacked page
   sections use --section-gap (20px phone / 24px desktop). */
@layer screens {
  :is(.ov-kpi-grid, .ov-chart-grid, .bi-kpi-strip, .bi-hero-grid, .pred-grid,
      .bd-layers, .bd-recommendation-grid, .bd-workbench, .admin-split, .apm-grid,
      .gl-divisions-grid, .chat-eval-kpis) {
    gap: var(--grid-gap);
  }
  :is(.ov-page, .ov-body, .bi-body, .settings-view, .ae-page) { gap: var(--section-gap); }
}

/* Grid columns: phones show headline KPI tiles two-up (like the sales strip)
   instead of 13 full-width tiles; tablets put cards two-up instead of one
   720px-wide column. */
@layer screens {
  @media (max-width: 640px) {
    .ov-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
  @media (min-width: 641px) and (max-width: 1024px) {
    :is(.pred-grid, .apm-grid, .ov-chart-grid) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
}

/* Form fields: one height for page-level search boxes and selects
   (44px touch size on phones, 36px on desktop), and button groups spaced
   with --stack-gap (8px) instead of 6 / 7.5 / 10px. */
@layer screens {
  #main-content :is(.cust-search-input, .cust-sort, .ae-route-input, .chats-search, .admin-page select) {
    box-sizing: border-box;
    height: var(--control-h);
    min-height: var(--control-h);
  }
  :is(.settings-account-actions, .settings-admin-cluster, .settings-session-actions,
      .predictions-toolbar, .pred-card-links, .ae-filter-group, .route-hdr-row,
      .route-empty-state__actions, .report-tools-row) {
    gap: var(--stack-gap);
  }
  @media (min-width: 821px) {
    :is(.settings-admin-cluster, .ae-filter-group) > :is(button, a) { height: 32px; min-height: 32px; }
  }
}

/* Empty space: Chats no longer opens with an 80px blank band above the list
   on phones, and the dashboard period switch and Refresh share one row down
   to 360px. */
@layer screens {
  .chats-view > .chats-search { margin-top: 0; }
  .chats-view > .chats-list { margin-top: 0; padding-top: 0; }
  .ov-header-controls { gap: var(--stack-gap); }
  @media (max-width: 380px) {
    .ov-period-sel .ov-period-btn { padding-inline: 10px; }
  }
}

/* 768-820px used the desktop scroll model (body locked, #main-content its own
   844px scroller) while every phone width scrolls the document. Give the
   whole mobile shell the phone model: the document is the one scroller. */
@layer screens {
  @media (min-width: 768px) and (max-width: 820px) {
    html { overflow-x: hidden; overflow-y: auto; height: auto; }
    body { overflow: visible; height: auto; }
    section#main.main, #main-content { height: auto; overflow: visible; }
  }
}

/* ===== Round six: Messages on phones and tablets (<=820px) =====
   Root cause of the clipped inbox and the blank thread on iPhone:
   #main had no height of its own on this route. It was a column flex box
   sized by its content, and #main-content was `flex: 1 1 0%` inside it, so
   Safari froze #main at whatever the inbox measured on first paint (app
   bar + search + the "Loading…" box, about 200-270px) after an in-app
   navigation. The list loaded into that strip and the rest stayed blank.
   Opening a thread hid the list, so #main collapsed to 0px, and the
   fixed thread pane was clipped inside that 0px scroll box: a blank
   screen. The list padding also ignored the notch, so the search row sat
   under the app bar.
   Fix: the Messages frame gets a definite height (the viewport), the
   column children fill it, nothing in the chain is a scroll box, and the
   list starts below the app bar plus the safe area. */
@layer screens {
  @media (max-width: 820px) {
    body.route-messages section#main.main {
      display: flex;
      flex-direction: column;
      height: 100vh;
      height: 100dvh;
      min-height: 0;
      max-height: none;
      padding: 0;
      overflow: hidden;
    }
    body.route-messages section#main.main > #main-content {
      flex: 1 1 auto;
      display: flex;
      flex-direction: column;
      height: auto;
      min-height: 0;
      max-height: none;
      padding: calc(56px + env(safe-area-inset-top, 0px)) 0 0;
      overflow: hidden;
    }
    body.route-messages.msg-mobile-thread section#main.main > #main-content { padding-top: 0; }
    body.route-messages #main-content > .msg-view {
      flex: 1 1 auto;
      height: auto;
      min-height: 0;
      max-height: none;
    }
    body.route-messages .msg-view > .msg-split {
      flex: 1 1 auto;
      min-height: 0;
    }
  }
}
/* ===== Round seven: states and small-screen fit ===== */
@layer screens {
  /* Customers: empty and error states read as a message with one action,
     not a lone dashed line of grey text. */
  .cust-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-1);
    padding: var(--sp-8) var(--sp-4);
    border-radius: var(--r-lg);
    text-align: center;
  }
  .cust-empty-title { font-size: var(--t-14); font-weight: 600; color: var(--text-primary); }
  .cust-empty-sub { font-size: var(--t-13); color: var(--text-secondary); }
  .cust-empty-btn { margin-top: var(--sp-3); }

  /* First/Last columns are gone. Phone fit is in customers-refine.css. */
  /* ...and keep Sort + Refresh on the chips row; the count drops to its own
     line instead of shoving the whole sort group onto a second row. */
  @media (min-width: 601px) and (max-width: 820px) {
    body.route-customers .cust-filter-row { flex-wrap: wrap; row-gap: var(--sp-2); }
    body.route-customers .cust-sort-wrap { display: contents; }
    body.route-customers .cust-sort-label { margin-left: auto; }
    body.route-customers .cust-total { order: 10; flex: 1 0 100%; margin-left: 0; }
  }
}
@layer screens {
  /* Admin > Error log filters: Show resolved + Refresh wrapped onto a row of
     their own and left a wide blank band in the card. Route now stretches to
     fill its row and the actions sit at its right end; on phones each label
     sits above its chips so "ALL" no longer drops to a line by itself. */
  .ae-filters { row-gap: var(--sp-3); }
  /* desktop/tablet: Level + Since on row one, Route + actions on row two */
  @media (min-width: 601px) {
    .ae-filters::before { content: ""; order: 1; flex: 0 0 100%; height: 0; margin-top: calc(-1 * var(--sp-3)); }
    .ae-filters > .ae-filter-group:nth-child(n+3) { order: 2; }
  }
  .ae-filter-group:has(> .ae-route-input) { flex: 1 1 260px; flex-wrap: nowrap; }
  .ae-filter-group > .ae-route-input { flex: 1 1 auto; min-width: 0; }
  .ae-filters > .ae-filter-group:last-child { margin-left: auto; flex-wrap: nowrap; }
  @media (max-width: 600px) {
    .ae-filters > .ae-filter-group { flex: 1 1 100%; flex-wrap: wrap; }
    .ae-filters .ae-filter-label { flex: 0 0 100%; margin: 0; }
    .ae-filters > .ae-filter-group:last-child { margin-left: 0; }
  }
}
@layer screens {
  /* Flat cards, plain borders: Divisions tiles still carried a two-layer drop
     shadow, and the Overview cards/KPI tiles a blue-tinted border. */
  .gl-division-card { box-shadow: none; border: 1px solid var(--border); }
  .main :is(.kpi-card, .card.hero-card, .card.panel, .card.right-section),
  .coo-kpi-grid .coo-kpi-btn { border-color: var(--border); }
}
@layer screens {
  /* Overview KPI placeholders: value-sized shimmer bar instead of "Loading…" text */
  .kpi-card.skeleton-card .skeleton-value { width: 60%; height: 26px; border-radius: var(--r-sm); }
  .kpi-skel-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  @media (prefers-reduced-motion: reduce) { .kpi-card.skeleton-card .skeleton-line { animation: none; } }
}
@layer screens {
  /* Messages: skeleton rows / bubbles while the list or a thread loads */
  .msg-skel { display: flex; flex-direction: column; padding: var(--sp-2) 0; }
  .msg-skel-row { display: flex; align-items: center; gap: var(--sp-3); padding: 10px var(--sp-4); }
  .msg-skel-avatar { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%; background: rgba(var(--ink-rgb), 0.06); }
  .msg-skel-lines { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
  .msg-skel-l1 { width: 45%; }
  .msg-skel-l2 { width: 80%; height: 10px; }
  .msg-skel--thread { gap: 10px; padding: var(--sp-4); }
  .msg-skel-bubble { height: 34px; border-radius: 17px; }
  .msg-skel-out { align-self: flex-end; }
  .msg-skel-w35 { width: 35%; } .msg-skel-w40 { width: 40%; } .msg-skel-w55 { width: 55%; }
  .msg-skel-w60 { width: 60%; } .msg-skel-w70 { width: 70%; }
  @media (prefers-reduced-motion: reduce) { .msg-skel .skeleton-line { animation: none; } }
  /* Retry on the blue pill: white text (dark text on #1976D2 was 3.9:1) */
  .msg-retry-btn { color: var(--on-accent); }
}
@layer screens {
  /* Toasts: one flat style with a small status dot (success / error / info
     looked identical before). Plain border, no coloured stripe or tint. */
  .toast-container { align-items: center; }
  .toast-container .toast {
    display: flex; align-items: center; gap: 10px;
    max-width: min(92vw, 440px);
    padding: 10px 14px;
    background: var(--bg-card); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: var(--r-md);
    box-shadow: var(--shadow-md);
    font-size: var(--t-13); line-height: 1.35;
  }
  .toast-container .toast::before {
    content: ""; flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%;
    background: var(--status-info);
  }
  .toast-container .toast-success::before { background: var(--status-ok); }
  .toast-container .toast-error::before { background: var(--status-bad); }
  .toast-container .toast-warning::before { background: var(--status-warn); }
}
@layer screens {
  /* Settings: one rule under each section title (the h2 and its header both
     drew a line, so every card opened with a double rule). */
  .settings-view .settings-block-head h2 { border-bottom: 0; padding-bottom: 0; margin-bottom: 0; }
  /* The annual-plan "Switch" button matches the other Settings buttons
     (it was the only grey-filled one). */
  .settings-view .settings-promo-btn {
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    font-size: var(--t-13); font-weight: 500;
  }
  .settings-view .settings-promo-btn:hover { background: var(--bg-hover); }
}
@layer screens {
  /* Customers on wide desktops: the column header stays put while the list
     scrolls. The table fits without sideways scrolling from ~1240px, so the
     list wrapper no longer needs to be its own scroller there; the header's
     existing sticky positioning then works against the page. Its tint is
     made opaque (same colour as the two stacked 4% layers) so rows don't
     show through. */
  @media (min-width: 1240px) {
    body.route-customers .cust-list { overflow: visible; }
    body.route-customers .cust-table { overflow: hidden; }
    body.route-customers .cust-table thead,
    body.route-customers .cust-table thead tr,
    body.route-customers .cust-table thead th { background-color: transparent; }
  }
}
@layer screens {
  /* Printing (Reports, Dashboards, Customers...): drop the app chrome so the
     page prints as a document. The phone-width top bar was repeating over
     every page and covering rows; the Ask composer, chat launcher, menus and
     toasts printed too. Cards and table rows no longer split across pages. */
  @media print {
    #mobile-topnav, #sidebar, #gl-tabbar, #gl-menu, #floating-chat,
    #floating-chat-panel, #notif-history-overlay, .ai-composer-wrap,
    .toast-container, .cust-pager, .cust-addcol-btn, .report-refresh { display: none; }
    #main, #main-content { height: auto; overflow: visible; }
    .cust-table thead { position: static; }
    .pred-card, .kpi-card, .report-section > h2, .settings-block,
    .cust-table tr, .cust-card { break-inside: avoid; }
    .report-section > h2, .report-section-head { break-after: avoid; }
  }
}

/* sharpen8: Try again button on page-level load errors */
@layer screens {
  .gl-retry-btn { margin-top: 12px; font: inherit; font-size: var(--t-13); }
}

/* sharpen9: New automation dialog — show its title and let the form scroll on short screens */
@layer screens {
  .auto-v2-modal .auto-v2-title { display: block; font-size: var(--t-15); font-weight: 600; color: var(--text-primary); }
  .auto-v2-modal.pred-card { overflow-y: auto; max-height: calc(100dvh - 2 * var(--sp-5)); overscroll-behavior: contain; }
}

/* Ask session tabs (round 10): the row fits at every width. Tabs keep a
   sensible width and ellipsize, the active tab is scrolled into view (JS),
   the + button sits outside the scroller so it is always visible, and only
   the tab row scrolls sideways. Tap targets: 44px on phones and tablets (mobile shell), 36px on desktop. */
@layer screens {
  #ty-agent-tabs.ty-agent-tabs { overflow: hidden; gap: var(--sp-1); border-radius: 0; }
  #ty-agent-tabs .ty-session-scroller {
    gap: var(--sp-1); flex: 1 1 auto; min-width: 0;
    overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain;
    scroll-padding-inline: var(--sp-2); scrollbar-width: none;
  }
  #ty-agent-tabs .ty-tab {
    height: 36px; min-width: 96px; max-width: 240px; flex: 0 1 auto;
    padding: 0 var(--sp-3); gap: var(--sp-1); overflow: hidden;
  }
  #ty-agent-tabs .ty-tab-label { flex: 1 1 auto; min-width: 0; max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #ty-agent-tabs .ty-tab.is-active { flex-shrink: 0; }
  #ty-agent-tabs .ty-tab-add { flex: 0 0 auto; width: 36px; height: 36px; margin: 0; }
}
@media (max-width: 599px) {
  @layer screens {
    /* Phones: "New Session" plus one long title fit side by side at 390px. */
    #ty-agent-tabs .ty-tab { max-width: min(56vw, 200px); }
  }
}
@media (min-width: 600px) {
  @layer screens {
    #ty-agent-tabs .ty-tab { max-width: 280px; }
  }
}

/* Follow-up chips sit under the answer text and above the thumbs row (the
   bubble orders its parts with flex order; chips had order 0 and jumped to the top). */
@layer screens {
  .msg-bubble.msg-assistant > .nx-followups { order: 2; margin-top: var(--sp-2); }
}

/* Round 11: what a refusal could still verify, as one flat card under the
   refusal text. Neutral surface and hairline border; no tint or glow. */
@layer screens {
  .msg-bubble.msg-assistant .ty-refusal-facts {
    margin-top: var(--sp-3); padding: var(--sp-3) var(--sp-4);
    border: 1px solid var(--border); border-radius: var(--r-lg);
    background: var(--bg-card); box-shadow: none;
  }
  .msg-bubble.msg-assistant .ty-refusal-facts > p { margin: 0; color: var(--text-secondary); font-size: var(--t-13); }
  .msg-bubble.msg-assistant .ty-refusal-facts > p strong { color: var(--text-primary); }
  .msg-bubble.msg-assistant .ty-refusal-facts > ul { margin: var(--sp-2) 0 0; padding-left: var(--sp-4); }
  .msg-bubble.msg-assistant .ty-refusal-facts > ul li { margin: 0; font-variant-numeric: tabular-nums; }
}

/* Round 15: Ask answer layout. Headline, range, table, then one flat proof
   line and a quiet action row. Neutral borders only: no tinted chips, no
   colored stripes, no nested scroll boxes. */
@layer screens {
  /* Thumbs: keep the 44px tap area, drop the chrome so they read small. */
  .msg-bubble.msg-assistant > .gl-msg-feedback.answer-feedback[role="group"] { gap: 0; margin-top: var(--sp-1); }
  .answer-feedback .pred-tool.answer-feedback-button {
    border: 0; background: transparent; box-shadow: none; color: var(--text-tertiary, var(--text-secondary));
    opacity: .8; margin: 0 -4px;
  }
  .answer-feedback .pred-tool.answer-feedback-button:first-child { margin-left: -12px; }
  .answer-feedback .answer-feedback-button svg { width: 15px; height: 15px; }
  .answer-feedback .pred-tool.answer-feedback-button:hover:not(:disabled),
  .answer-feedback .pred-tool.answer-feedback-button[aria-pressed="true"] {
    border: 0; background: transparent; color: var(--text-primary); opacity: 1;
  }
  .answer-feedback .answer-elapsed {
    margin-left: var(--sp-2); color: var(--text-secondary); font-size: var(--t-12);
    font-variant-numeric: tabular-nums; line-height: 1.5;
  }
  .answer-feedback .answer-elapsed + .answer-feedback-status:not(:empty)::before { content: "·"; margin-right: var(--sp-1); opacity: .6; }

  /* Tables in answers fit the bubble on phones: wrap header text, keep
     numbers on one line, tighter cells; never a sideways scroller. */
  .ai-messages .msg-bubble.msg-assistant .ai-prose table { width: 100%; max-width: 100%; table-layout: auto; }
  .ai-messages .msg-bubble.msg-assistant .ai-prose th { white-space: normal; overflow-wrap: break-word; word-break: normal; vertical-align: bottom; }
  .ai-messages .msg-bubble.msg-assistant .ai-prose td { overflow-wrap: break-word; word-break: normal; font-variant-numeric: tabular-nums; }
  .ai-messages .msg-bubble.msg-assistant .ai-prose td:first-child { overflow-wrap: anywhere; }
  .ai-messages .msg-bubble.msg-assistant .ai-prose th[align="right"],
  .ai-messages .msg-bubble.msg-assistant .ai-prose td[align="right"] { text-align: right; white-space: nowrap; }
  .msg-bubble.msg-assistant .ttl-sv-table td { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

  /* Suggestion chips and empty-state examples: neutral bordered, no tint. */
  .chat-suggest-chip { background: transparent; border: 1px solid var(--border); color: var(--text-primary); }
  .chat-suggest-chip:hover, .chat-suggest-chip:focus-visible { background: transparent; border-color: var(--text-secondary); }

  /* Session tabs: one compact row; tab and + share a center line. */
  #ty-agent-tabs.ty-agent-tabs { align-items: center; min-height: 40px; padding-block: 2px; }
  #ty-agent-tabs .ty-session-scroller { align-items: center; flex: 0 1 auto; }
  #ty-agent-tabs .ty-session-scroller + .ty-tab-add, #ty-agent-tabs .ty-tab-add { margin-right: auto; }
  #ty-agent-tabs .ty-tab { height: 32px; min-height: 32px; }
  #ty-agent-tabs .ty-tab-add { width: 32px; height: 32px; min-width: 32px; min-height: 32px; align-self: center; margin: 0 0 0 2px; }
}
@media (max-width: 420px) {
  @layer screens {
    .ai-messages .msg-bubble.msg-assistant .ai-prose table { font-size: var(--t-12); }
    .ai-messages .msg-bubble.msg-assistant .ai-prose th,
    .ai-messages .msg-bubble.msg-assistant .ai-prose td { padding: 0.35rem 0.4rem; }
    .ai-messages .msg-bubble.msg-assistant .ai-prose th:first-child,
    .ai-messages .msg-bubble.msg-assistant .ai-prose td:first-child { padding-left: 0; }
  }
}

/* Round 15: the proof line under the answer and the chart card. Injected
   operator styles are auto-layered as legacy, so these live here. */
@layer screens {
  .msg-bubble.msg-assistant > .ttl-answer-foot { order: 2; margin: var(--sp-2) 0 0; display: grid; gap: var(--sp-2); min-width: 0; }
  .msg-bubble.msg-assistant > .ttl-answer-foot:empty { display: none; }
  .msg-bubble .ttl-evidence,
  .msg-bubble .ttl-evidence[open],
  .msg-bubble .ttl-evidence[data-verified="1"] {
    margin: 0; padding: 0; display: block; max-width: 36rem; min-width: 0;
    border: 1px solid var(--border); border-radius: var(--r-md, 8px);
    background: transparent; box-shadow: none; color: var(--text-secondary);
  }
  .msg-bubble .ttl-evidence > summary.ttl-evidence-chip {
    display: block; margin: 0; padding: 6px 10px; border: 0; border-radius: inherit;
    background: transparent; box-shadow: none; color: var(--text-secondary);
    font-size: var(--t-12); line-height: 1.45; white-space: normal; overflow-wrap: anywhere;
    cursor: pointer; list-style: none;
  }
  .msg-bubble .ttl-evidence > summary.ttl-evidence-chip::-webkit-details-marker { display: none; }
  .msg-bubble .ttl-evidence > summary.ttl-evidence-chip:hover { color: var(--text-primary); }
  .msg-bubble .ttl-evidence .ttl-evidence-body { padding: 0 10px 8px; display: grid; gap: var(--sp-1); }
  .msg-bubble.msg-assistant.has-answer-elapsed .nx-thinking-elapsed { display: none; }
  .msg-bubble .ttl-sv-chart {
    border: 1px solid var(--border); border-radius: var(--r-md, 8px);
    background: transparent; box-shadow: none; max-width: 36rem; min-width: 0;
  }
}

/* Round 15: example questions on the empty Ask view. Neutral chips, gone
   once the thread has messages. */
@layer screens {
  .ai-view.ai-home > .ask-examples {
    position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center;
    gap: var(--sp-2); margin: auto var(--sp-4) var(--sp-3); padding: 0; text-align: center;
  }
  body.ai-has-messages .ai-view.ai-home > .ask-examples { display: none; }
  .ask-examples .ask-examples-title { color: var(--text-secondary); font-size: var(--t-13); font-weight: 500; }
  .ask-examples .ask-examples-row { margin-top: 0; justify-content: center; max-width: 36rem; }
}

/* Round 15: follow-up and "Ask can check these exactly" chips, neutral. */
@layer screens {
  .msg-bubble.msg-assistant > .nx-followups { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
  .msg-bubble.msg-assistant > .nx-followups .nx-followups-label { flex: 1 0 100%; color: var(--text-secondary); font-size: var(--t-12); font-weight: 500; }
  .ai-view .msg-bubble.msg-assistant .nx-followup-chip {
    background: transparent; border: 1px solid var(--border); color: var(--text-primary);
    border-radius: var(--r-pill); min-height: 36px; padding: 6px 12px; font-size: var(--t-13);
    text-align: left; white-space: normal; max-width: 100%;
  }
  .ai-view .msg-bubble.msg-assistant .nx-followup-chip:hover { background: transparent; border-color: var(--text-secondary); }
}

/* ── Ask composer, phone: one-row chat bar ─────────────────────────────────
   Was a tall card with the input on top and a second row of + / Web / model /
   mic / stop / send. Now it reads like a messaging app: a round + on the
   left, one pill input that grows to about five lines, a mic inside the pill
   and one round button at its right end (send when there is text, stop while
   an answer streams). Web search and model moved into the + menu (app.js,
   "Options" group); an active Web search shows as a small globe in the pill
   so it is never on silently. The bar is opaque and docked (position and
   keyboard offset are set inline by enforceMobileAskLayout), and the answer
   list reserves exactly the bar height, so the last lines are never covered.
   Flat: plain hairline borders, no shadows, glows, blur or gradients. */
@layer screens {
  @media (max-width: 820px) {
    body.route-ask .ai-view .ai-composer-wrap {
      border-top: 1px solid var(--border);
    }
    /* The list runs to the bottom edge (an old 100dvh - 200px cap left a dead
       band) and reserves exactly the bar height plus a small gap. */
    body.route-ask.ai-has-messages .ai-view .ai-messages {
      max-height: none;
      padding-bottom: calc(var(--composer-h, 64px) + 12px);
      scroll-padding-bottom: calc(var(--composer-h, 64px) + 12px);
    }

    body.route-ask .ai-view #ask-composer.rich-composer {
      display: grid;
      grid-template-columns: 44px minmax(0, 1fr) auto auto auto;
      column-gap: 0;
      row-gap: 0;
      align-items: end;
      width: 100%;
      min-height: 0;
      max-width: none;
      margin: 0;
      padding: 0;
      background: transparent;
      border: 0;
      border-radius: 0;
      box-shadow: none;
      backdrop-filter: none;
      -webkit-backdrop-filter: none;
    }
    body.route-ask .ai-view #ask-composer.rich-composer:focus-within { box-shadow: none; border: 0; }

    /* The pill outline: one box behind input, web, mic and the round button. */
    body.route-ask .ai-view #ask-composer.rich-composer::before {
      content: "";
      display: block;
      grid-row: 4;
      grid-column: 2 / -1;
      align-self: stretch;
      margin-left: 8px;
      min-height: 44px;
      box-sizing: border-box;
      background: var(--bg-elev);
      border: 1px solid var(--border-strong);
      border-radius: 22px;
      pointer-events: none;
      position: static;
      transform: none;
      box-shadow: none;
      opacity: 1;
    }
    body.route-ask .ai-view #ask-composer.rich-composer:focus-within::before { border-color: var(--accent); }
    body.route-ask .ai-view #ask-composer.rich-composer::after { content: none; display: none; }

    /* Flatten the old toolbar wrappers so their children sit on the grid. */
    body.route-ask .ai-view #ask-composer :is(.rc-toolbar, .rc-left, .rc-right, .rc-send-actions) {
      display: contents;
    }
    body.route-ask .ai-view #ask-composer :is(.rc-toolbar, .rc-left, .rc-right, .rc-send-actions)::before,
    body.route-ask .ai-view #ask-composer :is(.rc-toolbar, .rc-left, .rc-right, .rc-send-actions)::after {
      content: none;
      display: none;
    }

    /* Rows above the bar: connector chips, attachments, the source panel. */
    body.route-ask .ai-view #ask-composer > .rc-connector-chips { grid-row: 1; grid-column: 1 / -1; margin: 0 0 8px; }
    body.route-ask .ai-view #ask-composer > .rc-attachments { grid-row: 2; grid-column: 1 / -1; }
    body.route-ask .ai-view #ask-composer > .rc-attachments:not(:empty) { margin: 0 0 8px; }
    body.route-ask .ai-view #ask-composer > .rc-connector-panel { grid-row: 3; grid-column: 1 / -1; }
    body.route-ask .ai-view #ask-composer > .rc-connector-announcement { grid-row: 3; grid-column: 1 / -1; }

    /* Round + on the left (native OS menu: Add, Sources, Options, Chat). */
    body.route-ask .ai-view #ask-composer .rc-plus-wrap {
      grid-row: 4;
      grid-column: 1;
      align-self: end;
      width: 44px;
      height: 44px;
      flex: none;
      position: relative;
    }
    body.route-ask .ai-view #ask-composer .rc-plus-native-wrap {
      width: 44px;
      height: 44px;
      min-width: 44px;
      min-height: 44px;
      max-width: 44px;
      max-height: 44px;
      border-radius: 50%;
      background: var(--bg-elev);
      border: 1px solid var(--border-strong);
      color: var(--text-primary);
      box-shadow: none;
    }
    body.route-ask .ai-view #ask-composer .rc-plus-native-wrap > svg { width: 20px; height: 20px; }
    body.route-ask .ai-view #ask-composer .rc-plus-native-wrap:active { background: var(--bg-hover); }

    /* The input: single line at rest, grows to about five lines, then scrolls. */
    body.route-ask .ai-view #ask-composer .rc-input {
      grid-row: 4;
      grid-column: 2;
      align-self: stretch;
      position: relative;
      box-sizing: border-box;
      width: auto;
      min-width: 0;
      min-height: 44px;
      max-height: 132px;
      margin: 0 0 0 8px;
      padding: 11px 6px 11px 16px;
      overflow-y: auto;
      overflow-x: hidden;
      font-size: var(--t-16);
      line-height: 22px;
      color: var(--text-primary);
      background: transparent;
      border: 0;
      border-radius: 0;
      outline: none;
      box-shadow: none;
      white-space: pre-wrap;
      overflow-wrap: anywhere;
    }
    body.route-ask .ai-view #ask-composer .rc-input:empty::before {
      content: attr(data-placeholder);
      position: absolute;
      left: 16px;
      top: 11px;
      line-height: 22px;
      color: var(--text-tertiary);
      pointer-events: none;
    }

    /* Model chip and run mode live in the + menu now; the hidden model select stays for sync. */
    body.route-ask .ai-view #ask-composer .rc-chip--model { display: none; }
    body.route-ask .ai-view #ask-composer .rc-chip[data-chip="web"]:not(.rc-chip--active) { display: none; }

    /* In-pill controls: active Web globe, mic, then send / stop. 36px circles,
       4px from the pill edge, so a one-line pill is 44px tall like the +.
       :where() keeps this shared block at low specificity so the per-button
       rules below (stop/send swap, margins) win. */
    body.route-ask .ai-view #ask-composer :where(.rc-chip[data-chip="web"].rc-chip--active, .rc-mic, .rc-send, .gl-stop-btn) {
      grid-row: 4;
      align-self: end;
      position: relative;
      box-sizing: border-box;
      width: 36px;
      height: 36px;
      min-width: 36px;
      min-height: 36px;
      max-width: 36px;
      max-height: 36px;
      flex: none;
      margin: 0 0 4px 0;
      padding: 0;
      border-radius: 50%;
      border: 0;
      box-shadow: none;
      filter: none;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 0;
      transform: none;
      transition: background-color 120ms ease, color 120ms ease, transform 90ms ease;
    }
    /* Keep a 44px touch target around the 36px circles. */
    body.route-ask .ai-view #ask-composer :where(.rc-chip[data-chip="web"].rc-chip--active, .rc-mic, .rc-send, .gl-stop-btn)::after {
      content: "";
      position: absolute;
      inset: -4px;
    }
    body.route-ask .ai-view #ask-composer .rc-chip[data-chip="web"].rc-chip--active {
      grid-column: 3;
      background: transparent;
      color: var(--accent);
    }
    body.route-ask .ai-view #ask-composer .rc-chip[data-chip="web"] .rc-chip-web-label {
      position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0);
    }
    body.route-ask .ai-view #ask-composer .rc-mic {
      grid-column: 4;
      background: transparent;
      color: var(--text-secondary);
    }
    body.route-ask .ai-view #ask-composer .rc-mic svg { width: 20px; height: 20px; }
    body.route-ask .ai-view #ask-composer .rc-mic.rc-mic--on { color: var(--status-bad, #D93025); background: var(--bg-hover); }
    body.route-ask .ai-view #ask-composer.rc-composer--stopping .rc-mic {
      display: inline-flex; width: 36px; min-width: 36px; max-width: 36px; flex: none; overflow: visible;
    }

    body.route-ask .ai-view #ask-composer :is(.rc-send, .gl-stop-btn) {
      grid-column: 5;
      margin-right: 4px;
    }
    /* Empty: quiet grey circle. Typing: Totaly blue. */
    body.route-ask .ai-view #ask-composer .rc-send,
    body.route-ask .ai-view #ask-composer .rc-send:disabled {
      background: var(--bg-hover);
      color: var(--text-faint);
      opacity: 1;
    }
    body.route-ask .ai-view #ask-composer.rc-has-input .rc-send:not(:disabled) {
      background: var(--accent);
      color: var(--on-accent);
    }
    body.route-ask .ai-view #ask-composer .rc-send svg { width: 18px; height: 18px; stroke-width: 2.4; }
    /* Generating: the same spot becomes stop (send stays reachable by Enter). */
    body.route-ask .ai-view #ask-composer.rc-composer--stopping .rc-send { display: none; }
    body.route-ask .ai-view #ask-composer .gl-stop-btn {
      background: var(--text-primary);
      color: var(--bg-app);
    }
    body.route-ask .ai-view #ask-composer .gl-stop-btn svg { width: 11px; height: 11px; }
    body.route-ask .ai-view #ask-composer :is(.rc-send, .gl-stop-btn, .rc-mic):active { transform: scale(0.92); }

    @media (prefers-reduced-motion: reduce) {
      body.route-ask .ai-view #ask-composer :is(.rc-send, .gl-stop-btn, .rc-mic, .rc-chip) { transition: none; }
      body.route-ask .ai-view #ask-composer :is(.rc-send, .gl-stop-btn, .rc-mic):active { transform: none; }
    }
  }
}

/* ===== SuperViz: Preset-style dashboard =====
   Matches Apache Superset / Preset conventions: compact header, one filter
   bar row of chips, underline tabs, flat cards with a 1px border and a small
   radius, a small title with a quiet overflow menu, even gutters. Flat only:
   no tinted cards, no side stripes, no glows, blur or fades.
   Prefixed with `html` so these win over the later mobile-os.css rules. */
@layer screens {
  html .sv-page {
    --svx-card: var(--bg-card);
    --svx-border: var(--border-strong);
    --svx-rule: var(--border);
    --svx-text: var(--text-primary);
    --svx-muted: var(--text-tertiary);
    --svx-radius: 6px;
    --svx-gap: 16px;
    --sv-card: var(--svx-card);
    --sv-card-border: var(--svx-border);
    --sv-hover-border: var(--border-strong);
    --sv-accent: var(--accent);
    background: transparent;
  }
  html[data-app-theme="light"] .sv-page,
  html[data-theme="light"] .sv-page { --svx-card: #FFFFFF; --svx-border: #E0E0E0; --svx-rule: #ECECEC; }
  html[data-app-theme="dark"] .sv-page,
  html[data-theme="dark"] .sv-page { --svx-card: #1F2121; --svx-border: #303232; --svx-rule: #2A2C2C; }

  /* Header: title + count left, actions right, one thin rule below. */
  html .sv-page .sv-chrome { margin: 0; }
  html .sv-page .page-head {
    display: flex; align-items: center; flex-wrap: nowrap; gap: 12px;
    min-height: 0; padding: 0 0 12px; margin: 0;
    background: transparent; border: 0; box-shadow: none;
  }
  html .sv-page .sh-head-titles { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1 1 auto; }
  html .sv-page .page-title {
    font-size: 20px; font-weight: 600; line-height: 1.3; letter-spacing: 0; color: var(--svx-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
  }
  html .sv-page .sh-page-count { font-size: 12px; color: var(--svx-muted); margin: 0; white-space: nowrap; }
  html .sv-page .page-head-actions {
    display: flex; flex-wrap: nowrap; align-items: center; justify-content: flex-end; gap: 8px;
    margin-left: auto; flex: 0 0 auto; width: auto; max-width: none;
  }
  html .sv-page .page-head-actions > .btn { width: auto; flex: 0 0 auto; }
  html .sv-page .btn {
    height: 32px; min-height: 32px; padding: 0 12px; gap: 6px;
    border-radius: 4px; font-size: 13px; font-weight: 500; box-shadow: none;
  }
  html .sv-page .btn svg { width: 15px; height: 15px; }
  html .sv-page .btn:not(.btn-primary):not(.btn-ghost) {
    background: transparent; color: var(--svx-text); border: 1px solid var(--svx-border);
  }
  html .sv-page .btn:not(.btn-primary):not(.btn-ghost):hover { background: var(--bg-hover); }
  html .sv-page .btn-primary { background: var(--accent); border: 1px solid var(--accent); color: #FFFFFF; }
  html .sv-page .btn-primary:hover { background: var(--accent-hover, var(--accent)); filter: none; }
  html .sv-page .btn-ghost { background: transparent; border: 1px solid transparent; color: var(--text-secondary); }
  html .sv-page .btn-ghost:hover:not([disabled]) { background: var(--bg-hover); color: var(--svx-text); }
  html .sv-page .btn-sm { height: 32px; min-height: 32px; padding: 0 10px; font-size: 13px; }

  /* Overflow menus (header and cards): plain <details> with a flat sheet. */
  html .sv-page details.sh-more,
  html .sv-page details.sv-card-menu { position: relative; flex: 0 0 auto; }
  html .sv-page details.sh-more > summary,
  html .sv-page details.sv-card-menu > summary { list-style: none; cursor: pointer; }
  html .sv-page details.sh-more > summary::-webkit-details-marker,
  html .sv-page details.sv-card-menu > summary::-webkit-details-marker { display: none; }
  html .sv-page .sh-more-btn {
    width: 32px; height: 32px; min-width: 32px; min-height: 32px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--svx-border); border-radius: 4px; color: var(--text-secondary); background: transparent;
  }
  html .sv-page .sh-more-btn:hover, html .sv-page details[open] > .sh-more-btn { background: var(--bg-hover); color: var(--svx-text); }
  html .sv-page .sh-more-menu {
    position: absolute; top: calc(100% + 4px); right: 0; z-index: 60;
    min-width: 200px; padding: 4px; display: flex; flex-direction: column;
    background: var(--bg-card); border: 1px solid var(--svx-border); border-radius: var(--svx-radius);
  }
  html .sv-page .sh-more-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    min-height: 34px; padding: 0 10px; border: 0; border-radius: 4px;
    background: transparent; color: var(--svx-text); font-size: 13px; font-weight: 400; text-align: left; cursor: pointer;
  }
  html .sv-page .sh-more-item svg { width: 15px; height: 15px; color: var(--svx-muted); flex: none; }
  html .sv-page .sh-more-item:hover { background: var(--bg-hover); }
  html .sv-page .sh-more-item.is-on { color: var(--accent); font-weight: 500; }
  html .sv-page .sh-more-item.is-on svg { color: var(--accent); }
  html .sv-page .sh-more-item:disabled { opacity: 0.5; }
  html .sv-page .sh-more-rule { margin: 4px 0; border: 0; border-top: 1px solid var(--svx-rule); }
  html .sv-page .sh-more-phone { display: none; }

  /* Filter bar: one row of 32px chips with the label inside, thin rule below. */
  html .sv-page .sh-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    padding: 12px 0; margin: 0; border: 0; border-top: 1px solid var(--svx-rule); border-bottom: 1px solid var(--svx-rule);
    background: transparent;
  }
  html .sv-page .sh-toolbar > .search {
    flex: 0 1 240px; min-width: 180px; width: auto; height: 32px; min-height: 32px; padding: 0 10px;
    border: 1px solid var(--svx-border); border-radius: 4px; background: var(--svx-card); font-size: 13px;
  }
  html .sv-page .sh-toolbar > .search svg { width: 14px; height: 14px; color: var(--svx-muted); }
  html .sv-page .sh-toolbar > .search input { font-size: 13px; }
  html .sv-page .sh-toolbar > .select {
    flex: 0 0 auto; height: 32px; min-height: 32px; padding: 0 8px 0 10px; gap: 6px;
    border: 1px solid var(--svx-border); border-radius: 4px; background: var(--svx-card); color: var(--svx-text);
  }
  html .sv-page .sh-toolbar > .select:hover { border-color: var(--text-tertiary); }
  html .sv-page .sh-toolbar > .select .sh-menu-label { padding: 0; font-size: 12px; color: var(--svx-muted); white-space: nowrap; }
  html .sv-page .sh-toolbar > .select select { font-size: 13px; font-weight: 500; color: var(--svx-text); min-width: 0; padding-right: 2px; cursor: pointer; }
  html .sv-page .sh-toolbar > .btn-ghost { margin-left: 0; color: var(--accent); }
  html .sv-page .sh-toolbar > .btn-ghost[disabled] { color: var(--svx-muted); opacity: 0.6; }
  html .sv-page .sh-toolbar > .view-toggle { margin-left: auto; border: 1px solid var(--svx-border); border-radius: 4px; height: 32px; }
  html .sv-page .sh-toolbar > .view-toggle button { width: 32px; height: 30px; min-width: 32px; min-height: 30px; }
  html .sv-page .sh-toolbar > .view-toggle button svg { width: 15px; height: 15px; }
  html .sv-page .sh-toolbar > .view-toggle button.active { background: var(--bg-hover); color: var(--accent); }

  /* Tabs: text tabs with a 2px blue underline on the active one. */
  html .sv-page .sv-tabs-slot { margin: 0; }
  html .sv-page .sv-tabs {
    display: flex; flex-wrap: wrap; gap: 0 24px; margin: 0 0 20px; padding: 0;
    border-bottom: 1px solid var(--svx-rule);
  }
  html .sv-page .sv-tab {
    min-height: 40px; min-width: 0; padding: 10px 0; margin: 0 0 -1px;
    border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent;
    color: var(--text-secondary); font-size: 14px; font-weight: 500; letter-spacing: 0; text-transform: none;
  }
  html .sv-page .sv-tab:hover { color: var(--svx-text); border-bottom-color: var(--svx-border); background: transparent; }
  html .sv-page .sv-tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); background: transparent; }

  /* Section head: sentence case, muted blurb under it, freshness + Edit layout on the right. */
  html .sv-page .sv-section + .sv-section { margin-top: 32px; }
  html .sv-page .sv-section-head {
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
    margin: 0 0 12px; padding: 0; border: 0;
  }
  html .sv-page .sv-section-title {
    order: 1; font-size: 16px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--svx-text);
  }
  html .sv-page .sv-section-head .sv-fresh { order: 2; margin-left: auto; font-size: 12px; color: var(--svx-muted); }
  html .sv-page .sv-section-head .sv-fresh ~ .sv-fresh { margin-left: 0; }
  html .sv-page .sv-section-head .sv-refresh-cta { order: 3; margin-left: 0; height: 28px; border-radius: 4px; }
  html .sv-page .sv-section .sv-section-head > .de-head-actions { order: 4; margin-left: 0; display: flex; align-items: center; gap: 8px; }
  html .sv-page .sv-section-blurb { order: 5; flex: 1 0 100%; margin: 0; font-size: 13px; color: var(--svx-muted); }
  html .sv-page .de-button {
    height: 28px; min-height: 28px; padding: 0 10px; gap: 6px; display: inline-flex; align-items: center;
    border: 1px solid var(--svx-border); border-radius: 4px; background: transparent; box-shadow: none;
    color: var(--text-secondary); font-size: 12px; font-weight: 500;
  }
  html .sv-page .de-button[hidden] { display: none; }
  html .sv-page .de-button:hover { background: var(--bg-hover); color: var(--svx-text); }
  html .sv-page .de-button svg { width: 14px; height: 14px; }

  /* Grid and cards. */
  html .sv-page .sv-grid { gap: var(--svx-gap); }
  html .sv-page .sv-card {
    background: var(--svx-card); border: 1px solid var(--svx-border); border-radius: var(--svx-radius);
    box-shadow: none; transition: border-color 120ms ease;
  }
  html .sv-page .sv-card:hover { border-color: var(--text-tertiary); }
  html .sv-page .sv-card.sv-card-focus { border-color: var(--accent); box-shadow: none; }
  html .sv-page .sv-card-head {
    min-height: 0; padding: 12px 8px 4px 16px; gap: 8px; align-items: flex-start; font-size: 14px;
  }
  html .sv-page .sv-card-head .sv-card-title {
    font-size: 14px; font-weight: 600; line-height: 20px; letter-spacing: 0; color: var(--svx-text); padding-top: 2px;
  }
  html .sv-page .sv-card-body { padding: 4px 16px 12px; }
  html .sv-page .sv-card-actions { margin-left: auto; gap: 0; opacity: 1; display: block; }
  html .sv-page .sv-card-menu-btn {
    width: 28px; height: 28px; min-width: 28px; min-height: 28px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--svx-muted);
  }
  html .sv-page .sv-card-menu-btn svg { width: 16px; height: 16px; }
  html .sv-page .sv-card-menu-btn:hover,
  html .sv-page details[open] > .sv-card-menu-btn { background: var(--bg-hover); color: var(--svx-text); }
  html .sv-page .sv-card .sh-more-menu { min-width: 168px; top: calc(100% + 2px); }
  html .sv-page .sv-card.sv-card-full { box-shadow: none; border-radius: var(--svx-radius); }

  /* KPI tiles: big number, small grey label. */
  html .sv-page .ac-kpi-label { font-size: 12px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--svx-muted); }

  /* Tables: sticky header, thin row rules, no zebra. */
  html .sv-page .ac-table tbody tr,
  html .sv-page .ac-table tbody tr:nth-child(even),
  html .sv-page .ac-table tbody tr:nth-child(odd) { background: transparent; }
  html .sv-page .ac-table tbody tr:hover { background: var(--bg-hover); }
  html .sv-page .ac-table th { font-size: 12px; font-weight: 600; color: var(--text-secondary); background: var(--svx-card); border-bottom: 1px solid var(--svx-border); }
  html .sv-page .ac-table td { border-bottom: 1px solid var(--svx-rule); }

  /* Charts / datasets tables: one flat bordered panel, thin row rules, no
     column dividers. td.sh-truncate stays a table cell (display:block on a
     td broke the columns). */
  html .sv-page .table-wrap { border: 1px solid var(--svx-border); border-radius: var(--svx-radius); background: var(--svx-card); }
  html .sv-page table.sh-table th { height: 40px; padding: 8px 12px; font-size: 12px; font-weight: 600; color: var(--text-secondary);
    border-bottom: 1px solid var(--svx-border); background: var(--svx-card); }
  html .sv-page table.sh-table th + th:not(.sh-star-cell)::before { content: none; }
  html .sv-page table.sh-table td { height: 44px; padding: 6px 12px; font-size: 13px; border-bottom: 1px solid var(--svx-rule); }
  html .sv-page table.sh-table tbody tr:last-child td { border-bottom: 0; }
  html .sv-page table.sh-table tbody tr:hover td { background: var(--bg-hover); }
  html .sv-page td.sh-truncate { display: table-cell; max-width: 260px; }
  html .sv-page .sh-table .tag-viz { background: transparent; border: 1px solid var(--svx-border); color: var(--text-secondary); }

  /* Loading placeholders are flat: one solid fill, no shimmer. */
  html .sv-page .skel { background: var(--bg-elev); animation: none; }

  /* Phones: header keeps one row (title, New chart, menu); filters wrap as
     search on its own line, then chips. Touch targets stay 40px+. */
  @media (max-width: 820px) {
    html .sv-page { --svx-gap: 12px; }
    html .sv-page .page-head { padding-bottom: 10px; }
    html .sv-page .page-title { font-size: 18px; }
    html .sv-page .sh-head-titles { flex-direction: column; align-items: flex-start; gap: 0; }
    html .sv-page .page-head-actions { display: flex; gap: 8px; }
    html .sv-page .page-head-actions > .sh-head-secondary { display: none; }
    html .sv-page .sh-more-phone { display: flex; }
    html .sv-page .btn, html .sv-page .btn-sm { height: 40px; min-height: 40px; }
    html .sv-page .sh-more-btn { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
    html .sv-page .sh-more-item { min-height: 44px; font-size: 15px; }
    html .sv-page .sh-toolbar { padding: 10px 0; gap: 8px; }
    html .sv-page .sh-toolbar > .search { flex: 1 1 0; min-width: 0; height: 40px; min-height: 40px; font-size: 16px; }
    html .sv-page .sh-toolbar > .search input { font-size: 16px; }
    html .sv-page .sh-toolbar > .view-toggle { order: 1; flex: none; margin-left: 0; height: 40px; }
    html .sv-page .sh-toolbar > .view-toggle button { height: 38px; min-height: 38px; width: 36px; min-width: 36px; }
    html .sv-page .sh-toolbar > .select { order: 2; flex: 1 1 calc(50% - 4px); min-width: 0; height: 40px; min-height: 40px; }
    html .sv-page .sh-toolbar > .sh-time { flex-basis: 100%; }
    html .sv-page .sh-toolbar > .select select { flex: 1 1 auto; font-size: 15px; }
    html .sv-page .sh-toolbar > .btn-ghost { order: 3; margin-left: auto; height: 32px; min-height: 32px; }
    html .sv-page .sh-toolbar > .btn-ghost[disabled] { display: none; }
    html .sv-page .sv-tabs { gap: 0 20px; margin-bottom: 16px; }
    html .sv-page .sv-tab { min-height: 44px; padding: 12px 0; font-size: 14px; }
    html .sv-page .sv-card-head { min-height: 0; padding: 10px 4px 2px 12px; }
    html .sv-page .sv-card-body { padding: 4px 12px 10px; }
    html .sv-page .sv-card-menu-btn { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
    html .sv-page .de-button { height: 36px; min-height: 36px; }
    html .sv-page .sv-section .sv-section-head > .de-head-actions { order: 2; margin-left: auto; }
    html .sv-page .sv-section-head .sv-refresh-cta { order: 3; }
    html .sv-page .sv-section-blurb { order: 4; }
    html .sv-page .sv-section-head .sv-fresh { order: 5; margin-left: 0; }
  }
}

/* ===== SuperViz: chart detail view (chart-detail.js) =====
   Preset/Superset explore layout. One full-screen surface with one scroll
   area: header (back, title, subtitle, actions), headline numbers, the chart
   large, a compact Controls panel (right on desktop, under the chart on a
   phone) and Data / Query / Details tabs. Flat panels with a plain 1px
   border; no stripes, tints, glows or fades. Totaly blue is
   the only accent. */
@layer screens {
  html .sv-page .svd {
    --svd-bg: #F7F7F7; --svd-card: #FFFFFF; --svd-border: #E0E0E0; --svd-rule: #ECECEC;
    --svd-text: #1F2328; --svd-text-2: #4B5563; --svd-muted: #6B7280;
    --svd-blue: #2196F3; --svd-blue-ink: #1976D2; --svd-hover: rgba(17, 24, 39, 0.05);
    position: fixed; inset: 0; z-index: 2400; display: flex; flex-direction: column;
    background: var(--svd-bg); color: var(--svd-text); font-size: 14px; line-height: 1.4;
  }
  html[data-app-theme="dark"] .sv-page .svd,
  html[data-theme="dark"] .sv-page .svd {
    --svd-bg: #171818; --svd-card: #1F2121; --svd-border: #303232; --svd-rule: #2A2C2C;
    --svd-text: #E8E7E5; --svd-text-2: #B5B7BE; --svd-muted: #8F949E;
    --svd-blue: #2196F3; --svd-blue-ink: #64B5F6; --svd-hover: rgba(255, 255, 255, 0.06);
  }
  html.svd-open, html.svd-open body { overflow: hidden; }

  /* Header: one solid row with a single rule under it. */
  html .sv-page .svd-head {
    flex: none; display: flex; align-items: center; gap: 12px;
    padding: 12px 24px; min-height: 64px; background: var(--svd-card);
    border-bottom: 1px solid var(--svd-border); box-shadow: none;
  }
  html .sv-page .svd-back {
    flex: none; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--svd-border); border-radius: 4px; background: transparent; color: var(--svd-text-2); cursor: pointer;
  }
  html .sv-page .svd-back:hover { background: var(--svd-hover); color: var(--svd-text); }
  html .sv-page .svd-back svg { width: 18px; height: 18px; }
  html .sv-page .svd-titles { min-width: 0; flex: 1 1 auto; }
  html .sv-page .svd-crumb { margin: 0; font-size: 12px; color: var(--svd-muted); }
  html .sv-page .svd-title {
    margin: 0; font-size: 18px; font-weight: 600; line-height: 24px; letter-spacing: 0; color: var(--svd-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  html .sv-page .svd-title:focus { outline: none; }
  html .sv-page .svd-back:focus:not(:focus-visible) { outline: none; }
  html .sv-page .svd-sub { margin: 0; font-size: 12px; color: var(--svd-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  html .sv-page .svd-actions { flex: none; display: flex; align-items: center; gap: 8px; }
  html .sv-page .svd-btn {
    display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
    border: 1px solid var(--svd-border); border-radius: 4px; background: var(--svd-card);
    color: var(--svd-text); font-size: 13px; font-weight: 500; white-space: nowrap; cursor: pointer;
  }
  html .sv-page .svd-btn svg { width: 15px; height: 15px; color: var(--svd-muted); flex: none; }
  html .sv-page .svd-btn:hover { background: var(--svd-hover); }
  html .sv-page .svd-btn.svd-icon-only { width: 36px; padding: 0; justify-content: center; }
  html .sv-page .svd-btn.svd-icon-only span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  html .sv-page .svd-btn.svd-primary { background: var(--svd-blue); border-color: var(--svd-blue); color: #FFFFFF; }
  html .sv-page .svd-btn.svd-primary svg { color: #FFFFFF; }
  html .sv-page .svd-btn.svd-primary:hover { background: #1E88E5; border-color: #1E88E5; }
  html .sv-page .svd-more { display: none; position: relative; flex: none; }
  html .sv-page .svd-more > summary { list-style: none; }
  html .sv-page .svd-more > summary::-webkit-details-marker { display: none; }
  html .sv-page .svd-menu {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; min-width: 200px; padding: 4px;
    background: var(--svd-card); border: 1px solid var(--svd-border); border-radius: 6px; box-shadow: none;
  }
  html .sv-page .svd-menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 0 12px;
    border-radius: 4px; background: transparent; color: var(--svd-text); font-size: 15px; text-align: left;
  }
  html .sv-page .svd-menu-item svg { width: 16px; height: 16px; color: var(--svd-muted); }
  html .sv-page .svd-menu-item:hover { background: var(--svd-hover); }

  /* One scroll area for everything below the header. */
  html .sv-page .svd-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
  html .sv-page .svd-body {
    display: grid; gap: 16px; padding: 20px 24px 40px; max-width: 1440px; margin: 0 auto;
    grid-template-columns: minmax(0, 1fr) 280px;
    grid-template-areas: "stats controls" "chart controls" "lower controls";
    align-items: start;
  }
  html .sv-page .svd-stats { grid-area: stats; }
  html .sv-page .svd-chart { grid-area: chart; }
  html .sv-page .svd-controls { grid-area: controls; position: sticky; top: 0; }
  html .sv-page .svd-lower { grid-area: lower; }
  html .sv-page .svd-card { background: var(--svd-card); border: 1px solid var(--svd-border); border-radius: 6px; box-shadow: none; min-width: 0; }

  /* Headline numbers: one flat row, thin dividers, big number, small label. */
  html .sv-page .svd-stats {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    background: var(--svd-card); border: 1px solid var(--svd-border); border-radius: 6px;
  }
  html .sv-page .svd-stats[data-count="1"] { grid-template-columns: minmax(0, 1fr); }
  html .sv-page .svd-stats[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  html .sv-page .svd-stats[hidden] { display: none; }
  html .sv-page .svd-stat { padding: 14px 20px; min-width: 0; }
  html .sv-page .svd-stat + .svd-stat { border-left: 1px solid var(--svd-rule); }
  html .sv-page .svd-stat p { margin: 0; }
  html .sv-page .svd-stat-label { font-size: 12px; font-weight: 500; color: var(--svd-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  html .sv-page .svd-stat-value {
    display: flex; align-items: center; gap: 4px; margin-top: 4px !important;
    font-size: 24px; font-weight: 600; line-height: 30px; color: var(--svd-text);
    font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden;
  }
  html .sv-page .svd-stat-value span { overflow: hidden; text-overflow: ellipsis; }
  html .sv-page .svd-stat-value svg { width: 18px; height: 18px; flex: none; color: var(--svd-muted); }
  html .sv-page .svd-stat-value.is-up svg { color: var(--svd-blue); }
  html .sv-page .svd-stat-sub { margin-top: 2px !important; font-size: 12px; color: var(--svd-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* The chart, large. */
  html .sv-page .svd-chart { padding: 16px 20px 12px; }
  html .sv-page .svd-plot { position: relative; width: 100%; min-height: 160px; }
  html .sv-page .svd-body.is-table .svd-plot { min-height: 0; }
  html .sv-page .svd-plot .ac-table-scroll { max-height: none; overflow-y: visible; }
  html .sv-page .svd-note { margin: 8px 0 0; font-size: 12px; color: var(--svd-muted); }
  html .sv-page .svd-note[hidden] { display: none; }
  html .sv-page .svd-loading, html .sv-page .svd-empty {
    height: 100%; min-height: 160px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    color: var(--svd-muted); font-size: 13px; text-align: center;
  }
  html .sv-page .svd-empty strong { color: var(--svd-text); font-weight: 600; }

  /* Controls: compact labelled selects and filter chips. */
  html .sv-page .svd-controls { padding: 16px; }
  html .sv-page .svd-panel-title { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--svd-text); }
  html .sv-page .svd-fields { display: grid; gap: 14px; }
  html .sv-page .svd-field { display: grid; gap: 6px; min-width: 0; }
  html .sv-page .svd-field-label { font-size: 12px; font-weight: 500; color: var(--svd-muted); }
  html .sv-page .svd-select { position: relative; display: block; }
  html .sv-page .svd-select select {
    width: 100%; height: 36px; padding: 0 32px 0 10px; appearance: none; -webkit-appearance: none;
    border: 1px solid var(--svd-border); border-radius: 4px; background: var(--svd-card); color: var(--svd-text);
    font-size: 13px; cursor: pointer;
  }
  html .sv-page .svd-select select:focus-visible { outline: 2px solid var(--svd-blue); outline-offset: 1px; }
  html .sv-page .svd-select svg { position: absolute; right: 10px; top: 50%; width: 14px; height: 14px; margin-top: -7px; color: var(--svd-muted); pointer-events: none; }
  html .sv-page .svd-filterlist { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
  html .sv-page .svd-filter { padding: 4px 8px; border: 1px solid var(--svd-border); border-radius: 4px; font-size: 12px; color: var(--svd-text-2); }
  html .sv-page .svd-none { margin: 0; font-size: 13px; color: var(--svd-muted); }

  /* Lower tabs. */
  html .sv-page .svd-tabs { display: flex; gap: 24px; padding: 0 20px; border-bottom: 1px solid var(--svd-border); }
  html .sv-page .svd-tab {
    position: relative; height: 44px; padding: 0; margin-bottom: -1px; border-bottom: 2px solid transparent;
    font-size: 13px; font-weight: 500; color: var(--svd-muted); background: transparent;
  }
  html .sv-page .svd-tab:hover { color: var(--svd-text); }
  html .sv-page .svd-tab[aria-selected="true"] { color: var(--svd-text); border-bottom-color: var(--svd-blue); }
  html .sv-page .svd-tabpanel { padding: 0 0 4px; }
  html .sv-page .svd-hint { margin: 0; padding: 10px 20px 12px; font-size: 12px; color: var(--svd-muted); }

  /* Data table: sticky header in the page scroller, thin row rules. */
  html .sv-page .svd-table-wrap { overflow: visible; }
  html .sv-page .svd-table-wrap.is-wide { overflow-x: auto; }
  html .sv-page .svd-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
  html .sv-page .svd-table th {
    position: sticky; top: 0; z-index: 1; height: 40px; padding: 0 20px; text-align: left; white-space: nowrap;
    font-size: 12px; font-weight: 600; color: var(--svd-text-2); background: var(--svd-card); border-bottom: 1px solid var(--svd-border);
  }
  html .sv-page .svd-table td { height: 40px; padding: 0 20px; border-bottom: 1px solid var(--svd-rule); color: var(--svd-text); white-space: nowrap; }
  html .sv-page .svd-table .is-num { text-align: right; }
  html .sv-page .svd-table tbody tr:hover td { background: var(--svd-hover); }

  /* Query + Details. */
  html .sv-page .svd-dl { margin: 0; padding: 4px 20px 8px; }
  html .sv-page .svd-dl > div { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--svd-rule); }
  html .sv-page .svd-dl > div:last-child { border-bottom: 0; }
  html .sv-page .svd-dl dt { font-size: 12px; font-weight: 500; color: var(--svd-muted); }
  html .sv-page .svd-dl dd { margin: 0; font-size: 13px; color: var(--svd-text); overflow-wrap: anywhere; }
  html .sv-page .svd-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px !important; }
  html .sv-page .svd-raw { margin: 0 20px 16px; border: 1px solid var(--svd-border); border-radius: 4px; }
  html .sv-page .svd-raw > summary { min-height: 40px; display: flex; align-items: center; padding: 0 12px; font-size: 13px; color: var(--svd-text-2); cursor: pointer; }
  html .sv-page .svd-pre { margin: 0; padding: 12px; border-top: 1px solid var(--svd-rule); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--svd-text-2); white-space: pre-wrap; overflow-wrap: anywhere; }
  html .sv-page .svd-details section + section { border-top: 1px solid var(--svd-rule); }
  html .sv-page .svd-h4 { margin: 0; padding: 14px 20px 4px; font-size: 12px; font-weight: 600; color: var(--svd-text-2); }
  html .sv-page .svd-defs { list-style: none; margin: 0; padding: 4px 20px 12px; display: grid; gap: 10px; }
  html .sv-page .svd-defs li { display: grid; gap: 2px; font-size: 13px; }
  html .sv-page .svd-defs strong { font-weight: 600; color: var(--svd-text); }
  html .sv-page .svd-defs span { color: var(--svd-text-2); }

  html .sv-page .svd-toast-host { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 2401; display: grid; gap: 8px; }
  html .sv-page .svd-toast { padding: 10px 14px; border-radius: 6px; background: #1F2328; color: #FFFFFF; font-size: 13px; border: 1px solid #1F2328; max-width: 90vw; overflow-wrap: anywhere; }

  /* Tile titles open the detail view. */
  html .sv-page .sv-card-title[role="button"] { cursor: pointer; }
  html .sv-page .sv-card-title[role="button"]:hover { color: var(--svd-blue, #2196F3); }

  /* Pinned point read-out under the chart. */
  html .sv-page .svd-selection {
    display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 8px 10px; min-height: 40px;
    border: 1px solid var(--svd-border); border-radius: 4px; font-size: 13px; color: var(--svd-text-2);
  }
  html .sv-page .svd-selection[hidden] { display: none; }
  html .sv-page .svd-sel-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; }
  html .sv-page .svd-sel-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  html .sv-page .svd-sel-text strong { color: var(--svd-text); font-weight: 600; }
  html .sv-page .svd-sel-val { color: var(--svd-text); font-variant-numeric: tabular-nums; font-weight: 600; margin-left: 4px; }
  html .sv-page .svd-sel-clear { flex: none; height: 28px; padding: 0 10px; border: 1px solid var(--svd-border); border-radius: 4px; background: transparent; color: var(--svd-text); font-size: 12px; cursor: pointer; }
  html .sv-page .svd-sel-clear:hover { background: var(--svd-hover); }
  html .sv-page .svd-btn[hidden], html .sv-page .svd-menu-item[hidden] { display: none; }
  html .sv-page .svd-datatable { padding: 12px 20px 8px; }

  /* Interactive data table (data-table.js), Preset style. No nested
     scroller: the header sticks to the page scroller, and a table wider than
     its card stacks into labelled rows. Cell bars (off by default) are a
     full-height fill behind the number, never an underline. */
  html .sv-page .svt { position: relative; display: grid; gap: 10px; color: var(--svd-text); font-size: 13px; }
  html .sv-page .svt-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  html .sv-page .svt-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  html .sv-page .svt-search { position: relative; display: flex; align-items: center; flex: 0 1 260px; min-width: 160px; }
  html .sv-page .svt-search svg { position: absolute; left: 10px; width: 15px; height: 15px; color: var(--svd-muted); pointer-events: none; }
  html .sv-page .svt-search input {
    width: 100%; height: 36px; padding: 0 10px 0 32px; border: 1px solid var(--svd-border); border-radius: 4px;
    background: var(--svd-card); color: var(--svd-text); font-size: 13px;
  }
  html .sv-page .svt-search input:focus-visible { outline: 2px solid var(--svd-blue); outline-offset: 1px; border-color: var(--svd-blue); }
  html .sv-page .svt-count { font-size: 12px; color: var(--svd-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
  html .sv-page .svt-spacer { flex: 1 1 auto; }
  html .sv-page .svt-menuwrap { position: relative; }
  html .sv-page .svt-tool {
    display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
    border: 1px solid var(--svd-border); border-radius: 4px; background: var(--svd-card); color: var(--svd-text);
    font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
  }
  html .sv-page .svt-tool svg { width: 15px; height: 15px; color: var(--svd-muted); }
  html .sv-page .svt-tool:hover, html .sv-page .svt-tool[aria-expanded="true"] { background: var(--svd-hover); }
  html .sv-page .svt-sortsel select {
    height: 36px; padding: 0 10px; border: 1px solid var(--svd-border); border-radius: 4px;
    background: var(--svd-card); color: var(--svd-text); font-size: 13px; max-width: 220px;
  }
  html .sv-page .svt-pop {
    position: absolute; top: calc(100% + 4px); right: 0; z-index: 6; min-width: 220px; max-height: 360px; overflow-y: auto;
    padding: 6px; background: var(--svd-card); border: 1px solid var(--svd-border); border-radius: 6px; box-shadow: none;
    display: grid; gap: 2px;
  }
  html .sv-page .svt-pop-title { margin: 6px 8px 4px; font-size: 11px; font-weight: 600; color: var(--svd-muted); letter-spacing: 0.02em; }
  html .sv-page .svt-check { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 8px; border-radius: 4px; cursor: pointer; font-size: 13px; }
  html .sv-page .svt-check:hover { background: var(--svd-hover); }
  html .sv-page .svt-check input { width: 16px; height: 16px; accent-color: var(--svd-blue); margin: 0; }
  html .sv-page .svt-seg { display: grid; grid-template-columns: 1fr 1fr; margin: 0 8px 6px; border: 1px solid var(--svd-border); border-radius: 4px; overflow: hidden; }
  html .sv-page .svt-seg button { height: 32px; border: 0; background: transparent; color: var(--svd-text-2); font-size: 12px; cursor: pointer; }
  html .sv-page .svt-seg button + button { border-left: 1px solid var(--svd-border); }
  html .sv-page .svt-seg button[aria-checked="true"] { color: var(--svd-blue-ink); font-weight: 600; text-decoration: underline 2px var(--svd-blue); text-underline-offset: 6px; }
  html .sv-page .svt-link { justify-self: start; height: 32px; padding: 0 8px; border: 0; background: transparent; color: var(--svd-blue-ink); font-size: 13px; cursor: pointer; }
  html .sv-page .svt-cellmenu { right: auto; width: 220px; }
  html .sv-page .svt-cellmenu .svt-pop-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; color: var(--svd-text-2); letter-spacing: 0; }
  html .sv-page .svt-cellmenu button { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 8px; border: 0; border-radius: 4px; background: transparent; color: var(--svd-text); font-size: 13px; text-align: left; cursor: pointer; }
  html .sv-page .svt-cellmenu button svg { width: 15px; height: 15px; color: var(--svd-muted); }
  html .sv-page .svt-cellmenu button:hover { background: var(--svd-hover); }

  html .sv-page .svt-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; table-layout: auto; }
  html .sv-page .svt-table th {
    position: sticky; top: 0; z-index: 2; height: 40px; padding: 0; text-align: left; white-space: nowrap;
    background: var(--svd-card); border-bottom: 1px solid var(--svd-border);
  }
  html .sv-page .svt-table th button {
    display: flex; align-items: center; gap: 6px; width: 100%; height: 40px; padding: 0 12px; border: 0; background: transparent;
    color: var(--svd-text-2); font-size: 12px; font-weight: 600; cursor: pointer; text-align: left;
  }
  html .sv-page .svt-table th.is-num button { justify-content: flex-end; text-align: right; }
  html .sv-page .svt-table th button:hover { color: var(--svd-text); }
  html .sv-page .svt-th { overflow: hidden; text-overflow: ellipsis; }
  html .sv-page .svt-sort { display: inline-flex; flex: none; color: var(--svd-muted); opacity: 0; }
  html .sv-page .svt-sort svg { width: 13px; height: 13px; }
  html .sv-page .svt-table th button:hover .svt-sort, html .sv-page .svt-table th button:focus-visible .svt-sort { opacity: 1; }
  html .sv-page .svt-sort.is-on { opacity: 1; color: var(--svd-blue); }
  html .sv-page .svt-table td {
    position: relative; height: 40px; padding: 0 12px; border-bottom: 1px solid var(--svd-rule);
    color: var(--svd-text); white-space: nowrap; cursor: default; max-width: 360px; overflow: hidden; text-overflow: ellipsis;
  }
  html .sv-page .svt[data-density="compact"] .svt-table td { height: 32px; }
  html .sv-page .svt[data-density="compact"] .svt-table th, html .sv-page .svt[data-density="compact"] .svt-table th button { height: 34px; }
  html .sv-page .svt-table .is-num, html .sv-page .svt-sgrid .is-num, html .sv-page .svt-idx {
    text-align: right; font-variant-numeric: tabular-nums lining-nums; font-feature-settings: "tnum" 1, "lnum" 1;
  }
  html .sv-page .svt-table .is-null { color: var(--svd-muted); }
  html .sv-page .svt-table tbody tr:hover td { background: var(--svd-hover); }
  html .sv-page .svt-table .svt-idx { width: 44px; padding: 0 12px 0 4px; color: var(--svd-muted); font-size: 12px; }
  html .sv-page .svt-table tfoot td {
    height: 40px; font-weight: 600; color: var(--svd-text); border-top: 1px solid var(--svd-border); border-bottom: 0;
  }
  html .sv-page .svt-total-label { font-weight: 600; color: var(--svd-text); }
  html .sv-page .svt-table td.is-num .svt-total-label { float: left; }
  html .sv-page .svt-v { position: relative; z-index: 1; }
  /* The bar lives in a fixed-width box at the right of the cell, so wide
     columns do not turn into big blocks and every bar in a column shares
     one baseline (the right edge, where the numbers align). */
  html .sv-page .svt-barbox {
    position: absolute; top: 4px; bottom: 4px; right: 4px; width: min(160px, calc(100% - 8px));
    display: flex; justify-content: flex-end; pointer-events: none;
  }
  html .sv-page .svt-bar { height: 100%; background: rgba(33, 150, 243, 0.12); border-radius: 2px; }
  html .sv-page .svt-bar.is-neg { background: rgba(229, 115, 115, 0.16); }
  html[data-app-theme="dark"] .sv-page .svt-bar, html[data-theme="dark"] .sv-page .svt-bar { background: rgba(33, 150, 243, 0.2); }

  html .sv-page .svt-empty { display: grid; justify-items: center; gap: 4px; padding: 36px 12px; text-align: center; color: var(--svd-muted); font-size: 13px; }
  html .sv-page .svt-empty strong { color: var(--svd-text); font-size: 14px; }
  html .sv-page .svt-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; font-size: 12px; color: var(--svd-muted); }
  html .sv-page .svt-size { display: inline-flex; align-items: center; gap: 8px; }
  html .sv-page .svt-selwrap { position: relative; display: inline-flex; }
  html .sv-page .svt-selwrap select {
    height: 32px; padding: 0 28px 0 10px; appearance: none; -webkit-appearance: none; border: 1px solid var(--svd-border); border-radius: 4px;
    background: var(--svd-card); color: var(--svd-text); font-size: 12px; cursor: pointer;
  }
  html .sv-page .svt-selwrap svg { position: absolute; right: 8px; top: 50%; width: 13px; height: 13px; margin-top: -6.5px; color: var(--svd-muted); pointer-events: none; }
  html .sv-page .svt-range { font-variant-numeric: tabular-nums; }
  html .sv-page .svt-pager { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; }
  html .sv-page .svt-pager button {
    min-width: 32px; height: 32px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--svd-border); border-radius: 4px; background: var(--svd-card); color: var(--svd-text); font-size: 12px; cursor: pointer;
    font-variant-numeric: tabular-nums;
  }
  html .sv-page .svt-pager button svg { width: 14px; height: 14px; }
  html .sv-page .svt-pager button:hover:not(:disabled) { background: var(--svd-hover); }
  html .sv-page .svt-pager button:disabled { color: var(--svd-muted); opacity: 0.45; cursor: default; }
  html .sv-page .svt-pager button[aria-current="page"] { border-color: var(--svd-blue); color: var(--svd-blue-ink); font-weight: 600; }
  html .sv-page .svt-gap { padding: 0 2px; }
  html .sv-page .svt-note { margin: 0; font-size: 12px; color: var(--svd-muted); }

  /* Stacked rows: each row a block of label / value pairs, one page scroll. */
  html .sv-page .svt-stack { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--svd-border); }
  html .sv-page .svt-srow, html .sv-page .svt-stotal { padding: 12px 0; border-bottom: 1px solid var(--svd-rule); }
  html .sv-page .svt-stotal { border-bottom: 0; border-top: 1px solid var(--svd-border); margin-top: -1px; }
  html .sv-page .svt-shead { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
  html .sv-page .svt-shead .svt-idx { min-width: 20px; color: var(--svd-muted); font-size: 12px; text-align: left; }
  html .sv-page .svt-slead { font-weight: 600; font-size: 14px; color: var(--svd-text); }
  html .sv-page .svt-sgrid { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 16px; }
  html .sv-page .svt-spair { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 32px; }
  html .sv-page .svt-spair dt { font-size: 12px; color: var(--svd-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  html .sv-page .svt-spair dd { position: relative; margin: 0; padding: 2px 6px; font-size: 14px; color: var(--svd-text); white-space: nowrap; }
  html .sv-page .svt-spair dd .svt-barbox { top: 0; bottom: 0; right: 0; width: 100%; }
  html .sv-page .svt.is-stacked .svt-count { order: 0; }

  /* Tablet: controls drop under the chart as a row of fields. */
  @media (max-width: 1100px) {
    html .sv-page .svd-body { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stats" "chart" "controls" "lower"; }
    html .sv-page .svd-controls { position: static; }
    html .sv-page .svd-fields { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
    html .sv-page .svd-btn:not(.svd-primary):not(.svd-icon-only) span { display: none; }
    html .sv-page .svd-btn:not(.svd-primary):not(.svd-icon-only) { width: 36px; padding: 0; justify-content: center; }
  }

  /* Phone: chart first, then numbers, controls and tabs, in one scroll.
     Actions collapse into one menu; every target is 40px or more. */
  @media (max-width: 820px) {
    html .sv-page .svd-head { padding: 8px 8px 8px 12px; min-height: 60px; gap: 8px; }
    html .sv-page .svd-back { width: 40px; height: 40px; border-color: transparent; }
    html .sv-page .svd-title { font-size: 16px; line-height: 22px; }
    html .sv-page .svd-actions { display: none; }
    html .sv-page .svd-more { display: block; }
    html .sv-page .svd-body { gap: 12px; padding: 12px 12px 32px; grid-template-areas: "chart" "stats" "controls" "lower"; }
    html .sv-page .svd-chart { padding: 12px 12px 8px; }
    html .sv-page .svd-stats { grid-template-columns: minmax(0, 1fr) !important; }
    html .sv-page .svd-stat { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; column-gap: 12px; padding: 12px 14px; }
    html .sv-page .svd-stat + .svd-stat { border-left: 0; border-top: 1px solid var(--svd-rule); }
    html .sv-page .svd-stat-label { grid-column: 1; grid-row: 1; }
    html .sv-page .svd-stat-sub { grid-column: 1; grid-row: 2; }
    html .sv-page .svd-stat-value { grid-column: 2; grid-row: 1 / span 2; margin: 0 !important; font-size: 20px; justify-content: flex-end; max-width: 52vw; }
    html .sv-page .svd-controls { padding: 12px; }
    html .sv-page .svd-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
    html .sv-page .svd-fields > .svd-field:last-child:nth-child(odd) { grid-column: 1 / -1; }
    html .sv-page .svd-select select { height: 44px; font-size: 16px; }
    html .sv-page .svd-tabs { padding: 0 12px; gap: 20px; }
    html .sv-page .svd-tab { height: 48px; font-size: 14px; }
    html .sv-page .svd-hint { padding: 10px 12px 12px; }
    html .sv-page .svd-table th, html .sv-page .svd-table td { padding: 0 12px; height: 44px; }
    html .sv-page .svd-table td { white-space: normal; }
    html .sv-page .svd-dl { padding: 4px 12px 8px; }
    html .sv-page .svd-dl > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
    html .sv-page .svd-raw { margin: 0 12px 12px; }
    html .sv-page .svd-h4 { padding: 12px 12px 4px; }
    html .sv-page .svd-defs { padding: 4px 12px 12px; }
    html .sv-page .svd-datatable { padding: 10px 12px 8px; }
    html .sv-page .svt-search { flex: 1 1 100%; }
    html .sv-page .svt-search input { height: 44px; font-size: 16px; }
    html .sv-page .svt-tool { height: 40px; padding: 0 10px; }
    html .sv-page .svt-tool span { display: none; }
    html .sv-page .svt-tool { width: 40px; justify-content: center; padding: 0; }
    html .sv-page .svt-sortsel select { height: 40px; font-size: 14px; }
    html .sv-page .svt-pager button { min-width: 40px; height: 40px; }
    html .sv-page .svt-selwrap select { height: 40px; font-size: 14px; }
    html .sv-page .svt-toolbar { gap: 8px 6px; }
    html .sv-page .svt-spacer { display: none; }
    html .sv-page .svt-sortsel { flex: 1 1 0; min-width: 0; }
    html .sv-page .svt-sortsel select { width: 100%; max-width: none; }
    html .sv-page .svt-count { order: 10; flex: 1 1 100%; }
    html .sv-page .svt-spair { display: grid; gap: 2px; align-content: start; justify-content: stretch; min-height: 0; padding: 6px 0; }
    html .sv-page .svt-spair dd { justify-self: start; padding: 0; font-size: 15px; font-weight: 500; }
    html .sv-page .svt-sgrid .svt-spair dd, html .sv-page .svt-sgrid .svt-spair dd.is-num { min-width: 96px; text-align: left; }
    html .sv-page .svt-spair dd .svt-barbox { top: -2px; bottom: -2px; left: -4px; right: auto; width: calc(100% + 8px); justify-content: flex-start; }
    html .sv-page .svt-pop { right: 0; max-width: calc(100vw - 32px); }
    html .sv-page .svt-check { min-height: 44px; }
  }
}

@layer screens {
  /* Predictions: flat cards, sidebar surface, accent #2196F3. No stripe, tint, or glow. */
  body.route-predictions .pred-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: none;
  }
  body.route-predictions .pred-card--clickable:hover {
    transform: none;
    box-shadow: none;
    border-color: #2196F3;
  }
  body.route-predictions .pred-badge--paused {
    background: var(--bg-sidebar);
    color: #2196F3;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
  }
  body.route-predictions .pred-quality {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
  }
  body.route-predictions .pred-quality-kicker {
    margin: 0 0 6px;
    color: #2196F3;
    font-size: 12px;
    font-weight: 600;
  }
  body.route-predictions .pred-quality-reason {
    margin: 0;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.45;
  }
  body.route-predictions .pred-freshness {
    margin: 8px 0 0;
    color: var(--text-tertiary);
    font-size: 12px;
  }
}

/* ---- Messages: text templates (copy-only) -------------------------------
   Flat sheet: plain border, no shadow, glow, blur or tint. One scroller
   (.msg-tpl-body); head and foot stay put. Pills are neutral. */
@layer screens {
  .msg-composer-templates {
    flex: 0 0 auto; width: 32px; height: 32px; border: none; border-radius: 50%;
    background: transparent; color: var(--accent); display: inline-flex;
    align-items: center; justify-content: center; padding: 0; margin-bottom: 2px; cursor: pointer;
  }
  .msg-composer-templates:hover { background: var(--bg-hover); }
  .msg-composer-templates:disabled { opacity: 0.35; cursor: default; background: transparent; }
  body.route-messages .msg-composer-templates { width: 40px; height: 44px; min-height: 44px; pointer-events: auto; }

  .msg-tpl-sheet { position: fixed; inset: 0; z-index: calc(var(--z-toast, 800) - 1); display: flex; align-items: center; justify-content: center; }
  .msg-tpl-sheet[hidden] { display: none !important; }
  .msg-tpl-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.32); }
  .msg-tpl-panel {
    position: relative; display: flex; flex-direction: column; overflow: hidden;
    width: min(560px, calc(100vw - 32px)); max-height: min(720px, calc(100dvh - 64px));
    background: var(--bg-card); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: var(--r-lg, 12px); box-shadow: none;
  }
  .msg-tpl-head {
    flex: 0 0 auto; display: flex; align-items: center; gap: var(--sp-2, 8px);
    min-height: 52px; padding: 0 var(--sp-3, 12px) 0 var(--sp-4, 16px); border-bottom: 1px solid var(--border);
  }
  .msg-tpl-title { flex: 1 1 auto; min-width: 0; font-size: var(--t-16, 16px); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .msg-tpl-back, .msg-tpl-close {
    flex: 0 0 auto; width: 36px; height: 36px; border: none; border-radius: 50%; background: transparent;
    color: var(--text-secondary); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
  }
  .msg-tpl-back { margin-left: calc(-1 * var(--sp-2, 8px)); color: var(--accent); }
  .msg-tpl-back[hidden] { display: none; }
  .msg-tpl-back:hover, .msg-tpl-close:hover { background: var(--bg-hover); }
  .msg-tpl-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: var(--sp-3, 12px) var(--sp-4, 16px) var(--sp-4, 16px); }
  .msg-tpl-search-wrap { position: relative; display: flex; align-items: center; }
  .msg-tpl-search-icon { position: absolute; left: 12px; color: var(--text-tertiary); pointer-events: none; }
  .msg-tpl-search {
    width: 100%; box-sizing: border-box; min-height: 40px; padding: 8px 12px 8px 36px;
    border: 1px solid var(--border); border-radius: var(--r-md, 8px); background: var(--bg-elev);
    color: var(--text-primary); font-size: var(--t-15, 15px); outline: none;
  }
  .msg-tpl-search:focus { border-color: var(--accent); }
  .msg-tpl-hint { margin: 8px 0 4px; font-size: var(--t-12, 12px); color: var(--text-tertiary); }
  .msg-tpl-group { margin-top: var(--sp-3, 12px); }
  .msg-tpl-group-title {
    margin: 0 0 4px; font-size: var(--t-12, 12px); font-weight: 600; letter-spacing: 0.02em;
    text-transform: uppercase; color: var(--text-secondary);
  }
  .msg-tpl-count { font-weight: 500; color: var(--text-tertiary); }
  .msg-tpl-row {
    display: flex; flex-direction: column; align-items: stretch; gap: 2px; width: 100%;
    padding: 10px 0; border: none; border-bottom: 1px solid var(--border); background: transparent;
    color: var(--text-primary); text-align: left; cursor: pointer; font: inherit;
  }
  .msg-tpl-row:hover .msg-tpl-row-name { color: var(--accent-text, var(--accent)); }
  .msg-tpl-row-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .msg-tpl-row-name { font-size: var(--t-14, 14px); font-weight: 500; }
  .msg-tpl-row-sub { font-size: var(--t-12, 12px); color: var(--text-tertiary); }
  .msg-tpl-pill {
    display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: var(--r-pill, 999px);
    border: 1px solid var(--border); background: transparent; color: var(--text-secondary);
    font-size: var(--t-11, 11px); font-weight: 500; white-space: nowrap;
  }
  .msg-tpl-empty { padding: 24px 0; text-align: center; font-size: var(--t-13, 13px); color: var(--text-tertiary); }
  .msg-tpl-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: var(--sp-3, 12px); }
  .msg-tpl-trigger { font-size: var(--t-13, 13px); color: var(--text-secondary); }
  .msg-tpl-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-bottom: var(--sp-3, 12px); }
  .msg-tpl-field { display: flex; flex-direction: column; gap: 4px; }
  .msg-tpl-field-label { font-size: var(--t-12, 12px); font-weight: 500; color: var(--text-secondary); }
  .msg-tpl-optional { font-weight: 400; color: var(--text-tertiary); }
  .msg-tpl-input {
    min-height: 38px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--r-md, 8px);
    background: var(--bg-elev); color: var(--text-primary); font-size: var(--t-15, 15px); outline: none;
  }
  .msg-tpl-input:focus { border-color: var(--accent); }
  .msg-tpl-preview-label { font-size: var(--t-12, 12px); font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
  .msg-tpl-preview {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-md, 8px); background: transparent;
    white-space: pre-wrap; font-size: var(--t-14, 14px); line-height: 1.45; color: var(--text-primary);
  }
  .msg-tpl-fill { background: transparent; color: inherit; font-weight: 600; text-decoration: underline; text-decoration-color: var(--text-tertiary); text-underline-offset: 3px; }
  .msg-tpl-fill.is-empty { font-weight: 500; color: var(--text-tertiary); text-decoration-style: dashed; }
  .msg-tpl-notes { margin: 10px 0 0; font-size: var(--t-12, 12px); line-height: 1.4; color: var(--text-tertiary); }
  .msg-tpl-foot {
    flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 10px var(--sp-4, 16px);
    border-top: 1px solid var(--border); background: var(--bg-card);
  }
  .msg-tpl-foot[hidden] { display: none; }
  .msg-tpl-foot-msg { flex: 1 1 auto; min-width: 0; font-size: var(--t-12, 12px); color: var(--text-tertiary); }
  .msg-tpl-btn {
    flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px;
    border: 1px solid var(--border); border-radius: var(--r-md, 8px); background: transparent;
    color: var(--text-primary); font-size: var(--t-14, 14px); font-weight: 500; cursor: pointer;
  }
  .msg-tpl-btn:hover { background: var(--bg-hover); }
  .msg-tpl-btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
  .msg-tpl-btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
  .msg-tpl-btn:disabled { opacity: 0.45; cursor: default; filter: none; }

  @media (max-width: 640px) {
    .msg-tpl-sheet { align-items: flex-end; }
    .msg-tpl-panel {
      width: 100%; max-height: 88dvh; border-radius: var(--r-lg, 12px) var(--r-lg, 12px) 0 0;
      border-left: none; border-right: none; border-bottom: none;
    }
    .msg-tpl-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
    .msg-tpl-fields { grid-template-columns: 1fr; }
  }
}

/* SuperViz calm dashboard (v2): at most three tiles per row, equal rows,
   one-line subtitles, chart chrome revealed on hover. Only applies to a
   grid the page curated; a grid arranged with Edit layout, or one being
   edited, keeps its own 12-column spans. */
@layer screens {
  html .sv-page .sv-grid[data-sv-curated]:not(.de-editing) {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-auto-flow: row; align-items: stretch; gap: 16px;
  }
  html .sv-page .sv-grid[data-sv-curated]:not(.de-editing) > .sv-card { grid-column: span 2; }
  html .sv-page .sv-grid[data-sv-curated]:not(.de-editing) > .sv-card[data-kind="wide"] { grid-column: 1 / -1; }
  html .sv-page .sv-grid[data-sv-curated][data-kpis="1"]:not(.de-editing) > .sv-card[data-kind="kpi"]:not([data-sv-more]) { grid-column: 1 / -1; }
  html .sv-page .sv-grid[data-sv-curated][data-kpis="2"]:not(.de-editing) > .sv-card[data-kind="kpi"]:not([data-sv-more]) { grid-column: span 3; }

  /* Equal rows: every chart body is the same height; numbers are short. */
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="chart"] .sv-card-body { height: 252px; min-height: 0; flex: none; }
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="chart"] .sv-plot { height: 100%; min-height: 0; }
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .sv-card-body { height: 132px; min-height: 0; flex: none; }
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .sv-plot { height: 100%; min-height: 0; }
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .ac-kpi { padding: 0 4px; justify-content: flex-start; }
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .ac-kpi-value { margin-top: 0; font-size: 28px; line-height: 34px; }
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .ac-kpi .ac-spark { max-height: 44px; min-height: 28px; }
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .ac-kpi-context { display: none; }
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="wide"] .sv-card-body { max-height: 420px; min-height: 0; overflow: auto; }

  /* Title plus one muted line, never more. */
  html .sv-page .sv-card-head .sv-card-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  html .sv-page .sv-card-sub {
    margin: -2px 0 0; padding: 0 16px; font-size: 12px; line-height: 16px; color: var(--svx-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  html .sv-page .sv-card-sub[hidden] { display: none; }

  /* Secondary actions wait for the pointer; touch screens always show the
     menu button so the actions stay reachable. */
  @media (hover: hover) {
    html .sv-page .sv-card .sv-card-actions { opacity: 0; transition: opacity 120ms ease; }
    html .sv-page .sv-card:hover .sv-card-actions,
    html .sv-page .sv-card:focus-within .sv-card-actions,
    html .sv-page .sv-card .sv-card-actions[open] { opacity: 1; }
  }

  /* The rest of the catalog waits behind "Show more charts"; a search or
     filter reaches it directly. */
  html .sv-page .sv-section:not(.sv-show-more) .sv-card[data-sv-more] { display: none; }
  html .sv-page.sv-filtering .sv-section .sv-card[data-sv-more]:not([hidden]) { display: flex; }
  html .sv-page.sv-filtering .sv-more { display: none; }
  html .sv-page .sv-more { display: flex; justify-content: center; margin-top: 16px; }
  html .sv-page .sv-more-btn {
    height: 32px; padding: 0 14px; border: 1px solid var(--svx-border); border-radius: 4px;
    background: transparent; color: var(--text-secondary); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  }
  html .sv-page .sv-more-btn:hover { background: var(--bg-hover); color: var(--svx-text); }

  @media (max-width: 1100px) {
    html .sv-page .sv-grid[data-sv-curated]:not(.de-editing) > .sv-card { grid-column: span 3; }
    html .sv-page .sv-grid[data-sv-curated]:not(.de-editing) > .sv-card[data-kind="wide"] { grid-column: 1 / -1; }
    html .sv-page .sv-grid[data-sv-curated][data-kpis="1"]:not(.de-editing) > .sv-card[data-kind="kpi"]:not([data-sv-more]) { grid-column: 1 / -1; }
    html .sv-page .sv-grid[data-sv-curated][data-kpis="3"]:not(.de-editing) > .sv-card[data-kind="kpi"]:not([data-sv-more]) { grid-column: span 2; }
  }
  @media (max-width: 820px) {
    html .sv-page .sv-grid[data-sv-curated]:not(.de-editing) { gap: 12px; }
    html .sv-page .sv-grid[data-sv-curated]:not(.de-editing) > .sv-card,
    html .sv-page .sv-grid[data-sv-curated]:not(.de-editing) > .sv-card[data-kind="kpi"]:not([data-sv-more]) { grid-column: 1 / -1; }
    /* Two or three numbers share one compact strip. */
    html .sv-page .sv-grid[data-sv-curated][data-kpis="2"]:not(.de-editing) > .sv-card[data-kind="kpi"]:not([data-sv-more]) { grid-column: span 3; }
    html .sv-page .sv-grid[data-sv-curated][data-kpis="3"]:not(.de-editing) > .sv-card[data-kind="kpi"]:not([data-sv-more]) { grid-column: span 2; }
    html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="chart"] .sv-card-body { height: 224px; }
    html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .sv-card-body { height: 84px; }
    html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .ac-kpi .ac-spark { display: none; }
    html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .sv-card-title {
      white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 13px; line-height: 18px;
    }
    html .sv-page .sv-card-sub { margin-top: -6px; }
    html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .ac-kpi-value { font-size: 22px; line-height: 28px; }
    html .sv-page .sv-card-sub { padding: 0 12px; }
  }
}
@layer screens {
  /* The tile title already names the number. */
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .ac-kpi-label { display: none; }
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .ac-kpi-period,
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .ac-kpi-comparison {
    font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  html .sv-page .sv-grid[data-sv-curated] > .sv-card[data-kind="kpi"] .ac-kpi-period { display: none; }
}

@layer screens {
  /* Attachment thumbnails. Flat: 1px border, radius 10 on the square and 6
     on the filename label. */
  .ty-attach-thumb,
  .ty-bubble-photo {
    position: relative;
    display: block;
    flex: 0 0 auto;
    width: 96px;
    height: 96px;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    border: 1px solid #2F3232;
    border-radius: 10px;
    background: #252727;
    background-image: none;
    box-shadow: none;
    overflow: hidden;
    color: #ECEDEC;
    font-family: "Satoshi", system-ui, sans-serif;
  }

  .ty-bubble-photo {
    width: 168px;
    height: 168px;
    cursor: pointer;
  }

  .ty-attach-thumb img,
  .ty-bubble-photo img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    object-fit: cover;
    border: 0;
    border-radius: 0;
    background: #252727;
    box-shadow: none;
  }

  .ty-attach-name {
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: 6px;
    max-width: calc(100% - 12px);
    margin: 0;
    padding: 2px 6px;
    box-sizing: border-box;
    border: 1px solid #2F3232;
    border-radius: 6px;
    background: #1F2121;
    background-image: none;
    box-shadow: none;
    color: #A6ABAB;
    font-family: "Satoshi", system-ui, sans-serif;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.3;
    letter-spacing: 0;
    text-transform: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
  }

  .ty-attach-x {
    position: absolute;
    top: 4px;
    right: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin: 0;
    padding: 0;
    border: 1px solid #2F3232;
    border-radius: 6px;
    background: #1F2121;
    background-image: none;
    box-shadow: none;
    color: #ECEDEC;
    cursor: pointer;
    line-height: 1;
  }

  .ty-attach-x:hover {
    background: #252727;
    color: #ECEDEC;
  }

  .ty-attach-file {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: min(220px, 100%);
    height: 28px;
    margin: 0;
    padding: 0 28px 0 8px;
    box-sizing: border-box;
    border: 1px solid #2F3232;
    border-radius: 6px;
    background: #252727;
    background-image: none;
    box-shadow: none;
    color: #A6ABAB;
    font-family: "Satoshi", system-ui, sans-serif;
    font-size: 12px;
    font-weight: 500;
    line-height: 28px;
  }

  .ty-bubble-media .ty-attach-file {
    padding-right: 8px;
  }

  .ty-attach-file .ty-attach-x {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 22px;
    height: 22px;
  }

  .ty-attach-file-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #A6ABAB;
    text-transform: none;
    letter-spacing: 0;
  }

  .ty-bubble-media,
  .rc-attachments,
  .msg-composer-attach-list {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .msg-composer-attach-list {
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }

  .ty-photo-lightbox {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
    background: #171818;
    background-image: none;
    box-shadow: none;
  }

  .ty-photo-lightbox[hidden] {
    display: none;
  }

  .ty-photo-lightbox-img {
    display: block;
    max-width: min(960px, calc(100vw - 32px));
    max-height: calc(100vh - 96px);
    width: auto;
    height: auto;
    object-fit: contain;
    border: 1px solid #2F3232;
    border-radius: 10px;
    background: #1F2121;
    box-shadow: none;
  }

  .ty-photo-lightbox-x {
    position: absolute;
    top: max(12px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid #2F3232;
    border-radius: 6px;
    background: #1F2121;
    background-image: none;
    box-shadow: none;
    color: #ECEDEC;
    cursor: pointer;
  }

  @media (max-width: 820px) {
    .ty-attach-thumb {
      width: 84px;
      height: 84px;
    }
    .ty-bubble-photo {
      width: 140px;
      height: 140px;
    }
  }
}
