/* ---------- Chats: one inbox, Telegram's look ----------
   Channels sidebar (shared .ih-* page sidebar), a Telegram-style chat list,
   the conversation on a soft wallpaper with tailed bubbles, and customer info
   that slides in only when the customer's name is clicked. */

#page-contacts {
  --tg-accent: #3390ec;
  --tg-accent-soft: rgba(51, 144, 236, .1);
  --tg-select: #3390ec;
  --tg-select-text: #ffffff;
  --tg-in: #ffffff;
  --tg-out: #eeffde;
  --tg-out-meta: #4fae4e;
  --tg-meta: #8a9aa9;
  --tg-text: #000000;
  --tg-bubble-shadow: 0 1px 2px rgba(16, 35, 47, .15);
  --tg-wall: #d9e3c7;
  --tg-wall-a: rgba(255, 255, 240, .55);
  --tg-wall-b: rgba(150, 190, 130, .45);
  --tg-pill: rgba(76, 102, 70, .42);
  --tg-bar: #ffffff;
  --tg-green: #4fae4e;
  --tg-warn: #e3a23b;
}
html:not([data-theme="light"]) #page-contacts {
  --tg-accent: #6ab2f2;
  --tg-accent-soft: rgba(106, 178, 242, .12);
  --tg-select: #2b5278;
  --tg-in: #212121;
  --tg-out: #2b5278;
  --tg-out-meta: #8ec5f5;
  --tg-meta: #8e959c;
  --tg-text: #f1f1f1;
  --tg-bubble-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --tg-wall: #0f0f0f;
  --tg-wall-a: rgba(43, 82, 120, .16);
  --tg-wall-b: rgba(70, 90, 60, .12);
  --tg-pill: rgba(255, 255, 255, .1);
  --tg-bar: #1c1c1c;
  --tg-green: #5cb874;
  --tg-warn: #e0a548;
}

/* Frame: the inbox fills the panel; each pane scrolls on its own. */
html:root body.app-page #page-contacts .ih-main.inbox-main { padding: 0 !important; overflow: hidden !important; }
#page-contacts .inbox-grid { position: relative; display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); height: 100%; min-height: 0; overflow: hidden; background: var(--tp-panel); }
#page-contacts .inbox-list-pane,
#page-contacts .inbox-thread-pane { min-width: 0; min-height: 0; }

/* ---- Channels sidebar ---- */
#page-contacts .inbox-nav { gap: 1px; }
#page-contacts .inbox-nav-item,
#page-contacts .inbox-nav-add { display: flex; align-items: center; gap: 9px; width: 100%; height: 32px; padding: 0 9px; border: 0; border-radius: 8px; background: transparent; color: var(--tp-text-2); font: inherit; font-size: 13px; font-weight: 500; text-align: left; text-decoration: none; cursor: pointer; transition: background-color 120ms ease, color 120ms ease; }
#page-contacts .inbox-nav-item:hover,
#page-contacts .inbox-nav-add:hover { background: var(--tp-hover); color: var(--tp-text); }
#page-contacts .inbox-nav-item.is-active { background: var(--tp-active); color: var(--tp-text); }
#page-contacts .inbox-nav-item > span:not(.inbox-nav-initial) { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#page-contacts .inbox-nav-item > b { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--tp-active); color: var(--tp-text-2); font-size: 11.5px; font-weight: 600; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }
#page-contacts .inbox-nav-item > svg,
#page-contacts .inbox-nav-add > svg { flex: 0 0 16px; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#page-contacts .inbox-nav-logo { flex: 0 0 18px; width: 18px; height: 18px; border-radius: 50%; object-fit: contain; }
#page-contacts .inbox-nav-add { margin-top: 4px; color: var(--tp-muted); }
#page-contacts .inbox-nav-label { margin: 16px 9px 5px; color: var(--tp-muted); font-size: 11.5px; font-weight: 500; }
#page-contacts .inbox-nav-empty { margin: 12px 9px 2px; color: var(--tp-muted); font-size: 12.5px; }
#page-contacts .inbox-nav-initial { display: grid; flex: 0 0 18px; place-items: center; width: 18px; height: 18px; border-radius: 50%; color: #fff; font-size: 8.5px; font-weight: 700; }

