/* TalkCart chat widget — host theme isolation.
   Themes (sterling и любой другой) часто бьют по button/svg/ol/li
   глобально. Не хотим shadow DOM (бьётся с focus/IME), поэтому:
   1) повышаем специфичность через #tc-chat
   2) для всех потомков задаём box-sizing/font/line-height/letter-spacing
      явно — резетим унаследованные неожиданности
   3) для button/svg задаём border:0/background-color:transparent явно,
      чтобы тема не закрашивала иконки
*/

#tc-chat,
#tc-chat * {
    box-sizing: border-box;
}
#tc-chat {
    --tc-chat-color: var(--tc-chat-color);
    --tc-chat-color-dark: var(--tc-chat-color-dark);
    --tc-chat-color-grad: linear-gradient(135deg, var(--tc-chat-color) 0%, var(--tc-chat-color-dark) 100%);
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2147483600; /* выше большинства попапов темы */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #1f2328;
    text-align: left;
    letter-spacing: normal;
    text-transform: none;
    direction: ltr;
}
#tc-chat.tc-chat--left { right: auto; left: 20px; }
@media (max-width: 480px) {
    #tc-chat.tc-chat--left { left: 12px; right: auto; }
}

/* Поведение state */
#tc-chat[data-state="open"]  > .tc-chat__bubble { display: none !important; }
#tc-chat[data-state="closed"] > .tc-chat__panel { display: none !important; }

/* ── Bubble ──────────────────────────────────────────────────────── */
#tc-chat .tc-chat__bubble {
    appearance: none;
    -webkit-appearance: none;
    width: 56px;
    height: 56px;
    min-width: 0;
    min-height: 0;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 50%;
    background: var(--tc-chat-color);
    color: #fff;
    box-shadow: 0 8px 20px rgba(0,0,0,0.18);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s ease, box-shadow .15s ease;
    text-shadow: none;
    line-height: 1;
}
#tc-chat .tc-chat__bubble:hover,
#tc-chat .tc-chat__bubble:focus {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(0,0,0,0.22);
    background: var(--tc-chat-color);
    color: #fff;
    outline: none;
}
#tc-chat .tc-chat__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    pointer-events: none;
    animation: tc-chat-pop .25s ease-out;
}
#tc-chat .tc-chat__badge[hidden] { display: none; }
#tc-chat .tc-chat__bubble { position: relative; }
@keyframes tc-chat-pop {
    0%   { transform: scale(0.4); opacity: 0; }
    100% { transform: scale(1);   opacity: 1; }
}
#tc-chat .tc-chat__bubble svg {
    width: 28px;
    height: 28px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Panel ───────────────────────────────────────────────────────── */
#tc-chat .tc-chat__panel {
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 40px);
    background: #fff;
    border: 0;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* ── Head ────────────────────────────────────────────────────────── */
#tc-chat .tc-chat__head {
    background: linear-gradient(135deg, var(--tc-chat-color) 0%, var(--tc-chat-color-dark) 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}
#tc-chat .tc-chat__title-wrap {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}
#tc-chat .tc-chat__title {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    margin: 0;
}
#tc-chat .tc-chat__sub {
    color: #fff;
    font-size: 12px;
    opacity: .85;
    margin-top: 2px;
    line-height: 1.2;
}
#tc-chat .tc-chat__escalate {
    appearance: none;
    -webkit-appearance: none;
    background: rgba(255,255,255,0.18);
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    margin-inline-end: 4px;
    text-shadow: none;
    box-shadow: none;
    flex: 0 0 auto;
    transition: background .15s ease;
}
#tc-chat .tc-chat__escalate:hover { background: rgba(255,255,255,0.28); color: #fff; }
#tc-chat .tc-chat__escalate[hidden] { display: none; }

#tc-chat .tc-chat__mtc--bot {
    background: #f0f6fc;
    border: 1px solid #c5d9ed;
    color: #1f2328;
    border-bottom-left-radius: 4px;
}
#tc-chat .tc-chat__mtc--bot::before {
    content: '🤖';
    margin-inline-end: 6px;
    opacity: .85;
}

/* Typing indicator — appears while AI is thinking. Lives in the log
   stream as a faux bot message so flow/scroll stays consistent. */
