/* ==========================================================================
   HPU2 CLOUDFLARE FRONTEND - MODERN STYLESHEET (V2.3 ELEGANT LIGHT THEME)
   - Giao diện mặc định là SÁNG (Light Theme) cao cấp, hiện đại, sắc nét
   - Hỗ trợ Dark Theme khi bật công tắc
   - Thiết kế bong bóng chat User & Bot đẹp mắt, tinh tế
   - Tách riêng Tab Trò Chuyện AI và Tab Chat RAG
   - Đẩy bộ chọn mô hình và thanh điều khiển xuống đáy khung chat
   ========================================================================== */

:root {
    --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', Consolas, Monaco, monospace;

    /* ==========================================================================
       LIGHT THEME (MẶC ĐỊNH) - Tươi sáng, tinh tế, độ tương phản cao, phong cách Apple / Stripe
       ========================================================================== */
    --bg-base: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f1f5f9;
    --bg-surface-hover: #e2e8f0;
    --border-color: #e2e8f0;
    --border-color-focus: #4f46e5;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: rgba(79, 70, 229, 0.08);

    --accent: #0284c7;
    --accent-hover: #0369a1;
    --accent-light: rgba(2, 132, 199, 0.08);

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.06), 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.03);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 9999px;
}

/* ==========================================================================
   DARK THEME (TÙY CHỌN BẬT / TẮT)
   ========================================================================== */
body.dark-theme {
    --bg-base: #0b0f19;
    --bg-surface: #111827;
    --bg-surface-elevated: #1f2937;
    --bg-surface-hover: #374151;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-focus: rgba(99, 102, 241, 0.5);

    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.15);

    --accent: #06b6d4;
    --accent-hover: #0891b2;
    --accent-light: rgba(6, 182, 212, 0.15);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
}

/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
    transition: background-color 0.25s ease, color 0.25s ease;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

/* Toàn bộ thanh cuộn trong trang: siêu mảnh (5px), ẩn tự nhiên và hiện khi hover */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 10px;
    transition: background 0.2s ease;
}

*:hover::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.35);
}

*::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.65);
}

body.dark-theme *:hover::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.18);
}

body.dark-theme *::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.38);
}

.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ==========================================================================
   TOP NAVIGATION
   ========================================================================== */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 1.25rem;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 100;
    gap: 0.75rem;
    min-height: 56px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-shrink: 0;
}

.brand-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    border-radius: var(--radius-md);
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.2);
    flex-shrink: 0;
}

.brand-logo svg {
    width: 19px;
    height: 19px;
}

.brand-info h1 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    line-height: 1.2;
    white-space: nowrap;
}

.brand-subtitle {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 500;
    display: block;
    line-height: 1.2;
    white-space: nowrap;
}

/* Navigation Tabs: Tối ưu thanh hiển thị thoáng đãng, hiện đại */
.nav-tabs {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background-color: var(--bg-surface-elevated);
    padding: 4px 6px;
    border-radius: 9999px;
    border: 1.5px solid var(--border-color);
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    flex-shrink: 1;
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.38rem;
    padding: 0.38rem 0.82rem;
    font-family: var(--font-main);
    font-size: 0.8125rem;
    font-weight: 550;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    line-height: 1.35;
    transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
}

.tab-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    opacity: 0.82;
    transition: transform 0.16s ease, opacity 0.16s ease;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.05);
    border-radius: 9999px;
}

.tab-btn:hover svg {
    opacity: 1;
    transform: translateY(-0.5px);
}

body.dark-theme .tab-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.tab-btn.active {
    background-color: var(--primary);
    color: #ffffff;
    font-weight: 600;
    border-radius: 9999px;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.32);
}

.tab-btn.active svg {
    opacity: 1;
    stroke-width: 2.2;
}

body.dark-theme .tab-btn.active {
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.38);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

#header-admin-models-btn {
    display: none !important;
}

.icon-btn {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* User Header & Auth Widget */
.user-header-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logged-in-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-surface-elevated);
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.user-display-name {
    font-weight: 600;
    font-size: 0.84rem;
    color: var(--text-primary);
}

.user-role-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
}

.user-role-badge.admin-badge {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.user-role-badge.user-badge {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid rgba(79, 70, 229, 0.25);
}

.auth-buttons-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.5rem 1rem;
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-surface-elevated);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-surface-hover);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    border-radius: 6px;
}

.btn-xs {
    padding: 0.2rem 0.5rem;
    font-size: 0.72rem;
    border-radius: 4px;
}

.btn-block {
    width: 100%;
}

/* ==========================================================================
   MAIN CONTAINER & TABS
   ========================================================================== */
.main-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background-color: var(--bg-base);
    min-width: 0;
    width: 100%;
}

.tab-content {
    display: none;
    height: 100%;
    width: 100%;
    min-width: 0;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#tab-office {
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    min-width: 0;
    width: 100%;
}

/* ==========================================================================
   TAB 1: TRÒ CHUYỆN AI TRỰC TIẾP (DIRECT CHAT)
   ========================================================================== */
.direct-chat-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 920px;
    margin: 0 auto;
    width: 100%;
    position: relative;
}

/* Hero Greeting Card */
.chat-hero-card {
    text-align: center;
    margin: 1.5rem auto 1rem;
    max-width: 680px;
    padding: 1rem 1.25rem;
}

.hero-icon {
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
    animation: floatIcon 3s ease-in-out infinite;
}

@keyframes floatIcon {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.chat-hero-card h2 {
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    margin-bottom: 0.35rem;
    color: var(--text-primary);
}

.chat-hero-card p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin-bottom: 1.15rem;
}

.hero-prompt-suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.65rem;
    text-align: left;
}

.prompt-chip {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.6rem 0.85rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    box-shadow: var(--shadow-sm);
    font-family: inherit;
}

.prompt-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ==========================================================================
   BONG BÓNG TIN NHẮN (CHAT BUBBLES - COMPACT, ELEGANT & REFINED)
   ========================================================================== */
.messages-container {
    flex: 1 1 0%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    min-width: 0;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
    transition: scrollbar-color 0.25s ease;
}

.messages-container:hover {
    scrollbar-color: rgba(148, 163, 184, 0.4) transparent;
}

body.dark-theme .messages-container:hover {
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* Thanh cuộn tinh tế, siêu mỏng (5px), ẩn tự nhiên và hiện mềm mại khi hover */
.messages-container::-webkit-scrollbar,
.collections-checkbox-list::-webkit-scrollbar,
.chat-sidebar::-webkit-scrollbar,
.documents-table-wrap::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.markdown-preview::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

.messages-container::-webkit-scrollbar-track,
.collections-checkbox-list::-webkit-scrollbar-track,
.chat-sidebar::-webkit-scrollbar-track,
.documents-table-wrap::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track,
.markdown-preview::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb,
.collections-checkbox-list::-webkit-scrollbar-thumb,
.chat-sidebar::-webkit-scrollbar-thumb,
.documents-table-wrap::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.markdown-preview::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 10px;
    transition: background 0.25s ease;
}

.messages-container:hover::-webkit-scrollbar-thumb,
.collections-checkbox-list:hover::-webkit-scrollbar-thumb,
.chat-sidebar:hover::-webkit-scrollbar-thumb,
.documents-table-wrap:hover::-webkit-scrollbar-thumb,
.modal-body:hover::-webkit-scrollbar-thumb,
.markdown-preview:hover::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.38);
}

.messages-container::-webkit-scrollbar-thumb:hover,
.collections-checkbox-list::-webkit-scrollbar-thumb:hover,
.chat-sidebar::-webkit-scrollbar-thumb:hover,
.documents-table-wrap::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover,
.markdown-preview::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.65);
}

body.dark-theme .messages-container:hover::-webkit-scrollbar-thumb,
body.dark-theme .collections-checkbox-list:hover::-webkit-scrollbar-thumb,
body.dark-theme .chat-sidebar:hover::-webkit-scrollbar-thumb,
body.dark-theme .documents-table-wrap:hover::-webkit-scrollbar-thumb,
body.dark-theme .modal-body:hover::-webkit-scrollbar-thumb,
body.dark-theme .markdown-preview:hover::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.18);
}

body.dark-theme .messages-container::-webkit-scrollbar-thumb:hover,
body.dark-theme .collections-checkbox-list::-webkit-scrollbar-thumb:hover,
body.dark-theme .chat-sidebar::-webkit-scrollbar-thumb:hover,
body.dark-theme .documents-table-wrap::-webkit-scrollbar-thumb:hover,
body.dark-theme .modal-body::-webkit-scrollbar-thumb:hover,
body.dark-theme .markdown-preview::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

.message {
    display: flex;
    gap: 0.6rem;
    max-width: min(88%, 920px);
    min-width: 0;
    width: fit-content;
    animation: fadeInMsg 0.2s ease-out;
    box-sizing: border-box;
}

@keyframes fadeInMsg {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* User Message */
.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.user .message-content {
    align-items: flex-end;
}

.message.user .message-sender-title {
    text-align: right;
    justify-content: flex-end;
}

.message.user .content {
    background: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%);
    color: #ffffff;
    padding: 0.55rem 0.9rem;
    border-radius: 15px 15px 3px 15px;
    box-shadow: 0 2px 7px rgba(79, 70, 229, 0.16);
    font-size: 0.91rem;
    line-height: 1.55;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    box-sizing: border-box;
}

body.dark-theme .message.user .content {
    background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
    box-shadow: 0 3px 12px rgba(99, 102, 241, 0.28);
}

/* Bot Message */
.message.bot {
    align-self: flex-start;
}

.message.bot .message-content {
    align-items: flex-start;
}

.message.bot .content {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.65rem 1rem;
    border-radius: 15px 15px 15px 3px;
    box-shadow: var(--shadow-sm);
    font-size: 0.91rem;
    line-height: 1.6;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    box-sizing: border-box;
}

body.dark-theme .message.bot .content {
    background: #111827;
    border-color: rgba(255, 255, 255, 0.08);
}

/* Typography chuẩn hóa trong bong bóng chat (Loại bỏ khoảng trắng thừa) */
.content p {
    margin: 0.25rem 0;
    line-height: 1.55;
}

.content p:first-child {
    margin-top: 0;
}

.content p:last-child {
    margin-bottom: 0;
}

.content ul,
.content ol {
    margin: 0.25rem 0;
    padding-left: 1.25rem;
}

.content li {
    margin-bottom: 0.12rem;
    line-height: 1.5;
}

.content li:last-child {
    margin-bottom: 0;
}

.content h1, .content h2, .content h3, .content h4 {
    margin-top: 0.45rem;
    margin-bottom: 0.2rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text-primary);
}

.content h1:first-child, .content h2:first-child, .content h3:first-child, .content h4:first-child {
    margin-top: 0;
}

/* Inline Code */
.content code {
    font-family: 'JetBrains Mono', Consolas, 'Fira Code', monospace;
    font-size: 0.85em;
    padding: 0.12rem 0.38rem;
    border-radius: 4px;
    background: rgba(99, 102, 241, 0.08);
    color: #4338ca;
    font-weight: 500;
    word-break: break-word;
}

.message.user .content code {
    background: rgba(255, 255, 255, 0.22);
    color: #ffffff;
}

body.dark-theme .content code {
    background: rgba(129, 140, 248, 0.15);
    color: #c7d2fe;
}

/* Code Block Container hiện đại (ChatGPT/Claude Style) */
.code-block-wrapper {
    position: relative;
    margin: 0.45rem 0;
    border-radius: 9px;
    overflow: hidden;
    background: #181825;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.75rem;
    background: #11111b;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.72rem;
    color: #a6adc8;
    user-select: none;
}

.code-lang-badge {
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #89b4fa;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.code-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #cdd6f4;
    padding: 0.18rem 0.55rem;
    border-radius: 5px;
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    line-height: 1.2;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.25);
}

.code-copy-btn.copied {
    background: #059669 !important;
    border-color: #059669 !important;
    color: #ffffff !important;
}

