/* ==========================================================================
   Trợ Lý Học Tập Cục Bộ — giao diện tối + tím phẳng (phong cách Echo AI)
   Chỉ đổi màu sắc / hình thức. Không đổi ID, class, văn bản hay logic JS.
   ========================================================================== */
:root {
    color-scheme: dark;

    --bg-main: #0e1117;
    --bg-sidebar: rgba(19, 22, 31, 0.85);
    --bg-card: rgba(22, 26, 35, 0.72);
    --bg-elev: #181c26;
    --bg-input: rgba(22, 26, 35, 0.85);
    --bg-subtle: #1a1e28;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(251, 113, 133, 0.28);

    --primary: #f43f5e;
    --primary-hover: #fb7185;
    --primary-light: rgba(244, 63, 94, 0.12);
    --primary-border: rgba(251, 113, 133, 0.35);
    --accent: #fb7185;
    --grad: #f43f5e;
    --grad-soft: #fb7185;

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.12);

    --radius: 18px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.35);
    --shadow-md: 0 8px 24px -4px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.65);
    --glow: 0 0 0 1px rgba(251, 113, 133, 0.3), 0 8px 30px -4px rgba(244, 63, 94, 0.35);

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

button, input, select, textarea {
    font-family: inherit;
}

/* Thanh cuộn tối, mảnh */
* { scrollbar-width: thin; scrollbar-color: #3a3b44 transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #3a3b44; border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: #4b4c57; }

body {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(244, 63, 94, 0.35); color: #fff; }

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ----------------------------- Sidebar ----------------------------------- */
.sidebar {
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 18px 16px;
    gap: 16px;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Biểu tượng thương hiệu với logo mới */
.brand-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    overflow: hidden;
    border: 1px solid rgba(251, 113, 133, 0.35);
    box-shadow: 0 0 16px rgba(244, 63, 94, 0.25);
    flex-shrink: 0;
    background: #181c26;
}

.brand-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.brand-text h2 {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 9999px;
}

.badge.local {
    background: rgba(52, 211, 153, 0.1);
    color: #6ee7b7;
    border: 1px solid rgba(52, 211, 153, 0.3);
}

.sidebar-card {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.sidebar-card h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.history-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.history-heading h3 { margin-bottom: 0; }
.history-heading button { white-space: nowrap; }
.history-note { color: var(--text-muted); font-size: 12px; margin: 8px 0; }
.history-list { max-height: 220px; overflow-y: auto; font-size: 13px; }
.history-item { display: flex; align-items: center; border-top: 1px solid var(--border); }
.history-open { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; padding: 9px 2px; border: 0; background: transparent; color: var(--text-primary); cursor: pointer; }
.history-open:hover { color: var(--primary-hover); }
.history-delete { border: 0; background: transparent; color: var(--text-muted); font-size: 20px; cursor: pointer; padding: 2px 7px; }
.history-delete:hover { color: var(--danger); }

/* Multi-turn Session Styles */
.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 8px;
    border-top: 1px solid var(--border);
    border-radius: 10px;
    transition: background 0.15s ease;
}
.session-item:hover {
    background: rgba(255, 255, 255, 0.05);
}
.session-item.active {
    background: var(--bg-elev);
    border-left: 3px solid var(--primary);
    box-shadow: inset 0 0 0 1px rgba(251, 113, 133, 0.25);
}
.session-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
    text-align: left;
    background: none;
    border: none;
    padding: 0;
}
.session-title-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}
.session-item:hover .session-title-text { color: var(--text-primary); }
.session-item.active .session-title-text {
    color: var(--text-primary);
    font-weight: 600;
}
.session-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}
.session-badge {
    background: #2d2e35;
    color: var(--text-secondary);
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
}
.session-item.active .session-badge {
    background: rgba(244, 63, 94, 0.2);
    color: #fda4af;
}
.session-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    opacity: 0.5;
    transition: opacity 0.15s;
}
.session-item:hover .session-actions {
    opacity: 1;
}
.session-action-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 2px 4px;
    font-size: 12px;
    color: var(--text-muted);
    border-radius: 4px;
}
.session-action-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}
.session-action-btn.btn-del:hover {
    color: var(--danger);
}
.legacy-history-divider {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    padding: 8px 4px 4px 4px;
    margin-top: 6px;
    border-top: 2px dashed var(--border);
}

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}

.stat-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 10px;
    text-align: center;
}

.stat-num {
    display: block;
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.form-select, .form-input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-select:focus, .form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.2);
}

.form-input::placeholder { color: var(--text-muted); }

.form-range {
    width: 100%;
    accent-color: var(--primary);
}

.status-indicator {
    font-size: 11px;
    margin-top: 4px;
    display: block;
}

.status-indicator.connected {
    color: var(--success);
}

.status-indicator.disconnected {
    color: var(--danger);
}

.sidebar-footer {
    margin-top: auto;
}

.disclaimer-mini {
    font-size: 11px;
    color: #e9d08a;
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.25);
    padding: 10px;
    border-radius: 12px;
    line-height: 1.4;
}

/* ----------------------------- Buttons ----------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--grad);
    color: #fff;
    box-shadow: 0 4px 16px -4px rgba(244, 63, 94, 0.45);
}

.btn-primary:hover {
    filter: brightness(1.12);
    box-shadow: 0 6px 22px -4px rgba(251, 113, 133, 0.6);
}

.btn-secondary {
    background: var(--bg-elev);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: #2e2f36;
    border-color: var(--border-strong);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
}

.btn-outline:hover {
    background: var(--primary-light);
    border-color: var(--primary-border);
    color: #fff;
}

.btn-sm {
    padding: 7px 12px;
    font-size: 12px;
}

.btn-icon {
    background: transparent;
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
}

.btn-icon:hover {
    background: var(--primary-light);
    border-color: var(--primary-border);
    color: #fff;
}

.w-full {
    width: 100%;
}

.mt-2 {
    margin-top: 8px;
}

.mt-3 {
    margin-top: 12px;
}

/* --------------------------- Main content -------------------------------- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-main);
    position: relative;
    overflow: hidden;
    min-width: 0;
}

.main-content::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background: transparent;
}
.main-content > * {
    position: relative;
    z-index: 1;
}

.chat-header {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: rgba(8, 12, 36, 0.8);
    border-bottom: 1px solid var(--border);
    padding: 10px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 10;
}
.chat-header .header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.chat-header .subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ------------------------------ Messages --------------------------------- */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message {
    display: flex;
    gap: 14px;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--grad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    flex-shrink: 0;
    box-shadow: 0 0 16px rgba(244, 63, 94, 0.35);
}

.message.user .message-avatar {
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    box-shadow: none;
}

.message-body {
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    flex: 1;
    min-width: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow-sm);
    line-height: 1.7;
    font-size: 14.5px;
    color: var(--text-primary);
}

.message.user .message-body {
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    background: rgba(244, 63, 94, 0.08);
    border-color: rgba(251, 113, 133, 0.25);
}

