/* CutArc Support Chat Widget */

#chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Toggle button */
#chat-toggle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #c8956c;
    border: none;
    color: #1a1a2e;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    transition: transform 0.2s, background 0.2s;
}

#chat-toggle:hover { transform: scale(1.08); background: #e0a87c; }
#chat-toggle.chat-active { background: #556; }

/* Panel */
#chat-panel {
    position: absolute;
    bottom: 60px;
    right: 0;
    width: 360px;
    max-height: 500px;
    background: #16213e;
    border: 1px solid #2a3a5e;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    transition: width 0.2s, max-height 0.2s;
}

#chat-panel.chat-hidden { display: none; }

#chat-panel.chat-expanded {
    width: 560px;
    max-height: 75vh;
    bottom: 20px;
}

/* Header */
#chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #1a1a2e;
    border-bottom: 1px solid #2a3a5e;
    font-size: 0.85rem;
    font-weight: 600;
    color: #eee;
}

#chat-header span:first-child { flex: 1; }

#chat-close {
    background: none;
    border: none;
    color: #aab;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
#chat-close:hover { color: #eee; }

.chat-badge {
    font-size: 0.65rem;
    background: rgba(200, 149, 108, 0.2);
    color: #c8956c;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

/* Messages area */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 200px;
}

/* Expand button */
#chat-expand {
    background: none;
    border: none;
    color: #aab;
    font-size: 1rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: transform 0.2s;
}
#chat-expand:hover { color: #eee; }
.chat-expanded #chat-expand { transform: rotate(180deg); }

.chat-msg {
    display: flex;
}

.chat-user { justify-content: flex-end; }
.chat-assistant { justify-content: flex-start; }

.chat-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.82rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-user .chat-bubble {
    background: #c8956c;
    color: #1a1a2e;
    border-bottom-right-radius: 4px;
}

.chat-assistant .chat-bubble {
    background: #1a1a2e;
    color: #dde;
    border: 1px solid #2a3a5e;
    border-bottom-left-radius: 4px;
}

/* Typing indicator */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 16px;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    background: #556;
    border-radius: 50%;
    animation: chatTyping 1.2s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatTyping {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* Upgrade bar */
#chat-upgrade {
    padding: 10px 16px;
    background: rgba(200, 149, 108, 0.1);
    border-top: 1px solid #2a3a5e;
    font-size: 0.78rem;
    color: #aab;
    text-align: center;
}

#chat-upgrade a {
    color: #c8956c;
    text-decoration: underline;
    font-weight: 600;
}

#chat-upgrade.chat-hidden { display: none; }

/* Input form */
#chat-form {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid #2a3a5e;
    background: #1a1a2e;
}

#chat-form.chat-hidden { display: none; }

#chat-input {
    flex: 1;
    padding: 8px 12px;
    background: #16213e;
    color: #eee;
    border: 1px solid #2a3a5e;
    border-radius: 8px;
    font-size: 0.82rem;
    outline: none;
}

#chat-input:focus { border-color: #c8956c; }
#chat-input:disabled { opacity: 0.5; }

#chat-send {
    width: 36px;
    height: 36px;
    background: #c8956c;
    color: #1a1a2e;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

#chat-send:hover { background: #e0a87c; }
#chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Scrollbar */
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: #2a3a5e; border-radius: 2px; }

/* Quick action buttons */
#chat-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 12px;
    border-top: 1px solid #2a3a5e;
}

#chat-quick-actions.chat-hidden { display: none; }

.chat-quick-btn {
    padding: 4px 10px;
    background: rgba(200, 149, 108, 0.1);
    color: #c8956c;
    border: 1px solid rgba(200, 149, 108, 0.25);
    border-radius: 12px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.chat-quick-btn:hover {
    background: rgba(200, 149, 108, 0.2);
    border-color: #c8956c;
}

/* Feedback buttons */
.chat-feedback-row {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}

.chat-feedback {
    background: none;
    border: none;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.4;
    transition: opacity 0.15s;
}

.chat-feedback:hover { opacity: 0.8; }
.chat-feedback.chat-fb-active { opacity: 1; }
.chat-feedback:disabled { cursor: default; }

/* Email escalation */
#chat-escalation {
    padding: 8px 12px;
    border-top: 1px solid #2a3a5e;
    text-align: center;
}

#chat-escalation.chat-hidden { display: none; }

.chat-escalate-btn {
    width: 100%;
    padding: 7px 12px;
    background: transparent;
    color: #c8956c;
    border: 1px solid rgba(200, 149, 108, 0.3);
    border-radius: 8px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
}

.chat-escalate-btn:hover {
    background: rgba(200, 149, 108, 0.1);
    border-color: #c8956c;
}

.chat-escalate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Agent canvas-command result chip */
.chat-cmd-result { font-size: 12px; }
.chat-cmd-ok { color: #4caf50; }
.chat-cmd-skip { color: #ff9800; margin-top: 4px; }
.chat-undo-btn {
    margin-left: 8px;
    padding: 2px 10px;
    font-size: 11px;
    border: 1px solid currentColor;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.chat-undo-btn:disabled { opacity: 0.5; cursor: default; }

/* Mobile responsive */
@media (max-width: 480px) {
    #chat-panel {
        width: calc(100vw - 32px);
        right: -4px;
        max-height: 70vh;
    }

    #chat-quick-actions { padding: 6px 8px; }
    .chat-quick-btn { font-size: 0.65rem; }
}