.content pre {
    margin: 0;
    padding: 0.75rem 0.95rem;
    background: transparent;
    color: #cdd6f4;
    overflow-x: auto;
    font-family: 'JetBrains Mono', Consolas, 'Fira Code', monospace;
    font-size: 0.84rem;
    line-height: 1.55;
    max-width: 100%;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.content pre::-webkit-scrollbar {
    height: 5px;
}
.content pre::-webkit-scrollbar-track {
    background: transparent;
}
.content pre::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}
.content pre::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

.content pre code {
    background: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
    color: inherit !important;
    font-size: inherit !important;
    box-shadow: none !important;
    border: none !important;
    font-family: inherit;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
}

.content blockquote {
    margin: 0.3rem 0;
    padding: 0.25rem 0.75rem;
    border-left: 3px solid var(--primary);
    background: rgba(79, 70, 229, 0.05);
    border-radius: 0 6px 6px 0;
    color: var(--text-secondary);
}

/* Responsive Tables */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    margin: 0.45rem 0;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    scrollbar-width: thin;
    box-sizing: border-box;
}

.table-responsive::-webkit-scrollbar {
    height: 5px;
}
.table-responsive::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.35);
    border-radius: 3px;
}

.content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 0.84rem;
}

.content th,
.content td {
    padding: 0.42rem 0.65rem;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    text-align: left;
}

.content tr:last-child td {
    border-bottom: none;
}

.content tr td:last-child,
.content tr th:last-child {
    border-right: none;
}

.content th {
    background: var(--bg-surface-elevated);
    font-weight: 600;
    color: var(--text-primary);
}

/* LaTeX Math Container & Delimiters */
.katex-display {
    margin: 0.45rem 0 !important;
    padding: 0.45rem 0.65rem !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    max-width: 100% !important;
    text-align: center;
    background: rgba(79, 70, 229, 0.03);
    border-radius: 8px;
    border: 1px solid rgba(79, 70, 229, 0.08);
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.4) transparent;
    box-sizing: border-box;
}

body.dark-theme .katex-display {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.07);
}

.katex-display::-webkit-scrollbar {
    height: 4px;
}
.katex-display::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.4);
    border-radius: 3px;
}

.katex {
    font-size: 1.05em;
    line-height: 1.2;
}

/* Avatars */
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    font-weight: 700;
    font-size: 0.76rem;
}

.avatar.user-avatar {
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: #ffffff;
    font-size: 0.76rem;
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.25);
}

.avatar.bot-avatar {
    background: linear-gradient(135deg, #0284c7, #4f46e5);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.25);
}

.avatar.bot-avatar svg {
    width: 17px;
    height: 17px;
}

/* Sender Headers */
.message-content {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    max-width: 100%;
}

.message-sender-title {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.73rem;
    color: var(--text-muted);
    margin-bottom: 0.1rem;
}

.sender-name {
    font-weight: 600;
    color: var(--text-secondary);
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.75;
}

.sender-badge {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 8px;
}

.sender-badge.rag {
    background: rgba(14, 165, 233, 0.12);
    color: #0284c7;
    border: 1px solid rgba(14, 165, 233, 0.25);
}

.sender-badge.direct {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

/* Typing indicator dots */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background-color: var(--primary);
    border-radius: 50%;
    animation: typingBounce 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 typingBounce {
    0%, 80%, 100% { transform: scale(0.3); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Citations & Multimodal in Chat */
.citation-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--primary);
    padding: 0.25rem 0.65rem;
    border-radius: 14px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 0.4rem;
}

.citation-badge:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.multimodal-chat-images {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}

.chat-thumb-img {
    width: 140px;
    height: 95px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    background: #ffffff;
}

.chat-thumb-img:hover {
    transform: scale(1.04);
    border-color: var(--primary);
}

/* ==========================================================================
   BOTTOM CHAT DOCK (ĐẨY BỘ CHỌN MÔ HÌNH VÀ CONTROLS XUỐNG DƯỚI)
   ========================================================================== */
.chat-bottom-dock {
    padding: 0.85rem 1.5rem 1.25rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.03);
    z-index: 50;
    flex-shrink: 0;
}

.dock-controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
    flex-wrap: wrap;
}

/* Bộ chọn mô hình: Thiết kế Capsule Bo Tròn Cao Cấp */
.dock-model-picker {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-surface-elevated);
    border: 1.5px solid var(--border-color);
    border-radius: 9999px;
    padding: 2px 6px 2px 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.dock-model-picker:hover {
    border-color: rgba(79, 70, 229, 0.45);
    background: var(--bg-surface);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.1);
}

.dock-model-picker:focus-within {
    border-color: var(--primary);
    background: var(--bg-surface);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.16);
}

.dock-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    user-select: none;
}

.dock-select {
    appearance: none;
    -webkit-appearance: none;
    background-color: transparent;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    border: none;
    border-radius: 9999px;
    padding: 0.35rem 1.8rem 0.35rem 0.3rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
    font-family: inherit;
    transition: all 0.15s ease;
    max-width: 320px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dock-select option {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    padding: 8px 12px;
    font-size: 0.85rem;
}

.custom-select {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--bg-surface-elevated);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    border: 1.5px solid var(--border-color);
    border-radius: 9999px;
    padding: 0.4rem 2.2rem 0.4rem 1rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
    font-family: inherit;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.custom-select:hover {
    border-color: rgba(79, 70, 229, 0.4);
    background-color: var(--bg-surface);
}

.custom-select:focus {
    border-color: var(--primary);
    background-color: var(--bg-surface);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}

.custom-select option {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    padding: 8px 12px;
}

body.dark-theme .dock-model-picker {
    background: #1e293b;
    border-color: #334155;
}

body.dark-theme .dock-model-picker:hover {
    border-color: #6366f1;
    background: #0f172a;
}

body.dark-theme .dock-model-picker:focus-within {
    border-color: #6366f1;
    background: #0f172a;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

body.dark-theme .dock-select,
body.dark-theme .custom-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    color: #f1f5f9;
}

body.dark-theme .dock-select option,
body.dark-theme .custom-select option {
    background-color: #1e293b;
    color: #f1f5f9;
}

.dock-actions-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dock-rag-modes {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.pill-radio {
    display: inline-flex;
    align-items: center;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.32rem 0.85rem;
    border-radius: 9999px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.pill-radio:hover {
    border-color: rgba(79, 70, 229, 0.35);
    background: var(--bg-surface);
    color: var(--text-primary);
}

.pill-radio input {
    display: none;
}

.pill-radio:has(input:checked) {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 1px 4px rgba(79, 70, 229, 0.18);
}

.dock-tool-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
    margin-bottom: 1px;
}

.dock-tool-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--primary);
    transform: scale(1.08);
}

.attached-images-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.75rem;
    background: var(--bg-surface-elevated);
    border: 1.5px dashed var(--border-color);
    border-radius: 14px;
    margin-bottom: 0.5rem;
    overflow-x: auto;
}

.attached-thumb-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.25rem 0.45rem;
    max-width: 200px;
    flex-shrink: 0;
}

.attached-thumb-wrap img {
    width: 34px;
    height: 34px;
    object-fit: cover;
    border-radius: 6px;
}

.attached-thumb-wrap .attach-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 110px;
}

.attached-thumb-wrap .remove-attach-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ef4444;
    color: #ffffff;
    border: 1.5px solid #ffffff;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    transition: transform 0.15s;
}

.attached-thumb-wrap .remove-attach-btn:hover {
    transform: scale(1.15);
}

/* Attached File Pill in Dock Preview */
.attached-file-pill {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.35rem 0.65rem;
    max-width: 260px;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.attached-file-pill:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.attached-file-pill.loading {
    opacity: 0.8;
    background: var(--bg-surface-elevated);
    border-style: dashed;
}

.attached-file-pill .file-icon-badge {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.attached-file-pill .file-info-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.attached-file-pill .file-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.attached-file-pill .file-meta {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.attached-file-pill .remove-attach-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ef4444;
    color: #ffffff;
    border: 1.5px solid #ffffff;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    transition: transform 0.15s;
}

.attached-file-pill .remove-attach-btn:hover {
    transform: scale(1.15);
}

.user-attached-thumbnails {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.user-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    border: 1.5px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: transform 0.15s;
}

.user-thumb:hover {
    transform: scale(1.06);
}

/* User Message Attached Files Badges */
.user-attached-files-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.45rem;
}

.user-file-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    padding: 0.35rem 0.65rem;
    backdrop-filter: blur(4px);
    color: inherit;
    transition: transform 0.15s ease, background 0.15s ease;
}

.user-file-badge:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.22);
}

.user-file-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #ffffff;
}

.user-file-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.user-file-name {
    font-size: 0.8rem;
    font-weight: 600;
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-file-meta {
    font-size: 0.68rem;
    opacity: 0.85;
}

/* Drag over style on dock textarea */
.dock-input-wrapper textarea.drag-over {
    border-color: var(--primary) !important;
    background: var(--primary-light) !important;
}

.dock-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
    background: var(--bg-surface-elevated);
    border: 1.5px solid var(--border-color);
    border-radius: 24px;
    padding: 0.4rem 0.5rem 0.4rem 1.15rem;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

.dock-input-wrapper:focus-within {
    border-color: var(--primary);
    background: var(--bg-surface);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.dock-input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 0.94rem;
    color: var(--text-primary);
    padding: 0.4rem 0;
    resize: none;
    max-height: 180px;
    line-height: 1.5;
}

.dock-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background-color 0.15s;
    flex-shrink: 0;
}

.dock-send-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.dock-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ==========================================================================
   TAB 2: CHAT RAG CONTAINER & SIDEBAR
   ========================================================================== */
.chat-container {
    display: flex;
    height: 100%;
    overflow: hidden;
}

.chat-sidebar {
    width: 340px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    gap: 1.25rem;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: var(--bg-base);
}

/* Collection Selector */
.config-group {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.collection-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.label-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
}

.collection-quick-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.text-link-btn {
    background: transparent;
    border: none;
    font-size: 0.74rem;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    padding: 2px 4px;
}

.text-link-btn:hover {
    text-decoration: underline;
}

.sep {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.search-input-wrap {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: var(--bg-surface-elevated);
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    padding: 0.45rem 0.75rem;
    transition: all 0.2s ease;
}

.search-input-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.search-input-wrap input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.84rem;
    color: var(--text-primary);
    font-family: inherit;
}

#collection-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.collections-checkbox-list {
    flex: 1;
    min-height: 280px;
    max-height: calc(100vh - 420px);
    overflow-y: auto;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    padding: 0.45rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    background: var(--bg-surface);
}

.doc-check-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    font-size: 0.83rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.doc-check-item:hover {
    background: var(--bg-surface-hover);
    border-color: rgba(79, 70, 229, 0.35);
    transform: translateY(-1px);
}

.doc-check-item label {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    cursor: pointer;
    flex: 1;
    overflow: hidden;
}

.doc-check-item input[type="checkbox"],
.custom-table input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--border-color);
    border-radius: 6px;
    outline: none;
    cursor: pointer;
    background: var(--bg-surface);
    display: inline-grid;
    place-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.doc-check-item input[type="checkbox"]:checked,
.custom-table input[type="checkbox"]:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

.doc-check-item input[type="checkbox"]:checked::before,
.custom-table input[type="checkbox"]:checked::before {
    content: "";
    width: 8px;
    height: 4.5px;
    border-left: 2px solid #ffffff;
    border-bottom: 2px solid #ffffff;
    transform: rotate(-45deg) translate(1px, -1px);
}

.doc-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.doc-badge-sm {
    font-size: 0.68rem;
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-muted);
    font-weight: 600;
}

body.dark-theme .doc-badge-sm {
    background: rgba(255, 255, 255, 0.08);
}

.selected-docs-summary {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.65rem;
    background: var(--bg-surface-elevated);
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border-color);
}

