/* ==========================================================================================
 * TG Desk CRM - Chatwoot shell customization stylesheet
 * ==========================================================================================
 * Owner:        agent-shell          (see <ws>/INTEGRATION_CONTRACT.md section 1)
 * Served at:    /crm-shell/chatwoot-custom.css   (nginx alias -> gateway/)
 * Injected by:  sub_filter '</head>' -> <link rel="stylesheet" href="/crm-shell/chatwoot-custom.css">
 * Companion:    gateway/chatwoot-custom.js  (the only JS half; does no styling)
 *
 * RULES
 *  - Every class name is prefixed `cw-`. Chatwoot is Tailwind + `n-*` component classes, so a
 *    `cw-` prefix guarantees zero collision.
 *  - Light AND dark theme support: primitives (n-slate-*) are read through Chatwoot's own CSS
 *    custom properties when present, with a hard-coded light fallback for the dark theme.
 *  - Chatwoot's dark theme is implemented with `.dark` on <html> or <body>; we scope overrides
 *    under `html.dark, body.dark, .dark` and *never* rely on prefers-color-scheme alone, because
 *    Chatwoot's theme choice is user-managed, not OS-managed.
 *  - Role-shield hiding (`data-cw-hide`) stays retired (contract V3 §2 / custom_role).
 *  - V4 §8/§13: a small set of stock Chatwoot entries is removed for EVERY role
 *    («Диалоги» + vendor account-menu links). Those are hidden here in CSS so the first
 *    paint never flashes them; JS only re-applies after Vue re-renders.
 * SECTIONS
 *  - 0 tokens; 1 the CRM desk (nav entry + removed sections); 5 a11y/print;
 *    6 awaiting+flash; 7 reply-chain+composer; 8 SLA strip; 9 chat card; 9b quick replies;
 *    22 typing chip; 23 annotations; 24 TG action bar + modal + toasts; 25 TG deep search.
 * ========================================================================================= */

/* ------------------------------------------------------------------------------------------
 * 0. Design tokens
 * ------------------------------------------------------------------------------------------ */

/* Chatwoot renders its 500/700 brand ramp on :root in recent versions. We shadow the three
 * values we actually need behind `--cw-*` so a Chatwoot upgrade can never break our layout. */
:root {
  --cw-font: var(
    --cw-font-family,
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif
  );
  --cw-accent: var(--n-brand-500, #1f93ff);
  --cw-accent-hover: var(--n-brand-600, #1a7fe0);
  --cw-accent-soft: var(--n-brand-50, rgba(31, 147, 255, 0.1));
  --cw-surface: var(--n-background-color, var(--n-slate-1, #ffffff));
  --cw-surface-raised: var(--n-slate-2, #f8fafc);
  --cw-border: var(--n-border-color, var(--n-slate-5, #e2e8f0));
  --cw-text: var(--n-slate-12, #0f172a);
  --cw-text-muted: var(--n-slate-11, #64748b);
  /* Faint status dots/notes: declared here so every `var(--cw-text-faint)`
     resolves to a real colour instead of falling back to the inherited one
     (the `.cw-dot` backgrounds used to render transparent). */
  --cw-text-faint: var(--n-slate-9, #94a3b8);
  --cw-sidebar-hover: var(--n-slate-3, rgba(148, 163, 184, 0.16));
  --cw-shadow: 0 1px 2px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
  --cw-radius: 6px;
  /* Chatwoot's own header is 56px (h-14) and its sidebar is 232px wide in recent versions.
   * These are only used as a *fallback* when the runtime probe of the content box fails. */
  --cw-sidebar-width: var(--cw-sidebar-w, 232px);
}

/* Dark theme: Chatwoot toggles `.dark` on <html> (v3.x) or <body> (older). Cover both. */
.dark {
  --cw-surface: var(--n-background-color, var(--n-slate-1, #151718));
  --cw-surface-raised: var(--n-slate-2, #1d1f20);
  --cw-border: var(--n-border-color, var(--n-slate-5, #2b2f31));
  --cw-text: var(--n-slate-12, #e5e7eb);
  --cw-text-muted: var(--n-slate-11, #9aa4ad);
  --cw-text-faint: var(--n-slate-9, #64748b);
  --cw-sidebar-hover: var(--n-slate-3, rgba(226, 232, 240, 0.1));
  --cw-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.4);
  --cw-accent-soft: var(--n-brand-50, rgba(31, 147, 255, 0.18));
}

/* ------------------------------------------------------------------------------------------
 * 1. The CRM desk inside Chatwoot (v4, contract V4 §4)
 * ------------------------------------------------------------------------------------------
 * §1 sidebar entry  `.cw-nav-*`     — the "TG Desk CRM" tab (native list item + Vue route)
 * §1 page           `.cw-crm-page` / `.cw-crm-frame` — desk PAGE in Chatwoot's <main>
 *                   (not an overlay; route-driven sibling of the routed content)
 *
 * Still absent (retired in v2.0.0 and NOT coming back):
 *   - §2 role isolation `data-cw-hide` / `.cw-role-agent` / `[data-cw-native-shield]`
 *     hiding rules                        (menu shaping is Chatwoot's own custom_role now);
 *   - §4 `.cw-label-hint*`                (the admin hint bar is retired);
 *   - the 1.3.7 `.cw-crm-badge*` block    (no reverse link any more).
 * The extra tokens they used (--cw-sidebar-width, --cw-sidebar-hover) stay in section 0:
 * both are generic primitives and the sidebar probe may still emit them harmlessly.
 * ------------------------------------------------------------------------------------------ */

/* The sidebar entry is a CLONE of a native Chatwoot menu item, so it inherits the
 * native classes, the icon sprite, the typography and the hover behaviour. Only the
 * fallback (a sidebar with no native item to clone) needs styles of its own. */
.cw-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--cw-text);
  text-decoration: none;
  cursor: pointer;
}

/* ------------------------------------------------------------------------------------------
 * 1a. Removed stock Chatwoot menu entries (contract V4 §8 / §13)
 * ------------------------------------------------------------------------------------------
 * These used to be hidden only by JS (`crmDeskRemoveNativeSections`) on each sync tick.
 * Vue paints the sidebar / account menu first, so the deleted items flashed for a
 * fraction of a second (or longer while the MutationObserver was still debouncing).
 * CSS hides them on first paint; the JS pass stays as a fallback for odd markup.
 *
 * Match by href (locale-independent). Direct-child `a` for sidebar sections so nested
 * inbox links are not swept up; account-menu vendor links hide the whole row.
 * ------------------------------------------------------------------------------------------ */
/* Top-level «Диалоги» (/app/accounts/<id>/dashboard) — whole <li> with nested filters. */
li:has(> a[href*="/accounts/"][href*="/dashboard"]) {
  display: none !important;
}

/* First load still paints that page before the shell can leave it. The head
 * script adds cw-leave-home while the address is /dashboard, so the empty
 * conversation list never appears. My Inbox removes the class. */
html.cw-leave-home main {
  visibility: hidden !important;
}

/* Native «Контакты» (/contacts, /contacts/active) — replaced by dedicated /colleagues. */
li:has(> a[href*="/accounts/"][href*="/contacts"]) {
  display: none !important;
}

/*
 * Companies, Help Center and Settings are not part of this deployment.
 * Hidden on first paint (the JS pass is the fallback). Profile lives at
 * /app/profile/settings and does not match these account-scoped hrefs.
 */
a[href*="/accounts/"][href*="/companies"],
a[href*="/accounts/"][href*="/portals"],
a[href*="/accounts/"][href*="/help-center"],
a[href*="/accounts/"][href*="/help_center"],
a[href*="/accounts/"][href*="/settings"],
a[href*="/accounts/"][href*="/captain"],
li:has(> a[href*="/accounts/"][href*="/companies"]),
li:has(> a[href*="/accounts/"][href*="/portals"]),
li:has(> a[href*="/accounts/"][href*="/help-center"]),
li:has(> a[href*="/accounts/"][href*="/help_center"]),
li:has(> a[href*="/accounts/"][href*="/settings"]),
li:has(a[href*="/captain"]),
button:has(.i-woot-captain),
a:has(.i-woot-captain),
li:has(.i-woot-captain) {
  display: none !important;
}

/*
 * «Mark offline automatically» is not an operator status. The row is a dropdown
 * item whose only control is a switch. Hide it in CSS so the menu never paints
 * it, not even for one frame (a JS hide runs after Vue has already shown it).
 */
li.n-dropdown-item:has([role="switch"]),
[role="menuitem"]:has([role="switch"]) {
  display: none !important;
}

li:has(a[href*="chatwoot.com/hc/"]),
li:has(a[href*="chatwoot.com/changelog"]),
a[href*="chatwoot.com/hc/"],
a[href*="chatwoot.com/changelog"] {
  display: none !important;
}

/* The desk PAGE inside Chatwoot's content area.
 *
 * It is NOT an overlay: it occupies the content slot of the routed page, so the desk
 * behaves like a native section — the sidebar, the URL and the browser history work
 * exactly as they do for the other Chatwoot pages. The host (Chatwoot's <main>) is made
 * the positioning context, and the page fills it.
 *
 * NOTHING of ours is painted over the native UI: no header, no border, no shadow — the
 * desk SPA brings its own top bar. */
.cw-crm-page {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--cw-surface);
  color: var(--cw-text);
  font-family: var(--cw-font);
}

/* The desk SPA itself. It owns its own scrolling; the page only frames it. */
.cw-crm-frame {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background-color: var(--cw-surface);
}

/* ------------------------------------------------------------------------------------------
 * 1b. «Коллеги» и звонки (contract V4 §14)
 * ------------------------------------------------------------------------------------------
 * «Коллеги» is a dedicated /colleagues Vue route (NOT /contacts). «Звонки» still reuses
 * the native Calls page. Both blocks must read as part of Chatwoot: same surface, radius,
 * border, type scale — not a foreign widget pasted into the page.
 * ------------------------------------------------------------------------------------------ */

.cw-card {
  margin: 0 0 16px;
  border: 1px solid var(--cw-border);
  border-radius: 8px;
  background: var(--cw-surface);
  color: var(--cw-text);
  font-family: var(--cw-font);
  font-size: 14px;
  overflow: hidden;
}

.cw-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--cw-border);
  background: var(--cw-surface-raised);
}

.cw-card__title {
  font-size: 14px;
  font-weight: 600;
}

.cw-card__hint {
  font-size: 12px;
  color: var(--cw-text-muted);
}

.cw-card__body {
  padding: 10px 14px;
}

.cw-card__actions {
  display: flex;
  gap: 8px;
  padding: 0 14px 12px;
}

.cw-state {
  padding: 10px 0;
  font-size: 13px;
  color: var(--cw-text-muted);
}

/* the roster of colleagues */
.cw-roster {
  display: flex;
  flex-direction: column;
}

.cw-roster__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--cw-border);
}

.cw-roster__row:last-child {
  border-bottom: 0;
}

.cw-roster__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.cw-roster__role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cw-text-muted);
}

.cw-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--cw-text-faint);
}

.cw-dot--on {
  background: #16a34a;
}

/* buttons */
.cw-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--cw-border);
  border-radius: 6px;
  background: var(--cw-surface-raised);
  color: var(--cw-text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.cw-btn:hover {
  background: var(--cw-sidebar-hover);
}

.cw-btn--sm {
  height: 26px;
  padding: 0 9px;
  font-size: 12px;
}

.cw-btn--ghost {
  background: transparent;
  color: var(--cw-text-muted);
}

.cw-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--cw-border);
  border-radius: 6px;
  background: var(--cw-surface);
  color: var(--cw-text);
  font: inherit;
  font-size: 13px;
}

.cw-input:focus {
  border-color: var(--cw-accent);
  outline: none;
}

/* the messenger (an internal conversation) */
.cw-messenger {
  border-top: 1px solid var(--cw-border);
  background: var(--cw-surface-raised);
}

.cw-messenger__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--cw-border);
}

.cw-messenger__title {
  font-size: 13px;
  font-weight: 600;
}

.cw-messenger__list {
  max-height: 260px;
  overflow-y: auto;
  padding: 8px 14px;
}

.cw-messenger__composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 14px 12px;
}

.cw-messenger__input {
  flex: 1 1 auto;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--cw-border);
  border-radius: 6px;
  background: var(--cw-surface);
  color: var(--cw-text);
  font: inherit;
  font-size: 13px;
  resize: vertical;
}

