/* Bot v0.8 dashboard — "terminal ấm áp".
 *
 * Nền giấy kem, card trắng bo lớn, không đổ bóng. Inter cho chữ, Geist Mono cho
 * MỌI con số. Màu nhấn tiết chế, và chỉ dùng để mã hoá dữ liệu — không trang trí.
 *
 * Font nhúng tại chỗ trong web/fonts/, nạp bằng <link> riêng trong
 * index.html — không @import (test cấm, vì @import từ xa là lỗ CDN). CSP là
 * `style-src 'self'; font-src 'self'` không có unsafe-inline, nên không @import
 * và không CDN; script chỉ được đặt từng thuộc tính qua CSSOM (el.style.width),
 * không bao giờ là thuộc tính style.
 *
 * Tương phản: --text-3, --green-2, --amber-2, --orange-2 đo được 2.9–4.2:1 trên
 * nền trắng, nên chúng chỉ dùng cho đồ hoạ và số cỡ lớn (ngưỡng 3:1). Chữ nhỏ
 * dùng --text-2, --green, --red, --amber, --orange (4.5:1 trở lên).
 */

:root {
  /* Bề mặt */
  --bg: #F0EEE9;
  --surface: #FFFFFF;
  --surface-sunk: #F5F4F1;
  --surface-muted: #F1F0EC;
  --line: #ECECEA;
  --line-strong: #E5E4DF;

  /* Chữ */
  --text: #0A0A0A;
  --text-2: #77776F;
  --text-3: #98968E;

  /* Ngữ nghĩa */
  --amber: #A16207;
  --amber-2: #C98A1B;
  --green: #0B7A48;
  --green-2: #0E9F5D;
  --green-bg: #D9EEE3;
  --red: #C2402F;
  --red-bg: #F9DED6;
  /* Cam Claude. Ba sắc cho ba việc khác nhau, vì một sắc không đủ:
     --orange     chữ nhỏ và nhãn trên nền sáng (7.6:1 trên trắng)
     --orange-2   đồ hoạ: đường equity, chấm, mảng tô (3.12:1 trên nền lõm)
     --orange-bg  nền tint cho tag, tab đang mở, dòng lệnh đang mở

     --orange-2 là sắc NHẠT NHẤT còn qua được ngưỡng 3:1 trên nền lõm. Nhạt hơn
     nữa thì tách khỏi --red tốt hơn (mắt dễ phân biệt equity với drawdown) mà
     lại mờ đi so với nền — hai ràng buộc kéo ngược chiều nhau, và đây là điểm
     cân bằng. Cam Claude nguyên bản #D97757 chỉ đạt 2.84; muốn dùng nó phải
     nới nền lõm lên #FCFBF9, tức gần trắng, mất luôn hiệu ứng lõm. */
  --orange: #8A3B1B;
  --orange-2: #CE7247;
  --orange-bg: #FBEDE7;

  /* Tên cũ mà JS và các quy tắc dữ liệu đang dùng. Giữ nguyên tên, đổi giá trị:
     chart.js đọc --up/--down bằng tokenRgb(), nên màu vẫn sống ở một chỗ. */
  --up: var(--green-2);
  --down: var(--red);
  --accent: var(--amber);
  /* Đường equity của bot. Benchmark là NÉT ĐỨT chứ không chỉ khác màu: hai
     đường phải phân biệt được kể cả khi không phân biệt được màu. */
  --series: var(--orange-2);
  --muted: var(--text-2);
  --dim: var(--text-3);
  --border: var(--line);
  --surface-2: var(--surface-muted);

  --radius-lg: 20px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --gap: 16px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: var(--gap);
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.45 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; }

/* Mọi con số là Geist Mono, canh cột không nhảy khi refresh. */
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ── banner demo ─────────────────────────────────────────────────────────── */

.demo-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  margin-bottom: var(--gap);
  padding: 10px 16px;
  background: var(--amber);
  color: #FFF8EC;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: .08em;
  text-align: center;
}