#tc-chat .tc-chat__typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
}
#tc-chat .tc-chat__typing span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #6a737d;
    opacity: .35;
    animation: tc-chat-typing 1.2s infinite ease-in-out;
}
#tc-chat .tc-chat__typing span:nth-child(2) { animation-delay: .15s; }
#tc-chat .tc-chat__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes tc-chat-typing {
    0%, 60%, 100% { opacity: .35; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}

#tc-chat .tc-chat__close {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    margin: 0;
    opacity: .85;
    text-shadow: none;
    box-shadow: none;
    min-width: 0;
    min-height: 0;
    width: auto;
    height: auto;
}
#tc-chat .tc-chat__close:hover { opacity: 1; background: transparent; color: #fff; }

/* Expand / shrink toggle — only shown when there's room on screen
   (hidden under 1024px by the media query below). Two SVG icons share
   the button; CSS swaps which is visible based on data-size on the
   widget root. */
#tc-chat .tc-chat__expand {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 0;
    color: #fff;
    padding: 4px;
    margin: 0 2px 0 0;
    opacity: .8;
    cursor: pointer;
    line-height: 0;
    border-radius: 4px;
    min-width: 0; min-height: 0;
    width: auto; height: auto;
    display: none;
}
#tc-chat .tc-chat__expand:hover { opacity: 1; background: rgba(255,255,255,0.14); }
#tc-chat .tc-chat__expand-icon { display: block; }
#tc-chat .tc-chat__expand-icon--shrink { display: none; }
#tc-chat[data-size="large"] .tc-chat__expand-icon--expand { display: none; }
#tc-chat[data-size="large"] .tc-chat__expand-icon--shrink { display: block; }
/* Show the toggle only on screens roomy enough to actually expand. */
@media (min-width: 1024px) {
    #tc-chat .tc-chat__expand { display: inline-flex; align-items: center; justify-content: center; }
}

/* ── Log ─────────────────────────────────────────────────────────── */
/* Структура: ol > li (флекс-row, выравнивает bubble лево/право) > .msg (пузырь)
   Раньше align-self стоял на самом .msg и tailwind-каскад темы съедал
   max-width — bubble раздувался за viewport. Перенёс выравнивание на li,
   bubble стал inline-block с честным max-width. */
#tc-chat .tc-chat__log {
    flex: 1 1 auto;
    overflow-y: auto;
    margin: 0;
    padding: 14px 0 4px;
    list-style: none;
    background: #f6f8fa;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 0;
    counter-reset: none;
}
#tc-chat .tc-chat__log > li {
    list-style: none;
    margin: 0;
    padding: 0 14px;
    display: flex;
    width: 100%;
    box-sizing: border-box;
}
#tc-chat .tc-chat__log > li.tc-chat__row--user   { justify-content: flex-end; }
#tc-chat .tc-chat__log > li.tc-chat__row--agent  { justify-content: flex-start; }
#tc-chat .tc-chat__log > li.tc-chat__row--system { justify-content: center; }
#tc-chat .tc-chat__log > li::before,
#tc-chat .tc-chat__log > li::marker {
    content: none;
    display: none;
}
#tc-chat .tc-chat__msg {
    display: inline-block;
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    color: #1f2328;
    margin: 0;
}
#tc-chat .tc-chat__mtc--user {
    background: var(--tc-chat-color);
    color: #fff;
    border-bottom-right-radius: 4px;
}
#tc-chat .tc-chat__mtc--agent {
    background: #fff;
    border: 1px solid #e2e6ea;
    border-bottom-left-radius: 4px;
}
#tc-chat .tc-chat__mtc--system {
    background: transparent;
    color: #6a737d;
    font-size: 12px;
    font-style: italic;
}
#tc-chat .tc-chat__mtc-time {
    display: block;
    font-size: 10px;
    opacity: .65;
    margin-top: 4px;
    color: inherit;
    line-height: 1;
}
#tc-chat .tc-chat__att-image {
    display: block;
    max-width: 240px;
    max-height: 240px;
    width: auto;
    height: auto;
    border-radius: 8px;
    margin: 0;
    border: 0;
    object-fit: cover;
    background: #e9ecef;
}
#tc-chat .tc-chat__att-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
    font-size: 13px;
    line-height: 1.3;
    max-width: 100%;
}
#tc-chat .tc-chat__mtc--user .tc-chat__att-file { background: rgba(255,255,255,0.18); }
#tc-chat .tc-chat__att-file:hover { text-decoration: underline; }
#tc-chat .tc-chat__att-icon {
    flex: 0 0 auto;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.06);
    border-radius: 6px;
}
#tc-chat .tc-chat__mtc--user .tc-chat__att-icon { background: rgba(255,255,255,0.22); }
#tc-chat .tc-chat__att-icon svg { width: 16px; height: 16px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#tc-chat .tc-chat__att-meta { min-width: 0; flex: 1 1 auto; }
#tc-chat .tc-chat__att-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}
#tc-chat .tc-chat__att-mime { display: block; font-size: 11px; opacity: .7; }
#tc-chat .tc-chat__mtc-text { display: block; }
#tc-chat .tc-chat__mtc-text:not(:last-child) { margin-bottom: 6px; }
/* Markdown formatting inside bot bubbles. We render via DOM nodes (see
   widget.js → renderMarkdown) so untrusted text never reaches innerHTML;
   the styles here just give those nodes sensible spacing inside a chat
   bubble. */
