/* The chat in WhatsApp's layout, in Faheem's colours (client channels + team messenger). Loaded last: it restyles the
   .cx-* pieces of app.css / brand.css and adds the new ones (emoji picker, menu arrow, unread line, drafts, formatting).
   Tokens only: every tint is a color-mix of the theme tokens, so light and dark both follow. */
:root {
  --wa-wall: color-mix(in srgb, var(--champ) 22%, var(--surface-2));
  --wa-doodle: color-mix(in srgb, var(--heading) 8%, transparent);
  --wa-out: color-mix(in srgb, var(--accent) 20%, var(--surface));
  --wa-in: var(--surface);
  --wa-bar: var(--surface-2);
  --wa-shadow: 0 1px .5px color-mix(in srgb, var(--heading) 16%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --wa-wall: var(--bg); --wa-doodle: color-mix(in srgb, var(--text) 5%, transparent); --wa-out: color-mix(in srgb, var(--accent) 42%, var(--surface)); --wa-in: var(--surface-3); --wa-bar: var(--surface); }
}
:root[data-theme="dark"] { --wa-wall: var(--bg); --wa-doodle: color-mix(in srgb, var(--text) 5%, transparent); --wa-out: color-mix(in srgb, var(--accent) 42%, var(--surface)); --wa-in: var(--surface-3); --wa-bar: var(--surface); }

/* ------------------------------------------------------------------ the conversation list */
.cx-list-h { height: 60px; background: var(--wa-bar); border-block-end: 0; }
.cx-list-h h2 { font-size: 20px; }
.cx-search { margin: 8px 12px 6px; height: 38px; border: 0; border-radius: var(--r-pill); background: var(--surface-3); }
.cx-search:focus-within { background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--accent); }
.cx-search-in { font-size: 14px; }
.cx-tabs { padding: 4px 12px 8px; gap: 8px; }
.cx-tab { font-size: 13px; font-weight: 500; padding: 6px 13px; background: var(--surface-3); color: var(--muted); }
.cx-tab.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.cx-items { padding: 0; gap: 0; }
.cx-ci { padding: 0 12px; gap: 12px; align-items: center; border-radius: 0; min-height: 68px; }
.cx-ci:hover { background: var(--surface-2); }
.cx-ci.on { background: var(--surface-3); }
.cx-ci-main { align-self: stretch; justify-content: center; gap: 3px; border-block-end: 1px solid var(--line-2); padding-block: 10px; }
.cx-ci-top b { font-size: 15.5px; font-weight: 500; color: var(--heading); }
.cx-t { font-size: 11.5px; color: var(--muted); }
.cx-ci:has(.cx-unread) .cx-t { color: var(--accent-text); font-weight: 700; }
.cx-ci:has(.cx-unread) .cx-ci-top b { font-weight: 800; }
.cx-last { font-size: 13.5px; line-height: 1.5; }
.cx-unread { min-width: 21px; height: 21px; line-height: 21px; font-size: 11.5px; }
.cx-draft { color: var(--accent-text); font-weight: 700; }
.cx-ci .cx-no { width: 46px; height: 46px; border-radius: 50%; font-size: 14px; }
.dm-ci .cx-av, .dm-ci .dm-gface { width: 46px; height: 46px; font-size: 17px; }
.cx-group { padding: 12px 14px 6px; font-size: 12.5px; color: var(--accent-text); }
.cx-co { border-radius: 0; }

/* ------------------------------------------------------------------ the conversation: header, wallpaper, bubbles */
.cx-head { background: var(--wa-bar); border-block-end: 0; gap: 12px; }
.cx-head h2 { font-size: 16px; font-weight: 700; }
.cx-head .cx-ibtn { border: 0; background: transparent; border-radius: 50%; }
.cx-head .cx-ibtn:hover { background: var(--surface-3); }
.cx-typing { font-size: 12.5px; font-weight: 700; color: var(--accent-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cx-online { color: var(--accent-text); font-weight: 700; }

.cx-body { background: var(--wa-wall); isolation: isolate; }
.cx-body::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--wa-doodle); pointer-events: none;
  -webkit-mask: var(--wa-tile) 0 0 / 260px 260px; mask: var(--wa-tile) 0 0 / 260px 260px; }
