/* ═══════════════════════════════════════════════════════════════════════════
   Sổ Lệnh — hệ thiết kế dùng chung
   Bảng màu kế thừa từ bản mockup so-lenh.html ("mực in tiền").
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --paper: #ffffff;
  --recess: #f1f3f7;
  --rule: #e1e5ec;
  --rule-soft: #eef0f5;
  --ink: #141821;
  --ink-2: #3d4453;
  --muted: #666e7e;
  --faint: #98a0b0;
  --accent: #2f5fa8;
  --accent-soft: #e7edf7;
  --accent-ink: #24497f;
  --win: #0f7350;
  --win-soft: #e2f0ea;
  --loss: #b0332c;
  --loss-soft: #f7e6e4;
  --warn: #a9701a;
  --warn-soft: #f7efe0;
  --cat-1: #2f5fa8;
  --cat-2: #a9701a;
  --cat-3: #137a5c;
  --dv-n3: #b0332c;
  --dv-n2: #cf7a72;
  --dv-n1: #eccfcb;
  --dv-0: #e9ecf1;
  --dv-p1: #c9e2d7;
  --dv-p2: #5aa88a;
  --dv-p3: #0f7350;
  --shadow: 0 1px 2px rgba(20, 24, 33, .05), 0 18px 46px -14px rgba(20, 24, 33, .22);
  --shadow-lo: 0 1px 2px rgba(20, 24, 33, .05);
  --f-display: "Palatino Linotype", "Iowan Old Style", Palatino, "Book Antiqua", Georgia, serif;
  --f-ui: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, system-ui, "Helvetica Neue", sans-serif;
  --f-num: ui-monospace, "Cascadia Mono", "SF Mono", "Segoe UI Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --r: 10px;
  --r-sm: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12161d;
    --recess: #191f28;
    --rule: #262d38;
    --rule-soft: #1e242e;
    --ink: #e8ecf2;
    --ink-2: #bcc4d1;
    --muted: #8e97a8;
    --faint: #6a7382;
    --accent: #7faee8;
    --accent-soft: #1b2735;
    --accent-ink: #a9c9f2;
    --win: #3fbf95;
    --win-soft: #132a24;
    --loss: #f0847a;
    --loss-soft: #2c1b1a;
    --warn: #d6a44a;
    --warn-soft: #2b2313;
    --cat-1: #4a82c9;
    --cat-2: #b98126;
    --cat-3: #2fa37b;
    --dv-n3: #f0847a;
    --dv-n2: #a44b45;
    --dv-n1: #4a2a28;
    --dv-0: #232a35;
    --dv-p1: #1d3d34;
    --dv-p2: #2b8163;
    --dv-p3: #3fbf95;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 22px 54px -14px rgba(0, 0, 0, .7);
    --shadow-lo: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

:root[data-theme="dark"] {
  --paper: #12161d;
  --recess: #191f28;
  --rule: #262d38;
  --rule-soft: #1e242e;
  --ink: #e8ecf2;
  --ink-2: #bcc4d1;
  --muted: #8e97a8;
  --faint: #6a7382;
  --accent: #7faee8;
  --accent-soft: #1b2735;
  --accent-ink: #a9c9f2;
  --win: #3fbf95;
  --win-soft: #132a24;
  --loss: #f0847a;
  --loss-soft: #2c1b1a;
  --warn: #d6a44a;
  --warn-soft: #2b2313;
  --cat-1: #4a82c9;
  --cat-2: #b98126;
  --cat-3: #2fa37b;
  --dv-n3: #f0847a;
  --dv-n2: #a44b45;
  --dv-n1: #4a2a28;
  --dv-0: #232a35;
  --dv-p1: #1d3d34;
  --dv-p2: #2b8163;
  --dv-p3: #3fbf95;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 22px 54px -14px rgba(0, 0, 0, .7);
  --shadow-lo: 0 1px 2px rgba(0, 0, 0, .4);
}

/* ─── Reset & nền ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--recess);
  color: var(--ink);
  font-family: var(--f-ui);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--f-display); font-weight: 600; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
p { margin: 0 0 12px; }
a { color: var(--accent); text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 24px 0; }
code, .num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }

::selection { background: var(--accent-soft); color: var(--accent-ink); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ─── Bố cục ─────────────────────────────────────────────────────────────── */
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px; }
.wrap-narrow { max-width: 860px; margin: 0 auto; padding: 0 20px; }
.page { padding: 28px 0 72px; }

