:root {
    --bg-body: #0b1120;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --primary: #6366f1;
    --primary-light: #818cf8;
    --accent-green: #10b981;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --sidebar-width: 280px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Plus Jakarta Sans', sans-serif; }
body { background-color: var(--bg-body); color: var(--text-main); display: flex; min-height: 100vh; overflow-x: hidden; }

/* Sidebar Navigation */
.sidebar {
    width: var(--sidebar-width); background-color: #0f172a; border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 24px 16px; position: fixed; height: 100vh; z-index: 10;
}
.logo { display: flex; align-items: center; gap: 12px; font-size: 1.15rem; font-weight: 800; color: var(--text-main); margin-bottom: 24px; padding: 0 8px; }
.logo i { color: var(--primary-light); font-size: 1.5rem; }
.badge-ver { background: rgba(99, 102, 241, 0.2); color: var(--primary-light); font-size: 0.75rem; padding: 2px 8px; border-radius: 12px; }

.week-selector { margin-bottom: 20px; }
.week-selector select {
    width: 100%; background: #1e293b; border: 1px solid var(--primary); color: #fff;
    padding: 10px; border-radius: 10px; font-weight: 700; cursor: pointer; outline: none;
}

.day-menu { display: flex; flex-direction: column; gap: 6px; list-style: none; overflow-y: auto; flex: 1; padding-right: 4px; }
.day-item {
    display: flex; align-items: center; justify-content: space-between; padding: 10px 14px;
    border-radius: 10px; color: var(--text-muted); font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.day-item:hover, .day-item.active { background-color: var(--primary); color: #ffffff; }

.mode-toggle-card {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(16, 185, 129, 0.15));
    border: 1px solid rgba(99, 102, 241, 0.3); border-radius: 14px; padding: 14px; margin-top: 12px;
}
.mode-btns { display: flex; gap: 8px; margin-top: 8px; }
.mode-btn {
    flex: 1; padding: 8px; border-radius: 8px; border: none; font-weight: 700; font-size: 0.8rem; cursor: pointer; text-align: center;
}
.mode-btn.silent { background: var(--bg-card-hover); color: var(--text-main); }
.mode-btn.vocal { background: var(--accent-orange); color: #000; }
.mode-btn.active { outline: 2px solid var(--primary-light); box-shadow: 0 0 10px rgba(99, 102, 241, 0.5); }

/* Main Content */
.main-content { margin-left: var(--sidebar-width); flex: 1; padding: 28px 36px; max-width: 1200px; }
header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; border-bottom: 1px solid var(--border); padding-bottom: 16px; }
.header-title h1 { font-size: 1.6rem; font-weight: 800; color: var(--text-main); }
.header-title p { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; }

.tab-nav { display: flex; gap: 10px; margin-bottom: 24px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.tab-btn {
    background: none; border: none; color: var(--text-muted); font-weight: 700; font-size: 0.95rem;
    padding: 8px 16px; border-radius: 8px; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; gap: 8px;
}
.tab-btn:hover, .tab-btn.active { background: var(--primary); color: #fff; }

.section-pane { display: none; animation: fadeIn 0.3s ease; }
.section-pane.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* Cards & Elements */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 20px; margin-bottom: 20px; }
.card h3 { font-size: 1.15rem; font-weight: 700; margin-bottom: 12px; color: var(--primary-light); display: flex; align-items: center; gap: 10px; }

/* Vocab Table */
.vocab-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.vocab-table th, .vocab-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.vocab-table th { background: #0f172a; color: var(--text-muted); font-weight: 700; }
.vocab-table tr:hover { background: var(--bg-card-hover); }
.word-en { font-weight: 800; color: var(--primary-light); }
.word-ipa { color: var(--text-muted); font-style: italic; font-size: 0.85rem; }

/* Lego Dialogue Box */
.lego-box { background: #0f172a; border: 1px solid var(--primary); border-radius: 16px; padding: 24px; line-height: 1.8; font-size: 1.05rem; }
.dialogue-line { margin-bottom: 14px; padding-left: 12px; border-left: 3px solid var(--border); }
.dialogue-line.tien { border-left-color: var(--primary-light); }
.dialogue-line.anna { border-left-color: var(--accent-green); }
.speaker { font-weight: 800; margin-right: 6px; }
.speaker.tien { color: var(--primary-light); }
.speaker.anna { color: var(--accent-green); }

.interactive-word { cursor: pointer; padding: 2px 4px; border-radius: 4px; transition: background 0.2s; display: inline-block; }
.interactive-word:hover { background: rgba(99, 102, 241, 0.3); color: var(--primary-light); text-decoration: underline; }

.btn {
    background: var(--primary); color: white; border: none; padding: 10px 18px; border-radius: 10px;
    font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: all 0.2s; font-size: 0.9rem;
}
.btn:hover { background: var(--primary-light); }
.btn-secondary { background: var(--bg-card-hover); color: var(--text-main); }
.btn-accent { background: var(--accent-green); color: #000; }
.btn-orange { background: var(--accent-orange); color: #000; }

input[type="text"], textarea, select {
    width: 100%; background: #0f172a; border: 1px solid var(--border); border-radius: 10px;
    padding: 12px 14px; color: var(--text-main); font-size: 0.95rem; margin-bottom: 12px; outline: none;
}
input:focus, textarea:focus { border-color: var(--primary-light); }

/* Flashcard SRS */
.flashcard-box { perspective: 1000px; width: 100%; max-width: 480px; height: 260px; margin: 20px auto; }
.flashcard { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.5s; cursor: pointer; }
.flashcard.flipped { transform: rotateY(180deg); }
.card-face {
    position: absolute; width: 100%; height: 100%; backface-visibility: hidden; border-radius: 16px;
    background: var(--bg-card); border: 2px solid var(--primary); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; text-align: center;
}
.card-back { transform: rotateY(180deg); background: #0f172a; border-color: var(--accent-green); }

/* Popup Modal */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.75); z-index: 99; display: none; }
.popup-modal {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #1e293b;
    border: 1px solid var(--primary-light); box-shadow: 0 20px 30px rgba(0,0,0,0.6); border-radius: 18px; padding: 24px; width: 90%; max-width: 460px; z-index: 100; display: none;
}

/* Vocab View Toggle & Cards */
.vocab-view-toggle { display: flex; gap: 8px; margin-bottom: 0; background: #0f172a; padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.vocab-view-btn { background: none; border: none; color: var(--text-muted); font-weight: 700; font-size: 0.85rem; padding: 6px 14px; border-radius: 8px; cursor: pointer; transition: all 0.2s; }
.vocab-view-btn.active { background: var(--primary); color: #ffffff; }

.vocab-cards-grid { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.vocab-card { background: #0f172a; border: 1px solid var(--border); border-radius: 14px; padding: 18px; transition: all 0.2s; }
.vocab-card:hover { border-color: var(--primary-light); box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15); }
.vocab-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; flex-wrap: wrap; gap: 8px; }
.vocab-word-title { font-size: 1.2rem; font-weight: 800; color: var(--primary-light); display: flex; align-items: center; gap: 8px; }
.vocab-type-badge { background: rgba(99, 102, 241, 0.2); color: var(--primary-light); font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.vocab-ipa-text { color: var(--text-muted); font-style: italic; font-size: 0.9rem; }
.vocab-vi-meaning { font-size: 1rem; font-weight: 700; color: var(--text-main); margin-bottom: 8px; }

.collocations-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; margin-bottom: 10px; }
.collocation-chip { background: rgba(16, 185, 129, 0.15); border: 1px solid rgba(16, 185, 129, 0.3); color: var(--accent-green); font-size: 0.82rem; font-weight: 700; padding: 4px 10px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.vocab-example-box { background: rgba(30, 41, 59, 0.6); border-left: 3px solid var(--primary-light); border-radius: 6px; padding: 10px 12px; font-size: 0.9rem; line-height: 1.6; margin-top: 8px; }
.vocab-note-box { background: rgba(245, 158, 11, 0.1); border: 1px dashed var(--accent-orange); border-radius: 8px; padding: 8px 12px; font-size: 0.85rem; color: #fde68a; margin-top: 8px; }

/* Reflex Module */
.word-chip { background: #0f172a; border: 1px solid var(--primary-light); color: var(--primary-light); padding: 8px 14px; border-radius: 8px; font-weight: 700; cursor: pointer; user-select: none; transition: all 0.2s; }
.word-chip:hover { background: var(--primary); color: #fff; }
.word-chip.used { opacity: 0.3; cursor: not-allowed; }

/* Progress Bar Style */
.progress-bar {
    width: 100%;
    height: 8px;
    background: #0f172a;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-light), var(--accent-green));
    transition: width 0.4s ease-in-out;
}

.day-progress-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 18px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

/* Đánh dấu ngày đã học trong Sidebar Menu */
.day-item.completed {
    position: relative;
    border-left: 3px solid var(--accent-green);
}

.day-item.completed::after {
    content: "✓";
    color: var(--accent-green);
    font-weight: bold;
    margin-left: auto;
    margin-right: 6px;
}

/* Responsive Mobile Adjustment */
@media screen and (max-width: 768px) {
    body {
        flex-direction: column;
    }
    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .main-content {
        margin-left: 0;
        padding: 16px;
    }
    .tab-nav {
        overflow-x: auto;
        white-space: nowrap;
    }
}
/* ==========================================
   TRỢ LÝ AI (BẢN HOÀN CHỈNH - FIX LỖI MÀU CẤU TRÚC)
   ========================================== */

/* ==========================================
   TRỢ LÝ AI (BẢN TỐI ƯU CẤU TRÚC LAYOUT)
   ========================================== */

/* 1. Nút Trợ Lý Viền Gradient trên Header */
.btn-assistant-pill {
    background: linear-gradient(#0f172a, #0f172a) padding-box,
                linear-gradient(135deg, #ec4899, #3b82f6) border-box;
    border: 2px solid transparent;
    border-radius: 9999px;
    color: #ffffff !important;
    padding: 8px 18px;
    font-size: 0.9rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn-assistant-pill:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(236, 72, 153, 0.3);
}

.text-gradient {
    background: linear-gradient(135deg, #ec4899, #a855f7, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* 2. Panel Drawer Trợ Lý AI */
.ai-drawer {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100vh;
    background: #ffffff !important;
    color: #0f172a !important;
    z-index: 99999;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.25);
    border-top-left-radius: 24px;
    border-bottom-left-radius: 24px;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    transition: right 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: 'Plus Jakarta Sans', sans-serif;
}
.ai-drawer.open { right: 0; }
.ai-drawer.expanded { width: 600px; }

/* Header Panel Cố Định */
.ai-drawer-header {
    flex-shrink: 0;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f1f5f9;
}
.ai-drawer-header-left, .ai-drawer-header-right { display: flex; align-items: center; gap: 12px; }
.ai-drawer-title { font-weight: 800; font-size: 1.05rem; color: #0f172a !important; }
.ai-icon-btn { background: transparent; border: none; color: #64748b !important; font-size: 1.1rem; cursor: pointer; }
.ai-icon-btn:hover { color: #0f172a !important; }

/* Body Content Tự Cuộn Theo Chiều Dọc */
.ai-drawer-body {
    flex: 1 1 auto !important;
    padding: 20px;
    overflow-y: auto !important;
    min-height: 0 !important;
    background: #ffffff !important;
}

/* Action Cards */
.ai-action-list { display: flex; flex-direction: column; gap: 10px; }
.ai-action-item {
    background: #f8fafc !important;
    border: 1px solid #f1f5f9 !important;
    padding: 12px 14px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    text-align: left;
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155 !important;
    transition: background 0.2s;
}
.ai-action-item:hover { background: #f1f5f9 !important; }
.ai-action-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}
.ai-action-icon.blue { background: #dbeafe !important; color: #2563eb !important; }
.ai-action-icon.purple { background: #f3e8ff !important; color: #9333ea !important; }
.ai-action-icon.green { background: #dcfce7 !important; color: #16a34a !important; }

/* Footer & Input Cố Định Đáy */
.ai-drawer-footer {
    flex-shrink: 0 !important;
    padding: 16px 20px;
    border-top: 1px solid #f1f5f9;
    background: #ffffff !important;
}
.ai-input-card {
    border: 2px solid #a855f7 !important;
    border-radius: 20px;
    padding: 12px;
    background: #ffffff !important;
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.1);
}

/* Sửa triệt để ô gõ văn bản đè nền */
#ai-user-input {
    width: 100% !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    resize: none !important;
    font-size: 0.88rem !important;
    color: #0f172a !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    font-family: inherit !important;
}
#ai-user-input::placeholder {
    color: #64748b !important;
}

.ai-input-toolbar { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.ai-toolbar-left { display: flex; align-items: center; gap: 6px; }
.ai-tool-btn { background: transparent; border: none; color: #64748b !important; font-size: 1rem; cursor: pointer; }
.ai-tool-badge {
    background: #f3e8ff !important;
    border: none;
    color: #6b21a8 !important;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
}
.ai-send-circle-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f1f5f9 !important;
    border: none;
    color: #475569 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.ai-send-circle-btn:hover { background: #a855f7 !important; color: #ffffff !important; }
.ai-disclaimer { font-size: 0.7rem; color: #94a3b8 !important; text-align: center; margin-top: 8px; }

/* Bong bóng Chat trong Lịch sử */
.ai-chat-history { display: flex; flex-direction: column; gap: 12px; }
.chat-bubble { max-width: 85%; padding: 10px 14px; border-radius: 12px; font-size: 0.88rem; line-height: 1.5; }
.chat-bubble.user { background: #6366f1 !important; color: #ffffff !important; align-self: flex-end; }
.chat-bubble.bot {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    align-self: flex-start;
    border: 1px solid #e2e8f0 !important;
}
.chat-bubble.bot * { color: #0f172a !important; }
/* SỬA TRIỆT ĐỂ LỖI CHỮ BỊ ẨN KHI GÕ TRONG KHUNG AI */
.ai-input-card textarea#ai-user-input {
    background: transparent !important;
    background-color: transparent !important;
    color: #0f172a !important; /* Màu chữ đen xám đậm hiển thị rõ nét */
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 4px 0 !important;
    font-family: inherit !important;
    font-size: 0.9rem !important;
    line-height: 1.5 !important;
}

/* Màu chữ gợi ý (Placeholder) */
.ai-input-card textarea#ai-user-input::placeholder {
    color: #94a3b8 !important;
    opacity: 1 !important;
}