.cw-msg {
  display: flex;
  gap: 8px;
  padding: 3px 0;
  font-size: 13px;
}

.cw-msg--mine {
  flex-direction: row-reverse;
}

.cw-msg__author {
  flex: 0 0 auto;
  font-weight: 600;
  color: var(--cw-text-muted);
}

.cw-msg__text {
  white-space: pre-wrap;
}

/* the calls block */
.cw-call {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 0;
}

.cw-call--live {
  border-bottom: 1px solid var(--cw-border);
  margin-bottom: 8px;
}

.cw-call__state {
  font-size: 13px;
  font-weight: 600;
}

.cw-call__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--cw-text-muted);
}

.cw-call__groups {
  display: flex;
  flex-direction: column;
}

.cw-call__label {
  padding: 4px 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cw-text-faint);
}

.cw-call__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--cw-border);
}

.cw-call__row:last-child {
  border-bottom: 0;
}

.cw-call__note {
  padding-top: 8px;
  font-size: 12px;
  color: var(--cw-text-faint);
}

/* the group dialog */
.cw-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
}

.cw-modal__box {
  width: 360px;
  max-width: calc(100vw - 32px);
  padding: 16px;
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  background: var(--cw-surface);
  color: var(--cw-text);
  font-family: var(--cw-font);
  font-size: 14px;
}

.cw-modal__title {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
}

.cw-modal__list {
  max-height: 220px;
  overflow-y: auto;
  margin: 10px 0;
}

.cw-modal__row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
}

.cw-modal__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
/* ------------------------------------------------------------------------------------------
 * 1c. «Коллеги» и «Звонки» — redesign (contract V4 §14)
 * ------------------------------------------------------------------------------------------
 * Full-page team workspace inside Chatwoot. Same `--cw-*` tokens / dark theme as the rest
 * of the shell, but a denser layout: stats strip, presence rings, rail tabs, dial tiles,
 * and a live-call stage. Logic stays in chatwoot-custom.js; this file is presentation only.
 * ------------------------------------------------------------------------------------------ */

/* Host column that owns Коллеги / Звонки — fill Chatwoot's content slot without
 * fighting the native flex layout (100vh min-height was clipping the sidebar). */
[data-cw-shell-host] {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
  box-sizing: border-box;
}

.cw-card--page {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  margin: 0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--cw-shadow);
}

.cw-card__head--page {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--cw-border);
  background:
    radial-gradient(120% 140% at 0% 0%, var(--cw-accent-soft), transparent 55%),
    var(--cw-surface);
  flex: 0 0 auto;
}

.cw-page__heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1 1 220px;
}

.cw-page__kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cw-accent);
}

.cw-page__title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.cw-page__subtitle {
  font-size: 13px;
  color: var(--cw-text-muted);
}

.cw-page__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}

.cw-stats {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex: 0 1 auto;
  flex-wrap: wrap;
}

.cw-stat {
  min-width: 72px;
  padding: 8px 12px;
  border: 1px solid var(--cw-border);
  border-radius: 12px;
  background: var(--cw-surface);
  text-align: left;
}

.cw-stat__value {
  display: block;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.cw-stat__label {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--cw-text-muted);
}

.cw-stat--live .cw-stat__value {
  color: #16a34a;
}

/* two panes -------------------------------------------------------------------------- */

.cw-page {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
}

.cw-page__left {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  border-right: 1px solid var(--cw-border);
  background: var(--cw-surface-raised);
  overflow: hidden;
}

.cw-page__right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.02), transparent 120px),
    var(--cw-surface);
}

.dark .cw-page__right,
body.dark .cw-page__right,
html.dark .cw-page__right {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 120px),
    var(--cw-surface);
}

/* search + segmented switches -------------------------------------------------------------- */

.cw-tools {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: var(--cw-surface-raised);
  border-bottom: 1px solid var(--cw-border);
  flex: 0 0 auto;
}

.cw-search-wrap {
  position: relative;
}

.cw-search-wrap::before {
  content: '';
  position: absolute;
  left: 12px;
  top: 50%;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--cw-text-muted);
  border-radius: 999px;
  transform: translateY(-50%);
  pointer-events: none;
  opacity: 0.7;
  z-index: 1;
}

.cw-search-wrap::after {
  content: '';
  position: absolute;
  left: 23px;
  top: 50%;
  width: 6px;
  height: 1.5px;
  margin-top: 4px;
  background: var(--cw-text-muted);
  transform: rotate(45deg);
  pointer-events: none;
  opacity: 0.7;
  z-index: 1;
}

.cw-tools .cw-search,
.cw-picker .cw-search,
.cw-search-wrap .cw-search,
.cw-search {
  width: 100% !important;
  height: 38px !important;
  min-height: 38px !important;
  padding: 0 14px 0 36px !important;
  border: 1px solid var(--cw-border) !important;
  border-radius: 12px !important;
  background: var(--cw-surface) !important;
  color: var(--cw-text) !important;
  font: inherit !important;
  font-size: 13px !important;
  line-height: 20px !important;
  box-sizing: border-box !important;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.cw-search:focus {
  border-color: var(--cw-accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--cw-accent-soft);
}

.cw-segments {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--cw-sidebar-hover);
  width: 100%;
}