.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-tight { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 900px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

/* ─── Thanh điều hướng ───────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar-in { display: flex; align-items: center; gap: 18px; height: 58px; }

.brand { display: flex; align-items: baseline; gap: 9px; text-decoration: none; color: var(--ink); flex: 0 0 auto; }
.brand-mark { font-family: var(--f-display); font-size: 20px; font-weight: 600; letter-spacing: .01em; }
.brand-sub { font-size: 11px; color: var(--faint); letter-spacing: .08em; text-transform: uppercase; }

.nav { display: flex; gap: 2px; flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 7px 11px; border-radius: var(--r-sm); text-decoration: none;
  color: var(--ink-2); font-size: 14px; white-space: nowrap;
}
.nav a:hover { background: var(--recess); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

.icon-btn {
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink-2);
  border-radius: var(--r-sm); height: 32px; min-width: 32px; padding: 0 9px;
  cursor: pointer; font-family: var(--f-ui); font-size: 13px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  flex: 0 0 auto; white-space: nowrap;
}
.icon-btn:hover { background: var(--recess); color: var(--ink); }

/* ─── Khối tài khoản & đồng bộ trên thanh điều hướng ─────────────────────── */
.topbar-right { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.acct-box { display: flex; align-items: center; gap: 6px; }

.acct-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px 5px 9px; border-radius: 999px;
  background: var(--recess); border: 1px solid var(--rule);
  text-decoration: none; color: var(--ink); font-size: 13px;
  max-width: 170px; white-space: nowrap;
}
.acct-chip:hover { border-color: var(--accent); }
.acct-name { overflow: hidden; text-overflow: ellipsis; }
.acct-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--win); flex: 0 0 auto; }

.sync-chip {
  border: 1px solid var(--rule); background: var(--paper); color: var(--muted);
  border-radius: 999px; padding: 4px 11px; font-size: 12px; cursor: pointer;
  font-family: var(--f-ui); white-space: nowrap; flex: 0 0 auto;
}
.sync-chip:hover { border-color: var(--accent); color: var(--ink); }
.sync-chip.ok { color: var(--win); border-color: color-mix(in srgb, var(--win) 30%, var(--rule)); }
.sync-chip.busy { color: var(--accent); }
.sync-chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, var(--rule)); }
.sync-chip.bad { color: var(--loss); border-color: color-mix(in srgb, var(--loss) 35%, var(--rule)); }

/* Thanh trên phải co lại được, không bao giờ đẩy trang tràn ngang */
.topbar-in > * { min-width: 0; }
@media (max-width: 900px) {
  .sync-chip { display: none; }
  .brand-sub { display: none; }
}
@media (max-width: 560px) {
  /* Cần .acct-box đi kèm để thắng .btn { display: inline-flex } khai báo phía dưới.
     Ẩn nút "Đăng nhập" cho đỡ chật; vào được qua thẻ trên màn đăng ký. */
  .acct-box .acct-login { display: none; }
  .acct-chip { max-width: 96px; }
  .topbar-in { gap: 10px; }
}

/* ─── Nhãn gói ───────────────────────────────────────────────────────────── */
.plan-tag {
  font-size: 9.5px; font-weight: 700; letter-spacing: .07em;
  padding: 1px 5px; border-radius: 3px; flex: 0 0 auto;
  background: var(--rule); color: var(--muted);
}
.plan-tag.pro { background: var(--warn-soft); color: var(--warn); }