/* ---- Telegram avatar colours ---- */
#page-contacts [data-tone="0"] { --tone: linear-gradient(#ff885e, #ff516a); }
#page-contacts [data-tone="1"] { --tone: linear-gradient(#ffcd6a, #ffa85c); }
#page-contacts [data-tone="2"] { --tone: linear-gradient(#82b1ff, #665fff); }
#page-contacts [data-tone="3"] { --tone: linear-gradient(#a0de7e, #54cb68); }
#page-contacts [data-tone="4"] { --tone: linear-gradient(#53edd6, #28c9b7); }
#page-contacts [data-tone="5"] { --tone: linear-gradient(#72d5fd, #2a9ef1); }
#page-contacts [data-tone="6"] { --tone: linear-gradient(#e0a2f3, #d669ed); }
#page-contacts .inbox-nav-initial { background: var(--tone, var(--tp-active)); }
#page-contacts .inbox-avatar { position: relative; display: inline-flex; flex: 0 0 auto; }
#page-contacts .inbox-avatar .conversation-avatar { position: relative; display: inline-grid; place-items: center; width: 46px !important; height: 46px !important; flex: 0 0 46px; overflow: hidden; border: 0 !important; border-radius: 50%; background: var(--tone, var(--tp-active)) !important; color: #fff !important; font-size: 16px; font-weight: 600; letter-spacing: 0; }
#page-contacts .inbox-avatar .conversation-avatar-fallback { grid-area: 1 / 1; color: inherit; }
#page-contacts .inbox-avatar .conversation-avatar-image { grid-area: 1 / 1; width: 100%; height: 100%; object-fit: cover; }
#page-contacts .inbox-avatar-badge { position: absolute; right: -1px; bottom: -1px; width: 16px; height: 16px; border: 2px solid var(--tp-panel); border-radius: 50%; background: var(--tp-panel); }

/* ---- Chat list ---- */
#page-contacts .inbox-list-pane { display: flex; flex-direction: column; border-right: 1px solid var(--tp-line); background: var(--tp-panel); }
#page-contacts .inbox-list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 12px 6px 18px; }
#page-contacts .inbox-list-head h1 { margin: 0; overflow: hidden; color: var(--tp-text); font-size: 16px; font-weight: 600; letter-spacing: 0; text-overflow: ellipsis; white-space: nowrap; }
#page-contacts .inbox-icon-btn { display: grid; flex: 0 0 auto; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--tp-muted); cursor: pointer; transition: background-color 120ms ease, color 120ms ease; }
#page-contacts .inbox-icon-btn:hover { background: var(--tp-hover); color: var(--tp-text); }
#page-contacts .inbox-icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#page-contacts .inbox-search { display: flex; align-items: center; gap: 10px; height: 38px; margin: 2px 12px 4px; padding: 0 14px; border-radius: 19px; background: var(--tp-field); box-shadow: inset 0 0 0 1px var(--tp-line); transition: box-shadow 120ms ease; }
html[data-theme="light"] #page-contacts .inbox-search { background: #f1f2f4; box-shadow: none; }
#page-contacts .inbox-search:focus-within { box-shadow: inset 0 0 0 2px var(--tg-accent); background: var(--tp-panel); }
#page-contacts .inbox-search svg { flex: 0 0 17px; width: 17px; height: 17px; fill: none; stroke: var(--tp-muted); stroke-width: 1.8; }
#page-contacts .inbox-search input { flex: 1 1 auto; min-width: 0; height: 100%; padding: 0; border: 0 !important; background: transparent !important; box-shadow: none !important; color: var(--tp-text); font: inherit; font-size: 14px; outline: 0; }
/* Folder tabs with Telegram's blue underline. */
#page-contacts .inbox-tabs { display: flex; gap: 4px; padding: 0 10px; overflow-x: auto; border-bottom: 1px solid var(--tp-line); scrollbar-width: none; }
#page-contacts .inbox-tabs::-webkit-scrollbar { display: none; }
#page-contacts .inbox-tabs button { position: relative; display: inline-flex; flex: 0 0 auto; align-items: center; gap: 6px; height: 40px; padding: 0 10px; border: 0; border-radius: 8px 8px 0 0; background: transparent; color: var(--tp-muted); font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer; white-space: nowrap; }
#page-contacts .inbox-tabs button:hover { background: var(--tp-hover); }
#page-contacts .inbox-tabs button[aria-selected="true"] { color: var(--tg-accent); }
#page-contacts .inbox-tabs button[aria-selected="true"]::after { content: ""; position: absolute; right: 8px; bottom: -1px; left: 8px; height: 3px; border-radius: 3px 3px 0 0; background: var(--tg-accent); }
#page-contacts .inbox-tabs b { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--tp-muted); color: var(--tp-panel); font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums; }
#page-contacts .inbox-tabs button[aria-selected="true"] b { background: var(--tg-accent); color: #fff; }
#page-contacts .inbox-tabs b:empty { display: none; }
#page-contacts .inbox-status:empty { display: none; }
#page-contacts .inbox-status { display: grid; gap: 8px; padding: 14px 18px; color: var(--tp-muted); font-size: 13px; }
#page-contacts .inbox-status.is-error { color: var(--tp-text); }
#page-contacts .inbox-status .btn-secondary { justify-self: start; width: auto !important; height: 30px !important; min-height: 30px !important; padding: 0 12px !important; border-radius: 8px !important; font-size: 12.5px !important; }
#page-contacts .inbox-list { flex: 1 1 auto; min-height: 0; padding: 6px 8px 12px; overflow: hidden auto; scrollbar-width: thin; }
#page-contacts .inbox-list:empty { flex: 0 0 auto; padding: 0; }
#page-contacts .inbox-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 66px; padding: 9px 10px; border: 0; border-radius: 12px; background: transparent; color: var(--tp-text); font: inherit; text-align: left; cursor: pointer; transition: background-color 100ms ease; }
#page-contacts .inbox-row:hover { background: var(--tp-hover); }
#page-contacts .inbox-row-main { display: grid; flex: 1 1 auto; gap: 3px; min-width: 0; }
#page-contacts .inbox-row-top,
#page-contacts .inbox-row-bottom { display: flex; align-items: center; gap: 6px; min-width: 0; }
#page-contacts .inbox-row-top strong { flex: 1 1 auto; min-width: 0; overflow: hidden; font-size: 14.5px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
#page-contacts .inbox-row-top time { flex: 0 0 auto; color: var(--tp-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
#page-contacts .inbox-row-preview { flex: 1 1 auto; min-width: 0; overflow: hidden; color: var(--tp-text-2); font-size: 13.5px; text-overflow: ellipsis; white-space: nowrap; }
#page-contacts .inbox-row-handoff { color: var(--tg-accent); font-style: normal; font-weight: 500; }
#page-contacts .inbox-ticks { flex: 0 0 auto; width: 17px; height: 12px; fill: none; stroke: var(--tg-green); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#page-contacts .inbox-row-waiting { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; background: var(--tg-accent); }
#page-contacts .inbox-row-flag { flex: 0 0 auto; color: #e5534b; font-size: 11.5px; font-weight: 600; }
#page-contacts .inbox-row .conversation-draft-tag { flex: 0 0 auto; height: 18px; padding: 0 6px; border-radius: 5px; font-size: 10.5px; line-height: 18px; }
/* Selected row: Telegram's solid blue. */
#page-contacts .inbox-row.is-selected { background: var(--tg-select); color: var(--tg-select-text); }
#page-contacts .inbox-row.is-selected :is(.inbox-row-top time, .inbox-row-preview, .inbox-row-handoff) { color: rgba(255, 255, 255, .85); }
#page-contacts .inbox-row.is-selected .inbox-ticks { stroke: #fff; }
#page-contacts .inbox-row.is-selected .inbox-row-waiting { background: #fff; }
#page-contacts .inbox-row.is-selected .inbox-avatar-badge { border-color: var(--tg-select); background: var(--tg-select); }