#tc-chat .tc-chat__mtc-text a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-word;
}
#tc-chat .tc-chat__mtc--user .tc-chat__mtc-text a { color: #fff; }
#tc-chat .tc-chat__mtc-text a:hover { text-decoration-thickness: 2px; }
#tc-chat .tc-chat__mtc-text strong { font-weight: 600; }
#tc-chat .tc-chat__mtc-text em { font-style: italic; }
#tc-chat .tc-chat__mtc-text code {
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(0,0,0,0.06);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.92em;
}
#tc-chat .tc-chat__mtc--user .tc-chat__mtc-text code { background: rgba(255,255,255,0.2); }
#tc-chat .tc-chat__mtc-text .tc-md-p { margin: 0; }
#tc-chat .tc-chat__mtc-text .tc-md-p + .tc-md-p,
#tc-chat .tc-chat__mtc-text .tc-md-p + .tc-md-list,
#tc-chat .tc-chat__mtc-text .tc-md-list + .tc-md-p,
#tc-chat .tc-chat__mtc-text .tc-md-list + .tc-md-list,
#tc-chat .tc-chat__mtc-text .tc-md-heading + *,
#tc-chat .tc-chat__mtc-text * + .tc-md-heading { margin-top: 8px; }
#tc-chat .tc-chat__mtc-text .tc-md-heading { font-weight: 600; }
#tc-chat .tc-chat__mtc-text .tc-md-list {
    margin: 0;
    padding-left: 20px;
}
#tc-chat .tc-chat__mtc-text .tc-md-list li { margin: 2px 0; }
#tc-chat .tc-chat__mtc-text .tc-md-list li::marker { color: currentColor; opacity: .7; }
#tc-chat .tc-chat__empty {
    color: #6a737d;
    font-size: 13px;
    padding: 24px 16px;
    text-align: center;
    list-style: none;
    width: 100%;
    justify-content: center;
}

/* ── Form ────────────────────────────────────────────────────────── */
#tc-chat .tc-chat__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e2e6ea;
    background: #fff;
    flex: 0 0 auto;
    margin: 0;
}
#tc-chat .tc-chat__input {
    flex: 1 1 auto;
    width: auto;
    border: 1px solid #d0d7de;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    color: #1f2328;
    background: #fff;
    resize: none;
    max-height: 120px;
    min-height: 40px;
    outline: none;
    box-shadow: none;
    transition: border-color .15s ease;
    margin: 0;
    text-transform: none;
    letter-spacing: normal;
}
#tc-chat .tc-chat__input:focus {
    border-color: var(--tc-chat-color);
    box-shadow: none;
    outline: none;
}
#tc-chat .tc-chat__attach {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    color: #6a737d;
    border: 0;
    width: 36px;
    height: 36px;
    min-width: 0;
    min-height: 0;
    padding: 0;
    margin: 0 0 2px 0;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    box-shadow: none;
    text-shadow: none;
    line-height: 1;
    transition: background .15s ease, color .15s ease;
}
#tc-chat .tc-chat__attach:hover { background: #eef2f5; color: var(--tc-chat-color); }
#tc-chat .tc-chat__attach svg { width: 20px; height: 20px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#tc-chat .tc-chat__attach[disabled] { opacity: .5; cursor: not-allowed; }

