/* AI Assistant Styles - Matching LawGlitch Design System */

:root {
    --cream: #fdfaf5;
    --gold: #d4af37;
    --black: #0a0a0a;
    --white: #ffffff;
    --royal-blue: #1a237e;
    --light-gray: #f0f0f0;
    --dark-gray: #333;
    --border-gray: #ddd;
    --success-green: #4CAF50;
    --error-red: #dc3545;
    --warning-orange: #ff9800;
    --info-blue: #2196F3;
    --transition: all 0.3s ease-in-out;
    --box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
    --gold-glow: 0 0 15px rgba(212, 175, 55, 0.7);
    --border-radius: 8px;
    --border-radius-large: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--cream);
    color: var(--black);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

/* Container Layout */
.ai-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Layout override: ensure sidebar takes fixed space and main fills the remaining center area */
.ai-container {
    flex-direction: row;
    align-items: stretch;
}

.ai-sidebar {
    flex: 0 0 280px; /* fixed 280px sidebar */
    max-width: 280px;
}

.ai-main {
    flex: 1 1 auto; /* main takes remaining space */
    min-width: 0; /* allow it to shrink without overflowing */
    max-width: none;
}

/* Sidebar */
.ai-sidebar {
    width: 280px;
    background: linear-gradient(135deg, var(--white) 0%, #fafaf8 100%);
    border-right: 1px solid var(--border-gray);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
    transition: width 0.3s ease, margin-left 0.3s ease;
    z-index: 1100; /* keep sidebar above main content to avoid scroll overlap */
}

.ai-sidebar.collapsed {
    /* When collapsed keep a small visible strip for icons instead of hiding completely */
    width: 64px;
    min-width: 64px;
    border-right: none;
    overflow: visible;
    box-shadow: 2px 0 12px rgba(0,0,0,0.12);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-gray);
    background: var(--white);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-left h2 {
    font-family: 'Playfair Display', serif;
    font-size: 1.2rem;
    color: var(--black);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.icon-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dark-gray);
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--light-gray);
    color: var(--gold);
}

#new-chat-btn {
    margin-right: 4px;
}

#new-chat-btn:hover {
    background: var(--gold);
    color: var(--white);
}

.toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--dark-gray);
    font-size: 1rem;
    padding: 5px;
    transition: var(--transition);
}

.toggle-btn:hover {
    color: var(--gold);
    transform: scale(1.1);
}

/* Floating Toggle Button (always accessible) */
.floating-toggle-btn {
    position: fixed;
    /* place near the compact sidebar edge so it's visible when collapsed */
    left: 72px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--gold);
    border: 2px solid rgba(0,0,0,0.06);
    border-radius: 50%;
    width: 52px;
    height: 52px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--black);
    font-size: 1.3rem;
    box-shadow: 0 8px 20px rgba(0,0,0,0.18), 0 2px 6px rgba(212,175,55,0.15);
    transition: all 0.2s ease;
    z-index: 1200;
    opacity: 0;
    pointer-events: none;
}

.floating-toggle-btn:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.floating-toggle-btn:hover {
    background: #c9a961;
    box-shadow: 0 6px 12px rgba(212, 175, 55, 0.5);
    transform: translateY(-50%) scale(1.1);
}

/* Modes Section */
.modes-section,
.quick-actions,
.history-section {
    padding: 20px;
    border-bottom: 1px solid var(--border-gray);
}

.modes-section h3,
.quick-actions h3,
.history-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--dark-gray);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.mode-buttons {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    background: var(--white);
    border: 2px solid var(--border-gray);
    border-radius: var(--border-radius);
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--dark-gray);
    transition: var(--transition);
}

.mode-btn:hover {
    border-color: var(--gold);
    background: rgba(212, 175, 55, 0.05);
}

