/* TQTK Bot Web — trang người dùng + trang quản trị. Không có style nội tuyến (CSP style-src 'self'). */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --line: #e3e6ea;
  --text: #1d2330;
  --muted: #667085;
  --accent: #1f5fbf;
  --accent-soft: #e6eefb;
  --ok: #1a7f4b;
  --ok-soft: #e3f4ea;
  --warn: #9a6200;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --pro: #7a3cc3;
  --pro-soft: #f1e9fb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c; --panel: #1a1f29; --panel-2: #202633; --line: #2c3442; --text: #e6e9ef; --muted: #98a2b3;
    --accent: #6ea2f5; --accent-soft: #1d2b44; --ok: #4cc38a; --ok-soft: #173326; --warn: #f0b44c; --warn-soft: #3a2c13;
    --bad: #f97066; --bad-soft: #3d1c1a; --pro: #b98cf0; --pro-soft: #2d2140; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151c; --panel: #1a1f29; --panel-2: #202633; --line: #2c3442; --text: #e6e9ef; --muted: #98a2b3;
  --accent: #6ea2f5; --accent-soft: #1d2b44; --ok: #4cc38a; --ok-soft: #173326; --warn: #f0b44c; --warn-soft: #3a2c13;
  --bad: #f97066; --bad-soft: #3d1c1a; --pro: #b98cf0; --pro-soft: #2d2140; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- khung trang */