.summary-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.selected-docs-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.selected-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid rgba(79, 70, 229, 0.25);
    padding: 2px 7px;
    border-radius: 12px;
    font-size: 0.74rem;
    font-weight: 600;
}

.selected-chip .remove-chip {
    cursor: pointer;
    font-weight: bold;
    font-size: 0.85rem;
}

.selected-chip .remove-chip:hover {
    color: var(--danger);
}

.reranker-slider-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    background: var(--bg-surface-elevated);
    padding: 0.65rem;
    border-radius: var(--radius-sm);
}

.slider-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
}

.custom-slider {
    width: 100%;
    cursor: pointer;
    accent-color: var(--primary);
}

/* System Stats */
.system-stats {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    font-size: 0.74rem;
    color: var(--text-muted);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.dot.green {
    background-color: var(--success);
    box-shadow: 0 0 6px var(--success);
}

/* ==========================================================================
   TAB 3: OCR & CÔNG THỨC TOÁN
   ========================================================================== */
.ocr-container {
    display: flex;
    height: 100%;
    overflow: hidden;
}

.ocr-left-panel {
    width: 420px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto;
}

.ocr-left-panel h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.subtitle {
    font-size: 0.84rem;
    color: var(--text-muted);
}

.dropzone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-surface-elevated);
}

.dropzone:hover, .dropzone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}

.dropzone-content svg {
    color: var(--primary);
    margin-bottom: 0.75rem;
}

.dropzone-content h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.dropzone-content p {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.file-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.file-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.file-name {
    font-size: 0.88rem;
    font-weight: 600;
}

.file-size {
    font-size: 0.74rem;
    color: var(--text-muted);
}

.ocr-progress {
    text-align: center;
    padding: 1.5rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(79, 70, 229, 0.2);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 0.75rem;
}

.ocr-right-panel {
    flex: 1;
    background: var(--bg-base);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.results-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.subtabs-nav {
    display: flex;
    gap: 0.5rem;
    padding: 0.65rem 1.5rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
}

.subtab-btn {
    padding: 0.38rem 0.95rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.16s ease;
}

.subtab-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
}

.subtab-btn.active {
    background: var(--primary-light);
    color: var(--primary);
    box-shadow: 0 1px 4px rgba(79, 70, 229, 0.15);
}

.subtab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.subtab-content.active {
    display: block;
}

/* ==========================================================================
   OCR STUDIO & FORMULA EXTRACTOR STYLES (ENHANCED)
   ========================================================================== */
.ocr-config-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 1px 4px rgba(0,0,0,0.03);
}

.radio-pill-group .radio-pill:hover {
    border-color: var(--primary) !important;
}
.radio-pill-group .radio-pill input:checked + span {
    color: var(--primary);
    font-weight: 700;
}

/* Formula Comparison Card (Image Crop vs LaTeX) */
.formula-split-card {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.25rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.03);
    align-items: center;
}

@media (max-width: 900px) {
    .formula-split-card {
        grid-template-columns: 1fr;
    }
}

.formula-crop-col {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem;
    text-align: center;
    overflow: hidden;
}

.formula-crop-col img {
    max-width: 100%;
    max-height: 140px;
    object-fit: contain;
    border-radius: 4px;
    display: block;
    margin: 0 auto;
}

.formula-badge-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
    padding: 0 0.2rem;
}

.formula-code-col {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    min-width: 0;
}

.formula-latex-raw {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.6rem 0.85rem;
    overflow-x: auto;
}

.formula-latex-raw code {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: #e11d48;
    white-space: pre-wrap;
    word-break: break-all;
}

.formula-render {
    background: var(--bg-surface);
    border: 1px dashed var(--border-color);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    font-size: 1.1rem;
    overflow-x: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
}

/* Figures Gallery Grid */
.figures-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.25rem;
}

.figure-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,0.03);
    display: flex;
    flex-direction: column;
}

.figure-img-wrap {
    padding: 0.75rem;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
}

.figure-img-wrap img {
    max-width: 100%;
    max-height: 220px;
    object-fit: contain;
}

.figure-info-footer {
    padding: 0.65rem 0.85rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.78rem;
    font-weight: 600;
}

/* Layout Pages Container */
.layout-pages-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.page-annotated-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.page-annotated-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: var(--bg-surface-elevated);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.88rem;
    font-weight: 700;
}

.page-annotated-body {
    padding: 1rem;
    background: #f1f5f9;
    text-align: center;
    overflow-x: auto;
}

.page-annotated-body img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.markdown-preview {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    line-height: 1.75;
}

/* ==========================================================================
   TAB 4: KHO & QUẢN LÝ TÀI LIỆU
   ========================================================================== */
.docs-container {
    display: flex;
    height: 100%;
    overflow: hidden;
}

.docs-list-panel {
    flex: 3;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.documents-table-wrap {
    flex: 1;
    overflow-y: auto;
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    text-align: left;
}

.custom-table th {
    background: var(--bg-surface-elevated);
    padding: 0.75rem 1rem;
    font-weight: 700;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

.custom-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

.custom-table tr:hover {
    background: var(--bg-surface-elevated);
}

.doc-viewer-panel {
    flex: 2;
    background: var(--bg-base);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.viewer-content {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: hidden;
}

.viewer-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.88rem;
    text-align: center;
    max-width: 320px;
}

.badge-uploader {
    font-size: 0.72rem;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
}

.badge-uploader.admin {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
}

.badge-uploader.user {
    background: var(--primary-light);
    color: var(--primary);
}

.badge-uploader.system {
    background: rgba(148, 163, 184, 0.12);
    color: #64748b;
}

.badge.online {
    color: var(--primary);
    background: var(--primary-light);
    border: 1px solid rgba(79, 70, 229, 0.25);
    font-size: 0.72rem;
    padding: 2px 7px;
    border-radius: 12px;
    font-weight: 600;
}

/* ==========================================================================
   DOCUMENT TEXT READER (NEON DB CONTENT VIEWER)
   ========================================================================== */
.doc-text-reader {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.reader-meta-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 0.95rem;
    background: var(--bg-surface-elevated);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.reader-meta-tags {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.meta-tag {
    font-size: 0.72rem;
    padding: 2px 7px;
    border-radius: 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.meta-tag.col {
    color: var(--primary);
    border-color: rgba(79, 70, 229, 0.25);
    background: var(--primary-light);
    font-weight: 600;
}

.reader-tools {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.viewer-mode-toggle {
    display: flex;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 2px;
}

.toggle-mode-btn {
    border: none;
    background: transparent;
    padding: 2px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    color: var(--text-muted);
    transition: all 0.15s ease;
}

.toggle-mode-btn.active {
    background: var(--primary);
    color: #ffffff;
}

.reader-search-wrap {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.95rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
}

.reader-search-wrap input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.82rem;
    color: var(--text-primary);
    outline: none;
}

.reader-search-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.reader-body-text {
    flex: 1;
    padding: 1.25rem 1.5rem;
    overflow-y: auto;
    font-size: 0.92rem;
    line-height: 1.85;
    color: var(--text-primary);
    background: var(--bg-surface);
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--font-main);
}

.reader-body-text mark {
    background: rgba(245, 158, 11, 0.35);
    color: inherit;
    padding: 1px 3px;
    border-radius: 3px;
}

.doc-viewer-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    color: var(--text-muted);
    font-size: 0.88rem;
    padding: 2rem;
    text-align: center;
}

/* ==========================================================================
   MODALS & FORMS
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 580px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-card.modal-image-card {
    max-width: 820px;
    background: #000000;
}

.modal-card.auth-card {
    max-width: 440px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    font-size: 0.9rem;
}

.custom-input {
    width: 100%;
    padding: 0.65rem 0.95rem;
    background: var(--bg-surface-elevated);
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.88rem;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.custom-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.custom-input-file {
    width: 100%;
    padding: 0.65rem;
    background: var(--bg-surface-elevated);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.helper-text {
    font-size: 0.74rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    display: block;
}

.password-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-wrap .custom-input {
    padding-right: 2.5rem;
}

.toggle-password-btn {
    position: absolute;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toggle-password-btn:hover {
    color: var(--text-primary);
}

.signup-feature-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.25);
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    font-size: 0.8rem;
    margin-bottom: 0.95rem;
    line-height: 1.45;
}

.auth-switch-link {
    text-align: center;
    margin-top: 0.9rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.auth-switch-link a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}

.auth-switch-link a:hover {
    text-decoration: underline;
}

.auth-success-msg {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 0.65rem;
    border-radius: 6px;
    font-size: 0.84rem;
    margin-bottom: 0.85rem;
    text-align: center;
}

.upload-progress-box {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    background: var(--primary-light);
    padding: 0.75rem;
    border-radius: 8px;
    color: var(--primary);
    font-size: 0.85rem;
    margin-top: 0.85rem;
}

.spinner-sm {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(79, 70, 229, 0.2);
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.text-center {
    text-align: center;
}

/* ==========================================================================
   RESPONSIVE DESIGN & MOBILE DRAWER STYLES
   ========================================================================== */
.chat-mobile-bar {
    display: none;
}

.mobile-only-btn {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

.sidebar-header-btns {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

@media (max-width: 992px) {
    .ocr-container {
        flex-direction: column;
        overflow-y: auto;
    }

    .ocr-left-panel,
    .ocr-right-panel {
        width: 100%;
        max-width: 100%;
        height: auto;
        min-height: 400px;
    }

    .docs-container {
        flex-direction: column;
        overflow-y: auto;
    }

    .docs-list-panel,
    .doc-viewer-panel {
        width: 100%;
        max-width: 100%;
        height: auto;
        min-height: 380px;
    }
}

@media (max-width: 860px) {
    .chat-container {
        position: relative;
        overflow: hidden;
    }

    .chat-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85%;
        max-width: 360px;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
        background: var(--bg-surface);
    }

    .chat-sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.45);
        backdrop-filter: blur(2px);
        z-index: 95;
    }

    .chat-mobile-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.5rem 1rem;
        background: var(--bg-surface);
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0;
        gap: 0.5rem;
    }

    .mobile-rag-status {
        font-size: 0.76rem;
        font-weight: 600;
        color: var(--text-muted);
        display: flex;
        align-items: center;
        gap: 0.35rem;
    }

    .mobile-only-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .collections-checkbox-list {
        max-height: calc(100vh - 360px);
    }
}

@media (max-width: 1380px) {
    .brand-subtitle {
        display: none;
    }
    .brand-info h1 {
        font-size: 1rem;
    }
    .top-nav {
        padding: 0.5rem 1rem;
        gap: 0.6rem;
    }
    .tab-btn {
        padding: 0.35rem 0.65rem;
        font-size: 0.78rem;
        gap: 0.3rem;
        border-radius: 9999px;
    }
    .tab-btn svg {
        width: 14px;
        height: 14px;
    }
}

@media (max-width: 1120px) {
    .history-toggle-btn span {
        display: none;
    }
    .top-nav {
        padding: 0.45rem 0.85rem;
        gap: 0.5rem;
    }
    .tab-btn {
        padding: 0.32rem 0.6rem;
        font-size: 0.76rem;
        border-radius: 9999px;
    }
}

@media (max-width: 992px) {
    .top-nav {
        flex-wrap: wrap;
        padding: 0.5rem 0.85rem;
        gap: 0.5rem;
    }
    .nav-tabs {
        order: 3;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        display: flex;
        gap: 0.3rem;
        padding: 4px 6px;
        border-radius: 9999px;
    }
    .nav-tabs::-webkit-scrollbar {
        display: none;
    }
    .tab-btn {
        padding: 0.35rem 0.7rem;
        font-size: 0.78rem;
        flex-shrink: 0;
        border-radius: 9999px;
    }
}

@media (max-width: 768px) {
    .top-nav {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.45rem 0.75rem;
    }

    .brand-title {
        font-size: 0.95rem;
    }

    .nav-tabs {
        order: 3;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        display: flex;
        gap: 0.3rem;
        padding: 3px 5px;
        border-radius: 9999px;
    }
    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        padding: 0.32rem 0.65rem;
        font-size: 0.76rem;
        flex-shrink: 0;
        border-radius: 9999px;
    }

    .dock-controls-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .dock-model-picker {
        width: 100%;
    }

    .dock-select {
        flex: 1;
        width: 100%;
    }

    .dock-rag-modes {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .chat-bottom-dock {
        padding: 0.65rem 0.85rem;
    }

    .message {
        max-width: 95%;
    }

    .modal-card {
        width: 95%;
        margin: 0.5rem;
    }

    .table-batch-actions {
        flex-wrap: wrap;
        gap: 0.35rem;
    }
}

/* ==================== CHAT HISTORY MODAL & SESSION CARDS ==================== */
.history-session-card {
    background: var(--bg-surface-elevated, #ffffff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    padding: 0.75rem 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    gap: 0.75rem;
}

.history-session-card:hover {
    border-color: var(--primary-color, #4f46e5);
    background: var(--bg-hover, rgba(79, 70, 229, 0.04));
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.history-session-card.active {
    border-color: var(--primary-color, #4f46e5);
    background: rgba(79, 70, 229, 0.08);
}

.history-session-info {
    flex: 1;
    min-width: 0;
}

.history-session-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-color, #0f172a);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.3rem;
}

.history-session-meta {
    display: flex;
    gap: 0.45rem;
    align-items: center;
    flex-wrap: wrap;
    font-size: 0.74rem;
    color: var(--text-muted, #64748b);
}

.history-tag {
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--bg-secondary, #f8fafc);
    border: 1px solid var(--border-color, #e2e8f0);
    font-size: 0.72rem;
}

.history-tag-model {
    color: var(--primary-color, #4f46e5);
    font-weight: 600;
}

.history-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted, #94a3b8);
    padding: 0.4rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-delete-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* ==========================================================================
   APP BODY & REALTIME CHAT HISTORY SIDEBAR (RIGHT SIDEBAR)
   ========================================================================== */
.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    width: 100%;
    height: calc(100vh - 61px);
}

.chat-history-sidebar {
    width: 300px;
    min-width: 300px;
    height: 100%;
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    border-right: none;
    display: flex;
    flex-direction: column;
    transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1), transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    z-index: 50;
    overflow: hidden;
    position: relative;
}

.chat-history-sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    border-left: none;
    pointer-events: none;
    opacity: 0;
}

.sidebar-header {
    padding: 0.85rem 0.95rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    background-color: var(--bg-surface);
}

.sidebar-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-heading-wrap {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.sidebar-icon {
    font-size: 1.05rem;
}

.sidebar-heading {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.sidebar-header-badge {
    background: var(--primary-light);
    color: var(--primary);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 999px;
    border: 1px solid rgba(79, 70, 229, 0.2);
    line-height: 1.3;
}

.sidebar-header-tools {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.sidebar-new-chat-btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.82rem;
    padding: 0.55rem 0.85rem;
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    color: #ffffff;
    border: none;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-new-chat-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
    background: linear-gradient(135deg, #4338ca 0%, #4f46e5 100%);
}

.sidebar-new-chat-btn:active {
    transform: translateY(0);
}

.sidebar-search-box {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.6rem;
    color: var(--text-muted);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.sidebar-search-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.12);
}

.sidebar-search-box input {
    border: none;
    background: transparent;
    font-size: 0.78rem;
    color: var(--text-primary);
    width: 100%;
    outline: none;
    font-family: inherit;
}

.sidebar-search-box input::placeholder {
    color: var(--text-muted);
}

.sidebar-search-clear {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 3px;
    font-size: 0.72rem;
    line-height: 1;
    border-radius: 50%;
    transition: color 0.15s;
}

.sidebar-search-clear:hover {
    color: var(--text-primary);
}

.sidebar-sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.65rem 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.sidebar-session-item {
    padding: 0.65rem 0.8rem;
    border-radius: 10px;
    border: 1px solid transparent;
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    background: var(--bg-surface);
    position: relative;
    user-select: none;
}

.sidebar-session-item:hover {
    background-color: var(--bg-surface-hover);
    border-color: var(--border-color);
    border-left-color: rgba(79, 70, 229, 0.4);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.sidebar-session-item.active {
    background-color: var(--primary-light);
    border-color: rgba(79, 70, 229, 0.28);
    border-left-color: var(--primary);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.12);
}

.session-main-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
}

.session-title-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.session-icon-box {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    flex-shrink: 0;
}

.session-icon-box.direct {
    background: rgba(59, 130, 246, 0.12);
}

.session-icon-box.rag {
    background: rgba(139, 92, 246, 0.12);
}

.session-title-text {
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.35;
    flex: 1;
}

.sidebar-session-item.active .session-title-text {
    color: var(--primary);
}

.session-action-btns {
    display: flex;
    opacity: 0;
    transform: translateX(4px);
    align-items: center;
    gap: 0.2rem;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.sidebar-session-item:hover .session-action-btns {
    opacity: 1;
    transform: translateX(0);
}

.session-btn-action {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px 5px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.session-btn-action:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.08);
}

.session-btn-action.delete-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.12);
}

.session-meta-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.session-badge {
    padding: 1.5px 6px;
    border-radius: 6px;
    font-size: 0.67rem;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    font-weight: 500;
}

.session-badge-model {
    color: var(--primary);
    font-weight: 600;
    background: rgba(79, 70, 229, 0.08);
    border-color: rgba(79, 70, 229, 0.2);
}

.session-time {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-left: auto;
}

/* Form chỉnh sửa tên hội thoại (Inline Rename) */
.session-rename-form {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    width: 100%;
}

.session-rename-input {
    flex: 1;
    min-width: 0;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    padding: 3px 7px;
    border-radius: 5px;
    border: 1.5px solid var(--primary);
    background: var(--bg-surface);
    color: var(--text-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.session-rename-save-btn,
.session-rename-cancel-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.session-rename-save-btn {
    color: var(--success);
}
.session-rename-save-btn:hover {
    background: rgba(16, 185, 129, 0.15);
}

.session-rename-cancel-btn {
    color: var(--danger);
}
.session-rename-cancel-btn:hover {
    background: rgba(239, 68, 68, 0.15);
}

/* Error Card on fetch failure */
.sidebar-error-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.45rem;
    padding: 2rem 1rem;
    background: var(--bg-surface-elevated);
    border: 1px dashed rgba(239, 68, 68, 0.35);
    border-radius: 10px;
    margin: 1rem 0.5rem;
}

.sidebar-error-card .error-icon {
    font-size: 1.8rem;
}

.sidebar-error-card .error-title {
    font-weight: 600;
    font-size: 0.84rem;
    color: var(--danger);
}

.sidebar-error-card .error-desc {
    font-size: 0.74rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.35;
}

.sidebar-footer {
    padding: 0.6rem 0.95rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--text-muted);
    background: var(--bg-surface);
}

.neon-live-indicator {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 500;
}

.neon-live-indicator .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #10b981;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
    animation: pulseDot 2s infinite ease-in-out;
}

@keyframes pulseDot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(0.85); }
}

