/* LuwiPress Customer Chat Widget */
.lp-chat-widget {
    --lp-primary: #6366f1;
    --lp-text: #ffffff;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99990;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}
.lp-chat-widget *, .lp-chat-widget *::before, .lp-chat-widget *::after { box-sizing: border-box; margin: 0; padding: 0; }
.lp-ico { font-style: normal; font-size: inherit; line-height: 1; display: inline-block; }
.lp-chat-widget.lp-chat-left { right: auto; left: 20px; }

/* Toggle — minimal pill */
.lp-chat-toggle {
    height: 40px;
    padding: 0 16px;
    border-radius: 20px;
    background: var(--lp-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 2px 10px rgba(0,0,0,.12);
    transition: transform .2s ease, box-shadow .2s ease;
    position: relative;
    color: var(--lp-text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: .01em;
}
.lp-chat-toggle:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
}
.lp-chat-toggle::before {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
}
.lp-chat-toggle::after {
    content: 'Chat';
}

/* Window */
.lp-chat-window {
    position: absolute;
    bottom: 58px;
    right: 0;
    width: 340px;
    max-height: 460px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,.12), 0 0 0 1px rgba(0,0,0,.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(.85) translateY(10px);
    opacity: 0;
    pointer-events: none;
    transition: transform .2s cubic-bezier(.4,0,.2,1), opacity .2s ease;
    transform-origin: bottom right;
}
.lp-chat-widget.lp-chat-left .lp-chat-window {
    right: auto; left: 0;
    transform-origin: bottom left;
}
.lp-chat-widget:not(.lp-chat-closed) .lp-chat-window {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}
.lp-chat-widget:not(.lp-chat-closed) .lp-chat-toggle { display: none; }

/* Header — compact */
.lp-chat-header {
    background: var(--lp-primary);
    color: var(--lp-text);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.lp-chat-header-info { display: flex; flex-direction: column; }
.lp-chat-title { font-weight: 600; font-size: 13px; }
.lp-chat-subtitle { font-size: 10px; opacity: .7; }
.lp-chat-header-actions { display: flex; gap: 4px; align-items: center; }
.lp-chat-header-actions button {
    background: rgba(255,255,255,.15) !important;
    border: none !important;
    color: var(--lp-text) !important;
    cursor: pointer;
    width: 26px !important;
    height: 26px !important;
    min-width: 26px !important;
    min-height: 26px !important;
    max-width: 26px !important;
    max-height: 26px !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: background .15s;
    font-size: 13px;
    line-height: 1;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden;
    box-sizing: border-box !important;
}
.lp-chat-header-actions button:hover { background: rgba(255,255,255,.2); }
.lp-chat-escalate-btn {
    background: linear-gradient(135deg, #25d366, #20ba5a) !important;
    border-radius: 50% !important;
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    max-width: 32px !important;
    max-height: 32px !important;
    animation: lp-ring-pulse 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    position: relative;
    z-index: 2;
    box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.5);
}
.lp-chat-escalate-btn:hover {
    background: linear-gradient(135deg, #128c7e, #075e54) !important;
    animation: none !important;
    transform: scale(1.2);
    box-shadow: 0 2px 12px rgba(37, 211, 102, 0.5) !important;
}
.lp-chat-escalate-btn::before {
    content: '';
    display: inline-block;
    width: 16px;
    min-width: 16px;
    height: 16px;
    min-height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M20 15.5c-1.25 0-2.45-.2-3.57-.57a1 1 0 00-1.02.24l-2.2 2.2a15.05 15.05 0 01-6.59-6.58l2.2-2.21a1 1 0 00.24-1.02A11.36 11.36 0 018.5 4c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1 0 9.39 7.61 17 17 17 .55 0 1-.45 1-1v-3.5c0-.55-.45-1-1-1z'/%3E%3C/svg%3E");
    background-size: 16px 16px;
    background-repeat: no-repeat;
    background-position: center;
    filter: drop-shadow(0 0 2px rgba(255,255,255,0.5));
}
/* After pseudo-element: expanding ring */
.lp-chat-escalate-btn::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(37, 211, 102, 0.6);
    animation: lp-ring-expand 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
.lp-chat-escalate-btn:hover::after {
    animation: none !important;
    border-color: transparent;
}
@keyframes lp-ring-pulse {
    0% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.5); }
    70% { box-shadow: 0 0 0 10px rgba(37, 211, 102, 0); }
    100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); }
}
@keyframes lp-ring-expand {
    0% { inset: -2px; opacity: 1; border-width: 2px; }
    100% { inset: -10px; opacity: 0; border-width: 1px; }
}
.lp-chat-close-btn { font-size: 16px; line-height: 1; color: var(--lp-text) !important; }