/* ── header ──────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 22px;
  max-width: 1600px;
  margin: 0 auto var(--gap);
  padding: 18px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.brand { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { color: var(--text-3); font-size: 12px; }

.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex: none;
}
.status[data-status="online"] .status-dot {
  background: var(--green-2);
  animation: pulse 2.4s ease-in-out infinite;
}
.status[data-status="degraded"] .status-dot { background: var(--amber-2); }
.status[data-status="offline"] .status-dot,
.status[data-status="unreachable"] .status-dot { background: var(--red); }
.status-label { font-weight: 600; }
.status-detail {
  color: var(--text-3);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(14, 159, 93, .35); }
  50% { box-shadow: 0 0 0 5px rgba(14, 159, 93, 0); }
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  color: var(--text-2);
  font: 500 11.5px/1 var(--font-mono);
  letter-spacing: .02em;
  text-transform: uppercase;
}
.chip.is-accent {
  background: var(--orange-bg);
  border-color: transparent;
  color: var(--orange);
}

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-left: auto; }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface-muted);
  border-radius: var(--radius-pill);
}
.segmented button {
  padding: 6px 13px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-2);
  font: 500 12px/1 var(--font-mono);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: 5px 12px;
  color: var(--text);
}

.btn {
  padding: 7px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-2);
  font: 500 12px/1 var(--font-mono);
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease;
}
.btn:hover { border-color: var(--text-3); color: var(--text); }
.btn:disabled { color: var(--text-3); border-color: var(--line); cursor: progress; }
.btn[aria-pressed="true"] { background: var(--orange-bg); border-color: transparent; color: var(--orange); }

button:focus-visible,
.select:focus-visible,
.table-scroll:focus-visible,
.chart-svg:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.updated { color: var(--text-3); font-size: 11.5px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.boot-error {
  max-width: 1600px;
  margin: 0 auto var(--gap);
  padding: 14px 18px;
  background: var(--red-bg);
  border-radius: var(--radius-md);
  color: var(--red);
}

/* ── layout ──────────────────────────────────────────────────────────────── */

.page { max-width: 1600px; margin: 0 auto; padding: 0; }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  /* Panel giữ chiều cao của chính nó: kéo một panel ngắn cho bằng panel cao bên
     cạnh sẽ để lại một khoảng trắng lớn, trông như thiếu dữ liệu. */
  align-items: start;
}
@media (min-width: 768px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2, .span-3 { grid-column: span 2; }
}
@media (min-width: 1200px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .span-3 { grid-column: span 3; }
}

/* ── tabs ────────────────────────────────────────────────────────────────── */
/* Ba mục thay cho một trang cuộn rất dài. Viên thuốc, đặt đúng chỗ các tiêu đề
   nhóm trước đây. Panel thuộc tab đang đóng thì ngừng poll — xem app.js. */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 24px 0 14px;
}
.tab {
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-2);
  font: 500 12px/1 var(--font-mono);
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.tab:hover { background: var(--surface-muted); color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--orange-bg);
  border-color: transparent;
  color: var(--orange);
}
.tab[aria-selected="true"]:hover { background: var(--orange-bg); color: var(--orange); }

@media (max-width: 600px) {
  .tabs { gap: 6px; margin: 18px 0 12px; }
  .tab { padding: 8px 13px; font-size: 11px; letter-spacing: .02em; }
}

.panel {
  position: relative;
  min-width: 0;
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  transition: opacity 250ms ease;
}
.panel.is-stale .panel-body { opacity: .45; }
.panel.is-loading .panel-body { opacity: .45; }

.panel-title {
  margin-bottom: 14px;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
}

/* Trạng thái rỗng/lỗi dùng chung cho mọi panel. */
.panel-state { padding: 28px 8px; text-align: center; }
.state-title { font-weight: 600; }
.panel[data-availability="error"] .state-title { color: var(--red); }
.state-note { max-width: 70ch; margin: 6px auto 0; color: var(--text-2); font-size: 13px; }

