/* SOLVAIRA_UI_CLEANUP_R1
   Responsive app-wide polish. UI-only. No worker/data logic. */

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body.sva-ui-cleanup-r1,
body.sva-ui-cleanup-r1 * {
  box-sizing: border-box;
}

body.sva-ui-cleanup-r1 .main-content,
body.sva-ui-cleanup-r1 main,
body.sva-ui-cleanup-r1 .container,
body.sva-ui-cleanup-r1 .container-fluid {
  min-width: 0 !important;
  max-width: 100% !important;
}

body.sva-ui-cleanup-r1 img,
body.sva-ui-cleanup-r1 video,
body.sva-ui-cleanup-r1 canvas,
body.sva-ui-cleanup-r1 svg {
  max-width: 100%;
}

body.sva-ui-cleanup-r1 table {
  width: 100%;
}

body.sva-ui-cleanup-r1 .table-responsive {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

body.sva-ui-cleanup-r1 .card,
body.sva-ui-cleanup-r1 .panel,
body.sva-ui-cleanup-r1 .sva-card,
body.sva-ui-cleanup-r1 [class*="panel"],
body.sva-ui-cleanup-r1 [class*="card"] {
  min-width: 0;
}

body.sva-ui-cleanup-r1 .btn,
body.sva-ui-cleanup-r1 button,
body.sva-ui-cleanup-r1 .badge,
body.sva-ui-cleanup-r1 [class*="chip"] {
  max-width: 100%;
}

/* Prevent the vertical letter-stacking seen in the chat screenshot. */
body.sva-ui-cleanup-r1 .chat-title,
body.sva-ui-cleanup-r1 .chat-header,
body.sva-ui-cleanup-r1 .chat-list-item,
body.sva-ui-cleanup-r1 .chat-list-item *,
body.sva-ui-cleanup-r1 .crm-snapshot,
body.sva-ui-cleanup-r1 .crm-snapshot *,
body.sva-ui-cleanup-r1 .crm-value-block,
body.sva-ui-cleanup-r1 .crm-value-block *,
body.sva-ui-cleanup-r1 .crm-activity,
body.sva-ui-cleanup-r1 .crm-activity *,
body.sva-ui-cleanup-r1 [class*="snapshot"],
body.sva-ui-cleanup-r1 [class*="snapshot"] *,
body.sva-ui-cleanup-r1 [class*="chat"] {
  writing-mode: horizontal-tb !important;
  text-orientation: mixed !important;
  word-break: normal !important;
  overflow-wrap: anywhere !important;
}

/* Chat monitor layout safety. */
body.sva-route-chats .main-content {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
}

body.sva-route-chats .main-content > *,
body.sva-route-chats .row,
body.sva-route-chats .row > *,
body.sva-route-agency-chats .main-content > *,
body.sva-route-chatter-workspace .main-content > * {
  min-width: 0 !important;
}

body.sva-route-chats .crm-filter-bar,
body.sva-route-chats .chat-crm-search,
body.sva-route-agency-chats .crm-filter-bar,
body.sva-route-agency-chats .chat-crm-search {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center;
  gap: .5rem !important;
}

body.sva-route-chats .crm-filter-bar .btn,
body.sva-route-agency-chats .crm-filter-bar .btn,
body.sva-route-chats .chat-crm-search .btn,
body.sva-route-chats .chat-crm-search .form-control,
body.sva-route-chats .chat-crm-search .form-select {
  min-width: max-content;
}

body.sva-route-chats .crm-badge-row,
body.sva-route-agency-chats .crm-badge-row {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: .35rem !important;
}

body.sva-route-chats .crm-chip,
body.sva-route-agency-chats .crm-chip,
body.sva-route-chatter-workspace .crm-chip {
  white-space: normal !important;
  line-height: 1.15 !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  max-width: 100%;
}

body.sva-route-chats .crm-snapshot,
body.sva-route-agency-chats .crm-snapshot {
  min-width: min(320px, 100%) !important;
  max-width: 420px !important;
  width: 100% !important;
  overflow: visible !important;
}

body.sva-route-chats .crm-snapshot-grid,
body.sva-route-chats .crm-value-grid,
body.sva-route-agency-chats .crm-snapshot-grid,
body.sva-route-agency-chats .crm-value-grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: .55rem !important;
}

