/* ============================================================
   MERKATOMARKET CUSTOMER SUPPORT CHAT WIDGET
   Fixed: No shrinking, all elements clearly visible and usable
   ============================================================ */

.chat-widget-container,
.chat-widget-container * {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.chat-widget-container {
    /*
      SPLIT-CORNER LAYOUT (no overlap ever):
        LEFT BOTTOM  = ⬆ ftScrollTop 34x34  bottom:28px left:28px
        RIGHT BOTTOM = 💬 Chat pill      H32 × W~auto  bottom:24px right:24px
    */
    position: fixed;
    bottom: 24px;
    right:  24px;
    z-index: 99999;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.4;
}

/* ── Chat Toggle Button — SMALL PILL, EYE-CATCHING, ANIMATED ── */
.chat-widget-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 14px 0 12px;
    height: 32px;
    min-width: 0;
    border-radius: 999px;          /* pill shape */
    /* Bold teal→cyan→teal animated gradient — grabs attention */
    background: linear-gradient(120deg, #0d9488, #06b6d4, #0891b2, #0d9488, #0ea5e9);
    background-size: 300% 300%;
    background-position: 0% 50%;
    animation: chatShimmer 5s ease-in-out infinite;
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow:
        0 6px 18px rgba(12, 182, 212, .55),
        0 12px 28px rgba(13, 148, 136, .45),
        0 0 0 3px rgba(6, 182, 212, .10);
    position: relative;
    z-index: 2;
    transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

/* Shimmer across the gradient */
@keyframes chatShimmer {
    0%   { background-position:   0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position:   0% 50%; }
}

.chat-toggle-icon {
    font-size: 13px;
    line-height: 1;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
}
.chat-toggle-text {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .02em;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(0,0,0,.22);
    display: inline-flex;
    align-items: center;
}

/* Tiny pulsing ping dot — eye-catching "someone's here" feeling */
.chat-toggle-ping {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #f97316;
    box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.7);
    animation: ping 1.6s cubic-bezier(0, 0, 0.2, 1) infinite;
}
@keyframes ping {
    75%, 100% {
        box-shadow: 0 0 0 10px rgba(249, 115, 22, 0);
    }
}

.chat-widget-toggle:hover {
    transform: translateY(-2px) scale(1.04);
    filter: brightness(1.08) saturate(1.1);
    box-shadow:
        0 10px 24px rgba(12, 182, 212, .62),
        0 16px 36px rgba(13, 148, 136, .5),
        0 0 0 4px rgba(6, 182, 212, .12);
}
.chat-widget-toggle:active { transform: translateY(-1px) scale(1); }

/* ============================================================
   CHAT BOX - VIEWPORT-SAFE FIXED POSITIONING, NEVER CUTS OFF
   (new small 32px Chat pill means the box can sit much lower)
   ============================================================ */
.chat-widget-box {
    position: fixed;
    /*
      Split-corner layout:
        Scroll-top: bottom:28px / left:28px  (LEFT — NO OVERLAP possible)
        Chat pill:  bottom:24px / right:24px (RIGHT)
      Chat box bottom = 24 + 32 (pill) + 16px gap = 72px clean above everything.
      Box right edge = 24px (same anchor as pill) — right-aligned perfectly.
    */
    right:  24px;
    bottom: 72px;
    /* Prevent overflow: keep preferred 390x520 but never exceed these viewport caps */
    width:  clamp(300px, 390px, calc(100vw - 48px));
    height: clamp(360px, 520px, calc(100vh - 120px));
    min-width:  300px;
    min-height: 360px;
    max-width:  390px;
    max-height: 520px;
    background: #fff;
    border-radius: 18px;
    overflow: hidden;
    display: none;
    flex-direction: column;
    box-shadow:
        0 24px 72px rgba(0, 0, 0, .22),
        0 12px 32px rgba(0, 0, 0, .16),
        0 0 0 1px rgba(0,0,0,.07);
    transform-origin: bottom right;
    /* Safety margin so even if all clamp() fails, top stays visible */
    margin-top: 24px;
    margin-right: 0;
}
.chat-widget-box.open {
    display: flex;
    animation: chatPop .38s cubic-bezier(.4, 0, .2, 1);
}
@keyframes chatPop {
    0%   { opacity: 0; transform: translateY(24px) scale(.94); }
    65%  { opacity: 1; }
    100% { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ============================================================
   HEADER - FIXED HEIGHT, NEVER COLLAPSES
   ============================================================ */
.chat-widget-header {
    background: linear-gradient(135deg, #0a3d3d 0%, #0d5c5c 40%, #009999 100%);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    /* FIXED HEIGHT */
    height: 70px;
    min-height: 70px;
    max-height: 70px;
    flex: 0 0 70px;
}
.chat-widget-header::before {
    content: "";
    position: absolute;
    top: -50%;
    right: -20%;
    width: 220px;
    height: 220px;
    background: radial-gradient(circle, rgba(0,229,229,.22) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}
.chat-widget-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 1;
}
.chat-widget-header .chat-widget-avatar {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #00e5e5 0%, #009999 60%, #006666 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 0 0 2px rgba(255,255,255,.25), 0 4px 12px rgba(0,0,0,.2);
    position: relative;
    margin-right: 0;
}
.chat-widget-header .chat-widget-avatar::after {
    content: "";
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border: 2px solid #fff;
    border-radius: 50%;
}
.chat-widget-title h3 {
    margin: 0 0 3px;
    font-size: 14.5px;
    font-weight: 700;
    letter-spacing: -.2px;
    color: #fff;
    white-space: nowrap;
}
.chat-widget-title p {
    margin: 0;
    font-size: 11.5px;
    opacity: .9;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}
.chat-widget-title p::before {
    content: "●";
    color: #4ade80;
    font-size: 9px;
    animation: statusPulse 1.8s infinite;
}
@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: .55; }
}
.chat-widget-close {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.18);
    color: #fff;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    position: relative;
    z-index: 1;
    line-height: 1;
    padding: 0;
}
.chat-widget-close:hover {
    background: rgba(255,255,255,.22);
    transform: rotate(90deg);
}

/* ============================================================
   MESSAGES AREA - FILLS REMAINING SPACE, SCROLLS PROPERLY
   ============================================================ */
.chat-widget-messages {
    /* Fills remaining space without collapsing */
    flex: 1 1 auto;
    height: 1px; /* flexbox trick: allows scrolling within flex child */
    min-height: 0;
    padding: 16px 18px 14px;
    overflow-y: auto;
    overflow-x: hidden;
    background:
        radial-gradient(ellipse at top left, rgba(0,153,153,.04) 0%, transparent 50%),
        linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    scroll-behavior: smooth;
}
.chat-widget-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-widget-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-widget-messages::-webkit-scrollbar-thumb {
    background: rgba(0,153,153,.3);
    border-radius: 3px;
}
.chat-widget-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0,153,153,.5);
}