.mode-btn.active {
    background: linear-gradient(135deg, var(--gold) 0%, #d9a833 100%);
    color: var(--white);
    border-color: var(--gold);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.mode-btn i {
    font-size: 1rem;
}

/* Action Buttons */
.action-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--white);
    border: 1px solid var(--border-gray);
    border-radius: var(--border-radius);
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-size: 0.85rem;
    color: var(--dark-gray);
    transition: var(--transition);
    margin-bottom: 8px;
}

.action-btn:hover {
    background: var(--light-gray);
    border-color: var(--gold);
    color: var(--gold);
}

.action-btn i {
    font-size: 0.9rem;
}

/* Actions Section */
.actions-section {
    padding: 20px;
    border-bottom: 1px solid var(--border-gray);
}

.actions-section .action-btn {
    margin-bottom: 8px;
    width: 100%;
    justify-content: flex-start;
    font-weight: 500;
}

#new-chat-btn {
    background: var(--gold);
    color: var(--white);
    border: none;
}

#new-chat-btn:hover {
    background: #c9a961;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.2);
}

/* History Section */
.history-section {
    flex: 1;
    padding: 20px;
    border-bottom: 1px solid var(--border-gray);
    display: flex;
    flex-direction: column;
}

.history-section h3 {
    margin-bottom: 15px;
    color: var(--dark-gray);
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.conversation-history {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    flex: 1;
    padding-right: 4px; /* Space for scrollbar */
}

/* Style scrollbar for history */
.conversation-history::-webkit-scrollbar {
    width: 6px;
}

.conversation-history::-webkit-scrollbar-track {
    background: var(--light-gray);
    border-radius: 3px;
}

.conversation-history::-webkit-scrollbar-thumb {
    background: var(--dark-gray);
    border-radius: 3px;
}

.conversation-history::-webkit-scrollbar-thumb:hover {
    background: var(--gold);
}

.history-item {
    padding: 10px 12px;
    background: var(--white);
    border: 1px solid var(--border-gray);
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--dark-gray);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: var(--transition);
}

.history-item:hover {
    background: var(--light-gray);
    border-color: var(--gold);
}

/* Main Content Area */
.ai-main {
    /* Let the main area flex to fill remaining space but not exceed it */
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    background: var(--white);
    width: auto;
    /* ensure it can shrink in constrained layouts */
    min-width: 0;
    /* prevent main from growing past the viewport minus sidebar */
    max-width: calc(100% - 280px);
    height: 100vh;
    overflow: hidden;
}

/* Header */
.ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 30px;
    background: linear-gradient(135deg, var(--white) 0%, #fafaf8 100%);
    border-bottom: 1px solid var(--border-gray);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.header-left h1 {
    font-family: 'Playfair Display', serif;
    font-size: 1.8rem;
    color: var(--black);
    margin-bottom: 5px;
}

.header-left p {
    font-size: 0.9rem;
    color: var(--dark-gray);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: var(--border-radius);
}

.indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.indicator.connected {
    background: var(--success-green);
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.indicator.disconnected {
    background: var(--error-red);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#api-status-text {
    font-size: 0.85rem;
    color: var(--dark-gray);
}

/* Chat Area */
.ai-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    width: 100%;
    position: relative;
    background: linear-gradient(180deg, var(--cream) 0%, #f7f4ed 100%);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    position: relative; /* For history panel positioning */
}

/* When there are no messages, center a chat card in the messages area */
.messages-container.empty {
    align-items: center;
    justify-content: center;
}

.chat-card {
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(250,250,248,0.98));
    border: 1px solid var(--border-gray);
    box-shadow: var(--box-shadow);
    border-radius: 16px;
    padding: 40px;
    max-width: 800px;
    width: 90%;
    margin: 0 auto;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chat-card.centered {
    position: relative;
    top: 50%;
    transform: translateY(-50%);
}

.chat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
}

.chat-card .welcome-message {
    text-align: center;
    margin: 0 auto;
    max-width: 600px;
}

/* Welcome Message */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 25px;
    text-align: center;
}

