/* LV Screener V2: giao diện dashboard theo hướng tối giản kiểu Dub (sidebar, thẻ 1px, nút đen/trắng, bo 12px). Không dùng CSS của V1. */
/* Token theo tên Dub (merged-spec §2-3, docs/arch/v2-design-system.md). Tên cũ (--bg, --surface, --radius…) đã bỏ ở E7. */
:root {
  --bg-muted: #0a0a0a;
  --bg-default: #141415;
  --bg-subtle: #1c1c1e;
  --bg-inverted: #ededed;
  --bg-sidebar: #0f0f10;
  --border-subtle: #26262a;
  --content-default: #ededed;
  --content-subtle: #8b8b93;
  --content-inverted: #0a0a0a;
  --content-error: #f87171;
  --content-warning: #f5b84b;
  --bg-warning: color-mix(in srgb, var(--content-warning) 12%, transparent);
  --bg-overlay: rgb(0 0 0 / .4);
  --shadow-drawer: -12px 0 32px rgb(0 0 0 / .25);
  --content-on-media: #fff;
  --bg-media: rgb(0 0 0 / .6);
  --bg-media-hover: rgb(0 0 0 / .75);
  --border-media: rgb(255 255 255 / .35);
  --shadow-media: 0 6px 18px rgb(0 0 0 / .35);
  --shadow-media-img: 0 8px 24px rgb(0 0 0 / .25);
  --up: #34d399;
  --down: #f87171;
  --focus: #60a5fa;
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 20px;
  --text-3xl: 24px;
  --text-display: 26px;
  --duration-fast: 120ms;
  --duration-base: 200ms;
  --duration-slow: 260ms;
  --duration-flash: 400ms;
  --duration-flash-long: 900ms;
  --duration-shimmer: 1200ms;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-in: cubic-bezier(.4, 0, 1, 1);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg-muted: #f7f7f8;
  --bg-default: #ffffff;
  --bg-subtle: #f2f2f4;
  --bg-inverted: #111113;
  --bg-sidebar: #ffffff;
  --border-subtle: #e4e4e8;
  --content-default: #111113;
  --content-subtle: #6b6b73;
  --content-inverted: #ffffff;
  --content-error: #b91c1c;
  --content-warning: #9a6700;
  --up: #15803d;
  --down: #b91c1c;
  --focus: #2563eb;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Thanh cuộn luôn giữ chỗ: dữ liệu về làm trang dài ra cũng không xô ngang cả layout (CLS). */
html { scrollbar-gutter: stable; }
body.v2 {
  margin: 0;
  font: var(--text-base)/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
  background: var(--bg-muted);
  color: var(--content-default);
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; }
h1 { font-size: var(--text-lg); font-weight: 600; }
h2 { font-size: var(--text-md); font-weight: 600; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.v2-muted { color: var(--content-subtle); }
.v2-small { font-size: var(--text-xs); }
.v2-error { color: var(--content-error); font-size: var(--text-sm); min-height: 0; }
.v2-error:empty { display: none; }
.up { color: var(--up); }
.down { color: var(--down); }

/* Shell */
/* Tai thỏ: mỗi inset dùng đúng một lần. Hai bên ở .v2-shell; trên ở thanh nằm sát mép trên; drawer ở vị trí. Inset 0 = không đổi pixel. */
.v2-shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; padding-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
.v2-sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 16px;
  padding: calc(16px + env(safe-area-inset-top)) 12px 16px; background: var(--bg-sidebar); border-right: 1px solid var(--border-subtle);
}
.v2-brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px; font-weight: 600; text-decoration: none; }
.v2-badge { margin-left: auto; font-size: var(--text-xs); padding: 1px 6px; border-radius: var(--radius-full); border: 1px solid var(--border-subtle); color: var(--content-subtle); }
.v2-nav { display: grid; gap: 2px; }
.v2-nav__item {
  display: block; width: 100%; padding: 7px 10px; border: 0; border-radius: var(--radius-md);
  background: none; color: var(--content-subtle); font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.v2-nav__item:hover { background: var(--bg-subtle); color: var(--content-default); }
.v2-nav__item.is-active { background: var(--bg-subtle); color: var(--content-default); font-weight: 600; }
/* Cột 2 cố định: v2-shell.js chèn sidebar có thể sau lần vẽ đầu, main không được nằm tạm cột 224px. */
.v2-main { min-width: 0; grid-column: 2; }
.v2-topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: calc(12px + env(safe-area-inset-top)) 24px 12px; background: color-mix(in srgb, var(--bg-muted) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
}
.v2-topbar__title { display: grid; gap: 2px; min-width: 0; flex: 1 1 auto; }
/* Chỉ h1 quyết định topbar xuống dòng: chữ #status về sau chỉ xuống dòng trong tiêu đề, không đẩy nút sang dòng mới. */
.v2-topbar__title > p { contain: inline-size; }
.v2-topbar__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.v2-content { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 20px 24px 40px; max-width: 1280px; margin-inline: auto; }
.v2-content > * { min-width: 0; }
.v2-content--wide { max-width: none; padding-inline: 16px; }

/* Buttons, switch, live */
/* Nút (merged-spec §4.1): .v2-account .btn là class V1 do account.js sinh ra, gom chung khối. */
.v2-btn, .v2-account .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  background: var(--bg-default); color: var(--content-default); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.v2-btn:hover:not(:disabled), .v2-account .btn:hover:not(:disabled) { background: var(--bg-subtle); }
.v2-btn:disabled, .v2-account .btn:disabled { background: var(--bg-subtle); border-color: var(--border-subtle); color: var(--content-subtle); cursor: not-allowed; }
.v2-btn--primary, .v2-account .btn--primary { background: var(--bg-inverted); color: var(--content-inverted); border-color: var(--bg-inverted); }
.v2-btn--primary:hover:not(:disabled) { background: var(--bg-inverted); opacity: .88; }
.v2-btn--ghost, .v2-account .btn--ghost { background: none; border-color: transparent; color: var(--content-subtle); }
.v2-btn--danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 50%, var(--border-subtle)); }
.v2-btn--danger:hover:not(:disabled) { background: color-mix(in srgb, var(--down) 14%, var(--bg-default)); }
.v2-btn--warn { color: var(--content-warning); border-color: color-mix(in srgb, var(--content-warning) 50%, var(--border-subtle)); }
.v2-btn--warn:hover:not(:disabled) { background: color-mix(in srgb, var(--content-warning) 14%, var(--bg-default)); }
.v2-icon-btn { width: 30px; height: 30px; border: 0; border-radius: var(--radius-md); background: none; color: var(--content-subtle); font-size: var(--text-2xl); line-height: 1; cursor: pointer; }
.v2-icon-btn:hover { background: var(--bg-subtle); color: var(--content-default); }
.v2-switch { display: inline-flex; padding: 2px; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); background: var(--bg-default); }
.v2-switch__opt { padding: 4px 10px; border-radius: var(--radius-sm); color: var(--content-subtle); font-size: var(--text-sm); font-weight: 500; text-decoration: none; }
.v2-switch__opt.is-active { background: var(--bg-inverted); color: var(--content-inverted); }
.v2-live { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); color: var(--content-subtle); }
.v2-live.is-on { color: var(--up); }