#page-contacts .inbox-empty[hidden] { display: none !important; }
#page-contacts .inbox-empty:not([hidden]) { display: grid; gap: 6px; margin: 14px 18px; padding: 22px 18px; border: 1px dashed var(--tp-line-strong); border-radius: 12px; background: transparent; box-shadow: none; }
#page-contacts .inbox-empty h2 { margin: 0; color: var(--tp-text); font-size: 14px; font-weight: 600; }
#page-contacts .inbox-empty p { margin: 0; color: var(--tp-muted); font-size: 12.5px; line-height: 1.5; }
#page-contacts .inbox-empty-link { margin-top: 4px; color: var(--tg-accent); font-size: 13px; font-weight: 600; text-decoration: none; }

#page-contacts .inbox-skeleton { display: block; height: 52px; border-radius: 12px; background: linear-gradient(90deg, var(--tp-hover), var(--tp-active), var(--tp-hover)); background-size: 200% 100%; animation: inbox-shimmer 1.4s ease-in-out infinite; }
@keyframes inbox-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---- Conversation ---- */
#page-contacts .inbox-thread-pane { display: flex; flex-direction: column; background: var(--tg-wall); }
#page-contacts .inbox-thread-head { position: relative; z-index: 2; display: flex; align-items: center; gap: 6px; min-height: 58px; padding: 6px 12px 6px 14px; border-bottom: 1px solid var(--tp-line); background: var(--tp-panel); }
#page-contacts .inbox-back { display: none; }
#page-contacts .inbox-thread-profile { display: flex; flex: 1 1 auto; align-items: center; gap: 12px; min-width: 0; padding: 4px 8px 4px 4px; border: 0; border-radius: 10px; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
#page-contacts .inbox-thread-profile:hover { background: var(--tp-hover); }
#page-contacts .inbox-thread-profile .conversation-avatar { width: 40px !important; height: 40px !important; flex-basis: 40px; font-size: 15px; }
#page-contacts .inbox-thread-who { display: grid; gap: 1px; min-width: 0; }
#page-contacts .inbox-thread-who > strong { overflow: hidden; color: var(--tp-text); font-size: 15px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
#page-contacts .inbox-thread-who > span { overflow: hidden; color: var(--tg-accent); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
#page-contacts .inbox-thread-who > span b { font-weight: 500; }
#page-contacts .inbox-thread-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 4px; }
#page-contacts .inbox-text-btn { height: 34px; padding: 0 14px; border: 0; border-radius: 9px; background: transparent; color: var(--tg-accent); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background-color 120ms ease; }
#page-contacts .inbox-text-btn:hover { background: var(--tg-accent-soft); }
#page-contacts .inbox-text-btn:disabled { opacity: .5; cursor: default; }
#page-contacts .inbox-text-btn.is-primary { background: #3390ec; color: #fff; }