.cw-segment {
  flex: 1 1 0;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--cw-text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.cw-segment:hover {
  color: var(--cw-text);
}

.cw-segment--on {
  background: var(--cw-surface);
  color: var(--cw-text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.cw-rail-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-bottom: 1px solid var(--cw-border);
  background: var(--cw-surface-raised);
}

.cw-rail-tab {
  position: relative;
  height: 42px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--cw-text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.cw-rail-tab:hover {
  color: var(--cw-text);
  background: var(--cw-sidebar-hover);
}

.cw-rail-tab--on {
  color: var(--cw-text);
}

.cw-rail-tab--on::after {
  content: '';
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 0;
  height: 2px;
  border-radius: 999px;
  background: var(--cw-accent);
}

.cw-rail-tab__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--cw-sidebar-hover);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cw-rail-tab--on .cw-rail-tab__count {
  background: var(--cw-accent-soft);
  color: var(--cw-accent);
}

/* lists ------------------------------------------------------------------------------------ */

.cw-lists {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 8px 16px;
}

.cw-list__label {
  padding: 10px 10px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cw-text-muted);
}

.cw-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 2px;
}

.cw-list .cw-state {
  padding: 16px 10px;
}

.cw-person {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 12px;
  transition: background-color 120ms ease, transform 120ms ease;
}

.cw-person:hover {
  background: var(--cw-surface);
  box-shadow: inset 0 0 0 1px var(--cw-border);
}

.cw-person__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.cw-person__name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-person__sub {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--cw-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-person__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex: 0 0 auto;
  opacity: 0.7;
  transition: opacity 120ms ease;
}

.cw-person:hover .cw-person__actions,
.cw-person:focus-within .cw-person__actions {
  opacity: 1;
}

.cw-person__actions .cw-btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  line-height: 1;
  font-size: 15px;
}

.cw-avatar-wrap {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
}

.cw-avatar-wrap:has(.cw-avatar--sm) {
  width: 32px;
  height: 32px;
}

.cw-avatar-wrap:has(.cw-avatar--lg) {
  width: 64px;
  height: 64px;
}

.cw-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.cw-avatar--sm {
  width: 32px;
  height: 32px;
  border-radius: 11px;
  font-size: 11px;
}

.cw-avatar--lg {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  font-size: 20px;
}

.cw-avatar-wrap .cw-avatar {
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.cw-avatar-wrap:has(.cw-avatar--sm) {
  border-radius: 11px;
}

.cw-avatar-wrap:not(:has(.cw-avatar--sm)):not(:has(.cw-avatar--lg)) {
  border-radius: 14px;
}

.cw-avatar-wrap:has(.cw-avatar--lg) {
  border-radius: 20px;
}

.cw-presence {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  border: 2px solid var(--cw-surface-raised);
  background: var(--cw-text-faint);
}

.cw-presence--on {
  background: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18);
}

.cw-badge-soft {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
  font-size: 10px;
  font-weight: 700;
}

.dark .cw-badge-soft,
body.dark .cw-badge-soft,
html.dark .cw-badge-soft {
  color: #fbbf24;
}

.cw-chatrow {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease, box-shadow 120ms ease;
}

.cw-chatrow:hover {
  background: var(--cw-surface);
  box-shadow: inset 0 0 0 1px var(--cw-border);
}

.cw-chatrow--on {
  background: var(--cw-accent-soft);
  box-shadow: inset 0 0 0 1px transparent;
}

.cw-chatrow__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.cw-chatrow__title {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-chatrow__sub {
  font-size: 11px;
  color: var(--cw-text-muted);
}

/* messenger -------------------------------------------------------------------------- */

.cw-page__right .cw-messenger__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--cw-border);
  background: color-mix(in srgb, var(--cw-surface) 88%, transparent);
  backdrop-filter: blur(8px);
}

.cw-messenger__peer {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.cw-messenger__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.cw-messenger__title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.cw-messenger__sub {
  font-size: 12px;
  color: var(--cw-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-messenger__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.cw-page__right .cw-messenger__head {
  flex: 0 0 auto;
}

.cw-page__right .cw-messenger__list {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  max-height: none;
  min-height: 0;
  padding: 18px 20px;
  overflow-x: hidden;
  overflow-y: auto;
  background: transparent;
}

/* Pin short threads to the bottom of the pane (chat-style), without breaking scroll. */
.cw-page__right .cw-messenger__list::before {
  content: '';
  flex: 1 1 auto;
  min-height: 0;
}

.cw-page__right .cw-messenger__composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 18px 14px;
  border-top: 1px solid var(--cw-border);
  background: var(--cw-surface-raised);
  flex: 0 0 auto;
  width: 100%;
  box-sizing: border-box;
}

.cw-page__right .cw-messenger__input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  max-width: none;
  height: 44px !important;
  min-height: 44px !important;
  max-height: 120px;
  border: 1px solid var(--cw-border) !important;
  border-radius: 14px !important;
  padding: 11px 14px !important;
  margin: 0 !important;
  background: var(--cw-surface) !important;
  color: var(--cw-text) !important;
  font: inherit !important;
  font-size: 13px !important;
  line-height: 20px !important;
  resize: none;
  overflow-y: auto;
  box-sizing: border-box !important;
}

.cw-page__right .cw-messenger__composer .cw-btn {
  flex: 0 0 auto;
  height: 44px !important;
  min-height: 44px !important;
  min-width: 108px;
  padding: 0 16px !important;
  margin: 0 !important;
  border-radius: 12px !important;
  align-self: flex-end;
}

.cw-msg {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
}

.cw-msg--mine {
  flex-direction: row-reverse;
}

.cw-msg__bubble {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 68%;
  padding: 9px 12px;
  border-radius: 16px;
  background: var(--cw-surface-raised);
  border: 1px solid var(--cw-border);
  box-shadow: 0 1px 1px rgba(15, 23, 42, 0.03);
}

.cw-msg--mine .cw-msg__bubble {
  background: var(--cw-accent);
  border-color: transparent;
  color: #fff;
  align-items: flex-end;
  border-bottom-right-radius: 6px;
}

.cw-msg:not(.cw-msg--mine) .cw-msg__bubble {
  border-bottom-left-radius: 6px;
}

.cw-msg__author {
  font-size: 11px;
  font-weight: 700;
  color: var(--cw-text-muted);
}

.cw-msg--mine .cw-msg__author {
  color: rgba(255, 255, 255, 0.78);
}

.cw-msg__text {
  white-space: pre-wrap;
  line-height: 1.4;
}

.cw-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1 1 auto;
  padding: 48px 28px;
  text-align: center;
}

.cw-empty__glyph {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin-bottom: 8px;
  border-radius: 22px;
  background:
    linear-gradient(145deg, var(--cw-accent-soft), transparent 60%),
    var(--cw-surface-raised);
  border: 1px solid var(--cw-border);
  color: var(--cw-accent);
  font-size: 28px;
  font-weight: 700;
}

.cw-empty__title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.cw-empty__text {
  max-width: 360px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--cw-text-muted);
}

/* notices ---------------------------------------------------------------------------------- */

.cw-notices {
  display: flex;
  flex-direction: column;
}

.cw-notice {
  padding: 10px 18px;
  background: var(--cw-accent-soft);
  color: var(--cw-text);
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--cw-border);
  animation: cw-notice-in 180ms ease-out;
}

.cw-notice--warn {
  background: rgba(239, 68, 68, 0.12);
  color: #b91c1c;
}

.dark .cw-notice--warn,
body.dark .cw-notice--warn,
html.dark .cw-notice--warn {
  color: #fca5a5;
}

@keyframes cw-notice-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* calls page layout ---------------------------------------------------------------------- */

