/* InstaPress AI Agents - OpenAI Style Frontend */

.ai-chatbot-single {
    max-width: 100%;
    margin: 0 auto;
    padding: 20px;
}

.ai-chatbot-container {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    overflow: visible;
    transition: all 0.3s ease;
    width: 100%;
    min-height: 200px;
    max-width: none;
}

.ai-chatbot-container.minimized {
    height: 60px !important;
}

.ai-chatbot-container.minimized .ai-chatbot-messages,
.ai-chatbot-container.minimized .ai-chatbot-input {
    display: none;
}

/* Header - OpenAI style */
.ai-chatbot-header {
    background: #ffffff;
    color: #374151;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
}

.ai-chatbot-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #111827;
}

.ai-chatbot-controls {
    display: flex;
    gap: 8px;
}

.ai-chatbot-controls button {
    background: #f9fafb;
    border: 1px solid #d1d5db;
    color: #6b7280;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 12px;
}

.ai-chatbot-controls button:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

/* Messages area - OpenAI style */
.ai-chatbot-messages {
    flex: 1;
    padding: 0;
    overflow: visible;
    background: #ffffff;
    min-height: auto;
}


/* Individual messages */
.ai-chatbot-message {
    padding: 24px 20px;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.ai-chatbot-message:last-child {
    border-bottom: none;
}

.ai-chatbot-message-user {
    background: #f9fafb;
    flex-direction: row-reverse;
}

.ai-chatbot-message-ai {
    background: #ffffff;
}

/* Message content */
.message-content {
    flex: 1;
    line-height: 1.6;
    font-size: 14px;
    color: #374151;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.ai-chatbot-message-user .message-content {
    color: #111827;
    text-align: right;
}

.ai-chatbot-message-ai .message-content {
    color: #374151;
}

/* Avatar styles */
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.ai-chatbot-message-user .message-avatar {
    background: #10b981;
    color: white;
}

.ai-chatbot-message-ai .message-avatar {
    background: #6366f1;
    color: white;
}

/* Welcome message */
.ai-chatbot-welcome {
    padding: 24px 20px;
    text-align: center;
    color: #6b7280;
    font-size: 14px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}

/* Input area - OpenAI style */
.ai-chatbot-input {
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
    padding: 16px 20px;
}

.ai-chatbot-input-container {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 12px 16px;
    transition: all 0.2s ease;
}

.ai-chatbot-input-container:focus-within {
    border-color: #d1d5db;
    box-shadow: none;
}

.ai-chatbot-message-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: #111827;
    background: transparent;
    max-height: 120px;
    min-height: 63px; /* 3 lines: 14px font * 1.5 line-height * 3 = 63px */
}

.ai-chatbot-message-input::placeholder {
    color: #9ca3af;
}

.ai-chatbot-send {
    background: #6366f1;
    border: none;
    color: white;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-chatbot-send:hover:not(:disabled) {
    background: #4f46e5;
    transform: scale(1.05);
}

.ai-chatbot-send:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    transform: none;
}

/* Typing indicator */
.ai-chatbot-typing {
    padding: 16px 20px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 12px;
}

.typing-indicator {
    display: flex;
    gap: 4px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.typing-text {
    color: #6b7280;
    font-size: 14px;
}

/* Dark theme */
.ai-chatbot-container[data-theme="dark"] {
    background: #1f2937;
    border-color: #374151;
    color: #f9fafb;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-header {
    background: #1f2937;
    color: #f9fafb;
    border-color: #374151;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-messages {
    background: #1f2937;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-message {
    border-color: #374151;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-message-user {
    background: #374151;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-message-ai {
    background: #1f2937;
}

.ai-chatbot-container[data-theme="dark"] .message-content {
    color: #f9fafb;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-input {
    background: #1f2937;
    border-color: #374151;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-input-container {
    background: #374151;
    border-color: #4b5563;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-message-input {
    color: #f9fafb;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-message-input::placeholder {
    color: #9ca3af;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-welcome {
    background: #374151;
    color: #d1d5db;
    border-color: #4b5563;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-typing {
    background: #374151;
    border-color: #4b5563;
}

/* Light theme */
.ai-chatbot-container[data-theme="light"] {
    background: #ffffff;
    border-color: #e5e7eb;
}

/* Minimal theme */
.ai-chatbot-container[data-theme="minimal"] {
    border: none;
    box-shadow: none;
    background: transparent;
}

.ai-chatbot-container[data-theme="minimal"] .ai-chatbot-header {
    background: transparent;
    color: #374151;
    border-bottom: 1px solid #e5e7eb;
}

.ai-chatbot-container[data-theme="minimal"] .ai-chatbot-messages {
    background: transparent;
}

.ai-chatbot-container[data-theme="minimal"] .ai-chatbot-input {
    background: transparent;
    border-color: #e5e7eb;
}

/* Responsive design */
@media (max-width: 768px) {
    .ai-chatbot-container {
        border-radius: 0;
        border: none;
        box-shadow: none;
        margin: 0;
    }
    
    .ai-chatbot-messages {
        padding: 0;
    }
    
    .ai-chatbot-message {
        padding: 16px;
    }
    
    .ai-chatbot-input {
        padding: 12px 16px;
    }
    
    .ai-chatbot-input-container {
        padding: 8px 12px;
    }
}

/* Accessibility - Remove focus borders */
.ai-chatbot-container:focus-within,
.ai-chatbot-container *:focus,
.ai-chatbot-send:focus,
.ai-chatbot-message-input:focus,
.ai-chatbot-input-container:focus-within,
.ai-chatbot-controls button:focus {
    outline: none !important;
    box-shadow: none !important;
}

.ai-chatbot-history-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    color: #6b7280;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chatbot-history-toggle:hover {
    background: #f3f4f6;
    color: #374151;
}

