/* OpenAI Chat Module - ChatGPT-like Interface Styles */

:root {
    /* ChatGPT colors */
    --chat-bg: #ffffff;
    --chat-surface: #f7f7f8;
    --chat-border: #e5e5e5;
    --chat-text: #202123;
    --chat-text-light: #6e6e80;
    --chat-hover: #f7f7f8;
    
    /* User message */
    --user-bg: #f7f7f8;
    --user-text: #202123;
    
    /* Assistant message */
    --assistant-bg: #ffffff;
    --assistant-border: #e5e5e5;
    
    /* Accent colors */
    --accent-green: #10a37f;
    --accent-green-hover: #0d8c6f;
    --accent-red: #ef4444;
    
    /* Effects */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --radius: 8px;
    --transition: all 0.15s ease;
}

/* Container */
.openai-chat-container {
    display: flex;
    flex-direction: row;
    height: 85vh;
    max-width: 100%;
    background: #f3f4f6;
    border-radius: 16px;
    border: 1px solid var(--chat-border);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    position: relative;
}

/* Sidebar */
.chat-sidebar {
    width: 280px;
    background: var(--chat-surface);
    border-right: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s ease;
}

.chat-sidebar.collapsed {
    width: 56px;
}

.sidebar-header {
    padding: 12px 8px;
    border-bottom: 1px solid var(--chat-border);
    background: var(--chat-surface);
}

.sidebar-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* Icon-only buttons for sidebar header */
.btn-sidebar-icon-only {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--chat-border);
    cursor: pointer;
    background: transparent;
    color: var(--chat-text-light);
    transition: var(--transition);
    text-decoration: none;
}

.btn-sidebar-icon-only:hover {
    background: #ffffff;
    color: var(--chat-text);
    border-color: var(--chat-text-light);
}

.btn-sidebar-icon-only svg {
    width: 20px;
    height: 20px;
}

/* New chat button with text */
.btn-sidebar-new-chat {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #2563eb;
    cursor: pointer;
    background: #2563eb;
    color: #ffffff;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-sidebar-new-chat:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.btn-sidebar-new-chat svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn-sidebar-new-chat .btn-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Collapsed state - hide text */
.chat-sidebar.collapsed .btn-sidebar-new-chat {
    justify-content: center;
    padding: 8px;
    flex: 0 0 40px;
}

.chat-sidebar.collapsed .btn-sidebar-new-chat .btn-text {
    display: none;
}

/* Toggle button icons */
.chat-sidebar.collapsed .icon-collapse {
    display: none;
}

.chat-sidebar.collapsed .icon-expand {
    display: block;
}

.chat-sidebar:not(.collapsed) .icon-expand {
    display: none;
}

.chat-sidebar:not(.collapsed) .icon-collapse {
    display: block;
}

/* Collapsed sidebar state */
.chat-sidebar.collapsed .sidebar-header-row {
    flex-direction: column;
    gap: 4px;
}

.chat-sidebar.collapsed .section-title,
.chat-sidebar.collapsed .history-list {
    display: none;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.sidebar-section {
    margin-bottom: 20px;
}

.section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--chat-text-light);
    margin-bottom: 8px;
    padding: 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 4px;
}

.history-item {
    padding: 10px 10px;
    border-radius: 14px;
    cursor: pointer;
    transition: var(--transition);
    background: transparent;
    border: 1.5px solid transparent;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    position: relative;
}

.history-item:hover {
    background: #f8fafc;
}

.history-item.active {
    background: #ffffff;
    border-color: #e2e8f0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.history-item > svg.history-item-icon {
    width: 18px;
    height: 18px;
    color: #94a3b8;
    flex-shrink: 0;
    margin-top: 3px;
}

.history-item.active > svg.history-item-icon {
    color: #3b82f6;
}

.history-item-icon {
    width: 18px;
    height: 18px;
    color: #94a3b8;
    flex-shrink: 0;
    margin-top: 3px;
}

.history-item.active .history-item-icon {
    color: #3b82f6;
}

.history-item-content {
    flex: 1;
    min-width: 0;
}

