/* WP Customer Service Pro - Frontend Chat Styles */
.wpcs-widget {
    --cs-primary: #2563eb;
    --cs-primary-rgb: 37, 99, 235;
    --cs-white: #ffffff;
    --cs-bg: #f3f4f6;
    --cs-border: #e5e7eb;
    --cs-radius: 16px;
    --cs-shadow: 0 20px 60px rgba(0,0,0,.18), 0 4px 20px rgba(0,0,0,.1);
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

/* Positions */
.wpcs-pos-bottom-right { bottom: 24px; right: 24px; }
.wpcs-pos-bottom-left  { bottom: 24px; left: 24px; }
.wpcs-pos-top-right    { top: 24px; right: 24px; }
.wpcs-pos-top-left     { top: 24px; left: 24px; }

/* Toggle Button */
.wpcs-toggle-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--cs-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(var(--cs-primary-rgb), .4);
    transition: transform .3s cubic-bezier(.34,1.56,.64,1), box-shadow .3s;
    position: relative;
    user-select: none;
}
.wpcs-toggle-btn:hover { transform: scale(1.08); box-shadow: 0 6px 25px rgba(var(--cs-primary-rgb), .5); }
.wpcs-toggle-btn:active { transform: scale(.95); }
.wpcs-btn-icon { transition: transform .3s, opacity .3s; }
.wpcs-close-icon { position: absolute; font-size: 18px; opacity: 0; transform: rotate(-90deg) scale(0); transition: all .3s; }
.wpcs-widget.wpcs-open .wpcs-btn-icon { opacity: 0; transform: scale(0) rotate(90deg); }
.wpcs-widget.wpcs-open .wpcs-close-icon { opacity: 1; transform: rotate(0) scale(1); }
.wpcs-unread-dot {
    position: absolute;
    top: -2px; right: -2px;
    width: 20px; height: 20px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}

/* Chat Window */
.wpcs-chat-window {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 24px);
    background: var(--cs-white);
    border-radius: var(--cs-radius);
    box-shadow: var(--cs-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: wpcs-open .3s cubic-bezier(.34,1.56,.64,1);
    max-height: 520px;
}
.wpcs-pos-bottom-left .wpcs-chat-window { right: auto; left: 0; transform-origin: bottom left; }
.wpcs-pos-top-right .wpcs-chat-window { bottom: auto; top: 72px; transform-origin: top right; }
.wpcs-pos-top-left .wpcs-chat-window { bottom: auto; top: 72px; right: auto; left: 0; transform-origin: top left; }

