/* WeHa — thành phần dùng chung. Trang riêng đặt CSS ở styles/pages/<tên-trang>.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--font-sans); font-size: 15px; line-height: 1.6;
  color: var(--text); background: var(--surface-page);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.serif { font-family: var(--font-serif); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 5px rgba(226,183,104,.45); }

/* Bố cục */
.container { max-width: var(--container); margin: 0 auto; padding: 0 var(--s4); }
@media (min-width: 640px) { .container { padding: 0 var(--s6); } }
.stack > * + * { margin-top: var(--s4); }
.section { margin-top: var(--s8); }
.grid { display: grid; gap: var(--s4); }
.grid-2 { grid-template-columns: 1fr; }
.grid-3, .grid-4 { grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-3 { grid-template-columns: repeat(2, 1fr); } .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(3, 1fr); } .grid-4 { grid-template-columns: repeat(4, 1fr); } }

/* Thanh trên */
.site-header { position: sticky; top: 0; z-index: 20; background: var(--header-bg); backdrop-filter: blur(8px); box-shadow: 0 1px 0 var(--border); }
.site-header .bar { display: flex; align-items: center; gap: var(--s4); height: 64px; }
.brand { display: flex; align-items: center; gap: var(--s2); text-decoration: none; flex-shrink: 0; }
.brand img { height: 36px; width: auto; }
.brand .brand-text { font-size: 12px; line-height: 1.3; color: var(--text-2); display: none; }
.brand .brand-text strong { display: block; color: var(--ink); font-size: 14px; }
@media (min-width: 1024px) { .brand .brand-text { display: block; } }
.search { margin-left: auto; position: relative; flex: 0 1 240px; }
.search input { width: 100%; height: 40px; border: 1px solid var(--border); border-radius: var(--r-full); padding: 0 var(--s4) 0 38px; font: inherit; font-size: 14px; background: var(--surface-soft); color: var(--text); }
.search input:focus { border-color: var(--ink); background: var(--surface); }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-2); }

/* Menu viên thuốc */
.nav { display: flex; gap: var(--s1); overflow-x: auto; scrollbar-width: none; padding: var(--s2) 0; -webkit-overflow-scrolling: touch; }
.nav::-webkit-scrollbar { display: none; }
.nav-pill { flex-shrink: 0; display: inline-flex; align-items: center; height: 36px; padding: 0 var(--s4); border-radius: var(--r-full); font-size: 14px; font-weight: 500; color: var(--text-2); text-decoration: none; white-space: nowrap; }
.nav-pill:hover { background: var(--surface-soft); color: var(--ink); }
.nav-pill[aria-current="page"] { background: var(--primary-bg); color: var(--primary-fg); }

/* Đầu trang */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s3); padding: var(--s8) 0 var(--s6); border-bottom: 1px solid var(--border); margin-bottom: var(--s6); }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--gold-strong); }
.h1 { font-family: var(--font-serif); font-size: 30px; font-weight: 700; line-height: 1.15; color: var(--ink); margin-top: var(--s1); }
@media (min-width: 640px) { .h1 { font-size: 36px; } }
.h2 { font-size: 17px; font-weight: 700; line-height: 1.4; color: var(--ink); }
.h2 .sub { font-weight: 400; color: var(--text-2); font-size: 14px; }
.h3 { font-size: 14px; font-weight: 600; line-height: 1.4; color: var(--text); }
.meta { font-size: 13px; color: var(--text-2); text-align: right; }
.meta strong { color: var(--text); }
.pill-status { display: inline-block; margin-top: var(--s1); padding: 4px 12px; border-radius: var(--r-full); background: var(--up-bg); color: var(--up-strong); font-size: 13px; font-weight: 600; }

/* Nút */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 44px; padding: 10px 20px; border-radius: var(--r-full); font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer; border: 1px solid transparent; transition: background .15s, border-color .15s; }
.btn-sm { min-height: 36px; padding: 6px 16px; font-size: 13px; }
.btn-primary { background: var(--primary-bg); color: var(--primary-fg); }
.btn-primary:not([disabled]):hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-secondary:not([disabled]):hover { border-color: var(--ink); }
.btn[disabled] { opacity: .4; cursor: not-allowed; }
.seg { display: inline-flex; flex-wrap: wrap; gap: var(--s2); }
.seg .btn[aria-pressed="true"] { background: var(--primary-bg); color: var(--primary-fg); border-color: var(--primary-bg); }

