/* base.css — khối dùng chung cho MỌI trang theo khung mới (layouts/app.html).
   Phần riêng của từng trang để ở css/pages/<trang>.css. Chỉ dùng biến trong tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
button { font-family: inherit; }
img { max-width: 100%; }
.jp, :lang(ja) { font-family: var(--font-jp); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.icon { flex-shrink: 0; display: block; }
/* Nhảy tới #id (vd lùi về /admin#content): chừa chỗ cho thanh trên đang dính, khỏi che tiêu đề. */
[id] { scroll-margin-top: calc(var(--topbar-h) + 12px); }
/* Thuộc tính hidden luôn thắng display của lớp (.prop, .callout, .card… đặt display riêng). */
[hidden] { display: none !important; }

/* ── Khung: thanh bên + khu nội dung ─────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.side {
  width: var(--side-w);
  flex-shrink: 0;
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 14px 10px;
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px;
}
.side-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 12px;
  font-size: 15px; font-weight: 700; color: var(--ink); text-decoration: none;
}
.side-brand img { width: 24px; height: 24px; border-radius: 6px; object-fit: cover; }
.side-brand:hover { color: var(--ink); }

.side-search {
  display: flex; align-items: center; gap: 8px;
  width: 100%; height: 32px; padding: 0 8px; margin-bottom: 8px;
  border-radius: var(--r); border: 1px solid var(--line); background: var(--bg);
  font-size: 13px; color: var(--faint); cursor: pointer; text-align: left;
}
.side-search:hover { border-color: var(--faint); }
.side-search .grow { flex-grow: 1; }
.side-search kbd { font: inherit; font-size: 11px; color: var(--faint); }

.side-group {
  margin: 12px 0 4px; padding: 0 8px;
  font-size: 12px; font-weight: 600; color: var(--faint);
}
.side-link {
  display: flex; align-items: center; gap: 10px;
  height: 32px; padding: 0 8px; border-radius: var(--r);
  text-decoration: none; font-size: 14px; color: var(--text);
}
.side-link .icon { color: var(--muted); }
.side-link:hover { background: var(--line); color: var(--ink); }
.side-link.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-link.is-active .icon { color: var(--accent); }
.side-foot { margin-top: auto; padding-top: 12px; }
button.side-link { width: 100%; border: 0; background: none; font: inherit; font-size: 14px; cursor: pointer; text-align: left; }
/* Chấm đỏ "còn bài lớp giao chưa làm" (layouts/app.html, core/homework.py) */
.nav-dot {
  width: 8px; height: 8px; margin-left: auto; flex-shrink: 0;
  border-radius: 50%; background: #e5383b; box-shadow: 0 0 0 2px var(--bg);
}
.nav-dot--corner { position: absolute; top: 5px; right: 5px; margin: 0; }
/* Số tin chat chưa đọc cạnh mục "Trò chuyện" (js/core/unread.js cập nhật tức thì) */
.nav-count {
  margin-left: auto; flex-shrink: 0; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: #e5383b; color: #fff; box-shadow: 0 0 0 2px var(--bg);
  font-size: 11px; font-weight: 700; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums;
}
.nav-count.is-bump { animation: nav-count-bump 0.5s ease; }
@keyframes nav-count-bump { 40% { transform: scale(1.25); } }
@media (prefers-reduced-motion: reduce) { .nav-count.is-bump { animation: none; } }

.main { flex-grow: 1; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 20px;
  font-size: 14px; color: var(--ink);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-menu {
  display: none; position: relative;
  width: 32px; height: 32px; margin-left: -6px;
  border: 0; border-radius: var(--r); background: none; color: var(--ink);
  place-items: center; cursor: pointer;
}
.topbar-menu:hover { background: var(--bg-soft); }
.side-scrim { display: none; }

.topbar-back {
  width: 32px; height: 32px; flex-shrink: 0; margin-left: -6px;
  display: grid; place-items: center; border-radius: var(--r);
  color: var(--ink); text-decoration: none;
}
.topbar-back:hover { background: var(--bg-soft); color: var(--accent); }
.topbar-crumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb a, .crumb-link { color: var(--muted); text-decoration: none; }
.crumb a:hover, .crumb-link:hover { color: var(--accent); text-decoration: underline; }

.topbar .grow { flex-grow: 1; }
.lang-switch { margin-left: auto; display: flex; gap: 2px; padding: 2px; border-radius: var(--r); background: var(--bg-soft); flex-shrink: 0; }
.lang-switch-btn {
  height: 26px; padding: 0 9px; border: 0; border-radius: 4px;
  background: none; font: inherit; font-size: 12px; font-weight: 600;
  color: var(--muted); cursor: pointer;
}
.lang-switch-btn:hover { color: var(--ink); }
.lang-switch-btn.is-active { background: var(--bg); color: var(--accent); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08); }