/* Wallpaper: Telegram's soft gradient, matte. */
#page-contacts .inbox-wall { position: relative; display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; background: radial-gradient(120% 80% at 15% 10%, var(--tg-wall-a), transparent 60%), radial-gradient(110% 90% at 90% 85%, var(--tg-wall-b), transparent 60%), var(--tg-wall); }
#page-contacts .inbox-stream { display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; width: 100%; max-width: 760px; min-height: 0; margin: 0 auto; padding: 14px 18px 10px; overflow: hidden auto; scrollbar-width: thin; outline: 0; }
#page-contacts .inbox-day { position: sticky; top: 4px; z-index: 1; display: flex; justify-content: center; margin: 8px 0; pointer-events: none; }
#page-contacts .inbox-day span { padding: 3px 10px; border-radius: 12px; background: var(--tg-pill); color: #fff; font-size: 12.5px; font-weight: 500; backdrop-filter: blur(6px); }

#page-contacts #inboxThread .employee-conversation-message { position: relative; box-sizing: border-box; display: block; flex: 0 0 auto; align-self: flex-start; width: fit-content; min-width: 64px; max-width: min(78%, 520px); margin: 0 0 0 8px; padding: 6px 10px 6px 11px; border: 0 !important; border-radius: 15px; background: var(--tg-in); box-shadow: var(--tg-bubble-shadow); color: var(--tg-text); font-size: 14.5px; line-height: 1.38; overflow-wrap: anywhere; }
#page-contacts #inboxThread .employee-conversation-message.is-employee { align-self: flex-end; margin: 0 8px 0 0; background: var(--tg-out); }
#page-contacts #inboxThread .employee-conversation-message.is-tail { margin-bottom: 6px; }
#page-contacts #inboxThread .employee-conversation-message.is-customer.is-tail { border-bottom-left-radius: 0; }
#page-contacts #inboxThread .employee-conversation-message.is-employee.is-tail { border-bottom-right-radius: 0; }
/* The tail: a curved corner in the bubble's own colour. */
#page-contacts #inboxThread .employee-conversation-message.is-tail::after { content: ""; position: absolute; bottom: 0; width: 9px; height: 9px; background: inherit; }
#page-contacts #inboxThread .employee-conversation-message.is-customer.is-tail::after { left: -9px; -webkit-mask: radial-gradient(circle at 0 0, transparent 9px, #000 9.5px); mask: radial-gradient(circle at 0 0, transparent 9px, #000 9.5px); }
#page-contacts #inboxThread .employee-conversation-message.is-employee.is-tail::after { right: -9px; -webkit-mask: radial-gradient(circle at 100% 0, transparent 9px, #000 9.5px); mask: radial-gradient(circle at 100% 0, transparent 9px, #000 9.5px); }
#page-contacts #inboxThread .employee-conversation-text { color: var(--tg-text); font-size: 14.5px; line-height: 1.38; }
#page-contacts #inboxThread .employee-conversation-text::after { content: ""; display: block; clear: both; }
#page-contacts #inboxThread .employee-conversation-text :is(p, li) { margin: 0 0 4px; }
#page-contacts #inboxThread .employee-conversation-text p:last-of-type { margin-bottom: 0; }
#page-contacts #inboxThread .employee-conversation-text :is(h1, h2, h3, h4, h5, h6) { margin: 2px 0 3px; color: inherit; font-size: 14.5px; font-weight: 600; letter-spacing: 0; text-transform: none; }
#page-contacts #inboxThread .employee-conversation-text strong { display: inline; margin: 0; color: inherit; font-size: inherit; font-weight: 600; letter-spacing: 0; text-transform: none; }
#page-contacts #inboxThread .employee-conversation-text :is(ul, ol) { margin: 2px 0 4px; padding-left: 18px; }
#page-contacts #inboxThread .employee-conversation-text a { color: var(--tg-accent); }
/* Time (and ticks) sit inside the bubble at the lower right, as in Telegram. */
#page-contacts #inboxThread .employee-conversation-time { position: relative; top: 5px; display: inline-flex; float: right; align-items: center; gap: 3px; margin: 0 -2px 0 10px; color: var(--tg-meta); font-size: 11.5px; line-height: 1.6; text-align: right; font-variant-numeric: tabular-nums; }
#page-contacts #inboxThread .is-employee .employee-conversation-time { color: var(--tg-out-meta); }
#page-contacts #inboxThread .is-employee .inbox-ticks { width: 16px; stroke: var(--tg-out-meta); }
#page-contacts #inboxThread .employee-conversation-message > .employee-conversation-time { display: flex; float: none; justify-content: flex-end; top: 0; margin: 2px 0 0; }
#page-contacts #inboxThread .employee-conversation-source { display: block; margin: 0 0 2px; color: var(--tg-accent); font-size: 13px; font-weight: 600; letter-spacing: 0; text-transform: none; }
#page-contacts #inboxThread .employee-conversation-delivery,
#page-contacts #inboxThread .employee-conversation-observed { display: block; margin: 0 0 2px; color: var(--tg-warn); font-size: 12px; font-weight: 600; }
#page-contacts #inboxThread .employee-conversation-message.is-draft { opacity: .85; outline: 1.5px dashed var(--tg-warn); outline-offset: -1.5px; }
#page-contacts #inboxThread .employee-conversation-memory-context { display: none; }
#page-contacts #inboxThread .employee-conversation-media { display: block; max-width: 100%; max-height: 340px; margin: -2px -6px 4px; border-radius: 12px; }
#page-contacts #inboxThread .employee-conversation-audio { width: min(280px, 100%); margin: 2px 0 4px; }
#page-contacts #inboxThread .employee-conversation-attachment { display: inline-flex; margin: 2px 0 4px; padding: 6px 10px; border-radius: 9px; background: var(--tg-accent-soft); color: var(--tg-accent); font-size: 13px; font-weight: 500; text-decoration: none; }
#page-contacts #inboxThread .employee-conversation-caption { margin-top: 2px; font-size: 14px; }
#page-contacts .employee-conversation-draft-note { align-self: flex-end; max-width: 70%; margin: 0 8px 8px; padding: 4px 10px; border-radius: 10px; background: var(--tg-pill); color: #fff; font-size: 12px; text-align: right; }
#page-contacts .employee-conversation-draft-note a { color: #fff; text-decoration: underline; }