.cw-dial {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

[data-cw-shell-main] {
  min-height: 0 !important;
  overflow: hidden !important;
}

.cw-live {
  padding: 0;
}

.cw-live:empty {
  display: none;
}

.cw-hero {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  margin: 16px 16px 0;
  padding: 18px 20px;
  border-radius: 18px;
  color: #fff;
  overflow: hidden;
  background:
    radial-gradient(80% 120% at 100% 0%, rgba(255, 255, 255, 0.18), transparent 45%),
    linear-gradient(135deg, #0f172a 0%, #1d4ed8 52%, #0284c7 100%);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.22);
}

.cw-hero--out {
  background:
    radial-gradient(80% 120% at 100% 0%, rgba(255, 255, 255, 0.16), transparent 45%),
    linear-gradient(135deg, #0f172a 0%, #0369a1 48%, #0ea5e9 100%);
}

.cw-hero--ringing {
  animation: cw-hero-pulse 1.6s ease-in-out infinite;
}

@keyframes cw-hero-pulse {
  0%,
  100% {
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.22), 0 0 0 0 rgba(14, 165, 233, 0.45);
  }
  50% {
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.22), 0 0 0 12px rgba(14, 165, 233, 0);
  }
}

.cw-hero__meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.cw-hero__badge {
  align-self: flex-start;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.cw-hero__title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-hero__sub {
  font-size: 13px;
  opacity: 0.84;
}

.cw-hero__timer {
  font-variant-numeric: tabular-nums;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.cw-hero__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.cw-callbody {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.85fr);
  gap: 16px;
  padding: 16px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.cw-picker {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--cw-border);
  border-radius: 16px;
  background: var(--cw-surface-raised);
  overflow: hidden;
}

.cw-picker__bar {
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.cw-picker__bar .cw-segments {
  width: auto;
  flex: 1 1 160px;
  min-width: 140px;
  max-width: 100%;
}

.cw-picker__list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
  align-content: start;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 2px 2px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  flex: 1 1 auto;
  min-height: 0;
}

.cw-person--picker {
  position: relative;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--cw-border);
  border-radius: 14px;
  background: var(--cw-surface);
  min-height: 0;
}

.cw-person--picker:hover {
  border-color: color-mix(in srgb, var(--cw-accent) 35%, var(--cw-border));
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
  transform: translateY(-1px);
}

.cw-person--picker .cw-person__top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

.cw-person--picker .cw-person__actions {
  opacity: 1;
  width: auto;
  flex: 0 0 auto;
}

.cw-person--picker .cw-person__actions .cw-btn {
  width: auto;
  min-width: 104px;
  height: 32px;
  padding: 0 14px;
  border-radius: 10px;
}

.cw-person--picker .cw-check {
  position: absolute;
  top: 12px;
  right: 12px;
}

.cw-picker__foot {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid var(--cw-border);
}

.cw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  align-items: center;
}

.cw-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 10px;
  border-radius: 999px;
  background: var(--cw-accent-soft);
  color: var(--cw-text);
  font-size: 12px;
  font-weight: 600;
}

.cw-chip__x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--cw-text-muted);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.cw-chip__x:hover {
  background: var(--cw-sidebar-hover);
  color: var(--cw-text);
}

.cw-check {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  accent-color: var(--cw-accent);
  cursor: pointer;
}

.cw-input--title {
  max-width: none;
  height: 38px;
  border-radius: 12px;
}

.cw-quickcalls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--cw-border);
  border-radius: 16px;
  background: var(--cw-surface);
  overflow: hidden;
}

.cw-quickcalls .cw-list__label {
  padding: 0 2px 4px;
  flex: 0 0 auto;
}

.cw-quickcalls__list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 auto;
}

.cw-quickcalls .cw-call__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--cw-border);
  border-radius: 12px;
  background: var(--cw-surface-raised);
  min-width: 0;
}

.cw-quickcalls .cw-call__row:last-child {
  border-bottom: 1px solid var(--cw-border);
}

.cw-quickcalls .cw-call__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--cw-text);
  font-size: 13px;
  font-weight: 600;
}

.cw-quickcalls .cw-call__row .cw-btn {
  flex: 0 0 auto;
  height: 32px;
  min-width: 84px;
  padding: 0 12px;
  border-radius: 10px;
}

.cw-call__note {
  padding-top: 4px;
  font-size: 12px;
  color: var(--cw-text-faint);
}

/* buttons --------------------------------------------------------------------------------- */

.cw-btn--primary {
  border-color: transparent;
  background: var(--cw-accent);
  color: #fff;
}

.cw-btn--primary:hover {
  background: var(--cw-accent-hover);
}

.cw-btn--icon {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1;
}

.cw-btn--star {
  color: #f59e0b;
  font-size: 15px;
}

.cw-btn--star:hover {
  color: #d97706;
}

.cw-btn--call {
  height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  border-color: transparent;
  color: #fff;
  font-weight: 700;
}

.cw-btn--accept {
  background: #16a34a;
}

.cw-btn--accept:hover {
  background: #15803d;
}

.cw-btn--decline {
  background: #dc2626;
}

.cw-btn--decline:hover {
  background: #b91c1c;
}

.cw-btn--ghost-strong {
  background: var(--cw-surface);
  border-color: var(--cw-border);
  color: var(--cw-text);
}

/* Always-on call banner (works outside the «Звонки» page). */
.cw-global-call {
  position: fixed;
  top: 14px;
  left: 50%;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: min(440px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(135deg, #0f172a 0%, #111827 100%);
  color: #f8fafc;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.4);
  transform: translateX(-50%);
}

.cw-global-call__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.cw-global-call__title {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cw-global-call__sub {
  font-size: 11px;
  opacity: 0.75;
}

.cw-global-call__actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.dark .cw-btn--accept,
body.dark .cw-btn--accept,
html.dark .cw-btn--accept {
  background: #22c55e;
  color: #052e16;
}

.dark .cw-btn--decline,
body.dark .cw-btn--decline,
html.dark .cw-btn--decline {
  background: #ef4444;
  color: #450a0a;
}

/* narrow screens ----------------------------------------------------------------------- */

@media (max-width: 980px) {
  .cw-callbody {
    grid-template-columns: minmax(0, 1fr);
    overflow: auto;
  }

  .cw-quickcalls {
    max-height: 280px;
  }

  .cw-stats {
    display: none;
  }
}

@media (max-width: 900px) {
  .cw-page {
    grid-template-columns: minmax(0, 1fr);
  }

  .cw-page__left {
    border-right: 0;
    border-bottom: 1px solid var(--cw-border);
    max-height: 42vh;
  }

  .cw-card--page {
    height: 100%;
    max-height: 100%;
    min-height: 0;
  }

  .cw-hero {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .cw-hero__timer {
    grid-column: 1 / -1;
    font-size: 22px;
  }

  .cw-hero__actions {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cw-hero--ringing,
  .cw-notice {
    animation: none;
  }

  .cw-person--picker:hover {
    transform: none;
  }
}

/* ------------------------------------------------------------------------------------------
 * 1d. Медиа-стек звонков (WebRTC) — contract V4 §13
 * ------------------------------------------------------------------------------------------
 * The live call needs a stage: the video of the peer(s), the local preview and the
 * controls (microphone, camera, hang up). The sound itself lives in a hidden host
 * (`.cw-media-audio`) so it keeps playing when the operator walks to another page.
 * ------------------------------------------------------------------------------------------ */

.cw-media {
  margin: 12px 16px 0;
  border: 1px solid var(--cw-border);
  border-radius: 16px;
  background: var(--cw-surface-raised);
  overflow: hidden;
}

.cw-media__stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  background: #0b1220;
}

.cw-media__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  width: 100%;
  padding: 10px;
}

.cw-media__tile {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: #111827;
}

.cw-media__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111827;
}

.cw-media__name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.65);
  color: #f8fafc;
  font-size: 11px;
  font-weight: 600;
}

.cw-media__placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 26px 16px;
}

.cw-media__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 62px;
  border-radius: 999px;
  background: var(--cw-accent);
  color: #fff;
  font-size: 21px;
  font-weight: 700;
}

.cw-media__hint {
  color: #cbd5f5;
  font-size: 12px;
  text-align: center;
  max-width: 420px;
}

.cw-media__self {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 148px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.45);
  background: #0f172a;
}

.cw-media__video--self {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cw-media__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-top: 1px solid var(--cw-border);
  background: var(--cw-surface);
}

.cw-media__status {
  flex: 1 1 160px;
  min-width: 0;
  font-size: 12px;
  color: var(--cw-text-muted);
}

.cw-btn--off {
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.4);
}

.dark .cw-btn--off,
body.dark .cw-btn--off,
html.dark .cw-btn--off {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.45);
}

/* The hidden host of the remote sound: it must NOT be `display:none` (some browsers
 * stop playing a media element that is not rendered), so it is kept out of the flow. */
