* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font-family); background: var(--bg); color: var(--text); font-size: 15.5px; }
h1, h2, h3, .stat .num { font-family: var(--font-heading); }
.sidebar .brand { font-family: var(--font-display); }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-primary-light); border-color: var(--brand-primary); }
label { font-size: 13px; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 4px; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 30% 20%, #1B2552 0%, var(--navy) 45%, var(--navy-deep) 100%); }
.login-card { background: var(--ivory); border-radius: 16px; padding: 40px 36px; width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.45); border: 1px solid var(--gold); text-align: center; }
.login-card h1 { font-family: var(--font-display); font-size: 24px; margin-bottom: 2px; color: var(--navy); letter-spacing: .12em; }
.login-card .motto { font-size: 12px; letter-spacing: .28em; color: var(--gold-dk); text-transform: uppercase; margin-bottom: 20px; font-family: var(--font-display); }
.login-card form { text-align: left; }
.login-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-card .field { margin-bottom: 14px; }
.login-logo { height: 48px; margin-bottom: 16px; }
.demo-accounts { margin-top: 18px; font-size: 12px; color: var(--text-muted); background: var(--bg); border-radius: var(--radius-sm); padding: 10px 12px; line-height: 1.7; }

/* ---- Đăng nhập bằng Google ---- */
.or-divider { display: flex; align-items: center; gap: 10px; margin: 14px 0 12px; font-size: 12px; color: var(--text-muted); }
.or-divider::before, .or-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.btn-google { width: 100%; justify-content: center; gap: 10px; background: #fff; color: #3c4043;
  border: 1px solid var(--border); font-weight: 600; text-decoration: none; }