.message-user-col {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.message-user-col .message-body {
    width: 100%;
}

.message-body code {
    background: #2a2b31;
    color: #fda4af;
    padding: 1px 6px;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.9em;
}
.message-body h2, .message-body h3, .message-body h4 { margin: 10px 0 6px; }
.message-body li { margin-left: 20px; }
.typing-indicator { color: var(--text-secondary); animation: pulse-text 1.4s ease-in-out infinite; }
@keyframes pulse-text { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.truncation-warning { color: #fcd34d; }

.welcome-card {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 20px;
    border: 1px solid var(--border);
    padding: 1px;
    box-shadow: 0 10px 40px -12px rgba(244, 63, 94, 0.25);
}

.welcome-card .message-avatar { margin: 14px 0 0 14px; }
.welcome-card .message-body {
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px); border-radius: 20px; background: var(--bg-card); }

.welcome-card h3 {
    font-size: 16px;
    margin-bottom: 8px;
}

.suggestion-chips {
    margin-top: 18px;
    display: grid;
    grid-template-columns: repeat(2, minmax(240px, 1fr));
    gap: 12px 16px;
    justify-content: center;
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
}

.suggestion-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.chip {
    background: var(--primary-light);
    color: var(--text-secondary);
    border: 1px solid rgba(251, 113, 133, 0.25);
    border-radius: 9999px;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    justify-content: center;
    white-space: nowrap;
    transition: all 0.2s;
}

.chip:hover {
    background: rgba(45, 22, 39, 0.55);
    border-color: rgba(251, 113, 133, 0.4);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px -4px rgba(244, 63, 94, 0.3);
}

/* Citations & Sources Box */
.citations-box {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px dashed var(--border-strong);
}

.citations-header {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.citations-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.citation-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 12.5px;
}

.citation-title {
    font-weight: 600;
    color: #fb7185;
    display: flex;
    justify-content: space-between;
}

.citation-page {
    background: #31323a;
    color: var(--text-secondary);
    padding: 1px 6px;
    border-radius: 6px;
    font-size: 11px;
    font-family: var(--font-mono);
}

.citation-snippet {
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 12px;
    font-style: italic;
    background: var(--bg-input);
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* Crisis Banner */
.crisis-box {
    background: var(--danger-light) !important;
    border: 2px solid var(--danger) !important;
    color: #fecaca !important;
}

.crisis-box h3 {
    color: #fecaca;
}

/* ---------------------------- Input area --------------------------------- */
.input-area {
    background: var(--bg-main);
    border-top: 1px solid var(--border);
    padding: 12px 24px 16px;
}

.qa-answer-mode {
    max-width: 860px;
    margin: 0 auto 8px;
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--text-muted);
    font-size: 0.78rem;
}
.qa-answer-mode label { color: var(--text-secondary); font-weight: 600; }
.qa-answer-mode .form-select { width: auto; min-width: 190px; padding: 6px 30px 6px 10px; }

/* Khung nhập: viền tím + ánh sáng như hình mẫu */
.chat-form {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    max-width: 860px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    padding: 10px 10px 10px 16px;
    border: 1px solid var(--primary-border);
    border-radius: 22px;
    background: var(--bg-input);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.chat-form:focus-within {
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(251, 113, 133, 0.15);
}

.chat-form textarea {
    flex: 1;
    padding: 10px 4px;
    border-radius: 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14.5px;
    resize: none;
    outline: none;
    max-height: 140px;
    line-height: 1.5;
}

.chat-form textarea::placeholder { color: var(--text-muted); }

.chat-form textarea:focus {
    border-color: transparent;
    box-shadow: none;
}

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--primary);
    color: #fff;
    border: 1px solid rgba(251, 113, 133, 0.4);
    box-shadow: 0 4px 14px rgba(244, 63, 94, 0.35);
    cursor: pointer;
    transition: all 0.25s ease;
}
.btn-send:hover {
    filter: brightness(1.18);
    transform: scale(1.05);
    box-shadow: 0 6px 18px rgba(244, 63, 94, 0.45);
}
.btn-send .send-text { display: none; }
.btn-send .send-icon { font-size: 16px; margin: 0; }

.input-hint {
    max-width: 860px;
    margin: 8px auto 0;
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
}
.input-hint strong { color: var(--text-secondary); }

.qa-recovery-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.context-trim-notice {
    margin-top: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.78rem;
}

/* ------------------------------- Modals ---------------------------------- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(8, 8, 12, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}

.modal.active,
.modal[style*="display: block"],
.modal[style*="display: flex"] {
    display: flex !important;
}

.modal-content {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    max-width: 850px;
    width: min(850px, calc(100vw - 32px));
    max-height: min(88vh, 850px);
    margin: auto;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg), 0 0 60px -20px rgba(244, 63, 94, 0.35);
    position: relative;
}

.modal-content.modal-sm {
    max-width: 420px;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.btn-close-modal {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
}

.btn-close-modal:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.table-responsive {
    overflow-x: auto;
}

.kb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.kb-table th, .kb-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.kb-table th {
    background: var(--bg-elev);
    font-weight: 600;
    color: var(--text-secondary);
}

.badge-status {
    padding: 3px 8px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
}

.badge-status.indexed {
    background: rgba(52, 211, 153, 0.12);
    color: #6ee7b7;
}

.badge-status.scanned {
    background: rgba(251, 191, 36, 0.12);
    color: #fcd34d;
}

.badge-status.error {
    background: rgba(248, 113, 113, 0.12);
    color: #fca5a5;
}

/* Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #34353d;
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

.text-center {
    text-align: center;
}

.text-sm {
    font-size: 12px;
}

.text-muted {
    color: var(--text-muted);
}

.session-rename-dialog {
    width: min(420px, 90vw);
    margin: auto;
    padding: 24px;
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
}
.session-rename-dialog::backdrop { background: rgba(8, 8, 12, .65); backdrop-filter: blur(4px); }
.session-rename-dialog label { display: block; margin-bottom: 12px; font-weight: 600; }
.session-rename-dialog input { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--bg-input); color: var(--text-primary); outline: none; }
.session-rename-dialog input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.2); }
.session-rename-dialog form > div { display: flex; justify-content: flex-end; gap: 12px; margin-top: 16px; }
.session-rename-dialog button { padding: 8px 16px; cursor: pointer; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--bg-elev); color: var(--text-primary); font-family: inherit; }
.session-rename-dialog button:hover { border-color: var(--primary-border); }
.session-rename-dialog button[type="submit"] { background: var(--grad); border-color: transparent; color: #fff; }

/* -------- Chế độ: Hỏi đáp / Tra cứu tài liệu / Thời khóa biểu ------------ */
[hidden] { display: none !important; }
.mode-switch { display: flex; gap: 8px; padding: 12px 20px; background: transparent; border-bottom: 1px solid rgba(255, 255, 255, 0.06); flex-wrap: wrap; }
.mode-button { border: 1px solid var(--border-strong); background: rgba(255, 255, 255, 0.03); border-radius: 12px; padding: 10px 14px; font: inherit; cursor: pointer; color: var(--text-secondary); transition: all 0.2s; }
.mode-button:hover { border-color: var(--primary-border); color: #fff; background: var(--primary-light); }
.mode-button.active {
    background: var(--grad);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 10px rgba(244, 63, 94, 0.35);
}
.mode-button:focus-visible, .document-result a:focus-visible { outline: 3px solid rgba(251, 113, 133, 0.5); outline-offset: 2px; }
.qa-panel { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.documents-panel { flex: 1; overflow-y: auto; padding: 24px; min-height: 0; }
.documents-panel h2 { font-size: 20px; margin-bottom: 8px; }
.lookup-description, #document-search-status { color: var(--text-secondary); font-size: 14px; line-height: 1.5; margin: 8px 0 16px; }
.document-search-form > label { display: block; margin: 12px 0 6px; }
#document-query { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 12px; font: inherit; background: var(--bg-input); color: var(--text-primary); }
.document-filters { display: flex; gap: 12px; align-items: end; margin-top: 12px; }
.document-filters > div { flex: 1; min-width: 0; }
.document-filters label { display: block; margin-bottom: 6px; font-size: 13px; }
.document-filters > .btn { min-height: 44px; padding: 10px 16px; white-space: nowrap; }
.document-results { display: flex; flex-direction: column; gap: 16px; }
.document-result { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; overflow-wrap: anywhere; }
.document-result h3 { font-size: 16px; line-height: 1.5; }
.document-page { font-size: 13px; color: var(--text-secondary); margin: 5px 0 12px; }
.document-passage { white-space: pre-wrap; line-height: 1.65; font-size: 14px; }
.document-result-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.document-result-actions a { text-decoration: none; }

/* Timetable panel styles */
.timetable-panel {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    min-height: 0;
}

/* Source-grounded practice and browser-local review list. */
.practice-review-link,
.study-dialog-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}
.practice-review-link { justify-content: space-between; font-size: 0.78rem; }
.study-dialog {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(760px, calc(100vw - 32px));
    max-height: min(86vh, 900px);
    display: flex;
    flex-direction: column;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text-primary);
    background: var(--bg-card);
    box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
    z-index: 1000;
}
.study-dialog:not([open]) {
    display: none;
}
.study-dialog::backdrop {
    background: rgba(8, 8, 12, .65);
    backdrop-filter: blur(4px);
}
.study-dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    padding: 18px 22px 12px;
    border-bottom: 1px solid var(--border);
}
.study-dialog-header h2 { margin: 0; font-size: 1.15rem; }
.study-dialog-header p { margin: 5px 0 0; font-size: .82rem; }
.study-dialog-header .btn-close-modal { flex: 0 0 auto; }
.study-dialog-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 18px 22px 22px;
    overflow-y: auto;
}
.study-dialog-actions { justify-content: flex-start; }
.study-dialog-actions button { min-height: 38px; }
.study-dialog-actions .btn-primary { margin-left: auto; }
.practice-progress { margin: 0 0 8px; font-size: .82rem; }
.practice-question { margin: 0 0 10px; font-size: 1.05rem; line-height: 1.5; }
.practice-source-label { margin: 0 0 14px; color: var(--text-muted); font-size: .82rem; }
.practice-choices { display: grid; gap: 8px; margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.practice-choices legend { padding: 0 6px; font-size: .83rem; color: var(--text-secondary); }
.practice-choice { display: flex; align-items: flex-start; gap: 9px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; line-height: 1.45; }
.practice-choice:has(input:checked) { border-color: var(--primary); background: var(--primary-light); }
.practice-choice input { margin: 3px 0 0; }
.practice-result { margin: 0 0 12px; font-weight: 700; }
.practice-result.correct { color: #15803d; }
.practice-result.incorrect, .practice-error { color: #b91c1c; }
.practice-answer-key { margin: 0 0 8px; font-weight: 650; }
.practice-explanation { margin: 0 0 14px; line-height: 1.55; }
.practice-evidence { display: grid; gap: 8px; margin-top: 12px; padding: 12px; border-left: 3px solid var(--primary); border-radius: 6px; background: var(--bg-subtle); font-size: .84rem; }
.practice-evidence blockquote { margin: 0; padding-left: 10px; border-left: 2px solid #cbd5e1; line-height: 1.55; }
.practice-evidence a { width: fit-content; }
.practice-saved-status { color: #15803d; font-size: .84rem; }
.review-item { margin-bottom: 14px; padding: 14px; border: 1px solid var(--border); border-radius: 10px; }
.review-item h3 { margin: 0 0 8px; font-size: .98rem; line-height: 1.45; }
.review-item > p { line-height: 1.5; }
.review-status { color: #a16207; font-size: .8rem; }
.review-status.reviewed { color: #15803d; }
.study-dialog-actions .practice-saved-status { margin-right: auto; }
@media (max-width: 600px) {
    .study-dialog-header, .study-dialog-body { padding-left: 14px; padding-right: 14px; }
    .practice-review-link { align-items: flex-start; flex-direction: column; }
    #qa-source-scope { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
    .study-dialog-actions button { flex: 1 1 auto; }
}
.source-page-image {
    display: block;
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    margin: 10px 0;
    background: white;
}
.document-result details { margin-top: 10px; }
.document-result summary { cursor: pointer; }

/* Khối trích dẫn đối chiếu nguồn trang - Chế độ tối mặc định */
.citations-block {
    margin-top: 12px;
    padding: 12px 14px;
    background-color: var(--bg-elev);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 8px;
    font-size: 0.84rem;
    color: var(--text-primary);
}
.citations-block .citations-heading {
    display: block;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.citations-block .citation-detail {
    margin-top: 8px;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
}
.citations-block .citation-summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    outline: none;
    list-style-position: inside;
}
.citations-block .citation-summary:hover {
    color: var(--primary);
}
.citations-block .citation-preview-link {
    display: block;
    margin-top: 8px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-main);
    color: var(--primary);
    text-decoration: none;
}
.citations-block .citation-preview-link:hover {
    border-color: var(--primary);
}
.citations-block .source-page-image {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    background: var(--bg-card);
}
.citations-block .citation-hint {
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}
.citations-block .citation-text-fallback {
    margin-top: 6px;
    padding: 6px 10px;
    font-size: 0.8rem;
    background: var(--bg-main);
    border: 1px dashed var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
}
.timetable-header h2 {
    font-size: 20px;
    margin-bottom: 6px;
}
.timetable-grid {
    display: grid;
    grid-template-columns: minmax(0, 440px) minmax(0, 1fr);
    gap: 20px;
    margin-top: 16px;
    align-items: start;
    width: 100%;
}
.timetable-col-left,
.timetable-col-right {
    min-width: 0;
    max-width: 100%;
    width: 100%;
}
.timetable-card {
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    min-width: 0;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
}
.timetable-card .table-responsive {
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* One learning-tools destination with three focused tabs. */
.learning-tools-panel { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 24px 28px; }
.tool-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin: 0 0 16px; }
.tool-tab-button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--text-secondary); padding: 10px 14px; font: inherit; cursor: pointer; }
.tool-tab-button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 650; }
.tool-tab-button:focus-visible { outline: 3px solid var(--primary-hover); outline-offset: 2px; }
.tool-tab-button span { display: inline-flex; min-width: 1.5em; justify-content: center; margin-left: 4px; padding: 0 5px; border-radius: 999px; background: var(--primary-light); color: var(--primary); font-size: .75rem; }
.tool-tab-panel { min-height: 0; }
.tool-practice-scope, .tool-panel-header { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 16px; }
.tool-practice-scope h2, .tool-panel-header h2 { font-size: 1.15rem; margin-bottom: 4px; }
.tool-practice-scope p, .tool-panel-header p { margin: 0; }
.tool-practice-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.tool-status { margin: 12px 0; color: var(--text-secondary); }
.source-extraction-warning { margin: 10px 0; padding: 10px 12px; border: 1px solid #fbbf24; border-radius: 8px; color: #854d0e; background: #fffbeb; font-size: .88rem; }
.source-origin-label { font-weight: 650; }
.source-exercise-card .document-passage { max-height: 30rem; overflow: auto; }
.practice-examples-form { display: grid; grid-template-columns: minmax(180px, 2fr) minmax(90px, .7fr) minmax(90px, .7fr) auto; gap: 12px; align-items: end; margin: 16px 0; }
.practice-examples-form label { display: block; margin: 0 0 6px; color: var(--text-secondary); font-size: .85rem; }
.practice-examples-topic { grid-column: 1 / 4; }
.practice-examples-form button { min-height: 42px; padding: 9px 14px; }
@media (max-width: 600px) {
    .practice-examples-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
    .practice-examples-form > div { min-width: 0; }
    .practice-examples-form > div:first-child { grid-column: 1 / -1; }
    .practice-examples-topic { grid-column: 1 / -1; }
    .practice-examples-form button { grid-column: 1 / -1; width: 100%; }
}
.documents-panel { background: transparent; }
.document-result { background: var(--bg-card); }
.study-dialog { background: var(--bg-card); }

/* Learning tools new controls and cards */
.learning-topic-card, .learning-review-generator, .learning-exercise-search {
    margin-bottom: 20px;
}
.form-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.form-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.form-group label {
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.form-group.flex-1 {
    flex: 1 1 120px;
}
.form-group.flex-2 {
    flex: 2 1 240px;
}
.form-group.form-actions {
    flex: 0 0 auto;
}
.form-row.checkbox-row {
    align-items: center;
    margin-top: 6px;
}
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.88rem;
    color: var(--text-primary);
}
.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}
.advanced-source-selection {
    margin-top: 24px;
    padding: 12px 16px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    background: var(--bg-subtle);
}
.advanced-source-selection summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 4px 0;
}
.advanced-source-selection summary:hover {
    color: var(--primary);
}
.advanced-source-selection[open] summary {
    margin-bottom: 14px;
}
.learning-exercise-card {
    margin-bottom: 16px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
}
.exercise-question-title {
    margin: 0 0 8px 0;
    font-size: 1rem;
    line-height: 1.5;
}
.exercise-source-context {
    font-size: 0.85rem;
    color: var(--text-secondary, #475569);
    background: rgba(100, 116, 139, 0.08);
    border-left: 3px solid var(--accent, #3b82f6);
    padding: 6px 10px;
    margin-bottom: 8px;
    border-radius: 4px;
    line-height: 1.45;
}
.exercise-answer-section {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}
.exercise-answer-label {
    font-size: 0.88rem;
    color: var(--primary);
}
.exercise-answer-text {
    margin: 6px 0 10px 0;
    line-height: 1.5;
}

@media (max-width: 480px) {
    .form-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .form-group.flex-1,
    .form-group.flex-2 {
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }
    .form-group.form-actions {
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        box-sizing: border-box;
    }
    .form-group.form-actions button,
    .form-group.form-actions .btn {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        white-space: normal;
        word-break: break-word;
        text-align: center;
        justify-content: center;
    }
    .learning-tools-panel {
        padding: 10px 8px 16px;
    }
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme]) {
        color-scheme: dark;
        --bg-main: #0e1117;
        --bg-sidebar: rgba(19, 22, 31, 0.85);
        --bg-card: rgba(22, 26, 35, 0.72);
        --bg-subtle: #1a1e28;
        --text-primary: #f8fafc;
        --text-secondary: #cbd5e1;
        --text-muted: #94a3b8;
        --border: rgba(255, 255, 255, 0.08);
        --primary: #f43f5e;
        --primary-hover: #fb7185;
        --primary-light: rgba(244, 63, 94, 0.12);
        --danger-light: rgba(239, 68, 68, 0.12);
        --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
    }
    html:not([data-theme]) body, html:not([data-theme]) .main-content { background-color: var(--bg-main); color: var(--text-primary); }
    html:not([data-theme]) .sidebar, html:not([data-theme]) .chat-header, html:not([data-theme]) .mode-switch, html:not([data-theme]) .input-area, html:not([data-theme]) .form-select, html:not([data-theme]) .form-input,
    html:not([data-theme]) .chat-form textarea, html:not([data-theme]) .message-body, html:not([data-theme]) .welcome-card, html:not([data-theme]) .modal-content, html:not([data-theme]) .stat-item,
    html:not([data-theme]) .document-result, html:not([data-theme]) .study-dialog, html:not([data-theme]) .timetable-card {
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px); background: var(--bg-card); color: var(--text-primary); }
    html:not([data-theme]) .sidebar-card, html:not([data-theme]) .message.user .message-body, html:not([data-theme]) .citation-card, html:not([data-theme]) .practice-evidence,
    html:not([data-theme]) .tool-tabs, html:not([data-theme]) .practice-choice:has(input:checked), html:not([data-theme]) .timetable-dropzone { background: var(--bg-subtle); color: var(--text-primary); }
    html:not([data-theme]) .mode-button:not(.active) { background: var(--bg-card); color: var(--text-secondary); }
    html:not([data-theme]) .mode-button.active { color: #fff; }
    html:not([data-theme]) .tool-tab-button { color: var(--text-secondary); }
    html:not([data-theme]) .tool-tab-button.active { color: var(--primary); }
    html:not([data-theme]) .form-select, html:not([data-theme]) .form-input, html:not([data-theme]) .chat-form textarea { border-color: var(--border); color: var(--text-primary); }
    html:not([data-theme]) .btn-secondary { background: #334155; color: var(--text-primary); }
    html:not([data-theme]) .btn-secondary:hover, html:not([data-theme]) .btn-outline:hover { background: #273449; color: var(--text-primary); }
    html:not([data-theme]) .source-page-image { background: var(--bg-card); }
    html:not([data-theme]) .session-item:hover { background: rgb(148 163 184 / .08); }
    html:not([data-theme]) .session-item.active { background: rgb(244 63 94 / .12); }
    html:not([data-theme]) .session-badge, html:not([data-theme]) .citation-page { background: #334155; color: #e2e8f0; }
    html:not([data-theme]) .citation-snippet { background: var(--bg-card); border-color: var(--border); }
    html:not([data-theme]) .source-extraction-warning { color: #fde68a; background: #422006; border-color: #92400e; }
    html:not([data-theme]) .practice-result.correct, html:not([data-theme]) .practice-saved-status, html:not([data-theme]) .review-status.reviewed { color: #86efac; }
    html:not([data-theme]) .practice-result.incorrect, html:not([data-theme]) .practice-error { color: #fca5a5; }
    html:not([data-theme]) .review-status { color: #fcd34d; }
    html:not([data-theme]) .crisis-box, html:not([data-theme]) .crisis-box h3 { color: #fecaca !important; }
    html:not([data-theme]) a { color: #fb7185; }
}
.timetable-card h3 {
    font-size: 15px;
    margin: 0 0 10px 0;
    color: var(--text-primary);
}
.timetable-dropzone {
    border: 2px dashed var(--border-strong);
    border-radius: 16px;
    padding: 28px 16px;
    text-align: center;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: all 0.2s ease;
}
.timetable-dropzone:hover, .timetable-dropzone.dragover, .timetable-dropzone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 30px -10px rgba(244, 63, 94, 0.4);
}
.timetable-editor-table input, .timetable-editor-table select {
    width: 100%;
    padding: 4px 6px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-sizing: border-box;
    background: var(--bg-input);
    color: var(--text-primary);
}
.timetable-conflict-row {
    background: rgba(248, 113, 113, 0.12) !important;
}
#confirmed-table {
    min-width: 480px;
}
#confirmed-table td:nth-child(3) {
    white-space: nowrap;
}
.timetable-editor-table {
    min-width: 760px;
}

/* ==========================================================================
   Ghi đè các màu "sáng" được viết inline trong index.html / app.js /
   timetable.js để không phải sửa logic JS.
   ========================================================================== */
/* nền xám nhạt cũ -> nền tối nâng */
[style*="#f8fafc"], [style*="#fafafa"] {
    background: var(--bg-elev) !important;
    border-color: var(--border) !important;
}
[style*="#3b82f6"] { border-left-color: var(--primary) !important; }
[style*="#e2e8f0"] { border-color: var(--border) !important; }

/* nhóm vàng/amber: banner, cảnh báo, nhãn "BẢN NHÁP" */
[style*="#fef3c7"], [style*="#fffbeb"], [style*="#fff3cd"], [style*="#fef7e0"] {
    background: rgba(251, 191, 36, 0.12) !important;
    border-color: rgba(251, 191, 36, 0.35) !important;
    color: #fcd34d !important;
}

/* nhóm xanh lá: tóm tắt chủ đề, xuất .ics, nhãn "Đã xác minh" */
[style*="#f0fdf4"], [style*="#e6f4ea"] {
    background: rgba(52, 211, 153, 0.10) !important;
    border-color: rgba(52, 211, 153, 0.30) !important;
}
[style*="#166534"], [style*="#137333"] { color: #6ee7b7 !important; }
.btn[style*="#16a34a"] {
    background: var(--grad) !important;
    border-color: transparent !important;
    color: #fff !important;
}

/* chữ đỏ / xanh đặt bằng JS hoặc inline -> sáng hơn trên nền tối */
[style*="#dc2626"], [style*="rgb(220, 38, 38)"], [style*="color: red"] { color: #f87171 !important; }
[style*="rgb(22, 163, 74)"], [style*="color: green"] { color: #4ade80 !important; }

/* ------------------------------ Responsive ------------------------------- */
@media (max-width: 1360px) {
    .timetable-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.timetable-loading-box {
    text-align: center;
    padding: 20px;
    margin-top: 12px;
    background: var(--bg-elev);
    color: var(--text-primary);
    border-radius: 8px;
    border: 1px dashed var(--border);
}
.timetable-loading-box strong {
    color: var(--text-primary);
}

.form-manual-entry {
    background: var(--bg-elev);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    margin-bottom: 12px;
}
.form-manual-grid {
    display: grid;
    grid-template-columns: 110px 1fr 100px 100px 90px;
    gap: 8px;
    align-items: center;
}
@media (max-width: 768px) {
    .form-manual-grid {
        grid-template-columns: 1fr 1fr;
    }
    .form-manual-grid > div:nth-child(2) {
        grid-column: 1 / -1;
    }
}
@media (max-width: 480px) {
    .form-manual-grid {
        grid-template-columns: 1fr;
    }
    .form-manual-grid > div:nth-child(2) {
        grid-column: auto;
    }
}

.timetable-export-card {
    background: rgba(52, 211, 153, 0.10);
    border: 1px solid rgba(52, 211, 153, 0.30);
}
.timetable-export-title {
    color: #6ee7b7;
}
html[data-theme="light"] .timetable-export-card {
    background: #f0fdf4;
    border-color: #bbf7d0;
}
html[data-theme="light"] .timetable-export-title {
    color: #166534;
}

.ocr-run-form {
    background: var(--bg-elev);
    color: var(--text-primary);
}
.ocr-preview-box {
    background: var(--bg-elev);
    color: var(--text-primary);
}


/* ==========================================================================
   BỐ CỤC v2 — thanh bên gọn gàng, màn hình chào dạng "hero", thẻ gợi ý
   ========================================================================== */

/* ---- Sidebar ---- */
.sidebar {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    width: 300px;
    flex-shrink: 0;
    gap: 14px;
    padding: 18px 14px 14px;
    transition: margin-left 0.28s ease, transform 0.28s ease;
}
body.sidebar-collapsed .sidebar {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px); margin-left: -300px; }

.sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 4px;
}
.brand-text { min-width: 0; }
.brand-text h2 { font-size: 16px; white-space: nowrap; }
.brand-icon { width: 42px; height: 42px; font-size: 20px; }

.icon-btn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    border-radius: 10px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}
.icon-btn:hover { color: #fff; border-color: var(--primary-border); background: var(--primary-light); }

/* Nút "Cuộc trò chuyện mới" dạng viên thuốc (Pill Button) */
.new-chat-btn {
    width: 100%;
    padding: 10px 16px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(30, 34, 46, 0.7);
    color: #f1f5f9;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.new-chat-btn:hover:not(:disabled) {
    background: rgba(45, 22, 39, 0.65);
    border-color: rgba(251, 113, 133, 0.45);
    color: #fff;
    box-shadow: 0 0 20px -4px rgba(244, 63, 94, 0.3);
}
.new-chat-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Điều hướng 3 chế độ: thanh pill trên header */
.mode-switch {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    background: rgba(22, 26, 35, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 9999px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    flex-wrap: nowrap;
}
.mode-button {
    padding: 6px 14px;
    border: none;
    background: transparent;
    border-radius: 9999px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.mode-button:hover {
    color: var(--text-primary);
}
.mode-button.active {
    background: var(--primary);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 2px 10px rgba(244, 63, 94, 0.35);
}

/* Danh sách cuộc trò chuyện: phẳng, chiếm phần lớn chiều cao */
.sidebar-section h3 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0;
}
.history-card {
    flex: 1 1 auto;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    padding: 12px 0 0;
    border-top: 1px solid var(--border);
}
.history-card .history-heading { padding: 0 4px; }
.session-search-wrapper { margin: 10px 0 6px; }
.session-search-wrapper .form-input { font-size: 12.5px; padding: 8px 12px; }
.history-note { margin: 2px 4px 6px; }
.history-list { flex: 1; max-height: none; min-height: 0; padding-right: 2px; }
.history-card .session-item { border-top: 0; margin-bottom: 2px; }

.btn-ghost-danger {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
    padding: 4px 8px;
    font-size: 11.5px;
    border-radius: 8px;
}
.btn-ghost-danger:hover { color: var(--danger); background: rgba(248, 113, 113, 0.1); }

/* Khu vực cuối: thư viện + cấu hình dạng thu gọn */
.sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}
details.collapsible { padding: 0; }
details.collapsible > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-radius: var(--radius);
    user-select: none;
    transition: color 0.2s, background 0.2s;
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::after {
    content: "⌄";
    font-size: 16px;
    line-height: 1;
    color: var(--text-muted);
    transition: transform 0.2s;
}
details.collapsible[open] > summary::after { transform: rotate(180deg); }
details.collapsible > summary:hover { color: #fff; background: rgba(255, 255, 255, 0.03); }
details.collapsible[open] { border-color: var(--border-strong); }
.collapsible-body { padding: 2px 14px 14px; }
.collapsible-body .stat-grid { margin-bottom: 12px; }
.field-hint { display: block; margin-top: 4px; font-size: 0.74rem; line-height: 1.4; }

.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tool-tile {
    min-height: 54px;
    padding: 8px 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    border-radius: 12px;
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.tool-tile:hover {
    color: #fff;
    border-color: var(--primary-border);
    background: var(--primary-light);
    transform: translateY(-1px);
}
.sidebar-footer { margin-top: 0; }
.disclaimer-mini { font-size: 10.5px; padding: 8px 10px; }

/* ---- Header ---- */
.chat-header {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px); padding: 14px 24px; gap: 12px; }
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-info { min-width: 0; }
.chat-header h1 { font-size: 17px; }
.chat-header .subtitle { font-size: 12.5px; }
#btn-open-sidebar { display: none; }
body.sidebar-collapsed #btn-open-sidebar { display: inline-flex; }
.sidebar-backdrop { display: none; }

/* ---- Thanh phiên / tóm tắt / banner ---- */
.session-bar {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    font-size: 0.88rem;
    position: relative;
    box-sizing: border-box;
    flex-shrink: 0;
}
.session-title-wrapper { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; }
.session-title-wrapper strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: none; flex: 0 1 auto; }
.session-bar-icon { color: var(--text-muted); }
.session-controls { display: flex; align-items: center; gap: 10px; position: relative; flex-shrink: 0; }
.btn-mini { padding: 4px 10px; font-size: 0.78rem; border-radius: 9px; }

/* Dropdown menu cho nguồn gần nhất và câu hỏi gần nhất */
.recent-sources-dropdown-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.recent-sources-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.recent-sources-trigger:hover,
.recent-sources-trigger:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.recent-sources-trigger[aria-expanded="true"] {
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.4);
    color: #38bdf8;
}

.dropdown-chevron {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    display: inline-block;
    opacity: 0.8;
}

.recent-sources-trigger[aria-expanded="true"] .dropdown-chevron {
    transform: rotate(180deg);
}

.recent-sources-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: max-content;
    min-width: 290px;
    max-width: min(390px, calc(100vw - 32px));
    max-height: min(65vh, 480px);
    overflow-y: auto;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 16px 40px -8px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.recent-sources-menu[hidden] {
    display: none !important;
}

.recent-menu-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.recent-menu-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 4px 0;
}

.recent-menu-divider[hidden] {
    display: none !important;
}

.recent-menu-header {
    padding: 6px 10px 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.recent-menu-header[hidden] {
    display: none !important;
}

.recent-menu-header .header-title {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.recent-menu-header .header-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.recent-menu-action-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.recent-menu-action-btn:hover,
.recent-menu-action-btn:focus-visible {
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.35);
    color: #38bdf8;
    outline: none;
}

.recent-menu-action-btn[hidden] {
    display: none !important;
}

.resume-source-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.resume-source-list[hidden] {
    display: none !important;
}

.recent-menu-source-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-primary);
    font-size: 0.8rem;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.recent-menu-source-item:hover,
.recent-menu-source-item:focus-visible {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.15);
    outline: none;
}

.recent-menu-source-item .source-item-icon {
    flex-shrink: 0;
    font-size: 0.85rem;
    opacity: 0.8;
}

.recent-menu-source-item .source-item-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-menu-source-item .source-item-page {
    flex-shrink: 0;
    font-size: 0.74rem;
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.session-summary-box {
    margin: 12px auto 0;
    width: calc(100% - 48px);
    max-width: 860px;
    padding: 12px 16px;
    background: rgba(52, 211, 153, 0.08);
    border: 1px solid rgba(52, 211, 153, 0.28);
    border-radius: 14px;
    font-size: 0.85rem;
    color: #86efac;
}
.session-summary-box .summary-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.session-summary-box p { margin: 0; line-height: 1.5; }
.session-summary-box .summary-note { margin-top: 8px; font-size: 0.75rem; color: #6ee7b7; opacity: 0.85; }
.summary-close { background: none; border: none; cursor: pointer; color: inherit; font-size: 1.2rem; line-height: 1; }

.training-banner {
    background: rgba(251, 191, 36, 0.1);
    color: #fcd34d;
    border: 1px solid rgba(251, 191, 36, 0.3);
    padding: 10px 16px;
    margin: 12px auto 0;
    width: calc(100% - 48px);
    max-width: 860px;
    border-radius: 14px;
    font-size: 0.9rem;
    align-items: center;
    gap: 8px;
}

/* ---- Màn hình chào kiểu hero DeepSeek + iOS Liquid Glass ---- */
.messages-container.has-chat .welcome-card { display: none; }

.welcome-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 720px;
    margin: auto auto;
    padding: 0;
    gap: 20px;
    background: transparent;
    border: 0;
    box-shadow: none;
    border-radius: 0;
}
.welcome-card .message-avatar {
    margin: 0;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid rgba(251, 113, 133, 0.35);
    box-shadow: 0 0 32px rgba(244, 63, 94, 0.25), 0 12px 30px rgba(0, 0, 0, 0.45);
    background: #181c26;
    display: flex;
    align-items: center;
    justify-content: center;
}
.hero-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}
.welcome-card .message-body {
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    flex: none;
    width: 100%;
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
}
.welcome-card h3 {
    font-size: clamp(24px, 2.5vw, 32px);
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
    color: var(--text-primary);
}
.welcome-card .message-body > p {
    max-width: 580px;
    margin: 0 auto;
    color: var(--text-muted);
    font-size: 13.5px;
    line-height: 1.6;
}
.welcome-card .suggestion-chips {
    margin-top: 24px;
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 960px;
    overflow-x: auto;
    padding: 6px 2px;
}
.welcome-card .chip {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
    gap: 6px;
    min-height: auto;
    padding: 7px 14px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(22, 26, 35, 0.72);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
.welcome-card .chip::after {
    content: "✦";
    font-size: 13px;
    color: var(--accent);
    transition: transform 0.25s;
}
.welcome-card .chip:hover {
    color: #fff;
    background: rgba(45, 22, 39, 0.55);
    border-color: rgba(251, 113, 133, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px -4px rgba(244, 63, 94, 0.25);
}
.welcome-card .chip:hover::after { transform: scale(1.35) rotate(18deg); }

/* ---- Khung nhập nổi phong cách DeepSeek & iOS Liquid Glass ---- */
.input-area {
    background: transparent;
    border-top: 1px solid var(--border);
    padding: 12px 24px 20px;
    position: relative;
    z-index: 10;
}
.chat-form {
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 14px 16px 10px 18px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 22px;
    background: var(--bg-input);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), inset 0 1px 1px rgba(255, 255, 255, 0.12);
    transition: all 0.2s ease;
}
.chat-form:focus-within {
    border-color: rgba(251, 113, 133, 0.35);
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(251, 113, 133, 0.15), inset 0 1px 1px rgba(255, 255, 255, 0.15);
}
.chat-form textarea {
    width: 100%;
    padding: 2px 0 8px 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14.5px;
    resize: none;
    outline: none;
    max-height: 140px;
    line-height: 1.5;
}
.chat-form textarea::placeholder {
    color: #64748b;
}
.chat-form-bottom {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    margin-top: 4px;
}
.chat-form-controls {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.processing-level-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 12px;
    border-radius: 9999px;
    background: rgba(30, 34, 46, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    transition: border-color 0.2s ease;
}
.processing-level-pill:hover {
    border-color: rgba(251, 113, 133, 0.3);
}
.pill-icon {
    font-size: 13px;
    line-height: 1;
}
.pill-select {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    padding-right: 4px;
}
.pill-select option {
    background: #181c26;
    color: #f8fafc;
}
.scope-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 9999px;
    background: rgba(76, 29, 46, 0.45);
    border: 1px solid rgba(251, 113, 133, 0.35);
    color: #fecdd3;
    font-size: 12px;
    font-weight: 600;
    cursor: default;
    user-select: none;
}
.chat-form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(244, 63, 94, 0.35);
    font-size: 16px;
    font-weight: 700;
    padding: 0;
}
.btn-send:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.05);
    box-shadow: 0 6px 18px rgba(244, 63, 94, 0.45);
}
.btn-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
#qa-source-scope { max-width: 720px; margin: 0 auto 8px; }

/* ---- Panel Tra cứu / Thời khóa biểu: căn giữa, thẻ gọn ---- */
.documents-panel, .timetable-panel {
    padding: 28px max(24px, calc((100% - 1180px) / 2));
}
.document-search-form {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 20px 20px;
    box-shadow: var(--shadow-sm);
}
.document-search-form > label { margin-top: 14px; font-size: 13px; color: var(--text-secondary); }
.document-filters label { color: var(--text-secondary); font-size: 12.5px; }
.documents-panel > h2, .timetable-header h2 { letter-spacing: -0.01em; }
.document-result { transition: border-color 0.2s, box-shadow 0.2s; }
.document-result:hover { border-color: var(--primary-border); box-shadow: 0 10px 30px -14px rgba(244, 63, 94, 0.35); }

/* ---- Responsive: ngăn kéo trên màn hình nhỏ ---- */
@media (max-width: 900px) {
    .sidebar {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
        position: fixed;
        top: 0;
        left: 0;
        height: 100dvh;
        width: min(310px, 86vw);
        margin-left: 0 !important;
        transform: translateX(-102%);
        z-index: 200;
        box-shadow: var(--shadow-lg);
    }
    body.sidebar-open .sidebar {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px); transform: translateX(0); }
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(8, 8, 12, 0.6);
        backdrop-filter: blur(3px);
        z-index: 150;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s;
    }
    body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    #btn-open-sidebar { display: inline-flex; }
    .main-content { height: 100dvh; min-width: 0; }
    .chat-header {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px); padding: 12px 14px; }
    .chat-header .subtitle { display: none; }
    .messages-container { padding: 16px 12px; }
    .input-area { padding: 6px 12px 12px; }
    .message { gap: 8px; }
    .message-body {
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px); min-width: 0; padding: 12px; }
    .chat-form {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px); padding: 8px 8px 8px 14px; border-radius: 20px; }
    .chat-form textarea { min-width: 0; }
    .session-bar { padding: 8px 14px; }
    .session-controls { flex-wrap: wrap; justify-content: flex-end; }
    .qa-answer-mode { flex-wrap: wrap; }
    .qa-answer-mode span { flex-basis: 100%; margin-left: 2px; }
    .session-summary-box, .training-banner { width: calc(100% - 28px); }
    .documents-panel, .timetable-panel { padding: 16px 12px; }
    .document-filters { flex-direction: column; align-items: stretch; }
    .welcome-card .message-avatar { width: 60px; height: 60px; font-size: 28px; }
    .welcome-card .chip { min-height: auto; padding: 8px 14px; gap: 6px; }
}