.cx-body { --wa-tile: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260' viewBox='0 0 260 260' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 30h34M22 40h24M22 50h30M16 22h46v36H16z'/%3E%3Cpath d='M104 26v34h40M112 50l9-11 8 6 12-15'/%3E%3Ccircle cx='206' cy='40' r='15'/%3E%3Cpath d='M206 31v18M201 35h7a3 3 0 0 1 0 6h-6a3 3 0 0 0 0 6h8'/%3E%3Cpath d='M30 112l22-22M33 93h.01M49 109h.01'/%3E%3Ccircle cx='33' cy='93' r='4'/%3E%3Ccircle cx='49' cy='109' r='4'/%3E%3Cpath d='M112 92h36v44l-6-4-6 4-6-4-6 4-6-4-6 4zM120 104h20M120 114h14'/%3E%3Cpath d='M192 118v-14M204 118V92M216 118v-20M186 124h36'/%3E%3Cpath d='M18 178h40v30H18zM18 188h40M28 198h8'/%3E%3Cpath d='M110 196a20 20 0 1 1 20 20v-20z'/%3E%3Cpath d='M136 190v-20a20 20 0 0 1 20 20z'/%3E%3Cpath d='M196 176h28v36h-28zM202 184h16v8h-16zM203 200h.01M210 200h.01M217 200h.01M203 206h.01M210 206h.01M217 206h.01'/%3E%3Cpath d='M70 140l4 8 9 1-7 6 2 9-8-5-8 5 2-9-7-6 9-1z'/%3E%3Cpath d='M160 150c6-6 14 0 8 8l-8 8-8-8c-6-8 2-14 8-8z'/%3E%3Cpath d='M76 232h30M76 240h18M236 150v22M225 161h22M80 70l10 10M90 70 80 80M246 232a10 10 0 1 1-20 0 10 10 0 0 1 20 0z'/%3E%3C/svg%3E"); }
.cx-thread { background: none; padding: 12px 5% 10px; gap: 2px; }

/* mine and my side at the end of the line, the others at the start: WhatsApp, mirrored in Arabic by the logical sides */
.cx-msg { max-width: min(78%, 620px); gap: 6px; align-items: flex-start; }
.cx-msg.out { align-self: flex-end; flex-direction: row-reverse; }
.cx-msg.in { align-self: flex-start; flex-direction: row; }
.cx-msg:not(.cont) { margin-block-start: 8px; }
.cx-msg > .cx-av { margin-block-start: 0; }
.cx-bubble { background: var(--wa-in); border: 0; border-radius: 8px; padding: 6px 9px 6px; font-size: 14.2px; line-height: 1.5; box-shadow: var(--wa-shadow); }
.cx-msg.out .cx-bubble { background: var(--wa-out); }
.cx-msg:not(.cont) .cx-bubble::before { top: 0; width: 9px; height: 12px; background: inherit; }
.cx-msg.out:not(.cont) .cx-bubble { border-start-start-radius: 8px; border-start-end-radius: 0; }
.cx-msg.in:not(.cont) .cx-bubble { border-start-end-radius: 8px; border-start-start-radius: 0; }
.cx-msg.out:not(.cont) .cx-bubble::before { inset-inline-start: auto; inset-inline-end: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.cx-msg.in:not(.cont) .cx-bubble::before { inset-inline-end: auto; inset-inline-start: -8px; clip-path: polygon(0 0, 100% 0, 100% 100%); }
[dir="rtl"] .cx-msg.out:not(.cont) .cx-bubble::before { clip-path: polygon(0 0, 100% 0, 100% 100%); }
[dir="rtl"] .cx-msg.in:not(.cont) .cx-bubble::before { clip-path: polygon(0 0, 100% 0, 0 100%); }
.cx-who { margin-block-end: 1px; font-size: 12.8px; }
.cx-who b { font-weight: 700; }
.cx-meta { font-size: 11px; color: var(--muted); gap: 3px; }
.cx-tick.seen, .cx-tick.seen .ic { color: var(--info, var(--accent-text)); }
.cx-day { background: var(--surface); border: 0; box-shadow: var(--wa-shadow); border-radius: 8px; font-size: 12px; font-weight: 500; padding: 5px 12px; margin: 10px 0 4px; position: sticky; top: 4px; z-index: 2; }
.cx-sys { background: color-mix(in srgb, var(--champ) 34%, var(--surface)); border: 0; box-shadow: var(--wa-shadow); border-radius: 8px; }
.cx-msg.in .cx-reacts { inset-inline-start: 10px; inset-inline-end: auto; }
.cx-msg.out .cx-reacts { inset-inline-end: 10px; inset-inline-start: auto; }
.cx-quote { border-radius: 6px; background: color-mix(in srgb, var(--heading) 6%, transparent); border-inline-start: 4px solid var(--accent); }
.cx-msg.out .cx-quote { background: color-mix(in srgb, var(--heading) 8%, transparent); }

/* the hover bar is gone: an arrow inside the bubble opens the menu (computer); press and hold on a phone */
.cx-acts { display: none !important; }
.cx-chev { position: absolute; inset-block-start: 2px; inset-inline-end: 2px; width: 26px; height: 22px; display: grid; place-items: center; border: 0; border-radius: 6px; cursor: pointer; color: var(--muted);
  background: var(--wa-in); opacity: 0; transition: opacity .12s; z-index: 2; }
.cx-msg.out .cx-chev { background: var(--wa-out); }
.cx-msg:hover .cx-chev, .cx-chev:focus-visible { opacity: 1; }
@media (hover: none) { .cx-chev { display: none; } }

/* the menu beside its bubble (computer): no dimmed page */
.cx-sheet-bg.at { display: block; background: transparent; padding: 0; }
.cx-sheet-bg.at .cx-sheet { position: fixed; width: 250px; box-shadow: var(--shadow); }
.cx-sheet-reacts { align-items: center; }
.cx-react-more { color: var(--muted); font: 500 22px/1 var(--font-fig); }

/* text: formatting, links, mono, big emoji */
.cx-tx strong { font-weight: 800; }
.cx-tx em { font-style: italic; }
.cx-link { color: var(--info, var(--accent-text)); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; unicode-bidi: isolate; }
.cx-mono { font: 500 12.8px/1.5 var(--font-fig); background: color-mix(in srgb, var(--heading) 8%, transparent); border-radius: 4px; padding: 1px 5px; }
.cx-mono.block { display: block; white-space: pre-wrap; padding: 6px 8px; margin-block: 2px; }
.cx-tx.jumbo { font-size: 40px; line-height: 1.25; }

/* «رسائل غير مقروءة» and the older-pages loader */
.cx-unreadline { align-self: stretch; display: flex; justify-content: center; margin: 10px -5% 6px; padding: 5px 0; background: color-mix(in srgb, var(--surface) 70%, transparent); }
.cx-unreadline span { background: var(--surface); box-shadow: var(--wa-shadow); border-radius: var(--r-pill); padding: 5px 14px; font-size: 12.5px; font-weight: 500; color: var(--text); }
.cx-older { align-self: center; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); background: var(--surface); box-shadow: var(--wa-shadow); border-radius: var(--r-pill); padding: 5px 12px; }
.cx-older[hidden] { display: none; }
.cx-spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-block-start-color: var(--accent); animation: wa-spin .8s linear infinite; }
@keyframes wa-spin { to { transform: rotate(360deg); } }
.cx-newpill { width: 42px; height: 42px; border: 0; box-shadow: var(--shadow); inset-block-end: 12px; inset-inline-end: 14px; color: var(--muted); }
.cx-newpill .cx-unread[hidden] { display: none; }