.sidebar-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Mobile Responsive Sidebar (Right Drawer) */
@media (max-width: 768px) {
    .chat-history-sidebar {
        position: fixed;
        top: 57px;
        right: 0;
        left: auto;
        bottom: 0;
        z-index: 999;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.18);
        transform: translateX(0);
        border-left: 1px solid var(--border-color);
    }

    .chat-history-sidebar.collapsed {
        transform: translateX(100%) !important;
        width: 300px !important;
        min-width: 300px !important;
        opacity: 1 !important;
    }
}

/* ==========================================================================
   OFFICE STUDIO AI STYLES (TẠO, SỬA & ĐÁNH GIÁ OFFICE LOCAL OLLAMA)
   ========================================================================== */
.office-studio-container {
    width: 100%;
    max-width: 1380px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
    box-sizing: border-box;
    min-height: 100%;
}

.office-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1.25rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

.office-title-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.office-main-icon {
    font-size: 2.2rem;
    line-height: 1;
}

.office-title-row h2 {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0 0 0.2rem;
    color: var(--text-primary);
}

.office-title-row p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
}

.office-subnav-pills {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.office-pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 1.1rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface-elevated);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.office-pill-btn:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--primary-light, #818cf8);
}

.office-pill-btn.active {
    background: var(--primary, #4f46e5);
    color: #ffffff;
    border-color: var(--primary, #4f46e5);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.28);
}

.office-subpanel {
    animation: fadeIn 0.25s ease-out;
}

.office-grid-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    gap: 1.5rem;
    min-width: 0;
    width: 100%;
    align-items: start;
}

.office-form-card,
.office-result-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.office-card-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0 0 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Định dạng selector thẻ (docx, xlsx, pptx) */
.office-type-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.office-type-card {
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    padding: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-surface-elevated);
}

.office-type-card:hover {
    border-color: var(--primary-light, #818cf8);
    transform: translateY(-1px);
}

.office-type-card.active {
    border-color: var(--primary, #4f46e5);
    background: rgba(79, 70, 229, 0.06);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.12);
}

.type-icon {
    font-size: 1.75rem;
    line-height: 1;
}

.type-text strong {
    display: block;
    font-size: 0.88rem;
    color: var(--text-primary);
}

.type-text span {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.office-prompt-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.office-textarea {
    width: 100%;
    border-radius: 10px;
    padding: 0.85rem;
    font-size: 0.92rem;
    line-height: 1.5;
    resize: vertical;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    box-sizing: border-box;
}

.office-textarea:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.office-quick-prompts {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.25rem;
}

.quick-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.office-chip {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.office-chip:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.05);
}

.office-params-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin: 1.25rem 0;
}

.office-field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--text-secondary);
}

.office-btn-large {
    padding: 0.85rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Dropzones */
.office-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 2.2rem 1.5rem;
    text-align: center;
    background: var(--bg-surface-elevated);
    cursor: pointer;
    transition: all 0.2s ease;
}

.office-dropzone:hover {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.03);
}

.drop-icon {
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
}

.dropzone-inner h4 {
    margin: 0 0 0.35rem;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.browse-link {
    color: var(--primary);
    text-decoration: underline;
}

.drop-hint {
    margin: 0;
    font-size: 0.76rem;
    color: var(--text-muted);
}

.selected-file-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary);
    border: 1px solid rgba(79, 70, 229, 0.25);
    border-radius: 20px;
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 0.75rem;
}

.file-chip-remove {
    background: none;
    border: none;
    color: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0 2px;
}

/* Result Card & Placeholder */
.office-result-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3.5rem 1.5rem;
    border: 1.5px dashed var(--border-color);
    border-radius: 12px;
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
    opacity: 0.65;
}

.office-result-placeholder h4 {
    margin: 0 0 0.35rem;
    font-size: 1rem;
    color: var(--text-primary);
}

.office-result-placeholder p {
    margin: 0;
    font-size: 0.82rem;
    max-width: 360px;
}

.office-loading-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1.5rem;
}

.office-loading-box h4 {
    margin: 1rem 0 0.25rem;
    font-size: 1rem;
    color: var(--text-primary);
}

.office-loading-box p {
    margin: 0;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* Success Card */
.success-file-card {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    background: rgba(16, 185, 129, 0.08);
    border: 1.5px solid rgba(16, 185, 129, 0.25);
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.15rem;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

.success-file-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    width: 100%;
    min-width: 0;
}

.file-icon-badge {
    width: 44px;
    height: 44px;
    font-size: 1.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(16, 185, 129, 0.15);
    border-radius: 10px;
    flex-shrink: 0;
    line-height: 1;
}

.file-details {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.file-details h4 {
    margin: 0 0 0.25rem;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
}

.file-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.file-status-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: #10b981;
    font-weight: 600;
}

.file-status-tag::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
}