/* ==========================================================================
   STUDY MATERIALS, QUIZ & 3D FLASHCARD STYLES (YC-207)
   ========================================================================== */

/* --- Chat Attach Button & Floating Popup Menu --- */
.chat-attach-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-right: auto;
    flex-shrink: 0;
}

.btn-attach {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    padding: 0;
}

.btn-attach .attach-icon {
    font-size: 18px;
    font-weight: 400;
    line-height: 1;
    transition: transform 0.25s ease;
}

.btn-attach:hover {
    background: rgba(244, 63, 94, 0.15);
    border-color: rgba(251, 113, 133, 0.45);
    color: #fb7185;
    box-shadow: 0 0 12px rgba(244, 63, 94, 0.35);
    transform: scale(1.06);
}

.btn-attach[aria-expanded="true"] {
    background: #f43f5e;
    border-color: rgba(251, 113, 133, 0.5);
    color: #ffffff;
    box-shadow: 0 0 16px rgba(244, 63, 94, 0.5);
}

.btn-attach[aria-expanded="true"] .attach-icon {
    transform: rotate(45deg);
}

.attach-popup-menu {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 0;
    min-width: 290px;
    background: rgba(18, 22, 32, 0.95);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 8px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65), 0 0 24px rgba(244, 63, 94, 0.15);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: attachMenuPop 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes attachMenuPop {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.attach-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 14px;
    border-radius: 12px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: all 0.18s ease;
}

