/* ============================================================
   Trade Discipline Hub - Design system dùng chung cho toàn bộ Web UI
   Theme: dark, hiện đại, chuyên nghiệp (phong cách bảng điều khiển tài chính)
   ============================================================ */

:root {
  --bg: #0a0e17;
  --bg-soft: #0d1220;
  --panel: #131a2b;
  --panel-2: #1a2338;
  --panel-3: #212c46;
  --border: #26314a;
  --border-soft: #1d263c;
  --text: #eef1f8;
  --muted: #8993ab;
  --muted-2: #626d87;

  --accent: #4f7cff;
  --accent-2: #7c5cff;
  --accent-soft: rgba(79, 124, 255, 0.14);

  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.14);
  --red: #f43f5e;
  --red-soft: rgba(244, 63, 94, 0.14);
  --yellow: #f5a524;
  --yellow-soft: rgba(245, 165, 36, 0.14);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);

  font-size: 15px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(79, 124, 255, 0.10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(124, 92, 255, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }

::selection { background: var(--accent); color: #fff; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 999px; }

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: rgba(19, 26, 43, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.topbar .brand .brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 17px;
  box-shadow: 0 4px 14px rgba(79, 124, 255, 0.35);
  flex: none;
}
.topbar .brand .brand-sub {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.3px;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  overflow-x: auto;
}

.topbar nav a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 999px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.topbar nav a i { font-size: 15px; }
.topbar nav a:hover { color: var(--text); background: var(--panel-2); }
.topbar nav a.active { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

.topbar .right { display: flex; align-items: center; gap: 12px; flex: none; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.user-chip .avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  text-transform: uppercase;
}
.user-chip span[data-tdh-username] { font-size: 13px; font-weight: 600; color: var(--text); }

/* ---------------- Layout ---------------- */
.container { padding: 24px; max-width: 1240px; margin: 0 auto; }
/* Bien the rong hon cho cac trang bang co nhieu cot (VD positions.html sau khi bo sung Entry/SL/
   RR ky vong) - chi ap dung RIENG cho trang can, khong doi max-width mac dinh dung chung toan bo
   Web UI. Dung class phu tren cung 1 the <div class="container"> (VD class="container container-wide"). */
.container-wide { max-width: 1640px; }

.page-header { margin-bottom: 18px; }
.page-header h1 {
  font-size: 21px; margin: 0 0 4px; font-weight: 800;
  display: flex; align-items: center; gap: 10px;
}
.page-header h1 i { color: var(--accent); }
.page-header p { margin: 0; color: var(--muted); font-size: 13.5px; }

/* ---------------- Card ---------------- */
.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel) 100%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.card h2 {
  margin: 0 0 14px;
  font-size: 15.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 9px;
}
.card h2 i { color: var(--accent); font-size: 16px; }

/* ---------------- Table ---------------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--border-soft); text-align: left; }
th {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.4px;
}
tbody tr { transition: background 0.12s ease; }
tbody tr:hover td { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }

/* ---------------- Badge / pill ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.buy { background: var(--green-soft); color: var(--green); }
.badge.sell { background: var(--red-soft); color: var(--red); }
.badge.pending { background: var(--yellow-soft); color: var(--yellow); }
.badge.open { background: var(--accent-soft); color: var(--accent); }
.badge.on { background: var(--green-soft); color: var(--green); }
.badge.off { background: rgba(137, 147, 171, 0.16); color: var(--muted); }
.badge.danger { background: var(--red-soft); color: var(--red); }

/* ---------------- "Vung nguy hiem" - thao tac pha huy/khong the hoan tac (system-settings.html) ---------------- */
.card-danger { border: 1px solid var(--red); background: var(--red-soft); }
.card-danger h2 { color: var(--red); }

.pnl-pos { color: var(--green); font-weight: 700; }
.pnl-neg { color: var(--red); font-weight: 700; }

/* ---------------- Forms ---------------- */
label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 80px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted-2); }