.ai-chatbot-input-container:focus-within {
    border-color: #d1d5db;
}

/* Loading states */
.ai-chatbot-container.loading .ai-chatbot-send {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}

/* Code blocks and formatting */
.message-content pre {
    background: #f3f4f6;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
}

.ai-chatbot-container[data-theme="dark"] .message-content pre {
    background: #374151;
    color: #f9fafb;
}

.message-content code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
}

.ai-chatbot-container[data-theme="dark"] .message-content code {
    background: #374151;
    color: #f9fafb;
}

.message-content p {
    margin: 8px 0;
}

.message-content ul, .message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

/* TTS Controls */
.ai-chatbot-tts-controls {
    display: flex;
    gap: 16px;
    padding: 12px 16px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0;
}

.ai-chatbot-tts-toggle,
.ai-chatbot-autoplay-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #374151;
    font-weight: 500;
    transition: color 0.2s ease;
    padding: 4px 8px;
    border-radius: 6px;
    background: transparent;
}

.ai-chatbot-tts-toggle:hover,
.ai-chatbot-autoplay-toggle:hover {
    background: #e5e7eb;
    color: #111827;
}

.ai-chatbot-tts-enabled,
.ai-chatbot-autoplay-enabled {
    margin: 0;
    cursor: pointer;
}

.ai-chatbot-tts-label,
.ai-chatbot-autoplay-label {
    user-select: none;
    font-weight: 500;
}

.tts-controls {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e5e7eb;
}

.tts-play-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    color: #374151;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tts-play-btn:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.tts-play-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.tts-play-btn svg {
    width: 14px;
    height: 14px;
}

/* Dark theme TTS controls */
.ai-chatbot-container[data-theme="dark"] .ai-chatbot-tts-controls {
    background: #374151;
    border-bottom-color: #4b5563;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-tts-toggle,
.ai-chatbot-container[data-theme="dark"] .ai-chatbot-autoplay-toggle {
    color: #d1d5db;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-tts-toggle:hover,
.ai-chatbot-container[data-theme="dark"] .ai-chatbot-autoplay-toggle:hover {
    background: #4b5563;
    color: #f9fafb;
}

.ai-chatbot-container[data-theme="dark"] .tts-controls {
    border-top-color: #4b5563;
}

.ai-chatbot-container[data-theme="dark"] .tts-play-btn {
    background: #374151;
    border-color: #4b5563;
    color: #d1d5db;
}

.ai-chatbot-container[data-theme="dark"] .tts-play-btn:hover {
    background: #4b5563;
    border-color: #6b7280;
}

/* Chat History Sidebar */
.ai-chatbot-sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 300px;
    height: 100vh;
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    transition: left 0.3s ease;
    z-index: 1000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.ai-chatbot-container.sidebar-open .ai-chatbot-sidebar {
    left: 0;
}

.ai-chatbot-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f9fafb;
}

.ai-chatbot-sidebar-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #111827;
}

.ai-chatbot-sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: #6b7280;
    transition: color 0.2s ease;
}

.ai-chatbot-sidebar-toggle:hover {
    color: #374151;
    background: #e5e7eb;
}

.ai-chatbot-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.ai-chatbot-history-list {
    padding: 0 8px;
}

.ai-chatbot-history-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.ai-chatbot-history-item:hover {
    background: #f9fafb;
}

.ai-chatbot-history-item:last-child {
    border-bottom: none;
}

.ai-chatbot-history-message {
    font-size: 14px;
    color: #374151;
    line-height: 1.4;
    margin-bottom: 4px;
}

.ai-chatbot-history-time {
    font-size: 12px;
    color: #9ca3af;
}

.ai-chatbot-history-empty {
    padding: 20px;
    text-align: center;
    color: #6b7280;
    font-size: 14px;
}