.history-item-title {
    font-size: 13px;
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
    line-height: 1.3;
}

.history-item.active .history-item-title {
    color: #1e3a8a;
    font-weight: 600;
}

.history-item-meta {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
}

.history-item-actions {
    display: none;
    gap: 4px;
}

.history-item:hover .history-item-actions {
    display: flex;
}

.btn-delete-history {
    background: transparent;
    border: none;
    padding: 4px;
    cursor: pointer;
    border-radius: 4px;
    color: var(--chat-text-light);
    transition: var(--transition);
}

.btn-delete-history:hover {
    background: var(--accent-red);
    color: white;
}

.btn-delete-history svg {
    width: 14px;
    height: 14px;
}

.empty-history {
    text-align: center;
    padding: 40px 20px;
    color: var(--chat-text-light);
}

.empty-history svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.3;
}

.empty-history p {
    font-size: 13px;
    margin: 0;
}

/* Main chat area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Header - ChatGPT Style */
.chat-header {
    background: var(--chat-bg);
    border-bottom: 1px solid var(--chat-border);
    padding: 16px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 900px;
    margin: 0 auto;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-text);
    margin: 0;
}

.header-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 999px;
    background: #ecfdf3;
    border: 1px solid #bbf7d0;
    font-size: 11px;
    color: #15803d;
    font-weight: 500;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: #22c55e;
}

.status-text {
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.btn-new-chat {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid var(--chat-border);
    border-radius: 6px;
    color: var(--chat-text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-new-chat:hover {
    background: var(--chat-hover);
}

.btn-new-chat svg {
    width: 16px;
    height: 16px;
}

.btn-new-chat span {
    display: none;
}

@media (min-width: 640px) {
    .btn-new-chat span {
        display: inline;
    }
}

/* Legal Notice - subtle like ChatGPT */
.legal-notice {
    background: transparent;
    border: none;
    padding: 8px 16px;
    margin: 12px auto;
    max-width: 768px;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.notice-icon {
    width: 14px;
    height: 14px;
    color: var(--chat-text-light);
    flex-shrink: 0;
    margin-top: 2px;
    opacity: 0.6;
}

.legal-notice p {
    margin: 0;
    font-size: 11px;
    line-height: 1.5;
    color: var(--chat-text-light);
    opacity: 0.7;
}

.legal-notice strong {
    color: var(--chat-text-light);
    font-weight: 600;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    background: #ffffff;
    padding: 24px 40px 16px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--chat-border);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chat-text-light);
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    text-align: center;
    padding: 40px 20px;
}

.welcome-icon {
    width: 64px;
    height: 64px;
    color: var(--chat-primary);
    margin-bottom: 24px;
}

.welcome-icon svg {
    width: 100%;
    height: 100%;
}

.welcome-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--chat-primary);
    margin: 0 0 12px 0;
}

.welcome-subtitle {
    font-size: 15px;
    color: var(--chat-text);
    margin: 0 0 8px 0;
    line-height: 1.6;
}

.welcome-guide {
    font-size: 14px;
    color: var(--chat-text-secondary);
    margin: 0 0 28px 0;
    font-style: italic;
}

/* Starter Prompts */
.starter-prompts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    max-width: 900px;
    width: 100%;
}

.starter-prompt-btn {
    background: var(--chat-secondary-bg);
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius);
    padding: 20px;
    text-align: left;
    cursor: pointer;
    transition: var(--chat-transition);
    display: flex;
    gap: 16px;
}

.starter-prompt-btn:hover {
    background: var(--chat-bg);
    border-color: var(--chat-primary);
    box-shadow: 0 2px 8px var(--chat-shadow);
    transform: translateY(-2px);
}

.prompt-icon {
    flex-shrink: 0;
}

.prompt-icon svg {
    width: 24px;
    height: 24px;
    color: var(--chat-primary);
}

.prompt-content h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-text);
}

.prompt-content p {
    margin: 0;
    font-size: 14px;
    color: var(--chat-text-secondary);
    line-height: 1.5;
}

/* Messages List */
.messages-list {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
}