/* ---------------- Buttons ---------------- */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  box-shadow: 0 4px 14px rgba(79, 124, 255, 0.25);
  transition: filter 0.15s ease, transform 0.05s ease;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button.secondary {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: none;
}
button.danger { background: linear-gradient(135deg, var(--red), #d1264a); box-shadow: 0 4px 14px rgba(244, 63, 94, 0.25); }
button:disabled { opacity: 0.4; cursor: not-allowed; filter: none; box-shadow: none; }
button.small { padding: 6px 12px; font-size: 12.5px; }
button.block { width: 100%; }

/* ---------------- Dropdown (nut mo menu con) ---------------- */
/* Dung khi co NHIEU hanh dong lien quan can gom lai duoi 1 nut de do roi (VD "Chot lenh con" thay
   vi 3 nut rieng TP1/TP2/TP3) - toggle bang JS (them/bo class "open" tren .dropdown-menu), dong lai
   khi bam ra ngoai. Khong dung <select>/form nao ca de khong xung dot voi cac form khac tren trang. */
.dropdown { position: relative; display: inline-flex; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 190px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 40;
}
.dropdown-menu.open { display: block; }
.dropdown-menu button {
  display: flex;
  width: 100%;
  background: none;
  box-shadow: none;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  justify-content: flex-start;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.dropdown-menu button:hover { background: var(--panel-3); filter: none; }
.dropdown-menu button:disabled { opacity: 0.4; }

/* ---------------- Grid helpers ---------------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }

@media (max-width: 760px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  /* .topbar flex-wrap duoc xu ly rieng, chinh xac hon o breakpoint 860px (xem section "Mobile /
     PWA" cuoi file - .topbar chuyen sang flex-wrap:nowrap + menu dang hamburger xo xuong). */
}

/* ---------------- Checkbox list (multi-select) ---------------- */
.checkbox-list { display: flex; flex-wrap: wrap; gap: 10px; }
.checkbox-list label {
  display: flex; align-items: center; gap: 7px;
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px;
  font-weight: 500; color: var(--text);
  margin-bottom: 0;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.checkbox-list label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.checkbox-list input { width: auto; margin: 0; accent-color: var(--accent); }

/* ---------------- Checklist gom nhom theo Section (new-signal.html) ---------------- */
.checklist-group { margin-bottom: 12px; }
.checklist-group:last-child { margin-bottom: 0; }
.checklist-group-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); margin-bottom: 6px;
}

/* ---------------- Nhat ky giao dich: checklist da tick + anh phan tich (history.html) ---------------- */
.checklist-answer-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.chart-image-row { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.chart-image-block { flex: 1 1 220px; min-width: 180px; }
.chart-image-label { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.chart-image-thumb {
  display: block; max-width: 100%; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--panel-2);
}

/* ---------------- Vung dan/keo-tha anh phan tich (new-signal.html) ---------------- */
.paste-zone {
  margin-top: 6px; border: 1.5px dashed var(--border); border-radius: var(--radius-sm);
  background: var(--panel-2); padding: 16px 12px; text-align: center; cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease; outline: none;
}
.paste-zone:hover, .paste-zone:focus { border-color: var(--accent); background: var(--accent-soft); }
.paste-zone.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.paste-zone-icon { font-size: 22px; color: var(--muted); }
.paste-zone-text { font-size: 12px; color: var(--muted); margin-top: 6px; }
.paste-zone-thumb { display: block; max-width: 100%; max-height: 110px; margin: 0 auto; border-radius: var(--radius-sm); }
.paste-zone-replace { font-size: 11px; color: var(--accent); margin-top: 6px; }

/* ---------------- Ghi chu phan tu sau khi dong lenh (history.html) ---------------- */
.journal-block { font-size: 13px; }
.journal-edit-form textarea { margin-top: 0; }
.journal-edit-form label { margin-bottom: 0; font-size: 12px; }

/* ---------------- Text helpers ---------------- */
.muted { color: var(--muted); font-size: 13px; }
.error {
  color: var(--red);
  font-size: 13px;
  display: flex; align-items: center; gap: 6px;
}
.success {
  color: var(--green);
  font-size: 13px;
  display: flex; align-items: center; gap: 6px;
}

/* ---------------- Auth / Login page ---------------- */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 380px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-card .brand-icon-lg {
  width: 56px; height: 56px; margin: 0 auto 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  box-shadow: 0 8px 22px rgba(79, 124, 255, 0.35);
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; font-weight: 800; }
.auth-card .muted { margin-bottom: 22px; }
.auth-card label { text-align: left; }
.auth-card .field-icon { position: relative; }
.auth-card .field-icon i {
  position: absolute; left: 12px; top: 50%; transform: translateY(calc(-50% + 3px));
  color: var(--muted-2); font-size: 15px;
}
.auth-card .field-icon input { padding-left: 36px; }

/* ---------------- KPI cards ---------------- */
.kpi { display: flex; gap: 16px; flex-wrap: wrap; }
.kpi .box {
  flex: 1; min-width: 160px;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex; align-items: center; gap: 14px;
}
.kpi .box .icon {
  width: 40px; height: 40px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex: none;
  background: var(--accent-soft); color: var(--accent);
}
.kpi .box .value { font-size: 21px; font-weight: 800; line-height: 1.15; }
.kpi .box .label { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---------------- Live refresh indicator ---------------- */
.live-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: live-pulse 1.6s infinite;
  flex: none;
}
.live-dot.error { background: var(--red); box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.6); animation: live-pulse-red 1.6s infinite; }
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
@keyframes live-pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.55); }
  70% { box-shadow: 0 0 0 6px rgba(244, 63, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0); }
}

