/* ChatGPT Clone Styles */
#chatgpt-container {
    display: flex;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Sidebar Styles */
.chatgpt-sidebar {
    width: 280px;
    background: #f7f7f8;
    border-right: 1px solid #e5e5e5;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.chatgpt-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #e5e5e5;
}

.new-chat-button {
    width: 100%;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #d9d9e3;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #374151;
    transition: all 0.2s;
}

.new-chat-button:hover {
    background: #f9f9fb;
    border-color: #c5c5d2;
}

.chatgpt-conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    padding: 8px 16px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: #374151;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.2s;
    word-break: break-word;
}

.conversation-item:hover {
    background: #ececf1;
}

.conversation-item.active {
    background: #e3f2fd;
    color: #1976d2;
}

.conversation-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-actions {
    display: none;
    gap: 4px;
}

.conversation-item:hover .conversation-actions {
    display: flex;
}

.delete-conversation {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.delete-conversation:hover {
    background: #fee2e2;
}

/* Main Chat Area */
.chatgpt-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.chatgpt-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.welcome-message {
    text-align: center;
    color: #6b7280;
    margin-top: 40px;
}

.welcome-message h2 {
    font-size: 24px;
    font-weight: 600;
    margin: 0;
    color: #374151;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 100%;
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: #10a37f;
    color: white;
}

.message.assistant .message-avatar {
    background: #ab68ff;
    color: white;
}

.message-content {
    flex: 1;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
    max-width: calc(100% - 44px);
    font-size: 15px;
}

.message.user .message-content {
    background: #10a37f;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: #f7f7f8;
    color: #374151;
    border-bottom-left-radius: 4px;
    border: 1px solid #e5e5e5;
}

/* Input Area */
.chatgpt-input-container {
    padding: 20px;
    border-top: 1px solid #e5e5e5;
    background: #fff;
}

.chatgpt-input-wrapper {
    background: #f7f7f8;
    border: 1px solid #d9d9e3;
    border-radius: 12px;
    padding: 12px 16px;
    transition: border-color 0.2s;
}

.chatgpt-input-wrapper:focus-within {
    border-color: none;
}

.chatgpt-file-attachments {
    margin-bottom: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #e5e5e5;
}

.chatgpt-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.attach-button {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.attach-button:hover {
    background: #e5e5e5;
    color: #374151;
}

.attach-button:active {
    background: #d1d5db;
}

#chatgpt-input {
    flex: 1;
    border: none;
    background: none;
    resize: none;
    outline: none;
    font-size: 16px;
    line-height: 1.5;
    font-family: inherit;
    max-height: 120px;
    min-height: 24px;
}

#chatgpt-send {
    background: #10a37f;
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

#chatgpt-send:disabled {
    background: #d9d9e3;
    cursor: not-allowed;
}

#chatgpt-send:not(:disabled):hover {
    background: #0d8c6c;
}

/* File Attachment Styles */
.file-attachment {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 4px 8px 4px 0;
    font-size: 14px;
    max-width: 250px;
}

.file-attachment-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: white;
    font-size: 12px;
    font-weight: 600;
}

