/* Layout review. @layer screens beats legacy sheets, including mobile-os.css.
   Linked before mobile-os.css so that file stays the last stylesheet.
   Accent #2196F3. Flat cards: plain border, no stripe, tint, glow, or blur.
   The history list is the only place with a short bottom fade. */
@layer screens {
/* ── 1. Toasts: top end, clear of the composer and the lower cards ── */
#toast-container.toast-container,
.toast-container {
  top: 16px;
  right: 16px;
  bottom: auto;
  left: auto;
  transform: none;
  align-items: flex-end;
  width: max-content;
  max-width: min(380px, calc(100vw - 32px));
}

.toast.toast-error {
  background: var(--bg-card, #fff);
  color: var(--fg-primary, #1a1c1e);
  border: 1px solid var(--border-strong, rgba(0, 0, 0, 0.18));
  box-shadow: none;
}

.toast.toast-error::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--danger, #dc2626);
  vertical-align: middle;
}

@media (max-width: 820px) {
  #toast-container.toast-container,
  .toast-container {
    top: calc(env(safe-area-inset-top, 0px) + 64px);
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    align-items: stretch;
  }
}

/* ── 2. SuperViz: one column when narrow, readable errors, scrolling tabs ── */
html body .sv-error strong {
  color: var(--sv-title, var(--fg-primary, #1a1c1e));
}

html body .sv-error span,
html body .sv-empty span {
  max-width: 36ch;
  color: var(--fg-secondary, var(--sv-muted, #3c4043));
  overflow-wrap: anywhere;
}

html body .sv-error .sv-refresh-cta,
html body .sv-page .sv-refresh-cta,
html body .sv-refresh-cta {
  color: #2196F3;
  border-color: #2196F3;
  background: transparent;
}

html body .sv-error .sv-refresh-cta:hover,
html body .sv-refresh-cta:hover {
  background: rgba(33, 150, 243, 0.1);
  color: #1976D2;
}

/* mobile-os sets overflow:hidden !important on every chart body. Error
   copy and the Refresh button were clipped inside a half-width tile. */
html body .sv-page .sv-card-body:has(.sv-error),
html body .sv-card-body:has(.sv-error) {
  overflow: visible !important;
  min-height: 0 !important;
  height: auto !important;
}

html body .sv-error,
html body .sv-empty {
  height: auto;
  min-height: 140px;
  overflow: visible;
  padding: 16px 12px;
}

@media (max-width: 820px) {
  html body .sv-page .sv-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  html body .sv-page .sv-card,
  html body .sv-page .sv-card[data-span="4"],
  html body .sv-page .sv-card[data-span="6"],
  html body .sv-page .sv-card[data-span="8"],
  html body .sv-page .sv-card[data-span="12"] {
    grid-column: 1 / -1;
    min-width: 0;
  }

  html body .sv-page .sv-card-body {
    overflow: visible;
    min-height: 160px;
  }

  html body .sv-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
  }

  html body .sv-tabs::-webkit-scrollbar { display: none; }

  html body .sv-tab {
    flex: 0 0 auto;
  }

  html body .sv-error span {
    max-width: 100%;
  }
}

/* ── 3. Predictions: neutral unavailable, readable empty, filled last row ── */
html body .pred-badge--warm,
html body .pred-badge--fallback {
  background: transparent;
  color: var(--fg-secondary, #3c4043);
  border: 1px solid var(--border-strong, rgba(0, 0, 0, 0.18));
}

html body .pred-empty,
html body .pred-empty--muted {
  color: var(--fg-secondary, #3c4043);
}

html[data-app-theme="light"] body .pred-card,
html[data-app-theme="og"] body .pred-card {
  background: var(--bg-card, #fff);
  border: 1px solid var(--border-card, rgba(0, 0, 0, 0.08));
  box-shadow: none;
}

html[data-app-theme="light"] body .pred-card-title h2,
html[data-app-theme="og"] body .pred-card-title h2,
html[data-app-theme="light"] body .pred-section-title,
html[data-app-theme="og"] body .pred-section-title {
  color: var(--fg-primary, #1a1c1e);
}

html[data-app-theme="light"] body .pred-card-sub,
html[data-app-theme="og"] body .pred-card-sub,
html[data-app-theme="light"] body .pred-section-blurb,
html[data-app-theme="og"] body .pred-section-blurb {
  color: var(--fg-secondary, #3c4043);
}

@media (min-width: 1080px) {
  /* First Sales card already spans the row, so an even count leaves an
     orphan. Other sections orphan on an odd count. Fill that row. */
  html body .pred-grid > .pred-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  html body .pred-section[data-section="sales"] .pred-grid > .pred-card:last-child:nth-child(even) {
    grid-column: 1 / -1;
  }
}

/* ── 4. Divisions: same left edge as the rest of the content column ──
   A later rule set the grid to minmax(220px, max-content) and
   justify-content: center, so the five chips sat as a small cluster. */
html:not(#__nope__) body .gl-divisions-view,
html body .gl-divisions-view.gl-divisions-view--centered {
  max-width: none;
  margin: 0;
  padding: 8px 0 48px;
  text-align: left;
  min-height: 0;
}

html:not(#__nope__) body .gl-divisions-view .gl-divisions-grid,
html body .gl-divisions-grid.gl-divisions-grid--row5 {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  justify-content: stretch;
  justify-items: stretch;
  align-items: stretch;
  width: 100%;
  max-width: none;
  margin: 0;
}

@media (min-width: 1100px) {
  html body .gl-divisions-grid.gl-divisions-grid--row5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

html[data-app-theme="light"] body:not(.route-divisions) .gl-division-card,
html[data-app-theme="og"] body:not(.route-divisions) .gl-division-card {
  background: var(--bg-card, #fff) !important;
  border: 1px solid var(--border-card, rgba(0, 0, 0, 0.08)) !important;
  color: var(--fg-primary, #1a1c1e) !important;
  box-shadow: none !important;
}

html[data-app-theme="light"] body:not(.route-divisions) .gl-division-card .gdc-title,
html[data-app-theme="og"] body:not(.route-divisions) .gl-division-card .gdc-title {
  color: var(--fg-primary, #1a1c1e) !important;
}

html[data-app-theme="light"] body:not(.route-divisions) .gl-division-card .gdc-icon,
html[data-app-theme="og"] body:not(.route-divisions) .gl-division-card .gdc-icon {
  background: rgba(33, 150, 243, 0.1) !important;
  color: #2196F3 !important;
  border-color: transparent !important;
}

/* ── 5. Customers empty state. Table chrome moved to customers-refine.css
      (the light/og !important fills here overrode the list). ── */

html body.route-customers .cust-view {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 96px);
  box-sizing: border-box;
}

html body.route-customers .cust-list {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

html body.route-customers .cust-empty {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  margin: 0;
  padding: 32px 20px;
  text-align: center;
  color: var(--fg-secondary, #3c4043);
  background: transparent;
  border: 1px solid var(--border-card, rgba(0, 0, 0, 0.08));
  border-radius: 10px;
}

/* Phone column squeeze removed: customers-refine.css shows name, status, LTV. */

/* ── 6. My Hood: land color under missing tiles, readable scale, no extra scroll ── */
html body.route-hood,
html body.route-hood .main,
html body.route-hood .main-content,
html body.route-hood main#main-content {
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}

html body.route-hood .hood-page,
body.route-hood .hood-page,
body:not(.sidebar-collapsed) .hood-page {
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
}

html body .hood-map-wrap .mapboxgl-map,
html body .hood-map-wrap .mapboxgl-canvas-container {
  background-color: #1c1e22;
}

html[data-app-theme="light"] body .hood-map-wrap .mapboxgl-map,
html[data-app-theme="light"] body .hood-map-wrap .mapboxgl-canvas-container,
html[data-app-theme="og"] body .hood-map-wrap .mapboxgl-map,
html[data-app-theme="og"] body .hood-map-wrap .mapboxgl-canvas-container {
  background-color: #e7e5e1;
}

html body .hood-map-wrap .mapboxgl-ctrl-scale {
  opacity: 1;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 600;
  background-color: #fff;
  color: #1a1c1e;
  border: 2px solid #1a1c1e;
  border-top: none;
  padding: 1px 6px 2px;
}

/* ── 7. Ask on a short phone window: composer and chips clear the edge ── */
@media (max-width: 820px) {
  html body.route-ask,
  html body.route-ask section#main.main,
  html body.route-ask:not(.ai-has-messages) section#main.main,
  html body.route-ask:not(.ai-has-messages) .ai-view,
  html body.route-ask .ai-view {
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    overflow: hidden;
    box-sizing: border-box;
  }

  html body.route-ask section#main.main .ai-view .ai-composer-wrap,
  html body.route-ask section#main .ai-composer-wrap,
  html body.route-ask .ai-view .ai-composer-wrap,
  html body.route-ask .ai-composer-wrap {
    position: fixed;
    left: 0;
    right: 0;
    width: auto;
    bottom: max(12px, env(safe-area-inset-bottom, 0px)) !important;
    padding-bottom: 0 !important;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    box-sizing: border-box;
  }

  html body.route-ask .ai-messages,
  html body.route-ask:not(.ai-has-messages) .ai-view .ai-messages {
    padding-bottom: calc(max(16px, env(safe-area-inset-bottom, 0px)) + 132px);
    box-sizing: border-box;
  }

  html body.route-ask .working-memory-chips,
  html body.route-ask .chat-suggest-row,
  html body.route-ask .nx-followups {
    max-width: 100%;
  }
}

/* ── 8. Messages: skeleton while threads load, empty state fills the pane ── */
html body .msg-threads-list,
html body .msg-right-pane,
html body .msg-thread-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}

html body .msg-empty,
html body .msg-empty-large,
html body .msg-empty-error,
html body .msg-empty-campaign {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 160px;
  margin: 0;
  padding: 28px 16px;
  text-align: center;
  /* The messages surface is forced to #000. Keep light ink so a light
     app theme does not paint dark type on that black pane. */
  color: rgba(235, 235, 245, 0.82);
}

html body .msg-empty-large .msg-empty-title,
html body .msg-empty-title {
  color: rgba(245, 245, 247, 0.94);
}

html body .msg-empty-large .msg-empty-sub,
html body .msg-empty-sub,
html body .msg-empty-copy,
html body .msg-empty-hint {
  color: rgba(235, 235, 245, 0.78);
}

html body .msg-retry-btn {
  background: #2196F3;
  color: #fff;
  border: 0;
  border-radius: 8px;
  box-shadow: none;
}

html body .msg-skel {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 4px 0 12px;
}

html body .msg-skel-row {
  display: block;
  height: 56px;
  margin: 0 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
}

html body .msg-skel-row::before,
html body .msg-skel-row::after {
  content: "";
  position: absolute;
  left: 0;
  height: 10px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
}

html body .msg-skel-row::before {
  top: 14px;
  width: 42%;
}

html body .msg-skel-row::after {
  top: 32px;
  width: 68%;
  opacity: 0.7;
}

/* ── 9. History title: no second box inside the row hover ── */
html[data-app-theme="dark"] aside.sidebar#sidebar #sidebar-history-list .history-item:hover .history-title,
html[data-app-theme="dark"] aside.sidebar#sidebar #sidebar-history-list .history-item:focus-within .history-title,
html[data-app-theme="dark"] aside.sidebar#sidebar #sidebar-history-list .history-item.active .history-title,
html body aside.sidebar#sidebar #sidebar-history-list .history-item:hover .history-title,
html body aside.sidebar#sidebar #sidebar-history-list .history-item:hover .history-title-row,
html body aside.sidebar#sidebar #sidebar-history-list .history-item.active .history-title {
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  box-shadow: none !important;
}

/* ── 10. Project name tooltip sits to the right of the sidebar ── */
html body aside.sidebar#sidebar .sidebar-project-item[data-sidebar-tip]::after {
  content: none !important;
  display: none !important;
}
.sidebar-project-tip {
  position: fixed;
  z-index: 10050;
  display: none;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #1F2121;
  color: #E3E1DD;
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
}
.sidebar-project-tip.is-open { display: block; }
html[data-app-theme="light"] .sidebar-project-tip,
html[data-app-theme="og"] .sidebar-project-tip {
  background: #fff;
  color: #1A1C1E;
  border-color: rgba(0, 0, 0, 0.14);
}

/* ── 11. View all chats: flat row hover, #2196F3 label, no navy fill ── */
html body aside.sidebar#sidebar a.sidebar-history-viewall {
  display: block;
  box-sizing: border-box;
  width: calc(100% - 8px);
  margin: 4px 4px 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: transparent !important;
  background-color: transparent !important;
  color: var(--fg-muted, #8A8F9C);
  text-align: left;
  box-shadow: none !important;
}
html body aside.sidebar#sidebar a.sidebar-history-viewall:hover,
html body aside.sidebar#sidebar a.sidebar-history-viewall:focus-visible {
  color: #2196F3 !important;
  background: rgba(255, 255, 255, 0.07) !important;
  background-color: rgba(255, 255, 255, 0.07) !important;
  border-radius: 12px !important;
  box-shadow: none !important;
}
html[data-app-theme="light"] body aside.sidebar#sidebar a.sidebar-history-viewall:hover,
html[data-app-theme="light"] body aside.sidebar#sidebar a.sidebar-history-viewall:focus-visible,
html[data-app-theme="og"] body aside.sidebar#sidebar a.sidebar-history-viewall:hover,
html[data-app-theme="og"] body aside.sidebar#sidebar a.sidebar-history-viewall:focus-visible {
  color: #2196F3 !important;
  background: rgba(26, 28, 30, 0.06) !important;
  background-color: rgba(26, 28, 30, 0.06) !important;
}

/* ── 12. Only the history scroller fades its last 24px ── */
html body aside.sidebar#sidebar .sidebar-history .section-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
html body aside.sidebar#sidebar #sidebar-history-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 24px), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 24px), transparent 100%);
}

/* ── 13. Messages thread list, tabs, and composer.
   Visual rules moved to css/surfaces/messages-refine.css (unlayered, route-scoped).
   The !important versions here sat in @layer screens and beat that sheet. */

/* Shared dark surfaces: cards, search, chips, side panel. Flat, one border.
   Chat history rows and search are not in this list: that page draws one
   outer border in css/surfaces/chat-history-refine.css. .sv-card moved to
   css/surfaces/superviz-refine.css. Leaving either here would force a card
   border with !important that an unlayered sheet cannot beat.
   Predictions cards are the same case on that route only
   (css/surfaces/predictions-refine.css). Other pages keep this card. */
html[data-app-theme="dark"] body .floating-chat-panel,
html[data-app-theme="dark"] body:not(.route-predictions) .pred-card,
/* Division routes style .gl-division-card in divisions-refine.css.
   This !important border cannot be beaten from an unlayered sheet, so
   route-divisions is left out of the selector. */
html[data-app-theme="dark"] body:not(.route-divisions) .gl-division-card {
  background: var(--bg-card, #1F2121) !important;
  background-image: none !important;
  border: 1px solid var(--border-card, rgba(255, 255, 255, 0.08)) !important;
  border-radius: 12px !important;
  box-shadow: none !important;
  transition: border-color 140ms ease, background 140ms ease;
}
/* Ask suggestion rows are ask-refine.css. Predictions math links on that
   route are predictions-refine.css. An unlayered sheet cannot beat this
   !important, so those routes are left out. Other pages keep the pill. */
html[data-app-theme="dark"] body:not(.route-ask) .chat-suggest-chip,
html[data-app-theme="dark"] body:not(.route-ask) .nx-followup-chip,
html[data-app-theme="dark"] body:not(.route-predictions) .pred-math-link {
  background: transparent !important;
  border: 1px solid var(--border-strong, rgba(255, 255, 255, 0.14)) !important;
  color: var(--fg-primary, #E3E1DD) !important;
  box-shadow: none !important;
  border-radius: 999px !important;
}
html[data-app-theme="dark"] body:not(.route-ask) .chat-suggest-chip:hover,
html[data-app-theme="dark"] body:not(.route-ask) .nx-followup-chip:hover,
html[data-app-theme="dark"] body:not(.route-predictions) .pred-math-link:hover {
  border-color: #2196F3 !important;
  color: #2196F3 !important;
  background: transparent !important;
  transform: none !important;
}

/* Messages thread links are styled in messages-refine.css.
   FieldRoutes sheet action stays a flat accent. */
html body .hood-action-btn--fr {
  color: #2196F3 !important;
  background: transparent !important;
  border: 1px solid rgba(33, 150, 243, 0.45) !important;
  box-shadow: none !important;
  text-decoration: none !important;
  border-radius: 8px !important;
}
html body .hood-action-btn--fr:hover {
  color: #2196F3 !important;
  background: transparent !important;
  border-color: #2196F3 !important;
}


/* Session bar. Messages tabs are plain text in messages-refine.css.
   Ask tabs are plain text in ask-refine.css. This !important card does
   not include either route: an unlayered sheet cannot beat it.
   Phone Messages keeps the settings-gear sheet from mobile-os.css. */
@media (min-width: 821px) {
  html body.ty-has-agent-tabs:not(.route-ask) header.topbar#topbar,
  html body.ty-has-agent-tabs:not(.route-ask) header.topbar.topbar--no-header {
    padding: 8px 16px !important;
    background: var(--bg-app, #191A1A) !important;
    background-color: var(--bg-app, #191A1A) !important;
    border-bottom: 0 !important;
    box-sizing: border-box !important;
  }
  html body.ty-has-agent-tabs:not(.route-ask) header.topbar #ty-agent-tabs.ty-agent-tabs {
    box-sizing: border-box !important;
    width: auto !important;
    max-width: 100% !important;
    flex: 1 1 auto !important;
    margin: 8px 16px !important;
    min-height: 48px !important;
    padding: 6px 8px !important;
    align-items: center !important;
    gap: 8px !important;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08)) !important;
    border-radius: 12px !important;
    background: var(--bg-card, #1F2121) !important;
    background-color: var(--bg-card, #1F2121) !important;
    background-image: none !important;
    box-shadow: none !important;
    overflow: hidden !important;
  }
  html body.ty-has-agent-tabs header.topbar #ty-agent-tabs.ty-agent-tabs {
    margin: 0 !important;
  }
  html body:not(.route-ask) .ty-agent-tabs .ty-tab:not(.msg-tab) {
    max-width: none !important;
    height: 32px !important;
    padding: 0 12px !important;
    border-radius: 999px !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    overflow: visible !important;
    text-overflow: unset !important;
    background: transparent !important;
    color: var(--text-tertiary, #8A8F9C) !important;
  }
  html body:not(.route-ask) .ty-agent-tabs .ty-tab:not(.msg-tab):hover {
    background: transparent !important;
    color: var(--text-secondary, #B5B7BE) !important;
  }
  html body:not(.route-ask) .ty-agent-tabs .ty-tab:not(.msg-tab).is-active {
    background: rgba(255, 255, 255, 0.07) !important;
    color: var(--text-primary, #E3E1DD) !important;
    font-weight: 500 !important;
  }
  html body:not(.route-ask) .ty-agent-tabs .ty-tab:not(.msg-tab) .ty-tab-label {
    max-width: none !important;
    overflow: visible !important;
    text-overflow: unset !important;
    white-space: nowrap !important;
  }
}
}