/* ------------------------------------------------------------------ the composer */
.cx-comp { background: var(--wa-bar); border-block-start: 0; padding: 8px 12px 10px; }
.cx-comp-row { gap: 6px; align-items: flex-end; }
.cx-comp-row .cx-ibtn { border: 0; background: transparent; border-radius: 50%; width: 42px; height: 42px; color: var(--muted); }
.cx-comp-row .cx-ibtn:hover { background: var(--surface-3); color: var(--heading); }
.cx-box { border: 0; border-radius: 22px; background: var(--surface); min-height: 42px; padding-inline: 6px 12px; gap: 4px; align-items: flex-end; }
.cx-box:focus-within { box-shadow: none; border: 0; }
.cx-text { padding: 10px 2px; font-size: 15px; }
.cx-drop { display: none; }
.cx-emoji-btn { flex: none; width: 34px; height: 42px; display: grid; place-items: center; border: 0; background: transparent; cursor: pointer; font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .7; }
.cx-emoji-btn:hover, .cx-emoji-btn:focus-visible { filter: none; opacity: 1; outline: none; }
.cx-send { width: 42px; height: 42px; border-radius: 50%; }
.cx-replybar { background: var(--surface); border-radius: 10px; border-inline-start: 4px solid var(--accent); }

/* ------------------------------------------------------------------ the emoji picker */
.em-pop { position: fixed; z-index: 90; width: min(340px, calc(100vw - 16px)); height: min(360px, 60vh); display: flex; flex-direction: column; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.em-tabs { display: flex; flex: none; border-block-end: 1px solid var(--line-2); background: var(--wa-bar); }
.em-tab { flex: 1; height: 40px; border: 0; background: transparent; cursor: pointer; font-size: 18px; line-height: 1; border-block-end: 2px solid transparent; filter: grayscale(1); opacity: .65; }
.em-tab.on { border-block-end-color: var(--accent); filter: none; opacity: 1; }
.em-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 6px; display: grid; grid-template-columns: repeat(8, 1fr); align-content: start; gap: 2px; }
.em-it { aspect-ratio: 1; border: 0; background: transparent; border-radius: 8px; cursor: pointer; font-size: 24px; line-height: 1; padding: 0; }
.em-it:hover, .em-it:focus-visible { background: var(--surface-3); outline: none; }
.em-none { grid-column: 1 / -1; text-align: center; color: var(--muted); font-size: 13px; padding: 28px 12px; margin: 0; }