.file-attachment-icon.image { background: #3b82f6; }
.file-attachment-icon.pdf { background: #ef4444; }
.file-attachment-icon.docx { background: #2563eb; }
.file-attachment-icon.csv { background: #10b981; }
.file-attachment-icon.png { background: #3b82f6; }
.file-attachment-icon.jpg { background: #3b82f6; }
.file-attachment-icon.jpeg { background: #3b82f6; }
.file-attachment-icon.gif { background: #3b82f6; }
.file-attachment-icon.webp { background: #3b82f6; }

.file-attachment-info {
    flex: 1;
    min-width: 0;
}

.file-attachment-name {
    font-weight: 500;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-attachment-size {
    font-size: 12px;
    color: #6b7280;
}

.file-attachment-remove {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.file-attachment-remove:hover {
    background: #fee2e2;
    color: #ef4444;
}

/* File Preview in Messages */
.message-files {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    max-width: 200px;
}

.message.user .message-file {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
}

.message.assistant .message-file {
    background: #e5e5e5;
    color: #374151;
}

.message-file-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    color: white;
    font-size: 10px;
    font-weight: 600;
}

.message-file-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Image Previews in Messages */
.message-image {
    margin-top: 8px;
    border-radius: 8px;
    max-width: 300px;
    max-height: 200px;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
}

/* File Upload Drag and Drop */
.chatgpt-input-wrapper.drag-over {
    border-color: #10a37f;
    background: #f0fdf4;
}

.drag-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(16, 163, 127, 0.1);
    border: 2px dashed #10a37f;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #10a37f;
    font-weight: 500;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.drag-overlay.active {
    opacity: 1;
}

/* File Upload Progress */
.upload-progress {
    margin-top: 8px;
    padding: 8px 0;
    font-size: 13px;
    color: #6b7280;
}

.upload-progress-bar {
    width: 100%;
    height: 4px;
    background: #e5e5e5;
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}

.upload-progress-fill {
    height: 100%;
    background: #10a37f;
    transition: width 0.3s ease;
    border-radius: 2px;
}

/* Error States */
.file-error {
    color: #ef4444;
    font-size: 13px;
    margin-top: 4px;
    padding: 4px 8px;
    background: #fef2f2;
    border-radius: 4px;
    border: 1px solid #fecaca;
}

/* Loading State for File Processing */
.file-processing {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #6b7280;
    font-size: 13px;
    margin-top: 8px;
}

.file-processing-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e5e5;
    border-top: 2px solid #10a37f;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Loading Animation */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: #f7f7f8;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    border: 1px solid #e5e5e5;
    max-width: fit-content;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Streaming Response Cursor */
.streaming-cursor {
    display: inline-block;
    background: #10a37f;
    color: #10a37f;
    animation: blink 1s infinite;
    font-weight: normal;
    margin-left: 1px;
}

.message.assistant .streaming-cursor {
    background: #374151;
    color: #374151;
}

@keyframes blink {
    0%, 50% {
        opacity: 1;
    }
    51%, 100% {
        opacity: 0;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    #chatgpt-container {
        flex-direction: column;
        height: auto !important;
    }
    
    .chatgpt-sidebar {
        width: 100%;
        max-height: 200px;
        order: 2;
    }
    
    .chatgpt-main {
        order: 1;
        min-height: 400px;
    }
    
    .chatgpt-conversations-list {
        max-height: 120px;
    }
}

/* Scrollbar Styling */
.chatgpt-messages::-webkit-scrollbar,
.chatgpt-conversations-list::-webkit-scrollbar {
    width: 6px;
}

.chatgpt-messages::-webkit-scrollbar-track,
.chatgpt-conversations-list::-webkit-scrollbar-track {
    background: transparent;
}

.chatgpt-messages::-webkit-scrollbar-thumb,
.chatgpt-conversations-list::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.chatgpt-messages::-webkit-scrollbar-thumb:hover,
.chatgpt-conversations-list::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Code blocks and formatting */
.code-block-wrapper {
    position: relative;
    margin: 12px 0;
    border-radius: 8px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    overflow: hidden;
}

.code-language {
    background: #e9ecef;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: #495057;
    border-bottom: 1px solid #dee2e6;
    text-transform: uppercase;
}

.code-block-wrapper pre {
    background: #f8f9fa;
    border-radius: 0;
    padding: 16px;
    margin: 0;
    overflow-x: auto;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    color: #24292f;
}

.code-block-wrapper pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
    color: inherit;
}

.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #6c757d;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    opacity: 0.7;
    transition: all 0.2s;
}

.copy-code-btn:hover {
    opacity: 1;
    background: #495057;
}

.inline-code {
    background: #f1f3f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 13px;
    color: #d73a49;
    border: 1px solid #e1e4e8;
}

.message.user .inline-code {
    background: rgba(255, 255, 255, 0.2);
    color: #a7f3d0;
    border-color: rgba(255, 255, 255, 0.3);
}

/* Markdown Headers */
.markdown-header {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.25;
}

h1.markdown-header {
    font-size: 24px;
    border-bottom: 1px solid #e1e4e8;
    padding-bottom: 8px;
}

h2.markdown-header {
    font-size: 20px;
    border-bottom: 1px solid #e1e4e8;
    padding-bottom: 6px;
}

h3.markdown-header {
    font-size: 18px;
}

h4.markdown-header {
    font-size: 16px;
}

h5.markdown-header {
    font-size: 14px;
}

h6.markdown-header {
    font-size: 12px;
    color: #6a737d;
}

.message.user .markdown-header {
    color: rgba(255, 255, 255, 0.9);
    border-color: rgba(255, 255, 255, 0.3);
}

/* Markdown Lists */
.markdown-list,
.markdown-ordered-list {
    margin: 12px 0;
    padding-left: 24px;
}

.markdown-list {
    list-style-type: disc;
}

.markdown-ordered-list {
    list-style-type: decimal;
}

.markdown-list-item,
.markdown-ordered-item {
    margin: 4px 0;
    line-height: 1.5;
}

/* Markdown Blockquotes */
.markdown-blockquote {
    margin: 12px 0;
    padding: 8px 16px;
    border-left: 4px solid #dfe2e5;
    background: #f6f8fa;
    color: #6a737d;
    font-style: italic;
}

.message.user .markdown-blockquote {
    border-left-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
}

/* Markdown Horizontal Rules */
.markdown-hr {
    margin: 20px 0;
    border: none;
    height: 1px;
    background: #e1e4e8;
}

.message.user .markdown-hr {
    background: rgba(255, 255, 255, 0.3);
}

/* Markdown Tables */
.markdown-table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
    font-size: 14px;
}

.markdown-table td {
    border: 1px solid #d0d7de;
    padding: 8px 12px;
    text-align: left;
}

.markdown-table tr:nth-child(even) {
    background: #f6f8fa;
}

.message.user .markdown-table td {
    border-color: rgba(255, 255, 255, 0.3);
}

.message.user .markdown-table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.1);
}

/* Markdown Paragraphs */
.markdown-paragraph {
    margin: 8px 0;
    line-height: 1.6;
}

.markdown-paragraph:first-child {
    margin-top: 0;
}

.markdown-paragraph:last-child {
    margin-bottom: 0;
}

/* Text Formatting */
.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

.message-content del {
    text-decoration: line-through;
    opacity: 0.7;
}

/* Links in Messages */
.message-content a {
    color: #0969da;
    text-decoration: underline;
    transition: color 0.2s;
}

.message-content a:hover {
    color: #0550ae;
}

.message.user .message-content a {
    color: #a7f3d0;
}

.message.user .message-content a:hover {
    color: #6ee7b7;
}

/* Syntax Highlighting for Common Languages */
.language-javascript .keyword,
.language-js .keyword {
    color: #d73a49;
    font-weight: 600;
}

.language-python .keyword {
    color: #005cc5;
    font-weight: 600;
}

.language-css .property {
    color: #005cc5;
}

.language-html .tag {
    color: #22863a;
}

/* Math/LaTeX Support (basic) */
.math-inline {
    font-family: 'Times New Roman', serif;
    font-style: italic;
}

.math-block {
    display: block;
    text-align: center;
    margin: 16px 0;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    font-family: 'Times New Roman', serif;
}

/* Responsive adjustments for markdown */
@media (max-width: 768px) {
    .code-block-wrapper pre {
        font-size: 12px;
        padding: 12px;
    }
    
    .copy-code-btn {
        font-size: 10px;
        padding: 3px 6px;
    }
    
    .markdown-table {
        font-size: 12px;
    }
    
    .markdown-table td {
        padding: 6px 8px;
    }
    
    .markdown-header {
        margin: 12px 0 6px 0;
    }
    
    h1.markdown-header {
        font-size: 20px;
    }
    
    h2.markdown-header {
        font-size: 18px;
    }
}

/* Markdown in streaming messages */
.streaming-cursor + .code-block-wrapper,
.streaming-cursor + .markdown-header,
.streaming-cursor + .markdown-list {
    margin-top: 0;
}

/* Special formatting for AI responses */
.message.assistant .message-content {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Arial', sans-serif;
    line-height: 1.6;
}

/* Code syntax highlighting themes */
.dark-theme .code-block-wrapper pre {
    background: #0d1117;
    color: #c9d1d9;
}

.dark-theme .code-language {
    background: #21262d;
    color: #f0f6fc;
}

/* Ensure proper spacing in complex markdown */
.message-content > *:first-child {
    margin-top: 0;
}

.message-content > *:last-child {
    margin-bottom: 0;
}

/* Long message handling */
.long-message {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Focus states for accessibility */
#chatgpt-input:focus,
.new-chat-button:focus,
.attach-button:focus,
#chatgpt-send:focus {
    outline: 0px solid #10a37f;
    outline-offset: 2px;
}

/* Button active states */
.new-chat-button:active,
.attach-button:active {
    transform: translateY(1px);
}

/* Ensure proper text selection */
.message-content {
    user-select: text;
}

.conversation-item,
.new-chat-button,
.attach-button,
#chatgpt-send {
    user-select: none;
}