.office-success-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.office-preview-action,
.office-download-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.65rem 0.85rem;
    font-size: 0.84rem;
    font-weight: 600;
    border-radius: 8px;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    transition: all 0.15s ease;
}

.office-preview-action {
    background: var(--primary, #4f46e5);
    color: #ffffff !important;
    border: 1px solid var(--primary, #4f46e5);
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25);
}

.office-preview-action:hover {
    background: var(--primary-hover, #4338ca);
    transform: translateY(-1px);
}

.office-download-action {
    background: #10b981;
    color: #ffffff !important;
    border: 1px solid #10b981;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.25);
}

.office-download-action:hover {
    background: #059669;
    transform: translateY(-1px);
}

.office-preview-wrap {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-surface-elevated);
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    font-size: 0.82rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.02);
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

.preview-header-tag {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary, #4f46e5);
    font-weight: 600;
}

.office-preview-body {
    max-height: 420px;
    overflow-y: auto;
    overflow-x: auto;
    padding: 1rem 1.15rem;
    font-size: 0.86rem;
    line-height: 1.6;
    color: var(--text-secondary);
    word-break: break-word;
    overflow-wrap: anywhere;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

.office-preview-body * {
    max-width: 100%;
    box-sizing: border-box;
}

.office-preview-body h1,
.office-preview-body h2,
.office-preview-body h3,
.office-preview-body h4 {
    color: var(--text-primary);
    margin-top: 0.85rem;
    margin-bottom: 0.4rem;
    font-weight: 700;
    line-height: 1.35;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.office-preview-body h1 { font-size: 1.15rem; }
.office-preview-body h2 { font-size: 1.05rem; }
.office-preview-body h3 { font-size: 0.95rem; }
.office-preview-body h4 { font-size: 0.88rem; }

.office-preview-body p {
    margin: 0 0 0.65rem 0;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.6;
}

.office-preview-body ul,
.office-preview-body ol {
    margin: 0 0 0.75rem 1.25rem;
    padding: 0;
}

.office-preview-body li {
    margin-bottom: 0.35rem;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.office-preview-body table {
    width: 100% !important;
    max-width: 100% !important;
    border-collapse: collapse;
    font-size: 0.82rem;
    margin: 0.75rem 0;
    table-layout: auto;
}

.office-preview-body th,
.office-preview-body td {
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    text-align: left;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.office-preview-body th {
    background: rgba(79, 70, 229, 0.08);
    color: var(--text-primary);
    font-weight: 600;
}

.office-preview-body pre,
.office-preview-body code {
    white-space: pre-wrap !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    font-family: var(--font-mono, monospace);
    font-size: 0.82rem;
}

/* Changelog card */
.office-changelog-card {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1rem;
}

.office-changelog-card h4 {
    margin: 0 0 0.65rem;
    font-size: 0.88rem;
    color: var(--text-primary);
}

.changelog-list {
    margin: 0;
    padding-left: 1.25rem;
    font-size: 0.84rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Sub-panel 3: Đánh giá & Chấm điểm (Evaluator) */
.office-eval-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.office-eval-header-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

.eval-grid-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.eval-drop-box h4 {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.office-dropzone-sm {
    border: 1.5px dashed var(--border-color);
    border-radius: 10px;
    padding: 1.25rem;
    text-align: center;
    background: var(--bg-surface-elevated);
    cursor: pointer;
    transition: all 0.2s ease;
}

.office-dropzone-sm:hover {
    border-color: var(--primary);
}

.dropzone-inner-sm {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.drop-icon-sm {
    font-size: 1.35rem;
}

.drop-label-sm {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.selected-file-badge-sm {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary);
    border-radius: 14px;
    padding: 0.25rem 0.65rem;
    font-size: 0.78rem;
    font-weight: 600;
}

.eval-controls-bar {
    display: grid;
    grid-template-columns: 1.4fr 0.9fr auto;
    gap: 0.85rem;
    align-items: center;
}

.eval-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.65rem 1.25rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Evaluation Score Hero */
.eval-score-hero {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 50%, #3b82f6 100%);
    border-radius: 14px;
    padding: 1.5rem 1.75rem;
    color: #ffffff;
    box-shadow: 0 4px 16px rgba(30, 58, 138, 0.2);
}

.eval-score-circle {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    border: 3px solid rgba(255, 255, 255, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#eval-score-num {
    font-size: 2.1rem;
    font-weight: 800;
    line-height: 1;
    color: #ffffff;
}

.eval-score-max {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.85);
    margin-top: 2px;
}

.eval-score-meta {
    flex: 1;
}

.eval-badge-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.eval-grade-badge {
    background: #10b981;
    color: #ffffff;
    padding: 0.2rem 0.65rem;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 700;
}

.eval-percent-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.2rem 0.65rem;
    border-radius: 12px;
    font-size: 0.75rem;
}

#eval-title-display {
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: #ffffff;
}

.eval-summary-text {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.45;
    color: rgba(255, 255, 255, 0.9);
}

/* Section Cards for Evaluation */
.eval-section-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.25rem 1.5rem;
    margin-top: 1.25rem;
}

.eval-sec-title {
    font-size: 0.98rem;
    font-weight: 700;
    margin: 0 0 0.85rem;
    color: var(--text-primary);
}

.eval-two-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-top: 1.25rem;
}

.eval-column-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.25rem;
}

.eval-bullet-list {
    margin: 0;
    padding-left: 1.25rem;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.eval-bullet-list li {
    margin-bottom: 0.4rem;
}

/* Bảng Office Evaluation */
.table-office-eval,
.table-office-files {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.table-office-eval th,
.table-office-files th {
    background: var(--bg-surface-elevated);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 0.7rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

.table-office-eval td,
.table-office-files td {
    padding: 0.75rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

.table-office-eval tbody tr:hover,
.table-office-files tbody tr:hover {
    background: var(--bg-surface-elevated);
}

.status-badge-pass {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.75rem;
}

.status-badge-partial {
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.75rem;
}

.status-badge-fail {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.75rem;
}

/* Mobile responsive */
@media (max-width: 992px) {
    .office-grid-layout,
    .eval-grid-two,
    .eval-two-columns {
        grid-template-columns: 1fr;
    }
    .eval-controls-bar {
        grid-template-columns: 1fr;
    }
    .office-type-selector {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .eval-score-hero {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    .eval-download-action-wrap {
        width: 100%;
    }
    .eval-download-action-wrap .btn {
        flex: 1;
        justify-content: center;
    }
}

@media (max-width: 520px) {
    .office-success-actions {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   OFFICE STUDIO: SMART CONFIG DECK (MÔ HÌNH AI & PHONG CÁCH VĂN BẢN ĐỒNG BỘ)
   ========================================================================== */
.office-settings-deck {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.15rem;
    margin-top: 1.15rem;
    margin-bottom: 1.25rem;
    padding: 1.15rem;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: 14px;
}

.office-setting-col {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    min-width: 0;
}

.office-setting-heading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.office-model-pill-grid,
.office-style-pill-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.office-model-pill,
.office-style-pill {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.62rem 0.85rem;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    position: relative;
    text-align: left;
    width: 100%;
    box-sizing: border-box;
}

.office-model-pill:hover,
.office-style-pill:hover {
    border-color: var(--primary-light, #818cf8);
    background: var(--bg-surface-elevated);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
}

.office-model-pill.active,
.office-style-pill.active {
    border-color: var(--primary, #4f46e5);
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.08) 0%, rgba(79, 70, 229, 0.02) 100%);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.18), 0 3px 10px rgba(79, 70, 229, 0.08);
}

.pill-icon {
    font-size: 1.25rem;
    line-height: 1;
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface-elevated);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.pill-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pill-title-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.pill-title-row strong {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 700;
}

.pill-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pill-badge {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.2px;
}

.badge-rec { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.badge-cot { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.badge-pro { background: rgba(139, 92, 246, 0.15); color: #8b5cf6; }
.badge-code { background: rgba(14, 165, 233, 0.15); color: #0ea5e9; }
.badge-gov { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.badge-corp { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.badge-acad { background: rgba(168, 85, 247, 0.15); color: #a855f7; }
.badge-modern { background: rgba(20, 184, 166, 0.15); color: #14b8a6; }

.pill-check {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 800;
    color: transparent;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.office-model-pill.active .pill-check,
.office-style-pill.active .pill-check {
    background: var(--primary, #4f46e5);
    border-color: var(--primary, #4f46e5);
    color: #ffffff;
}

@media (max-width: 900px) {
    .office-settings-deck {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 0.95rem;
    }
}

/* ==========================================================================
   OFFICE ONLINE PREVIEW STUDIO MODAL (CHUYÊN NGHIỆP & HIỆN ĐẠI)
   ========================================================================== */
.office-preview-modal-card {
    max-width: 1200px;
    width: 96%;
    height: 92vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    border-radius: 16px;
    background: var(--bg-surface);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    transition: all 0.25s ease;
}

.office-preview-modal-card.is-fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    border-radius: 0 !important;
    border: none !important;
}

.office-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: var(--bg-surface-elevated);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 1rem;
    flex-wrap: wrap;
}

.preview-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.preview-doc-icon-badge {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    flex-shrink: 0;
}

.preview-filename {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 400px;
}

.preview-sub-status {
    font-size: 0.73rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 1px;
}

.status-live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 6px #10b981;
    display: inline-block;
}

.preview-tools-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-left: auto;
    flex-wrap: wrap;
}

.preview-zoom-group {
    display: inline-flex;
    align-items: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 2px 4px;
    gap: 3px;
}

.zoom-level-text {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0 6px;
    min-width: 42px;
    text-align: center;
    color: var(--text-secondary);
}

.office-preview-canvas {
    flex: 1;
    overflow: auto;
    background: #475569;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    box-sizing: border-box;
}

[data-theme="light"] .office-preview-canvas {
    background: #e2e8f0;
}

.office-preview-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #ffffff;
    gap: 0.75rem;
}

/* DOCX Preview Page Wrapper (A4 Simulation) */
.office-docx-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.office-docx-container .docx-wrapper {
    background: transparent !important;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.office-docx-container .docx {
    background: #ffffff !important;
    color: #1f2937 !important;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22) !important;
    border-radius: 4px !important;
    padding: 72pt 72pt !important;
    min-height: 842pt;
    width: 595pt;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0 auto !important;
}

/* Fallback visual document render (In case third-party library encounters odd binary) */
.office-preview-fallback-doc {
    background: #ffffff;
    color: #1f2937;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
    border-radius: 4px;
    padding: 60pt 60pt;
    min-height: 842pt;
    width: 595pt;
    max-width: 100%;
    box-sizing: border-box;
    font-family: "Times New Roman", Times, serif;
    line-height: 1.6;
}

.fallback-doc-header {
    text-align: center;
    margin-bottom: 2rem;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 1.5rem;
}

.fallback-doc-header h2 {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0 0 0.5rem 0;
    color: #1e3a8a;
    text-transform: uppercase;
}

.fallback-doc-header p {
    font-size: 0.95rem;
    font-style: italic;
    color: #64748b;
    margin: 0;
}

.fallback-doc-section {
    margin-bottom: 1.5rem;
}

.fallback-doc-section h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e3a8a;
    margin: 0 0 0.5rem 0;
}

/* XLSX Preview Container */
.office-xlsx-wrapper {
    width: 100%;
    max-width: 1050px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.office-xlsx-ribbon-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    background: #107c41;
    color: #ffffff;
    font-size: 0.82rem;
    font-weight: 600;
}

.office-xlsx-container {
    width: 100%;
    overflow: auto;
    max-height: 65vh;
    padding: 1rem;
    box-sizing: border-box;
}

.office-xlsx-container table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    color: #1f2937;
    font-family: Calibri, Segoe UI, sans-serif;
}

.office-xlsx-container th,
.office-xlsx-container td {
    border: 1px solid #d1d5db;
    padding: 6px 12px;
    text-align: left;
}

.office-xlsx-container th {
    background: #107c41;
    color: #ffffff;
    font-weight: 700;
    text-align: center;
}

.office-xlsx-container tr:nth-child(even) td {
    background: #f8fafc;
}

.office-xlsx-sheet-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 16px;
    background: #f1f5f9;
    border-top: 1px solid #e2e8f0;
    overflow-x: auto;
}

.xlsx-sheet-tab-btn {
    padding: 5px 14px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #475569;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.xlsx-sheet-tab-btn.active {
    background: #107c41;
    color: #ffffff;
    border-color: #107c41;
    box-shadow: 0 1px 4px rgba(16, 124, 65, 0.25);
}

/* PPTX Slide Studio Layout */
.office-pptx-container {
    width: 100%;
    max-width: 1080px;
    height: 72vh;
    display: flex;
    gap: 1rem;
}

.pptx-thumb-rail {
    width: 190px;
    flex-shrink: 0;
    background: var(--bg-surface-elevated);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 0.75rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    overflow-y: auto;
}

.pptx-thumb-item {
    padding: 0.65rem 0.75rem;
    border-radius: 8px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 3px;
    text-align: left;
}

.pptx-thumb-item:hover {
    border-color: var(--primary-light, #818cf8);
}

.pptx-thumb-item.active {
    border-color: var(--primary, #4f46e5);
    background: rgba(79, 70, 229, 0.08);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.15);
}

.thumb-num {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--primary);
}

.thumb-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pptx-main-deck {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
    height: 100%;
}

.pptx-slide-canvas {
    flex: 1;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
    overflow-y: auto;
    padding: 2.2rem 2.8rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 1px solid var(--border-color);
    box-sizing: border-box;
}

.office-pptx-nav-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    padding: 0.65rem 1.25rem;
    background: var(--bg-surface-elevated);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.office-pdf-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #ffffff;
    border-radius: 8px;
}

/* Print CSS */
@media print {
    body * {
        visibility: hidden !important;
    }
    #office-preview-modal,
    #office-preview-modal .office-preview-canvas,
    #office-preview-modal .office-docx-container,
    #office-preview-modal .office-docx-container * {
        visibility: visible !important;
    }
    #office-preview-modal {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        height: auto !important;
        background: transparent !important;
        display: block !important;
        padding: 0 !important;
    }
    .office-preview-toolbar,
    .preview-tools-actions {
        display: none !important;
    }
    .office-preview-canvas {
        background: transparent !important;
        padding: 0 !important;
    }
}

/* ==========================================================================
   ROLEPLAY (NHẬP VAI AI) - ELEGANT WHITE CHARACTER HUB & CHAT ARENA
   Giao diện màu trắng thanh lịch, đồng bộ thiết kế toàn hệ thống HPU2 AI
   ========================================================================== */

#tab-roleplay {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    width: 100%;
    background: var(--bg-base, #f8fafc);
    color: var(--text-primary, #0f172a);
    overflow: hidden;
    position: relative;
}

.roleplay-view-pane {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
}

/* ==========================================================================
   VIEW 1: CHARACTER HUB GALLERY
   ========================================================================== */
#roleplay-view-hub {
    padding: 24px 32px;
    gap: 20px;
}

/* 1. HERO BANNER CARD */
.roleplay-hero-card {
    background: #ffffff;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 18px;
    padding: 28px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.03), 0 2px 6px -1px rgba(0, 0, 0, 0.02);
    position: relative;
    overflow: hidden;
}

.roleplay-hero-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.08), transparent 70%);
    pointer-events: none;
}

.roleplay-hero-info {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 780px;
    position: relative;
    z-index: 1;
}

.roleplay-hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    border-radius: 20px;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: #4f46e5;
    font-size: 0.78rem;
    font-weight: 600;
    width: fit-content;
}

.badge-dot-live {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
    animation: livePulse 2s infinite ease-in-out;
}

@keyframes livePulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
}

.roleplay-hero-info h2 {
    font-size: 1.55rem;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: -0.02em;
    margin: 0;
}

.roleplay-hero-info p {
    font-size: 0.92rem;
    color: #64748b;
    line-height: 1.55;
    margin: 0;
}

.roleplay-hero-tags {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.hero-tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.8rem;
    color: #475569;
    font-weight: 500;
}

.hero-tag-chip code {
    background: #e2e8f0;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.75rem;
    color: #4f46e5;
}

.roleplay-hero-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.roleplay-hero-buttons .btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    font-size: 0.88rem;
    font-weight: 600;
    border-radius: 10px;
    white-space: nowrap;
}

/* 2. TOOLBAR CARD */
.roleplay-toolbar-card {
    background: #ffffff;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 14px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
}

.roleplay-category-pills {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.roleplay-cat-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    font-size: 0.84rem;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.roleplay-cat-pill:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #0f172a;
    transform: translateY(-1px);
}

.roleplay-cat-pill.active {
    background: #4f46e5;
    border-color: #4f46e5;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.pill-count {
    background: rgba(0, 0, 0, 0.08);
    padding: 1px 7px;
    border-radius: 12px;
    font-size: 0.74rem;
    font-weight: 700;
}

.roleplay-cat-pill.active .pill-count {
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
}

.roleplay-search-sort-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.roleplay-search-input-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 14px;
    width: 290px;
    color: #94a3b8;
    transition: all 0.2s;
}

.roleplay-search-input-box:focus-within {
    background: #ffffff;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
    color: #4f46e5;
}

.roleplay-search-input-box input {
    border: none;
    background: transparent;
    outline: none;
    font-size: 0.85rem;
    color: #0f172a;
    width: 100%;
}

.roleplay-search-input-box input::placeholder {
    color: #94a3b8;
}

.roleplay-sort-select-box {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: #64748b;
    font-weight: 500;
}

.roleplay-select-clean {
    border: 1.5px solid #e2e8f0;
    background: #ffffff;
    border-radius: 9999px;
    padding: 6px 16px;
    font-size: 0.82rem;
    color: #334155;
    font-weight: 600;
    outline: none;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.roleplay-select-clean:hover {
    border-color: rgba(79, 70, 229, 0.4);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.roleplay-select-clean:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

/* 3. CARDS GRID & CARD DESIGN */
.roleplay-grid-deck {
    width: 100%;
    margin-bottom: 24px;
}

.roleplay-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 22px;
    width: 100%;
}

.roleplay-grid-loading {
    grid-column: 1 / -1;
    padding: 60px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: #64748b;
    font-size: 0.92rem;
}

.roleplay-char-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.roleplay-char-card:hover {
    transform: translateY(-6px);
    border-color: #c7d2fe;
    box-shadow: 0 16px 32px -6px rgba(79, 70, 229, 0.12), 0 4px 10px -2px rgba(0, 0, 0, 0.04);
}

.roleplay-card-cover {
    width: 100%;
    aspect-ratio: 1 / 1;
    position: relative;
    background: #f1f5f9;
    overflow: hidden;
}

.roleplay-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: block;
}

.roleplay-char-card:hover .roleplay-card-img {
    transform: scale(1.05);
}

.roleplay-card-overlay-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.roleplay-card-temp-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 9px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #0f172a;
    font-size: 0.72rem;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.6);
}

.roleplay-card-body {
    padding: 16px 18px 12px 18px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    min-width: 0;
}

.roleplay-card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.roleplay-card-title {
    font-size: 1.05rem;
    font-weight: 750;
    color: #0f172a;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.roleplay-char-card:hover .roleplay-card-title {
    color: #4f46e5;
}

.roleplay-card-author {
    font-size: 0.75rem;
    color: #94a3b8;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.roleplay-card-author .author-name {
    color: #64748b;
    font-weight: 600;
}

.roleplay-card-tagline {
    font-size: 0.82rem;
    color: #475569;
    margin: 6px 0 0 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.45;
    min-height: 2.9em;
}

.roleplay-card-footer {
    padding: 10px 18px;
    border-top: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fafbfc;
    font-size: 0.78rem;
    color: #64748b;
}

.roleplay-card-chat-hint {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: #64748b;
}

.roleplay-card-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.roleplay-card-btn-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    background: #4f46e5;
    color: #ffffff;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.roleplay-card-btn-action:hover {
    background: #4338ca;
    transform: translateX(1px);
}