/* ------------------------------------------------------------------ phone */
@media (max-width: 760px) {
  .cx-thread { padding: 10px 8px 10px; }
  .cx-unreadline { margin-inline: -8px; }
  .cx-msg, .cx-msg.wide { max-width: 88%; }
  .cx-msg > .cx-av { display: none; }
  .cx-comp { padding: 6px 6px 8px; padding-block-end: max(8px, env(safe-area-inset-bottom)); }
  .cx-comp-row .cx-ibtn { width: 38px; height: 42px; }
  .cx-send { width: 46px; height: 46px; }
  .cx-list-h h2 { font-size: 22px; }
  .em-pop { inset-inline: 8px; width: auto; }
}
@media (prefers-reduced-motion: reduce) { .cx-spin { animation: none; } .cx-chev { transition: none; } }
/* a big-emoji message: the time sits under it, not over it */
.cx-bubble > .cx-tx.jumbo::after { content: none; }
.cx-bubble > .cx-tx.jumbo + .cx-meta { float: none; margin: 0; justify-content: flex-end; }
.cx-sheet-bg.at .cx-sheet { width: 292px; overflow-x: hidden; }
.cx-sheet-bg.at .cx-sheet-reacts { gap: 0; }
.cx-sheet-bg.at .cx-sheet-reacts button { width: 32px; height: 32px; font-size: 19px; background: transparent; flex: none; }
.cx-sheet-reacts .cx-react-more { background: var(--surface-3); }

/* ================================================================== phase 2: forward, star, pin, select, search */
.cx-chat { position: relative; }
.cx-fwd { display: flex; align-items: center; gap: 4px; font-size: 12px; font-style: italic; color: var(--muted); margin-block-end: 2px; }
.cx-fwd .ic { width: 13px; height: 13px; }
.cx-star { color: var(--muted); font-size: 11px; line-height: 1; }
.cx-starbtn { border: 0; background: transparent; border-radius: 50%; color: var(--muted); font-size: 17px; line-height: 1; }
.cx-starbtn:hover { background: var(--surface-3); color: var(--heading); }
.cx-list-h { gap: 8px; justify-content: flex-start; }