.welcome-icon {
    font-size: 3.5rem;
    color: var(--gold);
    margin-bottom: 10px;
    animation: floatIcon 3s ease-in-out infinite;
}

@keyframes floatIcon {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.setup-instructions {
    background: rgba(212, 175, 55, 0.05);
    padding: 20px 30px;
    border-radius: 12px;
    border: 1px solid rgba(212, 175, 55, 0.2);
    margin: 15px 0;
    text-align: left;
}

.setup-instructions p {
    color: var(--black);
    font-weight: 500;
    margin-bottom: 10px;
}

.setup-instructions ol {
    margin: 0;
    padding-left: 20px;
}

.setup-instructions li {
    color: var(--dark-gray);
    margin: 8px 0;
    font-size: 0.95rem;
}

.welcome-options {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 10px;
}

.welcome-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 24px;
    border-radius: var(--border-radius-large);
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    transition: all 0.3s ease;
}

.welcome-btn.primary {
    background: linear-gradient(135deg, var(--gold) 0%, #d9a833 100%);
    border: none;
    color: var(--white);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.welcome-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(212, 175, 55, 0.4);
}

.welcome-btn.secondary {
    background: var(--white);
    border: 2px solid var(--gold);
    color: var(--gold);
}

.welcome-btn.secondary:hover {
    background: rgba(212, 175, 55, 0.05);
    transform: translateY(-2px);
}

.welcome-message h2 {
    font-family: 'Playfair Display', serif;
    font-size: 2.2rem;
    color: var(--black);
    margin: 0;
}

.welcome-message h2 {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    color: var(--black);
}

.welcome-message p {
    font-size: 1rem;
    color: var(--dark-gray);
}

.welcome-options {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.welcome-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--gold) 0%, #d9a833 100%);
    border: none;
    color: var(--white);
    border-radius: var(--border-radius-large);
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.welcome-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(212, 175, 55, 0.4);
}

/* Messages */
.message {
    display: flex;
    gap: 12px;
    margin-bottom: 10px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    justify-content: flex-end;
}

.message.ai {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: var(--border-radius-large);
    word-wrap: break-word;
    line-height: 1.5;
    overflow-x: auto;
    overflow-y: hidden;
    min-width: 0;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, var(--royal-blue) 0%, #0d47a1 100%);
    color: var(--white);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(26, 35, 126, 0.2);
}

.message.ai .message-bubble {
    background: var(--light-gray);
    color: var(--black);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.message-bubble code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

.message-attachments {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.message.user .message-attachments {
    border-top-color: rgba(255, 255, 255, 0.2);
}

.attachments-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.message.user .attachment-item {
    background: rgba(255, 255, 255, 0.1);
}

.attachment-item i {
    font-size: 1.1em;
    color: var(--gold);
}

.message.user .attachment-item i {
    color: rgba(255, 255, 255, 0.9);
}

.message.ai .message-bubble code {
    background: rgba(0, 0, 0, 0.1);
    color: var(--black);
}

.message.user .message-bubble code {
    background: rgba(255, 255, 255, 0.2);
    color: var(--white);
}

.message.thinking .message-bubble {
    font-style: italic;
}

/* Input Area */
.ai-input-area {
    padding: 25px 30px;
    background: linear-gradient(135deg, var(--white) 0%, #fafaf8 100%);
    border-top: 1px solid var(--border-gray);
    position: relative;
    z-index: 10;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
}

.input-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--white);
    padding: 15px;
    border-radius: var(--border-radius-large);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-gray);
}

/* Input row with model selector and upload buttons */
.textarea-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.upload-buttons {
    display: flex;
    gap: 8px;
    position: relative;
}

.control-btn.uploading {
    background: var(--light-gray);
    color: var(--gold);
    animation: pulse 1.5s infinite;
}

.upload-preview-container {
    margin-top: 12px;
    padding: 12px;
    background: var(--light-gray);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-gray);
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.upload-preview-container.hidden {
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
}

@keyframes attachmentIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.preview-item {
    animation: attachmentIn 0.3s ease forwards;
}