/* Welcome screen */
.chat-widget-welcome {
    text-align: center;
    padding: 24px 20px 20px;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(255,255,255,.95) 0%, rgba(255,255,255,.55) 100%);
    border: 1px solid rgba(0,153,153,.08);
    margin: 4px 0 14px;
}
.chat-widget-welcome-icon {
    width: 58px;
    height: 58px;
    margin: 0 auto 10px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 30% 30%, rgba(0,229,229,.3) 0%, transparent 60%),
        linear-gradient(135deg, rgba(0,153,153,.1) 0%, rgba(0,229,229,.15) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    box-shadow: inset 0 0 0 1px rgba(0,153,153,.12), 0 4px 12px rgba(0,153,153,.08);
}
.chat-widget-welcome h4 {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 700;
    color: #0f172a;
}
.chat-widget-welcome p {
    margin: 0;
    color: #64748b;
    font-size: 12.5px;
    line-height: 1.55;
}
.chat-widget-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 14px;
    justify-content: center;
}
.chat-widget-quick-reply {
    padding: 6px 12px;
    background: #fff;
    border: 1px solid rgba(0,153,153,.2);
    border-radius: 999px;
    font-size: 11.5px;
    color: #009999;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s;
}
.chat-widget-quick-reply:hover {
    background: #009999;
    color: #fff;
    border-color: #009999;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,153,153,.2);
}

/* ============================================================
   MESSAGE BUBBLES - GOOD SIZE, READABLE
   ============================================================ */