body.sva-route-chats .crm-snapshot-card,
body.sva-route-chats .crm-value-card,
body.sva-route-agency-chats .crm-snapshot-card,
body.sva-route-agency-chats .crm-value-card {
  min-width: 0 !important;
  overflow: hidden;
}

body.sva-route-chats .crm-snapshot-label,
body.sva-route-chats .crm-value-label,
body.sva-route-agency-chats .crm-snapshot-label,
body.sva-route-agency-chats .crm-value-label {
  line-height: 1.1 !important;
  letter-spacing: .02em;
}

/* Hide redundant internal context cards inside /chats. The floating context pill remains. */
body.sva-route-chats .sva-hide-context-card {
  display: none !important;
}

/* Replace the giant red context rail with a compact internal pill. */
body.sva-ui-cleanup-r1 .sva-creator-context-pill {
  position: fixed !important;
  left: 14px !important;
  bottom: 14px !important;
  top: auto !important;
  right: auto !important;
  width: auto !important;
  min-width: 0 !important;
  max-width: min(460px, calc(100vw - 28px)) !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  padding: 10px 12px !important;
  margin: 0 !important;
  border-radius: 18px !important;
  background: rgba(15, 23, 42, .96) !important;
  border: 1px solid rgba(245, 158, 11, .35) !important;
  color: #f8fafc !important;
  box-shadow: 0 16px 44px rgba(0,0,0,.38) !important;
  z-index: 2147482000 !important;
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  flex-wrap: wrap !important;
  overflow: visible !important;
  transform: none !important;
}

body.sva-ui-cleanup-r1 .sva-creator-context-pill * {
  color: inherit !important;
  white-space: normal !important;
  writing-mode: horizontal-tb !important;
  word-break: normal !important;
  overflow-wrap: anywhere !important;
}

body.sva-ui-cleanup-r1 .sva-creator-context-pill a,
body.sva-ui-cleanup-r1 .sva-creator-context-pill button {
  border-radius: 999px !important;
  padding: 7px 10px !important;
  font-size: .82rem !important;
  line-height: 1 !important;
  margin: 0 !important;
}

/* Desktop: keep app content usable even with sidebars. */
@media (min-width: 1200px) {
  body.sva-route-chats .main-content {
    padding-right: clamp(12px, 1.2vw, 24px) !important;
  }

  body.sva-route-chats .crm-snapshot {
    position: relative !important;
  }
}

/* Tablet/mobile: stack instead of squeezing. */
@media (max-width: 1100px) {
  body.sva-route-chats .main-content,
  body.sva-route-agency-chats .main-content,
  body.sva-route-chatter-workspace .main-content {
    overflow-x: hidden !important;
  }

  body.sva-route-chats .crm-snapshot,
  body.sva-route-agency-chats .crm-snapshot {
    max-width: 100% !important;
  }
}

@media (max-width: 768px) {
  body.sva-ui-cleanup-r1 .sidebar {
    width: 100% !important;
    min-width: 0 !important;
  }

  body.sva-ui-cleanup-r1 .main-content {
    padding: 14px !important;
  }

  body.sva-route-chats .crm-snapshot-grid,
  body.sva-route-chats .crm-value-grid,
  body.sva-route-agency-chats .crm-snapshot-grid,
  body.sva-route-agency-chats .crm-value-grid {
    grid-template-columns: 1fr !important;
  }

  body.sva-ui-cleanup-r1 .sva-creator-context-pill {
    left: 10px !important;
    right: 10px !important;
    bottom: 10px !important;
    max-width: calc(100vw - 20px) !important;
  }
}

/* SOLVAIRA_UI_CLEANUP_R1_LEAK_GUARD */
script#SOLVAIRA_UI_CLEANUP_R1_SCRIPT,
script#SOLVAIRA_UI_CLEANUP_R1_EXTERNAL_SCRIPT {
  display: none !important;
}
