/* ============================================================================
   Live Chat widget — WhatsApp-inspired light skin (Phase 3b).
   Scoped under #gcw so nothing leaks into / out of the host page.
   ============================================================================ */

#gcw, #gcw * { box-sizing: border-box; font-family: 'Segoe UI', Helvetica, Arial, sans-serif; }

/* Floating launcher bubble */
#gcw-bubble {
    position: fixed; bottom: 22px; right: 22px; z-index: 99998;
    width: 60px; height: 60px; border-radius: 50%;
    background: #25D366; /* WhatsApp green */
    color: #fff; border: none; cursor: pointer;
    box-shadow: 0 8px 24px rgba(37,211,102,0.45);
    display: flex; align-items: center; justify-content: center;
    transition: transform .15s, box-shadow .15s;
}
#gcw-bubble:hover { transform: scale(1.05); box-shadow: 0 10px 30px rgba(37,211,102,0.55); }
#gcw-bubble svg { width: 30px; height: 30px; fill: #fff; }
#gcw-bubble.gcw-bubble-custom { background: transparent; box-shadow: 0 8px 24px rgba(0,0,0,0.30); overflow: hidden; }
#gcw-bubble.gcw-bubble-custom:hover { box-shadow: 0 10px 30px rgba(0,0,0,0.40); }
#gcw-bubble .gcw-bubble-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
#gcw-bubble .gcw-unread {
    position: absolute; top: -2px; right: -2px;
    min-width: 20px; height: 20px; border-radius: 10px;
    background: #ef4444; color: #fff; font-size: 11px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    padding: 0 5px; border: 2px solid #fff;
}

/* Panel */
#gcw-panel {
    position: fixed; bottom: 96px; right: 22px; z-index: 99999;
    width: 380px; max-width: calc(100vw - 32px);
    height: 580px; max-height: calc(100vh - 130px);
    background: #ECE5DD; /* WhatsApp beige chat background */
    color: #303030;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 12px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.30);
    display: none; flex-direction: column; overflow: hidden;
    transform-origin: bottom right;
    animation: gcw-pop .18s ease-out;
    color-scheme: light;
}
#gcw-panel.open { display: flex; }
@keyframes gcw-pop { from { opacity: 0; transform: scale(.95) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* Header — WhatsApp dark teal */
#gcw-head {
    background: #075E54;
    color: #fff; padding: 10px 14px;
    display: flex; align-items: center; gap: 11px;
    flex-shrink: 0;
}
#gcw-head .gcw-avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: rgba(255,255,255,0.22);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; overflow: hidden;
    border: 1.5px solid rgba(255,255,255,0.45);
}
#gcw-head .gcw-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Team mode — multiple avatars stacked WhatsApp-group style */
#gcw-head .gcw-avatar.gcw-avatar-multi {
    width: 92px; height: 42px;
    border: 0; background: transparent; overflow: visible;
    position: relative;
}
#gcw-head .gcw-avatar.gcw-avatar-multi img.gcw-avatar-stack {
    position: absolute; top: 5px;
    width: 28px; height: 28px; border-radius: 50%;
    border: 2px solid #075E54; object-fit: cover;
    background: #fff; cursor: pointer;
}
/* Active persona (first) is bigger and in front */
#gcw-head .gcw-avatar.gcw-avatar-multi img.gcw-avatar-stack:nth-child(1) { left: 0;  top: 1px; z-index: 20; width: 38px; height: 38px; }
#gcw-head .gcw-avatar.gcw-avatar-multi img.gcw-avatar-stack:nth-child(2) { left: 28px; z-index: 19; }
#gcw-head .gcw-avatar.gcw-avatar-multi img.gcw-avatar-stack:nth-child(3) { left: 44px; z-index: 18; }
#gcw-head .gcw-avatar.gcw-avatar-multi img.gcw-avatar-stack:nth-child(4) { left: 60px; z-index: 17; }
#gcw-head .gcw-avatar.gcw-avatar-multi img.gcw-avatar-stack:nth-child(5) { left: 76px; z-index: 16; }
#gcw-head .gcw-title { flex: 1; min-width: 0; }
#gcw-head .gcw-name {
    font-size: 15px; font-weight: 600; line-height: 1.15;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#gcw-head .gcw-role {
    font-size: 11.5px; opacity: .82; margin-top: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#gcw-head .gcw-status {
    font-size: 11px; opacity: .82;
    display: flex; align-items: center; gap: 5px; margin-top: 1px;
}
#gcw-head .gcw-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #25D366; box-shadow: 0 0 0 2px rgba(37,211,102,0.30);
}
#gcw-head .gcw-close {
    width: 30px; height: 30px; border: none; border-radius: 6px;
    background: rgba(255,255,255,0.14); color: #fff; cursor: pointer;
    font-size: 22px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
#gcw-head .gcw-close:hover { background: rgba(255,255,255,0.26); }