.attach-menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.attach-menu-item:hover .attach-menu-icon {
    transform: scale(1.15);
    background: rgba(244, 63, 94, 0.2);
    border-color: rgba(251, 113, 133, 0.4);
}

.attach-menu-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 18px;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.attach-menu-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.attach-menu-title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.attach-menu-sub {
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.3;
    margin-top: 2px;
}

/* --- Study Material Modal Layout --- */
.study-material-modal-content {
    background: rgba(15, 18, 26, 0.96);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7), 0 0 60px rgba(244, 63, 94, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.study-material-title-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.study-material-title-group h2 {
    font-size: 17px;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.study-material-meta {
    font-size: 12px;
    color: #94a3b8;
}

.study-material-tabs {
    display: flex;
    gap: 8px;
    padding: 10px 24px;
    background: rgba(10, 13, 20, 0.6);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
    overflow-x: auto;
}

.study-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #94a3b8;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.study-tab-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #f1f5f9;
}

.study-tab-btn.active {
    background: rgba(244, 63, 94, 0.22);
    border-color: rgba(251, 113, 133, 0.45);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 0 16px rgba(244, 63, 94, 0.25);
}

.study-tab-btn .tab-badge {
    padding: 1px 7px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.1);
    font-size: 11px;
    font-weight: 600;
}