/* Chip điểm thưởng → /shop (layouts/app.html; số cập nhật khi API trả "points" — core/api.js) */
.points-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px 0 8px; flex-shrink: 0;
  border-radius: 999px; background: var(--amber-bg); color: var(--amber); text-decoration: none;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.points-chip:hover { box-shadow: inset 0 0 0 1px var(--amber); color: var(--amber); }
.points-chip.is-bump { animation: points-bump 0.7s ease; }
@keyframes points-bump { 30% { transform: scale(1.12); } }
.toast.toast-points { background: linear-gradient(135deg, #ffd66b, #f5a524); color: #3b2300; font-weight: 700; }
@media (prefers-reduced-motion: reduce) { .points-chip.is-bump { animation: none; } }

/* ── Đầu trang cấp 1: ảnh bìa sóng + biểu tượng đè mép ───────────── */
.cover { height: 190px; background: var(--cover); position: relative; overflow: hidden; }
.cover svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.page { padding: 0 96px 64px; max-width: var(--content-w); margin: 0 auto; }
.page-icon {
  width: 78px; height: 78px; margin-top: -39px; position: relative;
  border-radius: var(--r-lg); background: var(--bg); box-shadow: var(--shadow-icon);
  display: grid; place-items: center; color: var(--accent);
}
.page-title {
  margin: 18px 0 6px;
  font-size: 40px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2;
}
.page-lead { margin: 0 0 20px; font-size: 15px; color: var(--muted); }

.section-title {
  margin: 40px 0 12px;
  font-size: 22px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink);
}
.section-title.has-lead { margin-bottom: 4px; }
.section-lead { margin: 0 0 14px; font-size: 14px; color: var(--muted); }

.page-narrow { max-width: 900px; }
.preview-note { margin: -8px 0 16px; font-size: 13px; color: var(--amber); }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.divider { height: 1px; border: 0; background: var(--line); margin: 18px 0; }
.crumb { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.crumb b { font-weight: 400; color: var(--ink); }
.link-btn {
  border: 0; background: none; padding: 0;
  font: inherit; font-size: 13px; color: var(--muted); cursor: pointer;
}
.link-btn:hover { color: var(--accent); text-decoration: underline; }

/* ── Dòng thuộc tính kiểu Notion ─────────────────────────────────── */
.props { display: flex; flex-direction: column; gap: 2px; }
.prop { display: flex; align-items: center; min-height: 34px; }
.prop-name {
  width: 160px; flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--muted);
}
.prop-value {
  flex-grow: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 14px; color: var(--ink);
}

/* ── Menu nổi (chọn một mục) ─────────────────────────────────────── */
.menu {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0;
  min-width: 220px; max-height: 60vh; overflow-y: auto;
  padding: 6px; border-radius: var(--r-md);
  background: var(--bg); box-shadow: var(--shadow-pop); border: 1px solid var(--line);
}
.menu[hidden] { display: none; }
.menu-title { margin: 6px 8px 4px; font-size: 12px; font-weight: 600; color: var(--faint); }
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 8px; border: 0; border-radius: var(--r);
  background: none; font: inherit; font-size: 14px; color: var(--text);
  text-align: left; text-decoration: none; cursor: pointer;
}
.menu-item:hover { background: var(--bg-soft); color: var(--ink); }
.menu-item.is-current { color: var(--accent); font-weight: 600; }
.menu-item .grow { flex-grow: 1; }

