/**
 * Confidence Talk - Chat Interface CSS
 *
 * Styling for the real-time chat interface with streaming AI responses.
 *
 * @package ConfidenceTalk
 */

/* --- Chat Container --- */
.ct-chat-container {
    display: flex;
    flex-direction: column;
    height: 60vh;
    min-height: 400px;
    max-height: 800px;
    background: var(--metallic-steel-gradient);
    border-radius: 16px;
    box-shadow: 0 15px 22px -8px rgba(44, 62, 80, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.15);
    overflow: hidden;
}

/* --- Chat Header --- */
.ct-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ct-chat-header .ct-chat-title {
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
}

.ct-chat-header .ct-chat-agents {
    display: flex;
    gap: 4px;
}

.ct-chat-header .ct-chat-agent-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #fff;
    font-weight: 600;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

/* --- Messages Area --- */
.ct-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ct-messages::-webkit-scrollbar {
    width: 6px;
}

.ct-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ct-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* --- Message Bubbles --- */
.ct-message {
    display: flex;
    gap: 10px;
    max-width: 85%;
}

.ct-message.user,
.ct-user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ct-message.agent,
.ct-agent-message {
    align-self: flex-start;
}

.ct-message .ct-msg-avatar,
.ct-message .ct-message-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    font-weight: 600;
}

.ct-message.user .ct-msg-avatar,
.ct-message.user .ct-message-avatar {
    background: var(--gold-gradient);
}

.ct-message .ct-msg-content,
.ct-message .ct-message-content {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
}

.ct-message.user .ct-msg-content,
.ct-user-message .ct-message-content {
    background: var(--gold-gradient);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.ct-message.agent .ct-msg-content,
.ct-agent-message .ct-message-content {
    background: linear-gradient(135deg, rgba(44, 62, 80, 0.85), rgba(52, 73, 94, 0.75));
    color: rgba(255, 255, 255, 0.95);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(4px);
}

.ct-message .ct-msg-sender,
.ct-message .ct-message-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    opacity: 0.8;
}

.ct-message .ct-msg-text,
.ct-message .ct-message-text {
    word-wrap: break-word;
}

.ct-message .ct-msg-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
}

.ct-message .ct-msg-time {
    font-size: 10px;
    opacity: 0.5;
}

/* Per-message TTS play/stop button */
.ct-speak-btn {
    background: rgba(0, 0, 0, 0.45);
    border: 2px solid rgba(255, 255, 255, 0.7);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    opacity: 1;
    transition: all 0.2s ease;
    line-height: 1;
    color: #ffffff;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 14px;
    flex-shrink: 0;
}
.ct-speak-btn::before {
    content: '▶️';
    display: block;
}
.ct-speak-btn.playing::before {
    content: '⏸️';
}
.ct-speak-btn:hover {
    background: rgba(0, 0, 0, 0.65);
    border-color: #ffffff;
    color: #fff;
    box-shadow: 0 0 14px rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}
.ct-speak-btn.playing {
    background: rgba(46, 204, 113, 0.5);
    border-color: #2ecc71;
    color: #ffffff;
    animation: ct-tts-pulse 1s ease-in-out infinite;
    box-shadow: 0 0 16px rgba(46, 204, 113, 0.4);
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.ct-msg-tts-btn {
    background: rgba(0, 0, 0, 0.45);
    border: 2px solid rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 18px;
    padding: 4px 10px;
    border-radius: 8px;
    opacity: 1;
    transition: all 0.2s ease;
    line-height: 1;
    color: #ffffff;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.ct-msg-tts-btn:hover {
    background: rgba(0, 0, 0, 0.65);
    border-color: #ffffff;
    color: #fff;
    box-shadow: 0 0 14px rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.ct-msg-tts-btn.speaking {
    background: rgba(46, 204, 113, 0.5);
    border-color: #2ecc71;
    color: #ffffff;
    animation: ct-tts-pulse 1s ease-in-out infinite;
    box-shadow: 0 0 16px rgba(46, 204, 113, 0.4);
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* TTS Speaking Status Indicator */
.ct-tts-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #2ecc71;
    font-weight: 600;
    padding: 2px 8px;
    background: rgba(46, 204, 113, 0.1);
    border-radius: 10px;
    white-space: nowrap;
    animation: ct-tts-pulse 1s ease-in-out infinite;
}

.ct-tts-status .ct-tts-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #2ecc71;
    animation: ct-blink 0.8s step-end infinite;
}

/* --- Typing Indicator --- */
.ct-typing {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    align-self: flex-start;
}

.ct-typing .ct-typing-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    font-weight: 600;
}