/* ---------------- Account overview cards (dashboard) ---------------- */
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.account-card {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.account-card:hover { border-color: var(--accent); }
.account-card .acc-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.account-card .acc-name {
  font-weight: 700; font-size: 14.5px;
  display: flex; align-items: center; gap: 7px;
}
.account-card .acc-name i { color: var(--accent); }
.account-card .acc-equity { font-size: 22px; font-weight: 800; }
.account-card .acc-balance { font-size: 15px; font-weight: 700; color: var(--muted); }
.account-card .acc-equity-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.account-card .acc-balance-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; }
.account-card .acc-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding-top: 8px; border-top: 1px solid var(--border-soft);
}
.account-card .acc-stat .v { font-size: 14px; font-weight: 700; }
.account-card .acc-stat .l { font-size: 11px; color: var(--muted); }
.account-card .acc-actions { margin-top: 2px; }

/* Badge theo tung Y TUONG (Signal) dang co leg con mo - thay the con so gop "X dang mo" cu (gay
   hieu lam la X lenh rieng biet trong khi thuc chat la X leg con cua vai y tuong) - xem
   AccountIdeaSummaryDto. Mau nen theo huong (buy/sell, dung lai --green/--red co san). Cham xanh
   nhap nhay (tai su dung .live-dot) = dang chay THAT (da khop, co vi the that); bieu tuong dong ho
   cat = con dang cho khop lenh (Limit/Stop chua cham gia).*/
.idea-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.idea-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700;
}
.idea-badge.buy { background: var(--green-soft); color: var(--green); }
.idea-badge.sell { background: var(--red-soft); color: var(--red); }
.idea-badge .idea-count { opacity: 0.7; font-weight: 600; margin-left: 1px; }
.idea-badge .idea-waiting-icon { color: var(--yellow); font-size: 10px; }

/* Bieu do mini bien dong Equity trong ngay cho 1 tai khoan (giong bieu do FTMO) - dat ngay duoi
   Equity/Balance de nguoi dung thay ngay xu huong trong ngay ma khong can mo trang rieng. */
.account-card .mini-chart { width: 100%; height: 46px; display: block; }
.account-card .mini-chart-empty {
  font-size: 11px; color: var(--muted); height: 46px;
  display: flex; align-items: center; justify-content: center;
}
.account-card .acc-actions button { width: 100%; }

