/**
 * LangChain Chatbot UI Styling
 * Styles for RAG Knowledge Base Manager and Chatbot Manager tabs
 *
 * @author Médéric (Académie des Étoiles)
 * @date 2025-11-21
 */

/* ============================================================================
   Chatbot Tab Container
   ============================================================================ */

.chatbot-tab-container {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.chatbot-tab-header {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.chatbot-tab-header h2 {
    margin: 0;
    font-size: 1.75rem;
    color: #1e293b;
}

.tab-description {
    color: #64748b;
    margin: 0.5rem 0 0 0;
    font-size: 0.95rem;
}

/* ============================================================================
   Knowledge Base Cards
   ============================================================================ */

.kb-list,
.chatbot-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 1.5rem;
}

.kb-card,
.chatbot-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    padding: 1.5rem;
    transition: box-shadow 0.2s, transform 0.2s;
}

.kb-card:hover,
.chatbot-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    transform: translateY(-2px);
}

.chatbot-card--disabled {
    opacity: 0.6;
}

.kb-card__header,
.chatbot-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    gap: 1rem;
}

.kb-card__title h3,
.chatbot-card__title h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.25rem;
    color: #1e293b;
}

/* Status Badges */

.kb-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.kb-badge--pending { background: #fef3c7; color: #92400e; }
.kb-badge--indexing { background: #dbeafe; color: #1e40af; }
.kb-badge--ready { background: #d1fae5; color: #065f46; }
.kb-badge--error { background: #fee2e2; color: #991b1b; }

.type-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.type-badge--course { background: #e0e7ff; color: #3730a3; }
.type-badge--training { background: #fce7f3; color: #831843; }

.badge-success {
    background: #d1fae5;
    color: #065f46;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Statistics */

.kb-card__stats,
.chatbot-card__stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 8px;
}

.stat,
.stat-item {
    text-align: center;
}

.stat__value,
.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 0.25rem;
}

.stat__label,
.stat-label {
    display: block;
    font-size: 0.75rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Metadata */

.kb-card__meta,
.chatbot-card__info {
    margin: 1rem 0;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

.kb-meta__item,
.info-row {
    display: block;
    margin: 0.5rem 0;
    font-size: 0.875rem;
    color: #475569;
}

.info-label {
    color: #64748b;
    margin-right: 0.5rem;
}

.info-value {
    color: #1e293b;
    font-weight: 500;
}

/* Actions */

.kb-card__actions,
.chatbot-card__actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* Standalone Link Section */

.chatbot-card__standalone {
    margin: 1rem 0;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.standalone-active {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.url-input {
    flex: 1;
    min-width: 200px;
    padding: 0.5rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.875rem;
    font-family: monospace;
}

/* ============================================================================
   Modals
   ============================================================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal__overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal__content {
    position: relative;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal--medium .modal__content {
    width: 90%;
    max-width: 600px;
}

.modal--large .modal__content {
    width: 90%;
    max-width: 900px;
}

.modal__header {
    padding: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal__header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: #1e293b;
}

.modal__close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #64748b;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s;
}

.modal__close:hover {
    background: #f1f5f9;
}

.modal__body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal__footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ============================================================================
   Chunks Viewer
   ============================================================================ */

.chunks-header {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.chunks-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chunk-item {
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fafafa;
}

.chunk-item__header {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.chunk-badge,
.lesson-badge,
.section-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.chunk-badge {
    background: #e0e7ff;
    color: #3730a3;
}

.lesson-badge {
    background: #fef3c7;
    color: #92400e;
}

.section-badge {
    background: #e2e8f0;
    color: #475569;
}

.token-count {
    margin-left: auto;
    color: #64748b;
    font-size: 0.75rem;
}

.chunk-item__content {
    padding: 0.75rem;
    background: white;
    border-radius: 6px;
    white-space: pre-wrap;
    font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
}

.chunk-item__meta {
    margin-top: 0.75rem;
}

.chunk-item__meta summary {
    cursor: pointer;
    color: #64748b;
    font-size: 0.875rem;
}

.chunk-item__meta pre {
    margin: 0.5rem 0 0 0;
    padding: 0.75rem;
    background: white;
    border-radius: 6px;
    overflow-x: auto;
}

/* ============================================================================
   Search Results
   ============================================================================ */

.search-query {
    padding: 1rem;
    background: #f8fafc;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.search-results {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.search-result {
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: white;
}

.result-header {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.result-rank {
    font-weight: 700;
    color: #667eea;
    font-size: 1.25rem;
}

.result-score {
    padding: 0.25rem 0.75rem;
    background: #e0e7ff;
    color: #3730a3;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.result-content {
    padding: 0.75rem;
    background: #f8fafc;
    border-radius: 6px;
    line-height: 1.6;
}

.no-results {
    text-align: center;
    padding: 2rem;
    color: #64748b;
}

/* ============================================================================
   Test Chat Interface
   ============================================================================ */

.test-chat-container {
    display: flex;
    flex-direction: column;
    height: 500px;
}

.test-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 8px;
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Note: Main message layout defined below at line 1484 with avatars */

.message-content {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    line-height: 1.6;
    word-wrap: break-word;
}

.message--user .message-content {
    background: #667eea;
    color: white;
}

.message--bot .message-content {
    background: white;
    border: 1px solid #e2e8f0;
    color: #1e293b;
}

.message--error .message-content {
    background: #fee2e2;
    border-color: #fecaca;
    color: #991b1b;
}

.message-sources {
    max-width: 75%;
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

.message-sources details {
    background: white;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.message-sources summary {
    cursor: pointer;
    font-weight: 500;
    color: #64748b;
}

.source-item {
    padding: 0.5rem;
    margin-top: 0.5rem;
    background: #f8fafc;
    border-radius: 6px;
    font-size: 0.875rem;
}

.message-meta {
    max-width: 75%;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: #94a3b8;
}

.typing-indicator {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.test-chat-input {
    display: flex;
    gap: 0.75rem;
}

.test-chat-input input {
    flex: 1;
}

/* ============================================================================
   Analytics Dashboard
   ============================================================================ */

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.analytics-card {
    text-align: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
}

.analytics-card__value {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.analytics-card__label {
    font-size: 0.875rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.usage-by-source,
.top-questions {
    margin-top: 2rem;
}

.usage-by-source h4,
.top-questions h4 {
    margin: 0 0 1rem 0;
    color: #1e293b;
}

.source-stats {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.source-stat {
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.source-name {
    text-transform: capitalize;
    font-weight: 600;
    color: #475569;
    margin-right: 0.5rem;
}

.source-count {
    color: #667eea;
    font-weight: 600;
}

.questions-list {
    margin: 0;
    padding: 0 0 0 1.5rem;
}

.questions-list li {
    padding: 0.75rem;
    margin: 0.5rem 0;
    background: #f8fafc;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.question-text {
    flex: 1;
}

.question-count {
    color: #667eea;
    font-weight: 700;
    font-size: 0.875rem;
}

.no-data {
    text-align: center;
    padding: 2rem;
    color: #94a3b8;
    font-style: italic;
}

/* ============================================================================
   Forms
   ============================================================================ */

.chatbot-config-form .form-group {
    margin-bottom: 1.5rem;
}

.chatbot-config-form label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #475569;
}

.chatbot-config-form small {
    color: #64748b;
    font-size: 0.875rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: normal !important;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* Link Generator */

.url-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 1.5rem 0;
}

.url-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.url-item label {
    min-width: 120px;
    font-weight: 600;
    color: #475569;
}

.embed-code {
    margin-top: 1.5rem;
}

.embed-code label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #475569;
}

.embed-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.875rem;
    resize: vertical;
}

/* ============================================================================
   Toggle Switch
   ============================================================================ */

.toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle__slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: 0.3s;
    border-radius: 26px;
}

.toggle__slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle input:checked + .toggle__slider {
    background-color: #667eea;
}

.toggle input:checked + .toggle__slider:before {
    transform: translateX(24px);
}

/* ============================================================================
   Empty States
   ============================================================================ */

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
}

.empty-state__icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.empty-state h3 {
    margin: 0 0 0.5rem 0;
    color: #1e293b;
}

.empty-state p {
    color: #64748b;
    max-width: 400px;
    margin: 0 auto;
}

/* ============================================================================
   Loading States
   ============================================================================ */

.loading-placeholder {
    text-align: center;
    padding: 3rem;
    color: #64748b;
    font-style: italic;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    color: white;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    margin-top: 1rem;
    font-size: 1.125rem;
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.btn-outline {
    background: white;
    border: 2px solid #667eea;
    color: #667eea;
}

.btn-outline:hover {
    background: #667eea;
    color: white;
}

/* ============================================================================
   Enhanced Source Citations & Markdown Rendering
   ============================================================================ */

.message-sources {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: #f0fdf4;
    border: 1px solid #86efac;
    border-radius: 6px;
}

.message-sources details {
    cursor: pointer;
}

.message-sources summary {
    font-weight: 600;
    color: #166534;
    padding: 0.25rem;
    user-select: none;
    list-style: none;
}

.message-sources summary::-webkit-details-marker {
    display: none;
}

.message-sources summary::before {
    content: '▶ ';
    display: inline-block;
    transition: transform 0.2s;
}

.message-sources details[open] summary::before {
    transform: rotate(90deg);
}

.source-item {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: white;
    border-left: 3px solid #22c55e;
    border-radius: 4px;
}

.source-badge {
    display: inline-block;
    background: #22c55e;
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-right: 0.5rem;
    margin-bottom: 0.25rem;
}

.source-excerpt {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #f9fafb;
    border-radius: 4px;
    font-size: 0.875rem;
    color: #4b5563;
    font-style: italic;
}

.message-warning {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: 6px;
    color: #92400e;
    font-size: 0.875rem;
}

/* Markdown rendering in messages */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin-top: 0.75rem;
    margin-bottom: 0.5rem;
    color: #1e293b;
}

.message-content h1 { font-size: 1.5rem; }
.message-content h2 { font-size: 1.25rem; }
.message-content h3 { font-size: 1.1rem; }

.message-content strong {
    font-weight: 600;
    color: #0f172a;
}

.message-content code {
    background: #f1f5f9;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.875em;
    color: #dc2626;
}

.message-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.75rem 0;
}

.message-content pre code {
    background: none;
    color: inherit;
    padding: 0;
}

.message-content ul,
.message-content ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}

.message-content li {
    margin: 0.25rem 0;
}

.message-content a {
    color: #2563eb;
    text-decoration: underline;
}

.message-content a:hover {
    color: #1d4ed8;
}

.message-content p {
    margin: 0.5rem 0;
}

.message-content p:first-child {
    margin-top: 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* ============================================================================
   Button Styles for RAG and Chatbot Tabs
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Button Sizes */
.btn-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
}

/* Button Variants */
.btn-primary {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border-color: #2563eb;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
    background: white;
    color: #64748b;
    border-color: #e2e8f0;
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #475569;
}

.btn-info {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    color: white;
    border-color: #0284c7;
}

.btn-info:hover {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.btn-warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    border-color: #d97706;
}

.btn-warning:hover {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border-color: #dc2626;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-outline {
    background: transparent;
    color: #3b82f6;
    border-color: #3b82f6;
}

.btn-outline:hover {
    background: #3b82f6;
    color: white;
}

/* Button Groups/Actions */
.kb-tab-actions,
.chatbot-tab-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Card Action Buttons */
.kb-card__actions,
.chatbot-card__actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

/* Specific Button Icons */
.btn::before {
    display: inline-block;
}

/* Make emoji icons in buttons slightly larger and better spaced */
.btn svg {
    width: 16px;
    height: 16px;
}

/* Button hover effects with specific colors */
.btn-primary:active {
    background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
}

.btn-secondary:active {
    background: #f1f5f9;
}

.btn-info:active {
    background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
}

.btn-warning:active {
    background: linear-gradient(135deg, #b45309 0%, #92400e 100%);
}

.btn-danger:active {
    background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%);
}

/* Button focus states for accessibility */
.btn:focus {
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.btn-danger:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3);
}

.btn-warning:focus {
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
}

/* Header action buttons - make them more prominent */
.kb-tab-actions .btn-primary,
.chatbot-tab-actions .btn-primary {
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    font-size: 0.9375rem;
}

/* Make icon emojis consistent size */
.btn::first-line {
    font-size: 1em;
}

/* Loading state for buttons */
.btn.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: button-spin 0.6s linear infinite;
    inset: 50% auto auto 50%;
    margin: -8px 0 0 -8px;
}

@keyframes button-spin {
    to { transform: rotate(360deg); }
}

/* Button groups in cards */
.kb-card__actions .btn,
.chatbot-card__actions .btn {
    flex: 1;
    min-width: fit-content;
}

/* Specific button enhancements */
.kb-card__actions .btn-danger,
.chatbot-card__actions .btn-danger {
    margin-left: auto; /* Push delete button to the right */
}

/* Responsive buttons */
@media (max-width: 768px) {
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.8125rem;
    }
    
    .kb-tab-actions,
    .chatbot-tab-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .kb-tab-actions .btn,
    .chatbot-tab-actions .btn {
        width: 100%;
    }
}

/* ============================================================================
   Configure Modal Form Styling
   ============================================================================ */

.chatbot-config-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 600;
    font-size: 0.875rem;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-group label small {
    font-weight: 400;
    color: #64748b;
    font-size: 0.75rem;
}

.form-control {
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: #1e293b;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    transition: all 0.2s ease;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-control:hover:not(:focus) {
    border-color: #94a3b8;
}

.form-control::placeholder {
    color: #94a3b8;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
    font-family: 'Courier New', monospace;
    font-size: 0.8125rem;
}

select.form-control {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

input[type="number"].form-control {
    max-width: 150px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 640px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.form-group small {
    color: #64748b;
    font-size: 0.75rem;
    margin-top: -0.25rem;
}

/* Form validation states */
.form-control:invalid {
    border-color: #ef4444;
}

.form-control:invalid:focus {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-control:valid {
    border-color: #cbd5e1;
}

/* Checkbox and toggle styles */
.form-checkbox {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #f8fafc;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.form-checkbox:hover {
    background: #f1f5f9;
}

.form-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Help text and hints */
.form-hint {
    display: block;
    color: #64748b;
    font-size: 0.75rem;
    font-style: italic;
    margin-top: 0.25rem;
}

/* Modal form actions (at bottom of modal) */
.modal__actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding-top: 1.5rem;
    border-top: 1px solid #e2e8f0;
    margin-top: 1.5rem;
}

.modal__actions .btn {
    min-width: 120px;
}

/* Divider between form sections */
.form-divider {
    height: 1px;
    background: linear-gradient(to right, transparent, #e2e8f0, transparent);
    margin: 1.5rem 0;
}

/* Form section headers */
.form-section-header {
    font-weight: 600;
    color: #475569;
    font-size: 0.9375rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e2e8f0;
}

/* ============================================================================
   Chat Message Avatars
   ============================================================================ */

.message {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.message-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.message-avatar--bot {
    background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
    padding: 6px;
    box-shadow: 0 2px 8px rgba(168, 85, 247, 0.3);
}

.message-avatar--bot img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

.message-avatar--user {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.message-avatar--user svg {
    width: 20px;
    height: 20px;
    color: white;
}

/* Message layout adjustments with avatars */
.message--user {
    flex-direction: row-reverse;
}

.message--user .message-content {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    margin-left: 0;
    margin-right: 0;
}

/* Bot messages need a wrapper for content + sources + metadata */
.message--bot {
    align-items: flex-start;
}

.message-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: calc(100% - 48px); /* Account for avatar width */
}

.message--bot .message-content {
    background: #faf5ff;
    border: 1px solid #e9d5ff;
    color: #1e293b;
    padding: 1rem;
    border-radius: 12px;
}

.message-content {
    max-width: 100%;
}

/* Adjust message sources and metadata to work with avatar layout */
.message--bot .message-sources,
.message--bot .message-meta {
    margin-left: 0;
}

/* Ensure message wrapping container allows avatars */
.test-chat-messages .message:first-child {
    margin-top: 0;
}

/* ============================================================================
   Markdown Table Styling in Chat Messages
   ============================================================================ */

.message-content table.markdown-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.875rem;
    background: white;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message-content table.markdown-table thead {
    background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
    color: white;
}

.message-content table.markdown-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.message-content table.markdown-table td {
    padding: 0.75rem 1rem;
    border-top: 1px solid #e2e8f0;
    color: #1e293b;
    line-height: 1.6;
}

.message-content table.markdown-table tbody tr:hover {
    background: #faf5ff;
}

.message-content table.markdown-table tbody tr:nth-child(even) {
    background: #f8fafc;
}

.message-content table.markdown-table tbody tr:nth-child(even):hover {
    background: #faf5ff;
}

/* Ensure table doesn't overflow on mobile */
@media (max-width: 640px) {
    .message-content table.markdown-table {
        font-size: 0.75rem;
    }

    .message-content table.markdown-table th,
    .message-content table.markdown-table td {
        padding: 0.5rem 0.75rem;
    }
}

/* Table inside user messages (blue theme) */
.message--user .message-content table.markdown-table thead {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
}
