/* Beacon — Tra cứu văn bản pháp luật (theo thiết kế "Tra cứu văn bản luật.dc.html") */

:root {
  --bg: #F4F5F8;
  --surface: #FFFFFF;
  --border: #DDE1EC;
  --border-strong: #C3C9DC;
  --text: #1A1D27;
  --muted: #5A6178;
  --faint: #A0A7BE;
  --accent: #F5A623;
  --accent-hover: #E8940F;
  --accent-text: #C77D00;
  --accent-deep: #92600A;
  --accent-soft: rgba(245, 166, 35, 0.14);
  --selected-bg: #FDF6E9;
  --hover: #EDEFF4;
  --row-hover: #F7F8FB;
  --blue: #2563EB;
  --green: #059669;
  --amber: #B45309;
  --red: #DC2626;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--accent-text); }
::selection { background: var(--accent); color: var(--text); }
input, select, button { font-family: inherit; font-size: 13px; color: var(--text); }
.mono { font-family: 'JetBrains Mono', monospace; }
.spacer { flex: 1; }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

/* ===== Header ===== */
.topbar {
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 24px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.logo { width: 24px; height: 24px; }
.app-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.beacon-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #FF4444;
  animation: beacon-pulse 1.6s cubic-bezier(0.2, 0.7, 0.2, 1) infinite;
}
@keyframes beacon-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.45); }
  70% { box-shadow: 0 0 0 10px rgba(255, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 68, 68, 0); }
}
.sync-line { font-size: 12px; color: var(--muted); }

.body { display: flex; flex: 1; overflow: hidden; }

/* ===== Sidebar ===== */
.sidebar {
  width: 232px; flex: none; overflow-y: auto; overflow-x: hidden;
  border-right: 1px solid var(--border); background: var(--surface);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 2px;
  transition: width 200ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
.sidebar.collapsed { width: 64px; }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px 8px; }
.sidebar.collapsed .side-head { justify-content: center; }
.side-title {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); padding-left: 8px; white-space: nowrap;
}
.sidebar.collapsed .side-title { display: none; }
.side-toggle {
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  padding: 5px; color: var(--muted); cursor: pointer; display: flex;
}
.side-toggle:hover { background: var(--hover); }
.lv-list { display: flex; flex-direction: column; gap: 2px; }
.lv-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text);
  border: none; border-left: 2px solid transparent; background: transparent;
  white-space: nowrap; overflow: hidden; text-align: left; width: 100%;
}
.sidebar.collapsed .lv-item { justify-content: center; }
.lv-item:hover { background: var(--hover); }
.lv-item.active { color: var(--accent-deep); background: var(--accent-soft); border-left-color: var(--accent); }
.lv-count { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); }
.sidebar.collapsed .lv-count { display: none; }
.side-fill { flex: 1; }
.side-note {
  font-size: 11px; color: var(--faint);
  padding: 12px; border-top: 1px solid var(--border); margin-top: 12px;
}
.sidebar.collapsed .side-note { display: none; }

/* ===== Main ===== */
.main { flex: 1; overflow-y: auto; padding: 24px; }

/* Stat tiles */
.stat-tiles { display: flex; gap: 10px; flex-wrap: wrap; }
.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 16px; min-width: 96px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.stat-tile.primary {
  border-color: var(--accent); background: var(--selected-bg);
  box-shadow: 0 1px 2px rgba(146, 96, 10, 0.06);
}
.stat-value {
  font-family: 'JetBrains Mono', monospace; font-size: 20px; font-weight: 600;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.stat-tile.primary .stat-value { color: var(--accent-deep); }
.stat-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); white-space: nowrap;
}
.stat-value.c-green { color: var(--green); }
.stat-value.c-amber { color: var(--amber); }
.stat-value.c-red { color: var(--red); }

/* ===== Vùng chức năng (zones) ===== */
.zone { margin-bottom: 24px; }
.zone-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; min-width: 0; }
.zone-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--muted); white-space: nowrap; flex: none;
}
.zone-context {
  font-size: 12.5px; color: var(--faint); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}