.preview-section {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.preview-section:not(:empty) {
    margin-bottom: 10px;
}

.preview-section:last-child:not(:empty) {
    margin-bottom: 0;
}

.preview-item {
    position: relative;
    background: var(--white);
    padding: 8px 12px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-gray);
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 300px;
}

.preview-item .file-preview {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--light-gray);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.preview-item .file-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
}

.preview-item .file-preview i {
    color: var(--dark-gray);
}

.preview-item .file-info {
    flex: 1;
    min-width: 0;
}

.preview-item .file-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--dark-gray);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-item .file-size {
    font-size: 0.8rem;
    color: #666;
}

.preview-item .remove-preview {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--error-red);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: transform 0.2s ease;
}

.preview-item .remove-preview:hover {
    transform: scale(1.1);
}

.attachment-info {
    padding: 8px;
    background: rgba(212, 175, 55, 0.1);
    border-radius: var(--border-radius);
    margin-top: 10px;
}

.attachment-info small {
    color: var(--dark-gray);
    display: flex;
    align-items: center;
    gap: 6px;
}

.attachment-info i {
    color: var(--gold);
}

.control-btn {
    padding: 8px 12px;
    background: var(--white);
    border: 1px solid var(--border-gray);
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Poppins', sans-serif;
    font-size: 0.85rem;
    color: var(--dark-gray);
    transition: var(--transition);
    white-space: nowrap;
}

.hidden {
    display: none !important;
}

/* Upload Preview */
.upload-preview-container {
    padding: 12px;
    border-top: 1px solid var(--border-gray);
    background: var(--light-gray);
}

.preview-section {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.preview-item {
    position: relative;
    border: 1px solid var(--border-gray);
    border-radius: 4px;
    overflow: hidden;
    background: white;
}

.preview-item {
    min-width: 200px;
    background: white;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.preview-item img {
    max-height: 80px;
    max-width: 120px;
    object-fit: cover;
}

.preview-item .file-preview {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dark-gray);
}

.preview-item .file-info {
    flex: 1;
    min-width: 0;
}

.preview-item .file-name {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--dark-gray);
    margin-bottom: 4px;
}

.preview-item .file-size {
    font-size: 0.8rem;
    color: #666;
}

.remove-preview {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

/* History Panel */
.history-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 100%;
    background: var(--white);
    border-left: 1px solid var(--border-gray);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    transform: translateX(100%);
    z-index: 1000;
}

.history-panel.visible {
    transform: translateX(0);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-gray);
}

.history-header h3 {
    font-size: 1.1rem;
    margin: 0;
}

.close-panel {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dark-gray);
}

.close-panel:hover {
    background: var(--light-gray);
    color: var(--gold);
}

.history-search {
    padding: 12px;
    border-bottom: 1px solid var(--border-gray);
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-wrapper i {
    position: absolute;
    left: 12px;
    color: var(--dark-gray);
}

#history-search {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border-gray);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.control-btn:hover {
    background: var(--light-gray);
    border-color: var(--gold);
    color: var(--gold);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.control-btn i {
    font-size: 1rem;
}

.message-textarea {
    width: 100%;
    padding: 15px 20px;
    border: 1px solid var(--border-gray);
    border-radius: var(--border-radius-large);
    font-family: 'Poppins', sans-serif;
    font-size: 1rem;
    resize: vertical;
    min-height: 100px;
    max-height: 200px;
    transition: var(--transition);
    background: var(--white);
}

.message-textarea:focus {
    outline: none;
}

.message-textarea:disabled {
    background: var(--light-gray);
    cursor: not-allowed;
    opacity: 0.6;
}

.send-btn {
    padding: 10px 16px;
    background: linear-gradient(135deg, var(--gold) 0%, #d9a833 100%);
    border: none;
    color: var(--white);
    border-radius: var(--border-radius-large);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 600;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
    font-size: 0.95rem;
    white-space: nowrap;
}

.send-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(212, 175, 55, 0.4);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* API Status Indicator */
.api-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 15px;
    font-size: 0.85rem;
    background: var(--light-gray);
    border-radius: var(--border-radius);
}

.api-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error-red);
    transition: var(--transition);
}

