:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1c2230;
  --line: #2a3140;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --gold: #e8b64c;
  --accent: #4d9de0;
  --radius: 6px;
  --sidebar-w: 340px;
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
  overflow: hidden;
}

.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- thanh trên cùng ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand strong { letter-spacing: .08em; font-size: 13px; }
.brand-sub { color: var(--text-dim); font-size: 11px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px var(--gold);
}

.ctrl-group { display: flex; gap: 3px; }
.ctrl-inline { display: flex; align-items: center; gap: 5px; color: var(--text-dim); font-size: 11px; }

.btn {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #3d4757; background: #232b3a; }
.btn.active { background: var(--accent); border-color: var(--accent); color: #08121c; font-weight: 600; }
.btn-primary { background: var(--gold); border-color: var(--gold); color: #241c05; font-weight: 600; }
.btn-primary:hover { background: #f0c463; }
.btn-sm { padding: 3px 8px; font-size: 11px; }
.btn-danger:hover { border-color: #e15554; color: #ff8b8a; }

.badge {
  display: inline-block;
  min-width: 16px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #08121c;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

.select {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 6px;
  font: inherit;
  font-size: 12px;
}
.select-sm { font-size: 11px; padding: 2px 4px; }

/* ---------- bảng chọn chỉ báo ---------- */

.popover {
  position: absolute;
  z-index: 60;
  top: 46px;
  left: 50%;
  transform: translateX(-50%);
  width: min(760px, 94vw);
  max-height: 70vh;
  overflow: auto;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
  padding: 12px 14px;
}
.pop-group { margin-bottom: 12px; }
.pop-group h4 {
  margin: 0 0 6px;
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
}
.pop-items { display: flex; flex-wrap: wrap; gap: 5px; }

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-3);
  cursor: pointer;
  font-size: 12px;
  user-select: none;
}
.chip:hover { border-color: #4a5568; }
.chip.on { border-color: currentColor; background: rgba(255,255,255,.06); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.chip .nm { color: var(--text); }
.chip.locked { opacity: .55; cursor: not-allowed; }

/* ---------- dải giá trị tại con trỏ ---------- */

.readout {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 14px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
  min-height: 32px;
  overflow-x: auto;
  white-space: nowrap;
}
.readout-date { color: var(--gold); font-weight: 700; letter-spacing: .04em; }
.readout-items { display: flex; gap: 14px; }
.ri { display: flex; align-items: baseline; gap: 5px; }
.ri-name { color: var(--text-dim); font-size: 11px; }
.ri-val { font-weight: 600; }
.ri-chg { font-size: 11px; }
.up { color: #3fb950; }
.down { color: #f85149; }

/* ---------- vùng làm việc ---------- */

.workspace { display: flex; height: calc(100vh - 32px - 47px); }
.chart-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.chk { display: flex; align-items: center; gap: 4px; color: var(--text-dim); font-size: 11px; cursor: pointer; }

.chart-wrap { position: relative; flex: 1; min-height: 0; }
#chart { position: absolute; inset: 0; }
/* Lớp phủ phải nằm trên canvas của thư viện biểu đồ, nếu không sẽ bị vẽ đè mất. */
.overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }

.zone-band {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(77,157,224,.10);
  border-left: 1px solid rgba(77,157,224,.55);
  border-right: 1px solid rgba(77,157,224,.55);
}
.event-line {
  position: absolute;
  top: 0; bottom: 0;
  width: 0;
  border-left: 1px dashed;
  opacity: .5;
}
.event-flag {
  position: absolute;
  top: 2px;
  transform: translateX(-50%);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  color: #08121c;
  pointer-events: auto;
  cursor: help;
  white-space: nowrap;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-line {
  position: absolute;
  border-top: 1px dashed rgba(232,182,76,.7);
  transform-origin: 0 0;
}

/* ---------- thanh bên ---------- */

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  border-left: 1px solid var(--line);
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  padding: 9px 4px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }

.tab-body { display: none; flex-direction: column; min-height: 0; flex: 1; }
.tab-body.active { display: flex; }

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text-dim);
  font-size: 11px;
  border-bottom: 1px solid var(--line);
}

.list { flex: 1; overflow-y: auto; padding: 8px; }
.empty { color: var(--text-dim); text-align: center; padding: 28px 12px; font-size: 12px; font-style: italic; }

.card {
  border: 1px solid var(--line);
  border-left: 3px solid var(--text-dim);
  border-radius: var(--radius);
  background: var(--bg-3);
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
}
.card:hover { border-color: #465166; background: #232b3a; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.card-title { font-size: 12px; font-weight: 600; }
.card-date { font-family: var(--mono); font-size: 10px; color: var(--text-dim); }
.card-meta { margin-top: 3px; font-size: 11px; color: var(--text-dim); }
.card-note { margin-top: 4px; font-size: 11px; color: var(--text); opacity: .85; }
.card-actions { margin-top: 6px; display: flex; gap: 5px; }
.tagpill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  color: #08121c;
}
.lag { font-family: var(--mono); }

/* ---------- biểu mẫu ---------- */

.form { padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg-3); }
.form h4 { margin: 0 0 8px; font-size: 12px; color: var(--gold); }
.form-row { margin-bottom: 8px; }
.form-row label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); margin-bottom: 3px; }
.form input[type=text], .form input[type=date], .form textarea, .form select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 7px;
  font: inherit;
  font-size: 12px;
}
.form textarea { resize: vertical; }
.form-actions { display: flex; gap: 6px; margin-top: 4px; }
.rel-opts { display: flex; flex-wrap: wrap; gap: 4px; }
.rel-opt {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
  font-size: 11px;
}
.rel-opt.on { color: #08121c; font-weight: 700; }

/* ---------- thanh trượt ngưỡng đảo chiều ---------- */

.nguong-box {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-3);
}
.nguong-hang {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}
.nguong-hang label { font-size: 11px; color: var(--text-dim); }
.nguong-so { font-family: var(--mono); font-size: 15px; font-weight: 700; color: var(--gold); }

#nguongSlider {
  width: 100%;
  margin: 0;
  accent-color: var(--gold);
  cursor: pointer;
}
.nguong-thang {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 9px;
  color: var(--text-dim);
}
.nguong-ket-qua {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px dashed var(--line);
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
}
.nguong-ket-qua b { color: var(--text); font-family: var(--mono); }

