/* UltraSmart Connect — Chat Widget */

#plc-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
#plc-chat-widget.plc-chat-bottom-right { bottom: 20px; right: 20px; }
#plc-chat-widget.plc-chat-bottom-left { bottom: 20px; left: 20px; }

/* Toggle Button */
.plc-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}
.plc-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}

/* Chat Window */
.plc-chat-window {
    position: absolute;
    bottom: 72px;
    width: 370px;
    height: 500px;
    max-height: calc(100vh - 100px);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.plc-chat-bottom-right .plc-chat-window { right: 0; }
.plc-chat-bottom-left .plc-chat-window { left: 0; }

/* Header */
.plc-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    color: #fff;
    flex-shrink: 0;
}
.plc-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.plc-chat-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.plc-chat-name {
    font-size: 15px;
    font-weight: 600;
}
.plc-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}
.plc-chat-new {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
    padding: 0;
}
.plc-chat-new:hover { opacity: 1; background: rgba(255,255,255,0.25); }
.plc-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.8;
    line-height: 1;
}
.plc-chat-close:hover { opacity: 1; }

/* Messages */
.plc-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.plc-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    animation: plcMsgFade 0.3s ease;
}
@keyframes plcMsgFade {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.plc-chat-msg-user {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.plc-chat-msg-assistant {
    align-self: flex-start;
    background: #f1f3f5;
    color: #1d2327;
    border-bottom-left-radius: 4px;
}

.plc-chat-msg-assistant a {
    color: #2563eb;
    text-decoration: underline;
}

/* Typing indicator */
.plc-chat-typing {
    align-self: flex-start;
    padding: 10px 16px;
    background: #f1f3f5;
    border-radius: 16px;
    display: flex;
    gap: 4px;
}
.plc-typing-dot {
    width: 7px;
    height: 7px;
    background: #aaa;
    border-radius: 50%;
    animation: plcTyping 1.4s infinite ease-in-out;
}
.plc-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.plc-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes plcTyping {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Input */
.plc-chat-input-area {
    display: flex;
    align-items: flex-end;
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    gap: 8px;
    flex-shrink: 0;
}
#plc-chat-input {
    flex: 1;
    border: 1.5px solid #d1d5db;
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    outline: none;
    font-family: inherit;
}
#plc-chat-input:focus { border-color: #2563eb; }

#plc-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
#plc-chat-send:hover { opacity: 0.85; }

/* Escalation */
.plc-chat-escalation {
    padding: 8px 16px;
    text-align: center;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.plc-chat-escalation a {
    font-size: 13px;
    color: #6b7280;
    text-decoration: none;
}
.plc-chat-escalation a:hover { color: #1d2327; }

/* Mobile */
@media (max-width: 480px) {
    .plc-chat-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        bottom: 68px;
    }
    #plc-chat-widget.plc-chat-bottom-right { right: 16px; }
    #plc-chat-widget.plc-chat-bottom-left { left: 16px; }
}

/* Safe area for iPhone notch */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #plc-chat-widget {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
}