.chat-message {
    display: flex;
    margin-bottom: 12px;
    animation: msgIn .3s cubic-bezier(.4, 0, .2, 1) both;
    gap: 6px;
    width: 100%;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.chat-message.ai,
.chat-message.agent { justify-content: flex-start; }
.chat-message.customer { justify-content: flex-end; }

.chat-message .chat-message-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    align-self: flex-end;
    margin-bottom: 2px;
    box-shadow: 0 2px 6px rgba(0,0,0,.1);
}
.chat-message.ai .chat-message-avatar,
.chat-message.agent .chat-message-avatar {
    background: linear-gradient(135deg, #009999 0%, #006666 100%);
    color: #fff;
    margin-right: 0;
}
.chat-message.agent .chat-message-avatar {
    background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
}
.chat-message.customer .chat-message-avatar {
    background: linear-gradient(135deg, #64748b 0%, #334155 100%);
    color: #fff;
    order: 2;
    margin-left: 0;
}

.chat-message-body {
    max-width: 78%;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-message.customer .chat-message-body { align-items: flex-end; }

.chat-message-content {
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.5;
    color: #1e293b;
    word-wrap: break-word;
    word-break: break-word;
    border-radius: 17px;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
    white-space: pre-wrap;
}
.chat-message.ai .chat-message-content,
.chat-message.agent .chat-message-content {
    background: #ffffff;
    border-bottom-left-radius: 5px;
    border: 1px solid rgba(0,0,0,.05);
}
.chat-message.agent .chat-message-content {
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
    border-color: rgba(99,102,241,.12);
}
.chat-message.customer .chat-message-content {
    background: linear-gradient(135deg, #009999 0%, #0a7a7a 100%);
    color: #ffffff;
    border-bottom-right-radius: 5px;
    box-shadow: 0 2px 8px rgba(0,153,153,.2);
}

.chat-message-time {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 3px;
    padding: 0 3px;
    font-weight: 500;
}
.chat-message.customer .chat-message-time { text-align: right; }

/* ============================================================
   AI / AGENT MESSAGE MARKDOWN — beautiful formatting
   (customer messages stay plain text, no MD rendering)
   ============================================================ */

/* Remove the raw text `white-space: pre-wrap` only from Markdown containers
   — otherwise blank lines between paragraphs would be doubled  */
.chat-message-content .chat-md {
    white-space: normal;
    color: inherit;
    font-size: inherit;
    line-height: 1.6;
}

/* Remove zero margins inside MD blocks — reset to sensible defaults */
.chat-md > *:first-child { margin-top: 0 !important; }
.chat-md > *:last-child  { margin-bottom: 0 !important; }

/* ── Headings ── */
.chat-md h4,
.chat-md h5,
.chat-md h6 {
    color: #0f172a;
    font-weight: 800;
    line-height: 1.3;
    margin: 18px 0 10px;
    padding: 0;
    letter-spacing: -0.01em;
}
.chat-md h4 { font-size: 15.5px; }
.chat-md h5 { font-size: 14px; }
.chat-md h6 { font-size: 13px; color: #0e7490; }

.chat-md h4:not(:first-child)::before,
.chat-md h5:not(:first-child)::before,
.chat-md h6:not(:first-child)::before {
    /* subtle separator between heading and preceding block */
    content: "";
    display: block;
    height: 1px;
    background: linear-gradient(90deg, rgba(14,165,233,.2), transparent 80%);
    margin: -10px 0 10px;
}

/* ── Paragraphs ── */
.chat-md p {
    margin: 0 0 12px;
    padding: 0;
}
.chat-md p:last-child { margin-bottom: 0; }

/* ── Inline Bold & Italic — styled, NO ASTERISKS ── */
.chat-md strong,
.chat-md b {
    font-weight: 700;
    color: #0e7490;           /* teal/cyan accent — matches Merkato brand */
    background: linear-gradient(transparent 68%, rgba(6,182,212,.18) 68%);
    padding: 0 1px;
    border-radius: 2px;
}
.chat-md em,
.chat-md i {
    font-style: italic;
    color: #334155;
}

/* ── Inline code ── */
.chat-md code {
    font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
    font-size: 12px;
    padding: 2px 6px;
    margin: 0 1px;
    background: #f1f5f9;
    color: #be185d;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    white-space: nowrap;
}

/* ── Links ── */
.chat-md a {
    color: #0d9488;
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px solid rgba(13,148,136,.3);
    padding-bottom: 1px;
    transition: color .15s ease, border-color .15s ease, background .15s ease;
    word-break: break-all;
}
.chat-md a:hover {
    color: #0f766e;
    border-color: #0f766e;
    background: rgba(13,148,136,.08);
    border-radius: 3px;
}

/* ── Unordered Lists ── custom teal bullets, soft spacing ── */
.chat-md ul {
    list-style: none;
    padding: 0;
    margin: 4px 0 14px 4px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.chat-md ul li {
    position: relative;
    padding: 0 0 0 20px;
    line-height: 1.55;
    color: #1e293b;
}
.chat-md ul li::before {
    content: "›";
    position: absolute;
    left: 0;
    top: -1px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ea5e9, #06b6d4);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 2px 4px rgba(6,182,212,.3);
    text-indent: -1px;
}

/* ── Ordered Lists ── numbered teal badges ── */
.chat-md ol {
    list-style: none;
    counter-reset: md-ol;
    padding: 0;
    margin: 4px 0 14px 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-md ol li {
    position: relative;
    counter-increment: md-ol;
    padding: 0 0 0 26px;
    line-height: 1.55;
    color: #1e293b;
}
.chat-md ol li::before {
    content: counter(md-ol);
    position: absolute;
    left: 0;
    top: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0d9488, #14b8a6);
    color: #fff;
    font-size: 10.5px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(13,148,136,.35);
    letter-spacing: -0.02em;
}

/* Lists can be nested — shrink styling for sub-lists */
.chat-md ul ul,
.chat-md ol ol,
.chat-md ul ol,
.chat-md ol ul {
    margin: 7px 0 4px 6px !important;
    gap: 6px !important;
}

/* ── Blockquotes ── teal accent left bar ── */
.chat-md blockquote {
    margin: 14px 0 16px;
    padding: 8px 12px 8px 14px;
    background: linear-gradient(90deg, rgba(20,184,166,.10), rgba(20,184,166,.02) 80%);
    border-left: 3px solid #14b8a6;
    border-radius: 0 10px 10px 0;
    color: #115e59;
    font-size: 13px;
    line-height: 1.65;
    font-style: italic;
}
.chat-md blockquote > *:last-child { margin-bottom: 0; }

/* ── Horizontal rule ── (the markdown renderer produces <p> but just in case / future) ── */
.chat-md hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(13,148,136,.35), transparent);
    margin: 14px 0;
}

/* Typing indicator */
.chat-widget-typing {
    padding: 10px 14px;
    background: #fff;
    border-radius: 17px 17px 17px 5px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid rgba(0,0,0,.05);
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
    min-height: 36px;
}
.chat-widget-typing span {
    width: 7px;
    height: 7px;
    background: #009999;
    border-radius: 50%;
    animation: typingBounce 1.3s ease-in-out infinite;
}
.chat-widget-typing span:nth-child(2) { animation-delay: .18s; }
.chat-widget-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0);    opacity: .5; }
    40%           { transform: translateY(-5px); opacity: 1; }
}

/* ============================================================
   INPUT AREA - FIXED HEIGHT, EASY TO TYPE IN
   ============================================================ */
.chat-widget-input-container {
    background: #ffffff;
    border-top: 1px solid rgba(0,0,0,.05);
    position: relative;
    /* FIXED HEIGHT + padding, never collapses */
    padding: 12px 16px 14px;
    min-height: 90px;
    flex: 0 0 auto;
}
.chat-widget-input-wrapper {
    display: flex;
    gap: 6px;
    align-items: center;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 25px;
    padding: 5px 5px 5px 14px;
    transition: all .2s;
    min-height: 44px;
}
.chat-widget-input-wrapper:focus-within {
    border-color: #009999;
    background: #fff;
    box-shadow:
        0 0 0 3px rgba(0,153,153,.08),
        0 2px 6px rgba(0,153,153,.08);
}
.chat-widget-textarea {
    flex: 1 1 auto;
    width: 100%;
    min-height: 28px;
    height: 28px;
    max-height: 72px;
    padding: 4px 0;
    border: none;
    background: transparent;
    font-size: 13.5px;
    color: #1e293b;
    resize: none;
    font-family: inherit;
    outline: none;
    line-height: 1.4;
    overflow-y: auto;
    display: block;
}
.chat-widget-textarea::placeholder {
    color: #94a3b8;
    font-size: 12.5px;
}
.chat-widget-actions {
    display: flex;
    gap: 2px;
    align-items: center;
    flex-shrink: 0;
}
.chat-widget-attach-btn,
.chat-widget-emoji-btn,
.chat-widget-send-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: all .2s cubic-bezier(.4, 0, .2, 1);
    flex-shrink: 0;
}
.chat-widget-attach-btn,
.chat-widget-emoji-btn {
    background: transparent;
    color: #64748b;
}
.chat-widget-attach-btn:hover,
.chat-widget-emoji-btn:hover {
    background: rgba(0,153,153,.1);
    color: #009999;
    transform: translateY(-1px);
}
.chat-widget-send-btn {
    background: linear-gradient(135deg, #009999 0%, #00a3a3 100%);
    color: #fff;
    box-shadow: 0 2px 6px rgba(0,153,153,.3);
}
.chat-widget-send-btn:hover:not(:disabled) {
    transform: translateY(-1px) scale(1.05);
    box-shadow: 0 3px 10px rgba(0,153,153,.4);
}
.chat-widget-send-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
    filter: grayscale(.3);
}
.chat-widget-powered {
    text-align: center;
    margin-top: 7px;
    font-size: 9px;
    color: #cbd5e1;
    font-weight: 500;
    letter-spacing: .5px;
    text-transform: uppercase;
}
.chat-widget-powered strong {
    color: #009999;
    font-weight: 700;
}

/* ============================================================
   EMOJI PICKER
   ============================================================ */
.chat-widget-emoji-picker {
    position: absolute;
    bottom: 96px;
    right: 20px;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,.18), 0 0 0 1px rgba(0,0,0,.06);
    padding: 10px;
    display: none;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    width: 280px;
    z-index: 10;
    animation: emojiIn .2s cubic-bezier(.4, 0, .2, 1);
}
@keyframes emojiIn {
    from { opacity: 0; transform: translateY(6px) scale(.95); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}
.chat-widget-emoji-picker.open { display: grid; }
.chat-widget-emoji {
    font-size: 19px;
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
    transition: all .15s;
    text-align: center;
    line-height: 1;
    width: 100%;
}
.chat-widget-emoji:hover {
    background: rgba(0,153,153,.1);
    transform: scale(1.15);
}

/* ============================================================
   MOBILE -  VIEWPORT SAFE, STATUS BAR + NOTCH INSENT PADDING,
   FULL WIDTH BUT NOT EDGE-TO-EDGE
   ============================================================ */
@media (max-width: 520px) {
    .chat-widget-container {
        bottom: 22px;
        right:  14px;
        left:   auto;
        max-width: 100%;
    }
    .chat-widget-toggle {
        height: 30px;
        padding: 0 12px 0 10px;
        gap: 5px;
    }
    .chat-toggle-icon { font-size: 12px; }
    .chat-toggle-text { font-size: 11.5px; }
    .chat-toggle-ping {
        width: 9px;
        height: 9px;
        top: -2px;
        right: -2px;
    }
    .chat-widget-box {
        position: fixed;
        /* leave safe margins for status bar notch + bottom gesture nav */
        top:    max(10px, env(safe-area-inset-top)) !important;
        left:   8px !important;
        right:  8px !important;
        bottom: max(12px, env(safe-area-inset-bottom)) !important;
        width:  auto !important;
        height: auto !important;
        min-width:  auto !important;
        min-height: auto !important;
        max-width:  none !important;
        max-height: none !important;
        margin: 0 !important;
        border-radius: 16px;
    }
    .chat-widget-box.open { animation: slideUpMobile .3s ease; }
    @keyframes slideUpMobile {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }
    .chat-widget-header {
        height: 64px;
        min-height: 64px;
        max-height: 64px;
        flex: 0 0 64px;
        padding: 12px 16px;
    }
    .chat-widget-messages {
        padding: 14px;
    }
    .chat-widget-input-container {
        padding: 10px 12px 14px;
        min-height: 86px;
    }
    .chat-widget-emoji-picker {
        right: 12px;
        bottom: 90px;
        width: calc(100% - 24px);
    }
}

/* ============================================================
   HEADER ACTIONS GROUP (Clear + Close buttons) - ALWAYS VISIBLE
   ============================================================ */
.chat-widget-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    z-index: 5;              /* above the header gradient decorative blob */
    position: relative;      /* z-index only works on positioned elements */
}