#page-contacts .inbox-thread-empty { display: grid; flex: 1 1 auto; place-content: center; justify-items: center; gap: 10px; padding: 32px; }
#page-contacts .inbox-thread-empty-pill { padding: 4px 12px; border-radius: 14px; background: var(--tg-pill); color: #fff; font-size: 13.5px; font-weight: 500; }
#page-contacts .inbox-thread-pane > .inbox-thread-empty { background: radial-gradient(120% 80% at 15% 10%, var(--tg-wall-a), transparent 60%), radial-gradient(110% 90% at 90% 85%, var(--tg-wall-b), transparent 60%), var(--tg-wall); }
#page-contacts .inbox-thread-loading { display: flex; flex-direction: column; gap: 8px; }
#page-contacts .inbox-thread-loading .inbox-skeleton { width: 46%; height: 38px; border-radius: 15px; background: var(--tg-in); opacity: .7; }
#page-contacts .inbox-thread-loading .is-out { align-self: flex-end; width: 38%; background: var(--tg-out); }

/* Bottom: who is replying, or the owner's composer. */
#page-contacts .inbox-replying,
#page-contacts .inbox-composer { width: calc(100% - 36px); max-width: 724px; margin: 0 auto 16px; }
#page-contacts .inbox-replying { display: flex; align-items: center; gap: 10px; min-height: 50px; padding: 6px 6px 6px 16px; border-radius: 14px; background: var(--tg-bar); box-shadow: var(--tg-bubble-shadow); }
#page-contacts .inbox-replying-copy { display: flex; flex: 1 1 auto; align-items: center; gap: 10px; min-width: 0; color: var(--tp-text-2); font-size: 14px; }
#page-contacts .inbox-replying-copy b { color: var(--tp-text); font-weight: 600; }
#page-contacts .inbox-replying.is-note { justify-content: center; padding-right: 16px; text-align: center; }
#page-contacts .inbox-live-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--tg-green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tg-green) 22%, transparent); animation: inbox-pulse 2.4s ease-in-out infinite; }
@keyframes inbox-pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--tg-green) 8%, transparent); } }
#page-contacts .inbox-composer { display: flex; align-items: flex-end; gap: 8px; }
#page-contacts .inbox-composer-field { display: flex; flex: 1 1 auto; flex-direction: column; justify-content: center; min-width: 0; min-height: 50px; padding: 0; border-radius: 16px; background: var(--tg-bar); box-shadow: var(--tg-bubble-shadow); transition: box-shadow 160ms ease; }
#page-contacts .inbox-composer-field:focus-within { box-shadow: var(--tg-bubble-shadow), 0 0 0 1.5px color-mix(in srgb, var(--tg-accent) 45%, transparent); }
#page-contacts .inbox-composer-row { display: flex; align-items: flex-end; gap: 6px; min-height: 50px; padding: 0 6px 0 16px; }
#page-contacts .inbox-composer-row textarea { align-self: center; padding: 13px 0 !important; }
#page-contacts .inbox-composer textarea { flex: 1 1 auto; min-width: 0; min-height: 22px; max-height: 160px; margin: 0; border: 0 !important; background: transparent !important; box-shadow: none !important; color: var(--tp-text); font: inherit; font-size: 14.5px; line-height: 1.5; resize: none; outline: 0; }
#page-contacts .inbox-send { position: relative; display: grid; flex: 0 0 50px; place-items: center; width: 50px; height: 50px; padding: 0; border: 0; border-radius: 50%; background: #3390ec; color: #fff; box-shadow: 0 2px 8px -2px rgba(51, 144, 236, .55), var(--tg-bubble-shadow); cursor: pointer; transition: transform 160ms cubic-bezier(.3, 1.5, .5, 1), background-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease; }
#page-contacts .inbox-send svg { width: 24px; height: 24px; margin-left: 3px; fill: currentColor; transition: transform 220ms cubic-bezier(.3, 1.5, .5, 1); }
#page-contacts .inbox-composer.has-text .inbox-send:hover { background: #2b84de; transform: scale(1.05); }
#page-contacts .inbox-composer.has-text .inbox-send:active { transform: scale(.92); }
#page-contacts .inbox-composer.has-text .inbox-send svg { transform: rotate(0) scale(1); }
#page-contacts .inbox-composer:not(.has-text) .inbox-send { background: var(--tg-bar); color: var(--tg-meta); box-shadow: var(--tg-bubble-shadow); cursor: default; }
#page-contacts .inbox-composer:not(.has-text) .inbox-send svg { transform: rotate(-12deg) scale(.86); }
#page-contacts .inbox-send:focus-visible, #page-contacts .inbox-attach:focus-visible { outline: 2px solid var(--tg-accent); outline-offset: 2px; }
#page-contacts .inbox-attach { display: grid; flex: 0 0 38px; place-items: center; width: 38px; height: 38px; margin: 6px 0; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--tg-meta); cursor: pointer; transition: color 120ms ease, background-color 120ms ease, transform 120ms ease; }
#page-contacts .inbox-attach:hover { background: var(--tg-accent-soft); color: var(--tg-accent); }
#page-contacts .inbox-attach:active { transform: scale(.92); }
#page-contacts .inbox-attach svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transform: rotate(45deg); }