/* ===== Vùng 1: Tìm kiếm (thẻ nổi bật — hành động chính) ===== */
.zone-search {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px;
  padding: 14px; margin-bottom: 24px;
  box-shadow: 0 1px 2px rgba(26, 29, 39, 0.03), 0 10px 28px -20px rgba(26, 29, 39, 0.22);
}
.search-row { display: flex; gap: 10px; align-items: stretch; }
.search-box {
  flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 0 14px; height: 46px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.search-box .search-ico { color: var(--faint); flex: none; transition: color 0.15s ease; }
.search-box:focus-within {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-box:focus-within .search-ico { color: var(--accent-text); }
.search-box input { flex: 1; min-width: 0; background: transparent; border: none; outline: none; font-size: 14.5px; }
.search-box input::placeholder { color: var(--faint); }
.clear-q {
  display: flex; align-items: center; justify-content: center; flex: none;
  width: 24px; height: 24px; border-radius: 6px;
  background: transparent; border: none; color: var(--faint); cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.clear-q:hover { background: var(--hover); color: var(--text); }
.btn-search {
  display: flex; align-items: center; gap: 8px; flex: none;
  background: var(--accent); color: var(--text); border: none; border-radius: 10px;
  height: 46px; padding: 0 22px; font-size: 14.5px; font-weight: 600; cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
  box-shadow: 0 1px 2px rgba(146, 96, 10, 0.18);
}
.btn-search:hover { background: var(--accent-hover); box-shadow: 0 2px 8px -2px rgba(146, 96, 10, 0.35); }
.btn-search:active { transform: translateY(1px); box-shadow: none; }
.btn-search svg { flex: none; }
.adv-toggle {
  display: flex; align-items: center; gap: 7px; flex: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  height: 46px; padding: 0 16px; color: var(--muted); font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.adv-toggle:hover { background: var(--hover); color: var(--text); border-color: var(--border-strong); }
.adv-toggle.on { background: var(--accent-soft); color: var(--accent-deep); border-color: transparent; }
.adv-toggle .chev { transition: transform 0.18s ease; }
.adv-toggle.on .chev { transform: rotate(180deg); }

/* Ô phản hồi tìm kiếm — ngay dưới hàng tìm, nổi bật theo trạng thái */
.search-feedback {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px; padding: 10px 14px; border-radius: 10px;
  font-size: 13px; font-weight: 500; line-height: 1.45;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
}
.search-feedback .fb-icon { flex: none; display: flex; }
.search-feedback .fb-text { min-width: 0; }
.search-feedback b { font-weight: 700; color: inherit; }
.search-feedback.loading { border-color: var(--border-strong); color: var(--text); background: var(--surface); }
.search-feedback.success { background: rgba(5, 150, 105, 0.07); border-color: rgba(5, 150, 105, 0.28); color: #047857; }
.search-feedback.warn { background: var(--accent-soft); border-color: rgba(245, 166, 35, 0.4); color: var(--accent-deep); }
.search-feedback.error { background: rgba(220, 38, 38, 0.06); border-color: rgba(220, 38, 38, 0.32); color: var(--red); }
.spinner {
  width: 15px; height: 15px; flex: none; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.adv-panel {
  display: flex; gap: 14px 18px; align-items: flex-end; flex-wrap: wrap;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
}
.adv-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.adv-flabel {
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--faint); padding-left: 2px;
}
.adv-panel select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; cursor: pointer; max-width: 240px;
  transition: border-color 0.15s ease;
}
.adv-panel select:hover { border-color: var(--border-strong); }
.chk-hide-expired {
  display: flex; align-items: center; gap: 8px; height: 36px;
  font-size: 13px; color: var(--muted); cursor: pointer; font-weight: 500;
}
.chk-hide-expired input { accent-color: var(--accent); }

/* ===== Vùng 3: Chip lọc theo loại (kèm số đếm) ===== */
.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.chips-label { font-size: 12px; color: var(--muted); font-weight: 500; margin-right: 2px; white-space: nowrap; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background 0.13s ease, border-color 0.13s ease, color 0.13s ease;
}
.chip:hover { border-color: var(--border-strong); background: var(--row-hover); }
.chip-count {
  font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 600;
  color: var(--faint); font-variant-numeric: tabular-nums;
}
.chip.active { background: var(--accent); color: var(--text); border-color: var(--accent); }
.chip.active .chip-count { color: var(--accent-deep); }

/* List head */
.list-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.list-head h3 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.list-count { font-size: 12px; color: var(--muted); }
.list-disclaimer { font-size: 11px; color: var(--faint); }
.layout-switch { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.layout-switch button {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); color: var(--muted); border: none;
  padding: 7px 12px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.layout-switch button.active { background: var(--accent); color: var(--text); }

/* Status / warnings */
.status { padding: 10px 14px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.status.error { border-color: rgba(220, 38, 38, 0.4); color: var(--red); }
.lex-warn {
  background: var(--accent-soft); border-radius: 8px; padding: 10px 14px;
  font-size: 13px; color: var(--accent-deep); margin-bottom: 12px;
}

/* ===== Results: panel layout ===== */
.panel-list { display: flex; flex-direction: column; gap: 12px; }
.doc-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 2px solid transparent;
  border-radius: 12px; padding: 16px; cursor: pointer;
}
.doc-card:hover { background: var(--row-hover); }
.badge-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge {
  background: var(--hover); color: var(--muted); padding: 3px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
}
.badge.pin { background: rgba(217, 119, 6, 0.12); color: #b45309; font-weight: 700; }
.badge.lv { background: var(--accent-soft); color: var(--accent-deep); }
.badge.scope { display: inline-flex; align-items: center; gap: 6px; background: rgba(37, 99, 235, 0.08); color: var(--blue); }
.badge.scope::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--blue); }
.badge.scope.trung-uong { background: rgba(5, 150, 105, 0.10); color: var(--green); }
.badge.scope.trung-uong::before { background: var(--green); }
.badge-kind { color: var(--faint); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
/* Badge trạng thái theo status_hint (UNTRUSTED, hiển thị nguyên trạng) */
.badge.st { display: inline-flex; align-items: center; gap: 6px; }
.badge.st::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.st-dang { background: rgba(37, 99, 235, 0.08); color: var(--blue); }
.badge.st-moi { background: rgba(5, 150, 105, 0.10); color: var(--green); }
.badge.st-sap { background: rgba(180, 83, 9, 0.10); color: var(--amber); }
.badge.st-het { background: rgba(220, 38, 38, 0.08); color: var(--red); }
.badge.st-unk { background: var(--hover); color: var(--muted); }
/* Ghi chú liên quan/thay thế trên item danh sách */
.doc-relnote {
  background: var(--accent-soft); border-radius: 4px; padding: 8px 10px;
  font-size: 12px; color: var(--accent-deep); margin-top: 10px; max-width: 760px;
}
.doc-relnote b { font-weight: 600; }
.score { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--accent-text); }
.doc-title { font-size: 16px; font-weight: 600; margin-top: 10px; }
.doc-title .so { font-family: 'JetBrains Mono', monospace; font-weight: 500; color: var(--accent-text); font-size: 14px; }
.doc-meta { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted); margin-top: 4px; }
.doc-snippet-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin-top: 10px; max-width: 760px;
}
.doc-snippet-heading { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--blue); }
.doc-snippet-text { font-size: 12px; color: var(--muted); margin-top: 4px; }
.doc-more-hits { font-size: 11px; color: var(--faint); margin-top: 6px; }
.doc-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.doc-actions .sep { width: 1px; height: 20px; background: var(--border); }
.act-btn {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; color: var(--muted); font-size: 13px; font-weight: 500; cursor: pointer;
}
.act-btn:hover { background: var(--hover); }
.act-link { border: none; font-size: 12px; color: var(--muted); padding: 6px 8px; }
.act-link:hover { color: var(--accent-text); }
mark { background: var(--accent-soft); color: inherit; border-radius: 2px; padding: 0 1px; }

/* ===== Results: table layout ===== */
.doc-table { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.doc-table .tr {
  display: grid; grid-template-columns: 150px 1fr 110px 170px 110px 140px;
  gap: 12px; align-items: center; padding: 10px 16px; font-size: 13px;
  border-top: 1px solid var(--border); cursor: pointer; border-left: 2px solid transparent;
}
.doc-table .tr:hover { background: var(--row-hover); }
.doc-table .thead {
  border-top: none; cursor: default;
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.doc-table .thead:hover { background: transparent; }
.doc-table .td-so { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--accent-text); }
.doc-table .td-ten { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-table .td-muted { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-table .td-date { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted); }

/* ===== Results: cards layout ===== */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 16px; }
.grid-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 2px solid transparent;
  border-radius: 12px; padding: 16px; cursor: pointer;
  display: flex; flex-direction: column; gap: 8px;
}
.grid-card:hover { background: var(--row-hover); }
.grid-card .gc-ten { font-size: 14px; font-weight: 600; }
.grid-card .gc-so { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--accent-text); }
.grid-card .gc-snippet { font-size: 12px; color: var(--muted); flex: 1; }
.grid-card .gc-meta { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); }

