/**
 * Client Chat Agent Styles
 * 
 * @package SP_AI_SEO_Vision
 * @since 1.5.0
 */

/* Sidebar - Sticky positioning */
.sp-ai-chat-sidebar {
    position: sticky;
    top: 100px;
    align-self: flex-start;
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
}

.sp-ai-chat-sidebar-inner {
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
}

 body.sp-chat-collapsed .sp-ai-chat-sidebar {
     display: none;
 }

 body.sp-chat-collapsed .sp-ai-chat-layout {
     gap: 0 !important;
 }

 body.sp-chat-collapsed .sp-ai-chat-main {
     flex: 1 1 100% !important;
     width: 100% !important;
     max-width: 100% !important;
 }

 .sp-chat-floating-toggle {
     position: fixed;
     top: 50%;
     transform: translateY(-50%);
     z-index: 9999;
     width: 40px;
     height: 56px;
     border: 1px solid #e2e8f0;
     border-radius: 10px;
     background: #fff;
     box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
     color: #64748b;
     cursor: pointer;
     display: flex;
     align-items: center;
     justify-content: center;
     transition: all 0.2s ease;
 }

 body:not(.sp-chat-collapsed) .sp-chat-floating-toggle {
     display: none;
 }

 body.sp-chat-collapsed .sp-chat-floating-toggle {
     display: flex;
 }

 .rtl .sp-chat-floating-toggle {
     right: 16px;
 }

 body:not(.rtl) .sp-chat-floating-toggle {
     left: 16px;
 }

 body.sp-chat-collapsed .rtl .sp-chat-floating-toggle {
     right: 12px;
 }

 body.sp-chat-collapsed:not(.rtl) .sp-chat-floating-toggle {
     left: 12px;
 }

 .sp-chat-floating-toggle:hover {
     background: #f8fafc;
     border-color: #cbd5e1;
     color: #334155;
     transform: translateY(-50%);
 }

 .sp-chat-floating-toggle span {
     font-size: 20px;
     line-height: 1;
 }

/* Chat Container */
.sp-client-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

/* Chat Header */
.sp-client-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f8fafc;
    color: #334155;
    border-bottom: 1px solid #e2e8f0;
}

.sp-client-chat-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
}

.sp-client-chat-icon {
    font-size: 1.3em;
}

.sp-client-chat-icon img.emoji {
    width: 22px;
    height: 22px;
}

/* Minimal style: hide decorative header icon */
.sp-client-chat-icon img.emoji {
    display: none;
}

.sp-client-chat-actions {
    display: flex;
    gap: 6px;
}

.sp-client-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid #e2e8f0;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    color: #64748b;
}

.sp-client-chat-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
}

.sp-client-chat-btn:active {
    background: #e2e8f0;
}

.sp-client-chat-btn span {
    font-size: 16px;
    line-height: 1;
}

.sp-client-chat-btn img.emoji {
    width: 18px;
    height: 18px;
}

/* Text Buttons with Labels */
.sp-client-chat-btn.sp-client-chat-btn-text {
    width: auto;
    padding: 6px 10px;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
}

.sp-client-chat-btn-text .sp-btn-icon {
    font-size: 12px;
}

/* Minimal style: hide emoji icons inside header buttons, keep labels */
.sp-client-chat-btn-text .sp-btn-icon {
    display: none;
}

.sp-client-chat-btn-text .sp-btn-label {
    color: #64748b;
}

.sp-client-chat-btn:hover .sp-btn-label {
    color: #334155;
}

/* Topics Panel */
.sp-client-chat-topics {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 1px solid #e2e8f0;
    max-height: 220px;
    overflow-y: auto;
}

.sp-client-chat-topics-header {
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
}

.sp-client-chat-topics-header h4 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sp-client-chat-topics-header h4::before {
    content: "";
}

.sp-topics-close-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #64748b;
    transition: all 0.2s ease;
}

.sp-topics-close-btn:hover {
    background: #cbd5e1;
    color: #475569;
}

.sp-client-chat-topics-list {
    padding: 8px;
}

.sp-client-chat-topic-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 4px;
    background: #fff;
    border: 1px solid transparent;
}

.sp-client-chat-topic-item:last-child {
    margin-bottom: 0;
}

.sp-client-chat-topic-item:hover {
    background: #f1f5f9;
    border-color: #e2e8f0;
}