/* ---------------- Modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(5, 8, 15, 0.6);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 200;
}
.modal-dialog {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
  flex: none;
}
.modal-header h3 {
  margin: 0; font-size: 16px; font-weight: 800;
  display: flex; align-items: center; gap: 9px;
}
.modal-header h3 i { color: var(--accent); }
.modal-close {
  background: var(--panel-2); border: 1px solid var(--border);
  width: 30px; height: 30px; border-radius: 8px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: none; color: var(--muted); font-size: 14px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px 20px; overflow-y: auto; }

@media (max-width: 560px) {
  .account-grid { grid-template-columns: 1fr; }
}

/* ---------------- Empty / loading state ---------------- */
.empty-state {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 18px; color: var(--muted); font-size: 13.5px;
}
.empty-state i { font-size: 16px; }

/* ---------------- Bảng tổng quan có thể bấm mở rộng (Lịch sử ý tưởng) ---------------- */
tr.row-clickable { cursor: pointer; }
tr.row-clickable:hover td { background: var(--panel-2); }
.toggle-icon { color: var(--muted); transition: transform 0.15s ease; font-size: 12px; }
tr.detail-row td {
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
}
tr.detail-row:hover td { background: var(--bg-soft); }
.detail-body { display: flex; flex-direction: column; gap: 14px; }

.detail-account-block {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.detail-account-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 10px; font-size: 13.5px;
}
.detail-legs-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.detail-legs-table th, .detail-legs-table td { padding: 8px 10px; border-bottom: 1px solid var(--border-soft); text-align: left; }
.detail-legs-table th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.3px; }
.detail-legs-table tbody tr:last-child td { border-bottom: none; }

/* ---------------- Lịch sử xử lý (SignalEventLog timeline) trong trang Lịch sử ---------------- */
.timeline-panel {
  background: var(--panel); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 10px 14px;
}
.timeline-panel summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted);
  list-style: none; display: flex; align-items: center; gap: 6px;
}
.timeline-panel summary::-webkit-details-marker { display: none; }
.timeline-panel[open] summary { margin-bottom: 10px; color: var(--text); }
.timeline-list { display: flex; flex-direction: column; gap: 8px; }
.timeline-item {
  display: flex; gap: 10px; align-items: flex-start; font-size: 12.5px;
  padding: 8px 0; border-bottom: 1px solid var(--border-soft);
}
.timeline-item:last-child { border-bottom: none; padding-bottom: 0; }
.timeline-item i { font-size: 14px; margin-top: 1px; flex: none; color: var(--accent); }
.timeline-body { flex: 1; line-height: 1.4; }
.timeline-detail { font-size: 11.5px; margin-top: 2px; }
.timeline-time { font-size: 11px; color: var(--muted-2); white-space: nowrap; }

/* Cot "Trạng thái" tren positions.html - bam de mo popup lich su (xem openTimelineModal) */
.status-cell-clickable {
  cursor: pointer; border-radius: var(--radius-sm); padding: 2px 4px; margin: -2px -4px;
  transition: background 0.15s;
}
.status-cell-clickable:hover { background: var(--panel-hover, rgba(137, 147, 171, 0.1)); }

/* ---------------- Toast: xác nhận kết quả hành động (EA đã xử lý xong hay chưa) ---------------- */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 1000;
  display: flex; flex-direction: column; gap: 10px;
  max-width: 380px;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 12px 14px; font-size: 13.5px; color: var(--text);
  animation: toast-in 0.18s ease;
}
.toast-out { animation: toast-out 0.2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(-4px); } }
.toast i:first-child { font-size: 17px; margin-top: 1px; flex-shrink: 0; }
.toast-success i:first-child { color: var(--green); }
.toast-error i:first-child { color: var(--red); }
.toast-warning i:first-child { color: var(--yellow); }
.toast-info i:first-child { color: var(--accent); }
.toast-msg { flex: 1; line-height: 1.45; }
.toast-close {
  background: none; border: none; box-shadow: none; padding: 0; margin: 0;
  color: var(--muted); font-size: 14px; flex-shrink: 0; width: auto; height: auto;
}
.toast-close:hover { color: var(--text); }
@media (max-width: 560px) {
  .toast-container { left: 12px; right: 12px; max-width: none; }
}