.roleplay-card-btn-del {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 5px 7px;
    border-radius: 6px;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.roleplay-card-btn-del:hover {
    color: #ef4444;
    background: #fee2e2;
}

/* ==========================================================================
   VIEW 2: DEDICATED CHAT ARENA
   ========================================================================== */
#roleplay-view-chat {
    background: #f8fafc;
}

.roleplay-arena-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 28px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    gap: 16px;
    flex-shrink: 0;
    flex-wrap: wrap;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
    z-index: 5;
}

.arena-left-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.roleplay-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 8px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #0f172a;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.roleplay-back-btn:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
    transform: translateX(-2px);
}

.arena-char-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.arena-char-avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    object-fit: cover;
    border: 2px solid #4f46e5;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.2);
}

.arena-char-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.arena-char-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.arena-char-title-row h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    color: #0f172a;
}

.badge-char-tag {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(99, 102, 241, 0.1);
    color: #4f46e5;
    font-weight: 600;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.arena-char-tagline {
    font-size: 0.78rem;
    color: #64748b;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 360px;
}

.arena-right-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.roleplay-model-picker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    border-radius: 9999px;
    padding: 4px 14px;
    color: #475569;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.roleplay-model-picker:hover {
    border-color: rgba(79, 70, 229, 0.4);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.08);
}

.roleplay-model-picker:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}

.roleplay-model-picker svg {
    color: var(--primary);
    flex-shrink: 0;
}

.roleplay-model-picker select {
    border: none;
    background: transparent;
    font-size: 0.82rem;
    font-weight: 600;
    color: #0f172a;
    outline: none;
    cursor: pointer;
    padding-right: 4px;
}

/* DRAWERS */
.roleplay-drawer {
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    padding: 16px 28px;
    animation: drawerSlide 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.04);
}

@keyframes drawerSlide {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.drawer-inner-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
}

.param-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.param-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    font-weight: 600;
    color: #334155;
}

.param-label-row strong {
    color: #4f46e5;
}

.param-item input[type="range"] {
    width: 100%;
    accent-color: #4f46e5;
    cursor: pointer;
}

.param-hint {
    font-size: 0.72rem;
    color: #64748b;
}

.bio-drawer-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 250px;
    overflow-y: auto;
}

.bio-section h4 {
    margin: 0 0 4px 0;
    font-size: 0.85rem;
    font-weight: 700;
    color: #0f172a;
}

.bio-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.82rem;
    color: #334155;
    line-height: 1.5;
    white-space: pre-wrap;
    max-height: 100px;
    overflow-y: auto;
}

/* MESSAGES FEED */
.roleplay-messages-feed {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
    background: #f8fafc;
}

.roleplay-msg-row {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
    animation: fadeInMsg 0.22s ease-out;
}

@keyframes fadeInMsg {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.roleplay-msg-row.user {
    justify-content: flex-end;
}

.roleplay-msg-row.assistant {
    justify-content: flex-start;
}

.roleplay-msg-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
    margin-top: 2px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.roleplay-char-bubble {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 18px 18px 18px 4px;
    padding: 14px 18px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
    max-width: 82%;
    color: #0f172a;
    line-height: 1.6;
    word-break: break-word;
    font-size: 0.95rem;
}

.roleplay-user-bubble {
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    color: #ffffff;
    border-radius: 18px 18px 4px 18px;
    padding: 13px 18px;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.25);
    max-width: 82%;
    line-height: 1.6;
    word-break: break-word;
    font-size: 0.95rem;
}

.roleplay-user-bubble p {
    margin: 0;
    color: #ffffff;
}

/* ASTERISK ACTION STYLING (*hành động*) */
.roleplay-action {
    color: #4f46e5;
    font-style: italic;
    font-weight: 500;
    background: rgba(99, 102, 241, 0.08);
    padding: 1px 6px;
    border-radius: 4px;
    display: inline;
}