.message-wrapper.message-user {
    align-items: flex-end;
}

.message-wrapper.message-assistant {
    align-items: stretch;
    max-width: 100%;
}

.message-assistant .chat-message {
    max-width: 100%;
    width: 100%;
}

.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: fadeInUp 0.3s ease;
    position: relative;
    max-width: 80%;
}

.chat-message:last-child {
    margin-bottom: 0;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-text {
    font-size: 14px;
    line-height: 1.6;
    color: var(--chat-text);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-text p {
    margin: 4px 0;
}

.message-text p:first-child {
    margin-top: 0;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text code {
    background: var(--chat-secondary-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

/* User message styling - ChatGPT style: gray bg, rounded, align right */
.message-user {
    background: #ffffff;
}

.message-user .message-content {
    display: flex;
    justify-content: flex-end;
}

.message-user .message-text {
    color: #1f2937;
    font-weight: 400;
    background: #f1f5f9;
    padding: 12px 16px;
    border-radius: 20px;
    border-top-right-radius: 4px;
    max-width: 70%;
    min-width: fit-content;
    display: inline-block;
    box-shadow: none;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-user .chat-message {
    flex-direction: row-reverse;
}

/* Assistant message styling - white background like ChatGPT */
.message-assistant {
    background: transparent;
}

.message-assistant .message-text {
    line-height: 1.6;
    font-size: 14px;
    color: #111827;
}

.message-assistant .message-text p {
    margin: 0 0 4px 0;
}

.message-assistant .message-text p:first-child {
    margin-top: 0;
}

.message-assistant .message-text p:last-child {
    margin-bottom: 0;
}

.message-assistant .message-text p + p {
    margin-top: 4px;
}

.message-assistant .message-text h1,
.message-assistant .message-text h2,
.message-assistant .message-text h3 {
    margin: 6px 0 2px 0;
    color: var(--chat-text);
    line-height: 1.4;
}

.message-assistant .message-text h1:first-child,
.message-assistant .message-text h2:first-child,
.message-assistant .message-text h3:first-child {
    margin-top: 0;
}

.message-assistant .message-text h1 { 
    font-size: 17px; 
    font-weight: 700;
}

.message-assistant .message-text h2 { 
    font-size: 15px; 
    font-weight: 600;
}

.message-assistant .message-text h3 { 
    font-size: 14px; 
    font-weight: 600;
}

.message-assistant .message-text ul,
.message-assistant .message-text ol {
    margin: 2px 0;
    padding-left: 16px;
}

.message-assistant .message-text ul:first-child,
.message-assistant .message-text ol:first-child {
    margin-top: 0;
}

.message-assistant .message-text ul:last-child,
.message-assistant .message-text ol:last-child {
    margin-bottom: 0;
}

/* Nested lists with more indentation */
.message-assistant .message-text li ul,
.message-assistant .message-text li ol {
    margin: 2px 0;
    padding-left: 24px;
}

.message-assistant .message-text li {
    margin: 0 0 2px 0;
    line-height: 1.5;
    padding-left: 4px;
}

.message-assistant .message-text li:last-child {
    margin-bottom: 0;
}

.message-assistant .message-text li p {
    margin: 0;
    display: inline;
}

.message-assistant .message-text li::marker {
    font-weight: 600;
}

.message-assistant .message-text ol > li::marker {
    color: var(--chat-text);
}

.message-assistant .message-text ul > li::marker {
    color: var(--chat-text);
}

.message-assistant .message-text li::marker {
    color: var(--chat-primary);
    font-weight: 600;
}

.message-assistant .message-text strong {
    font-weight: 700;
    color: #111827;
}

/* Assistant bubble as rounded card */
.message-assistant .message-content {
    display: block;
    width: 100%;
    max-width: 100%;
}

.message-assistant .message-text {
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    border: none;
    font-size: 14px;
    line-height: 1.5;
    color: #1e293b;
}

.message-assistant .message-text p {
    margin: 0 0 6px 0;
}

.message-assistant .message-text p:last-child {
    margin-bottom: 0;
}

.message-assistant .message-text ol,
.message-assistant .message-text ul {
    margin: 4px 0 8px 0;
    padding-left: 24px;
}

.message-assistant .message-text ol {
    list-style-type: decimal;
}

.message-assistant .message-text li {
    margin-bottom: 4px;
    line-height: 1.5;
    padding-left: 4px;
}

.message-assistant .message-text li:last-child {
    margin-bottom: 0;
}

.message-assistant .message-text .numbered-heading {
    margin: 6px 0 2px 0;
    font-size: 14px;
}

.message-assistant .message-text .numbered-heading:first-child {
    margin-top: 0;
}

.message-assistant .message-text .numbered-item {
    margin: 2px 0;
}

/* Markdown Tables */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 12px 0;
}

.markdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.markdown-table th,
.markdown-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: top;
}

.markdown-table th {
    background: #f8fafc;
    font-weight: 600;
    color: #1e293b;
    border-bottom: 2px solid #e2e8f0;
}

.markdown-table tr:last-child td {
    border-bottom: none;
}

.markdown-table tr:hover td {
    background: #f8fafc;
}

.markdown-table td:first-child,
.markdown-table th:first-child {
    font-weight: 500;
}

.message-assistant .message-text h1,
.message-assistant .message-text h2,
.message-assistant .message-text h3,
.message-assistant .message-text h4,
.message-assistant .message-text h5 {
    margin: 8px 0 4px 0;
    font-weight: 600;
    color: #0f172a;
}

.message-assistant .message-text h1 {
    font-size: 18px;
}

.message-assistant .message-text h2 {
    font-size: 16px;
}

.message-assistant .message-text h3 {
    font-size: 15px;
}

.message-assistant .message-text h4 {
    font-size: 14px;
}

.message-assistant .message-text h5 {
    font-size: 13px;
}

.message-assistant .message-text strong {
    font-weight: 600;
    color: #0f172a;
}

.message-assistant .message-text br + br {
    display: none;
}

.message-assistant .chat-message {
    /* Avatar on left, content on right */
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: linear-gradient(135deg, #0d9488 0%, #14b8a6 100%);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(13, 148, 136, 0.25);
}

.avatar svg {
    width: 16px;
    height: 16px;
}

.assistant-label {
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
    margin-bottom: 6px;
    margin-left: 46px;
}

.message-timestamp {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.message-user .message-timestamp {
    justify-content: flex-end;
}

.message-assistant .message-timestamp {
    margin-left: 46px;
}

.message-text code {
    background: var(--chat-secondary-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.message-text pre {
    background: var(--chat-secondary-bg);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-text pre code {
    background: none;
    padding: 0;
}

.message-time {
    font-size: 12px;
    color: var(--chat-text-secondary);
    margin-top: 8px;
}

/* Input Area - ChatGPT style with shadow */
.chat-input-container {
    background: var(--chat-bg);
    border-top: none;
    padding: 20px 16px 24px;
    flex-shrink: 0;
}

.chat-input-wrapper {
    max-width: 768px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 999px;
    padding: 10px 18px;
    transition: var(--transition);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.02), 0 1px 3px rgba(0,0,0,0.1);
}

.chat-input-wrapper:focus-within {
    border-color: var(--chat-text);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.1), 0 2px 8px rgba(0,0,0,0.15);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--chat-text);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    min-height: 24px;
    max-height: 200px;
    line-height: 1.5;
    padding: 4px 0;
}

.chat-input::placeholder {
    color: var(--chat-text-light);
}

.btn-send {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    background: #2563eb;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.btn-send:hover:not(:disabled) {
    background: #1d4ed8;
}

.btn-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: var(--chat-text-light);
}

.send-icon {
    width: 18px;
    height: 18px;
    color: white;
}

.btn-input-action {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    border: none;
    background: #e5edff;
    color: #2563eb;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.btn-input-action:hover {
    background: #d4ddff;
}

.btn-input-action svg {
    width: 18px;
    height: 18px;
}

.input-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 8px;
    font-size: 11px;
    color: var(--chat-text-light);
    text-align: center;
    max-width: 768px;
    margin-left: auto;
    margin-right: auto;
}

.char-count {
    display: none; /* Hide like ChatGPT */
}

.powered-by {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Loading Indicator */
.loading-indicator {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--chat-secondary-bg);
    border: 1px solid var(--chat-border);
    border-radius: 20px;
    padding: 12px 20px;
    box-shadow: 0 2px 8px var(--chat-shadow);
}

.loading-dots {
    display: flex;
    gap: 6px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--chat-primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .openai-chat-container {
        height: 100vh;
        border-radius: 0;
    }

    .starter-prompts {
        grid-template-columns: 1fr;
    }

    .header-title {
        font-size: 18px;
    }

    .welcome-title {
        font-size: 24px;
    }

    .chat-messages {
        padding: 16px;
    }
}

/* Accessibility */
.btn-header:focus,
.btn-send:focus,
.starter-prompt-btn:focus {
    outline: 2px solid var(--chat-primary);
    outline-offset: 2px;
}

.chat-input:focus {
    outline: none;
}

/* Scrollbar styling for Firefox */
.chat-messages {
    scrollbar-width: thin;
    scrollbar-color: var(--chat-border) transparent;
}

/* Company Information Display */
.company-info {
    background: var(--chat-secondary-bg);
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    padding: 16px;
    margin: 8px 0;
}

.company-info h3 {
    margin: 0 0 12px 0;
    color: var(--chat-primary);
    font-size: 18px;
    font-weight: 600;
}

.company-info p {
    margin: 6px 0;
    color: var(--chat-text);
    font-size: 14px;
    line-height: 1.5;
}

.company-info a {
    color: var(--chat-primary);
    text-decoration: none;
}

.company-info a:hover {
    text-decoration: underline;
}

/* JSON Display */
.message-text pre {
    background: var(--chat-secondary-bg);
    border: 1px solid var(--chat-border);
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    line-height: 1.4;
}

/* Error Message */
.message-error {
    background: #fee;
    border-left: 3px solid #dc2626;
}

.avatar-error {
    background: #dc2626;
    color: white;
}

/* ChatKit Integration Styles */
.chatkit-wrapper {
    flex: 1;
    width: 100%;
    height: 100%;
    display: none; /* Hidden until initialized */
}

.chatkit-wrapper.active {
    display: block;
}

/* Override ChatKit default styles to match DNN theme */
chatkit-root {
    width: 100%;
    height: 100%;
    display: block;
}

/* Hide welcome screen when ChatKit is active */
.welcome-screen.hidden {
    display: none !important;
}

/* Markdown Rendering Styles */
.markdown-body {
    line-height: 1.6;
}

.markdown-body p {
    margin: 4px 0;
}

.markdown-body p:empty {
    display: none;
}

.markdown-body h1 {
    font-size: 1.8em;
    font-weight: 600;
    margin: 0.8em 0 0.5em 0;
    border-bottom: 2px solid var(--chat-border);
    padding-bottom: 0.3em;
}

.markdown-body h2 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 0.7em 0 0.4em 0;
    border-bottom: 1px solid var(--chat-border);
    padding-bottom: 0.2em;
}

.markdown-body h3 {
    font-size: 1.25em;
    font-weight: 600;
    margin: 8px 0 4px 0;
}

.markdown-body h4 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 8px 0 4px 0;
}

.markdown-body h5 {
    font-size: 1em;
    font-weight: 600;
    margin: 8px 0 4px 0;
}

.markdown-body ul,
.markdown-body ol {
    margin: 4px 0;
    padding-left: 1.5em;
}

.markdown-body li {
    margin: 2px 0;
}

.markdown-body blockquote {
    border-left: 4px solid var(--chat-primary);
    margin: 0.5em 0;
    padding: 0.5em 1em;
    background: var(--chat-secondary-bg);
    font-style: italic;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--chat-border);
    margin: 1em 0;
}

.markdown-body pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.markdown-body code {
    background: rgba(175, 184, 193, 0.2);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

.markdown-body pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.markdown-body a {
    color: var(--chat-primary);
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body strong {
    font-weight: 600;
}

.markdown-body em {
    font-style: italic;
}

/* Streaming Cursor Animation */
.streaming-cursor {
    display: inline-block;
    width: 8px;
    background: var(--chat-primary);
    margin-left: 2px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 49% {
        opacity: 1;
    }
    50%, 100% {
        opacity: 0;
    }
}

/* =========================================
   SOURCE PANE - Right panel for citations
   ========================================= */

.source-pane {
    width: 0;
    background: var(--chat-surface);
    border-left: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s ease;
    overflow: hidden;
}

.source-pane.visible {
    width: 380px;
}

.source-pane-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--chat-bg);
}

.source-pane-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-text);
}