/* Cards */
.v2-card { background: var(--bg-default); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 16px; }
.v2-eyebrow { font-size: var(--text-xs); letter-spacing: .06em; text-transform: uppercase; color: var(--content-subtle); }
.v2-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.v2-market { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; align-items: start; }
.v2-market__main { display: grid; gap: 4px; }
.v2-market__main h2 { font-size: var(--text-2xl); font-weight: 650; }
.v2-market__main p:empty { min-height: 1.5em; }
.v2-sessions { display: grid; gap: 8px; }
.v2-sessions.is-closed { justify-self: end; align-self: start; padding: 6px 12px; border: 1px solid var(--border-subtle); border-radius: var(--radius-full); background: var(--bg-subtle, transparent); }
.v2-sessions.is-closed p { margin: 0; font-size: var(--text-sm); }
.v2-sessions__list { display: grid; gap: 6px; }
.v2-session { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); font-size: var(--text-sm); }
.v2-session.is-current { border-color: var(--focus); }
.v2-session.is-marked b { color: var(--content-warning); }

/* Notice (ToS) */
.v2-notice__form { display: grid; gap: 10px; }
.v2-notice { border-color: var(--content-warning); }

/* Tiers */
.v2-tiers { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.v2-tier {
  display: grid; gap: 2px; padding: 12px; text-align: left; font: inherit; color: var(--content-default);
  background: var(--bg-default); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); cursor: pointer;
}
.v2-tier:hover { background: var(--bg-subtle); }
.v2-tier:disabled { cursor: progress; }
.v2-tier.is-active { border-color: var(--content-default); box-shadow: inset 0 0 0 1px var(--content-default); }
.v2-tier strong { font-size: var(--text-md); font-weight: 600; }