.btn-google:hover { background: #f7f8f8; border-color: var(--gold-dk); }
.btn-google img { display: block; }
/* ---- Đăng nhập bằng Facebook — xanh thương hiệu chính thức #1877F2 ---- */
.btn-facebook { width: 100%; justify-content: center; gap: 10px; background: #1877F2; color: #fff;
  border: 1px solid #1877F2; font-weight: 600; text-decoration: none; }
.btn-facebook:hover { background: #166FE5; border-color: #166FE5; }
.btn-facebook img { display: block; }
.login-card .hint { margin-top: 8px; font-size: 11.5px; color: var(--text-muted); line-height: 1.6; }

/* ---- Layout ---- */
.shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 232px; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar .brand { padding: 20px 18px; font-weight: 700; font-size: 16px; letter-spacing: .1em; color: var(--gold-lt); display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(200,161,75,.25); }
.sidebar .brand img { height: 36px; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 8px; }
.sidebar a { display: flex; align-items: center; gap: 10px; color: var(--sidebar-text); text-decoration: none; padding: 10px 12px; border-radius: 8px; margin-bottom: 2px; font-size: 14px; }
.sidebar .nav-group-label { padding: 14px 12px 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: rgba(255,255,255,.45); }
.sidebar nav > .nav-group-label:first-child { padding-top: 6px; }
.sidebar a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar a.active { background: rgba(255,255,255,.12); color: #fff; border-left: 3px solid var(--sidebar-active); padding-left: 9px; }
.sidebar .user-box { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.sidebar .user-box .name { color: #fff; font-weight: 600; }
.sidebar .user-box .role { font-size: 12px; opacity: .8; }
.sidebar .user-box button { margin-top: 8px; width: 100%; background: rgba(255,255,255,.1); color: #fff; border: none; padding: 7px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.sidebar .user-box button:hover { background: rgba(255,255,255,.2); }

.main { flex: 1; overflow-y: auto; padding: 24px 28px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-head h2 { font-size: 21px; font-family: var(--font-heading); }
.page-head .actions { display: flex; gap: 8px; }

/* ---- Components ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer; font-size: 14px; font-weight: 600; background: var(--brand-primary); color: #fff; }
.btn:hover { background: var(--brand-primary-dark); }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.accent { background: linear-gradient(135deg, var(--gold-dk), var(--gold) 45%, var(--gold-lt)); color: var(--navy-deep); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card h3 { font-size: 15px; margin-bottom: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .num { font-size: 26px; font-weight: 700; color: var(--brand-primary); }
.stat .lbl { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.stat.accent .num { color: var(--brand-accent); }

table.data { width: 100%; border-collapse: collapse; background: var(--surface); }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: 10px 12px; border-bottom: 2px solid var(--border); background: #FAFBFE; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:hover td { background: var(--brand-primary-light); cursor: default; }
table.data tr.clickable { cursor: pointer; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.green { background: var(--success-bg); color: var(--success); }
.badge.orange { background: var(--warning-bg); color: var(--warning); }
.badge.red { background: var(--danger-bg); color: var(--danger); }
.badge.blue { background: var(--info-bg); color: var(--info); }
.badge.gray { background: #EEF0F5; color: var(--text-muted); }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(13,20,40,.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 24px; }
.modal.wide { max-width: 820px; }
.modal h3 { margin-bottom: 18px; font-size: 17px; }
.modal .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal .field { margin-bottom: 12px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: #fff; padding: 11px 18px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); animation: slideup .25s ease; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slideup { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tabs button { background: none; border: none; padding: 10px 16px; font-size: 14px; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tabs button.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }

/* Attendance buttons */
.att-btns { display: flex; gap: 4px; }
.att-btns button { padding: 5px 10px; border: 1px solid var(--border); background: #fff; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.att-btns button.sel-present { background: var(--success); color: #fff; border-color: var(--success); }
.att-btns button.sel-absent { background: var(--danger); color: #fff; border-color: var(--danger); }
.att-btns button.sel-late { background: var(--warning); color: #fff; border-color: var(--warning); }
.att-btns button.sel-excused { background: var(--info); color: #fff; border-color: var(--info); }

.chart-box { position: relative; height: 300px; }
.muted { color: var(--text-muted); font-size: 13px; }
.empty { text-align: center; color: var(--text-muted); padding: 40px 20px; }
.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid-2col { grid-template-columns: 1fr; } .sidebar { width: 64px; } .sidebar .brand span, .sidebar a span, .sidebar .user-box { display: none; } }

/* ---- Print (báo cáo phụ huynh) ---- */
@media print {
  .sidebar, .page-head .actions, .toolbar, .no-print { display: none !important; }
  .main { padding: 0; overflow: visible; }
  .shell { display: block; height: auto; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
.report-print h1 { color: var(--brand-primary); font-size: 22px; }
.report-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid var(--brand-primary); padding-bottom: 14px; margin-bottom: 18px; }

/* ===== Phase 1: Khóa học · Bài tập · Quiz ===== */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 14px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card-grid .card { margin-bottom: 0; }
.card .card-title { font-family: var(--font-heading); font-size: 16px; font-weight: 700; color: var(--brand-primary); margin-bottom: 4px; }

.chapter-head { font-size: 14px; font-weight: 700; color: var(--brand-primary); margin: 16px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.lesson-list { display: flex; flex-direction: column; gap: 6px; }
.lesson-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.lesson-item .lesson-title { font-weight: 600; cursor: pointer; }
.lesson-item .lesson-title:hover { color: var(--brand-primary); text-decoration: underline; }

.opt-list { margin: 8px 0 0 18px; display: flex; flex-direction: column; gap: 3px; }
.opt-list li { padding: 2px 0; }
.opt-list li.correct { color: var(--success); font-weight: 600; }
.opt-list li.wrong { color: var(--danger); font-weight: 600; }

.take-opts { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.take-opt { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; transition: background .15s, border-color .15s; }
.take-opt:hover { background: var(--parchment); }
.take-opt input { width: auto; }

.quiz-timer { display: inline-block; font-weight: 700; color: var(--brand-primary); background: var(--info-bg); padding: 6px 14px; border-radius: 99px; margin-bottom: 10px; }
.quiz-timer.warn { color: var(--danger); background: var(--danger-bg); }

/* ===== Phase 2: CRM ===== */
.pipeline { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.pipe-step { flex: 1; min-width: 96px; text-align: center; padding: 10px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; transition: all .15s; }
.pipe-step:hover { border-color: var(--brand-primary); }
.pipe-step.active { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; }
.pipe-step.active .pipe-num, .pipe-step.active .pipe-lbl { color: #fff; }
.pipe-step.lost { border-style: dashed; }
.pipe-step.lost.active { background: var(--danger); border-color: var(--danger); }
.pipe-num { font-size: 20px; font-weight: 700; color: var(--brand-primary); }
.pipe-lbl { font-size: 12px; color: var(--text-muted); font-weight: 600; }

.due-now { color: var(--danger); font-weight: 700; }

.timeline { display: flex; flex-direction: column; gap: 10px; }
.tl-item { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--brand-primary); border-radius: var(--radius-sm); padding: 12px 16px; }
.tl-head { margin-bottom: 4px; font-size: 13px; }

.funnel-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.funnel-lbl { width: 120px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.funnel-bar-wrap { flex: 1; background: #EEF0F5; border-radius: 99px; height: 22px; overflow: hidden; }
.funnel-bar { height: 100%; background: var(--brand-primary); border-radius: 99px; min-width: 2px; transition: width .3s; }
.funnel-bar.lost { background: var(--danger); }
.funnel-num { width: 36px; text-align: right; font-weight: 700; }

/* ===== Phase 2b: Bán khóa học ===== */
.chk-list { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface); }
.chk-item { display: flex; align-items: center; gap: 8px; font-size: 14.5px; cursor: pointer; }
.chk-item input { width: auto; }
table.data s { opacity: .7; }

/* ===== Phase 3: AI Trợ lý học tập ===== */
.ai-banner { background: var(--info-bg); border: 1px solid var(--info); border-radius: var(--radius-sm); padding: 11px 16px; margin-bottom: 16px; font-size: 14.5px; color: var(--info); }
.ai-banner.on { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.ai-banner code { background: rgba(0,0,0,.07); padding: 1px 6px; border-radius: 4px; font-size: 13px; }

.ai-summary { background: var(--brand-accent-light); border: 1px solid var(--gold); border-radius: var(--radius); padding: 16px 18px; margin: 14px 0; }

.skill-row { display: flex; align-items: center; gap: 12px; margin-bottom: 9px; }
.skill-lbl { width: 92px; font-size: 14px; font-weight: 600; color: var(--text-muted); }
.skill-bar-wrap { flex: 1; background: #EEF0F5; border-radius: 99px; height: 20px; overflow: hidden; }
.skill-bar { height: 100%; border-radius: 99px; min-width: 2px; transition: width .35s; }
.skill-bar.green { background: var(--success); }
.skill-bar.blue { background: var(--info); }
.skill-bar.orange { background: var(--warning); }
.skill-bar.red { background: var(--danger); }
.skill-bar.gray { background: #B9BECD; }
.skill-num { width: 60px; text-align: right; font-weight: 700; }

.risk-list { margin: 0 0 0 18px; }
.risk-list li { padding: 2px 0; font-size: 14.5px; }
.risk-panel { border-left: 3px solid var(--warning); }

.plan-content { white-space: pre-wrap; font-family: var(--font-family); font-size: 15px; line-height: 1.8; margin-top: 12px; background: rgba(0,0,0,.02); padding: 14px 16px; border-radius: var(--radius-sm); max-height: 420px; overflow: auto; }

/* ===== Phase 4: Tài chính · Chấm công · Thông báo ===== */
.notif-badge { background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; min-width: 19px; height: 19px; border-radius: 99px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; margin-left: auto; }

.clock-card { text-align: center; padding: 28px 20px; }
.clock-now { font-family: var(--font-heading); font-size: 40px; font-weight: 700; color: var(--brand-primary); letter-spacing: .04em; }
.clock-card .btn { margin-top: 14px; }
.clock-card p { margin: 8px 0; }

.notif-list { display: flex; flex-direction: column; gap: 8px; }
.notif-item { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: var(--radius-sm); padding: 13px 16px; cursor: default; }
.notif-item.unread { background: var(--brand-primary-light); border-left-color: var(--brand-primary); cursor: pointer; }
.notif-item.success { border-left-color: var(--success); }
.notif-item.warning { border-left-color: var(--warning); }
.notif-item.error { border-left-color: var(--danger); }
.notif-title { font-weight: 700; color: var(--text); margin-bottom: 2px; }

/* ===== Phase 7: Tệp đính kèm ===== */
.file-list { display: flex; flex-direction: column; gap: 5px; }
.file-item { display: flex; align-items: center; gap: 9px; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14.5px; }
.file-item .file-name { font-weight: 600; color: var(--brand-primary); text-decoration: none; }
.file-item .file-name:hover { text-decoration: underline; }

/* ===== Phase 8: Trao đổi & Tiến độ bài giảng ===== */
.chat-wrap { display: grid; grid-template-columns: 260px 1fr; gap: 14px; height: calc(100vh - 190px); min-height: 420px; }
.chat-threads { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.thread-item { padding: 11px 13px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; transition: all .15s; }
.thread-item:hover { border-color: var(--brand-primary); }
.thread-item.active { background: var(--brand-primary-light); border-color: var(--brand-primary); }

.chat-main { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.chat-head { padding: 13px 18px; border-bottom: 1px solid var(--border); background: var(--parchment); }
.chat-log { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { display: flex; }
.chat-msg.mine { justify-content: flex-end; }
.chat-bubble { position: relative; max-width: 76%; background: var(--parchment); border: 1px solid var(--border); border-radius: 12px; padding: 9px 14px; font-size: 15px; }
.chat-msg.mine .chat-bubble { background: var(--brand-primary-light); border-color: #C9D0E8; }
.chat-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 3px; }
.chat-del { position: absolute; top: 4px; right: 6px; border: none; background: none; color: var(--text-muted); cursor: pointer; font-size: 15px; line-height: 1; opacity: 0; }
.chat-bubble:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--danger); }
.chat-input { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); background: var(--parchment); }
.chat-input textarea { flex: 1; resize: none; }

.lesson-item.done { background: var(--success-bg); border-color: var(--success); }
.lesson-item.done .lesson-title { text-decoration: line-through; opacity: .75; }
.lesson-done { display: flex; align-items: center; cursor: pointer; }
.lesson-done input { width: 17px; height: 17px; cursor: pointer; }

@media (max-width: 780px) { .chat-wrap { grid-template-columns: 1fr; height: auto; } .chat-threads { max-height: 200px; } }


/* ===== Luoi thumbnail khoa hoc ===== */
.cc-search { width: 100%; max-width: 420px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 99px; font: inherit; background: var(--surface); margin-bottom: 12px; }
.cc-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.cc-chip { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer; }
.cc-chip.on { background: var(--navy, #141B4D); color: #fff; border-color: transparent; }
.cc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.cc-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s; }
.cc-card:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(20,27,77,.18); }
.cc-thumb { position: relative; height: 150px; color: #fff; display: flex; flex-direction: column; justify-content: flex-end; padding: 14px; overflow: hidden; }
.cc-icon { position: absolute; right: 12px; top: 8px; font-size: 64px; opacity: .28; line-height: 1; }
.cc-topic { position: absolute; left: 12px; top: 12px; background: rgba(255,255,255,.22); padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.cc-free { position: absolute; left: 12px; top: 40px; background: #fff; color: #166534; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.cc-cover-title { font-weight: 700; font-size: 17px; line-height: 1.25; text-shadow: 0 1px 3px rgba(0,0,0,.35); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cc-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.cc-title { font-weight: 700; }
.cc-meta { font-size: 13px; }
.cc-desc { margin: 0; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; flex: 1; }
.cc-body .badge { align-self: flex-start; }