/* Thẻ */
.card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-card); padding: var(--s4); }
@media (min-width: 640px) { .card { padding: 20px; } }
a.card { display: block; text-decoration: none; transition: box-shadow .15s; }
a.card:hover { box-shadow: var(--shadow-card-hover); }
.card-hero { background: var(--hero-bg); color: var(--on-dark); border-radius: var(--r-lg); padding: var(--s6); }
.card-hero .eyebrow { color: var(--gold-light); }
.card-hero .muted { color: var(--on-dark-2); }
.metric { font-family: var(--font-serif); font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.display-score { font-family: var(--font-serif); font-size: 52px; font-weight: 700; line-height: 1; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
@media (min-width: 640px) { .display-score { font-size: 64px; } }
.up { color: var(--up); } .down { color: var(--down); }
.card-hero .up { color: var(--up-on-dark); } .card-hero .down { color: var(--down-on-dark); }
.muted { color: var(--text-2); }

/* Khối "Cách đọc" — nét riêng của WeHa */
.how-to-read { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--border); font-size: 13px; line-height: 1.55; color: var(--text-2); }
.how-to-read strong { color: var(--text); }
.card-hero .how-to-read { border-top-color: var(--navy-track); color: var(--on-dark-2); }
.card-hero .how-to-read strong { color: var(--on-dark); }

/* Nhãn vùng */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: var(--r-sm); font-size: 13px; font-weight: 600; line-height: 1.4; white-space: nowrap; }
.badge-positive { background: var(--up-bg); color: var(--up-strong); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-strong); }
.badge-caution { background: var(--down-bg); color: var(--down); }
.badge-gold { background: var(--gold-fill); color: var(--gold-strong); }

/* Bảng */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: var(--s3); border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.table td.r, .table th.r { text-align: right; }
.table-wrap { overflow-x: auto; }
.table tbody tr:hover td { background: var(--surface-soft); }
.table caption { caption-side: bottom; text-align: left; padding-top: var(--s2); font-size: 12px; color: var(--text-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ===== Quy ước thống nhất (mọi trang PHẢI dùng, không tự chế kiểu riêng) ===== */

/* Tiêu đề khối: LUÔN nằm ngoài thẻ, ngay trên thẻ/lưới thẻ */
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s2) var(--s4); margin: var(--s8) 0 var(--s3); }
.section-head .h2 { margin: 0; }
.section-head .actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.lead { margin-top: var(--s2); font-size: 15px; color: var(--text-2); max-width: 680px; }
@media (max-width: 639px) { .meta { text-align: left; } }

/* Nhãn loại nội dung (Vĩ mô, Doanh nghiệp, Cổ tức...): MỘT kiểu duy nhất */
.tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--gold-strong); }