.cx-pinbar { flex: none; display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 6px 16px; border: 0; background: var(--surface); color: var(--text); cursor: pointer; text-align: start; box-shadow: var(--wa-shadow); z-index: 3; }
.cx-pinbar[hidden] { display: none; }
.cx-pinbar > .ic { color: var(--accent-text); flex: none; }
.cx-pin-dots { display: flex; flex-direction: column; gap: 2px; flex: none; }
.cx-pin-dots i { width: 3px; height: 9px; border-radius: 2px; background: var(--line); }
.cx-pin-dots i.on { background: var(--accent); }
.cx-pin-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 12.5px; line-height: 1.4; }
.cx-pin-tx b { color: var(--accent-text); font-weight: 700; }
.cx-pin-tx span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cx-pin-n { color: var(--muted); font-size: 11px; }

.cx-selbar { position: absolute; inset-block-start: 0; inset-inline: 0; height: 60px; z-index: 6; display: flex; align-items: center; gap: 6px; padding: 0 12px; background: var(--wa-bar); border-block-end: 1px solid var(--line); }
.cx-selbar[hidden] { display: none; }
.cx-selbar .cx-ibtn { border: 0; background: transparent; border-radius: 50%; }
.cx-selbar .cx-ibtn:hover:not(:disabled) { background: var(--surface-3); }
.cx-selbar .cx-ibtn:disabled { opacity: .4; cursor: default; }
.cx-sel-n { font-size: 15px; color: var(--heading); margin-inline-start: 6px; }
.cx-chat.selecting .cx-msg { cursor: pointer; }
.cx-chat.selecting .cx-msg:not(.deleted)::after { content: ""; position: absolute; inset-block: -2px; inset-inline: -100vw; z-index: -1; }
.cx-chat.selecting .cx-msg.picked::after { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.cx-chat.selecting .cx-thread { overflow-x: clip; }
.cx-chat.selecting .cx-chev, .cx-chat.selecting .cx-comp { display: none; }

.cx-results { position: absolute; inset-block-start: 8px; inset-inline-end: 12px; z-index: 5; width: min(380px, calc(100% - 24px)); max-height: min(70%, 460px); overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.cx-results[hidden] { display: none; }
.cx-results-h { padding: 8px 14px; font-size: 12px; font-weight: 700; color: var(--muted); border-block-end: 1px solid var(--line-2); }
.cx-result { display: flex; flex-direction: column; gap: 2px; padding: 9px 14px; border: 0; border-block-end: 1px solid var(--line-2); background: transparent; color: var(--text); text-align: start; cursor: pointer; }
.cx-result:hover, .cx-result:focus-visible { background: var(--surface-2); outline: none; }
.cx-result-top { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; }
.cx-result-top b { color: var(--heading); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-result-top .num { color: var(--muted); font-size: 11px; flex: none; }
.cx-result-tx { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cx-result-tx mark { background: var(--accent-soft); color: var(--heading); border-radius: 3px; padding: 0 2px; }

.cx-sheet.fw { width: min(440px, 100%); padding: 0; display: flex; flex-direction: column; max-height: min(82vh, 640px); overflow: hidden; }
.fw-top { padding: 10px 14px 6px; }
.fw-list { flex: 1; min-height: 120px; overflow-y: auto; display: flex; flex-direction: column; }
.fw-row { display: flex; align-items: center; gap: 12px; padding: 9px 16px; cursor: pointer; border-block-end: 1px solid var(--line-2); }
.fw-row:hover { background: var(--surface-2); }
.fw-row input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.fw-row .grow { min-width: 0; display: flex; flex-direction: column; }
.fw-row b { font-size: 14px; color: var(--heading); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fw-row small { font-size: 12px; color: var(--muted); }
.fw-foot { padding: 10px 14px; display: flex; justify-content: flex-end; border-block-start: 1px solid var(--line-2); }
.st-list .cx-result { padding-inline: 16px; }