.source-pane-title svg {
    color: var(--accent-green);
}

.btn-close-pane {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--chat-text-light);
    transition: var(--transition);
}

.btn-close-pane:hover {
    background: var(--chat-hover);
    color: var(--chat-text);
}

.source-pane-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.source-pane-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--chat-border);
    background: var(--chat-bg);
}

.btn-show-all-sources {
    width: 100%;
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid var(--chat-border);
    background: var(--chat-bg);
    color: var(--chat-text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

.btn-show-all-sources:hover {
    background: var(--chat-hover);
    border-color: var(--accent-green);
}

.source-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: var(--chat-text-light);
}

.source-placeholder svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.source-placeholder p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
}

/* Citation detail card */
.citation-detail {
    background: var(--chat-bg);
    border-radius: 12px;
    border: 1px solid var(--chat-border);
    overflow: hidden;
}

.citation-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #e5e7eb, #d1d5db);
    color: #111827;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.citation-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-weight: 700;
    font-size: 14px;
}

.citation-title {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    flex: 1;
}

/* Citation tabs */
.citation-tabs {
    display: flex;
    border-bottom: 1px solid var(--chat-border);
    background: var(--chat-surface);
}

.source-tab {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--chat-text-light);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 2px solid transparent;
}

.source-tab:hover {
    color: var(--chat-text);
    background: var(--chat-hover);
}