.api-indicator.connected {
    background: var(--success-green);
    box-shadow: 0 0 6px var(--success-green);
}

.api-indicator.disconnected {
    background: var(--error-red);
}

#api-status-text {
    color: var(--dark-gray);
    font-weight: 500;
}

.input-hint {
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--dark-gray);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--white);
    border-radius: var(--border-radius-large);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s ease-out;
}

.modal-content.large {
    max-width: 800px;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 25px;
    border-bottom: 1px solid var(--border-gray);
    background: linear-gradient(135deg, var(--white) 0%, #fafaf8 100%);
}

.modal-header h2 {
    font-family: 'Playfair Display', serif;
    font-size: 1.5rem;
    color: var(--black);
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--dark-gray);
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--gold);
    transform: rotate(90deg);
}

.modal-body {
    padding: 25px;
}

.form-section {
    margin-bottom: 20px;
}

.form-section label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--black);
}

.form-input,
.form-input select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-gray);
    border-radius: var(--border-radius);
    font-family: 'Poppins', sans-serif;
    font-size: 0.95rem;
    transition: var(--transition);
}

.form-input:focus,
.form-input select:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
}

/* Provider Options */
.provider-options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.provider-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--light-gray);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
}

.provider-label:hover {
    background: rgba(212, 175, 55, 0.1);
}

.provider-label input[type="radio"] {
    cursor: pointer;
}

.provider-label span {
    font-weight: 500;
}

.security-note,
#model-hint {
    display: block;
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--success-green);
}

.provider-info {
    background: rgba(33, 150, 243, 0.05);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-top: 15px;
    border-left: 4px solid var(--info-blue);
}

.provider-info h4 {
    color: var(--info-blue);
    margin-bottom: 10px;
}

.provider-info p {
    font-size: 0.9rem;
    color: var(--dark-gray);
    line-height: 1.6;
}

/* Modal Actions */
.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 25px;
}

.btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--gold) 0%, #d9a833 100%);
    color: var(--white);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(212, 175, 55, 0.4);
}

.btn-secondary {
    background: var(--light-gray);
    color: var(--dark-gray);
    border: 1px solid var(--border-gray);
}

.btn-secondary:hover {
    background: rgba(212, 175, 55, 0.1);
    border-color: var(--gold);
    color: var(--gold);
}

.test-result {
    margin-top: 15px;
    padding: 12px 15px;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
}

.test-result.success {
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid var(--success-green);
    color: var(--success-green);
}

.test-result.error {
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid var(--error-red);
    color: var(--error-red);
}

.test-result.hidden {
    display: none;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 15px 20px;
    background: var(--white);
    border-radius: var(--border-radius-large);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.success {
    border-left: 4px solid var(--success-green);
    color: var(--success-green);
}

.toast.error {
    border-left: 4px solid var(--error-red);
    color: var(--error-red);
}

.toast.warning {
    border-left: 4px solid var(--warning-orange);
    color: var(--warning-orange);
}

.toast.info {
    border-left: 4px solid var(--info-blue);
    color: var(--info-blue);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--light-gray);
}

::-webkit-scrollbar-thumb {
    background: var(--dark-gray);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gold);
}

/* Image Upload Controls */
.image-preview-container {
    display: flex;
    gap: 10px;
    padding: 10px 15px;
    background: #f9f9f9;
    border-top: 1px solid var(--border-gray);
    overflow-x: auto;
    align-items: center;
}

.image-preview-container.hidden {
    display: none;
}

.image-preview-item {
    position: relative;
    flex-shrink: 0;
}

.image-preview-item img {
    max-height: 80px;
    max-width: 120px;
    border-radius: 4px;
    border: 1px solid var(--border-gray);
}

