:root {
  color-scheme: dark;
  --bg: #0b0e13;
  --bg2: #121720;
  --bg3: #1a2130;
  --line: #263044;
  --text: #e6e9ef;
  --muted: #8e98ab;
  --accent: #3fa7ff;
  --up: #00e650;
  --down: #ff3c3c;
  --ref: #ffd700;
  --ceil: #ff00ff;
  --floor: #00e5ff;
  --sel: #22406a;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
button, input, select { font-family: inherit; font-size: 13px; }

/* ---------- Header / tabs ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  height: 44px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: .3px; white-space: nowrap; }
.brand span { color: var(--accent); }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  color: var(--muted);
  padding: 12px 12px 10px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-weight: 600;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.topbar .clock { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.topbar form { margin: 0; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.toolbar .title { font-weight: 700; font-size: 14px; margin-right: 6px; }
.toolbar .count { color: var(--muted); }
.toolbar .spacer { flex: 1 1 auto; }
input[type=text], input[type=number], input[type=search], input[type=password], select {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.btn {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: #1f6fd1; border-color: #1f6fd1; color: #fff; }
.btn.primary:hover { background: #2a7ee6; }
.btn.danger { border-color: #7a2a2a; }
.btn:disabled { opacity: .5; cursor: default; }
label.chk { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; color: var(--text); white-space: nowrap; }

/* ---------- Layout ---------- */
.main { flex: 1 1 auto; display: flex; min-height: 0; }
.pane { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.scroll { flex: 1 1 auto; overflow: auto; min-height: 0; }
.side {
  flex: 0 0 46%;
  max-width: 900px;
  min-width: 360px;
  border-left: 1px solid var(--line);
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.side.open { display: flex; }
.page { padding: 14px; overflow: auto; flex: 1 1 auto; }

/* ---------- Grid ---------- */
table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
table.grid th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg2);
  color: var(--muted);
  font-weight: 700;
  padding: 7px 6px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid #1b2232;
  text-align: center;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
table.grid th:hover { color: var(--text); }
table.grid th.sorted { color: var(--accent); }
table.grid th.sticky-col, table.grid td.sticky-col { position: sticky; left: 0; z-index: 1; }
table.grid th.sticky-col { z-index: 3; }
table.grid td {
  padding: 4px 6px;
  border-bottom: 1px solid #151b27;
  border-right: 1px solid #151b27;
  white-space: nowrap;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  background-color: var(--bg);
}
table.grid tr:hover td { background-color: #111826; }
table.grid tr.sel td { background-color: var(--sel); }
table.grid td.c { text-align: center; }
table.grid td.l { text-align: left; }
table.grid td.sym { text-align: left; font-weight: 700; }
table.grid td.star { cursor: pointer; color: #555f73; text-align: center; padding: 4px 4px; }
table.grid td.star.on { color: var(--ref); }
table.grid td.muted { color: var(--muted); font-weight: 500; }
td.bar { position: relative; text-shadow: 0 0 2px #000, 0 0 3px #000, 0 0 5px #000; }
td.t-buy { background-color: #00a028 !important; color: #fff !important; }
td.t-sell { background-color: #c81e1e !important; color: #fff !important; }
td.t-up { color: var(--up) !important; }
td.t-down { color: var(--down) !important; }
td.fibo { color: #000 !important; }
.up { color: var(--up); }
.down { color: var(--down); }
.ref { color: var(--ref); }
.ceil { color: var(--ceil); }
.floor { color: var(--floor); }
.muted { color: var(--muted); }
.ma-col.hidden { display: none; }

/* ---------- Status bar ---------- */
.statusbar {
  flex: 0 0 auto;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 5px 12px;
  background: var(--bg2);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
}
.statusbar .dot { width: 8px; height: 8px; border-radius: 50%; background: #666; display: inline-block; margin-right: 5px; }
.statusbar .dot.ok { background: #19d26a; }
.statusbar .dot.warn { background: #f0b400; }
.statusbar .dot.err { background: #ff4d4d; }
.statusbar .msg { overflow: hidden; text-overflow: ellipsis; }
.statusbar .summary { margin-left: auto; color: var(--text); }

/* ---------- Chart ---------- */
.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.chart-head .sym { font-size: 18px; font-weight: 800; }
.chart-head .name { color: var(--muted); }
.chart-head .px { font-size: 16px; font-weight: 700; }
.chart-head .rs { color: var(--accent); }
.chart-head .close { margin-left: auto; }
.chart-tools { display: flex; flex-wrap: wrap; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--line); color: var(--muted); }
.tf-group { display: inline-flex; gap: 0; }
.tf-group .btn { border-radius: 0; padding: 4px 10px; margin-left: -1px; }
.tf-group .btn:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.tf-group .btn:last-child { border-radius: 0 6px 6px 0; }
.chart-stats { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 6px 12px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.chart-stats b { color: var(--text); }
.chart-stats b.up { color: var(--up); }
.chart-stats b.down { color: var(--down); }
.chart-stats .intrade { color: var(--text); }
.chart-alerts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.chart-alerts .al-price { width: 110px; }
.chart-alerts .al-note { width: 170px; }
.chart-alerts .al-hint { font-size: 12px; }
.al-list { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.al-chip { background: #2a2210; border: 1px solid #6b5313; color: #ffd27a; border-radius: 12px; padding: 2px 9px; font-size: 12px; white-space: nowrap; }
.al-chip.done { background: transparent; border-color: var(--line); color: var(--muted); }
.al-chip a { color: inherit; cursor: pointer; margin-left: 4px; opacity: .8; }
.al-chip a:hover { opacity: 1; color: var(--down); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 4px 12px; font-size: 12px; color: var(--muted); }
.chart-legend b { font-weight: 700; }
.chart-main { flex: 3 1 0; min-height: 220px; position: relative; }
.chart-rs { flex: 1 1 0; min-height: 90px; border-top: 1px solid var(--line); position: relative; }
.chart-wrap { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.chart-empty { padding: 30px; color: var(--muted); text-align: center; }

.chart-page { display: flex; flex: 1 1 auto; min-height: 0; }
.chart-list { flex: 0 0 280px; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chart-list .toolbar { padding: 8px; }
.chart-list input { width: 100%; }

/* ---------- Cards / forms ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 12px 0; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.card .k { color: var(--muted); font-size: 12px; }
.card .v { font-size: 18px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.section { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; max-width: 1100px; }
.section h3 { margin: 0 0 10px; font-size: 15px; }
.section p.hint { color: var(--muted); margin: 6px 0 10px; line-height: 1.5; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
table.simple { border-collapse: collapse; }
table.simple td, table.simple th { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.syncmsg { color: var(--ref); margin-top: 8px; white-space: pre-wrap; }
.equity { height: 260px; border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 14px; bottom: 40px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { white-space: pre-line; background: #10233d; border: 1px solid var(--accent); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px #0008; max-width: 340px; }
.toast.buy { border-color: var(--up); }
.toast.sell { border-color: var(--down); }

/* ---------- Login ---------- */
.login { margin: auto; width: min(360px, 92vw); background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.login h1 { font-size: 20px; margin: 0 0 16px; }
.login label { display: block; color: var(--muted); margin: 10px 0 4px; }
.login input { width: 100%; }
.login .err { color: var(--down); margin-top: 10px; }
.login .btn { width: 100%; margin-top: 16px; padding: 9px; }

@media (max-width: 900px) {
  .side.open { position: fixed; inset: 44px 0 26px 0; max-width: none; min-width: 0; z-index: 20; }
  .chart-list { flex-basis: 150px; }
  .topbar .clock { display: none; }
}

/* ---------- Hộp thoại chọn ---------- */
dialog.picker { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--bg2); color: var(--text); width: min(560px, 94vw); }
dialog.picker::backdrop { background: rgba(0, 0, 0, .6); }
.picker-box { display: flex; flex-direction: column; gap: 10px; padding: 16px; max-height: 80vh; margin: 0; }
.picker-box h3 { margin: 0; font-size: 16px; }
.picker-box .hint { margin: 0; color: var(--muted); line-height: 1.5; }
.picker-list { overflow: auto; min-height: 120px; max-height: 50vh; border: 1px solid var(--line); border-radius: 8px; }
.picker-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid #1b2232; cursor: pointer; }
.picker-item:hover { background: var(--bg3); }
.picker-item .pi-name { font-weight: 600; }
.picker-item .pi-id { color: var(--muted); font-size: 12px; margin-left: auto; font-family: Consolas, monospace; }
.picker-item.disabled { opacity: .45; cursor: not-allowed; }
.picker-empty { padding: 20px; text-align: center; color: var(--muted); }
.picker-foot { display: flex; align-items: center; gap: 8px; }
.picker-foot .spacer { flex: 1 1 auto; }

/* Câu miễn trừ trách nhiệm */
.disclaimer { color: #c9a227; font-size: 11px; white-space: nowrap; }
.chart-stats .disclaimer { white-space: normal; flex-basis: 100%; }
.login .disclaimer { white-space: normal; margin-top: 14px; text-align: center; }
@media (max-width: 900px) { .statusbar .disclaimer { white-space: normal; } }

/* Nhật ký truy cập */
.al-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.al-summary .chip { border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; font-size: 12px; color: var(--muted); cursor: pointer; }
.al-summary .chip b { color: var(--text); font-size: 13px; }
.al-summary .chip.warn { border-color: #b8860b; }
.al-summary .chip.warn b { color: #f0b400; }
.al-summary .chip.bad { border-color: var(--down); }
.al-summary .chip.bad b { color: var(--down); }
.al-table td { white-space: nowrap; font-size: 12px; }
.al-table td.path { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.al-table td.detail { white-space: normal; max-width: 320px; }
.al-table tr.ev-LOGIN_FAIL td:nth-child(2) { color: #f0b400; }
.al-table tr.ev-LOGIN_BLOCKED td:nth-child(2) { color: var(--down); font-weight: 600; }
.al-table tr.ev-LOGIN_OK td:nth-child(2) { color: var(--up); }