.source-tab.active {
    color: var(--accent-green);
    border-bottom-color: var(--accent-green);
}

.citation-tab-content {
    padding: 16px 20px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.excerpt-text blockquote {
    margin: 0;
    padding: 16px;
    background: #fff8e1;
    border-left: 4px solid #ffc107;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: var(--chat-text);
    line-height: 1.6;
}

.clause-text {
    padding: 12px;
    background: var(--chat-surface);
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.6;
}

.fulltext-container {
    max-height: 400px;
    overflow-y: auto;
}

.file-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: var(--chat-surface);
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 13px;
}

.relevance-score {
    color: var(--accent-green);
    font-weight: 500;
}

.fulltext-content {
    padding: 16px;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.7;
    word-wrap: break-word;
    max-height: 60vh;
    overflow-y: auto;
}

/* Markdown content in source pane */
.fulltext-content.markdown-content {
    white-space: normal;
}

.fulltext-content.markdown-content h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 16px 0 8px 0;
    color: var(--chat-text);
    border-bottom: 1px solid var(--chat-border);
    padding-bottom: 6px;
}

.fulltext-content.markdown-content h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 14px 0 6px 0;
    color: var(--chat-text);
}

.fulltext-content.markdown-content h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 12px 0 4px 0;
    color: var(--chat-text);
}