.study-tab-btn.active .tab-badge {
    background: rgba(244, 63, 94, 0.4);
    color: #ffffff;
}

.study-material-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.study-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.study-panel[hidden] {
    display: none !important;
}

/* --- Quiz Styles --- */
.quiz-progress-bar-container {
    margin-bottom: 20px;
}

.quiz-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.quiz-counter {
    font-size: 13px;
    font-weight: 600;
    color: #94a3b8;
}

.quiz-score-pill {
    font-size: 12.5px;
    padding: 3px 12px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
}

.quiz-score-pill strong {
    color: #fb7185;
}

.progress-track {
    width: 100%;
    height: 6px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.06);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 9999px;
    background: #f43f5e;
    box-shadow: 0 0 10px rgba(244, 63, 94, 0.5);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.quiz-question-card {
    background: rgba(22, 26, 38, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    padding: 22px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    margin-bottom: 20px;
}

.quiz-question-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
    background: rgba(244, 63, 94, 0.15);
    border: 1px solid rgba(251, 113, 133, 0.25);
    color: #fb7185;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.quiz-question-text {
    font-size: 16.5px;
    font-weight: 600;
    color: #ffffff;
    line-height: 1.5;
    margin-bottom: 18px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.quiz-choices-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.quiz-choice-btn {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    font-size: 14px;
    cursor: pointer;
    text-align: left;
    line-height: 1.45;
    transition: all 0.2s ease;
}

.quiz-choice-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.16);
    transform: translateX(3px);
}