/* Empty + load more */
.empty-state { padding: 48px; text-align: center; color: var(--muted); font-size: 13px; }
.btn-reset {
  display: block; margin: 12px auto 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer;
}
.btn-reset:hover { background: var(--hover); }
.load-more-wrap { display: flex; justify-content: center; margin-top: 16px; }
.btn-more {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 20px; font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer;
}
.btn-more:hover { background: var(--hover); }

/* ===== Footer ===== */
.footer {
  display: flex; align-items: center; gap: 8px;
  margin-top: 40px; padding: 14px 2px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--faint);
}
.footer-label { text-transform: uppercase; letter-spacing: 0.06em; font-size: 10.5px; font-weight: 600; }
.footer-mail {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px; margin-left: -8px; border-radius: 6px;
  font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted);
  transition: color 0.12s ease, background 0.12s ease;
}
.footer-mail svg { color: var(--faint); transition: color 0.12s ease; }
.footer-mail:hover { color: var(--accent-text); background: var(--accent-soft); }
.footer-mail:hover svg { color: var(--accent-text); }

/* ===== Detail overlay (v2) ===== */
.detail-overlay { position: fixed; top: 56px; left: 0; right: 0; bottom: 0; background: var(--bg); overflow-y: auto; z-index: 40; }
.detail-inner { max-width: 1240px; margin: 0 auto; padding: 20px 24px 64px; }