/* ─── Vùng tính năng bị khoá ─────────────────────────────────────────────── */
.locked { position: relative; }
.locked > .locked-inner {
  filter: blur(4px); opacity: .5; pointer-events: none; user-select: none;
}
.locked-veil {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center; padding: 24px;
  background: color-mix(in srgb, var(--paper) 62%, transparent);
  border-radius: var(--r);
}
.locked-veil .lk-title { font-family: var(--f-display); font-size: 17px; color: var(--ink); }
.locked-veil .lk-sub { font-size: 13px; color: var(--muted); max-width: 42ch; }

/* ─── Bảng giá ───────────────────────────────────────────────────────────── */
.price-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 700px) { .price-grid { grid-template-columns: minmax(0, 1fr); } }

.price-card {
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r);
  padding: 24px; display: flex; flex-direction: column;
}
.price-card.featured { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.price-name { font-family: var(--f-display); font-size: 19px; margin-bottom: 2px; }
.price-amt { font-family: var(--f-num); font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin: 10px 0 2px; }
.price-per { font-size: 12.5px; color: var(--faint); margin-bottom: 16px; }
.price-list { list-style: none; padding: 0; margin: 0 0 18px; font-size: 13.5px; }
.price-list li { padding: 5px 0 5px 22px; position: relative; color: var(--ink-2); }
.price-list li::before {
  content: '✓'; position: absolute; left: 0; top: 5px;
  color: var(--win); font-weight: 700; font-size: 12px;
}
.price-list li.no { color: var(--faint); }
.price-list li.no::before { content: '—'; color: var(--faint); font-weight: 400; }
.price-card .btn { margin-top: auto; }

.pay-box {
  background: var(--recess); border: 1px solid var(--rule);
  border-radius: var(--r); padding: 18px;
}
.pay-row { display: flex; justify-content: space-between; gap: 14px; padding: 7px 0; border-bottom: 1px solid var(--rule-soft); font-size: 14px; }
.pay-row:last-child { border-bottom: 0; }
.pay-row .k { color: var(--muted); }
.pay-row .v { font-family: var(--f-num); font-weight: 600; text-align: right; word-break: break-all; }

/* ─── Dải nhắc dành cho khách ────────────────────────────────────────────── */
.guestbar { background: var(--warn-soft); border-bottom: 1px solid color-mix(in srgb, var(--warn) 25%, var(--rule)); }
.guestbar-in { display: flex; align-items: center; gap: 14px; padding: 9px 0; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.guestbar strong { color: var(--ink); }

/* ─── Trang xác thực ─────────────────────────────────────────────────────── */
.auth-wrap { max-width: 460px; margin: 0 auto; padding: 44px 20px 80px; }
.auth-card { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); box-shadow: var(--shadow); padding: 28px; }
.auth-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); margin: -4px -4px 20px; }
.auth-tabs button {
  flex: 1; border: 0; background: none; padding: 11px 8px; cursor: pointer;
  font-family: var(--f-ui); font-size: 14.5px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.auth-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.auth-card .field + .field { margin-top: 14px; }
.auth-card .btn-lg { width: 100%; margin-top: 18px; }
.auth-alt { text-align: center; font-size: 13px; margin-top: 16px; color: var(--muted); }
.mode-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: var(--recess); color: var(--muted); margin-bottom: 14px;
}

/* ─── Thẻ ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--r); box-shadow: var(--shadow-lo); padding: 18px;
}
.card-lg { padding: 24px; }
.card-flush { padding: 0; overflow: hidden; }

.card-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .hint { font-size: 12px; color: var(--faint); }

.section-label {
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--faint); font-weight: 600; margin-bottom: 10px;
}

/* ─── Ô chỉ số (KPI) ─────────────────────────────────────────────────────── */
.kpi {
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r);
  padding: 14px 16px; box-shadow: var(--shadow-lo);
}
.kpi-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.kpi-value { font-family: var(--f-num); font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; }
.kpi-sub { font-size: 12px; color: var(--faint); margin-top: 2px; font-family: var(--f-num); }
.kpi.pos .kpi-value { color: var(--win); }
.kpi.neg .kpi-value { color: var(--loss); }