.image-preview-item .remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--error-red);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: var(--transition);
}

.image-preview-item .remove-image:hover {
    background: #c82333;
    transform: scale(1.1);
}

/* Responsive Design */
@media (max-width: 1024px) {
    .ai-sidebar {
        width: 240px;
    }

    .messages-container {
        padding: 20px;
    }

    .message-bubble {
        max-width: 80%;
    }
}

@media (max-width: 768px) {
    .ai-container {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    .ai-sidebar {
        width: 100% !important;
        border-right: none;
        border-bottom: 1px solid var(--border-gray);
        max-height: 120px;
        flex-shrink: 0;
        overflow-x: auto;
    }

    .ai-main {
        width: 100% !important;
        height: calc(100vh - 120px);
    }

    .sidebar-header,
    .modes-section,
    .quick-actions {
        display: inline-block;
        vertical-align: top;
    }

    .mode-buttons,
    .quick-actions {
        display: flex;
        gap: 10px;
    }

    .mode-btn,
    .action-btn {
        flex: 0 1 auto;
        margin-bottom: 0;
    }

    .history-section {
        display: none;
    }

    .ai-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .message-bubble {
        max-width: 90%;
    }

    .modal-content {
        width: 95%;
        max-height: 85vh;
    }
}

@media (max-width: 480px) {
    .ai-header {
        padding: 15px 20px;
    }

    .ai-header h1 {
        font-size: 1.3rem;
    }

    .messages-container {
        padding: 15px;
        gap: 10px;
    }

    .ai-input-area {
        padding: 15px;
    }

    .modal-content {
        margin: 10px;
    }

    .toast-container {
        bottom: 10px;
        right: 10px;
    }

    .toast {
        min-width: 85vw;
        max-width: calc(100vw - 20px);
    }
}

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Code Block Wrapper with Copy Button */
.code-block-wrapper {
    position: relative;
    background: #1e1e1e;
    border-radius: var(--border-radius);
    overflow: hidden;
    margin: 10px 0;
    max-width: 100%;
    display: block;
}

.code-block-wrapper pre {
    margin: 0;
    padding: 15px;
    background: #1e1e1e;
    color: #d4d4d4;
    overflow-x: auto;
    overflow-y: visible;
    font-size: 0.85em;
    max-width: 100%;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.code-block-wrapper code {
    background: none !important;
    padding: 0 !important;
    color: #d4d4d4;
    font-family: 'Courier New', monospace;
    display: block;
    max-width: 100%;
}

.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--gold);
    border: none;
    color: var(--black);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 10;
}

.copy-code-btn:hover {
    background: #e5c158;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(212, 175, 55, 0.3);
}

/* Ensure code blocks in AI messages display properly */
.message.ai .message-bubble pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 15px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.85em;
}

/* Token warning display */
.token-warning {
    font-style: italic;
    text-decoration: underline;
    opacity: 0.8;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid currentColor;
}

/* Compact sidebar: hide text labels but keep icons visible */
.ai-sidebar.collapsed .mode-btn,
.ai-sidebar.collapsed .action-btn,
.ai-sidebar.collapsed .mode-buttons .mode-btn span,
.ai-sidebar.collapsed .action-btn span,
.ai-sidebar.collapsed .sidebar-header h2 {
    display: none;
}

.ai-sidebar.collapsed .mode-btn,
.ai-sidebar.collapsed .action-btn {
    justify-content: center;
    padding: 12px 8px;
}

/* Ensure history header and + button remain visible in collapsed state (icons only) */
.ai-sidebar.collapsed .history-section {
    padding: 8px;
}

.ai-sidebar.collapsed .history-section .conversation-history {
    display: none; /* keep history list hidden to avoid cutting content; user can expand sidebar */
}

/* Make the new-chat (+) button clearly visible when sidebar is compact */
.ai-sidebar.collapsed #new-chat-btn {
    background: var(--gold);
    color: var(--white);
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 14px rgba(212,175,55,0.18);
}