/* Filters */
.v2-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; margin-bottom: 12px; }
.v2-field { display: grid; gap: 4px; min-width: 0; }
.v2-field--vip { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; padding-top: 8px; border-top: 1px dashed var(--border-subtle); }
.v2-field--vip.is-locked > * { opacity: .55; }
.v2-field--vip label:not(.v2-check) { display: grid; gap: 4px; width: 160px; }
.v2-field--vip .v2-check { min-height: 34px; }
.v2-field--exchange .v2-checks { flex-wrap: nowrap; }
@media (min-width: 1200px) { .v2-filters { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.v2-label { font-size: var(--text-xs); color: var(--content-subtle); }
.v2-checks { display: flex; gap: 12px; flex-wrap: wrap; min-height: 34px; align-items: center; }
/* The whole label is the tap target: 32px tall, above the 24px floor of WCAG 2.5.8. */
.v2-check, .v2-checks label { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; font-size: var(--text-sm); cursor: pointer; }
.v2-check input, .v2-checks input { flex: none; width: 18px; height: 18px; margin: 0; }
/* Ô nhập (§4.2): gồm input/select/textarea của account.js. */
.v2-input, .v2-account input, .v2-account select, .v2-account textarea {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
  background: var(--bg-subtle); color: var(--content-default); font: inherit;
}
.v2-input:disabled { opacity: .5; }
.v2-input[aria-invalid="true"], .v2-account [aria-invalid="true"] { border-color: var(--content-error); }
.v2-quality { display: inline-block; padding: 0 6px; border-radius: var(--radius-full); border: 1px solid var(--up); color: var(--up); font-size: var(--text-xs); }

/* Table */
.v2-table-wrap { overflow: auto; border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); max-height: 68vh; }
/* Thanh cuộn mảnh (§4.4). Chrome 121+/Firefox dùng scrollbar-*, Safari dùng ::-webkit-scrollbar. */
.v2-table-wrap, .v2-drawer, #detail .sd-card { scrollbar-width: thin; scrollbar-color: var(--border-subtle) transparent; }
.v2-table-wrap::-webkit-scrollbar, .v2-drawer::-webkit-scrollbar, #detail .sd-card::-webkit-scrollbar { width: 8px; height: 8px; }
.v2-table-wrap::-webkit-scrollbar-track, .v2-drawer::-webkit-scrollbar-track, #detail .sd-card::-webkit-scrollbar-track { background: transparent; }
.v2-table-wrap::-webkit-scrollbar-thumb, .v2-drawer::-webkit-scrollbar-thumb, #detail .sd-card::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: var(--radius-full); }
.v2-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.v2-table th, .v2-table td { padding: 9px 12px; border-bottom: 1px solid var(--border-subtle); text-align: right; white-space: nowrap; }
.v2-table th:first-child, .v2-table td:first-child, .v2-table th:nth-child(2), .v2-table td:nth-child(2) { text-align: left; }
.v2-table thead th { position: sticky; top: 0; z-index: 1; background: var(--bg-subtle); font-size: var(--text-xs); font-weight: 500; color: var(--content-subtle); }
.v2-table tbody tr:last-child td { border-bottom: 0; }
.v2-table small { font-size: var(--text-xs); }
.v2-row { cursor: pointer; }
.v2-row:hover td { background: var(--bg-subtle); }
.v2-symbol { font-weight: 650; margin-right: 6px; }
/* Pill (§4.3): gồm .pill của account.js. */
.v2-pill, .v2-account .pill { display: inline-block; padding: 1px 8px; border-radius: var(--radius-full); font-size: var(--text-xs); border: 1px solid var(--border-subtle); color: var(--content-subtle); }
.v2-pill--full, .v2-account .pill--full { color: var(--up); border-color: var(--up); }
.v2-pill--sample { color: var(--content-warning); border-color: var(--content-warning); }
.v2-pill--locked, .v2-account .pill--locked { color: var(--content-subtle); }
/* Chip lọc (admin, styleguide). */
.v2-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.v2-chip {
  padding: 5px 11px; border: 1px solid var(--border-subtle); border-radius: var(--radius-full);
  background: none; color: var(--content-subtle); font: inherit; font-size: var(--text-sm); cursor: pointer;
}
.v2-chip:hover { background: var(--bg-subtle); }
.v2-chip.is-active { background: var(--bg-subtle); color: var(--content-default); border-color: var(--bg-inverted); }
.v2-blur { filter: blur(4px); user-select: none; color: var(--content-subtle); }
.v2-empty { padding: 24px; text-align: center; color: var(--content-subtle); }
.v2-footer { padding-top: 4px; justify-self: center; max-width: 820px; text-align: center; text-wrap: balance; }
.v2-footer a { display: inline-block; padding: 6px 0; }
.v2-footer__contact { display: block; margin-top: 4px; }

/* CTA */
.v2-cta { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.v2-cta__title { font-weight: 600; }

.v2-scrim { position: fixed; inset: 0; z-index: 15; background: var(--bg-overlay); }
/* Drawer nổi: cách mép 8px, viền đủ, bo --radius-lg (§4.5). */
.v2-drawer {
  position: fixed; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); z-index: 20;
  /* max-width cũng giới hạn --wide/--detail: không tràn sang inset bên trái khi xoay ngang. */
  width: min(380px, 100% - 16px); max-width: calc(100% - max(8px, env(safe-area-inset-left)) - max(8px, env(safe-area-inset-right))); display: grid; align-content: start; gap: 14px;
  padding: 20px; background: var(--bg-default); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); overflow: auto;
  box-shadow: var(--shadow-drawer);
  /* One shrinkable column: an implicit auto column grows to the widest nowrap table and pushes content off-screen. */
  grid-template-columns: minmax(0, 1fr); overflow-x: hidden; overscroll-behavior: contain;
}
.v2-drawer > * { min-width: 0; }
.v2-dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: var(--text-sm); }
.v2-dl dt { color: var(--content-subtle); }
.v2-dl dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* Dialogs */
.v2-dialog { width: min(440px, 92vw); padding: 0; border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); background: var(--bg-default); color: var(--content-default); }
.v2-dialog::backdrop { background: var(--bg-overlay); }
.v2-dialog__form { display: grid; gap: 12px; padding: 18px; }
.v2-dialog__actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.v2-linkrow { display: flex; gap: 8px; }
.v2-linkrow .v2-input { flex: 1; }
.v2-tabs { display: inline-flex; padding: 2px; gap: 2px; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); width: max-content; }
.v2-tab { padding: 4px 10px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--content-subtle); font: inherit; font-size: var(--text-sm); cursor: pointer; }
.v2-tab.is-active { background: var(--bg-subtle); color: var(--content-default); }