#tc-chat .tc-chat__send {
    appearance: none;
    -webkit-appearance: none;
    background: var(--tc-chat-color);
    color: #fff;
    border: 0;
    width: 40px;
    height: 40px;
    min-width: 0;
    min-height: 0;
    padding: 0;
    margin: 0;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    box-shadow: none;
    text-shadow: none;
    line-height: 1;
    transition: background .15s ease;
}
#tc-chat .tc-chat__send:hover { background: var(--tc-chat-color-dark); color: #fff; }
#tc-chat .tc-chat__send:disabled { background: #99c9e3; cursor: not-allowed; }
#tc-chat .tc-chat__send svg {
    width: 20px;
    height: 20px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#tc-chat .tc-chat__error {
    color: #cf222e;
    font-size: 12px;
    padding: 4px 14px 0;
    background: #fff;
}

#tc-chat .tc-chat__notice {
    background: #fff8e1;
    color: #6a4f00;
    border-top: 1px solid #f0d77a;
    padding: 10px 14px;
    font-size: 12px;
    line-height: 1.45;
    flex: 0 0 auto;
}
#tc-chat .tc-chat__notice[hidden] { display: none; }

#tc-chat .tc-chat__legal {
    margin: 0;
    padding: 6px 14px 8px;
    font-size: 11px;
    line-height: 1.4;
    color: #94a3b8;
    background: #fff;
    text-align: center;
    flex: 0 0 auto;
}

#tc-chat .tc-chat__preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f6f8fa;
    border-top: 1px solid #e2e6ea;
    flex: 0 0 auto;
}
#tc-chat .tc-chat__preview[hidden] { display: none; }
#tc-chat .tc-chat__preview-thumb {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 6px;
    background: #e9ecef center/cover no-repeat;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6a737d;
    overflow: hidden;
}
#tc-chat .tc-chat__preview-thumb svg {
    width: 22px; height: 22px; display: block;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
#tc-chat .tc-chat__preview-meta {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    line-height: 1.3;
    color: #1f2328;
}
#tc-chat .tc-chat__preview-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#tc-chat .tc-chat__preview-size { color: #6a737d; font-size: 11px; }
#tc-chat .tc-chat__preview-remove {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 0;
    color: #6a737d;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    margin: 0;
    flex: 0 0 auto;
    width: 28px; height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease, color .15s ease;
}
#tc-chat .tc-chat__preview-remove:hover { background: #fee; color: #cf222e; }

/* ── Pre-chat form (rendered when needs_profile === true) ────────── */
#tc-chat .tc-chat__pre {
    flex: 1 1 auto;
    overflow-y: auto;
    background: #fff;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    color: #1f2328;
}
#tc-chat .tc-chat__pre[hidden] { display: none; }
#tc-chat .tc-chat__pre-intro {
    font-size: 13px;
    color: #50575e;
    line-height: 1.45;
    margin: 0;
}
#tc-chat .tc-chat__pre-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
#tc-chat .tc-chat__pre-field-label {
    font-size: 12px;
    font-weight: 600;
    color: #1f2328;
    line-height: 1.2;
}
#tc-chat .tc-chat__pre-field-label-req::after {
    content: ' *';
    color: #cf222e;
}
#tc-chat .tc-chat__pre-field-input,
#tc-chat .tc-chat__pre-field-textarea {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    border: 1px solid #d0d7de;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    color: #1f2328;
    background: #fff;
    outline: none;
    box-shadow: none;
    transition: border-color .15s ease;
    margin: 0;
    text-transform: none;
    letter-spacing: normal;
}
#tc-chat .tc-chat__pre-field-textarea {
    resize: vertical;
    min-height: 70px;
    max-height: 160px;
}
#tc-chat .tc-chat__pre-field-input:focus,
#tc-chat .tc-chat__pre-field-textarea:focus {
    border-color: var(--tc-chat-color);
}
#tc-chat .tc-chat__pre-field-error {
    color: #cf222e;
    font-size: 11px;
    line-height: 1.3;
}
#tc-chat .tc-chat__pre-submit {
    appearance: none;
    -webkit-appearance: none;
    margin-top: 4px;
    background: var(--tc-chat-color);
    color: #fff;
    border: 0;
    padding: 11px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-shadow: none;
    box-shadow: none;
    transition: background .15s ease;
}
#tc-chat .tc-chat__pre-submit:hover { background: var(--tc-chat-color-dark); color: #fff; }
#tc-chat .tc-chat__pre-submit:disabled { background: #99c9e3; cursor: not-allowed; }

