/* Bộ thiết kế chung. Mọi agent dùng biến & lớp ở đây, KHÔNG tự đặt màu/cỡ chữ riêng.
   Agent Vỏ app sở hữu file này; agent khác cần thêm kiểu riêng thì tạo public/css/<phan>.css
   và chỉ dùng biến --... ở đây. Đổi --brand là đổi màu toàn app
   (nhớ đổi kèm theme-color trong index.html, manifest.webmanifest và biểu tượng). */

:root {
  --brand: #c2410c;          /* cam thương hiệu (anh Tâm chốt) — chữ trắng tương phản ≈5:1 */
  --brand-ink: #ffffff;      /* chữ trên nền màu chính */
  --brand-soft: #fff1e6;     /* nền nhạt của màu chính */
  --brand-hover: #9a3412;    /* :hover / :active của nút chính */
  --accent: #1f2a44;         /* điểm nhấn tương phản với cam (nút mua, huy hiệu) */
  --accent-ink: #ffffff;

  --bg: #fbf8f5;
  --surface: #ffffff;
  --surface-2: #f5f1ec;      /* nền phụ: ô xám nhạt, thanh tiến độ */
  --ink: #1d1d1b;
  --ink-2: #55534e;
  --ink-3: #8a877f;
  --line: #ebe5dd;
  --ok: #1f8a4c;
  --danger: #c0392b;
  --on-dark: #ffffff;        /* chữ trên nền đậm (lỗi, thông báo nhanh, chấm đỏ) */
  --overlay: rgba(29, 29, 27, .55);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --fs-xs: 12px; --fs-sm: 14px; --fs: 16px; --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 28px;

  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --maxw: 960px;
  --top-h: 56px;             /* thanh trên */
  --nav-h: 64px;             /* thanh dưới (điện thoại) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { margin: 0; font: 400 var(--fs)/1.55 var(--font); color: var(--ink); background: var(--bg); min-height: 100vh; min-height: 100dvh; }
a { color: var(--brand); text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--s3); letter-spacing: -.01em; }
h1 { font-size: var(--fs-2xl); } h2 { font-size: var(--fs-xl); } h3 { font-size: var(--fs-lg); }
p { margin: 0 0 var(--s3); }
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ===== Khung ===== */
.container { max-width: var(--maxw); margin: 0 auto; padding: var(--s4); padding-left: max(var(--s4), var(--safe-left)); padding-right: max(var(--s4), var(--safe-right)); }
#view { min-height: 60vh; padding-bottom: calc(var(--nav-h) + var(--s5) + var(--safe-bottom)); }

/* Thanh trên */
.topbar { position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--line);
  padding-top: var(--safe-top); }
.topbar-in { max-width: var(--maxw); margin: 0 auto; height: var(--top-h); display: flex; align-items: center; gap: var(--s4);
  padding: 0 max(var(--s4), var(--safe-right)) 0 max(var(--s4), var(--safe-left)); }
.logo { display: inline-flex; align-items: center; gap: var(--s2); color: var(--ink); min-height: 44px; }
.logo-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: var(--brand-ink);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--fs-lg); flex: none; }
.logo-text { display: flex; flex-direction: column; line-height: 1.15; }
.logo-text strong { font-size: var(--fs); }
.logo-text small { font-size: var(--fs-xs); color: var(--ink-3); font-weight: 500; }
.topnav { display: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }
.icon-btn { position: relative; width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); }
.icon-btn:hover, .icon-btn.active { background: var(--brand-soft); color: var(--brand); }
.icon-btn svg, .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.only-desktop { display: none !important; }

/* Ô người dùng */
#user-slot { display: inline-flex; align-items: center; gap: var(--s2); }
.user-chip { display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s1); border-radius: 999px; color: var(--ink); }
.user-chip .user-name { display: none; font-weight: 600; font-size: var(--fs-sm); max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip:hover .avatar { box-shadow: 0 0 0 3px var(--brand-soft); }

/* Thanh dưới (điện thoại) */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left); box-shadow: 0 -2px 12px rgba(0,0,0,.04); }
.tabbar a { height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-3); font-size: 11px; font-weight: 500; line-height: 1.2; text-align: center; }
.tabbar a.active { color: var(--brand); font-weight: 700; }
.tabbar a.active svg { stroke-width: 2.2; }
.tab-ico { position: relative; display: inline-flex; }

/* Chấm đỏ số thông báo chưa đọc */
.notif-count { position: absolute; top: -4px; right: -8px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: var(--on-dark); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  box-shadow: 0 0 0 2px var(--surface); }
.icon-btn .notif-count { top: 4px; right: 2px; }