.goi-y-moi { color: var(--gold); }

/* ---------- bảng thống kê ---------- */

.canh-bao {
  border: 1px solid #6b4a1f;
  border-left: 3px solid var(--gold);
  background: rgba(232, 182, 76, .07);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
}
.canh-bao b { color: var(--gold); }

.stat-hang {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 5px;
  font-size: 12px;
}
.stat-nhan {
  flex: none;
  width: 66px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-dim);
}
.stat-phu { color: var(--text-dim); font-size: 11px; }

.stat-ket {
  margin-top: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .025);
}
.stat-canh-bao {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px dashed var(--line);
  color: #f0b429;
  font-size: 11px;
}


.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius);
  z-index: 90;
  box-shadow: 0 8px 26px rgba(0,0,0,.55);
  font-size: 12px;
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #313b4d; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3f4b60; }

@media (max-width: 1100px) {
  .workspace { flex-direction: column; height: auto; }
  .sidebar { width: 100%; height: 340px; border-left: none; border-top: 1px solid var(--line); }
  .chart-area { height: 60vh; }
}

/* ---- tab Mô phỏng ----
   Ô nhập từng ăn theo CSS của tab "Yêu cầu"; tab đó bị gỡ nên textarea rơi về
   kiểu mặc định của trình duyệt (nền trắng, chữ đen) — chọi hẳn với giao diện
   tối. Khai báo riêng ở đây để không phụ thuộc vào tab khác nữa. */
.sim-form { padding: 8px 10px; }
.sim-label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 5px; }
.sim-form textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 92px;
  resize: vertical;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 9px;
  font: inherit;
  font-size: 12px;
  line-height: 1.5;
}
.sim-form textarea:focus { outline: none; border-color: var(--accent); }
.sim-chitiet {
  margin-top: 6px;
  padding: 7px 9px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 11px;
  line-height: 1.55;
}
.sim-chitiet b { color: var(--text); }
.sim-chitiet .khoi { margin-bottom: 6px; }
.sim-chitiet .the {
  display: inline-block; margin: 2px 3px 0 0; padding: 1px 6px;
  background: #22314a; border-radius: 9px; font-size: 10px; color: #9fc6f5;
}

/* ---- khung MiroFish nhúng toàn màn hình ----
   Wizard 5 bước của MiroFish cần nhiều chỗ; sidebar 260px không chứa nổi nên
   mở đè lên toàn trang, giữ được ngữ cảnh mà không phải rời vang.svnagentic.site. */
.sim-frame-wrap {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column;
  background: var(--bg-1);
}
.sim-frame-wrap.hidden { display: none; }
.sim-frame-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.sim-frame-bar .spacer { flex: 1; }
#simFrame { flex: 1; width: 100%; border: 0; background: #fff; }