/* Offline email handoff form (reuses .tc-chat__pre-field controls). */
#tc-chat .tc-chat__email {
    flex: 1 1 auto;
    overflow-y: auto;
    background: #fff;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    color: #1f2328;
}
#tc-chat .tc-chat__email[hidden] { display: none; }
#tc-chat .tc-chat__email-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}
#tc-chat .tc-chat__email-intro {
    margin: 0;
    font-size: 13px;
    color: #50575e;
    line-height: 1.45;
}
#tc-chat .tc-chat__email-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#tc-chat .tc-chat__email-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
}
#tc-chat .tc-chat__email-cancel {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    color: #50575e;
    border: 0;
    padding: 8px 4px;
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
    line-height: 1.2;
}
#tc-chat .tc-chat__email-cancel:hover { color: #1f2328; }

/* ── Lightbox (fullscreen image preview) ─────────────────────────── */
#tc-chat .tc-chat__lightbox {
    position: fixed;
    inset: 0;
    background: rgba(15,18,23,0.92);
    z-index: 2147483601;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    cursor: zoom-out;
}
#tc-chat .tc-chat__lightbox[hidden] { display: none; }
#tc-chat .tc-chat__lightbox-img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    cursor: default;
    border-radius: 4px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
#tc-chat .tc-chat__lightbox-close {
    appearance: none;
    -webkit-appearance: none;
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: rgba(255,255,255,0.12);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}
#tc-chat .tc-chat__lightbox-close:hover { background: rgba(255,255,255,0.2); }
#tc-chat .tc-chat__msg .tc-chat__att-image { cursor: zoom-in; }

/* ── Mobile ──────────────────────────────────────────────────────── */
/*
 * On a phone the chat takes over the whole viewport — half-screen panels
 * are useless when the OS keyboard pops up and grabs another 40 % of the
 * height. We:
 *   1) pin the panel to position:fixed inset:0 (full screen) when state=open,
 *   2) measure height with --tc-vh, written by widget.js from
 *      visualViewport (with 100dvh / 100vh fallbacks), so the panel shrinks
 *      to the visible area when the keyboard slides up,
 *   3) drop the rounded corners and shadow — Material/iOS full-sheet feel,
 *   4) keep the bubble at its corner offset; only the panel goes fullscreen.
 */
@media (max-width: 480px) {
    #tc-chat { right: 12px; bottom: 12px; }
    #tc-chat[data-state="open"] {
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        top: 0 !important;
    }
    #tc-chat .tc-chat__panel {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: 100vw;
        /* --tc-vh is set by widget.js to match visualViewport.height when
           the OS keyboard opens. Falls back to 100dvh (dynamic viewport,
           respects browser UI) and then 100vh on very old engines. */
        height: 100vh;
        height: 100dvh;
        height: var(--tc-vh, 100dvh);
        max-height: var(--tc-vh, 100dvh);
        border-radius: 0;
        box-shadow: none;
    }
    /* Lightbox already goes fullscreen — make sure it sits above the
       fullscreen panel and respects the visible viewport too. */
    #tc-chat .tc-chat__lightbox {
        height: var(--tc-vh, 100dvh);
    }
}

/* ── Desktop sizing ──────────────────────────────────────────────────
 * Default panel / bubble sizes are tuned for tight space; on real
 * monitors the bubble and the window deserve more presence. We also
 * surface an expand/shrink toggle here so visitors with lots of screen
 * can blow the window up to something resembling a proper chat client.
 *
 *   - default desktop:  bubble 64px, panel 400×600
 *   - data-size="large": panel ~ 560 × min(80vh, 760px)
 *
 * Mobile (≤480px) keeps the existing fullscreen panel rules above.
 */
@media (min-width: 1024px) {
    #tc-chat { right: 24px; bottom: 24px; }
    #tc-chat .tc-chat__bubble { width: 64px; height: 64px; }
    #tc-chat .tc-chat__bubble svg { width: 32px; height: 32px; }
    #tc-chat .tc-chat__panel {
        width: 400px;
        height: 600px;
    }
    #tc-chat[data-size="large"] .tc-chat__panel {
        width: 560px;
        height: min(80vh, 760px);
        max-height: calc(100vh - 40px);
    }
    #tc-chat[data-size="large"] .tc-chat__msg {
        max-width: 84%;
    }
}