/* ensure action-btn icons in compact sidebar remain high-contrast */
.ai-sidebar.collapsed .action-btn i,
.ai-sidebar.collapsed .mode-btn i {
    color: var(--dark-gray);
    font-size: 1.05rem;
}

/* Show floating toggle button when collapsed so user can expand easily */
.ai-sidebar.collapsed ~ .ai-main {
    /* main content should not be pushed offscreen when sidebar is collapsed */
    margin-left: 0;
}

.ai-sidebar.collapsed + .ai-main {
    margin-left: 0;
}

/* ========================================================= */
/* COMPREHENSIVE MOBILE RESPONSIVE STYLES - AI ASSISTANT   */
/* ========================================================= */

/* Tablet Devices (max-width: 1024px) */
@media (max-width: 1024px) {
    /* Container - Tablet */
    .ai-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    /* Sidebar - Tablet */
    .ai-sidebar {
        width: 100% !important;
        border-right: none;
        border-bottom: 1px solid var(--border-gray);
        max-height: 120px;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    /* Main Content - Tablet */
    .ai-main {
        flex: 1;
        width: 100%;
    }

    /* Header - Tablet */
    .ai-header {
        padding: 1rem;
        flex-wrap: wrap;
        gap: 1rem;
    }

    .header-left h1 {
        font-size: 1.4rem;
    }

    .header-right {
        width: 100%;
        flex-wrap: wrap;
    }

    /* Chat Container - Tablet */
    .chat-container {
        height: calc(100vh - 250px);
    }

    /* Messages Area - Tablet */
    .messages-area {
        height: calc(100vh - 300px);
    }

    /* Input Area - Tablet */
    .input-area {
        padding: 1rem;
    }

    .input-wrapper {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .message-input {
        min-height: 60px;
        font-size: 16px;
        flex: 1;
        min-width: 100%;
    }

    .send-btn {
        width: 100%;
        padding: 0.8rem;
    }
}

/* Mobile Devices (max-width: 768px) */
@media (max-width: 768px) {
    /* Container - Mobile */
    .ai-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    /* Sidebar - Mobile (collapsed by default) */
    .ai-sidebar {
        width: 64px !important;
        max-height: none;
        height: auto;
        border-bottom: 1px solid var(--border-gray);
        flex-direction: column;
    }

    .ai-sidebar:not(.collapsed) {
        width: 100% !important;
        max-width: 100%;
        max-height: none;
    }

    /* Main Content - Mobile */
    .ai-main {
        width: 100%;
        height: calc(100vh - 80px);
    }

    /* Header - Mobile */
    .ai-header {
        padding: 0.75rem;
        flex-direction: column;
        gap: 0.5rem;
        border-bottom: 1px solid var(--border-gray);
    }

    .header-left h1 {
        font-size: 1.1rem;
    }

    .header-left p {
        font-size: 0.8rem;
    }

    .header-right {
        width: 100%;
        gap: 0.5rem;
    }

    .api-status {
        font-size: 0.8rem;
        padding: 0.6rem 0.8rem;
    }

    /* Messages Container - Mobile */
    .messages-area {
        height: calc(100vh - 200px);
        padding: 0.75rem;
    }

    .message {
        margin-bottom: 0.5rem;
    }

    .message-bubble {
        padding: 0.75rem;
        font-size: 0.9rem;
        max-width: 90vw;
    }

    /* Input Area - Mobile */
    .input-area {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .message-input {
        min-height: 50px;
        font-size: 16px;
        padding: 0.6rem;
    }

    .send-btn {
        width: auto;
        min-width: 50px;
        padding: 0.6rem 0.8rem;
    }

    /* Modes Section - Mobile */
    .modes-section,
    .quick-actions,
    .history-section {
        padding: 0.8rem;
    }

    .mode-btn {
        padding: 0.8rem;
        font-size: 0.8rem;
    }

    /* Action Buttons - Mobile */
    .action-btn {
        padding: 0.7rem;
        font-size: 0.8rem;
    }

    /* History Item - Mobile */
    .history-item {
        padding: 0.7rem;
        font-size: 0.8rem;
    }

    /* Sidebar Header - Mobile */
    .sidebar-header {
        padding: 0.8rem;
    }

    .header-left h2 {
        font-size: 1rem;
    }

    /* Icon Button - Mobile */
    .icon-btn {
        width: 24px;
        height: 24px;
    }
}

/* Small Phones (max-width: 480px) */
@media (max-width: 480px) {
    /* Container - Small Phones */
    .ai-container {
        flex-direction: column;
        height: 100vh;
    }

    /* Sidebar - Small Phones */
    .ai-sidebar {
        width: 56px !important;
        height: auto;
        max-height: 70px;
        overflow-y: hidden;
    }

    .ai-sidebar:not(.collapsed) {
        width: 100% !important;
        max-height: 150px;
    }

    /* Main Content - Small Phones */
    .ai-main {
        width: 100%;
        height: calc(100vh - 70px);
        flex-direction: column;
    }

    /* Header - Small Phones */
    .ai-header {
        padding: 0.5rem;
        min-height: auto;
        gap: 0.3rem;
    }

    .header-left h1 {
        font-size: 1rem;
        margin: 0;
    }

    .header-left p {
        font-size: 0.7rem;
        margin: 0;
    }

    .header-right {
        width: 100%;
        gap: 0.3rem;
    }

    .api-status {
        font-size: 0.7rem;
        padding: 0.4rem 0.6rem;
        gap: 4px;
    }

    /* Messages - Small Phones */
    .messages-area {
        height: calc(100vh - 150px);
        padding: 0.5rem;
    }

    .message-bubble {
        padding: 0.5rem;
        font-size: 0.85rem;
        max-width: 95vw;
    }

    .message.user .message-bubble {
        border-radius: 12px 4px 12px 12px;
    }

    .message.ai .message-bubble {
        border-radius: 4px 12px 12px 12px;
    }

    /* Input Area - Small Phones */
    .input-area {
        padding: 0.5rem;
        gap: 0.3rem;
        flex-direction: column;
    }

    .input-wrapper {
        flex-direction: column;
        gap: 0.4rem;
    }

    .message-input {
        min-height: 45px;
        font-size: 16px;
        padding: 0.5rem;
        width: 100%;
    }

    .send-btn {
        width: 100%;
        padding: 0.6rem;
        font-size: 0.9rem;
    }

    /* Modes Section - Small Phones */
    .modes-section,
    .quick-actions,
    .history-section {
        padding: 0.6rem;
    }

    .mode-btn {
        padding: 0.6rem;
        font-size: 0.75rem;
        gap: 6px;
    }

    .mode-btn i {
        font-size: 0.9rem;
    }

    /* Action Buttons - Small Phones */
    .action-btn {
        padding: 0.5rem;
        font-size: 0.75rem;
    }

    .action-btn i {
        font-size: 0.8rem;
    }

    /* History Item - Small Phones */
    .history-item {
        padding: 0.5rem;
        font-size: 0.75rem;
    }

    /* Sidebar Header - Small Phones */
    .sidebar-header {
        padding: 0.6rem;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0.4rem;
    }

    .header-left h2 {
        font-size: 0.9rem;
    }

    .header-actions {
        gap: 2px;
    }

    /* Icon Buttons - Small Phones */
    .icon-btn {
        width: 20px;
        height: 20px;
        font-size: 0.8rem;
    }

    /* Toggle Button - Small Phones */
    .floating-toggle-btn {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
        left: 64px;
    }

    /* Code Textarea - Small Phones */
    .code-textarea {
        font-size: 12px;
    }

    /* Scrollbar - Small Phones */
    .conversation-history::-webkit-scrollbar {
        width: 4px;
    }

    /* Message Tags - Small Phones */
    .message-timestamp {
        font-size: 0.7rem;
    }
}