.fulltext-content.markdown-content p {
    margin: 0 0 12px 0;
}

.fulltext-content.markdown-content ul,
.fulltext-content.markdown-content ol {
    margin: 8px 0 12px 0;
    padding-left: 24px;
}

.fulltext-content.markdown-content li {
    margin: 4px 0;
}

.fulltext-content.markdown-content blockquote {
    margin: 10px 0;
    padding: 10px 16px;
    border-left: 3px solid var(--accent-green);
    background: var(--chat-surface);
    border-radius: 0 6px 6px 0;
    color: var(--chat-text-light);
    font-style: italic;
}

.fulltext-content.markdown-content code {
    background: var(--chat-surface);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
}

.fulltext-content.markdown-content strong {
    font-weight: 600;
}

.fulltext-content.markdown-content em {
    font-style: italic;
}

.fulltext-content.markdown-content hr {
    border: none;
    border-top: 1px solid var(--chat-border);
    margin: 16px 0;
}

.fulltext-content mark.highlight {
    background: #fef08a;
    padding: 2px 4px;
    border-radius: 2px;
}

.no-content {
    color: var(--chat-text-light);
    font-style: italic;
    text-align: center;
    padding: 20px;
}

/* Sources overview */
.sources-overview h3 {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-text);
}

.sources-overview h4 {
    margin: 24px 0 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--chat-text-light);
}