/* INPUT DOCK */
.roleplay-input-dock {
    padding: 14px 24px 18px 24px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
    width: 100%;
}

.roleplay-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #f8fafc;
    border: 1.5px solid #cbd5e1;
    border-radius: 16px;
    padding: 8px 14px;
    transition: all 0.2s ease;
    max-width: 920px;
    margin: 0 auto;
}

.roleplay-input-bar:focus-within {
    border-color: #4f46e5;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.roleplay-input-bar textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 0.95rem;
    color: #0f172a;
    outline: none;
    max-height: 140px;
    min-height: 24px;
    line-height: 1.5;
}

.roleplay-send-btn {
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #4f46e5;
    border: none;
    color: #ffffff;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
    transition: all 0.15s ease;
}

.roleplay-send-btn:hover {
    background: #4338ca;
    transform: scale(1.05);
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.45);
}

.roleplay-input-hint {
    margin-top: 8px;
    text-align: center;
    font-size: 0.75rem;
    color: #64748b;
    max-width: 920px;
    margin-left: auto;
    margin-right: auto;
}

.roleplay-input-hint code {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.72rem;
    color: #4f46e5;
}

/* ==========================================================================
   CREATE CHARACTER MODAL STYLES
   ========================================================================== */
.roleplay-modal-card {
    max-width: 620px;
    width: 95%;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.12);
    border-radius: 16px;
    color: #0f172a;
}

.roleplay-form-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 24px;
    max-height: 78vh;
    overflow-y: auto;
}

.roleplay-form-body .form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.roleplay-form-body label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #334155;
}

.roleplay-form-body input[type="text"],
.roleplay-form-body textarea {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 12px;
    color: #0f172a;
    font-size: 0.88rem;
    outline: none;
    transition: all 0.15s;
}

.roleplay-form-body input[type="text"]:focus,
.roleplay-form-body textarea:focus {
    background: #ffffff;
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.roleplay-form-body input[type="range"] {
    accent-color: #4f46e5;
    cursor: pointer;
}

/* ==========================================================================
   DARK THEME COMPATIBILITY FOR ROLEPLAY
   ========================================================================== */
body.dark-theme #tab-roleplay {
    background: #0f172a;
    color: #f1f5f9;
}

body.dark-theme .roleplay-hero-card,
body.dark-theme .roleplay-toolbar-card,
body.dark-theme .roleplay-char-card,
body.dark-theme .roleplay-arena-topbar,
body.dark-theme .roleplay-drawer,
body.dark-theme .roleplay-input-dock,
body.dark-theme .roleplay-modal-card {
    background: #1e293b;
    border-color: #334155;
    color: #f1f5f9;
}

body.dark-theme .roleplay-hero-info h2,
body.dark-theme .roleplay-card-title,
body.dark-theme .arena-char-title-row h3,
body.dark-theme .bio-section h4 {
    color: #f8fafc;
}

body.dark-theme .roleplay-hero-info p,
body.dark-theme .roleplay-card-tagline,
body.dark-theme .arena-char-tagline,
body.dark-theme .param-label-row,
body.dark-theme .roleplay-form-body label {
    color: #94a3b8;
}

body.dark-theme .roleplay-cat-pill {
    background: #1e293b;
    border-color: #334155;
    color: #94a3b8;
}

body.dark-theme .roleplay-cat-pill:hover {
    background: #334155;
    color: #f8fafc;
}

body.dark-theme .roleplay-cat-pill.active {
    background: #4f46e5;
    border-color: #4f46e5;
    color: #ffffff;
}

body.dark-theme .roleplay-search-input-box,
body.dark-theme .roleplay-select-clean,
body.dark-theme .hero-tag-chip,
body.dark-theme .roleplay-back-btn,
body.dark-theme .roleplay-model-picker,
body.dark-theme .bio-box,
body.dark-theme .roleplay-form-body input[type="text"],
body.dark-theme .roleplay-form-body textarea {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}

body.dark-theme .roleplay-search-input-box input {
    color: #f1f5f9;
}

body.dark-theme .roleplay-card-footer {
    background: #172033;
    border-top-color: #334155;
}

body.dark-theme .roleplay-char-bubble {
    background: #1e293b;
    border-color: #334155;
    color: #f1f5f9;
}

body.dark-theme .roleplay-input-bar {
    background: #0f172a;
    border-color: #334155;
}

body.dark-theme .roleplay-input-bar textarea {
    color: #f8fafc;
}

/* ==========================================================================
   RESPONSIVE DESIGN (BREAKPOINTS)
   ========================================================================== */
@media (max-width: 1200px) {
    #roleplay-view-hub {
        padding: 20px 24px;
    }
    .roleplay-hero-card {
        flex-direction: column;
        align-items: flex-start;
    }
    .roleplay-hero-buttons {
        flex-direction: row;
        width: 100%;
    }
}

@media (max-width: 768px) {
    #roleplay-view-hub {
        padding: 16px;
    }
    .roleplay-cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 14px;
    }
    .roleplay-search-input-box {
        width: 100%;
    }
    .roleplay-search-sort-wrap {
        width: 100%;
        justify-content: space-between;
    }
    .arena-char-tagline {
        max-width: 180px;
    }
}

@media (max-width: 480px) {
    .roleplay-cards-grid {
        grid-template-columns: 1fr;
    }
}


/* ==========================================================================
   ADMIN MODEL MANAGEMENT STYLES
   ========================================================================== */
.admin-models-hero-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 24px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
    margin-bottom: 20px;
}

.admin-badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(2, 132, 199, 0.08);
    color: #0284c7;
    border: 1px solid rgba(2, 132, 199, 0.2);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 4px 10px;
    border-radius: 999px;
    margin-bottom: 10px;
}

.pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #0284c7;
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.9); opacity: 1; }
    50% { transform: scale(1.4); opacity: 0.5; }
    100% { transform: scale(0.9); opacity: 1; }
}

.admin-models-hero-main h2 {
    margin: 0 0 8px 0;
    font-size: 1.45rem;
    font-weight: 700;
    color: #0f172a;
}

.admin-models-hero-main p {
    margin: 0;
    font-size: 0.88rem;
    color: #64748b;
    max-width: 760px;
    line-height: 1.5;
}

.admin-models-hero-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.admin-models-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.admin-stat-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

.stat-icon-wrap {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-data {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stat-num {
    font-size: 1.25rem;
    font-weight: 700;
    color: #0f172a;
}

.stat-num.truncate-stat {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
}

.stat-label {
    font-size: 0.76rem;
    color: #64748b;
    margin-top: 2px;
}

.admin-models-layout {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 20px;
    align-items: start;
}

.admin-models-column {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 20px 22px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.02);
}

.admin-column-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 12px;
}

.col-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.col-title-wrap h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
}

.admin-tag-badge {
    background: #f1f5f9;
    color: #475569;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid #e2e8f0;
}

.col-subdesc {
    margin: 0 0 14px 0;
    font-size: 0.8rem;
    color: #64748b;
    line-height: 1.4;
}

.admin-search-input {
    padding: 7px 16px;
    border-radius: 9999px;
    border: 1.5px solid #cbd5e1;
    font-size: 0.82rem;
    outline: none;
    background: #f8fafc;
    width: 220px;
    transition: all 0.2s ease;
}

.admin-search-input:focus {
    border-color: #0284c7;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}

.admin-models-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 600px;
    overflow-y: auto;
}

.admin-model-item-card {
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 16px;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.admin-model-item-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

.admin-model-item-card.is-default {
    background: #f0fdf4;
    border-color: #86efac;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.1);
}

.model-item-left {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}

.model-chip-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.model-info-wrap {
    min-width: 0;
}

.model-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.model-item-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: #0f172a;
}

.model-tag-id {
    font-size: 0.76rem;
    font-family: monospace;
    font-weight: 600;
    background: #e2e8f0;
    color: #334155;
    padding: 2px 10px;
    border-radius: 9999px;
}

.badge-default {
    background: #22c55e;
    color: #ffffff;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 9999px;
    text-transform: uppercase;
}

.badge-vision {
    background: #a855f7;
    color: #ffffff;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 9999px;
    text-transform: uppercase;
}

.model-desc-text {
    font-size: 0.78rem;
    color: #64748b;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 380px;
}

.model-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.admin-model-item-card .btn,
.admin-ollama-item .btn {
    border-radius: 9999px;
    padding: 4px 12px;
    font-weight: 600;
    transition: all 0.16s ease;
}

.admin-ollama-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 600px;
    overflow-y: auto;
}

.admin-ollama-item {
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 14px;
    padding: 11px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.admin-ollama-item:hover {
    border-color: #cbd5e1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.ollama-tag-name {
    font-size: 0.84rem;
    font-weight: 600;
    color: #0284c7;
    background: rgba(2, 132, 199, 0.08);
    padding: 3px 10px;
    border-radius: 9999px;
    font-family: monospace;
}

.ollama-size-badge {
    font-size: 0.72rem;
    font-weight: 600;
    color: #64748b;
    background: #e2e8f0;
    padding: 3px 8px;
    border-radius: 9999px;
    margin-left: 6px;
}

.admin-loading-placeholder {
    text-align: center;
    padding: 28px;
    color: #64748b;
    font-size: 0.88rem;
}

/* Dark mode */
body.dark-theme .admin-models-hero-card,
body.dark-theme .admin-stat-card,
body.dark-theme .admin-models-column {
    background: #1e293b;
    border-color: #334155;
    color: #f1f5f9;
}

body.dark-theme .admin-models-hero-main h2,
body.dark-theme .col-title-wrap h3,
body.dark-theme .stat-num,
body.dark-theme .model-item-title {
    color: #f8fafc;
}

body.dark-theme .admin-models-hero-main p,
body.dark-theme .stat-label,
body.dark-theme .col-subdesc,
body.dark-theme .model-desc-text {
    color: #94a3b8;
}

body.dark-theme .admin-model-item-card,
body.dark-theme .admin-ollama-item {
    background: #0f172a;
    border-color: #334155;
}

body.dark-theme .admin-model-item-card.is-default {
    background: #064e3b;
    border-color: #059669;
}

body.dark-theme .admin-search-input {
    background: #0f172a;
    border-color: #334155;
    color: #f8fafc;
}

body.dark-theme .model-chip-icon {
    background: #1e293b;
    border-color: #334155;
}

body.dark-theme .ollama-tag-name {
    color: #e2e8f0;
}

@media (max-width: 900px) {
    .admin-models-layout {
        grid-template-columns: 1fr;
    }
    .admin-models-hero-card {
        flex-direction: column;
        align-items: flex-start;
    }
}


#tab-admin-models {
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    min-width: 0;
    width: 100%;
    padding: 1.5rem;
}

.admin-auth-notice-card {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 12px;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

body.dark-theme .admin-auth-notice-card {
    background: #451a03;
    border-color: #78350f;
}

body.dark-theme .admin-auth-notice-card strong {
    color: #fef3c7 !important;
}

body.dark-theme .admin-auth-notice-card span {
    color: #fde68a !important;
}


/* ==========================================================================
   AI PLAYGROUND: LLM PARAMETERS CUSTOMIZATION (DRAWER & PRESETS)
   Cho phep tuy bien sieu tham so Ollama: Temperature, num_ctx, top_p, etc.
   ========================================================================== */

.dock-params-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 9999px !important;
    padding: 0.35rem 0.75rem !important;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.dock-params-btn:hover {
    border-color: #4f46e5 !important;
    color: #4f46e5 !important;
    background: rgba(79, 70, 229, 0.06) !important;
}

.dock-params-btn.active {
    background: #eef2ff !important;
    border-color: #6366f1 !important;
    color: #4338ca !important;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.params-active-badge {
    background: #ecfdf5;
    color: #059669;
    font-weight: 700;
    border: 1px solid #a7f3d0;
    border-radius: 9999px;
    padding: 1px 7px;
    font-size: 0.68rem;
    font-family: 'JetBrains Mono', monospace;
    display: inline-flex;
    align-items: center;
}

.chat-params-drawer {
    width: 100%;
    max-height: 480px;
    overflow-y: auto;
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    border-radius: 16px;
    padding: 14px 18px;
    margin: 8px 0 10px 0;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.06), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    animation: drawerSlideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    position: relative;
    z-index: 60;
}