/* Chat body — beige with subtle pattern */
#gcw-body {
    flex: 1; overflow-y: auto;
    padding: 14px 12px;
    background: #ECE5DD;
    background-image:
        radial-gradient(rgba(0,0,0,0.025) 1px, transparent 1px),
        radial-gradient(rgba(0,0,0,0.025) 1px, transparent 1px);
    background-size: 22px 22px;
    background-position: 0 0, 11px 11px;
    display: flex; flex-direction: column; gap: 6px;
    scroll-behavior: smooth;
}
#gcw-body::-webkit-scrollbar { width: 6px; }
#gcw-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.20); border-radius: 3px; }
#gcw-body::-webkit-scrollbar-track { background: transparent; }

/* Message rows */
.gcw-msg { display: flex; max-width: 85%; animation: gcw-msgin .2s ease-out; }
@keyframes gcw-msgin { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.gcw-msg-wrap { position: relative; padding: 6px 9px 22px; border-radius: 7.5px; font-size: 13.5px;
    line-height: 1.4; word-break: break-word; color: #303030;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13); min-width: 70px; }

/* Bubble corners — WhatsApp signature "tail" via clip-path triangle */
.gcw-msg.user        { align-self: flex-end; }
.gcw-msg.user .gcw-msg-wrap        { background: #DCF8C6; border-top-right-radius: 0; }
.gcw-msg.user .gcw-msg-wrap::before {
    content: ''; position: absolute; top: 0; right: -7px;
    border: 7px solid transparent;
    border-top-color: #DCF8C6; border-right: 0;
}

.gcw-msg.ai, .gcw-msg.admin { align-self: flex-start; }
.gcw-msg.ai .gcw-msg-wrap,
.gcw-msg.admin .gcw-msg-wrap        { background: #ffffff; border-top-left-radius: 0; }
.gcw-msg.ai .gcw-msg-wrap::before,
.gcw-msg.admin .gcw-msg-wrap::before {
    content: ''; position: absolute; top: 0; left: -7px;
    border: 7px solid transparent;
    border-top-color: #ffffff; border-left: 0;
}

.gcw-msg.system {
    align-self: center; max-width: 95%;
}
.gcw-msg.system .gcw-msg-wrap {
    background: rgba(225,245,254,0.92); color: #075E54;
    font-size: 11.5px; padding: 5px 10px;
    border-radius: 8px; box-shadow: none;
    font-weight: 500;
}
.gcw-msg.system .gcw-msg-wrap::before { display: none; }
.gcw-msg.system .gcw-msg-time { display: none; }

/* Timestamp inside the bubble — bottom right */
.gcw-msg-time {
    position: absolute; bottom: 3px; right: 8px;
    font-size: 10.5px; color: rgba(0,0,0,0.45);
    display: flex; align-items: center; gap: 3px;
}
.gcw-msg-author {
    font-size: 11.5px; font-weight: 700; color: #06CF9C;
    margin-bottom: 2px;
}
/* WhatsApp-like "double tick" on user msgs (visually only — no real read receipt yet) */
.gcw-tick {
    width: 14px; height: 14px; display: inline-block; opacity: .55;
}

/* Auto-detected links inside bubbles */
/* ── Attachment picker + bubbles ─────────────────────────────────────── */
#gcw-attach {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 50%;
    cursor: pointer; flex-shrink: 0; color: #54656F;
    transition: background .15s;
}
#gcw-attach:hover { background: rgba(0,0,0,0.06); color: #075E54; }
#gcw-attach svg { width: 22px; height: 22px; fill: currentColor; }
#gcw-mic {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 50%;
    background: transparent; border: 0; cursor: pointer;
    color: #54656F; flex-shrink: 0; transition: background .15s, color .15s;
}
#gcw-mic:hover { background: rgba(0,0,0,0.06); color: #075E54; }
#gcw-mic svg { width: 22px; height: 22px; fill: currentColor; }
#gcw-mic.gcw-mic-rec { color: #fff; background: #ef4444; animation: gcw-pulse 1s infinite; }
@keyframes gcw-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* Recording bar shown above #gcw-foot during MediaRecorder capture */
#gcw-rec-bar {
    display: none; align-items: center; gap: 10px;
    padding: 10px 14px; border-top: 1px solid rgba(0,0,0,0.08);
    background: #fff3cd; font-size: 13px; color: #92400e;
}
.gcw-rec-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: #ef4444; animation: gcw-pulse 1s infinite; flex-shrink: 0;
}
.gcw-rec-txt { font-weight: 600; }
.gcw-rec-time { font-family: monospace; font-weight: 700; margin-right: auto; }
.gcw-rec-cancel, .gcw-rec-send {
    padding: 5px 12px; border: 0; border-radius: 6px;
    font-size: 12px; font-weight: 600; cursor: pointer;
}
.gcw-rec-cancel { background: #e5e7eb; color: #374151; }
.gcw-rec-cancel:hover { background: #d1d5db; }
.gcw-rec-send { background: #075E54; color: #fff; }
.gcw-rec-send:hover { background: #0a7869; }
.gcw-att-img img { max-width: 220px; max-height: 240px; border-radius: 8px; display: block; }
.gcw-att-audio { width: 230px; max-width: 100%; vertical-align: middle; }
.gcw-att-doc {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 12px; background: rgba(0,0,0,0.04);
    border-radius: 8px; color: inherit; text-decoration: none;
    font-size: 13px; word-break: break-all;
}
.gcw-att-doc:hover { background: rgba(0,0,0,0.08); }
.gcw-att-sz { color: #6b7280; font-size: 11px; }

.gcw-link {
    color: #039BE5; text-decoration: underline; word-break: break-all; font-weight: 500;
}
.gcw-msg.user .gcw-link, .gcw-msg.user .gcw-link:hover { color: #039BE5; }

/* "Persona is typing…" — WhatsApp dot loader */
.gcw-typing {
    align-self: flex-start; max-width: 80px;
    background: #ffffff; border-top-left-radius: 0;
    border-radius: 7.5px; padding: 9px 14px;
    display: flex; align-items: center; gap: 4px;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
    position: relative;
}
.gcw-typing::before {
    content: ''; position: absolute; top: 0; left: -7px;
    border: 7px solid transparent;
    border-top-color: #ffffff; border-left: 0;
}
.gcw-typing span {
    width: 7px; height: 7px; background: #93A8B6; border-radius: 50%;
    animation: gcw-blink 1.4s infinite both;
}
.gcw-typing span:nth-child(2) { animation-delay: .2s; }
.gcw-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes gcw-blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* Footer / input bar */
#gcw-foot {
    padding: 9px 10px; background: #F0F0F0;
    border-top: 1px solid rgba(0,0,0,0.08);
    display: flex; align-items: flex-end; gap: 8px;
    flex-shrink: 0;
}
#gcw-input {
    flex: 1; padding: 10px 14px;
    border: 0; border-radius: 22px;
    background: #ffffff;
    color: #303030;
    font-size: 14px; font-family: inherit; line-height: 1.35;
    resize: none; min-height: 40px; max-height: 110px; outline: none;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}
#gcw-input::placeholder { color: #94A3B8; }
#gcw-input:focus { box-shadow: 0 0 0 2px rgba(7,94,84,0.22); }
#gcw-send {
    width: 44px; height: 44px; border-radius: 50%; border: none;
    background: #075E54;
    color: #fff; cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
}
#gcw-send:hover:not(:disabled) { background: #128C7E; }
#gcw-send:disabled { opacity: .4; cursor: not-allowed; }
#gcw-send svg { width: 22px; height: 22px; fill: #fff; }

#gcw-err {
    padding: 7px 14px; background: #FEE2E2; color: #B91C1C;
    font-size: 12px; border-top: 1px solid #FCA5A5; display: none;
}
#gcw-err.show { display: block; }

/* Proactive nudge — light bubble above the launcher */
#gcw-nudge {
    position: fixed; bottom: 96px; right: 22px; z-index: 2147483646;
    max-width: 280px; padding: 14px 36px 14px 16px;
    background: #fff; color: #1e293b;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.18), 0 2px 6px rgba(0,0,0,0.08);
    font: 500 13.5px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    cursor: pointer;
    animation: gcwNudgeIn .35s cubic-bezier(.2,.9,.3,1.2);
    border: 1px solid rgba(0,0,0,0.06);
}
.gcw-nudge-text { color: inherit; }
.gcw-nudge-close {
    position: absolute; top: 6px; right: 6px;
    width: 22px; height: 22px;
    background: rgba(0,0,0,0.06); border: 0; border-radius: 50%;
    color: #64748b; font-size: 16px; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.gcw-nudge-close:hover { background: rgba(0,0,0,0.12); color: #1e293b; }
.gcw-nudge-arrow {
    position: absolute; bottom: -8px; right: 32px;
    width: 0; height: 0;
    border-left: 8px solid transparent; border-right: 8px solid transparent;
    border-top: 8px solid #fff;
    filter: drop-shadow(0 1px 0 rgba(0,0,0,0.05));
}
.gcw-nudge-badge {
    display: inline-block; background: #25D366;
    color: #fff; font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; padding: 2px 7px; border-radius: 99px;
    margin-bottom: 6px;
}
@keyframes gcwNudgeIn {
    0% { opacity: 0; transform: translateY(8px) scale(.96); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 480px) {
    #gcw-panel { right: 6px; left: 6px; width: auto; bottom: 88px; height: calc(100vh - 120px); border-radius: 8px; }
    #gcw-bubble { right: 14px; bottom: 14px; }
}