/* ---------------- Panel "Tình trạng an toàn hệ thống" (Lớp 6, Dashboard) ---------------- */
.safety-summary-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.safety-summary-row .box { flex: 1; min-width: 150px; }

.safety-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.safety-card {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.safety-card.locked { border-color: var(--red); }
.safety-card .sf-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.safety-card .sf-name { font-weight: 700; font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
.safety-card .sf-lock-reason { font-size: 12px; color: var(--red); line-height: 1.4; }

.progress-bar {
  width: 100%; height: 7px; border-radius: 999px;
  background: rgba(137, 147, 171, 0.16);
  overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 999px; background: var(--green); transition: width 0.2s ease; }
.progress-fill.warn { background: var(--yellow); }
.progress-fill.danger { background: var(--red); }
.progress-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 2px; }

.alert-feed { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; }
.alert-item {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 12.5px;
}
.alert-item i { font-size: 15px; margin-top: 1px; flex: none; }
.alert-item.sev-critical { border-color: rgba(244, 63, 94, 0.4); }
.alert-item.sev-critical i { color: var(--red); }
.alert-item.sev-warning i { color: var(--yellow); }
.alert-item.sev-info i { color: var(--accent); }
.alert-item .alert-body { flex: 1; line-height: 1.45; }
.alert-item .alert-body b { color: var(--text); }
.alert-item .alert-time { font-size: 11px; color: var(--muted-2); white-space: nowrap; }

/* Bo loc + nhan phan loai thong bao (System/Account/TradeIdea/Motivation - xem AlertCategory) */
.alert-filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 12px; }
.alert-filter-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--panel-2); border: 1px solid var(--border-soft); color: var(--muted);
  border-radius: 999px; padding: 5px 12px; font-size: 12px; cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.alert-filter-chip:hover { color: var(--text); border-color: var(--border); }
.alert-filter-chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.alert-category-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--border-soft); color: var(--muted);
  border-radius: 6px; padding: 1px 7px; font-size: 10.5px; margin-right: 6px;
  vertical-align: middle;
}

/* ---------------- Vào lệnh mới: chọn nhanh cặp ưa thích ---------------- */
.fav-symbol-btn { min-width: 120px; justify-content: center; }
.fav-symbol-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---------------- Vào lệnh mới: danh sách tài khoản đích kèm trạng thái ---------------- */
.checkbox-list label.account-pick-item {
  align-items: flex-start;
  flex-direction: column;
  gap: 6px;
  min-width: 230px;
}
.account-pick-item .acc-pick-top { display: flex; align-items: center; gap: 7px; width: 100%; }
.account-pick-item .acc-pick-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-left: 22px; }

/* ============================================================
   Mobile / PWA — menu điều hướng dạng hamburger, bảng dạng thẻ, modal full-screen,
   safe-area cho notch/thanh cử chỉ, cỡ chạm tối thiểu cho ngón tay.
   ============================================================ */

/* ---------------- Nút hamburger mở menu điều hướng (chỉ hiện khi màn hẹp) ---------------- */
.nav-toggle {
  display: none;
  width: 38px; height: 38px; padding: 0; flex: none;
  align-items: center; justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  box-shadow: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 18px;
}
.nav-toggle:hover { filter: none; background: var(--panel-3); }
.nav-toggle i { transition: transform 0.15s ease; }
.nav-toggle.open i { transform: rotate(90deg); }