/* Chuyển động (0.23.0). Chỉ opacity/transform/màu, không animate layout. Không có transition toàn cục khi đổi theme. */
.v2-btn, .v2-account .btn, .v2-icon-btn, .v2-switch__opt, .v2-nav__item, .v2-tab, .v2-tier, .v2-pill, .v2-chip, .v2-stat,
.v2-input, .v2-account input, .v2-account select, .v2-account textarea {
  transition-property: background-color, border-color, color, opacity, box-shadow;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease-out);
}
.v2-row td { transition: background-color var(--duration-fast) var(--ease-out); }
/* Đang tải lại (aria-busy trên khung bảng): giữ hàng cũ, mờ nhanh; không đổi layout. */
.v2-table-wrap tbody { transition: opacity var(--duration-fast) var(--ease-out); }
.v2-table-wrap[aria-busy="true"] tbody { opacity: .55; }
/* Khung xương trước dữ liệu: cao đúng một dòng chữ của ô, giữ chỗ để không xô layout. */
.v2-skel { display: block; height: 1.5em; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--bg-default) 50%, var(--bg-subtle) 75%); background-size: 200% 100%; animation: v2-shimmer var(--duration-shimmer) linear infinite; }
@keyframes v2-shimmer { to { background-position: -200% 0; } }
/* Drawer + scrim: [hidden] giữ nguyên, JS không đổi. display chuyển rời rạc (allow-discrete) để kịp chạy hiệu ứng thoát;
   trình duyệt chưa hỗ trợ thì bật/tắt tức thì như cũ. Vào: --duration-slow ease-out; ra: --duration-base ease-in. */