.quiz-choice-key {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 700;
    font-size: 12.5px;
    color: #94a3b8;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.quiz-choice-text {
    flex: 1;
    padding-top: 2px;
}

/* Quiz Choice States */
.quiz-choice-btn.selected {
    background: rgba(244, 63, 94, 0.12);
    border-color: rgba(251, 113, 133, 0.4);
}

.quiz-choice-btn.correct {
    background: rgba(16, 185, 129, 0.16) !important;
    border-color: rgba(16, 185, 129, 0.5) !important;
    color: #ffffff !important;
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.25) !important;
}

.quiz-choice-btn.correct .quiz-choice-key {
    background: #10b981 !important;
    color: #ffffff !important;
    border-color: #10b981 !important;
}

.quiz-choice-btn.incorrect {
    background: rgba(239, 68, 68, 0.16) !important;
    border-color: rgba(239, 68, 68, 0.5) !important;
    color: #fca5a5 !important;
}

.quiz-choice-btn.incorrect .quiz-choice-key {
    background: #ef4444 !important;
    color: #ffffff !important;
    border-color: #ef4444 !important;
}

/* Unverified Proposed Answer Match/Difference States (Truthful non-authoritative grading) */
.quiz-choice-btn.proposed-match {
    background: rgba(14, 165, 233, 0.16) !important;
    border-color: rgba(56, 189, 248, 0.5) !important;
    color: #ffffff !important;
    box-shadow: 0 0 14px rgba(14, 165, 233, 0.2) !important;
}

.quiz-choice-btn.proposed-match .quiz-choice-key {
    background: #0ea5e9 !important;
    color: #ffffff !important;
    border-color: #0ea5e9 !important;
}

.quiz-choice-btn.proposed-diff {
    background: rgba(245, 158, 11, 0.16) !important;
    border-color: rgba(245, 158, 11, 0.5) !important;
    color: #fde68a !important;
}

.quiz-choice-btn.proposed-diff .quiz-choice-key {
    background: #f59e0b !important;
    color: #ffffff !important;
    border-color: #f59e0b !important;
}

.quiz-bubble.proposed-match {
    background: #0ea5e9 !important;
    border-color: #38bdf8 !important;
    color: #ffffff !important;
}

.quiz-bubble.proposed-diff {
    background: #f59e0b !important;
    border-color: #fbbf24 !important;
    color: #ffffff !important;
}

/* Quiz Feedback & Grounding Citation Box */
.quiz-feedback-box {
    margin-top: 18px;
    padding: 16px;
    border-radius: 12px;
    background: rgba(15, 20, 30, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.08);
    animation: fadeInSlide 0.25s ease forwards;
}

@keyframes fadeInSlide {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.quiz-feedback-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14.5px;
    margin-bottom: 8px;
}

.quiz-explanation-text {
    font-size: 13.5px;
    color: #cbd5e1;
    line-height: 1.55;
    margin-bottom: 12px;
}

.quiz-citation-box {
    padding: 10px 14px;
    border-radius: 8px;
    background: rgba(244, 63, 94, 0.06);
    border-left: 3px solid #f43f5e;
}

.citation-tag {
    font-size: 12px;
    color: #fb7185;
    font-weight: 600;
    margin-bottom: 4px;
}

.citation-quote {
    font-size: 12.5px;
    font-style: italic;
    color: #94a3b8;
    line-height: 1.5;
    margin: 0;
}

/* Quiz Navigation Footer */
.quiz-navigation-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.quiz-bubbles-nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.quiz-bubble {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.quiz-bubble:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

.quiz-bubble.active {
    border-color: #f43f5e;
    box-shadow: 0 0 10px rgba(244, 63, 94, 0.4);
    color: #ffffff;
    font-weight: 700;
}

.quiz-bubble.correct {
    background: rgba(16, 185, 129, 0.25);
    border-color: #10b981;
    color: #6ee7b7;
}

.quiz-bubble.wrong {
    background: rgba(239, 68, 68, 0.25);
    border-color: #ef4444;
    color: #fca5a5;
}

/* --- 3D Flashcard Styles --- */
.flashcard-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.flashcard-counter-info {
    display: flex;
    flex-direction: column;
}

.card-counter {
    font-size: 14px;
    font-weight: 700;
    color: #ffffff;
}

.flashcard-hint-text {
    font-size: 12px;
    color: #94a3b8;
}

.flashcard-mastery-stats {
    display: flex;
    gap: 8px;
}

.stat-badge {
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
}

.stat-badge.learned {
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #6ee7b7;
}

.stat-badge.learning {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #fde68a;
}

.flashcard-viewport {
    perspective: 1200px;
    margin: 10px auto 20px auto;
    width: 100%;
    max-width: 660px;
    height: 380px;
}

.flashcard-card {
    width: 100%;
    height: 100%;
    position: relative;
}

.flashcard-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.34, 1.4, 0.64, 1);
    cursor: pointer;
}

.flashcard-inner.is-flipped {
    transform: rotateY(180deg);
}

.flashcard-face {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 20px;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    user-select: none;
    box-sizing: border-box;
}

.flashcard-front {
    background: #151824;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.flashcard-front:hover {
    border-color: rgba(251, 113, 133, 0.35);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5), 0 0 30px rgba(244, 63, 94, 0.15);
}