/* The footer holds the composer; it is built once per mode so typing is never interrupted. */
#page-contacts .inbox-foot { position: relative; flex: 0 0 auto; }
#page-contacts .inbox-composer-field { position: relative; }
#page-contacts .inbox-composer-count { position: absolute; right: 14px; bottom: 2px; color: var(--tg-meta); font-size: 11px; font-variant-numeric: tabular-nums; pointer-events: none; }
#page-contacts .inbox-spinner { display: inline-block; width: 13px; height: 13px; margin: 0 7px -2px 0; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: inbox-spin .7s linear infinite; }
@keyframes inbox-spin { to { transform: rotate(360deg); } }

/* Messages you sent that Telegram hasn't confirmed yet. */
#page-contacts #inboxThread .employee-conversation-message.is-pending-queued,
#page-contacts #inboxThread .employee-conversation-message.is-pending-sending { animation: inbox-bubble-in 160ms cubic-bezier(.2, .8, .2, 1); }
@keyframes inbox-bubble-in { from { transform: translateY(6px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
#page-contacts #inboxThread .employee-conversation-message.is-pending-failed,
#page-contacts #inboxThread .employee-conversation-message.is-pending-uncertain { outline: 1.5px solid var(--tg-warn); outline-offset: -1.5px; }
#page-contacts #inboxThread .inbox-pending-note { display: grid; gap: 4px; clear: both; margin: 6px 0 0; padding-top: 6px; border-top: 1px solid color-mix(in srgb, var(--tg-warn) 30%, transparent); color: var(--tg-warn); font-size: 12.5px; font-weight: 500; line-height: 1.35; }
#page-contacts #inboxThread .inbox-pending-actions { display: flex; flex-wrap: wrap; gap: 6px; }
#page-contacts #inboxThread .inbox-pending-actions button { height: 26px; padding: 0 10px; border: 0; border-radius: 8px; background: var(--tg-accent-soft); color: var(--tg-accent); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
#page-contacts #inboxThread .inbox-pending-actions button + button { background: transparent; color: var(--tg-out-meta); }

@property --p { syntax: "<number>"; inherits: false; initial-value: 0; }
/* Message states, as in Telegram: clock, one tick, two ticks, red mark. */
#page-contacts .inbox-mark { flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#page-contacts #inboxThread .inbox-mark { color: var(--tg-out-meta); }
#page-contacts .inbox-mark.is-sent, #page-contacts .inbox-mark.is-read { width: 18px; height: 12px; }
#page-contacts .inbox-mark.is-sending { width: 13px; height: 13px; stroke-width: 1.4; }
#page-contacts .inbox-mark .inbox-clock-hand { transform-origin: 8px 8px; animation: inbox-spin 1.4s linear infinite; }
#page-contacts .inbox-mark.is-failed { width: 14px; height: 14px; fill: #e53935; stroke: #fff; stroke-width: 1.8; }
#page-contacts #inboxThread .inbox-mark.is-failed { color: #e53935; }
#page-contacts .inbox-row .inbox-mark { color: var(--tg-green, #4fae4e); }
#page-contacts .inbox-row .inbox-mark.is-sending { color: var(--tp-muted); }
#page-contacts .inbox-row.is-selected .inbox-mark { color: currentColor; }

/* New messages slide in; nothing else moves. */
#page-contacts #inboxThread .employee-conversation-message.is-new { animation: inbox-bubble-in 220ms cubic-bezier(.2, .9, .3, 1.15) both; }
#page-contacts #inboxThread .employee-conversation-message.is-customer.is-new { transform-origin: left bottom; }
#page-contacts #inboxThread .employee-conversation-message.is-employee.is-new { transform-origin: right bottom; }

/* A photo or file on its way. */
#page-contacts .inbox-upload.is-photo { position: relative; display: grid; place-items: center; margin: -2px -6px 4px; overflow: hidden; border-radius: 12px; }
#page-contacts .inbox-upload.is-photo img { display: block; max-width: 100%; max-height: 340px; }
#page-contacts .is-pending-queued .inbox-upload.is-photo img, #page-contacts .is-pending-sending .inbox-upload.is-photo img { filter: brightness(.82); }
#page-contacts .inbox-progress { position: absolute; display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 0; border-radius: 50%; background: radial-gradient(closest-side, rgba(0, 0, 0, .55) 79%, transparent 80% 100%), conic-gradient(#fff calc(var(--p, 0) * 360deg), rgba(255, 255, 255, .25) 0); color: #fff; cursor: pointer; transition: --p 200ms linear; }
#page-contacts .inbox-progress svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
#page-contacts .inbox-upload.is-file, #page-contacts .inbox-tray-item.is-file { display: flex; align-items: center; gap: 10px; min-width: 200px; max-width: 320px; margin: 2px 0 4px; }
#page-contacts .inbox-file-icon { position: relative; display: grid; flex: 0 0 46px; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: #3390ec; color: #fff; }
#page-contacts .inbox-file-icon b { font-size: 11px; font-weight: 700; letter-spacing: .02em; }
#page-contacts .inbox-file-icon .inbox-progress { position: static; width: 46px; height: 46px; background: radial-gradient(closest-side, #3390ec 79%, transparent 80% 100%), conic-gradient(#fff calc(var(--p, 0) * 360deg), rgba(255, 255, 255, .3) 0); }
#page-contacts .inbox-file-meta { display: grid; gap: 2px; min-width: 0; }
#page-contacts .inbox-file-meta strong { overflow: hidden; letter-spacing: 0; text-transform: none; color: var(--tg-text); font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
#page-contacts .inbox-file-meta small { color: var(--tg-meta); font-size: 12.5px; font-variant-numeric: tabular-nums; }
#page-contacts .is-employee .inbox-file-meta small { color: var(--tg-out-meta); }

#page-contacts #inboxThread .employee-conversation-attachment.inbox-file-card { display: flex; align-items: center; gap: 10px; min-width: 200px; max-width: 320px; margin: 2px 0 4px; padding: 0; background: transparent; color: inherit; text-decoration: none; }
#page-contacts #inboxThread .inbox-file-card .inbox-file-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#page-contacts #inboxThread .inbox-file-card:hover .inbox-file-icon { background: #2b84de; }

#page-contacts #inboxThread .inbox-file-card.is-gone .inbox-file-icon { background: var(--tg-meta); opacity: .7; }
#page-contacts #inboxThread .inbox-file-card.is-gone strong { color: var(--tg-meta); }

/* Files waiting above the text until Send. */
#page-contacts .inbox-tray { display: flex; gap: 8px; padding: 10px 10px 0; overflow-x: auto; scrollbar-width: thin; }
#page-contacts .inbox-tray[hidden] { display: none; }
#page-contacts .inbox-tray-item { position: relative; flex: 0 0 auto; animation: inbox-bubble-in 160ms ease; }
#page-contacts .inbox-tray-item.is-photo img { display: block; width: 76px; height: 76px; border-radius: 10px; object-fit: cover; }
#page-contacts .inbox-tray-item.is-file { min-width: 180px; max-width: 240px; margin: 0; padding: 8px 30px 8px 8px; border-radius: 12px; background: var(--tg-accent-soft); }
#page-contacts .inbox-tray-item.is-file .inbox-file-icon { flex-basis: 38px; width: 38px; height: 38px; }
#page-contacts .inbox-tray-remove { position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; }
#page-contacts .inbox-tray-remove svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
#page-contacts .inbox-composer-count.is-over { color: #e53935; font-weight: 600; }

/* Drop files onto the chat. */
#page-contacts .inbox-drop { position: absolute; inset: 10px; z-index: 4; display: none; place-items: center; border: 2px dashed var(--tg-accent); border-radius: 18px; background: color-mix(in srgb, var(--tg-bar) 86%, transparent); color: var(--tg-accent); font-size: 17px; font-weight: 600; pointer-events: none; }
#page-contacts #inboxThread.is-dropping .inbox-drop { display: grid; }

/* Jump to the latest message, with a count of new ones. */
#page-contacts .inbox-jump { position: absolute; right: max(18px, calc((100% - 760px) / 2 + 18px)); bottom: 84px; z-index: 2; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: var(--tg-bar); color: var(--tp-text-2); box-shadow: var(--tg-bubble-shadow); cursor: pointer; animation: inbox-bubble-in 140ms ease; }
#page-contacts .inbox-jump[hidden] { display: none; }
#page-contacts .inbox-jump svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#page-contacts .inbox-jump b { position: absolute; top: -6px; right: -2px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: #3390ec; color: #fff; font-size: 11.5px; font-weight: 600; line-height: 20px; text-align: center; }
#page-contacts .inbox-jump b:empty { display: none; }

/* ---- Customer info: slides in when the customer's name is clicked ---- */
#page-contacts .inbox-detail-pane { position: absolute; top: 0; right: 0; bottom: 0; z-index: 5; display: flex; flex-direction: column; width: min(340px, 100%); overflow: hidden auto; border-left: 1px solid var(--tp-line); background: var(--tp-panel); box-shadow: -18px 0 40px -24px rgba(0, 0, 0, .45); animation: inbox-slide-in 200ms cubic-bezier(.2, .8, .2, 1); scrollbar-width: thin; }
#page-contacts .inbox-detail-pane[hidden] { display: none; }
@keyframes inbox-slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
#page-contacts .inbox-info-head { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 6px 14px; }
#page-contacts .inbox-info-head h2 { margin: 0; color: var(--tp-text); font-size: 16px; font-weight: 600; }
#page-contacts .inbox-info-person { display: grid; justify-items: center; gap: 4px; padding: 6px 20px 18px; text-align: center; }
#page-contacts .inbox-avatar.is-xl .conversation-avatar { width: 100px !important; height: 100px !important; flex-basis: 100px; margin-bottom: 8px; font-size: 34px; }
#page-contacts .inbox-info-person strong { color: var(--tp-text); font-size: 19px; font-weight: 600; }
#page-contacts .inbox-info-person > span:last-child { color: var(--tp-muted); font-size: 13.5px; }
#page-contacts .inbox-info-rows { display: grid; gap: 2px; margin: 0; padding: 8px; border-top: 8px solid var(--tp-panel-2); list-style: none; }
#page-contacts .inbox-info-rows li { display: flex; align-items: center; gap: 22px; padding: 9px 12px; border-radius: 10px; }
#page-contacts .inbox-info-rows li:hover { background: var(--tp-hover); }
#page-contacts .inbox-info-rows svg { flex: 0 0 22px; width: 22px; height: 22px; fill: none; stroke: var(--tp-muted); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#page-contacts .inbox-info-rows div { display: grid; gap: 1px; min-width: 0; }
#page-contacts .inbox-info-rows span { overflow: hidden; color: var(--tp-text); font-size: 14.5px; text-overflow: ellipsis; white-space: nowrap; }
#page-contacts .inbox-info-rows small { color: var(--tp-muted); font-size: 12.5px; }
#page-contacts .inbox-info-rows a { color: var(--tg-accent); text-decoration: none; }
#page-contacts .inbox-info-action { padding: 12px 20px 22px; border-top: 8px solid var(--tp-panel-2); }
#page-contacts .inbox-info-action .inbox-text-btn { width: 100%; height: 42px; }

/* ---- Narrower screens ---- */
@media (max-width: 900px) {
  #page-contacts .inbox-grid { grid-template-columns: minmax(0, 1fr); }
  #page-contacts .inbox-thread-pane { display: none; }
  #page-contacts .inbox-grid.has-thread .inbox-list-pane { display: none; }
  #page-contacts .inbox-grid.has-thread .inbox-thread-pane { display: flex; }
  #page-contacts .inbox-back { display: grid; }
  #page-contacts .inbox-detail-pane { width: 100%; border-left: 0; }
}
@media (max-width: 760px) {
  html body.app-page.contacts-route .app-main { padding: 0 !important; overflow: hidden !important; overscroll-behavior: none; }
  #page-contacts.active { height: 100%; margin: 0 !important; padding: 0 !important; }
  #page-contacts .ih-side { display: none !important; }
  #page-contacts .ih-app { display: block; height: 100%; }
  #page-contacts .ih-main.inbox-main { height: 100%; border-radius: 0; box-shadow: none; }
  #page-contacts .ih-show-side { display: none !important; }
  #page-contacts .inbox-list { padding: 4px 6px 16px; }
  #page-contacts .inbox-stream { padding: 10px 8px 8px; }
  #page-contacts .inbox-replying,
  #page-contacts .inbox-composer { width: calc(100% - 16px); margin-bottom: calc(8px + env(safe-area-inset-bottom)); }
  #page-contacts #inboxThread .employee-conversation-message { max-width: 84%; }
  #page-contacts .inbox-jump { right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  #page-contacts .inbox-skeleton,
  #page-contacts .inbox-live-dot,
  #page-contacts .inbox-detail-pane { animation: none; }
}