/* Thanh điều hướng sticky của trang chi tiết: trong suốt + blur khi nổi trên nội dung,
   chỉ hiện viền/bóng lúc đã cuộn để không tạo viền đôi với header lúc ở đỉnh. */
.detail-topbar {
  position: sticky; top: 0; z-index: 45;
  background: rgba(255, 255, 255, 0);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.detail-topbar.is-scrolled {
  background: rgba(255, 255, 255, 0.78);
  border-bottom-color: var(--border);
  box-shadow: 0 1px 2px rgba(26, 29, 39, 0.04), 0 6px 16px -8px rgba(26, 29, 39, 0.1);
}
.detail-topbar-inner {
  max-width: 1240px; margin: 0 auto; min-width: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 24px;
}
.btn-back {
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); font-size: 13px; font-weight: 500;
  padding: 6px 14px 6px 10px; cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.btn-back:hover { color: var(--text); border-color: var(--border-strong); background: var(--row-hover); }
.btn-back:active { background: var(--hover); }
.btn-back svg { transition: transform 0.18s ease; }
.btn-back:hover svg { transform: translateX(-2px); }
/* Ngữ cảnh văn bản — chỉ fade-in khi tiêu đề thật đã cuộn khuất */
.topbar-sep { flex: none; width: 1px; height: 18px; background: var(--border); }
.topbar-sep, .topbar-doc {
  opacity: 0; transform: translateY(3px); pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.detail-topbar.is-scrolled .topbar-sep,
.detail-topbar.is-scrolled .topbar-doc { opacity: 1; transform: none; }
.topbar-doc { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.topbar-doc-so { flex: none; font-size: 12px; color: var(--accent-text); }
.topbar-doc-ten {
  font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.detail-ten { font-size: 28px; font-weight: 600; letter-spacing: -0.015em; margin-top: 14px; line-height: 1.2; }
.detail-so { font-size: 16px; color: var(--accent-text); margin-top: 6px; }

/* Thẻ metadata ngang dưới tiêu đề */
.meta-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 20px; margin-top: 20px;
  display: flex; gap: 28px; align-items: center; flex-wrap: wrap;
}
.meta-k {
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--faint);
}
.meta-v { font-size: 13px; font-weight: 500; margin-top: 2px; max-width: 260px; }
.meta-v.v-mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; margin-top: 3px; }
.btn-copy {
  display: flex; align-items: center; gap: 6px;
  background: var(--accent); color: var(--text); border: none; border-radius: 8px;
  padding: 9px 14px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn-copy:hover { background: var(--accent-hover); }
.btn-source {
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px; color: var(--muted); padding: 8px 12px; white-space: nowrap;
}
.btn-source:hover { color: var(--accent-text); }

.detail-cols { display: grid; grid-template-columns: 300px 1fr; gap: 24px; align-items: start; margin-top: 24px; }
.detail-main { min-width: 0; display: flex; flex-direction: column; gap: 24px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.panel-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 12px;
}
.panel-label.no-mb { margin-bottom: 0; }
.provenance { padding: 0 4px; }
.provenance .mono { font-size: 11px; color: var(--faint); word-break: break-all; }
.prov-note { font-size: 11px; color: var(--faint); margin-top: 8px; }

/* Ghi chú liên quan/thay thế cấp văn bản */
.rel-note {
  background: var(--accent-soft); border-radius: 8px; padding: 12px 14px;
  font-size: 13px; color: var(--accent-deep); line-height: 1.5;
}
.rel-note b { font-weight: 600; }

/* Khối văn bản liên quan (thu gọn được) */
.rels-panel { padding: 14px 20px; }
.rels-head { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.rels-count { font-size: 11px; color: var(--faint); }
.rels-toggle { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.rels-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr)); gap: 8px; margin-top: 10px; }
.rel-row {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  border: 1px solid var(--border); border-left: 2px solid var(--muted);
  border-radius: 8px; padding: 7px 10px; background: var(--surface);
}
.rel-row.internal { cursor: pointer; }
.rel-row.internal:hover { background: var(--row-hover); }
.rel-badge {
  padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap;
}
.rel-so { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--accent-text); white-space: nowrap; }
.rel-ten { flex: 1; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rel-ext { font-size: 10px; color: var(--faint); white-space: nowrap; flex: none; }

/* Mục lục sticky */
.toc-panel {
  position: sticky; top: 70px; /* dưới thanh "Quay lại" sticky (~54px) + 16px */
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; max-height: calc(100vh - 186px); overflow-y: auto;
}
.toc-legend { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0 0; }
.toc-legend .lg-item { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.toc-legend .lg-dot { width: 8px; height: 8px; border-radius: 2px; }
.toc-legend .lg-note { flex-basis: 100%; font-size: 11px; color: var(--faint); }
.toc { display: flex; flex-direction: column; margin-top: 12px; border-top: 1px solid var(--hover); padding-top: 8px; }
.toc button {
  display: flex; align-items: center; gap: 8px;
  background: transparent; border: none; text-align: left; cursor: pointer;
  padding: 6px 10px 6px 24px; border-radius: 6px;
  font-size: 13px; color: var(--muted); line-height: 1.4;
}
.toc button .t { flex: 1; }
.toc button .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: transparent; }
.toc button.lvl-head { color: var(--text); font-weight: 600; padding: 8px 10px; }
.toc button:hover { background: var(--bg); }
.toc button.het .t { text-decoration: line-through; color: var(--faint); }
.toc .toc-empty { padding: 8px 0; font-size: 13px; color: var(--faint); }

/* Nội dung văn bản: section + lề ghi chú quan hệ */
.content-panel { padding: 0; overflow: hidden; }
.content-head { display: flex; align-items: center; gap: 12px; padding: 14px 24px; }
.content-hint { font-size: 11px; color: var(--faint); }
.sec-row {
  display: grid; grid-template-columns: 1fr 230px; gap: 20px;
  padding: 14px 24px; border-top: 1px solid var(--hover);
  transition: background 400ms;
}
.sec-row.no-margin { grid-template-columns: 1fr; }
.sec-row.flash { background: rgba(245, 166, 35, 0.18); }
.sec-row.head-row { padding: 18px 24px 6px; }
.sec-heading { font-size: 15px; font-weight: 600; color: var(--text); line-height: 1.4; white-space: pre-line; }
.sec-row.head-row .sec-heading {
  font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.sec-row.het .sec-heading { text-decoration: line-through; color: var(--faint); }
.sec-body { min-width: 0; }
.sec-margin { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.mg-card {
  border: 1px solid var(--border); border-left: 2px solid var(--muted);
  border-radius: 8px; padding: 8px 10px; background: var(--surface); font-size: 11px;
}
.mg-card.internal { cursor: pointer; }
.mg-card.internal:hover { background: var(--row-hover); }
.mg-het {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--red); margin-bottom: 4px;
}
.mg-het::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--red); }
.mg-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mg-note { font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.mg-open { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--accent-deep); margin-top: 5px; }
.mg-ext { font-size: 10px; color: var(--faint); margin-top: 5px; }