.flashcard-back {
    background: #1c1722;
    border: 1px solid rgba(251, 113, 133, 0.35);
    transform: rotateY(180deg);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.55), 0 0 30px rgba(244, 63, 94, 0.2);
}

.card-face-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-type-tag {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
    color: #94a3b8;
}

.card-type-tag.back {
    background: rgba(244, 63, 94, 0.15);
    color: #fb7185;
}

.card-flip-prompt {
    font-size: 11.5px;
    color: #94a3b8;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.card-face-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow-y: auto;
    padding: 12px 0;
}

.card-concept-title {
    font-size: 22px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.45;
    text-align: center;
    letter-spacing: -0.01em;
}

.card-definition-text {
    font-size: 15px;
    color: #f1f5f9;
    line-height: 1.6;
    text-align: left;
    margin-bottom: 14px;
}

.card-citation-grounding {
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    border-left: 2px solid #fb7185;
    text-align: left;
}

.citation-label {
    font-size: 11.5px;
    color: #fb7185;
    font-weight: 600;
    display: block;
    margin-bottom: 2px;
}

.card-quote {
    font-size: 12px;
    font-style: italic;
    color: #94a3b8;
    line-height: 1.45;
    margin: 0;
}

.card-face-footer {
    display: flex;
    justify-content: flex-end;
}

.card-number-indicator {
    font-size: 12px;
    color: #64748b;
    font-weight: 600;
}

.flashcard-controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    max-width: 660px;
    margin: 0 auto;
    width: 100%;
}

.flashcard-nav-btns {
    display: flex;
    gap: 8px;
}

.flashcard-mastery-actions {
    display: flex;
    gap: 8px;
}

.btn-mastery {
    padding: 6px 14px !important;
    border-radius: 9999px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    transition: all 0.2s ease !important;
}

.btn-learning {
    background: rgba(245, 158, 11, 0.12) !important;
    border: 1px solid rgba(245, 158, 11, 0.35) !important;
    color: #fde68a !important;
}

.btn-learning:hover {
    background: rgba(245, 158, 11, 0.22) !important;
}

.btn-mastered {
    background: rgba(16, 185, 129, 0.15) !important;
    border: 1px solid rgba(16, 185, 129, 0.4) !important;
    color: #6ee7b7 !important;
}

.btn-mastered:hover {
    background: rgba(16, 185, 129, 0.25) !important;
}

/* --- Sources & Document Details Panel --- */
.source-document-details {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.source-meta-card {
    background: rgba(22, 26, 38, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 18px;
}

.source-meta-card h3 {
    font-size: 16px;
    color: #ffffff;
    margin-bottom: 10px;
}

.source-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    font-size: 13px;
    color: #94a3b8;
}

.source-meta-grid strong {
    color: #cbd5e1;
}

.source-preview-section h4 {
    font-size: 14px;
    color: #cbd5e1;
    margin-bottom: 8px;
}

.source-text-preview {
    max-height: 300px;
    overflow-y: auto;
    padding: 14px;
    border-radius: 10px;
    background: rgba(10, 13, 20, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.06);
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.6;
    color: #cbd5e1;
    white-space: pre-wrap;
}

/* --- Chat Assistant Study Card --- */
.message.study-card-message {
    display: flex;
    gap: 14px;
    width: 100%;
    max-width: 720px !important;
    margin: 0 auto !important;
    align-items: flex-start;
}

.message.study-card-message .message-body {
    padding: 18px 22px;
    border-radius: 22px;
    background: rgba(20, 23, 34, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.42);
}

.study-card-assistant {
    background: #171a28;
    border: 1px solid rgba(251, 113, 133, 0.42);
    border-radius: 16px;
    padding: 18px 20px;
    margin-top: 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), 0 0 20px rgba(244, 63, 94, 0.14);
}

.study-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.study-card-icon {
    font-size: 22px;
}

.study-card-title {
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.4;
}

#study-loading-modal .modal-content {
    max-width: 460px !important;
    width: min(460px, calc(100vw - 32px)) !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
}

#study-loading-title,
#study-loading-step,
.source-meta-card h3 {
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.study-card-details {
    font-size: 13px;
    color: #94a3b8;
    line-height: 1.55;
    margin-bottom: 14px;
}

.study-card-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Compact attachment banners preserve room for the conversation. */
.chat-attachment-preview-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 80px;
    overflow-y: auto;
    padding: 0 0 6px;
}
.chat-attachment-preview-tray[hidden] { display: none !important; }
.chat-attachment-card {
    display: flex;
    align-items: center;
    min-width: 0;
    max-width: min(100%, 360px);
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #151822;
}
.attachment-card-open {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 6px 8px;
    color: var(--text-primary);
    background: transparent;
    border: 0;
    cursor: pointer;
}
.attachment-file-icon {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    color: #fda4af;
}
.attachment-file-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}
.attachment-file-status {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 11px;
}
.attachment-card-remove {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
}
.attachment-card-remove:hover { color: #fb7185; }
.attachment-card-open:focus-visible,
.attachment-card-remove:focus-visible { outline: 2px solid var(--accent); }

/* --- Dedicated Quiz & Flashcard Generator Pill Button --- */
.study-gen-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 13px;
    border-radius: 9999px;
    background: rgba(244, 63, 94, 0.22);
    border: 1px solid rgba(251, 113, 133, 0.45);
    color: #ffe4e6;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 12px rgba(244, 63, 94, 0.18);
}

.study-gen-pill:hover {
    background: rgba(244, 63, 94, 0.35);
    border-color: rgba(251, 113, 133, 0.75);
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(244, 63, 94, 0.32);
}

.study-gen-pill.has-active-file {
    background: #f43f5e;
    border-color: #fb7185;
    color: #ffffff;
    box-shadow: 0 4px 16px rgba(244, 63, 94, 0.4);
}

/* --- Document Content Viewer Modal Cards --- */
.doc-content-page-card {
    background: rgba(18, 22, 34, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.doc-content-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.doc-content-page-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 9999px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(96, 165, 250, 0.35);
    color: #93c5fd;
    font-size: 11.5px;
    font-weight: 700;
}

.doc-content-page-chars {
    font-size: 11.5px;
    color: #94a3b8;
}

.doc-content-page-text {
    font-size: 13.5px;
    line-height: 1.68;
    color: #e2e8f0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* =========================================================================
   Canvas Document Viewer (Styled after ChatGPT / Gemini Canvas - Image 3)
   ========================================================================= */
.canvas-document-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(8, 11, 18, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}

.canvas-document-modal.active {
    display: flex !important;
}

.canvas-modal-content {
    width: min(1160px, calc(100vw - 32px));
    height: min(92vh, 880px);
    max-width: 1160px;
    background: #0f131c;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7);
    transition: all 0.25s ease;
}

/* Fullscreen mode */
.canvas-document-modal.fullscreen {
    padding: 0;
}

.canvas-document-modal.fullscreen .canvas-modal-content {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    border: none !important;
}

/* --- Canvas Top Navigation Bar (Image 3) --- */
.canvas-top-bar {
    background: #141824;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.canvas-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 200px;
    flex: 1 1 auto;
}

.canvas-file-icon {
    font-size: 24px;
    line-height: 1;
}

.canvas-doc-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.canvas-doc-title {
    font-size: 15px;
    font-weight: 700;
    color: #f1f5f9;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 320px;
}

.canvas-doc-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}

.canvas-doc-meta {
    font-size: 11.5px;
    color: #94a3b8;
}

.canvas-src-badge {
    display: inline-block;
    font-size: 10.5px;
    font-weight: 600;
    color: #60a5fa;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 6px;
    padding: 1px 6px;
}

.canvas-bar-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 260px;
    max-width: 360px;
}

.canvas-search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 6px 12px;
    transition: border-color 0.15s ease;
}

.canvas-search-box:focus-within {
    border-color: #3b82f6;
    background: rgba(255, 255, 255, 0.07);
}

.canvas-search-icon {
    font-size: 13px;
    opacity: 0.7;
}

.canvas-search-input {
    background: transparent;
    border: none;
    outline: none;
    color: #f8fafc;
    font-size: 13px;
    width: 100%;
}

.canvas-search-input::placeholder {
    color: #64748b;
}

.canvas-search-count {
    font-size: 11px;
    color: #94a3b8;
    white-space: nowrap;
}

.canvas-bar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* Zoom controls */
.canvas-zoom-group {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 2px 4px;
}

.canvas-tool-btn {
    background: transparent;
    border: none;
    color: #cbd5e1;
    font-size: 15px;
    font-weight: 700;
    width: 24px;
    height: 24px;
    cursor: pointer;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.canvas-tool-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.canvas-zoom-label {
    font-size: 12px;
    font-weight: 600;
    color: #e2e8f0;
    padding: 0 8px;
    min-width: 44px;
    text-align: center;
    user-select: none;
}

/* Action buttons */
.canvas-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 12.5px;
    font-weight: 600;
    padding: 6px 12px;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.canvas-action-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
    color: #ffffff;
}

.canvas-primary-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #e11d48;
    border: 1px solid #f43f5e;
    border-radius: 8px;
    color: #ffffff;
    font-size: 12.5px;
    font-weight: 700;
    padding: 6px 14px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(225, 29, 72, 0.35);
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.canvas-primary-btn:hover {
    background: #be123c;
    transform: translateY(-1px);
}