/* Banner của vỏ app (cài app, mở bằng trình duyệt, có bản mới) */
.banners { max-width: var(--maxw); margin: 0 auto; padding: 0 max(var(--s4), var(--safe-right)) 0 max(var(--s4), var(--safe-left)); }
.banners:empty { display: none; }
.banner { display: flex; gap: var(--s3); align-items: flex-start; margin-top: var(--s3); padding: var(--s3) var(--s4);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); font-size: var(--fs-sm); }
.banner-ico { flex: none; width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.banner-ico svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.banner-body { flex: 1; min-width: 0; }
.banner-body strong { display: block; font-size: var(--fs); margin-bottom: 2px; }
.banner-body p { margin: 0 0 var(--s2); color: var(--ink-2); }
.banner-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.banner-close { flex: none; width: 36px; height: 36px; margin: -6px -10px 0 0; border: 0; background: none; color: var(--ink-3);
  font-size: 22px; line-height: 1; cursor: pointer; border-radius: 50%; }
.banner-close:hover { background: var(--surface-2); }
.banner-warn { background: var(--brand-soft); border-color: var(--brand-soft); }
.banner-warn .banner-ico { background: var(--surface); }
.ios-share { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; fill: none; stroke: var(--brand); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Thanh "Đã có bản mới" */
.update-bar { position: fixed; left: 50%; transform: translateX(-50%); z-index: 90; bottom: calc(var(--nav-h) + var(--s3) + var(--safe-bottom));
  width: min(92vw, 420px); display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s2) var(--s2) var(--s4);
  background: var(--accent); color: var(--accent-ink); border-radius: var(--r); box-shadow: var(--shadow-lg); font-weight: 600; font-size: var(--fs-sm); }
.update-bar span { flex: 1; }

/* ===== Thẻ & bố cục ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s4); box-shadow: var(--shadow); }
a.card { display: block; color: inherit; }
.stack > * + * { margin-top: var(--s3); }
.row { display: flex; gap: var(--s3); align-items: center; }
.grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.section { margin-top: var(--s6); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.section-head h2 { margin: 0; font-size: var(--fs-lg); }
.section-head a { font-size: var(--fs-sm); font-weight: 600; }

/* ===== Nút ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s4);
  border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 600 var(--fs) var(--font); cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover, .btn-primary:active { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { filter: brightness(1.15); border-color: var(--accent); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--on-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-ghost:hover { background: var(--brand-soft); border-color: transparent; }
.btn-sm { min-height: 34px; padding: 0 var(--s3); font-size: var(--fs-sm); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ===== Form ===== */
.field { display: block; margin-bottom: var(--s4); }
.field > span { display: block; font-size: var(--fs-sm); font-weight: 600; margin-bottom: var(--s1); color: var(--ink-2); }
.input, textarea.input, select.input { width: 100%; min-height: 46px; padding: var(--s3); border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); font: var(--fs) var(--font); color: var(--ink); }
.input:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.error-text { color: var(--danger); font-size: var(--fs-sm); }