/* Matched chunks in detail */
.match-item { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: var(--bg); }
.match-item + .match-item { margin-top: 10px; }
.match-heading { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--blue); margin-bottom: 6px; }
.match-heading .m-score { color: var(--accent-text); float: right; }
.match-text { font-size: 13px; color: var(--text); }
.match-open { background: none; border: none; color: var(--muted); font-size: 12px; cursor: pointer; padding: 6px 0 0; }
.match-open:hover { color: var(--accent-text); }

/* ===== Legal text formatting (giữ từ bản cũ) ===== */
.legal-text { font-size: 14px; line-height: 1.65; }
.legal-text .section-title { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
.legal-text .note { color: var(--faint); font-size: 13px; }
.fmt-line { margin: 0 0 8px; }
.fmt-center { text-align: center; }
.fmt-right { text-align: right; }
.fmt-bold { font-weight: 700; }
.fmt-semibold { font-weight: 600; }
.fmt-italic { font-style: italic; }
.fmt-small { font-size: 13px; }
.fmt-dieu { font-weight: 700; margin-top: 14px; }
.fmt-khoan { margin-left: 16px; }
.fmt-diem { margin-left: 32px; }

/* ===== Responsive ===== */

/* Nút mở drawer lĩnh vực — chỉ hiện trên màn hẹp */
.menu-btn {
  display: none; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: none;
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.menu-btn:hover { background: var(--hover); color: var(--text); }
.menu-btn:active { background: var(--border); }

/* Scrim phủ nội dung khi drawer mở */
.scrim {
  position: fixed; inset: 56px 0 0 0; z-index: 55;
  background: rgba(26, 29, 39, 0.4);
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s ease;
}
body.nav-open .scrim { opacity: 1; pointer-events: auto; }

/* --- ≤1024px: sidebar thành drawer off-canvas, detail về 1 cột --- */
@media (max-width: 1024px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; top: 56px; bottom: 0; left: 0; width: 280px; z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.2, 0.7, 0.2, 1);
    border-right: 1px solid var(--border);
  }
  body.nav-open .sidebar {
    transform: none;
    box-shadow: 16px 0 40px -20px rgba(26, 29, 39, 0.3);
  }
  /* Trong drawer luôn hiện đầy đủ nhãn — trạng thái collapsed của desktop không áp dụng */
  .sidebar.collapsed { width: 280px; }
  .sidebar.collapsed .side-title { display: block; }
  .sidebar.collapsed .lv-count { display: inline; }
  .sidebar.collapsed .side-note { display: block; }
  .sidebar.collapsed .side-head { justify-content: space-between; }
  .sidebar.collapsed .lv-item { justify-content: space-between; }
  .side-toggle { display: none; }

  .main { padding: 20px; }

  .detail-cols { grid-template-columns: 1fr; gap: 16px; }
  .toc-panel { position: static; max-height: 300px; }
  .detail-ten { font-size: 24px; }
}