@keyframes wpcs-open {
    from { opacity: 0; transform: scale(.8) translateY(20px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Header */
.wpcs-chat-header {
    background: var(--cs-primary);
    color: white;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.wpcs-bot-info { display: flex; align-items: center; gap: 12px; }
.wpcs-bot-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
    overflow: hidden;
}
.wpcs-bot-avatar img { width: 100%; height: 100%; object-fit: cover; }
.wpcs-bot-name { font-weight: 700; font-size: 16px; letter-spacing: .3px; }
.wpcs-online-status { font-size: 12px; opacity: .85; display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.wpcs-dot { width: 8px; height: 8px; background: #86efac; border-radius: 50%; animation: wpcs-blink 2s infinite; }
@keyframes wpcs-blink { 0%,100%{opacity:1} 50%{opacity:.3} }
.wpcs-header-close { background: none; border: none; color: rgba(255,255,255,.7); font-size: 18px; cursor: pointer; padding: 4px; border-radius: 6px; }
.wpcs-header-close:hover { background: rgba(255,255,255,.15); color: white; }

/* Messages */
.wpcs-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #f8fafc;
    min-height: 250px;
    max-height: 320px;
    scroll-behavior: smooth;
}
.wpcs-messages::-webkit-scrollbar { width: 4px; }
.wpcs-messages::-webkit-scrollbar-track { background: transparent; }
.wpcs-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

/* Message Bubbles */
.wpcs-msg { display: flex; gap: 8px; align-items: flex-end; animation: wpcs-msg-in .3s ease; }
@keyframes wpcs-msg-in { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:none} }
.wpcs-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--cs-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    overflow: hidden;
}
.wpcs-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.wpcs-msg-avatar.user-av { background: #8b5cf6; }
.wpcs-msg-content { max-width: 78%; }
.wpcs-msg-name { font-size: 11px; color: #9ca3af; margin-bottom: 4px; font-weight: 500; }
.wpcs-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    position: relative;
}
.wpcs-msg-bot .wpcs-bubble, .wpcs-msg-agent .wpcs-bubble {
    background: white;
    border: 1px solid var(--cs-border);
    border-bottom-left-radius: 4px;
    color: #111827;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.wpcs-msg-user { flex-direction: row-reverse; }
.wpcs-msg-user .wpcs-bubble {
    background: var(--cs-primary);
    color: white;
    border-bottom-right-radius: 4px;
}
.wpcs-msg-user .wpcs-msg-content { align-items: flex-end; display: flex; flex-direction: column; }
.wpcs-msg-time { font-size: 10px; color: #d1d5db; margin-top: 4px; }
.wpcs-msg-user .wpcs-msg-time { color: rgba(255,255,255,.6); text-align: right; }

/* Typing indicator */
.wpcs-typing {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    flex-shrink: 0;
}
.wpcs-typing-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    background: white;
    border: 1px solid var(--cs-border);
    padding: 8px 12px;
    border-radius: 20px;
}
.wpcs-typing-bubble span {
    width: 6px; height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: wpcs-typing 1.4s infinite;
}
.wpcs-typing-bubble span:nth-child(2) { animation-delay: .2s; }
.wpcs-typing-bubble span:nth-child(3) { animation-delay: .4s; }
@keyframes wpcs-typing { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-8px)} }
.wpcs-typing-text { font-size: 12px; color: #9ca3af; }

/* Quick replies */
.wpcs-quick-reply-bar {
    display: flex;
    gap: 6px;
    padding: 0 12px 8px;
    flex-wrap: wrap;
    background: #f8fafc;
    flex-shrink: 0;
}
.wpcs-quick-reply-btn {
    padding: 7px 14px;
    border: 1.5px solid var(--cs-primary);
    color: var(--cs-primary);
    border-radius: 20px;
    font-size: 13px;
    background: white;
    cursor: pointer;
    transition: all .2s;
    font-family: inherit;
}
.wpcs-quick-reply-btn:hover { background: var(--cs-primary); color: white; }

/* Input */
.wpcs-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--cs-border);
    background: white;
    flex-shrink: 0;
}
.wpcs-input-area textarea {
    flex: 1;
    border: 1px solid var(--cs-border);
    border-radius: 22px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    font-family: inherit;
    line-height: 1.4;
    max-height: 100px;
    transition: border-color .2s;
    background: #f9fafb;
}
.wpcs-input-area textarea:focus { border-color: var(--cs-primary); background: white; }
.wpcs-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--cs-primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform .2s, background .2s;
}
.wpcs-send-btn:hover { transform: scale(1.1); }
.wpcs-send-btn:disabled { background: #d1d5db; }

/* Offline Form */
.wpcs-offline-form {
    padding: 20px;
    background: white;
    border-top: 1px solid var(--cs-border);
}
.wpcs-offline-form h4 { margin: 0 0 14px; font-size: 15px; color: #111827; }
.wpcs-offline-form input, .wpcs-offline-form textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--cs-border);
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 8px;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
}
.wpcs-offline-form textarea { resize: none; }
.wpcs-offline-form button {
    width: 100%;
    padding: 12px;
    background: var(--cs-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

/* Footer */
.wpcs-footer {
    padding: 6px 16px;
    text-align: center;
    font-size: 11px;
    color: #d1d5db;
    background: white;
    border-top: 1px solid #f3f4f6;
    flex-shrink: 0;
}

/* System message */
.wpcs-system-msg {
    text-align: center;
    font-size: 12px;
    color: #9ca3af;
    padding: 6px 12px;
    background: rgba(0,0,0,.04);
    border-radius: 20px;
    margin: 0 auto;
}

/* Rating Stars */
.wpcs-rating { text-align: center; padding: 10px 16px; border-top: 1px solid var(--cs-border); }
.wpcs-stars-input span {
    font-size: 24px;
    cursor: pointer;
    color: #d1d5db;
    transition: color .15s;
}
.wpcs-stars-input span.active, .wpcs-stars-input span:hover { color: #f59e0b; }

/* Mobile Responsive */
@media (max-width: 480px) {
    .wpcs-chat-window {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 85vh !important;
    }
    .wpcs-pos-bottom-left .wpcs-toggle-btn,
    .wpcs-pos-bottom-right .wpcs-toggle-btn { bottom: 16px; }
    .wpcs-messages { max-height: 50vh; }
}