/* ─── Nút ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
  border-radius: var(--r-sm); padding: 8px 14px; font-size: 14px; font-family: var(--f-ui);
  cursor: pointer; text-decoration: none; line-height: 1.3; white-space: nowrap;
}
.btn:hover { background: var(--recess); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
:root[data-theme="dark"] .btn-primary, :root:not([data-theme="light"]) .btn-primary { color: #0d1119; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .btn-primary { color: #fff; } }
:root[data-theme="light"] .btn-primary { color: #fff; }

.btn-buy { background: var(--win); border-color: var(--win); color: #fff; font-weight: 600; }
.btn-buy:hover { filter: brightness(.92); background: var(--win); }
.btn-sell { background: var(--loss); border-color: var(--loss); color: #fff; font-weight: 600; }
.btn-sell:hover { filter: brightness(.92); background: var(--loss); }
.btn-lg { padding: 11px 20px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--recess); color: var(--ink); }
.btn-danger { color: var(--loss); border-color: color-mix(in srgb, var(--loss) 35%, var(--rule)); }
.btn-danger:hover { background: var(--loss-soft); }

/* ─── Form ───────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12px; color: var(--muted); font-weight: 500; }
input[type="text"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  font-family: var(--f-ui); font-size: 14px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-sm);
  padding: 7px 10px; width: 100%; min-width: 0;
}
input[type="number"], input.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { cursor: pointer; }
label.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
input[type="range"] { accent-color: var(--accent); width: 100%; cursor: pointer; }
.hint { font-size: 12px; color: var(--faint); }

/* ─── Bảng ───────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th {
  text-align: left; font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint); font-weight: 600; padding: 9px 12px;
  border-bottom: 1px solid var(--rule); background: var(--recess);
  position: sticky; top: 0; white-space: nowrap;
}
table.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--recess); }
table.tbl td.n, table.tbl th.n { text-align: right; font-family: var(--f-num); font-variant-numeric: tabular-nums; }
table.tbl tr.is-win td.pnl { color: var(--win); }
table.tbl tr.is-loss td.pnl { color: var(--loss); }
.empty { padding: 44px 20px; text-align: center; color: var(--faint); font-size: 14px; }

/* ─── Nhãn / huy hiệu ────────────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--recess); color: var(--muted);
}
.tag.buy { background: var(--win-soft); color: var(--win); }
.tag.sell { background: var(--loss-soft); color: var(--loss); }
.tag.win { background: var(--win-soft); color: var(--win); }
.tag.loss { background: var(--loss-soft); color: var(--loss); }
.tag.accent { background: var(--accent-soft); color: var(--accent-ink); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

.pos { color: var(--win); }
.neg { color: var(--loss); }

/* ─── Thông báo ──────────────────────────────────────────────────────────── */
.note {
  border: 1px solid var(--rule); border-left: 3px solid var(--accent);
  background: var(--paper); border-radius: var(--r-sm);
  padding: 12px 14px; font-size: 13.5px; color: var(--ink-2);
}
.note.warn { border-left-color: var(--warn); }
.note.danger { border-left-color: var(--loss); }
.note strong { color: var(--ink); }

#toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 90;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  background: var(--paper); border: 1px solid var(--rule); border-left: 3px solid var(--accent);
  border-radius: var(--r-sm); box-shadow: var(--shadow); padding: 10px 14px;
  font-size: 13.5px; max-width: 340px; animation: toast-in .18s ease-out;
}
.toast.win { border-left-color: var(--win); }
.toast.loss { border-left-color: var(--loss); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ─── Chân trang ─────────────────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--rule); background: var(--paper);
  padding: 28px 0; font-size: 13px; color: var(--muted); margin-top: 40px;
}
.footer-grid { display: flex; gap: 40px; flex-wrap: wrap; align-items: flex-start; }
.footer a { color: var(--ink-2); }
.disclaimer {
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--rule-soft);
  font-size: 12px; color: var(--faint); line-height: 1.6;
}

/* ─── Tiện ích ───────────────────────────────────────────────────────────── */
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.mono { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