/* --- ≤900px: bảng ẩn cột phụ (Loại, Lĩnh vực), nội dung chi tiết bỏ lề ghi chú --- */
@media (max-width: 900px) {
  .doc-table .tr { grid-template-columns: 130px 1fr 150px 96px; }
  .doc-table .tr > :nth-child(3),
  .doc-table .tr > :nth-child(6) { display: none; }

  .sec-row { grid-template-columns: 1fr; gap: 10px; }
}

/* --- ≤640px: bố cục một cột cho điện thoại --- */
@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 10px; }
  .app-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sync-line { display: none; }

  .main { padding: 16px; }

  .stat-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
  .stat-tile { min-width: 0; padding: 10px 12px; }
  .stat-value { font-size: 18px; }

  .zone-search { padding: 12px; }
  .search-row { flex-wrap: wrap; gap: 10px; }
  .search-box { flex: 1 1 100%; order: -1; }
  /* 16px để iOS không tự zoom khi focus */
  .search-box input { font-size: 16px; }
  .btn-search { flex: 1 1 auto; justify-content: center; }
  .adv-toggle { flex: none; }
  .adv-panel { gap: 12px; }
  .adv-field { flex: 1 1 calc(50% - 10px); min-width: 0; }
  .adv-panel select { flex: none; width: 100%; max-width: none; }
  .zone { margin-bottom: 20px; }

  /* Chips cuộn ngang tràn mép thay vì xuống dòng chiếm màn hình */
  .chips {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    margin: 0 -16px 16px; padding: 0 16px 4px;
    scrollbar-width: none;
  }
  .chips::-webkit-scrollbar { display: none; }

  .list-head { gap: 8px 12px; }
  .list-head h3 { font-size: 17px; }
  .list-head .spacer { display: none; }
  .layout-switch { margin-left: auto; }
  .list-disclaimer { flex-basis: 100%; order: 10; }

  .doc-table .tr { grid-template-columns: 104px 1fr 82px; gap: 10px; padding: 10px 12px; }
  .doc-table .tr > :nth-child(4) { display: none; }

  .doc-card { padding: 14px; }
  .doc-title { font-size: 15px; }

  .footer { flex-wrap: wrap; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

  /* Trang chi tiết */
  .detail-topbar-inner { padding: 10px 16px; gap: 10px; }
  .detail-inner { padding: 16px 16px 48px; }
  .detail-ten { font-size: 21px; }
  .detail-so { font-size: 14px; }
  .meta-card { gap: 12px 24px; padding: 14px 16px; }
  .meta-card .spacer { display: none; }
  .meta-v { max-width: none; }
  .panel { padding: 16px; }
  .toc-panel { padding: 14px; max-height: 260px; }
  .content-head { padding: 12px 16px; }
  .sec-row { padding: 12px 16px; }
  .sec-row.head-row { padding: 16px 16px 4px; }
  .rels-panel { padding: 12px 14px; }
}