.cw-media-audio {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.cw-media__audio {
  width: 1px;
  height: 1px;
}
/* ------------------------------------------------------------------------------------------
 * 5. Accessibility / print / reduced motion
 * ------------------------------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .cw-msg-flash {
    animation: none;
  }
  .cw-typing-chip__dot {
    animation: none;
  }
  .cw-tg-bar__btn,
  .cw-modal,
  .cw-tg-search,
  .cw-toast {
    transition: none !important;
  }
}

/* Print/exports: the transient shell chrome must never leak into a printed conversation. */
@media print {
  .cw-typing-chip,
  .cw-annot,
  .cw-tg-bar,
  .cw-tg-search,
  .cw-modal,
  .cw-toasts,
  .cw-tg-search-btn {
    display: none !important;
  }
}

/* ------------------------------------------------------------------------------------------
 * 6. 1.3.0 feature marks: awaiting-reply highlight + search-jump flash
 * ------------------------------------------------------------------------------------------
 * All selectors below target ONLY our own classes (which the shell adds/removed exclusively
 * on the conversation-list rows, the chat panel and the message wrapper). Nothing here
 * styles native Chatwoot class names, and every rule degrades to no visible effect while
 * the corresponding mark is absent.
 *
 * Palette (lead approval, 30.10): base amber #F5E27A (light theme), #E2B93B (dark theme);
 * rows @10% / @8%, panel @7% / @6%, overdue = slightly stronger + 3px left amber bar.
 * ------------------------------------------------------------------------------------------ */

/* D. Conversation-list row: chat is waiting for the operator's reply (both roles). */
.cw-awaiting-reply {
  background-color: rgba(245, 226, 122, 0.10); /* #F5E27A @ 10% */
}
html.dark .cw-awaiting-reply,
body.dark .cw-awaiting-reply,
.dark .cw-awaiting-reply {
  background-color: rgba(226, 185, 59, 0.08); /* #E2B93B @ 8% */
}

/* D. Overdue (SLA breached): stronger background + 3px amber accent bar on the left.
 * The bar is an inset box-shadow, not a border: zero layout impact on the row. */
.cw-awaiting-reply.cw-awaiting-reply--overdue {
  background-color: rgba(245, 226, 122, 0.16);
  box-shadow: inset 3px 0 0 0 rgba(226, 185, 59, 0.9);
}
html.dark .cw-awaiting-reply--overdue,
body.dark .cw-awaiting-reply--overdue,
.dark .cw-awaiting-reply--overdue {
  background-color: rgba(226, 185, 59, 0.14);
  box-shadow: inset 3px 0 0 0 #e2b93b;
}

/* D. Active chat panel tint: the open conversation itself is awaiting a reply. */
.cw-chat-awaiting {
  background-color: rgba(245, 226, 122, 0.07); /* @ 7% */
}
html.dark .cw-chat-awaiting,
body.dark .cw-chat-awaiting,
.dark .cw-chat-awaiting {
  background-color: rgba(226, 185, 59, 0.06); /* @ 6% */
}

/* E4. Flash on the message reached from a search jump (Telegram-style): one 3 s ease-out
 * pulse from amber to transparent. The JS adds the class to the existing
 * [data-message-id] wrapper and removes it on animationend (3200 ms fallback), so the
 * animation itself is the entire highlight; after removal the wrapper returns to its
 * normal styling. */
.cw-msg-flash {
  animation: cw-flash 3s ease-out 1;
}
@keyframes cw-flash {
  0% {
    background-color: rgba(245, 226, 122, 0.55);
  }
  100% {
    background-color: transparent;
  }
}
html.dark .cw-msg-flash,
body.dark .cw-msg-flash,
.dark .cw-msg-flash {
  animation-name: cw-flash-dark;
}
@keyframes cw-flash-dark {
  0% {
    background-color: rgba(226, 185, 59, 0.5);
  }
  100% {
    background-color: transparent;
  }
}

/* ========================================================================================
 * 7. Reply-chain block + composer toolbar (1.3.0 wave-2, features e / e5)
 * ----------------------------------------------------------------------------------------
 * Additive UI only: our own classes, own tokens, no foreign selectors touched. The block
 * lives INSIDE the [data-message-id] wrapper, below the bubble (both roles).
 * ===================================================================== */

.cw-reply-chain {
  margin: 2px 0 6px;
  padding: 2px 0 0 4px;
  max-width: 78%;
  font-size: 12px;
  line-height: 1.35;
}
.cw-reply-chain__head {
  color: #b45309;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  padding: 1px 4px;
  border-radius: 4px;
}
.cw-reply-chain__head:hover {
  background-color: rgba(245, 226, 122, 0.18);
}
.cw-reply-chain__body {
  display: none;
  margin: 2px 0 4px 2px;
  border-left: 2px solid rgba(245, 226, 122, 0.55);
  padding: 2px 0 2px 8px;
}
.cw-reply-chain--open .cw-reply-chain__body {
  display: block;
}
.cw-reply-chain__link {
  margin: 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw-reply-chain__sender {
  font-weight: 600;
  margin-right: 6px;
}
.cw-reply-chain__excerpt {
  opacity: 0.85;
  margin-right: 6px;
}
.cw-reply-chain__ts {
  opacity: 0.55;
  font-size: 11px;
}
html.dark .cw-reply-chain__head,
body.dark .cw-reply-chain__head,
.dark .cw-reply-chain__head {
  color: #e2b93b;
}
html.dark .cw-reply-chain__head:hover,
body.dark .cw-reply-chain__head:hover,
.dark .cw-reply-chain__head:hover {
  background-color: rgba(226, 185, 59, 0.14);
}
html.dark .cw-reply-chain__body,
body.dark .cw-reply-chain__body,
.dark .cw-reply-chain__body {
  border-left-color: rgba(226, 185, 59, 0.45);
}

.cw-composer-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px 0;
}
.cw-composer-toolbar__btn {
  min-width: 24px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid rgba(100, 116, 139, 0.35);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.4;
}
.cw-composer-toolbar__btn:hover {
  background-color: rgba(100, 116, 139, 0.12);
}
.cw-composer-toolbar__btn[data-cw-cmd='italic'] {
  font-style: italic;
  font-weight: 600;
}
.cw-composer-toolbar__btn[data-cw-cmd='strikeThrough'] {
  text-decoration: line-through;
  font-weight: 600;
}

/* ==========================================================================================
 * 9b. Quick replies - the "/" door into Chatwoot's own canned responses (1.3.4, §4 A4)
 * ------------------------------------------------------------------------------------------
 * Only our own `cw-quick-replies*` classes; nothing here targets a native selector, so a
 * Chatwoot upgrade cannot be broken by this block. The button deliberately reuses
 * `.cw-composer-toolbar__btn` so it sits in the same visual language as B/I/S.
 * ======================================================================================== */
.cw-quick-replies {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 6px;
  padding-left: 8px;
  border-left: 1px solid rgba(100, 116, 139, 0.3);
}
.cw-quick-replies__btn {
  font-weight: 700;
  letter-spacing: 0.02em;
}
/* Transient explanation ("нужен пробел…", "шаблоны не настроены…"). It reports a state the
 * operator must act on, so it is styled as information, not as an error. */
.cw-quick-replies__hint {
  font-size: 11px;
  line-height: 1.3;
  color: #b45309;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46ch;
}
.dark .cw-quick-replies__hint,
body.dark .cw-quick-replies__hint {
  color: #fbbf24;
}
@media (prefers-reduced-motion: reduce) {
  .cw-quick-replies__hint {
    transition: none;
  }
}
@media (max-width: 767px) {
  /* On narrow screens the hint would crowd the composer row; the aria-live `role="status"`
   * still announces it to assistive tech, so hiding it visually loses no information. */
  .cw-quick-replies__hint {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .cw-reply-chain__head {
    transition: none;
  }
}

/* ========================================================================================
 * 8. Conversation SLA strip (1.3.2, contract v2 §4 A2)
 * ----------------------------------------------------------------------------------------
 * One additive row inside the native conversation column, immediately below the native
 * header (see chatwoot-custom.js section 19). Only our own classes: nothing here targets a
 * native Chatwoot selector, and every rule degrades to no visible effect while the strip is
 * absent. Palette follows the 1.3.0 amber family (light #F5E27A / dark #E2B93B), with a
 * stronger red-ish treatment for a breached deadline so "overdue" is unmistakable.
 * ===================================================================== */

.cw-sla-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;                 /* keeps its own line; never squeezed by the message list */
  padding: 3px 12px;
  font-size: 12px;
  line-height: 1.5;
  border-bottom: 1px solid rgba(100, 116, 139, 0.25);
  background-color: rgba(245, 226, 122, 0.10); /* #F5E27A @ 10%: SLA open, on track */
  color: inherit;
}
html.dark .cw-sla-strip,
body.dark .cw-sla-strip,
.dark .cw-sla-strip {
  background-color: rgba(226, 185, 59, 0.08);  /* #E2B93B @ 8% */
  border-bottom-color: rgba(148, 163, 184, 0.22);
}

/* A. Static caption. */
.cw-sla-strip__label {
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

/* B. Deadline + remaining time: the two numbers the operator acts on. */
.cw-sla-strip__due {
  font-weight: 600;
}
.cw-sla-strip__remaining {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* C. Who is being waited on. The operator is the one who owes an answer, so that state is
 * the loud one; "ждём клиента" stays quiet (nothing for the operator to do). */
.cw-sla-strip__waiting {
  opacity: 0.85;
}
.cw-sla-strip--waiting-operator .cw-sla-strip__waiting {
  font-weight: 700;
  opacity: 1;
  color: #b45309;
}
html.dark .cw-sla-strip--waiting-operator .cw-sla-strip__waiting,
body.dark .cw-sla-strip--waiting-operator .cw-sla-strip__waiting,
.dark .cw-sla-strip--waiting-operator .cw-sla-strip__waiting {
  color: #e2b93b;
}

/* D. Overdue: the deadline is breached. Stronger background plus a left accent bar drawn as
 * an inset box-shadow, so it costs zero layout (the 1.3.0 row precedent). */
.cw-sla-strip--overdue {
  background-color: rgba(239, 68, 68, 0.14);
  box-shadow: inset 3px 0 0 0 #dc2626;
}
.cw-sla-strip--overdue .cw-sla-strip__remaining,
.cw-sla-strip--overdue .cw-sla-strip__due {
  color: #b91c1c;
}
html.dark .cw-sla-strip--overdue,
body.dark .cw-sla-strip--overdue,
.dark .cw-sla-strip--overdue {
  background-color: rgba(248, 113, 113, 0.16);
  box-shadow: inset 3px 0 0 0 #f87171;
}
html.dark .cw-sla-strip--overdue .cw-sla-strip__remaining,
body.dark .cw-sla-strip--overdue .cw-sla-strip__remaining,
.dark .cw-sla-strip--overdue .cw-sla-strip__remaining,
html.dark .cw-sla-strip--overdue .cw-sla-strip__due,
body.dark .cw-sla-strip--overdue .cw-sla-strip__due,
.dark .cw-sla-strip--overdue .cw-sla-strip__due {
  color: #fca5a5;
}

/* E. Narrow viewports: the strip wraps instead of overflowing the header column. */
@media (max-width: 640px) {
  .cw-sla-strip {
    gap: 6px;
    padding: 3px 8px;
  }
}

/* ========================================================================================
 * 9. CRM chat card in the native conversation (1.3.3, contract v2 §4 A1)
 * ----------------------------------------------------------------------------------------
 * One additive row directly below the native header, rendered by chatwoot-custom.js
 * section 20 and placed on its own line for the same measured reason as the SLA strip:
 * the header is a `space-between` flex row whose left group is a flexible absorber, so a
 * card inside it steals width from the conversation TITLE (measured: 899 -> 570 px at
 * 1720 px, and it moves the native action buttons at 1280 px). On its own row every native
 * geometry is untouched and only the message list shifts down.
 *
 * Only our own `cw-chat-card*` classes: nothing here targets a native selector, and every
 * rule is inert while the card is absent. The SLA strip (section 8) stays visually dominant
 * because a deadline is more urgent than a summary; the card is deliberately quieter.
 * ===================================================================== */

.cw-chat-card {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;                 /* keeps its own line; never squeezed by the message list */
  padding: 4px 12px;
  font-size: 12px;
  line-height: 1.5;
  border-bottom: 1px solid rgba(100, 116, 139, 0.2);
  background-color: rgba(100, 116, 139, 0.06); /* deliberately neutral: it is a summary */
  color: inherit;
}
html.dark .cw-chat-card,
body.dark .cw-chat-card,
.dark .cw-chat-card {
  background-color: rgba(148, 163, 184, 0.08);
  border-bottom-color: rgba(148, 163, 184, 0.18);
}

/* A. The CRM chat title. Truncates rather than overflowing the column. */
.cw-chat-card__title {
  font-weight: 700;
  max-width: 42ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* B. Who owes the next answer - the same vocabulary as the SLA strip, so the two rows agree. */
.cw-chat-card__waiting {
  opacity: 0.8;
}
.cw-chat-card--waiting-operator .cw-chat-card__waiting {
  font-weight: 700;
  opacity: 1;
  color: #b45309;
}
html.dark .cw-chat-card--waiting-operator .cw-chat-card__waiting,
body.dark .cw-chat-card--waiting-operator .cw-chat-card__waiting,
.dark .cw-chat-card--waiting-operator .cw-chat-card__waiting {
  color: #e2b93b;
}

/* C. SLA presence. A breached deadline reuses the strip's red language so the two rows never
 * contradict each other visually. */
.cw-chat-card__sla {
  font-weight: 600;
  opacity: 0.85;
}
.cw-chat-card--overdue {
  background-color: rgba(239, 68, 68, 0.10);
  box-shadow: inset 3px 0 0 0 #dc2626;
}
.cw-chat-card--overdue .cw-chat-card__sla {
  color: #b91c1c;
  opacity: 1;
}
html.dark .cw-chat-card--overdue,
body.dark .cw-chat-card--overdue,
.dark .cw-chat-card--overdue {
  background-color: rgba(248, 113, 113, 0.12);
  box-shadow: inset 3px 0 0 0 #f87171;
}
html.dark .cw-chat-card--overdue .cw-chat-card__sla,
body.dark .cw-chat-card--overdue .cw-chat-card__sla,
.dark .cw-chat-card--overdue .cw-chat-card__sla {
  color: #fca5a5;
}

/* D. The doorway to the ONE existing CRM surface. Pushed to the right edge of the row so it
 * reads as an action, not as more summary text. */
.cw-chat-card__open {
  margin-left: auto;
  padding: 2px 10px;
  font: inherit;
  font-weight: 600;
  color: inherit;
  cursor: pointer;
  background-color: rgba(100, 116, 139, 0.12);
  border: 1px solid rgba(100, 116, 139, 0.3);
  border-radius: 6px;
}
.cw-chat-card__open:hover {
  background-color: rgba(100, 116, 139, 0.2);
}
.cw-chat-card__open:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}
html.dark .cw-chat-card__open,
body.dark .cw-chat-card__open,
.dark .cw-chat-card__open {
  background-color: rgba(148, 163, 184, 0.16);
  border-color: rgba(148, 163, 184, 0.3);
}

/* E. Narrow viewports: wrap instead of overflowing the conversation column. */
@media (max-width: 640px) {
  .cw-chat-card {
    gap: 6px;
    padding: 4px 8px;
  }
  .cw-chat-card__title {
    max-width: 100%;
  }
}

/* F. Reduced motion: nothing here animates, but the button must stay clearly interactive. */
@media (prefers-reduced-motion: reduce) {
  .cw-chat-card__open {
    transition: none;
  }
}

/* ==========================================================================================
 * 22. Typing-lock chip (v2, contract V3 §4.1)
 * ------------------------------------------------------------------------------------------
 * One additive row above the native composer (.reply-box); light + dark; nothing native is
 * ever restyled. The pulsing dot is the only animation and it degrades to static under
 * prefers-reduced-motion (section 5).
 * ========================================================================================== */

.cw-typing-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 2px 12px 4px;
  padding: 2px 10px;
  font-family: var(--cw-font);
  font-size: 12px;
  line-height: 1.5;
  color: #047857;
  background-color: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 999px;
  user-select: none;
  font-variant-numeric: tabular-nums;
  transition: opacity 200ms ease;
}

.cw-typing-chip__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: currentColor;
  animation: cw-typing-pulse 1.2s ease-in-out infinite;
}

@keyframes cw-typing-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.cw-typing-chip__text {
  max-width: 42ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The early re-arm state (>60 s TTL): quieter, «ждём <username>». */
.cw-typing-chip--waiting {
  color: #64748b;
  background-color: rgba(100, 116, 139, 0.1);
  border-color: rgba(100, 116, 139, 0.3);
}
.cw-typing-chip--waiting .cw-typing-chip__dot {
  animation-duration: 2.6s;
}

html.dark .cw-typing-chip,
body.dark .cw-typing-chip,
.dark .cw-typing-chip {
  color: #34d399;
  background-color: rgba(16, 185, 129, 0.14);
  border-color: rgba(52, 211, 153, 0.35);
}
html.dark .cw-typing-chip--waiting,
body.dark .cw-typing-chip--waiting,
.dark .cw-typing-chip--waiting {
  color: #9aa4ad;
  background-color: rgba(148, 163, 184, 0.12);
  border-color: rgba(148, 163, 184, 0.3);
}

/* ==========================================================================================
 * 23. TG annotations on mirrored message bubbles (v2, contract V3 §4.2)
 * ------------------------------------------------------------------------------------------
 * Overlay rows INSIDE the existing [data-message-id] wrappers (update-in-place, no invented
 * bubbles). `.cw-msg-tombstone` is OUR OWN class on the wrapper - the only rule here that
 * touches descendants of native nodes, and it only blurs the deleted text (reversible).
 * ========================================================================================== */

.cw-annot {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 2px 0 6px;
  max-width: 78%;
  font-family: var(--cw-font);
  font-size: 11px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.cw-annot__badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

/* Badges: «изменено» (amber) and «удалено в TG» (soft grey). Tooltips ride title=. */
.cw-annot__badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
  cursor: default;
}
.cw-annot__badge--edited {
  color: #b45309;
  background-color: rgba(245, 226, 122, 0.22);
  border: 1px solid rgba(226, 185, 59, 0.4);
}
.cw-annot__badge--deleted {
  color: var(--cw-text-muted, #64748b);
  background-color: rgba(100, 116, 139, 0.12);
  border: 1px solid rgba(100, 116, 139, 0.28);
}

.cw-annot__history-row {
  display: block;
  max-width: 46ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-left: 6px;
  margin-left: 2px;
  border-left: 2px solid rgba(226, 185, 59, 0.55);
  font-weight: 400;
}

/* Delivery ticks on OUTGOING bubbles; failed is deliberately loud. */
.cw-annot__tick {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  border-radius: 999px;
  font-weight: 700;
  cursor: default;
}
.cw-annot__tick--pending { color: #64748b; }
.cw-annot__tick--sent { color: #047857; }
.cw-annot__tick--failed {
  color: #b91c1c;
  background-color: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
}

/* Reaction chips under the bubble: emoji×N; «me» is highlighted. */
.cw-annot__chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.cw-annot__tip-host {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.cw-annot__tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  z-index: 40;
  min-width: 120px;
  max-width: 220px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.96);
  color: #f8fafc;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.28);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-50%) translateY(2px);
  transition: opacity 120ms ease, transform 120ms ease, visibility 120ms ease;
}
.cw-annot__tip-host:hover .cw-annot__tip,
.cw-annot__tip-host:focus-within .cw-annot__tip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
.cw-annot__tip-head {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #94a3b8;
}
.cw-annot__tip-row,
.cw-annot__tip-empty,
.cw-annot__tip-more {
  display: block;
  font-size: 11px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw-annot__tip-more {
  margin-top: 2px;
  color: #94a3b8;
}
.cw-annot__tip-empty {
  color: #cbd5e1;
}
.cw-annot__tip-host--has .cw-annot__tick--sent {
  color: #0284c7;
}
.cw-annot__chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  font: inherit;
  font-size: 12px;
  line-height: 1.5;
  color: inherit;
  background-color: rgba(100, 116, 139, 0.1);
  border: 1px solid rgba(100, 116, 139, 0.28);
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 120ms ease-in-out, border-color 120ms ease-in-out;
}
.cw-annot__chip-emoji {
  flex: 0 0 auto;
  line-height: 1;
}
.cw-annot__chip-count {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 600;
  opacity: 0.78;
}
.cw-annot__chip:hover {
  background-color: rgba(100, 116, 139, 0.18);
}
.cw-annot__chip--me {
  color: #1d4ed8;
  background-color: rgba(31, 147, 255, 0.14);
  border-color: rgba(31, 147, 255, 0.55);
  box-shadow: inset 0 -2px 0 0 rgba(31, 147, 255, 0.6);  /* the «me» underline */
  font-weight: 700;
}
.cw-annot__chip--me:hover {
  background-color: rgba(31, 147, 255, 0.22);
}
.cw-annot__chip:focus-visible {
  outline: 2px solid var(--cw-accent);
  outline-offset: 1px;
}

/* Deleted-in-TG: soft blur over the mirrored text, one click reveals (class on the wrapper
 * is ours alone; the rules below only ever touch what is inside a .cw-msg-tombstone). */
.cw-msg-tombstone .right-bubble,
.cw-msg-tombstone .left-bubble,
.cw-msg-tombstone [data-bubble-name] {
  filter: blur(3.5px);
  transition: filter 160ms ease;
}
.cw-msg-tombstone.cw-msg-revealed .right-bubble,
.cw-msg-tombstone.cw-msg-revealed .left-bubble,
.cw-msg-tombstone.cw-msg-revealed [data-bubble-name] {
  filter: none;
}
.cw-msg-tombstone {
  cursor: pointer;
}

html.dark .cw-annot__badge--edited,
body.dark .cw-annot__badge--edited,
.dark .cw-annot__badge--edited {
  color: #e2b93b;
  background-color: rgba(226, 185, 59, 0.16);
  border-color: rgba(226, 185, 59, 0.4);
}
html.dark .cw-annot__badge--deleted,
body.dark .cw-annot__badge--deleted,
.dark .cw-annot__badge--deleted {
  color: #9aa4ad;
}
html.dark .cw-annot__chip,
body.dark .cw-annot__chip,
.dark .cw-annot__chip {
  background-color: rgba(148, 163, 184, 0.14);
  border-color: rgba(148, 163, 184, 0.3);
}
html.dark .cw-annot__chip--me,
body.dark .cw-annot__chip--me,
.dark .cw-annot__chip--me {
  color: #7cb8ff;
  background-color: rgba(31, 147, 255, 0.2);
  border-color: rgba(124, 184, 255, 0.5);
  box-shadow: inset 0 -2px 0 0 rgba(124, 184, 255, 0.6);
}
html.dark .cw-annot__tick--sent,
body.dark .cw-annot__tick--sent,
.dark .cw-annot__tick--sent {
  color: #34d399;
}
html.dark .cw-annot__tick--failed,
body.dark .cw-annot__tick--failed,
.dark .cw-annot__tick--failed {
  color: #fca5a5;
}
html.dark .cw-annot__tick--pending,
body.dark .cw-annot__tick--pending,
.dark .cw-annot__tick--pending {
  color: #9aa4ad;
}

/* ==========================================================================================
 * 24. TG action bar + shell modal + mini toasts (v2, contract V3 §5 ADD-1)
 * ========================================================================================== */

/* The bar itself: hover affordance near the bubble. The JS anchors it fixed against the
 * wrapper rect when measurable and lets it flow in-row otherwise (fake-DOM/live parity). */
.cw-tg-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 4px;
  margin: 2px 0 4px;
  width: max-content;
  max-width: 96%;
  font-family: var(--cw-font);
  font-size: 12px;
  line-height: 1.4;
  color: inherit;
  background-color: var(--cw-surface-raised, #f8fafc);
  border: 1px solid var(--cw-border);
  border-radius: 8px;
  box-shadow: var(--cw-shadow);
  z-index: 35;                       /* above message content, below native popovers (>=40) */
}
.cw-tg-bar--fixed {
  position: fixed;
  margin: 0;                         /* anchored by JS (top/right inline styles) */
}

.cw-tg-bar__btn {
  appearance: none;
  min-width: 26px;
  height: 24px;
  padding: 0 7px;
  font: inherit;
  font-size: 13px;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 120ms ease-in-out, border-color 120ms ease-in-out;
}
.cw-tg-bar__btn:hover,
.cw-tg-bar__btn:focus-visible {
  background-color: rgba(100, 116, 139, 0.14);
  border-color: rgba(100, 116, 139, 0.25);
}
.cw-tg-bar__btn--mine {
  background-color: rgba(31, 147, 255, 0.16);
  border-color: rgba(31, 147, 255, 0.5);
}
.cw-tg-bar__btn--delete:hover {
  color: #b91c1c;
  background-color: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
}
.cw-tg-bar__btn:focus-visible {
  outline: 2px solid var(--cw-accent);
  outline-offset: 1px;
}

/* Wrapper carrying the open bar: a faint outline so the operator sees the action target. */
.cw-tg-hover {
  outline: 1px dashed rgba(100, 116, 139, 0.45);
  outline-offset: 2px;
}

/* Shell-style modal (edit / delete confirm / forward). One instance at a time.
 * NOTE: this is the second `.cw-modal` rule — the first one (the group dialog
 * above) and this one declare the same z-index on purpose. The cascade merges
 * the two, so keep them in sync: a divergent z-index here would let one modal
 * variant sink under our bars while the other stays above them. */
.cw-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(15, 23, 42, 0.45);
  z-index: 70;                       /* under native modals (100), above our bars */
  font-family: var(--cw-font);
}
.cw-modal__card {
  position: relative;                /* the close button anchors to the card */
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(480px, calc(100vw - 32px));
  max-height: min(560px, calc(100vh - 48px));
  overflow: auto;
  padding: 14px 16px;
  background-color: var(--cw-surface, #ffffff);
  color: var(--cw-text, #0f172a);
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  box-shadow: var(--cw-shadow);
}
.cw-modal__title {
  font-size: 14px;
  font-weight: 700;
  padding-right: 24px;
}
.cw-modal__close {
  position: absolute;
  top: 8px;
  right: 8px;
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  opacity: 0.7;
}
.cw-modal__close:hover { opacity: 1; }
.cw-modal__body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cw-modal__text {
  font-size: 13px;
  line-height: 1.5;
}
.cw-modal__input,
.cw-modal__textarea {
  font: inherit;
  font-size: 13px;
  color: inherit;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 9px;
  background-color: var(--cw-surface-raised, #f8fafc);
  border: 1px solid var(--cw-border);
  border-radius: 6px;
  resize: vertical;
}
.cw-modal__input:focus,
.cw-modal__textarea:focus {
  outline: 2px solid var(--cw-accent);
  outline-offset: 0;
}
.cw-modal__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 200px;
  overflow: auto;
  border: 1px solid var(--cw-border);
  border-radius: 6px;
  padding: 3px;
}
.cw-modal__row {
  appearance: none;
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 5px;
  padding: 5px 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw-modal__row:hover {
  background-color: rgba(100, 116, 139, 0.14);
}
.cw-modal__empty {
  font-size: 12px;
  color: var(--cw-text-muted, #64748b);
  padding: 6px 8px;
}
.cw-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.cw-modal__btn {
  appearance: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: inherit;
  padding: 5px 14px;
  background-color: rgba(100, 116, 139, 0.12);
  border: 1px solid rgba(100, 116, 139, 0.3);
  border-radius: 7px;
  cursor: pointer;
}
.cw-modal__btn:hover {
  background-color: rgba(100, 116, 139, 0.2);
}
.cw-modal__btn--primary {
  color: #ffffff;
  background-color: #1f93ff;
  border-color: #1f93ff;
}
.cw-modal__btn--primary:hover {
  background-color: #1a7fe0;
}
.cw-modal__btn--danger {
  color: #ffffff;
  background-color: #dc2626;
  border-color: #dc2626;
}
.cw-modal__btn--danger:hover {
  background-color: #b91c1c;
}
.cw-modal__btn:focus-visible {
  outline: 2px solid var(--cw-accent);
  outline-offset: 1px;
}
html.dark .cw-modal,
body.dark .cw-modal,
.dark .cw-modal {
  background-color: rgba(0, 0, 0, 0.6);
}

/* Mini toasts: top-center, 2.5 s, never blocking (pointer-events: none on the stack). */
.cw-toasts {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 80;
  pointer-events: none;
  font-family: var(--cw-font);
}
.cw-toast {
  max-width: min(420px, 90vw);
  padding: 6px 14px;
  font-size: 12.5px;
  line-height: 1.45;
  color: #f8fafc;
  background-color: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  box-shadow: var(--cw-shadow);
  animation: cw-toast-in 150ms ease-out 1;
}
.cw-toast--err {
  background-color: rgba(153, 27, 27, 0.95);
  border-color: rgba(248, 113, 113, 0.5);
}
@keyframes cw-toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================================
 * 25. TG deep search (v2) - overlay + header button
 * ========================================================================================== */

/* The header button next to the native icons of the conversations list. */
.cw-tg-search-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 6px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--cw-text, #0f172a);
  background-color: rgba(100, 116, 139, 0.1);
  border: 1px solid rgba(100, 116, 139, 0.3);
  border-radius: 7px;
  padding: 3px 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease-in-out;
}
.cw-tg-search-btn:hover {
  background-color: rgba(100, 116, 139, 0.2);
}
.cw-tg-search-btn:focus-visible {
  outline: 2px solid var(--cw-accent);
  outline-offset: 1px;
}
html.dark .cw-tg-search-btn,
body.dark .cw-tg-search-btn,
.dark .cw-tg-search-btn {
  color: #e5e7eb;
  background-color: rgba(148, 163, 184, 0.14);
  border-color: rgba(148, 163, 184, 0.32);
}

/* The overlay panel (no iframe): dim backdrop + centered column, Esc/backdrop closes. */
.cw-tg-search {
  position: fixed;
  inset: 0;
  z-index: 60;                       /* above bars, under our modal (70) and native modals */
  font-family: var(--cw-font);
}
.cw-tg-search__backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.45);
}
html.dark .cw-tg-search__backdrop,
body.dark .cw-tg-search__backdrop,
.dark .cw-tg-search__backdrop {
  background-color: rgba(0, 0, 0, 0.6);
}
.cw-tg-search__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(680px, calc(100vw - 32px));
  max-height: min(78vh, 640px);
  margin: 7vh auto 0;
  padding: 14px 16px;
  box-sizing: border-box;
  overflow: auto;
  background-color: var(--cw-surface, #ffffff);
  color: var(--cw-text, #0f172a);
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  box-shadow: var(--cw-shadow);
}
.cw-tg-search__head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cw-tg-search__title {
  font-size: 15px;
  font-weight: 700;
  flex: 1 1 auto;
}
.cw-tg-search__close {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 20px;
  line-height: 1;
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.7;
}
.cw-tg-search__close:hover {
  opacity: 1;
  background-color: rgba(100, 116, 139, 0.14);
}
.cw-tg-search__controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.cw-tg-search__input {
  flex: 1 1 220px;
  min-width: 200px;
  font: inherit;
  font-size: 13px;
  color: inherit;
  padding: 6px 10px;
  box-sizing: border-box;
  background-color: var(--cw-surface-raised, #f8fafc);
  border: 1px solid var(--cw-border);
  border-radius: 7px;
}
.cw-tg-search__input:focus {
  outline: 2px solid var(--cw-accent);
  outline-offset: 0;
}
.cw-tg-search__select,
.cw-tg-search__date {
  font: inherit;
  font-size: 12.5px;
  color: inherit;
  padding: 5px 8px;
  background-color: var(--cw-surface-raised, #f8fafc);
  border: 1px solid var(--cw-border);
  border-radius: 7px;
}
.cw-tg-search__check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: inherit;
  cursor: pointer;
  user-select: none;
}
.cw-tg-search__results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: auto;
  min-height: 120px;
}
.cw-tg-search__empty {
  padding: 18px 8px;
  text-align: center;
  font-size: 13px;
  color: var(--cw-text-muted, #64748b);
}
.cw-tg-search__hit {
  padding: 7px 10px;
  border: 1px solid var(--cw-border);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 120ms ease-in-out, border-color 120ms ease-in-out;
}
.cw-tg-search__hit:hover {
  background-color: rgba(100, 116, 139, 0.08);
  border-color: rgba(31, 147, 255, 0.5);
}
.cw-tg-search__hit--deleted .cw-tg-search__hit-snippet {
  opacity: 0.7;
}
.cw-tg-search__hit-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}
.cw-tg-search__hit-title {
  font-weight: 700;
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}
.cw-tg-search__hit-when {
  font-size: 11px;
  color: var(--cw-text-muted, #64748b);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cw-tg-search__hit-deleted {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 700;
  padding: 0 6px;
  border-radius: 999px;
  color: #64748b;
  border: 1px solid rgba(100, 116, 139, 0.4);
  white-space: nowrap;
}
.cw-tg-search__hit-snippet {
  font-size: 12.5px;
  line-height: 1.5;
  word-break: break-word;
}
.cw-tg-search__hit-snippet mark {
  background-color: rgba(245, 226, 122, 0.65);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}
html.dark .cw-tg-search__hit-snippet mark,
body.dark .cw-tg-search__hit-snippet mark,
.dark .cw-tg-search__hit-snippet mark {
  background-color: rgba(226, 185, 59, 0.4);
}
.cw-tg-search__count {
  font-size: 11.5px;
  color: var(--cw-text-muted, #64748b);
  padding: 2px 2px 0;
}
.cw-tg-search__foot {
  font-size: 11.5px;
  color: var(--cw-text-muted, #64748b);
}
/* Photos and videos in a text bubble (caption or a "[photo]" label) are stored
 * files. Chatwoot draws them as a 72px chip, which reads as "the file is missing".
 * Show the file large enough to read a payment receipt. Click opens the original. */
[data-message-id] .cursor-pointer:has(> img),
[data-message-id] .cursor-pointer:has(video) {
  width: min(440px, 100%) !important;
  height: auto !important;
  max-height: none !important;
  aspect-ratio: auto !important;
}
[data-message-id] .cursor-pointer:has(> img) img,
[data-message-id] .cursor-pointer:has(video) video {
  width: 100% !important;
  height: auto !important;
  max-height: 640px !important;
  object-fit: contain !important;
  background: #0f172a;
}
.cw-media-label-hidden {
  display: none !important;
}

@media (max-width: 640px) {
  .cw-tg-search__panel {
    margin: 4vh auto 0;
    width: calc(100vw - 20px);
  }
  .cw-tg-search-btn {
    padding: 3px 7px;
  }
}