/* Body */
.lp-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 200px;
    max-height: 280px;
    background: #fafafa;
}
.lp-chat-body { scrollbar-width: thin; scrollbar-color: #d1d5db transparent; }
.lp-chat-body::-webkit-scrollbar { width: 4px; }
.lp-chat-body::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
.lp-chat-body::-webkit-scrollbar-track { background: transparent; }

/* Messages */
.lp-chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    animation: lp-msg-in .2s ease;
}
.lp-chat-msg-customer { align-self: flex-end; align-items: flex-end; }
.lp-chat-msg-assistant { align-self: flex-start; align-items: flex-start; }
@keyframes lp-msg-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
.lp-chat-bubble {
    padding: 8px 12px;
    border-radius: 12px;
    word-break: break-word;
    font-size: 13px;
    line-height: 1.4;
}
.lp-chat-msg-customer .lp-chat-bubble {
    background: var(--lp-primary);
    color: var(--lp-text);
    border-bottom-right-radius: 3px;
}
.lp-chat-msg-assistant .lp-chat-bubble {
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 3px;
}
.lp-chat-bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.lp-chat-msg-assistant .lp-chat-bubble a { color: var(--lp-primary); }
.lp-chat-time { font-size: 10px; color: #aaa; margin-top: 2px; padding: 0 4px; }

/* Typing */
.lp-chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px !important;
    background: #fff !important;
    border: 1px solid #e5e7eb !important;
}
.lp-chat-typing span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #bbb;
    animation: lp-typing 1.4s infinite;
}
.lp-chat-typing span:nth-child(2) { animation-delay: .2s; }
.lp-chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes lp-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: .3; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Input */
.lp-chat-input-area {
    display: flex;
    padding: 8px 10px;
    gap: 6px;
    border-top: 1px solid #eee;
    background: #fff;
    flex-shrink: 0;
}
.lp-chat-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 18px;
    padding: 7px 12px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
    background: #f5f5f5;
    transition: border-color .15s, background .15s;
}
.lp-chat-input:focus { border-color: var(--lp-primary); background: #fff; }
.lp-chat-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--lp-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .15s;
    flex-shrink: 0;
}
.lp-chat-send-btn::before {
    content: '';
    display: inline-block;
    width: 16px;
    min-width: 16px;
    height: 16px;
    min-height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M2.01 21L23 12 2.01 3 2 10l15 2-15 2z'/%3E%3C/svg%3E");
    background-size: 16px 16px;
    background-repeat: no-repeat;
    background-position: center;
}
.lp-chat-send-btn:disabled { opacity: .25; cursor: default; }
.lp-chat-send-btn:not(:disabled):hover { opacity: .85; }

/* Footer */
.lp-chat-footer {
    text-align: center;
    padding: 4px;
    font-size: 9px;
    color: #c0c0c0;
    background: #fff;
    flex-shrink: 0;
}

/* Channel choice */
.lp-chat-channel-choice p { margin: 0 0 6px; font-size: 12px; }
.lp-chat-channel-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 16px;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    margin: 0 4px 4px 0;
    transition: opacity .15s;
}
.lp-chat-channel-btn:hover { opacity: .85; }
.lp-chat-wa-btn { background: #25d366; color: #fff; }
.lp-chat-tg-btn { background: #0088cc; color: #fff; }

/* Inline escalation */
.lp-chat-inline-escalate {
    display: inline-block;
    margin-top: 6px;
    padding: 5px 12px;
    background: var(--lp-primary);
    color: var(--lp-text);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}
.lp-chat-inline-escalate:hover { opacity: .85; }

/* Mobile — full screen chat */
@media (max-width: 600px) {
    .lp-chat-widget { bottom: 14px; right: 14px; }
    .lp-chat-widget.lp-chat-left { left: 14px; }
    .lp-chat-toggle { height: 36px; padding: 0 12px; font-size: 12px; }
    .lp-chat-toggle::before { width: 14px; height: 14px; min-width: 14px; min-height: 14px; background-size: 14px 14px; }
    .lp-chat-window {
        position: fixed;
        top: 0; bottom: 0; right: 0; left: 0;
        width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        transform-origin: bottom center;
    }
    .lp-chat-body {
        flex: 1;
        min-height: 0;
        max-height: none;
    }
    .lp-chat-header { border-radius: 0; }
}

/* Avoid floating cart overlap — extra bottom spacing for right-side widgets */
@media (min-width: 601px) {
    .lp-chat-widget:not(.lp-chat-left) { bottom: 80px; }
}
