/* ==========================================
   OPENCLAW CHAT MODAL STYLES
   Desktop floating panel + Mobile slide-up
   ========================================== */

/* ---- Desktop Chat Panel ---- */
.chat-panel-desktop {
    position: fixed;
    top: 72px;
    right: 24px;
    width: 400px;
    max-height: 520px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    z-index: 10050;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---- Mobile Chat Panel ---- */
.chat-panel-mobile {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(72px + env(safe-area-inset-bottom, 0));
    max-height: 58vh;
    background: #1a1a1a;
    border-top: 1px solid #333;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
    z-index: 10100;
    display: flex;
    flex-direction: column;
    animation: chat-slide-up 0.25s ease-out;
}

@keyframes chat-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ---- Chat Header ---- */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.chat-header-title {
    font-size: 15px;
    font-weight: 600;
    color: #e5e7eb;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
}

.chat-header-close {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    font-size: 18px;
    line-height: 1;
}

.chat-header-close:hover {
    color: #e5e7eb;
}

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

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #374151;
    border-radius: 2px;
}

/* ---- Message Bubbles ---- */
.chat-message-user {
    align-self: flex-end;
    max-width: 80%;
}

.chat-message-assistant {
    align-self: flex-start;
    max-width: 80%;
}

.chat-message-user .chat-bubble {
    background: #3b82f6;
    color: white;
    border-radius: 12px 12px 4px 12px;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-message-assistant .chat-bubble {
    background: #374151;
    color: #e5e7eb;
    border-radius: 12px 12px 12px 4px;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-message-assistant .chat-bubble.chat-bubble-error {
    background: #7f1d1d;
    border: 1px solid #991b1b;
}

.chat-timestamp {
    font-size: 10px;
    color: #6b7280;
    margin-top: 2px;
}

.chat-message-user .chat-timestamp {
    text-align: right;
}

/* ---- Empty State ---- */
.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    color: #6b7280;
    text-align: center;
    gap: 8px;
}

.chat-empty-icon {
    opacity: 0.4;
}

.chat-empty-text {
    font-size: 13px;
}

/* ---- Typing Indicator (driven by bridge "thinking" pulses) ---- */
.chat-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    align-self: flex-start;
    background: #374151;
    border-radius: 12px 12px 12px 4px;
}

.chat-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6b7280;
    animation: chat-typing-bounce 1.4s infinite ease-in-out;
}

