/* Shared working surfaces. Load after legacy component sheets. */
:root { --ui-readable-muted: #5d697b; }
*, *::before, *::after { box-sizing: border-box; }
.content, #view, .main, .card, .modal__body, .modal__foot, .form-row > *, .grid > * { min-width: 0; }
.input, .select, textarea, select, input { max-width: 100%; }
.field label, .help { line-height: 1.5; }
.help, .cockpit .ctx .ctx-cell .k, .cockpit .pulse-col .pc-stage { color: var(--ui-readable-muted); }
.cockpit.gc-dashboard { --ink3: var(--ui-readable-muted); }
.gc-metric__note { white-space: normal; font-size: 12px; line-height: 1.4; }
.gc-pipeline-stage span { white-space: normal; font-size: 12px; }
.gc-pipeline-stage small { white-space: normal; font-size: 11px; line-height: 1.4; }
.wa-conv__badge { background: var(--crm-brand-primary); color: #fff; }
/* Keep every column reachable without moving the full page sideways. */
.table-wrap { min-width: 0; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-gutter: stable; }
.table-wrap > table { width: 100%; }
.table-wrap:focus-visible { outline: 2px solid var(--ui-primary, var(--crm-brand-focus)); outline-offset: 2px; }
.table-wrap th { vertical-align: bottom; }
.table-wrap td { overflow-wrap: anywhere; }
.table-wrap td .btn, .table-wrap td .chip { white-space: nowrap; }
/* Dialog content scrolls; persistent header/actions remain reachable. */
.modal-overlay { overflow-y: auto; padding: 20px; }
.modal { display: flex; flex-direction: column; max-width: 100%; max-height: calc(100dvh - 40px); overflow: hidden; }
.modal:not(.modal--wide) { max-width: 520px; }
.modal.modal--wide { max-width: 820px; }
.modal__head { flex: 0 0 auto; gap: 12px; }
.modal__head h3 { min-width: 0; overflow-wrap: anywhere; }
.modal__body { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.modal__body > * { max-width: 100%; }
.modal__foot { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 8px; }
.modal__head .icon-btn { flex: 0 0 auto; }
.toast-wrap { max-width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; }
.toast { width: 100%; min-width: 0; align-items: flex-start; gap: 10px; }
.toast__message { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.toast__dismiss { appearance: none; border: 0; border-radius: 6px; background: transparent; color: inherit; display: grid; place-items: center; flex: 0 0 28px; width: 28px; height: 28px; margin: -5px -6px -5px 0; cursor: pointer; }
.toast__dismiss:hover { background: rgba(255,255,255,.15); }
/* Flexible builders preserve the productive desktop layout. */
.ui-form-builder-layout { display: grid; grid-template-columns: 240px minmax(0,1fr) 280px; gap: 14px; min-height: 600px; align-items: start; }
.ui-chatbot-builder-layout { display: grid; grid-template-columns: 300px minmax(0,1fr); gap: 20px; align-items: start; }
.ui-chatbot-field-row { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr) 140px 64px 40px; gap: 8px; margin-bottom: 10px; align-items: center; }
.ui-form-builder-layout > *, .ui-chatbot-builder-layout > *, .ui-chatbot-field-row > * { min-width: 0; }
/* Inbox: full thread on a phone; list and optional context remain one action away. */
.wa-shell { min-width: 0; grid-template-columns: minmax(230px,280px) minmax(0,1fr) minmax(240px,280px); height: max(520px, calc(100dvh - 210px)); }
.wa-shell.no-context { grid-template-columns: minmax(230px,280px) minmax(0,1fr); }
.wa-pane { min-height: 0; }
.wa-conv { appearance: none; width: 100%; text-align: left; color: inherit; background: transparent; font: inherit; border: 0; border-bottom: 1px solid var(--border); }
.wa-thread-heading { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.wa-thread-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.wa-thread-identity b { overflow-wrap: anywhere; }
.wa-thread-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.wa-thread-tools select { max-width: 210px; }
.wa-pane-back, .wa-details-toggle { display: none; }
.wa-compose-row { display: flex; gap: 8px; align-items: flex-end; }
.wa-compose-row > textarea { flex: 1; min-width: 0; }
.wa-compose-actions { display: flex; flex-direction: column; gap: 6px; }
.wa-compose-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.wa-canned-choice { text-align: left; width: 100%; color: inherit; font: inherit; background: var(--surface); }
.wa-lead__row { gap: 12px; overflow-wrap: anywhere; }
.wa-lead > .wa-pane-back { margin-bottom: 14px; }
.sim-phone { width: min(340px, 100%); max-width: 100%; }
.dp { max-width: 100%; }
.dp-time { min-width: 0; }
@media (max-width: 1200px) {
  .wa-shell, .wa-shell.no-context { grid-template-columns: minmax(230px,280px) minmax(0,1fr); }
  .wa-details-toggle { display: inline-flex; }
  .wa-shell[data-pane="context"] { grid-template-columns: minmax(0,1fr); }
  .wa-shell[data-pane="context"] > .wa-pane { display: none; }
  .wa-shell[data-pane="context"] > .wa-lead { display: flex; }
  .wa-lead > .wa-pane-back { display: inline-flex; align-self: flex-start; }
  .ui-form-builder-layout { grid-template-columns: minmax(180px, .7fr) minmax(0,1.3fr); }
  .ui-form-builder-layout > :last-child { grid-column: 1 / -1; }
  .ui-chatbot-field-row { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
}
@media (max-width: 900px) {
  .wa-shell, .wa-shell.no-context { grid-template-columns: minmax(0,1fr); height: max(520px, calc(100dvh - 190px)); }
  .wa-shell > .wa-pane { display: none; }
  .wa-shell[data-pane="list"] > [data-testid="wa-conv-list"], .wa-shell[data-pane="thread"] > [data-testid="wa-thread"], .wa-shell[data-pane="context"] > [data-testid="wa-context"] { display: flex; }
  .wa-thread-identity .wa-pane-back { display: inline-flex; }
  .ui-chatbot-builder-layout { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 680px) {
  .form-row, .grid.grid-2, .ui-form-builder-layout { grid-template-columns: minmax(0,1fr); }
  .ui-form-builder-layout { min-height: 0; }
  .ui-form-builder-layout > :last-child { grid-column: auto; }
  .modal-overlay { padding: 10px; }
  .modal { max-height: calc(100dvh - 20px); }
  .modal__head, .modal__body, .modal__foot { padding: 16px; }
  .modal__body > [style*="min-width"] { min-width: 0 !important; }
  .modal__foot .btn { flex: 1 1 auto; justify-content: center; }
  .modal__head .icon-btn { min-height: 40px; min-width: 40px; }
  .toast-wrap { right: 12px; bottom: 12px; max-width: calc(100vw - 24px); }
  .wa-thread-heading { padding: 12px; }
  .wa-thread-identity { flex-wrap: wrap; }
  .wa-thread-tools { width: 100%; }
  .wa-compose-row { flex-direction: column; align-items: stretch; }
  .wa-compose-actions { flex-direction: row-reverse; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .wa-compose-tools { flex: 1; }
  .wa-compose-row > textarea { width: 100%; min-height: 72px; }
  .ui-chatbot-field-row { padding: 12px; border: 1px solid var(--ui-line, #dfe5ee); border-radius: 9px; }
}
@media (pointer: coarse) {
  .btn, .icon-btn, .dp-nav, .dp-day, .nav__item { min-height: 44px; }
  .icon-btn, .dp-nav { min-width: 44px; }
}

/* Search and financial summaries share the same responsive surface rules. */
[hidden] { display: none !important; }
.ui-template-search { display: grid; gap: 6px; margin-bottom: 16px; }
.ui-template-search > label { font-size: 12px; color: var(--ui-readable-muted); font-weight: 600; }
.ui-template-search__controls { display: flex; gap: 8px; }
.ui-template-search__controls .input { flex: 1; min-width: 0; }
.aging-strip { grid-template-columns: repeat(5, minmax(0,1fr)); }
.aging-cell { min-width: 0; }
.aging-cell .v { overflow-wrap: anywhere; }
@media (max-width: 900px) { .aging-strip { grid-template-columns: repeat(3,minmax(0,1fr)); } }
@media (max-width: 560px) { .aging-strip { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; } .aging-cell { padding: 14px; } }
