/* ============================================================================
   BP Training — design tokens + base UI
   Nguyên tắc: không emoji cho control; scrollbar có style; control nhỏ gọn,
   container rộng rãi (max-w-5xl) — "modern compact", không phải co mọi thứ.
   ========================================================================== */

:root {
  --brand-700: #047857;
  --brand-600: #059669;
  --ring: 16 185 129;              /* emerald-500 */
  --radius: 10px;
  --border: 226 232 240;           /* slate-200 */
}

html { -webkit-tap-highlight-color: transparent; }
html, body { scrollbar-gutter: stable; }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.lesson-content p { margin: 0.35rem 0; }

/* ── Scrollbar: mảnh, bo tròn, tự ẩn màu khi không hover ─────────────────── */
* { scrollbar-width: thin; scrollbar-color: rgb(203 213 225) transparent; }
@supports selector(::-webkit-scrollbar) {
  *::-webkit-scrollbar { width: 8px; height: 8px; }
  *::-webkit-scrollbar-track { background: transparent; }
  *::-webkit-scrollbar-thumb {
    background-color: rgb(203 213 225);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: content-box;
  }
  *::-webkit-scrollbar-thumb:hover { background-color: rgb(148 163 184); }
  *::-webkit-scrollbar-corner { background: transparent; }
}
/* Vùng tối (header/nav) — scrollbar sáng hơn để không bị "hố đen" */
.bg-brand-700 ::-webkit-scrollbar-thumb,
.bg-emerald-700 ::-webkit-scrollbar-thumb { background-color: rgb(255 255 255 / 0.3); }

/* ── Base control: đồng nhất chiều cao, không thô ────────────────────────── */
:where(button, a.btn, .btn) {
  transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .06s ease;
}
:where(button, a.btn, .btn):active { transform: scale(.985); }

:where(button, .btn, a.btn):focus-visible,
:where(input, select, textarea):focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgb(var(--ring) / .28);
}