.chat-params-drawer.is-open {
    display: block !important;
}

.chat-params-drawer:not(.is-open) {
    display: none;
}

@keyframes drawerSlideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.params-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f1f5f9;
}

.params-drawer-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
}

.params-presets-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.preset-label {
    font-size: 0.74rem;
    font-weight: 600;
    color: #64748b;
    margin-right: 2px;
}

.param-preset-pill {
    border-radius: 9999px !important;
    padding: 4px 10px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #475569;
    transition: all 0.16s ease;
    user-select: none;
}

.param-preset-pill:hover {
    background: #eef2ff;
    color: #4338ca;
    border-color: #c7d2fe;
}

.param-preset-pill.active {
    background: #4f46e5;
    color: #ffffff;
    border-color: #4f46e5;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.28);
}

.params-drawer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.param-field-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.param-field-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.param-field-head label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #334155;
    margin: 0;
}

.param-val-pill {
    border-radius: 9999px;
    padding: 2px 8px;
    font-size: 0.74rem;
    font-weight: 700;
    background: #e0e7ff;
    color: #4338ca;
    font-family: 'JetBrains Mono', monospace;
}

.param-range-slider {
    width: 100%;
    height: 6px;
    border-radius: 9999px;
    accent-color: #4f46e5;
    outline: none;
    cursor: pointer;
    margin: 4px 0;
}

.param-field-hints {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: #94a3b8;
}

.param-select-control {
    width: 100%;
    border-radius: 9999px !important;
    padding: 5px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    outline: none;
    cursor: pointer;
}

.param-select-control:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.param-field-full {
    grid-column: 1 / -1;
}

.param-hint-tag {
    font-size: 0.7rem;
    font-weight: 500;
    color: #94a3b8;
    background: #f1f5f9;
    padding: 1px 6px;
    border-radius: 6px;
}

.param-textarea-control {
    width: 100%;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
    background: #ffffff;
    color: #0f172a;
    transition: border-color 0.15s ease;
}

.param-textarea-control:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.12);
}

.params-drawer-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #f1f5f9;
}

/* DARK THEME STYLING FOR PARAMETERS DRAWER */
body.dark-theme .dock-params-btn.active {
    background: #312e81 !important;
    border-color: #6366f1 !important;
    color: #e0e7ff !important;
}

body.dark-theme .params-active-badge {
    background: #064e3b;
    color: #6ee7b7;
    border-color: #047857;
}

body.dark-theme .chat-params-drawer {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}

body.dark-theme .params-drawer-header,
body.dark-theme .params-drawer-footer {
    border-color: #334155;
}

body.dark-theme .params-drawer-title {
    color: #f8fafc;
}

body.dark-theme .param-preset-pill {
    background: #0f172a;
    border-color: #334155;
    color: #cbd5e1;
}

body.dark-theme .param-preset-pill:hover {
    background: #1e293b;
    color: #818cf8;
    border-color: #4f46e5;
}

body.dark-theme .param-preset-pill.active {
    background: #4f46e5;
    color: #ffffff;
    border-color: #6366f1;
}

body.dark-theme .param-field-item {
    background: #0f172a;
    border-color: #334155;
}

body.dark-theme .param-field-head label {
    color: #e2e8f0;
}

body.dark-theme .param-val-pill {
    background: #312e81;
    color: #c7d2fe;
}

body.dark-theme .param-select-control {
    background: #1e293b;
    border-color: #475569;
    color: #f8fafc;
}

body.dark-theme .param-textarea-control {
    background: #1e293b;
    border-color: #475569;
    color: #f8fafc;
}



/* ==========================================================================
   AI PLAYGROUND: STABLE DIFFUSION 1.5 IMAGE STUDIO STYLING
   ========================================================================== */
#tab-image-gen {
    height: 100%;
    overflow: hidden;
}

.image-gen-container {
    display: flex;
    height: 100%;
    width: 100%;
    overflow: hidden;
    background: var(--bg-base);
}

/* Cột trái: Điều khiển & Prompt */
.image-gen-sidebar {
    width: 440px;
    min-width: 360px;
    height: 100%;
    overflow-y: auto;
    padding: 1.25rem;
    border-right: 1px solid var(--border-color);
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex-shrink: 0;
}

.image-gen-card {
    display: flex;
    flex-direction: column;
}

.gen-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.1rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border-color);
}

.gen-title-group {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-primary);
}

.gen-title-group h3 {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.label-with-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.btn-text-action {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.btn-text-action:hover {
    background: rgba(79, 70, 229, 0.08);
}

/* Box bật/tắt Tối ưu Prompt bằng Ollama */
.enhance-prompt-box {
    background: var(--bg-surface-elevated, #f8fafc);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.75rem 0.9rem;
    margin-bottom: 1rem;
}

.switch-toggle-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    user-select: none;
    margin: 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
}

.switch-toggle-label input {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Lưới phong cách nghệ thuật (Style Grid) */
.sd-style-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.sd-style-pill {
    padding: 6px 4px;
    border-radius: 9999px !important;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: all 0.16s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sd-style-pill:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(79, 70, 229, 0.04);
}

.sd-style-pill.active {
    background: var(--primary) !important;
    color: #ffffff !important;
    border-color: var(--primary) !important;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.28);
}

/* Tỷ lệ & Kích thước */
.sd-ratio-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.sd-ratio-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 6px;
    border-radius: 12px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.16s ease;
}

.sd-ratio-btn span {
    font-weight: 700;
    font-size: 0.86rem;
}

.sd-ratio-btn small {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.sd-ratio-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.sd-ratio-btn.active {
    background: rgba(79, 70, 229, 0.08);
    border-color: var(--primary);
    color: var(--primary);
}

/* Cài đặt nâng cao (Collapse) */
.sd-advanced-collapse {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.sd-advanced-toggle {
    width: 100%;
    padding: 9px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface-elevated, #f8fafc);
    border: none;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s ease;
}

.sd-advanced-toggle:hover {
    color: var(--text-primary);
}

.sd-advanced-panel {
    padding: 10px 12px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
}

/* Cột phải: Canvas & Gallery */
.image-gen-main {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    padding: 1.25rem 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sd-canvas-card {
    background: var(--bg-surface);
    border: 1.5px solid var(--border-color);
    border-radius: 20px;
    padding: 1.25rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sd-canvas-wrapper {
    position: relative;
    width: 100%;
    min-height: 480px;
    max-height: 580px;
    background: #0f172a;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Empty state */
.sd-empty-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: #94a3b8;
    max-width: 480px;
}

.sd-empty-icon {
    font-size: 3.5rem;
    margin-bottom: 0.75rem;
    animation: floatIcon 3s ease-in-out infinite;
}

@keyframes floatIcon {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.sd-empty-state h3 {
    color: #f8fafc;
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.sd-empty-state p {
    font-size: 0.85rem;
    line-height: 1.5;
}

/* Loading state */
.sd-loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1.5rem;
    color: #ffffff;
}

.spinner-lg {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1.25rem;
}

.sd-loading-progress-bar {
    width: 280px;
    height: 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 9999px;
    overflow: hidden;
    margin-top: 1rem;
}

.sd-progress-fill {
    width: 40%;
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #06b6d4);
    border-radius: 9999px;
    animation: indeterminateProgress 1.6s ease-in-out infinite;
}

@keyframes indeterminateProgress {
    0% { transform: translateX(-100%); width: 30%; }
    50% { width: 60%; }
    100% { transform: translateX(350%); width: 30%; }
}

/* Result image display */
.sd-result-state {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sd-main-img {
    max-width: 100%;
    max-height: 540px;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: fadeInImg 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInImg {
    from { opacity: 0; transform: scale(0.97); }
    to { opacity: 1; transform: scale(1); }
}

.sd-result-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem 1.25rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0) 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.sd-meta-badges {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.meta-tag {
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(8px);
    color: #ffffff;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.sd-actions-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Box hiển thị Prompt đã thực thi */
.sd-prompt-used-box {
    background: var(--bg-surface-elevated, #f8fafc);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.85rem 1.15rem;
}

.prompt-used-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.prompt-used-content {
    font-size: 0.84rem;
    color: var(--text-primary);
    line-height: 1.5;
    margin: 0;
    word-break: break-word;
}

/* Thư viện tác phẩm gần đây (History Gallery) */
.sd-history-section {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.sd-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sd-history-header h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.sd-history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.sd-history-card {
    position: relative;
    aspect-ratio: 1;
    border-radius: 14px;
    overflow: hidden;
    border: 1.5px solid var(--border-color);
    background: #0f172a;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.sd-history-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    border-color: var(--primary);
}

.sd-history-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sd-history-card-hover {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 8px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.sd-history-card:hover .sd-history-card-hover {
    opacity: 1;
}

.sd-history-prompt-preview {
    color: #ffffff;
    font-size: 0.72rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 6px;
}

.sd-history-card-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}

.sd-history-card-actions button,
.sd-history-card-actions a {
    padding: 3px 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    font-size: 0.7rem;
    border: none;
    cursor: pointer;
    text-decoration: none;
}

.sd-history-card-actions button:hover,
.sd-history-card-actions a:hover {
    background: var(--primary);
}

/* Dark mode styling */
body.dark-theme .enhance-prompt-box,
body.dark-theme .sd-advanced-toggle,
body.dark-theme .sd-prompt-used-box {
    background: #1e293b;
    border-color: #334155;
}

body.dark-theme .sd-style-pill {
    background: #1e293b;
    border-color: #334155;
    color: #cbd5e1;
}

body.dark-theme .sd-ratio-btn {
    background: #1e293b;
    border-color: #334155;
    color: #cbd5e1;
}

body.dark-theme .sd-canvas-card {
    background: #1e293b;
    border-color: #334155;
}

@media (max-width: 900px) {
    .image-gen-container {
        flex-direction: column;
        overflow-y: auto;
    }
    .image-gen-sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .image-gen-main {
        height: auto;
        padding: 1rem;
    }
    .sd-canvas-wrapper {
        min-height: 340px;
    }
}

/* SD 1.5 Model & GPU Status Card */
.sd-status-card {
    background: var(--bg-hover, #f8fafc);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    padding: 0.75rem 0.85rem;
    margin-bottom: 0.85rem;
    transition: all 0.2s ease;
}

.sd-status-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

.sd-status-indicator {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.sd-status-desc {
    font-size: 0.76rem;
    color: var(--text-muted, #64748b);
    line-height: 1.4;
}

.sd-progress-box {
    margin-top: 0.65rem;
    padding: 0.65rem;
    background: rgba(79, 70, 229, 0.05);
    border: 1px solid rgba(79, 70, 229, 0.15);
    border-radius: 8px;
}

.sd-progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.74rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--primary, #4f46e5);
}

.sd-progress-bar-bg {
    width: 100%;
    height: 7px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.4rem;
}

.sd-progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #4f46e5, #06b6d4);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.sd-progress-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted, #64748b);
}

.sd-progress-note {
    display: block;
    font-size: 0.69rem;
    color: #b45309;
    background: #fef3c7;
    padding: 4px 6px;
    border-radius: 6px;
    margin-top: 0.45rem;
    line-height: 1.35;
}

body.dark-theme .sd-status-card {
    background: #1e293b;
    border-color: #334155;
}

body.dark-theme .sd-progress-box {
    background: rgba(79, 70, 229, 0.15);
    border-color: rgba(79, 70, 229, 0.3);
}

body.dark-theme .sd-progress-bar-bg {
    background: #334155;
}

body.dark-theme .sd-progress-note {
    background: rgba(180, 83, 9, 0.25);
    color: #fde68a;
}