.canvas-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #cbd5e1;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.canvas-icon-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

.canvas-close-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.canvas-close-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

/* --- Canvas Viewport & Sheet (Image 3) --- */
.canvas-viewport {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    padding: 32px 24px;
    background: #090c12;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.canvas-image-box {
    margin-bottom: 24px;
    max-width: 840px;
    width: 100%;
    text-align: center;
    background: #141824;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 16px;
}

.canvas-image-preview {
    max-width: 100%;
    max-height: 380px;
    object-fit: contain;
    border-radius: 8px;
}

.canvas-sheet-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* Clean white paper document sheet (ChatGPT/Gemini Canvas style) */
.canvas-doc-sheet {
    background: #ffffff;
    color: #0f172a;
    width: 100%;
    max-width: 820px;
    min-height: 1000px;
    padding: 56px 64px;
    border-radius: 4px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.75;
    font-size: 15px;
    transition: transform 0.15s ease-out;
}

.canvas-doc-flow {
    display: flex;
    flex-direction: column;
}

.canvas-original-page {
    margin-bottom: 32px;
}

.canvas-original-page-heading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: #475569;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 8px;
}

.canvas-original-page-heading a {
    color: #1d4ed8;
    font-weight: 600;
}

.canvas-original-page-image {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid #e2e8f0;
}

.canvas-extracted-text {
    margin-top: 10px;
    color: #475569;
    font-size: 13px;
}

.canvas-extracted-text summary {
    cursor: pointer;
    margin-bottom: 12px;
}

/* Document Typography Elements (Matching Image 3) */
.canvas-h1 {
    font-size: 23px;
    font-weight: 800;
    text-align: center;
    color: #1e3a8a;
    margin: 0 0 8px 0;
    letter-spacing: -0.3px;
    line-height: 1.35;
    text-transform: uppercase;
}

.canvas-subtitle {
    font-size: 13.5px;
    font-style: italic;
    color: #64748b;
    text-align: center;
    margin: 0 0 28px 0;
    line-height: 1.5;
}

.canvas-h2 {
    font-size: 17px;
    font-weight: 700;
    color: #1d4ed8;
    margin: 28px 0 12px 0;
    padding-bottom: 6px;
    border-bottom: 2px solid #dbeafe;
    text-transform: uppercase;
    letter-spacing: 0.2px;
}

.canvas-h3 {
    font-size: 15px;
    font-weight: 700;
    color: #0f172a;
    margin: 18px 0 8px 0;
    line-height: 1.45;
}

.canvas-p {
    font-size: 14.5px;
    color: #334155;
    margin: 0 0 12px 0;
    line-height: 1.72;
}

.canvas-bullet-line {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 0 6px 0;
    font-size: 14.5px;
    color: #334155;
    line-height: 1.68;
}

.canvas-bullet-dot {
    color: #2563eb;
    font-weight: 700;
    line-height: 1.68;
    flex-shrink: 0;
}

.canvas-bullet-text {
    flex: 1;
}

.canvas-callout-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-left: 4px solid #2563eb;
    border-radius: 6px;
    padding: 14px 18px;
    margin: 16px 0;
    font-size: 14px;
    line-height: 1.65;
    color: #1e293b;
}

/* Subtle continuous page transition divider */
.canvas-page-divider {
    border-top: 1px dashed #cbd5e1;
    margin: 40px 0 32px 0;
    position: relative;
    text-align: center;
}

.canvas-page-badge {
    display: inline-block;
    position: relative;
    top: -11px;
    background: #f1f5f9;
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 14px;
    border-radius: 9999px;
    border: 1px solid #e2e8f0;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.canvas-mark {
    background: #fef08a;
    color: #713f12;
    padding: 1px 3px;
    border-radius: 3px;
}

.canvas-empty-state {
    text-align: center;
    color: #64748b;
    padding: 48px 24px;
    font-size: 14.5px;
}

.canvas-table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 20px 0;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.canvas-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    line-height: 1.6;
    text-align: left;
    background: #ffffff;
}

.canvas-table th {
    background: #f8fafc;
    color: #1e293b;
    font-weight: 700;
    padding: 10px 14px;
    border-bottom: 2px solid #cbd5e1;
    border-right: 1px solid #e2e8f0;
}

.canvas-table th:last-child {
    border-right: none;
}

.canvas-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    border-right: 1px solid #f1f5f9;
    color: #334155;
    vertical-align: top;
}

.canvas-table td:last-child {
    border-right: none;
}

.canvas-table tr:last-child td {
    border-bottom: none;
}

.canvas-table tr:hover td {
    background: #f8fafc;
}

/* =========================================================================
   User Message Attachment Card (Image 2)
   ========================================================================= */
.message-attachment-card {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    background: #181d29;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 320px;
    text-align: left;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    user-select: none;
}

.message.user .message-attachment-card {
    margin-left: auto;
}

.message-attachment-card:hover {
    background: #202737;
    border-color: #3b82f6;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.message-attachment-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35);
    border-radius: 8px;
    color: #60a5fa;
    flex-shrink: 0;
}

.message-attachment-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.message-attachment-title {
    font-size: 13.5px;
    font-weight: 600;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.message-attachment-sub {
    font-size: 11px;
    color: #94a3b8;
    text-transform: capitalize;
    margin-top: 1px;
}



/* Usage refers to the most recent packed request, not the entire saved chat. */
.context-status { font-size: .8rem; color: var(--text-secondary, #64748b); line-height: 1.5; }
.context-status span:not([hidden]) { display: block; margin-bottom: .35rem; }
.context-status [hidden] { display: none !important; }

/* Timetable partial field highlighting (YC-06) */
.draft-field-missing {
    border-color: #f59e0b !important;
    background-color: rgba(245, 158, 11, 0.12) !important;
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35);
}
.draft-field-missing::placeholder {
    color: #fbbf24;
}

/* ==========================================================================
   Trợ lý AI lập lịch học tập cá nhân (Personal Study Schedule Assistant)
   ========================================================================== */
.planner-step-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.planner-step-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 9999px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    transition: border-color 0.2s, color 0.2s;
}
.planner-step-pill:hover {
    border-color: var(--primary);
    color: var(--text-primary);
}
.planner-next-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.35);
}
.planner-section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    flex-wrap: wrap;
}
.planner-header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.planner-badge-recurring {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(56, 189, 248, 0.14);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, 0.3);
}
.planner-rule-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 8px;
    margin-top: 12px;
}
.rule-legend-item {
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.45;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.rule-legend-item.rule-fixed { border-left: 3px solid #38bdf8; }
.rule-legend-item.rule-protected { border-left: 3px solid #2dd4bf; }
.rule-legend-item.rule-flexible { border-left: 3px solid #f59e0b; }
.rule-legend-item.rule-window { border-left: 3px solid #a855f7; }

.planner-prefs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    align-items: start;
}
.planner-prefs-notes {
    grid-column: 1 / -1;
}
.planner-prefs-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
}

.planner-task-form {
    padding: 14px;
    border-radius: 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
}
.planner-task-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    gap: 10px;
    align-items: end;
}
.planner-task-grid .task-col-wide {
    grid-column: span 2;
}
@media (max-width: 640px) {
    .planner-task-grid .task-col-wide {
        grid-column: 1 / -1;
    }
}

.planner-ai-explanation {
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: var(--text-primary);
}
.planner-warnings-alert {
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.38);
    color: #fde68a;
    font-size: 13px;
}
.planner-suggestions-panel {
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
}
.suggestion-option-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 12px;
    margin-top: 8px;
    border-radius: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
}
.planner-draft-review-box {
    padding: 14px;
    border-radius: 14px;
    background: var(--bg-elev);
    border: 1px solid rgba(245, 158, 11, 0.4);
}

.planner-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
}
.planner-stat-box {
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.planner-stat-box.stat-class { border-left: 3px solid #38bdf8; }
.planner-stat-box.stat-routine { border-left: 3px solid #f472b6; }
.planner-stat-box.stat-window { border-left: 3px solid #a855f7; }
.planner-stat-box.stat-study { border-left: 3px solid #10b981; }
.planner-stat-label {
    font-size: 11.5px;
    color: var(--text-muted);
}
.planner-stat-box strong {
    font-size: 15px;
    color: var(--text-primary);
}

.planner-filter-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
}
.planner-badge-legend {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.sched-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 9999px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}
.sched-badge.badge-class {
    background: rgba(56, 189, 248, 0.15);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, 0.35);
}
.sched-badge.badge-routine {
    background: rgba(244, 114, 182, 0.15);
    color: #f9a8d4;
    border: 1px solid rgba(244, 114, 182, 0.35);
}
.sched-badge.badge-rest {
    background: rgba(45, 212, 191, 0.15);
    color: #5eead4;
    border: 1px solid rgba(45, 212, 191, 0.35);
}
.sched-badge.badge-study-ai {
    background: rgba(245, 158, 11, 0.16);
    color: #fcd34d;
    border: 1px solid rgba(245, 158, 11, 0.35);
}
.sched-badge.badge-study-done {
    background: rgba(16, 185, 129, 0.16);
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.35);
}
.sched-badge.badge-window {
    background: rgba(168, 85, 247, 0.15);
    color: #d8b4fe;
    border: 1px dashed rgba(168, 85, 247, 0.45);
}
.master-row-completed td {
    opacity: 0.72;
}
.master-row-completed .master-item-title {
    text-decoration: line-through;
}