/* Thay đổi giá / %: chữ màu + mũi tên, KHÔNG có nền */
.chg { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chg.up { color: var(--up); } .chg.down { color: var(--down); } .chg.flat { color: var(--text-2); }
.chg.up::before { content: "▲\00a0"; font-size: .8em; } .chg.down::before { content: "▼\00a0"; font-size: .8em; }
.chg-lg { font-size: 17px; }

/* Ô chỉ số: nhãn Inter nhỏ + số Lora + dòng phụ */
.stat-tile { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-card); padding: var(--s3) var(--s4); min-width: 0; }
.stat-label { font-size: 13px; color: var(--text-2); }
.stat-value { font-family: var(--font-serif); font-size: 24px; font-weight: 700; line-height: 1.2; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-value .unit { font-family: var(--font-sans); font-size: 13px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.stat-sub { font-size: 13px; color: var(--text-2); }
.stat-grid { display: grid; gap: var(--s3); grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(3, minmax(0,1fr)); } }
@media (min-width: 1024px) { .stat-grid { grid-template-columns: repeat(var(--cols, 5), minmax(0,1fr)); } }
.stat-grid.flat .stat-tile { box-shadow: none; background: var(--surface-soft); }

/* Thẻ tin: tag + tiêu đề Inter + tóm tắt + ngày. Tiêu đề tin KHÔNG dùng Lora */
.news-card { display: flex; flex-direction: column; gap: var(--s1); }
.news-title { font-size: 16px; font-weight: 700; line-height: 1.4; color: var(--text); }
.news-sum { font-size: 14px; color: var(--text-2); }
.news-date { margin-top: auto; padding-top: var(--s2); font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Ô nhấn "Vì sao quan trọng" */
.highlight { background: var(--gold-fill); border-left: 3px solid var(--gold); border-radius: 0 var(--r-sm) var(--r-sm) 0; padding: var(--s3) var(--s4); font-size: 14px; }
.highlight .tag { display: block; margin-bottom: var(--s1); }

/* Dòng thời gian (Tin nhanh) */
.timeline { list-style: none; }
.timeline li { display: grid; grid-template-columns: 48px 1fr; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

/* Dòng bấm mở (FAQ, giải thích yếu tố) */
.disclosure { border-bottom: 1px solid var(--border); }
.disclosure > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 48px; padding: var(--s2) 0; font-weight: 600; }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after { content: "+"; font-size: 18px; color: var(--text-2); flex-shrink: 0; }
.disclosure[open] > summary::after { content: "−"; }
.disclosure > .body { padding: 0 0 var(--s3); font-size: 14px; color: var(--text-2); }

/* Thanh biên độ thấp–cao */
.range { margin-top: var(--s2); }
.range-track { position: relative; height: 6px; border-radius: var(--r-full); background: var(--border); }
.range-fill { position: absolute; inset: 0 auto 0 0; border-radius: var(--r-full); background: var(--gold-light); }
.range-dot { position: absolute; top: 50%; width: 14px; height: 14px; margin-left: -7px; transform: translateY(-50%); border-radius: 50%; background: var(--ink); border: 2px solid var(--surface); }
.range-ends { display: flex; justify-content: space-between; margin-top: var(--s1); font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Ghi chú dữ liệu minh họa */
.sample-note { display: inline-flex; gap: var(--s2); align-items: center; font-size: 13px; color: var(--text-2); }

@media (max-width: 639px) { .btn-sm { min-height: 44px; } }

/* Ô nhập (form): .field > .field-label + .input (+ .field-hint) */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; border: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text); }
.field-label .opt { font-weight: 400; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--text-2); }
.input {
  width: 100%; min-height: 44px; padding: 10px var(--s3);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 15px; font-variant-numeric: tabular-nums;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-2); opacity: .8; }
.input:hover { border-color: var(--text-2); }
.input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(226,183,104,.45); }
.input.upper { text-transform: uppercase; }
textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
.input { min-height: 44px; }

/* Thanh lọc: .card.toolbar > .toolbar-row > (.seg | .search-field | .field select.input) */
.toolbar { display: flex; flex-direction: column; gap: var(--s3); }
.toolbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); }
.toolbar-row .grow { flex: 1 1 220px; min-width: 0; }
.search-field { position: relative; display: block; flex: 1 1 220px; min-width: 0; }
.search-field svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-2); pointer-events: none; }
.search-field .input { padding-left: 40px; border-radius: var(--r-full); }
select.input { appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.toolbar-row .field { flex: 0 1 200px; }
@media (max-width: 639px) { .toolbar-row > * { flex-basis: 100%; } .toolbar-row .seg { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; } }

/* Chân trang */
.site-footer { margin-top: var(--s12); padding: var(--s8) 0; background: var(--footer-bg); color: var(--on-dark-2); font-size: 13px; }
.site-footer strong { color: var(--on-dark); }
.site-footer .disclaimer { margin-top: var(--s2); }

.stat-value.chg::before { font-size: .5em; vertical-align: .35em; margin-right: 2px; }

.seg .btn { flex-shrink: 0; white-space: nowrap; }

/* Trạng thái dữ liệu (dùng qua WeHa.state.* trong scripts/common.js) */
.state { padding: var(--s6) var(--s4); text-align: center; color: var(--text-2); font-size: 14px; }
.state-loading { text-align: left; padding: var(--s4) 0; }
.skeleton { height: 14px; margin: var(--s3) 0; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--surface-soft) 0%, var(--border) 50%, var(--surface-soft) 100%); background-size: 200% 100%; animation: weha-shimmer 1.2s linear infinite; }
.skeleton:nth-child(3n+2) { width: 82%; } .skeleton:nth-child(3n) { width: 64%; }
@keyframes weha-shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.state-error p { margin-bottom: var(--s3); color: var(--down); font-weight: 600; }
.data-time { font-size: 12px; color: var(--text-2); }

/* Nút sáng/tối */
.theme-toggle { margin-left: auto; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: var(--r-full); border: 1px solid var(--border); background: var(--surface); color: var(--ink); cursor: pointer; }
.theme-toggle:hover { border-color: var(--ink); }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
.brand .logo-dark { display: none; }
:root[data-theme="dark"] .brand .logo-light { display: none; }
:root[data-theme="dark"] .brand .logo-dark { display: block; }
