/* =========================================================
   Phương Nguyễn Advisor — Khu dữ liệu: trang chi tiết cổ phiếu
   Theo mẫu 2 (nền tối mặc định, có nút chuyển sáng). Dùng chung token/component với styles.css.
   ========================================================= */
:root[data-theme="dark"] {
  --bg: #0D0D0D;
  --surface: #161616;
  --surface-muted: #222222;
  --border: #2A2A2A;
  --rule: #5E5B55;
  --text: #F4F2ED;
  --text-muted: #9A978F;
  --heading: #F4F2ED;
  --brand-text: #0D0D0D;
  --up: #22C55E;
  --down: #EF4444;
  color-scheme: dark;
}
:root[data-theme="light"] { --surface-2: #FFFFFF; }

/* Nút & header trên nền tối */
[data-theme="dark"] .btn--primary { background: var(--text); border-color: var(--text); color: var(--brand-text); }
[data-theme="dark"] .btn--primary:hover { background: #fff; box-shadow: none; }
[data-theme="dark"] .btn--secondary { border-color: #4a4a4a; }
[data-theme="dark"] .btn-icon--zalo { border-color: #1f3d73; color: #5B9BFF; }
[data-theme="dark"] .footer { background: #080808; }
[data-theme="dark"] .chart-card { background: var(--surface); }
[data-theme="dark"] .tag { background: transparent; }
[data-theme="dark"] .fab:not(.fab--zalo) { background: #222; border: 1px solid #3a3a3a; }
.nav a[aria-current="page"]::after { transform: scaleX(1); }
.btn-icon { cursor: pointer; color: var(--text); }
.eyebrow a { text-decoration: none; }
.eyebrow a:hover { color: var(--text); }

/* ---------- Ticker bar (mẫu 2) ---------- */
.ticker-bar { background: #050505; color: #F4F2ED; border-bottom: 1px solid #222; font-size: 12px; }
[data-theme="light"] .ticker-bar { background: var(--inverse-bg); }
.ticker-bar__inner {
  display: flex; align-items: center; gap: 28px; min-height: 36px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; white-space: nowrap;
}
.ticker-bar__inner::-webkit-scrollbar { display: none; }
.ticker-bar__item { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ticker-bar__item b { font-weight: 700; font-size: 11px; letter-spacing: .04em; }
.ticker-bar__src { margin-left: auto; color: #9A978F; font-size: 10.5px; flex-shrink: 0; padding-left: 12px; }

/* Badge % đổ màu (PriceChange — biến thể badge) */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 700;
  font-variant-numeric: tabular-nums; background: #3a3a3a; color: #fff;
}
.badge.change--up { background: #16A34A; color: #fff; }
.badge.change--down { background: #DC2626; color: #fff; }
.badge--lg { font-size: 13px; padding: 4px 10px; vertical-align: middle; letter-spacing: 0; }
.tag--preview { color: var(--chart-line); border-color: var(--chart-line); margin-left: 4px; }

/* ---------- Trạng thái trống / khoá ---------- */
.stock { padding-top: 28px; }
.stock-state { padding: 56px 0 88px; max-width: 760px; }
.stock-state__title { font-size: clamp(26px, 3.4vw, 40px); font-weight: 700; letter-spacing: -.025em; line-height: 1.2; margin: 12px 0 14px; color: var(--heading); }
.stock-state__text { color: var(--text-muted); max-width: 600px; }
.stock-state__cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }

/* ---------- Đầu trang mã ---------- */
.stock-head { padding-bottom: 24px; }
.stock-head__top { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.stock-head__top .eyebrow { font-size: 13px; color: var(--text); }
.stock-head__warn { margin-top: 10px; color: var(--chart-line); }
.sym-tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--surface-muted); padding: 4px; border-radius: 22px; max-width: 760px; }
.sym-tabs--many { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); width: 100%; max-width: none; border-radius: 14px; }
.sym-tabs--many a { min-width: 0; padding: 0 8px; }
.sym-tabs a {
  display: inline-grid; place-items: center; min-width: 64px; min-height: 40px; padding: 0 16px;
  border-radius: 999px; text-decoration: none; font-size: 12px; font-weight: 700; letter-spacing: .06em;
  color: var(--text-muted); transition: background .2s, color .2s;
}
.sym-tabs a:hover { color: var(--text); }
.sym-tabs a[aria-current="page"] { background: var(--text); color: var(--bg); }
.stock-head__main { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px 40px; flex-wrap: wrap; margin-top: 22px; padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.stock-head__sym { font-size: clamp(40px, 5.6vw, 64px); font-weight: 800; letter-spacing: -.04em; line-height: 1; color: var(--heading); }
.stock-head__name { font-size: 15px; font-weight: 600; margin-top: 10px; max-width: 520px; }
.stock-head__info { margin-top: 4px; }
.stock-head__price { display: grid; gap: 6px; justify-items: end; text-align: right; }
.stock-head__value { font-size: clamp(32px, 4vw, 46px); font-weight: 700; letter-spacing: -.03em; line-height: 1.05; }
.stock-head__value .badge { margin-left: 8px; }

/* ---------- Lưới biểu đồ + thông tin phiên ---------- */
.stock-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 24px; padding-bottom: 56px; }

/* Card dữ liệu */
.s-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px 20px 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.s-card__title { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text); }
.s-card__title small { font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text-muted); }
.s-card__big { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.s-card__big.change--up { color: var(--up); }
.s-card__big.change--down { color: var(--down); }
.s-card > .note:last-child { margin-top: auto; }
.s-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.fin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.empty { color: var(--text-muted); font-size: 13px; padding: 18px 0; }

/* Danh sách khoá–giá trị */
.kv { margin: 0; display: grid; }
.kv > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.kv > div:last-child { border-bottom: 0; }
.kv--tight > div { padding: 7px 0; }
.kv dt { font-size: 12px; color: var(--text-muted); }
.kv dd { margin: 0; font-size: 13.5px; font-weight: 600; text-align: right; }
.kv dd small { font-size: 10.5px; font-weight: 600; margin-left: 6px; }
.kv dd small.change--up, .s-card .change--up { color: var(--up); }
.kv dd small.change--down, .s-card .change--down { color: var(--down); }

/* Thanh khối ngoại ròng (mini bar xanh/đỏ quanh trục 0) */
.nbars { position: relative; display: flex; align-items: stretch; gap: 3px; height: 112px; }
.nbars::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--border); }
.nbars i { position: relative; flex: 1; }
.nbars i::before {
  content: ""; position: absolute; left: 0; right: 0; height: calc(var(--h) * 50%); border-radius: 2px;
}
.nbars i.up::before { bottom: 50%; background: var(--up); transform-origin: bottom; }
.nbars i.down::before { top: 50%; background: var(--down); transform-origin: top; }
.nbars__x { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.js .nbars i::before { transform: scaleY(0); transition: transform .9s var(--ease); transition-delay: calc(var(--i, 0) * 30ms + 200ms); }
.js .is-in .nbars i::before { transform: scaleY(1); }

/* RSI */
.rsi { display: grid; gap: 6px; }
.rsi__head { display: flex; justify-content: space-between; align-items: baseline; }
.rsi__track { position: relative; height: 8px; border-radius: 99px; background: var(--surface-muted); }
.rsi__zone { position: absolute; top: 0; bottom: 0; }
.rsi__zone--lo { left: 0; width: 30%; background: color-mix(in srgb, var(--up) 30%, transparent); border-radius: 99px 0 0 99px; }
.rsi__zone--hi { right: 0; width: 30%; background: color-mix(in srgb, var(--down) 30%, transparent); border-radius: 0 99px 99px 0; }
.rsi__track i { position: absolute; top: 50%; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--chart-line); border: 2px solid var(--surface); transform: translateY(-50%); }
.rsi__x { position: relative; height: 14px; font-size: 10px; color: var(--text-muted); }
.rsi__x span { position: absolute; transform: translateX(-50%); }
.rsi__x span:nth-child(1) { left: 0; transform: none; }
.rsi__x span:nth-child(2) { left: 30%; }
.rsi__x span:nth-child(3) { left: 70%; }
.rsi__x span:nth-child(4) { right: 0; transform: none; }

/* Cơ cấu sở hữu */
.own { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--surface-muted); }
.own i { display: block; height: 100%; }
.own--state { background: var(--brand-gold); }
.own--foreign { background: var(--brand-blue); }
.own--other { background: #6B7280; }
.js .own { transform: scaleX(0); transform-origin: left; transition: transform 1s var(--ease) .2s; }
.js .is-in .own { transform: scaleX(1); }
.own__legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.own__legend li { display: flex; align-items: center; gap: 8px; }
.own__legend b { margin-left: auto; }
.own__legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* Bảng tài chính */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-inline: -4px; padding-inline: 4px; }
.table-scroll:focus-visible { outline-offset: 0; }
.ftable { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 460px; }
.ftable th, .ftable td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.ftable thead th { font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.ftable th[scope="row"], .ftable thead th:first-child { text-align: left; font-weight: 500; white-space: normal; min-width: 150px; }
.ftable th[scope="row"] small { color: var(--text-muted); font-size: 11px; }
.ftable tbody tr:last-child th, .ftable tbody tr:last-child td { border-bottom: 0; }
.ftable td:nth-child(2) { font-weight: 700; }
.ftable td.change--down { color: var(--down); }

/* Bảng cùng ngành (dùng .mtable của trang chủ) */
.s-card .mtable { width: 100%; }
.s-card .mtable a { text-decoration: underline; text-underline-offset: 3px; display: inline-block; padding-block: 10px; }

/* Danh sách sự kiện / tin */
.list { list-style: none; margin: 0; padding: 0; display: grid; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--border); display: grid; gap: 3px; }
.list li:last-child { border-bottom: 0; }
.list__title { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.list__text { font-size: 13.5px; line-height: 1.5; }

/* Giới thiệu */
.overview { margin: 0; padding: 0 0 0 18px; display: grid; gap: 8px; max-width: 920px; color: var(--text-muted); }
.overview li::marker { color: var(--brand-gold); }

.overview--p { padding: 0; line-height: 1.7; }

/* Bản công khai: khối ngoại mua/bán trong phiên, link bộ lọc */
.fbuy { background: var(--up); }
.fsell { background: var(--down); }
.stock-head__links { margin-top: 10px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.stock-head__links a { display: inline-block; padding-block: 12px; text-decoration: none; color: var(--text-muted); }
.stock-head__links a:hover { color: var(--text); }
.kv .is-ceiling { color: var(--ceiling); }
.kv .is-floor { color: var(--floor); }

/* Pháp lý */
.stock-legal { border-top: 1px solid var(--border); padding: 28px 0 72px; display: grid; gap: 12px; max-width: 920px; }
.stock-legal__yuanta { font-size: 13px; line-height: 1.65; color: var(--text); padding: 14px 16px; border-left: 3px solid var(--brand-gold); background: var(--surface); border-radius: 0 8px 8px 0; }
.stock-legal__pna { font-size: 12.5px; color: var(--text-muted); }
.stock-legal .btn { justify-self: start; margin-top: 8px; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .js .nbars i::before, .js .own { transform: none !important; transition: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1500px) { .ticker-bar__src { display: none; } }
@media (max-width: 1080px) {
  .s-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .stock-grid, .fin-grid { grid-template-columns: 1fr; }
  .stock-grid { gap: 20px; }
}
@media (max-width: 640px) {
  .stock { padding-top: 18px; }
  .s-cards { grid-template-columns: 1fr; }
  .stock-head__top { align-items: flex-start; }
  .sym-tabs { width: 100%; }
  .sym-tabs a { flex: 1; min-width: 0; min-height: 44px; }
  .sym-tabs--many { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); }
  .stock-head__price { justify-items: start; text-align: left; }
  .stock-head__value .badge { margin-left: 4px; }
  .chart-card { padding: 16px 14px 10px; }
  .s-card { padding: 16px; }
  .ticker-bar__inner { gap: 20px; }
  .stock-state__cta .btn { width: 100%; }
}