.chat-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.chat-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes chat-typing-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ---- Delivery Status ---- */
.chat-delivery-status {
    font-size: 11px;
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-message-user .chat-delivery-status {
    justify-content: flex-end;
}

.chat-status-pending {
    color: #9ca3af;
}

.chat-status-delivered {
    color: #10b981;
}

.chat-status-failed {
    color: #ef4444;
}

/* ---- Input Area ---- */
.chat-input-row {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #333;
    background: #1f2937;
    flex-shrink: 0;
}

.chat-panel-mobile .chat-input-row {
    border-radius: 0;
}

.chat-input {
    flex: 1;
    background: #111827;
    border: 1px solid #374151;
    border-radius: 8px;
    padding: 10px 12px;
    color: white;
    font-size: 14px;
    outline: none;
    font-family: inherit;
}

.chat-input:focus {
    border-color: #3b82f6;
}

.chat-input::placeholder {
    color: #6b7280;
}

.chat-mic-btn {
    background: #374151;
    border: none;
    border-radius: 8px;
    padding: 10px;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.chat-mic-btn:hover {
    background: #4b5563;
    color: #e5e7eb;
}

.chat-mic-btn-active {
    background: #ef4444;
    color: white;
    animation: chat-mic-pulse 1.2s ease-in-out infinite;
}

.chat-mic-btn-active:hover {
    background: #dc2626;
}

@keyframes chat-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.chat-send-btn {
    background: #3b82f6;
    border: none;
    border-radius: 8px;
    padding: 10px 14px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.chat-send-btn:hover {
    background: #2563eb;
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---- Mobile Center Chat Button (in bottom nav) ---- */
.chat-nav-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #3b82f6;
    border: 3px solid #1f2937;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    margin-top: -6px;
    box-shadow: 0 2px 12px rgba(59, 130, 246, 0.4);
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-nav-btn:active {
    transform: scale(0.93);
}

.chat-nav-btn-open {
    width: 56px;
    height: 56px;
    margin-top: -12px;
    background: #10b981;
    box-shadow: 0 2px 16px rgba(16, 185, 129, 0.5);
}

.chat-nav-btn-send {
    width: 56px;
    height: 56px;
    margin-top: -12px;
    background: #10b981;
    box-shadow: 0 2px 16px rgba(16, 185, 129, 0.5);
}

.mobile-bottom-nav-recording {
    z-index: 10200 !important;
}

.chat-nav-btn-recording {
    width: 64px;
    height: 64px;
    margin-top: -16px;
    background: #ef4444;
    box-shadow: 0 0 24px rgba(239, 68, 68, 0.6);
    animation: chat-btn-breathe 0.8s ease-in-out infinite;
}

.chat-nav-btn-recording::after {
    content: '';
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    border-radius: 50%;
    border: 2px solid #ef4444;
    animation: chat-pulse-ring 1s ease-out infinite;
}

.chat-nav-btn-recording::before {
    content: '';
    position: absolute;
    top: -14px;
    left: -14px;
    right: -14px;
    bottom: -14px;
    border-radius: 50%;
    border: 1.5px solid rgba(239, 68, 68, 0.3);
    animation: chat-pulse-ring 1s ease-out 0.3s infinite;
}

@keyframes chat-pulse-ring {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.5); opacity: 0; }
}

@keyframes chat-btn-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* ---- Desktop Header Chat Button ---- */
.chat-header-btn {
    background: #374151;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    color: #d1d5db;
    transition: background 0.2s ease;
    font-size: 14px;
    font-weight: 500;
}

.chat-header-btn:hover {
    background: #4b5563;
}

.chat-header-btn-active {
    background: #3b82f6;
    color: white;
}

.chat-header-btn-active:hover {
    background: #2563eb;
}

/* ---- Voice Picker ---- */
.chat-voice-picker-btn {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
}

.chat-voice-picker-btn:hover {
    color: #e5e7eb;
    background: #374151;
}

.chat-voice-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10300;
}

.chat-voice-dropdown {
    position: fixed;
    right: 12px;
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 8px;
    max-height: 200px;
    width: 220px;
    overflow-y: auto;
    z-index: 10300;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

@media (max-width: 767px) {
    .chat-voice-dropdown {
        bottom: calc(60vh + 72px + env(safe-area-inset-bottom, 0) - 44px);
    }
}

@media (min-width: 768px) {
    .chat-voice-dropdown {
        top: 116px;
    }
}

.chat-voice-dropdown::-webkit-scrollbar {
    width: 4px;
}

.chat-voice-dropdown::-webkit-scrollbar-thumb {
    background: #4b5563;
    border-radius: 2px;
}

.chat-voice-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 10px;
    font-size: 12px;
    color: #d1d5db;
    background: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-voice-option:hover {
    background: #374151;
}

.chat-voice-option.active {
    color: #3b82f6;
    background: #1e3a5f;
}

/* ---- Speaking indicator (TTS active) ---- */
.chat-speaking-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: #10b981;
    margin-left: 8px;
}

.chat-speaking-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    animation: chat-speaking-pulse 1s infinite;
}

@keyframes chat-speaking-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* ---- Responsive ---- */
@media (max-width: 767px) {
    .chat-panel-desktop { display: none !important; }
}

@media (min-width: 768px) {
    .chat-panel-mobile { display: none !important; }
    .chat-nav-btn { display: none !important; }
}