.sources-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.source-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--chat-border);
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.source-item:hover {
    background: var(--chat-hover);
    border-color: var(--accent-green);
}

.source-title {
    font-size: 14px;
    line-height: 1.4;
    color: var(--chat-text);
}

.file-results-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.file-result-item {
    display: flex;
    flex-direction: column;
    padding: 12px;
    border-radius: 8px;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    margin-bottom: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}

.file-result-item:hover {
    background: var(--chat-hover);
    border-color: var(--accent-green);
}

.file-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.file-name {
    color: var(--chat-text);
    font-weight: 500;
}

.file-score {
    color: var(--accent-green);
    font-weight: 600;
    font-size: 12px;
}

.file-preview {
    color: var(--chat-text-light);
    font-size: 12px;
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.btn-back-sources {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    margin-bottom: 16px;
    border-radius: 6px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface);
    color: var(--chat-text);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-back-sources:hover {
    background: var(--chat-hover);
    border-color: var(--accent-green);
}

/* Citation links in text [1], [2], etc. */
.citation-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    margin: 0 3px;
    background: #e5e7eb;
    color: #111827;
    font-size: 12px;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
    vertical-align: middle;
    transition: all 0.2s ease;
    position: relative;
    box-shadow: 0 1px 2px rgba(55, 65, 81, 0.15);
    text-decoration: none;
    border: 1px solid #d1d5db;
}

.citation-link:hover {
    background: #d1d5db;
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 2px 4px rgba(55, 65, 81, 0.2);
    border-color: #c5cbd3;
}

.citation-link:active {
    transform: translateY(0) scale(1.0);
    box-shadow: 0 1px 2px rgba(55, 65, 81, 0.18);
}

/* Enhanced tooltip styling for citations - CUSTOM ONLY, NO NATIVE TITLE */
.citation-link[data-tooltip-text] {
    position: relative;
}

#citationTooltipFloating { display: none !important; }
.citation-link[data-tooltip-text]:hover::after { display: none !important; content: none !important; }
.citation-link[data-tooltip-text]:hover::before { display: none !important; content: none !important; }




@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Highlight in fulltext */
.highlight {
    background: #fff3cd;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 500;
    box-shadow: 0 0 0 3px rgba(255, 243, 205, 0.5);
}

/* Pulse highlight animation */
.pulse-highlight {
    animation: pulseHighlight 1s ease-in-out 2;
}

@keyframes pulseHighlight {
    0%, 100% {
        background: #fff3cd;
        box-shadow: 0 0 0 3px rgba(255, 243, 205, 0.5);
    }
    50% {
        background: #ffc107;
        box-shadow: 0 0 0 6px rgba(255, 193, 7, 0.3);
    }
}

/* Sources button on assistant messages */
.sources-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin-top: 12px;
    border-radius: 6px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface);
    color: var(--chat-text-light);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.sources-button:hover {
    background: var(--chat-bg);
    border-color: var(--accent-green);
    color: var(--accent-green);
}

/* Adjust main chat area when source pane is visible */
.chat-main.with-source-pane {
    flex: 1;
    min-width: 0;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .source-pane.visible {
        width: 320px;
    }
}

@media (max-width: 992px) {
    .source-pane {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    }
    
    .source-pane.visible {
        width: 360px;
    }
    
    .chat-main.with-source-pane {
        margin-right: 0;
    }
}

@media (max-width: 768px) {
    .source-pane.visible {
        width: 100%;
    }
}