.sp-client-chat-topic-item.active {
    background: #3b82f6;
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.25);
}

.sp-topic-title {
    flex: 1;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.sp-topic-delete {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
    background: #fff;
    border-radius: 6px;
    color: #94a3b8;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    flex: 0 0 auto;
    order: 1;
    margin-left: 8px;
}

.sp-topic-rename {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
    background: #fff;
    border-radius: 6px;
    color: #64748b;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    flex: 0 0 auto;
    order: 2;
    margin-left: 8px;
}

.sp-topic-rename:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
}

.sp-client-chat-topic-item.active .sp-topic-rename {
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
}

.sp-client-chat-topic-item.active .sp-topic-rename:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.45);
    color: #fff;
}

.sp-topic-delete:hover {
    background: #fef2f2;
    border-color: #fecaca;
    color: #dc2626;
}

.sp-client-chat-topic-item.active .sp-topic-delete {
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
}

.sp-client-chat-topic-item.active .sp-topic-delete:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.45);
    color: #fff;
}

.sp-topic-count {
    font-size: 11px;
    padding: 3px 8px;
    background: #e2e8f0;
    border-radius: 12px;
    margin-right: 0;
    margin-left: 8px;
    font-weight: 600;
    color: #64748b;
    order: 2;
}

.sp-client-chat-topic-item.active .sp-topic-count {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.sp-client-chat-topics-empty {
    padding: 24px 16px;
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
}

.sp-client-chat-topics-empty::before {
    content: "💬";
    display: block;
    font-size: 24px;
    margin-bottom: 8px;
}

/* Messages Container */
.sp-client-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: linear-gradient(180deg, #fafbfc 0%, #f5f7fa 100%);
}

/* Message Styles */
.sp-chat-message {
    display: flex;
    gap: 12px;
    animation: sp-chat-fade-in 0.4s ease-out;
}

/* Slower, smoother animation for assistant messages */
.sp-chat-message.sp-chat-assistant {
    animation: sp-chat-assistant-fade-in 0.6s ease-out;
}

@keyframes sp-chat-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes sp-chat-assistant-fade-in {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sp-chat-message.sp-chat-user {
    flex-direction: row-reverse;
}

.sp-chat-avatar {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-radius: 12px;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #e5e7eb;
}

.sp-chat-avatar img.emoji {
    width: 20px;
    height: 20px;
}

.sp-chat-message.sp-chat-user .sp-chat-avatar {
    background: #3b82f6;
    border: none;
}

.sp-chat-message.sp-chat-assistant .sp-chat-avatar {
    background: #64748b;
    border: none;
}

.sp-chat-bubble {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
}

.sp-chat-message.sp-chat-assistant .sp-chat-bubble {
    background: #fff;
    color: #1e293b;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid #e5e7eb;
}

.rtl .sp-chat-message.sp-chat-assistant .sp-chat-bubble {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 6px;
}

.sp-chat-message.sp-chat-user .sp-chat-bubble {
    background: #3b82f6;
    color: #fff;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.2);
}

.rtl .sp-chat-message.sp-chat-user .sp-chat-bubble {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 6px;
}

.sp-chat-bubble p {
    margin: 0;
}

.sp-chat-bubble p + p {
    margin-top: 10px;
}

.sp-chat-bubble code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 13px;
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
}

.sp-chat-message.sp-chat-user .sp-chat-bubble code {
    background: rgba(255, 255, 255, 0.2);
}

.sp-chat-bubble a {
    color: #3b82f6;
    text-decoration: none;
    font-weight: 500;
}

.sp-chat-bubble a:not(.sp-chat-page-link) {
    border-bottom: 1px solid currentColor;
}

.sp-chat-message.sp-chat-user .sp-chat-bubble a {
    color: #fff;
}

.sp-chat-bubble a:hover {
    opacity: 0.85;
}

/* Page Navigation Links - Button Style */
.sp-chat-page-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin: 4px 4px 4px 0;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    color: #334155 !important;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none !important;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.sp-chat-page-link:hover {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-color: #93c5fd;
    color: #1e40af !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.15);
    opacity: 1 !important;
}

.sp-chat-page-link .sp-chat-link-icon {
    font-size: 14px;
    line-height: 1;
}

.sp-chat-page-link .sp-chat-link-text {
    white-space: nowrap;
}

/* User message - lighter button style */
.sp-chat-message.sp-chat-user .sp-chat-page-link {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff !important;
}