/* ── Hộp nhấn nhá (hành động chính) ──────────────────────────────── */
.callout {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--r-md); background: var(--callout);
}
.callout-body { display: flex; gap: 12px; flex-grow: 1; min-width: 0; }
.callout-body .icon { color: var(--accent); margin-top: 1px; }
.callout-title { margin: 0; font-size: 14px; font-weight: 600; }
.callout-text { margin: 2px 0 0; font-size: 13px; color: var(--text); line-height: 1.5; }
.callout-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Nút ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--bg); color: var(--text);
  font-size: 13px; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--faint); color: var(--ink); }
.btn-primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn-lg { height: 44px; padding: 0 20px; border-radius: var(--r-md); font-size: 15px; font-weight: 600; }

/* ── Thẻ & lưới ──────────────────────────────────────────────────── */
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--bg); color: var(--ink); text-decoration: none;
}
a.card:hover { border-color: var(--faint); color: var(--ink); }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-title { font-size: 15px; font-weight: 600; }
.card-text { font-size: 14px; color: var(--text); line-height: 1.4; }
.card-muted { font-size: 13px; color: var(--muted); line-height: 1.55; margin: 0; }

.tile {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: var(--r-md); display: grid; place-items: center;
}
.tone-green { background: var(--green-bg); color: var(--green); }
.tone-amber { background: var(--amber-bg); color: var(--amber); }
.tone-blue { background: var(--blue-bg); color: var(--blue); }
.tone-violet { background: var(--violet-bg); color: var(--violet); }
.tone-sand { background: var(--sand-bg); color: var(--amber); }