/* Nút chuẩn (dùng class .btn + biến thể) */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .375rem;
  height: 2.25rem; padding: 0 .875rem;
  border-radius: var(--radius);
  font-size: .8125rem; font-weight: 500; line-height: 1;
  white-space: nowrap; cursor: pointer; border: 1px solid transparent;
}
.btn-primary { background: var(--brand-600); color: #fff; }
.btn-primary:hover { background: var(--brand-700); }
.btn-secondary { background: #fff; color: #334155; border-color: rgb(var(--border)); }
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-ghost { background: transparent; color: var(--brand-700); }
.btn-ghost:hover { background: rgb(5 150 105 / .08); }
.btn-danger { background: transparent; color: #e11d48; }
.btn-danger:hover { background: rgb(225 29 72 / .08); }
.btn-sm { height: 2rem; padding: 0 .625rem; font-size: .75rem; }
.btn-icon { width: 2.25rem; padding: 0; }
.btn:disabled, .btn[disabled], button:disabled {
  opacity: .5; cursor: not-allowed; transform: none !important;
}

/* Input/select/textarea: viền mảnh, radius thống nhất.
   Dùng `html body` prefix để thắng preflight của Tailwind (`border-width:0`). */
html body :where(input[type="text"], input[type="password"], input[type="email"],
                 input[type="number"], input[type="search"], select, textarea) {
  border-radius: var(--radius);
  border: 1px solid rgb(var(--border));
  background: #fff;
  color: #334155;
  transition: border-color .15s ease, box-shadow .15s ease;
}
html body :where(input, select, textarea):hover { border-color: #cbd5e1; }
html body select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%2364748b' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .5rem center;
  background-size: 1rem;
  padding-right: 1.85rem;
}

/* iOS: input < 16px làm Safari tự zoom khi focus */
@media (max-width: 640px) {
  input[type="text"], input[type="password"], input[type="email"],
  input[type="number"], input[type="search"], input:not([type]), textarea, select {
    font-size: 16px;
  }
}

/* Tap target: chỉ áp cho control chính, không ép mọi <a> (tránh phá layout) */
@media (max-width: 640px) {
  .btn, button:not(.link-plain) { min-height: 2.25rem; }
  .touch-target { min-height: 44px; min-width: 44px; }
}

/* Chống tràn ngang — bảng rộng phải cuộn trong khung riêng */
main { overflow-x: clip; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap > table { min-width: 100%; }

/* Vùng an toàn đáy iOS */
.pb-safe { padding-bottom: env(safe-area-inset-bottom); }

/* ── Debate Room: composer dính đáy ─────────────────────────────────────── */
#debate-turn-form.composer {
  backdrop-filter: blur(8px);
  background-color: rgb(255 255 255 / .97);
}
@media (max-width: 767px) {
  #debate-app.has-composer #debate-turns { padding-bottom: .5rem; }
  body:has(#debate-app.has-composer) main { padding-bottom: 13rem; }
}

/* Bottom nav 7 mục: thu chữ nhỏ trên máy hẹp để không tràn */
@media (max-width: 400px) {
  .grid-cols-7 { font-size: 9px; letter-spacing: -0.01em; }
}
@media (max-width: 340px) {
  .grid-cols-7 span { font-size: 8.5px; }
}

/* ── Rich text editor (HDSD) ──────────────────────────────────────────── */
.rte-toolbar { display: flex; flex-wrap: wrap; gap: 2px; }
.rte-toolbar button {
  height: 2rem; min-width: 2rem; padding: 0 .4rem; border-radius: 6px;
  border: 1px solid transparent; font-size: 12px; color: #475569; background: transparent;
}
.rte-toolbar button:hover { background: #f1f5f9; border-color: #e2e8f0; }
.rte-toolbar button.is-active { background: #d1fae5; color: #047857; }
.rte-area { min-height: 22rem; }
.rte-area:focus { outline: none; }
.rte-area img { max-width: 100%; height: auto; border-radius: 8px; }
.rte-area table { border-collapse: collapse; width: 100%; }
.rte-area td, .rte-area th { border: 1px solid #e2e8f0; padding: .35rem .5rem; }
.rte-area blockquote { border-left: 3px solid #a7f3d0; margin: .5rem 0; padding-left: .75rem; color: #475569; }
.rte-area pre { background: #0f172a; color: #e2e8f0; padding: .75rem; border-radius: 8px; overflow-x: auto; }

/* ── Trang HDSD ──────────────────────────────────────────────────────── */
.help-content h2 { font-size: 1.125rem; font-weight: 600; margin: 1.5rem 0 .5rem; }
.help-content h3 { font-size: 1rem; font-weight: 600; margin: 1.15rem 0 .4rem; }
.help-content p { margin: .5rem 0; line-height: 1.65; }
.help-content ul, .help-content ol { margin: .5rem 0 .5rem 1.25rem; }
.help-content li { margin: .2rem 0; line-height: 1.6; }
.help-content ul { list-style: disc; }
.help-content ol { list-style: decimal; }
.help-content img { max-width: 100%; height: auto; border-radius: 10px; border: 1px solid #e2e8f0; margin: .5rem 0; }
.help-content table { border-collapse: collapse; width: 100%; margin: .75rem 0; font-size: .875rem; }
.help-content td, .help-content th { border: 1px solid #e2e8f0; padding: .4rem .6rem; text-align: left; }
.help-content th { background: #f8fafc; font-weight: 600; }
.help-content blockquote { border-left: 3px solid #34d399; padding-left: .75rem; color: #475569; margin: .75rem 0; }
.help-content a { color: #047857; text-decoration: underline; }
.help-content code { background: #f1f5f9; padding: .1rem .3rem; border-radius: 4px; font-size: .85em; }

/* Ảnh minh hoạ có chú thích + viền highlight component */
.help-figure { margin: .9rem 0 1.1rem; }
.help-figure .shot { position: relative; border: 1px solid #e2e8f0; border-radius: 10px; overflow: hidden; }
.help-figure .shot img { display: block; width: 100%; margin: 0; border: 0; border-radius: 0; }
.help-figure figcaption { font-size: .75rem; color: #64748b; margin-top: .35rem; }
.help-figure .hl {           /* khoanh đỏ component cần chú ý */
  position: absolute; border: 2px solid #f43f5e; border-radius: 6px;
  box-shadow: 0 0 0 3px rgb(244 63 94 / .22);
}

/* Chống tràn ngang cho vùng HDSD (bảng/pre/ảnh rộng phải cuộn trong khung) */
.help-content { overflow-wrap: anywhere; }
.help-content table { display: block; overflow-x: auto; max-width: 100%; }
.help-content pre { max-width: 100%; }
.help-content img, .help-figure .shot img { max-width: 100%; }
.help-figure .shot { max-width: 100%; overflow: hidden; }

/* Chặn tuyệt đối tràn ngang trong trang HDSD (ảnh/khung rộng) */
#help-content, #help-content > *, .help-figure, .help-figure .shot { max-width: 100%; box-sizing: border-box; }
main { overflow-x: hidden; }