/* Clear Chat Button */
.chat-widget-clear-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,.22);
    background: rgba(255,255,255,.12);
    color: #ffffff;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: inline-flex !important;   /* NEVER hide the clear button */
    visibility: visible !important;
    opacity: 1 !important;
    align-items: center;
    justify-content: center;
    transition: all .18s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    flex-shrink: 0;
}
.chat-widget-clear-btn:hover:not(:disabled) {
    background: rgba(255, 80, 80, 0.88);
    border-color: rgba(255,255,255,.45);
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.45);
}
.chat-widget-clear-btn:disabled {
    cursor: not-allowed;
    pointer-events: none;
    opacity: .55 !important;
}

/* Close Button - match size and ensure never hidden */
.chat-widget-close {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    min-height: 34px !important;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,.22);
    background: rgba(255,255,255,.14);
    color: #fff;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    align-items: center;
    justify-content: center;
    transition: all .18s ease;
    flex-shrink: 0;
}
.chat-widget-close:hover {
    background: rgba(255,255,255,.28);
    transform: rotate(90deg);
    border-color: rgba(255,255,255,.45);
}

/* ============================================================
   CONFIRMATION DIALOG (Custom lightweight modal)
   ============================================================ */
.chat-confirm-mask {
    position: absolute;
    inset: 0;
    z-index: 10;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border-radius: inherit;
    animation: confirmFadeIn .18s ease-out;
}
@keyframes confirmFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.chat-confirm-box {
    background: #ffffff;
    border-radius: 16px;
    box-shadow:
        0 22px 48px -12px rgba(15, 23, 42, 0.35),
        0 0 0 1px rgba(15, 23, 42, 0.05);
    max-width: 320px;
    width: 100%;
    padding: 22px 20px 18px;
    text-align: center;
    animation: confirmPopIn .22s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes confirmPopIn {
    from { opacity: 0; transform: translateY(8px) scale(.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-confirm-icon {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #dc2626;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.15);
}
.chat-confirm-title {
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 8px;
    line-height: 1.3;
}
.chat-confirm-body {
    font-size: 12.5px;
    color: #475569;
    line-height: 1.55;
    margin: 0 0 18px;
}
.chat-confirm-body strong {
    color: #b91c1c;
    font-weight: 600;
}
.chat-confirm-actions {
    display: flex;
    gap: 10px;
}
.chat-confirm-cancel,
.chat-confirm-ok {
    flex: 1;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all .15s ease;
    line-height: 1.2;
}
.chat-confirm-cancel {
    background: #f1f5f9;
    color: #475569;
}
.chat-confirm-cancel:hover {
    background: #e2e8f0;
    color: #0f172a;
}
.chat-confirm-ok {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.25);
}
.chat-confirm-ok:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(220, 38, 38, 0.35);
}
.chat-confirm-ok:active,
.chat-confirm-cancel:active {
    transform: translateY(0);
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.chat-toast-host {
    position: absolute;
    bottom: 110px;
    left: 10px;
    right: 10px;
    z-index: 20;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-toast {
    pointer-events: none;
    background: #0f172a;
    color: #f8fafc;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 12.5px;
    line-height: 1.4;
    box-shadow:
        0 10px 25px -6px rgba(15, 23, 42, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.05);
    transform: translateY(10px);
    opacity: 0;
    transition: opacity .2s ease, transform .22s cubic-bezier(.2,.9,.3,1.1);
    font-weight: 500;
    word-break: break-word;
}
.chat-toast.show {
    opacity: 1;
    transform: translateY(0);
}
.chat-toast-success {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    box-shadow:
        0 10px 24px -6px rgba(5, 150, 105, 0.4),
        0 0 0 1px rgba(255,255,255,.08);
}
.chat-toast-error {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    box-shadow:
        0 10px 24px -6px rgba(220, 38, 38, 0.4),
        0 0 0 1px rgba(255,255,255,.08);
}
.chat-toast-warning {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    box-shadow:
        0 10px 24px -6px rgba(217, 119, 6, 0.4),
        0 0 0 1px rgba(255,255,255,.08);
}
.chat-toast-info {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    box-shadow:
        0 10px 24px -6px rgba(2, 132, 199, 0.4),
        0 0 0 1px rgba(255,255,255,.08);
}