@media (max-width: 860px) {
  .topbar { position: relative; flex-wrap: nowrap; }
  .nav-toggle { display: inline-flex; }
  /* nav duoc dieu khien bang JS them/bo class "nav-open" (xem guard.js) - mac dinh an, mo thanh 1
     bang xo xuong duoi topbar, xep doc cho de bam bang ngon tay. */
  .topbar nav {
    display: none;
    position: absolute;
    top: calc(100% + 1px);
    left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    background: var(--panel);
    border-bottom: 1px solid var(--border-soft);
    box-shadow: var(--shadow);
    padding: 8px 12px 12px;
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    z-index: 60;
  }
  .topbar nav.nav-open { display: flex; }
  .topbar nav a { width: 100%; padding: 11px 13px; }
  .topbar .brand span:not(.brand-icon) { overflow: hidden; text-overflow: ellipsis; }
  .topbar .brand .brand-sub { display: none; }
  .user-chip span[data-tdh-username] { display: none; }
}

/* ---------------- Cỡ chạm tối thiểu cho ngón tay + container gọn hơn trên điện thoại ---------------- */
@media (max-width: 640px) {
  :root { font-size: 14px; }
  .container, .container-wide { padding: 14px; }
  .card { padding: 15px; margin-bottom: 14px; }
  .page-header h1 { font-size: 18px; }
  button { min-height: 40px; }
  button.small { min-height: 34px; }
  .nav-toggle, .modal-close { min-height: 0; }
  input, select, textarea { font-size: 16px; } /* >=16px de Safari iOS khong tu zoom khi focus */
}

/* ---------------- Modal: full-screen dạng bottom-sheet trên điện thoại ---------------- */
@media (max-width: 640px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-dialog {
    max-width: 100%;
    width: 100%;
    max-height: 88vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
}

/* ---------------- Bảng cuộn ngang (dùng cho trang Admin - giữ nguyên cấu trúc bảng) ---------------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 640px; }

/* ---------------- Bảng dạng thẻ trên điện thoại (dùng data-label trên từng <td>) ----------------
   Ap dung cho cac bang nhieu cot o trang dung hang ngay tren dien thoai (Vi the dang mo/Lich su/
   Xem truoc gia) - KHONG can viet lai ham renderXxx() bang JS, chi can moi <td> co san thuoc tinh
   data-label="Ten cot" (xem positions.html/history.html/new-signal.html). Duoi nguong, tung <tr>
   tro thanh 1 "the" rieng, tung <td> xep doc voi nhan nho o tren gia tri. */
@media (max-width: 700px) {
  table.table-responsive-cards thead { display: none; }
  table.table-responsive-cards, table.table-responsive-cards tbody { display: block; width: 100%; }
  table.table-responsive-cards tr {
    display: block;
    background: var(--panel-2);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 4px 12px;
    margin-bottom: 10px;
  }
  table.table-responsive-cards tr:last-child { margin-bottom: 0; }
  table.table-responsive-cards tr.detail-row { background: none; border: none; padding: 0; margin: 0; }
  table.table-responsive-cards td {
    display: block;
    padding: 7px 0;
    border-bottom: 1px dashed var(--border-soft);
    text-align: left;
  }
  table.table-responsive-cards tr:last-child td:last-child,
  table.table-responsive-cards td:last-child { border-bottom: none; }
  table.table-responsive-cards td::before {
    content: attr(data-label);
    display: block;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--muted);
    margin-bottom: 3px;
  }
  table.table-responsive-cards td[data-label=""]::before,
  table.table-responsive-cards td:not([data-label])::before { display: none; }
  table.table-responsive-cards td[data-label=""] { padding-top: 2px; }
  /* Dong "detail-row" (khung mo rong chi tiet, colspan het bang) khong phai 1 the rieng - bo vien/
     nen the vao chinh no, chi de noi dung ben trong (detail-body voi cac detail-account-block rieng)
     tu quyet dinh giao dien. */
  table.table-responsive-cards tr.detail-row td { padding: 0; border-bottom: none; }
}

/* ---------------- Safe-area cho PWA standalone (notch / thanh cử chỉ điện thoại) ---------------- */
@supports (padding: max(0px)) {
  .topbar {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    padding-top: max(12px, env(safe-area-inset-top));
  }
  body { padding-bottom: env(safe-area-inset-bottom); }
  .toast-container {
    bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px));
  }
}