.panel-note { margin-top: 14px; }
.panel-note summary { color: var(--text-3); cursor: pointer; font-size: 12px; }
.panel-note summary:hover { color: var(--text-2); }
.panel-note p { max-width: 90ch; margin-top: 8px; color: var(--text-2); font-size: 13px; }

.panel-stale { margin-top: 12px; color: var(--amber); font-size: 12px; }

/* ── dải KPI ─────────────────────────────────────────────────────────────── */

.kpi-panel { padding: 0; background: transparent; border: 0; }
.kpi-panel .panel-state,
.kpi-panel .panel-note,
.kpi-panel .panel-stale {
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.kpi-panel .panel-state { padding: 28px 20px; }

.kpis { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
@media (min-width: 480px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 768px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1400px) { .kpis { grid-template-columns: minmax(0, 1.6fr) repeat(5, minmax(0, 1fr)); } }

.kpi {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.badge {
  padding: 2px 9px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}
.badge.is-accent { background: var(--orange-bg); border-color: transparent; color: var(--orange); }
.badge.is-up { background: var(--green-bg); border-color: transparent; color: var(--green); }
.badge.is-down { background: var(--red-bg); border-color: transparent; color: var(--red); }
.badge.is-muted { border-color: var(--line-strong); color: var(--text-3); }

/* Con số chính: Geist Mono, cỡ lớn, hơi bó chữ. */
.value {
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kpi-hero .value { font-size: clamp(28px, 2.8vw, 34px); }
@media (min-width: 1400px) { .kpi-hero .value { font-size: 34px; } }

.delta { font-size: 13px; min-height: 1.5em; }
.sub {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

/* Màu chỉ mã hoá dữ liệu. Chữ nhỏ dùng bản đậm (>=4.5:1); số cỡ lớn dùng bản
   sáng hơn, vẫn trên ngưỡng 3:1 cho chữ lớn. */
.up { color: var(--green); }
.down { color: var(--red); }
.missing { color: var(--text-3); }
.redacted { color: var(--text-3); letter-spacing: .12em; }
.value.up, .figure.up, .stat-value.up, .lead-value.up { color: var(--green-2); }

/* Tỉ số dựng trên quá ít lệnh: vẫn hiện, nhưng thấy rõ là không đáng tin. */
.kpi.is-thin .value, .stat.is-thin .stat-value { color: var(--text-3); }

.meter {
  height: 8px;
  margin: 8px 0 2px;
  overflow: hidden;
  background: var(--surface-muted);
  border-radius: var(--radius-pill);
}
.meter-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--text-3);
  transition: width 250ms ease;
}
.meter[data-state="ok"] .meter-fill { background: var(--green-2); }
.meter[data-state="warn"] .meter-fill { background: var(--amber-2); }
.meter[data-state="breach"] .meter-fill { background: var(--red); }
.meter[data-tone="up"] .meter-fill { background: var(--green-2); }
.meter[data-tone="down"] .meter-fill { background: var(--red); }
.meter[data-tone="flat"] .meter-fill { background: var(--text-3); }

/* ── footer ──────────────────────────────────────────────────────────────── */

.footer {
  max-width: 1600px;
  margin: 24px auto 0;
  padding: 18px 24px;
  color: var(--text-3);
  font-size: 12px;
}
.footer .source { margin-top: 6px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.fatal {
  max-width: 60ch;
  margin: 80px auto;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--red);
  border-radius: var(--radius-md);
  font-size: 15px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── phần đầu panel, hàng số liệu, chú giải ──────────────────────────────── */

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 14px;
}
.panel-head .panel-title { margin-bottom: 0; display: flex; align-items: center; gap: 8px; }
.head-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }

.stats-row { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-value {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-label { color: var(--text-3); font-size: 11.5px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 10px; color: var(--text-2); font-size: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-key { display: inline-block; width: 16px; height: 2px; border-radius: 1px; }
.key-line { background: var(--series); }
.key-bench {
  background: repeating-linear-gradient(90deg,
    var(--text-3) 0 5px, transparent 5px 9px);
}
.key-down { background: var(--red); }

/* ── biểu đồ: khối nền lõm, không viền ───────────────────────────────────── */

.chart {
  position: relative;
  min-height: 20px;
  padding: 14px 16px;
  background: var(--surface-sunk);
  border-radius: var(--radius-lg);
}
.chart-svg { display: block; max-width: 100%; height: auto; overflow: visible; }
.chart-svg:focus { outline: none; }

.chart-caption {
  margin: 18px 0 8px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.chart-hidden { padding: 48px 8px; color: var(--text-2); text-align: center; }
.chart-foot { margin-top: 12px; max-width: 110ch; color: var(--text-3); font-size: 12px; line-height: 1.5; }

.chart-enter { animation: chart-fade 250ms ease both; }
@keyframes chart-fade { from { opacity: 0; } to { opacity: 1; } }

/* Mark SVG: màu từ token, hình học từ thuộc tính SVG. */
.gridline { stroke: var(--line-strong); stroke-width: 1; shape-rendering: crispEdges; }
.gridline-x { opacity: .7; }
.gridline-zero { stroke: var(--text-3); opacity: .6; }
/* `stroke` di truyền trong SVG: text phải tự reset, nếu không nó ăn stroke của
   node cha rồi hiện ra nhoè và có viền. */
.chart-svg text { stroke: none; }
.axis-label {
  fill: var(--text-3);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}
.line-equity { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area-equity { fill: var(--series); fill-opacity: .045; stroke: none; }
.line-bench {
  fill: none;
  stroke: var(--text-3);
  stroke-width: 1.75;
  stroke-linejoin: round;
  stroke-dasharray: 5 4;
}
.line-down { fill: none; stroke: var(--red); stroke-width: 1.5; stroke-linejoin: round; }
.area-down { fill: var(--red); fill-opacity: .07; stroke: none; }
.dot-equity { fill: var(--series); stroke: var(--surface-sunk); stroke-width: 2; }
.dot-down { fill: var(--red); stroke: var(--surface-sunk); stroke-width: 2; }
.crosshair { stroke: var(--text-2); stroke-width: 1; opacity: .4; shape-rendering: crispEdges; pointer-events: none; }
.limit-line { stroke: var(--amber-2); stroke-width: 1; opacity: .9; shape-rendering: crispEdges; }
.limit-label { fill: var(--amber); font-size: 10.5px; font-family: var(--font-sans); font-weight: 500; }

/* ── tooltip ─────────────────────────────────────────────────────────────── */

.chart-tip {
  position: fixed;
  z-index: 30;
  min-width: 170px;
  max-width: 280px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 12px;
  pointer-events: none;
}
.tip-title { margin-bottom: 6px; color: var(--text-3); font-family: var(--font-mono); font-size: 11px; font-variant-numeric: tabular-nums; }
.tip-row { display: flex; align-items: center; gap: 8px; line-height: 1.7; }
.tip-key { flex: none; width: 12px; height: 2px; border-radius: 1px; }
.tip-key.key-line { background: var(--series); }
.tip-key.key-bench {
  background: repeating-linear-gradient(90deg,
    var(--text-3) 0 4px, transparent 4px 7px);
}
.tip-key.key-down { background: var(--red); }
.tip-value { color: var(--text); font-weight: 600; }
.tip-value.up { color: var(--green); }
.tip-value.down { color: var(--red); }
.tip-label { color: var(--text-2); }

/* ── heatmap tháng ───────────────────────────────────────────────────────── */

.hm-grid { display: flex; flex-direction: column; gap: 3px; }
.hm-row { display: grid; grid-template-columns: 44px repeat(12, minmax(0, 1fr)); gap: 3px; }
.hm-month, .hm-year { color: var(--text-3); font-size: 11px; text-align: center; align-self: center; }
.hm-year { text-align: left; font-family: var(--font-mono); }
.hm-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  cursor: default;
  transition: box-shadow 150ms ease;
}
.hm-cell.hm-none { background: transparent; border: 1px dashed var(--line-strong); }
.hm-cell.hm-nobase { color: var(--text-3); }
.hm-cell[tabindex]:hover,
.hm-cell[tabindex]:focus-visible { box-shadow: inset 0 0 0 1.5px var(--text); outline: none; }
.hm-val { overflow: hidden; white-space: nowrap; font-family: var(--font-mono); font-weight: 500; }

.hm-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; color: var(--text-3); font-size: 11px; }
.hm-scale { display: inline-block; width: 140px; height: 10px; border-radius: var(--radius-pill); }
.hm-scale-label { margin-left: 8px; }

@media (max-width: 600px) {
  .hm-row { grid-template-columns: 30px repeat(12, minmax(0, 1fr)); gap: 2px; }
  .hm-cell { height: 28px; border-radius: 8px; }
  .hm-val { display: none; }
}

/* ── danh sách nhãn → giá trị ────────────────────────────────────────────── */

.figures { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: 3px 16px; margin: 0; }
.fig-label { color: var(--text-3); font-size: 12px; line-height: 1.95; }
.fig-value {
  margin: 0;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.95;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fig-note { margin-left: 8px; color: var(--text-3); font-size: 11px; }

/* ── thanh ngang (cách thoát lệnh, đóng góp theo chiến lược) ─────────────── */

.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: flex; flex-direction: column; gap: 5px; }
.bar-head { display: flex; align-items: baseline; gap: 8px; font-size: 12px; }
.bar-label { overflow: hidden; color: var(--text-2); text-overflow: ellipsis; white-space: nowrap; }
.bar-count { margin-left: auto; color: var(--text-3); }
.bar-pnl { min-width: 6ch; text-align: right; }

/* ── bảng ────────────────────────────────────────────────────────────────── */

/* Cuộn nằm trong panel: trang không bao giờ cuộn ngang. */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  padding: 0 12px 10px;
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .08em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.table td { padding: 9px 12px; border-top: 1px solid var(--line); white-space: nowrap; }
.table th.right, .table td.right { text-align: right; }
.table tbody tr { transition: background-color 150ms ease; }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:hover { background: var(--surface-muted); }
.table tbody tr:focus-visible { outline: 2px solid var(--orange); outline-offset: -2px; }
.table tbody tr.is-quiet td { color: var(--text-3); }
.table tbody tr.is-open-row td { background: var(--orange-bg); }

.cell-stack { display: inline-flex; align-items: center; gap: 8px; }
.share { display: flex; align-items: center; gap: 10px; min-width: 120px; }
.share .meter { flex: 1; min-width: 60px; margin: 0; }
.share-pct { color: var(--text-3); font-size: 11.5px; }
.share-cell { width: 25%; min-width: 150px; }

.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 16px; }
.pager-info { color: var(--text-3); font-size: 12px; }
.pager .field { margin-left: auto; }

.field { display: inline-flex; align-items: center; gap: 7px; color: var(--text-3); font-size: 11.5px; }
.field-label { letter-spacing: .04em; }
.select {
  max-width: 160px;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font: 500 11.5px/1 var(--font-mono);
}

/* ── vị thế đang mở ──────────────────────────────────────────────────────── */

.panel-lead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; margin-bottom: 16px; }
.lead-value { font-family: var(--font-mono); font-size: 22px; font-weight: 500; letter-spacing: -0.02em; }
.lead-label { color: var(--text-3); font-size: 12px; }

.cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
@media (min-width: 900px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.position { min-width: 0; padding: 18px 20px; background: var(--surface-sunk); border-radius: var(--radius-lg); }
.position-head { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-bottom: 12px; }
.position-symbol { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.position-meta { color: var(--text-3); font-size: 11.5px; }
.position-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }

/* ── giới hạn rủi ro ─────────────────────────────────────────────────────── */

.halt { margin-bottom: 16px; padding: 12px 16px; background: var(--red-bg); border-radius: var(--radius-lg); color: var(--red); font-weight: 500; }
.meters { display: flex; flex-direction: column; gap: 16px; }
.risk-head { display: flex; align-items: baseline; gap: 9px; margin-bottom: 7px; }
.risk-label { color: var(--text-2); font-size: 13px; }
.risk-value { margin-left: auto; font-family: var(--font-mono); font-weight: 500; font-size: 13px; white-space: nowrap; }
.risk-foot { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 7px; font-size: 11px; }
.risk-state.is-ok { color: var(--text-3); }
.risk-state.is-warn { color: var(--amber); }
.risk-state.is-breach { color: var(--red); }
.risk-state.is-unknown { color: var(--text-3); }
.risk-share { color: var(--text-3); }
.risk-note { flex-basis: 100%; max-width: 80ch; color: var(--text-3); line-height: 1.5; }
.risk-row[data-state="breach"] .risk-value { color: var(--red); }
.risk-row[data-state="warn"] .risk-value { color: var(--amber); }
.risk-row[data-state="unknown"] .risk-value { color: var(--text-3); }

/* ── dòng sự kiện ────────────────────────────────────────────────────────── */

.feed { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.feed-row {
  display: grid;
  grid-template-columns: auto 8px minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  transition: background-color 150ms ease;
}
.feed-row + .feed-row { border-top: 1px solid var(--line); border-radius: 0; }
.feed-row.is-clickable { cursor: pointer; }
.feed-row.is-clickable:hover { background: var(--surface-muted); border-radius: var(--radius-sm); }
.feed-row:focus-visible { outline: 2px solid var(--orange); outline-offset: -2px; border-radius: var(--radius-sm); }
.feed-time { color: var(--text-3); font-family: var(--font-mono); font-size: 11px; line-height: 1.6; white-space: nowrap; }
.feed-dot { width: 6px; height: 6px; margin-top: 7px; border-radius: 50%; background: var(--text-3); }
.feed-row[data-severity="warn"] .feed-dot { background: var(--amber-2); }
.feed-row[data-severity="error"] .feed-dot { background: var(--red); }
.feed-row[data-kind="trade"] .feed-dot { background: var(--orange-2); }
.feed-row[data-kind="trade"][data-severity="warn"] .feed-dot { background: var(--amber-2); }
.feed-main { min-width: 0; }
.feed-title { font-size: 13px; overflow-wrap: anywhere; }
.feed-detail {
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.feed-pnl { font-family: var(--font-mono); font-weight: 500; font-size: 12px; white-space: nowrap; }

/* ── sức khoẻ hệ thống ───────────────────────────────────────────────────── */

.uptime-strip { display: flex; gap: 2px; align-items: stretch; padding: 14px 16px; background: var(--surface-sunk); border-radius: var(--radius-lg); }
.uptime-cell { flex: 1 1 0; min-width: 2px; height: 36px; border-radius: 3px; background: var(--green-2); }
.uptime-cell[data-state="degraded"] { background: var(--amber-2); }
.uptime-cell[data-state="down"] { background: var(--red); }
/* "Không có dữ liệu" phải nhìn ra là một trạng thái, không phải một lỗ hổng. */
.uptime-cell[data-state="no_data"] { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-strong); }
.uptime-cell:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }

.bar-legends { display: flex; flex-wrap: wrap; gap: 7px 14px; margin-top: 10px; color: var(--text-3); font-size: 11px; }
.bar-legend { display: inline-flex; align-items: center; gap: 7px; }
.bar-legend .uptime-cell { flex: none; width: 10px; height: 10px; padding: 0; border-radius: 3px; }

.count-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 10px; }
.count-cell { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; background: var(--surface-sunk); border-radius: var(--radius-sm); }
.count-value { font-family: var(--font-mono); font-size: 17px; font-weight: 500; letter-spacing: -0.02em; }
/* Tên bảng có dấu gạch dưới, không phải chỗ ngắt dòng: cho cột đủ rộng thay vì
   bẻ "equity_snapshots" làm đôi. */
.count-label { color: var(--text-3); font-size: 11px; }
.count-cell .badge { align-self: flex-start; margin-top: 3px; }

.error-card { padding: 14px 16px; background: var(--red-bg); border-radius: var(--radius-lg); }
.error-head { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-bottom: 8px; }
.error-module { color: var(--red); font-family: var(--font-mono); font-size: 12px; }
.error-time { margin-left: auto; color: var(--text-2); font-family: var(--font-mono); font-size: 11px; }
.error-message { color: var(--text-2); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }

/* ── drawer ──────────────────────────────────────────────────────────────── */

.drawer {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--text);
}
.drawer::backdrop { background: rgba(40, 38, 33, .35); }
.drawer-head { display: flex; align-items: center; gap: 14px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.drawer-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.drawer-controls { display: flex; gap: 8px; margin-left: auto; }
.drawer-head > .btn { margin-left: auto; }
.drawer-head .drawer-controls .btn { margin-left: 0; }
.drawer-body { max-height: calc(100vh - 140px); padding: 22px; overflow-y: auto; }
.drawer-loading, .drawer-error { padding: 28px 0; color: var(--text-2); text-align: center; }
.drawer-error { color: var(--red); }

.timeline { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.timeline-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 7px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.timeline-row:first-child { border-top: 0; }
.timeline-time { color: var(--text-3); font-family: var(--font-mono); font-size: 11px; white-space: nowrap; }
.timeline-what { min-width: 13ch; color: var(--text-2); font-size: 13px; }

.tags { display: flex; flex-wrap: wrap; gap: 5px 6px; }
.tag { padding: 3px 10px; background: var(--surface-muted); border-radius: var(--radius-pill); color: var(--text-2); font-family: var(--font-mono); font-size: 11px; }
.tag.up { background: var(--green-bg); color: var(--green); }
.tag.down { background: var(--red-bg); color: var(--red); }

.signal-card { padding: 16px 18px; background: var(--surface-sunk); border-radius: var(--radius-lg); }
.signal-head { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.signal-meta { color: var(--text-3); font-size: 12px; }
.signal-time { color: var(--text-3); font-family: var(--font-mono); font-size: 11px; white-space: nowrap; }
.signal-rsi { margin-left: auto; color: var(--text-2); font-family: var(--font-mono); font-size: 12px; }
/* Văn bản tự do do bot viết, tiếng Việt. */
.signal-reason { margin-top: 8px; max-width: 90ch; color: var(--text-2); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }

.signal-list { display: flex; flex-direction: column; margin: 16px 0 0; padding: 0; list-style: none; }
.signal-row { padding: 12px 10px; border-top: 1px solid var(--line); border-radius: var(--radius-sm); transition: background-color 150ms ease; }
.signal-row.is-clickable { cursor: pointer; }
.signal-row.is-clickable:hover { background: var(--surface-muted); }
.signal-row:focus-visible { outline: 2px solid var(--orange); outline-offset: -2px; }

@media (max-width: 600px) {
  body { padding: 10px; }
  .topbar { padding: 16px 18px; }
  .panel { padding: 18px 16px; }
  .figures { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .fig-value { margin-bottom: 8px; text-align: left; }
  .feed-row { grid-template-columns: auto 8px minmax(0, 1fr); }
  .feed-pnl { grid-column: 3; }
  .share-cell { min-width: 110px; }
  .uptime-strip { gap: 1px; padding: 12px; }
  .uptime-cell { min-width: 1px; }
  .position { padding: 14px 16px; }
}