/* Dark theme sidebar */
.ai-chatbot-container[data-theme="dark"] .ai-chatbot-sidebar {
    background: #1f2937;
    border-right-color: #374151;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-sidebar-header {
    background: #374151;
    border-bottom-color: #4b5563;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-sidebar-header h4 {
    color: #f9fafb;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-sidebar-toggle {
    color: #9ca3af;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-sidebar-toggle:hover {
    color: #d1d5db;
    background: #4b5563;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-history-item {
    border-bottom-color: #374151;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-history-item:hover {
    background: #374151;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-history-message {
    color: #d1d5db;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-history-time {
    color: #9ca3af;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-history-empty {
    color: #9ca3af;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-history-toggle {
    color: #9ca3af;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-history-toggle:hover {
    background: #4b5563;
    color: #d1d5db;
}

/* Formatted Content Styles */
.message-content {
    line-height: 1.6;
    word-wrap: break-word;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.message-content h1 {
    font-size: 1.5em;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 8px;
}

.message-content h2 {
    font-size: 1.3em;
}

.message-content h3 {
    font-size: 1.1em;
}

.message-content p {
    margin: 8px 0;
}

.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

.message-content code {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    color: #d63384;
}

.message-content pre {
    background: #f8f9fa;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 16px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    line-height: 1.4;
}

.message-content pre code {
    background: none;
    border: none;
    padding: 0;
    color: #374151;
    font-size: inherit;
}

.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 4px 0;
}

.message-content a {
    color: #0073aa;
    text-decoration: underline;
}

.message-content a:hover {
    color: #005a87;
}

.message-content blockquote {
    border-left: 4px solid #e5e7eb;
    margin: 12px 0;
    padding: 8px 16px;
    background: #f9fafb;
    font-style: italic;
}

/* Dark theme support for formatted content */
.ai-chatbot-container[data-theme="dark"] .message-content h1 {
    border-bottom-color: #374151;
    color: #f9fafb;
}

.ai-chatbot-container[data-theme="dark"] .message-content h2,
.ai-chatbot-container[data-theme="dark"] .message-content h3,
.ai-chatbot-container[data-theme="dark"] .message-content h4,
.ai-chatbot-container[data-theme="dark"] .message-content h5,
.ai-chatbot-container[data-theme="dark"] .message-content h6 {
    color: #f9fafb;
}

.ai-chatbot-container[data-theme="dark"] .message-content code {
    background: #374151;
    border-color: #4b5563;
    color: #fbbf24;
}

.ai-chatbot-container[data-theme="dark"] .message-content pre {
    background: #1f2937;
    border-color: #374151;
}

.ai-chatbot-container[data-theme="dark"] .message-content pre code {
    color: #d1d5db;
}

.ai-chatbot-container[data-theme="dark"] .message-content a {
    color: #60a5fa;
}

.ai-chatbot-container[data-theme="dark"] .message-content a:hover {
    color: #93c5fd;
}

.ai-chatbot-container[data-theme="dark"] .message-content blockquote {
    border-left-color: #4b5563;
    background: #374151;
    color: #d1d5db;
}

/* Conversation History Actions */
.ai-chatbot-history-item {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 8px;
    margin: 2px 0;
}

.ai-chatbot-history-item:hover {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    transform: translateX(2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.ai-chatbot-history-item:hover .ai-chatbot-history-actions {
    opacity: 1;
    transform: translateX(0);
}

.ai-chatbot-history-content {
    flex: 1;
    min-width: 0;
    padding-right: 8px;
}

.ai-chatbot-history-actions {
    display: flex;
    gap: 6px;
    opacity: 0;
    transform: translateX(8px);
    transition: all 0.2s ease;
}

.ai-chatbot-rename-btn,
.ai-chatbot-delete-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #e5e7eb;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(4px);
    min-width: 28px;
    min-height: 28px;
}

.ai-chatbot-rename-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #475569;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.ai-chatbot-delete-btn:hover {
    background: #fef2f2;
    border-color: #fecaca;
    color: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(220, 38, 38, 0.1);
}

.ai-chatbot-rename-btn:active,
.ai-chatbot-delete-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.ai-chatbot-rename-btn svg,
.ai-chatbot-delete-btn svg {
    width: 14px;
    height: 14px;
    stroke-width: 2;
}

/* Dark theme for history actions */
.ai-chatbot-container[data-theme="dark"] .ai-chatbot-history-item {
    border-bottom-color: #374151;
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-history-item:hover {
    background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
    transform: translateX(2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-rename-btn,
.ai-chatbot-container[data-theme="dark"] .ai-chatbot-delete-btn {
    background: rgba(31, 41, 55, 0.9);
    border-color: #4b5563;
    color: #9ca3af;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-rename-btn:hover {
    background: #374151;
    border-color: #6b7280;
    color: #d1d5db;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.ai-chatbot-container[data-theme="dark"] .ai-chatbot-delete-btn:hover {
    background: #7f1d1d;
    border-color: #dc2626;
    color: #fca5a5;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(220, 38, 38, 0.2);
}