/* ── Nhãn ────────────────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center;
  height: 22px; padding: 0 8px; border-radius: var(--r-sm);
  font-size: 13px; white-space: nowrap;
  background: var(--bg-soft); color: var(--text);
}
.tag-green { background: var(--green-tag); color: var(--green); }
.tag-amber { background: var(--amber-bg); color: var(--amber); }
.tag-blue { background: var(--blue-tag); color: var(--blue); }
.tag-violet { background: var(--violet-bg); color: var(--violet); }
.tag-red { background: var(--red-bg); color: var(--red); }

/* ── Nút chỉ có icon, tab gạch chân, vòng xoay chờ — dùng chung nhiều trang ── */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex-shrink: 0;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--bg); color: var(--muted); cursor: pointer;
}
.icon-btn:hover { border-color: var(--faint); color: var(--ink); background: var(--bg-soft); }
.icon-btn:disabled { opacity: 0.5; cursor: default; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab {
  padding: 10px 4px; margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; background: none;
  font: inherit; font-size: 14px; color: var(--muted); cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.spinner {
  width: 16px; height: 16px; flex-shrink: 0;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ── Thanh tiến độ ───────────────────────────────────────────────── */
.progress { display: flex; align-items: center; gap: 8px; }
/* <progress value max> — không cần style="width:…" trong HTML */
.progress-bar {
  flex-grow: 1; min-width: 0; height: 4px; border: 0; border-radius: 2px;
  background: var(--line); overflow: hidden; appearance: none; -webkit-appearance: none;
}
.progress-bar::-webkit-progress-bar { background: var(--line); }
.progress-bar::-webkit-progress-value { background: var(--accent); }
.progress-bar::-moz-progress-bar { background: var(--accent); }
.progress-label { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* Khung chờ tải (khối xám nhấp nháy) */
.skeleton {
  display: block; height: 14px; border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--bg-soft), var(--line), var(--bg-soft));
  background-size: 200% 100%;
  animation: skeleton 1.2s ease-in-out infinite;
}
@keyframes skeleton { to { background-position: -200% 0; } }

/* ── Hộp tìm kiếm Ctrl K (js/core/search.js) ─────────────────────── */
.search-scrim {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, 0.3);
  display: flex; justify-content: center; align-items: flex-start;
  padding: 12vh 16px 16px;
}
.search-scrim[hidden] { display: none; }
.search-box {
  width: 100%; max-width: 560px; max-height: 70vh;
  display: flex; flex-direction: column;
  border-radius: 10px; background: var(--bg); box-shadow: var(--shadow-pop); overflow: hidden;
}
.search-input {
  height: 48px; padding: 0 16px; border: 0; border-bottom: 1px solid var(--line);
  font: inherit; font-size: 15px; color: var(--ink); outline: none;
}
.search-list { overflow-y: auto; padding: 6px; }
.search-group-title { margin: 8px 10px 4px; font-size: 12px; font-weight: 600; color: var(--faint); }
.search-row {
  display: flex; flex-direction: column; gap: 1px;
  padding: 8px 10px; border-radius: var(--r);
  color: var(--ink); text-decoration: none;
}
.search-row:hover, .search-row[aria-selected="true"] { background: var(--accent-soft); color: var(--ink); }
.search-row-label { font-size: 14px; }
.search-row-sub {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-note { margin: 10px; font-size: 13px; color: var(--muted); }
body.is-search-open { overflow: hidden; }

/* ── Thông báo nổi (js/core/toast.js) ────────────────────────────── */
.toast-host {
  position: fixed; z-index: 200; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: max-content; max-width: calc(100vw - 32px); pointer-events: none;
}
.toast {
  padding: 10px 14px; border-radius: var(--r-md);
  background: var(--dark); color: #ffffff; font-size: 14px;
  box-shadow: var(--shadow-pop); transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast-error { background: var(--red); }
.toast-success { background: var(--green); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); }

/* ── Hộp xác nhận (js/core/dialog.js) ────────────────────────────── */
.dialog {
  width: min(420px, calc(100vw - 32px)); padding: 0; border: 0;
  border-radius: 10px; box-shadow: var(--shadow-pop); color: var(--ink);
}
.dialog::backdrop { background: rgba(15, 23, 42, 0.35); }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.dialog-title { margin: 0; font-size: 17px; font-weight: 700; }
.dialog-text { margin: 0; font-size: 14px; color: var(--text); line-height: 1.5; }
.dialog-input {
  height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r);
  font: inherit; font-size: 14px; color: var(--ink);
}
.dialog-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.btn-danger { border-color: var(--red); background: var(--red); color: var(--on-accent); font-weight: 600; }
.btn-danger:hover { opacity: 0.9; color: var(--on-accent); }

/* ── Điện thoại & máy tính bảng ──────────────────────────────────── */
@media (max-width: 1100px) {
  .page { padding: 0 48px 56px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .side {
    position: fixed; left: 0; top: 0; z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }
  .app.is-nav-open .side { transform: none; box-shadow: var(--shadow-pop); }
  .app.is-nav-open .side-scrim {
    display: block; position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, 0.3);
  }
  .topbar { padding: 0 16px; }
  .topbar-menu { display: grid; }
  .cover { height: 98px; }
  .page { padding: 0 16px 48px; }
  .page-icon { width: 50px; height: 50px; margin-top: -25px; border-radius: 10px; }
  .page-icon svg { width: 25px; height: 25px; }
  .page-title { margin-top: 14px; font-size: 30px; }
  .page-lead { font-size: 14px; }
  .section-title { margin-top: 32px; font-size: 20px; }
  .callout { flex-direction: column; align-items: stretch; }
  .prop-name { width: auto; min-width: 116px; margin-right: 8px; }
  .callout-actions { padding-left: 32px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 480px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .side { transition: none; }
  .skeleton { animation: none; }
}

/* Câu ví dụ "cách đọc TRÊN TỪNG TỪ" (core/ruby.js) — giống chế độ Đọc: mỗi cụm một từ, không ngắt dòng giữa cụm */
.jf-ruby { line-height: 2.25; }
.jf-u { white-space: nowrap; margin-right: 0.22em; }
.jf-ruby ruby { ruby-align: center; }
.jf-ruby rt { font-size: max(10.5px, 0.6em); font-weight: 400; line-height: 1; color: var(--muted); letter-spacing: 0;
  padding: 0 0.15em; user-select: none; -webkit-user-select: none; }
/* Tiếng Trung: các TỪ cách quãng rõ (13/10/2026 — mọi chỗ hiện câu tiếng Trung) */
.jf-ruby.is-zh .jf-u { margin-right: 0.55em; }
.jf-words { word-break: normal; }
.jf-w { display: inline-block; white-space: nowrap; margin-right: 0.5em; }
.jf-w:last-child { margin-right: 0; }
.jf-w.is-mark { color: var(--accent, #0576a6); font-weight: 600; }