.sp-chat-message.sp-chat-user .sp-chat-page-link:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    color: #fff !important;
}

.sp-chat-bubble strong {
    font-weight: 600;
}

/* Typing Indicator */
.sp-chat-typing-dots {
    display: flex;
    gap: 5px;
    padding: 6px 0;
}

.sp-chat-typing-dots span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: sp-chat-typing 1.4s infinite ease-in-out both;
}

.sp-chat-typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.sp-chat-typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes sp-chat-typing {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Container */
.sp-client-chat-input {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.sp-client-chat-textarea {
    flex: 1;
    padding: 12px 18px;
    border: 2px solid #e5e7eb;
    border-radius: 24px;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    font-family: inherit;
    transition: all 0.2s ease;
    background: #f8fafc;
}

.sp-client-chat-textarea:focus {
    outline: none;
    border-color: #3b82f6;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.sp-client-chat-textarea::placeholder {
    color: #94a3b8;
}

.sp-client-chat-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

/* Minimal style: replace emoji send icon with simple glyph */
.sp-client-chat-send span,
.sp-client-chat-send img.emoji {
    display: none;
}

.sp-client-chat-send::before {
    content: "➤";
    font-size: 14px;
    line-height: 1;
}

.sp-client-chat-send:hover:not(:disabled) {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
}

.sp-client-chat-send:active:not(:disabled) {
    transform: translateY(0);
}

.sp-client-chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.sp-client-chat-send span {
    font-size: 18px;
    line-height: 1;
}

.sp-client-chat-send img.emoji {
    width: 20px;
    height: 20px;
}

/* Chat Notices */
.sp-chat-notice {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    height: 100%;
}

.sp-chat-notice-icon {
    font-size: 3em;
    margin-bottom: 16px;
}

.sp-chat-notice p {
    margin: 0 0 20px;
    color: #64748b;
    font-size: 15px;
    line-height: 1.5;
}

.sp-chat-notice-error {
    background: linear-gradient(180deg, #fef2f2 0%, #fee2e2 100%);
    border: 1px solid #fecaca;
}

.sp-chat-notice-warning {
    background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
    border: 1px solid #fde68a;
}

.sp-chat-notice-info {
    background: linear-gradient(180deg, #eff6ff 0%, #dbeafe 100%);
    border: 1px solid #93c5fd;
}

/* RTL Adjustments */
.rtl .sp-client-chat-topic-item {
    flex-direction: row;
}

/* RTL: delete button on the left side (which is first in RTL row-reverse) */
.rtl .sp-client-chat-topic-item .sp-topic-delete {
    order: 1;
    margin-left: 8px;
    margin-right: 0;
}

.rtl .sp-client-chat-topic-item .sp-topic-rename {
    order: 2;
    margin-left: 8px;
    margin-right: 0;
}

.rtl .sp-client-chat-topic-item .sp-topic-count {
    order: 3;
    margin-left: 0;
    margin-right: 8px;
}

.rtl .sp-topic-count {
    margin-right: 0;
    margin-left: 8px;
}

.rtl .sp-chat-message.sp-chat-user {
    flex-direction: row;
}

.rtl .sp-chat-message.sp-chat-assistant {
    flex-direction: row-reverse;
}

/* Responsive */
@media (max-width: 1200px) {
    .sp-ai-chat-sidebar {
        top: 20px;
    }
    
    .sp-ai-chat-sidebar-inner {
        height: calc(100vh - 80px);
        max-height: 700px;
    }
}

@media (max-width: 1024px) {
    .sp-ai-chat-sidebar {
        position: static;
        max-height: none;
    }
    
    .sp-ai-chat-sidebar-inner {
        height: auto;
        min-height: 450px;
        max-height: 600px;
    }
    
    .sp-client-chat-messages {
        min-height: 280px;
    }
}

/* Scrollbar Styling */
.sp-client-chat-messages::-webkit-scrollbar,
.sp-client-chat-topics::-webkit-scrollbar {
    width: 6px;
}

.sp-client-chat-messages::-webkit-scrollbar-track,
.sp-client-chat-topics::-webkit-scrollbar-track {
    background: transparent;
}

.sp-client-chat-messages::-webkit-scrollbar-thumb,
.sp-client-chat-topics::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.sp-client-chat-messages::-webkit-scrollbar-thumb:hover,
.sp-client-chat-topics::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}