.ct-typing .ct-typing-dots {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.ct-typing .ct-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    animation: ct-bounce 1.4s ease-in-out infinite;
}

.ct-typing .ct-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ct-typing .ct-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes ct-bounce {
    0%, 80%, 100% { transform: scale(0.6); }
    40% { transform: scale(1); }
}

/* --- Streaming Message --- */
.ct-message.streaming .ct-msg-content::after,
.ct-message.streaming .ct-message-content::after {
    content: '▊';
    animation: ct-blink 0.8s step-end infinite;
    margin-left: 2px;
}

@keyframes ct-blink {
    50% { opacity: 0; }
}

/* --- Agent Start Animation --- */
.ct-agent-start {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    align-self: flex-start;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    font-style: italic;
}

.ct-agent-start .ct-start-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: #fff;
    font-weight: 600;
}

/* --- TTS Toggle Button --- */
.ct-tts-toggle {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
    transition: all 0.2s ease;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ct-tts-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
    border-color: rgba(255, 255, 255, 0.4);
}

.ct-tts-toggle.active {
    color: #2ecc71;
    border-color: rgba(46, 204, 113, 0.5);
    background: rgba(46, 204, 113, 0.1);
}

.ct-tts-toggle.active:hover {
    background: rgba(46, 204, 113, 0.2);
    border-color: rgba(46, 204, 113, 0.7);
}

.ct-tts-toggle.speaking {
    animation: ct-tts-pulse 1s ease-in-out infinite;
    color: #2ecc71;
    border-color: rgba(46, 204, 113, 0.7);
    background: rgba(46, 204, 113, 0.15);
}

@keyframes ct-tts-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0); }
}

/* TTS not supported message */
.ct-tts-toggle.unsupported {
    opacity: 0.3;
    cursor: not-allowed;
}

/* --- Emotional Action Markers --- */
.ct-emotional-action {
    color: rgba(255, 255, 255, 0.6);
    font-style: italic;
    font-size: 12px;
    display: inline-block;
    padding: 0 2px;
    opacity: 0.85;
    transition: opacity 0.2s ease;
}

.ct-message.agent .ct-msg-text .ct-emotional-action {
    color: rgba(255, 215, 0, 0.7);
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.15);
}

/* ============================================================
 * VOICE INPUT SYSTEM
 * ============================================================ */

/* --- Voice Button (Mic) — matches Send button size --- */
.ct-voice-btn {
    height: 36px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    position: relative;
    line-height: 1;
    gap: 4px;
    white-space: nowrap;
    font-family: inherit;
}

.ct-voice-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.9);
}

.ct-voice-btn:active {
    transform: scale(0.97);
}

/* Active — listening */
.ct-voice-btn.ct-voice-active {
    background: rgba(46, 204, 113, 0.2);
    border-color: #2ecc71;
    color: #2ecc71;
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.3);
    animation: ct-voice-pulse 1s ease-in-out infinite;
}

/* Agent speaking indicator */
.ct-voice-btn.ct-agent-speaking {
    border-color: rgba(205, 133, 63, 0.5);
    color: #CD853F;
    background: rgba(205, 133, 63, 0.1);
}

/* Denied — mic permission blocked */
.ct-voice-btn.ct-voice-denied {
    border-color: #ef4444;
    color: #ef4444;
    opacity: 0.6;
    cursor: not-allowed;
}

.ct-voice-btn.ct-voice-disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.ct-voice-btn.ct-voice-unsupported {
    display: none;
}

@keyframes ct-voice-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0); }
}

/* --- Chat input bar --- */
.ct-chat-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
}

.ct-chat-input .ct-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 8px 12px;
    color: #fff;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.ct-chat-input .ct-input:focus {
    border-color: rgba(205, 133, 63, 0.5);
}

.ct-chat-input .ct-input::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

/* --- Mobile Chat --- */

@media screen and (max-width: 768px) {
    .ct-chat-container {
        height: calc(100vh - 200px);
        min-height: 400px;
        border-radius: 0;
    }

    .ct-message {
        max-width: 95%;
    }

    .ct-chat-input {
        padding: 8px 12px;
    }
}