.v2-scrim, .v2-drawer {
  transition-property: opacity, transform, display;
  transition-duration: var(--duration-slow);
  transition-timing-function: var(--ease-out);
  transition-behavior: allow-discrete;
}
.v2-scrim[hidden] { opacity: 0; transition-duration: var(--duration-base); transition-timing-function: var(--ease-in); }
.v2-drawer[hidden] { opacity: 0; transform: translateX(16px); transition-duration: var(--duration-base); transition-timing-function: var(--ease-in); }
/* Dialog (showModal): mờ dần + scale .98→1; overlay giữ dialog trong top layer khi đang đóng. */
.v2-dialog, .v2-dialog::backdrop {
  transition-property: opacity, transform, overlay, display;
  transition-duration: var(--duration-base);
  transition-timing-function: var(--ease-out);
  transition-behavior: allow-discrete;
}
.v2-dialog:not([open]) { opacity: 0; transform: scale(.98); transition-duration: var(--duration-fast); transition-timing-function: var(--ease-in); }
.v2-dialog:not([open])::backdrop { opacity: 0; transition-duration: var(--duration-fast); transition-timing-function: var(--ease-in); }
/* Đặt sau các luật trên: trạng thái bắt đầu khi phần tử vừa hiện. */
@starting-style {
  .v2-scrim { opacity: 0; }
  .v2-drawer { opacity: 0; transform: translateX(16px); }
  .v2-dialog[open] { opacity: 0; transform: scale(.98); }
  .v2-dialog[open]::backdrop { opacity: 0; }
}
/* Một chỗ cho cả V2: giảm chuyển động = mọi --duration-* về 0 (các luật riêng từng file vẫn giữ). */
@media (prefers-reduced-motion: reduce) {
  :root { --duration-fast: 0ms; --duration-base: 0ms; --duration-slow: 0ms; --duration-flash: 0ms; --duration-flash-long: 0ms; --duration-shimmer: 0ms; }
  .v2-skel { animation: none; }
}

/* Responsive */
@media (max-width: 960px) {
  .v2-sessions.is-closed { justify-self: start; }
  /* align-content start: trang còn ngắn thì hàng sidebar không giãn theo 100vh rồi co lại (giật lúc tải). */
  .v2-shell { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .v2-main { grid-column: auto; }
  .v2-sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; border-right: 0; border-bottom: 1px solid var(--border-subtle); }
  .v2-nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .v2-nav__item { width: auto; }
  /* Sidebar nằm trên cùng và giữ inset trên; topbar chỉ dính dưới inset khi cuộn. */
  .v2-topbar { top: env(safe-area-inset-top); padding-top: 12px; }
  .v2-market { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .v2-content { padding: 14px 12px 32px; }
  .v2-topbar { padding: 10px 12px; }
  .v2-live { display: none; }
  .v2-drawer { padding: 14px 14px 24px; }
}