/* ===== Huy hiệu, giá, tiến độ ===== */
.badge { display: inline-block; padding: 2px var(--s2); border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.badge-accent { background: var(--accent); color: var(--accent-ink); }
.price { font-weight: 700; color: var(--brand); }
.price-old { color: var(--ink-3); text-decoration: line-through; font-size: var(--fs-sm); margin-left: var(--s2); font-weight: 400; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }

/* ===== Trạng thái ===== */
.empty { text-align: center; padding: var(--s7) var(--s4); color: var(--ink-2); }
.loading { display: flex; justify-content: center; padding: var(--s7); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Ảnh đại diện */
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Thông báo nhanh */
#toasts { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--s4) + var(--safe-bottom)); transform: translateX(-50%); z-index: 100; display: grid; gap: var(--s2); width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: var(--on-dark); padding: var(--s3) var(--s4); border-radius: var(--r-sm); box-shadow: var(--shadow); transition: opacity .4s; pointer-events: auto; }
.toast-ok { background: var(--ok); } .toast-error { background: var(--danger); }
.toast.out { opacity: 0; }

/* Video tỉ lệ 16:9 */
.video { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: var(--r); overflow: hidden; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ===== Máy tính (≥ 768px): menu trên, ẩn thanh dưới ===== */
@media (min-width: 768px) {
  :root { --top-h: 64px; }
  .topnav { display: flex; gap: var(--s1); margin-left: var(--s5); }
  .topnav a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 var(--s3); border-radius: var(--r-sm); color: var(--ink-2); font-weight: 600; }
  .topnav a:hover { background: var(--surface-2); color: var(--ink); }
  .topnav a.active { background: var(--brand-soft); color: var(--brand); }
  .tabbar, .only-mobile { display: none !important; }
  .only-desktop { display: inline-flex !important; }
  .user-chip .user-name { display: inline; }
  .user-chip { padding: 0 var(--s3) 0 var(--s1); border: 1px solid var(--line); }
  #view { padding-bottom: calc(var(--s7) + var(--safe-bottom)); }
  #toasts, .update-bar { bottom: calc(var(--s5) + var(--safe-bottom)); }
  .container { padding: var(--s5) var(--s4); }
}

/* Chạy như app đã cài: thêm khoảng đệm phía trên cho tai thỏ (thanh trên đã có --safe-top) */
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
}

/* ===== Trang chủ (agent D) ===== */
.hero { background: var(--brand); color: var(--brand-ink); border-radius: var(--r-lg); padding: var(--s5) var(--s4); box-shadow: var(--shadow); }
.hero h1 { color: var(--brand-ink); margin-bottom: var(--s2); }
.hero-hello { font-weight: 600; opacity: .9; margin-bottom: var(--s1); }
.hero-text { opacity: .92; max-width: 560px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
.btn-hero { background: var(--surface); border-color: var(--surface); color: var(--brand); }
.btn-hero:hover { background: var(--brand-soft); border-color: var(--brand-soft); }
.btn-hero-ghost { background: transparent; border-color: var(--brand-ink); color: var(--brand-ink); }
.btn-hero-ghost:hover { background: var(--brand-hover); border-color: var(--brand-ink); }

.hscroll { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 85%); gap: var(--s3); overflow-x: auto;
  scroll-snap-type: x mandatory; margin: 0 calc(-1 * var(--s4)); padding: 2px var(--s4) var(--s2); scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { scroll-snap-align: start; }
.continue-card { display: flex; flex-direction: column; gap: var(--s3); }
.continue-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); }
.continue-top h3 { margin: 0; font-size: var(--fs); }
.continue-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }

.course-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s; }
.course-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.course-cover { position: relative; aspect-ratio: 16 / 9; background: var(--brand-soft); }
.course-cover img { width: 100%; height: 100%; object-fit: cover; }
.course-cover-ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 48px; font-weight: 700; color: var(--brand); }
.course-owned { position: absolute; top: var(--s2); left: var(--s2); }
.course-body { padding: var(--s4); display: flex; flex-direction: column; flex: 1; }
.course-body h3 { font-size: var(--fs); margin-bottom: var(--s1); }
.course-body p { margin-bottom: var(--s3); }
.course-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: var(--s2); flex-wrap: wrap; }
.course-go { font-size: var(--fs-sm); font-weight: 600; color: var(--brand); }

.community-card { display: flex; gap: var(--s4); align-items: flex-start; }
.community-ico { flex: none; width: 48px; height: 48px; border-radius: var(--r); background: var(--brand-soft); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; }
.community-ico svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.community-body { flex: 1; min-width: 0; }
.community-body h3 { margin-bottom: var(--s1); }

/* ===== Thông báo (agent D) ===== */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }
.page-head h1 { margin: 0; }
.notif-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.notif-list:empty { display: none; }
.notif-list li + li { border-top: 1px solid var(--line); }
.notif { width: 100%; display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s4); min-height: 64px; border: 0; background: none;
  text-align: left; font: inherit; color: inherit; cursor: pointer; }
.notif:hover { background: var(--surface-2); }
.notif.unread { background: var(--brand-soft); }
.notif-dot { flex: none; width: 10px; height: 10px; margin-top: 7px; border-radius: 50%; background: transparent; }
.notif.unread .notif-dot { background: var(--brand); }
.notif-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.notif-main strong { font-weight: 600; }
.notif.unread .notif-main strong { font-weight: 700; }
.notif-text { color: var(--ink-2); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.notif-time { color: var(--ink-3); font-size: var(--fs-xs); }
.notif-go { flex: none; align-self: center; color: var(--ink-3); font-size: 24px; line-height: 1; }
.notif-more { margin-top: var(--s4); }

@media (min-width: 768px) {
  .hero { padding: var(--s7) var(--s6); }
  .hero h1 { font-size: 36px; }
  .hscroll { grid-auto-flow: row; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); overflow: visible; margin: 0; padding: 0; }
}