header.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
header.top .brand { font-weight: 700; font-size: 16px; }
header.top .brand small { font-weight: 500; color: var(--muted); margin-left: 6px; }
header.top .spacer { flex: 1; }
main { max-width: 1180px; margin: 0 auto; padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer-flex { flex: 1; }
.stack > * + * { margin-top: 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card h2 { font-size: 15px; margin: 0 0 10px; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 20px; font-weight: 650; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; word-break: break-all; }

.banner { border-radius: var(--radius); padding: 10px 14px; border: 1px solid transparent; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.banner.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- nút + ô nhập */
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.sm { padding: 3px 9px; min-height: 26px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0 4px; min-height: 0; }

input[type=text], input[type=password], input[type=number], input[type=datetime-local], select {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 9px; min-height: 32px; min-width: 0;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
input[type=number] { width: 120px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
label.field input, label.field select { width: 100%; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.error-text { color: var(--bad); min-height: 1.2em; }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
details > summary { cursor: pointer; margin-bottom: 8px; }

/* ---------- chip / trạng thái */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.pro { background: var(--pro-soft); color: var(--pro); border-color: transparent; font-weight: 650; }
.chip.xu { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); } .dot.info { background: var(--accent); }

/* ---------- bảng */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-2); }
table.list tr:last-child td { border-bottom: 0; }
table.list td .sub { color: var(--muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- thẻ tài khoản (trang người dùng) */
.accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.acc { display: flex; flex-direction: column; gap: 8px; }
.acc .head { display: flex; align-items: flex-start; gap: 8px; }
.acc .name { font-weight: 650; font-size: 15px; word-break: break-all; }
.acc .player { color: var(--muted); font-size: 13px; }
.acc .res { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.acc .res div { background: var(--panel-2); border-radius: 8px; padding: 5px 7px; }
.acc .res .k { font-size: 11px; color: var(--muted); }
.acc .res .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.status { font-size: 13px; display: flex; align-items: center; gap: 6px; min-height: 20px; min-width: 0; }
.status .note { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }

/* ---------- hộp thoại */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog.wide { width: min(980px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 14, 22, .45); }
dialog .dlg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
dialog .dlg-head h3 { margin: 0; font-size: 16px; flex: 1 1 220px; overflow-wrap: anywhere; }
dialog .dlg-body { padding: 14px 16px; }
dialog .dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }

/* ---------- thẻ cấu hình */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.opt-group { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; }
.opt-group > h4 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.opt { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 4px 0; }
.opt.indent-1 { padding-left: 22px; }
.opt.indent-2 { padding-left: 44px; }
.opt .lbl { flex: 1 1 220px; }
.opt .hint { flex-basis: 100%; color: var(--muted); font-size: 12px; margin-top: -2px; }
.multi { display: flex; flex-direction: column; gap: 4px; max-height: 210px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; flex-basis: 100%; }
.heroes { flex-basis: 100%; border: 1px solid var(--line); border-radius: 8px; max-height: 260px; overflow: auto; }
.heroes .hero { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.heroes .hero:last-child { border-bottom: 0; }
.heroes .hero .rank { min-width: 26px; text-align: center; font-size: 12px; color: var(--accent); font-weight: 650; }
.heroes .hero .info { color: var(--muted); font-size: 12px; }
.locked-feature { color: var(--muted); font-size: 13px; padding: 4px 0; }

/* ---------- nhật ký */
.log { font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.log .l-warn { color: var(--warn); }
.log .l-error { color: var(--bad); }
.log .l-detail { color: var(--muted); }
.log .t { color: var(--muted); }

/* ---------- đăng nhập */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { margin: 0 0 14px; }

/* ---------- cài đặt lần đầu */
main.setup { max-width: 860px; }
main.setup h1 { font-size: 20px; margin: 0; }
main.setup h2 { font-size: 15px; margin: 0; }
main.setup p { margin: 0; }
a.btn { text-decoration: none; color: inherit; }
a.btn.primary { color: #fff; }

/* ---------- góp ý */
textarea { font: inherit; color: inherit; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 9px; width: 100%; min-height: 110px; resize: vertical; }
textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
.fb { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.fb + .fb { margin-top: 10px; }
.fb textarea { min-height: 58px; }
.fb .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 12px; color: var(--muted); }
.fb .body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 6px; }
.fb .reply { margin-top: 8px; padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.fb .reply .who { font-size: 12px; color: var(--accent); font-weight: 600; display: block; margin-bottom: 2px; }
.badge { display: inline-flex; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; align-items: center; justify-content: center; }

.toast { position: fixed; right: 16px; bottom: 16px; max-width: min(420px, calc(100vw - 32px)); background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); z-index: 50; }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 560px) {
  main { padding: 12px; }
  .accounts { grid-template-columns: 1fr; }
  .acc .res { grid-template-columns: repeat(2, 1fr); }
  input[type=number] { width: 100px; }
}

/* danh sách ô tinh anh + nút chạy ngay (PRO) */
.cells-wrap { flex-basis: 100%; display: flex; flex-direction: column; gap: 6px; }
.cells-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.cells-bar input[type=search] { flex: 1 1 180px; min-width: 0; }
.heroes.cells { max-height: 380px; }
.heroes .cell { align-items: flex-start; }
.heroes .cell .chip { margin-top: 2px; }
.heroes .cell .ct { color: var(--ok); font-weight: 600; }
.opt-group h4 .run-now { margin-left: auto; }
#up-log { height: auto; max-height: 300px; margin: 6px 0 0; }
#up-file { max-width: 100%; }

/* bảng tướng chung (Luyện / Mãnh tiến / Chuyển sinh / CS Xu) */
.hero-table-wrap { flex-basis: 100%; max-height: 380px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.hero-table { width: 100%; border-collapse: collapse; }
.hero-table th, .hero-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.hero-table thead th { position: sticky; top: 0; background: var(--panel-2); z-index: 1; font-size: 12px; white-space: nowrap; }
.hero-table .c { text-align: center; white-space: nowrap; width: 1%; }
.hero-table .info { color: var(--muted); font-size: 12px; }
.hero-table .cell-check { display: inline-flex; align-items: center; gap: 2px; cursor: pointer; }
.hero-table .rank { min-width: 20px; font-size: 11px; color: var(--accent); font-weight: 650; text-align: left; }
.hero-table tbody tr:last-child td { border-bottom: 0; }

/* bản đồ Chinh chiến */
.map-list { flex-basis: 100%; max-height: 560px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.map-lane { position: sticky; top: 0; z-index: 1; padding: 6px 10px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.map-cell { display: flex; align-items: flex-start; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.map-cell .chip { margin-top: 2px; min-width: 96px; justify-content: center; }
.map-cell .info { color: var(--muted); font-size: 12px; }
.map-cell .ct { color: var(--ok); font-weight: 600; }
.map-cell.won b:first-child { font-weight: 600; }
.cells-bar select { max-width: 100%; }
.det-table td, .det-table th { white-space: nowrap; }
.det-table tr.chosen td { background: var(--accent-soft); }
.det-table .ct { color: var(--ok); }
.heroes .cell .cell-side { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
/* lượt toàn server còn lại của ô tinh anh: "Còn x/16" + giờ máy chủ báo */
.chip.turn { font-weight: 650; font-variant-numeric: tabular-nums; }
.chip.turn .turn-at { font-weight: 400; opacity: .75; }
/* bảng đổi đồ Quân Ải: giá đủ lệnh bài (xanh) / thiếu (đỏ) */
.qa-table td, .qa-table th { white-space: nowrap; }
.qa-table .ct { color: var(--ok); }
.qa-table .bad-text { color: var(--bad); }

/* thẻ Lính */
.linh-status { display: flex; flex-direction: column; gap: 4px; min-width: 240px; }
.linh-status .bar { height: 6px; border-radius: 3px; background: var(--line, #ddd); overflow: hidden; max-width: 320px; }
.linh-status .bar > span { display: block; height: 100%; background: var(--ok, #2e9d4f); }
