/* =====================================================================
   FCO Farming — giao diện mobile-first (kiểu AutoFCO: nền tối, cyan).
   Mọi màu đi qua biến để chỉ cần đổi một khối cho nền sáng.
   ===================================================================== */

:root {
  color-scheme: dark;
  --bg: #0a0a0f;
  --bg-soft: #0f0f15;
  --card: #111116;
  --card-2: #17171d;
  --card-3: #1d1d24;
  --ink: #e4e4e7;
  --strong: #fafafa;
  --muted: #9ca3b1;
  --line: #2a2a31;
  --line-soft: rgba(255, 255, 255, .06);
  --brand: #22d3ee;
  --brand-ink: #041418;
  --brand-soft: rgba(34, 211, 238, .12);
  --brand-line: rgba(34, 211, 238, .35);
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, .14);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, .14);
  --err: #ef4444;
  --err-soft: rgba(239, 68, 68, .14);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, .14);
  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, .14);
  --field: #0d0d12;
  --row-hover: #17171e;
  --shadow: 0 14px 34px rgba(0, 0, 0, .34);
  --radius: 12px;
  --radius-sm: 9px;
  --radius-lg: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --topbar-h: calc(56px + var(--safe-top));
  --dock-h: 56px;
  --nav-h: 44px;
  /* Alias ngữ nghĩa (Pha 2) — giữ tên cũ để không phá template. */
  --surface-0: var(--bg);
  --surface-1: var(--card);
  --surface-2: var(--card-2);
  --surface-3: var(--card-3);
  --surface-field: var(--field);
  --text-1: var(--ink);
  --text-strong: var(--strong);
  --text-2: var(--muted);
  --text-3: #7d8594;
  --border-1: var(--line);
  --border-soft: var(--line-soft);
  --accent: var(--brand);
  --accent-ink: var(--brand-ink);
  --accent-soft: var(--brand-soft);
  --accent-line: var(--brand-line);
  --success: var(--ok);
  --warning: var(--warn);
  --danger: var(--err);
  --special: var(--violet);
  --stale: var(--warn);
  --focus: #67e8f9;
  --overlay: rgba(4, 6, 10, .62);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --control-h: 36px;
  --control-h-lg: 44px;
  --row-pad-y: 7px;
  --motion-fast: 120ms;
  --motion-sheet: 160ms;
  --motion-dialog: 200ms;
  --font-body: 13.5px;
  --font-table: 13px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --chart-grid: #26262d;
  --chart-axis: #8b8b96;
  --chart-1: #22d3ee;
  --chart-2: #4ade80;
  --pos-attack-ink: #fca5a5;
  --pos-midfield-ink: #86efac;
  --pos-defense-ink: #7dd3fc;
  --pos-gk-ink: #fdba74;
  --badge-ink: #e4e4e7;
  --badge-bg: #18181b;
  --badge-border: #3f3f46;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f8;
  --bg-soft: #eef1f5;
  --card: #ffffff;
  --card-2: #f7f8fa;
  --card-3: #eef1f5;
  --ink: #1c1f26;
  --strong: #09090b;
  --muted: #59616e;
  --line: #dfe4ea;
  --line-soft: rgba(9, 9, 11, .05);
  --brand: #0e7490;
  --brand-ink: #ffffff;
  --brand-soft: rgba(14, 116, 144, .10);
  --brand-line: rgba(14, 116, 144, .30);
  --text-3: #6b7280;
  --focus: #0e7490;
  --overlay: rgba(16, 24, 40, .35);
  --ok: #15803d;
  --ok-soft: rgba(21, 128, 61, .1);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, .1);
  --err: #b91c1c;
  --err-soft: rgba(185, 28, 28, .09);
  --info: #0369a1;
  --info-soft: rgba(3, 105, 161, .09);
  --violet: #6d28d9;
  --violet-soft: rgba(109, 40, 217, .09);
  --field: #ffffff;
  --row-hover: #f6f8fb;
  --shadow: 0 10px 26px rgba(16, 24, 40, .1);
  --chart-grid: #e4e8ef;
  --chart-axis: #5f6673;
  --chart-1: #0e7490;
  --chart-2: #15803d;
  --pos-attack-ink: #991b1b;
  --pos-midfield-ink: #166534;
  --pos-defense-ink: #075985;
  --pos-gk-ink: #9a3412;
  --badge-ink: #1f2937;
  --badge-bg: #f1f5f9;
  --badge-border: #cbd5e1;
}

* { box-sizing: border-box; }

html { background: var(--bg); scroll-padding-top: calc(var(--topbar-h) + 12px); }

body {
  margin: 0;
  min-width: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: .95rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

h1, h2, h3, h4 { margin: 0; letter-spacing: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; font-weight: 750; }
h2 { font-size: 1rem; font-weight: 720; letter-spacing: -.01em; }
h3 { font-size: .92rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 120;
  background: var(--card); color: var(--ink); padding: 8px 12px;
  border: 1px solid var(--brand); border-radius: 8px;
}
.skip-link:focus { left: 8px; }

.sim-banner {
  background: linear-gradient(90deg, #b42318, #dc2626);
  color: #fff; padding: 7px 14px; font-weight: 600; font-size: .8rem; text-align: center;
}

/* ------------------------------------------------------------ top bar */
.topbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  min-height: var(--topbar-h);
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: rgba(10, 10, 15, .92);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
:root[data-theme="light"] .topbar { background: rgba(255, 255, 255, .92); }

.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; flex: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; flex: none; display: inline-grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, rgba(34, 211, 238, .26), rgba(37, 99, 235, .18));
  border: 1px solid var(--brand-line);
  color: var(--brand);
  font-weight: 800; font-size: .7rem; letter-spacing: .02em;
}
.brand-name { font-weight: 700; font-size: .95rem; white-space: nowrap; }
.brand-name b { color: var(--brand); font-weight: 750; }

/* Nhãn máy chủ trên header (Server 1 / Server 2 — đặt FCOF_SERVER_LABEL trong .env từng máy). */
.server-tag {
  flex: none; display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--brand-line, var(--line-soft));
  background: rgba(34, 211, 238, .12);
  color: var(--brand);
  font-weight: 700; font-size: .72rem; letter-spacing: .03em; white-space: nowrap;
}
:root[data-theme="light"] .server-tag { background: rgba(8, 145, 178, .10); }
/* Điện thoại: NHÃN MÁY VẪN HIỆN (chủ dự án yêu cầu 02/11) — chỉ thu nhỏ nhẹ. */
@media (max-width: 640px) { .server-tag { padding: 2px 7px; font-size: .66rem; } }

/* Menu chọn máy chủ trong header (3 farm: f1/f2/f3.huy.onl).
   Nút swap mở danh sách; máy đang phục vụ được đánh dấu "đang mở", các máy khác là link.
   JS nối đoạn đường dẫn cấp 1 của trang hiện tại vào gốc máy đích (giữ nguyên tab). */
.server-switch { position: relative; flex: none; display: inline-flex; }
.server-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 90;
  min-width: 208px; max-width: min(320px, calc(100vw - 24px));
  display: grid; gap: 2px; padding: 6px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); box-shadow: var(--shadow);
}
.server-menu[hidden] { display: none !important; }
.server-menu-head {
  padding: 4px 8px 6px; color: var(--muted);
  font-size: .66rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
}
.server-item {
  display: flex; flex-direction: column; gap: 1px;
  padding: 7px 9px; border-radius: 8px;
  color: var(--ink); text-decoration: none;
  font-size: .84rem; font-weight: 600;
}
.server-item-label { display: inline-flex; align-items: center; gap: 6px; }
.server-item-host { color: var(--muted); font-size: .7rem; font-weight: 500; }
a.server-item:hover, a.server-item:focus-visible { background: var(--card-2); }
.server-item.on { background: var(--card-2); color: var(--brand); }
.server-item.on .server-item-host { color: var(--brand); opacity: .75; }
.server-item-now {
  color: var(--brand); font-size: .62rem; font-weight: 800;
  font-style: normal; letter-spacing: .04em; text-transform: uppercase;
}

.topbar-spacer { flex: 1 1 auto; }
.topbar-actions { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.who {
  max-width: 28vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-size: .8rem;
}

.icon-btn {
  width: 42px; height: 42px; flex: none;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-2);
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { border-color: var(--brand-line); color: var(--brand); }
.icon-btn .ico { width: 18px; height: 18px; }
.icon-btn .icon-label { display: none; }

/* --------------------------------------------------------- nav rail (desktop) */
.rail {
  display: none;
  position: sticky; top: var(--topbar-h); z-index: 55;
  gap: 2px;
  padding: 6px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  background: rgba(10, 10, 15, .9);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  scrollbar-width: none;
}
:root[data-theme="light"] .rail { background: rgba(255, 255, 255, .92); }
.rail::-webkit-scrollbar { display: none; }
.rail a {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 8px; border-radius: 8px;
  color: var(--muted); font-size: .74rem; font-weight: 600; white-space: nowrap;
  text-decoration: none;
}
.rail { flex-wrap: wrap; }
.rail a .ico { width: 14px; height: 14px; opacity: .8; }
.rail a:hover { color: var(--ink); background: var(--card-2); text-decoration: none; }
.rail a.on { color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand-line); }

@media (min-width: 768px) { .rail { display: flex; } }

/* --------------------------------------------------------------- main */
main {
  width: min(100%, 1500px);
  margin: 0 auto;
  padding: 14px 12px calc(24px + var(--dock-h) + var(--safe-bottom));
}
@media (min-width: 768px) {
  main { padding: 20px 18px 40px; }
}

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.page-head .page-title-wrap { min-width: 0; }
.page-head h1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-sub { margin-top: 4px; color: var(--muted); font-size: .82rem; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-actions .btn { min-height: 38px; }

/* ---------------------------------------------------------- containers */
.grid { display: grid; gap: 12px; }
.grid.c2 { grid-template-columns: minmax(0, 1fr); }
.grid.c3 { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .02), 0 10px 26px rgba(0, 0, 0, .15);
  padding: 14px;
  margin-bottom: 12px;
  min-width: 0;
}
:root[data-theme="light"] .card { box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 22px rgba(16, 24, 40, .05); }
.card.tight { padding: 10px; }
.card.flat { background: var(--card-2); box-shadow: none; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 11px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { display: flex; align-items: center; gap: 6px; }
.card-head .head-note { color: var(--muted); font-size: .78rem; }
.card-head .seg { margin-bottom: 0; width: auto; flex: 0 1 260px; }

.section-gap { height: 2px; }

/* -------------------------------------------------------------- kpis */
.kpi-grid, .asset-grid, .statbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
@media (min-width: 700px) {
  .kpi-grid, .asset-grid, .statbar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.kpi, .asset, .stat {
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .035), rgba(255, 255, 255, 0));
}
:root[data-theme="light"] .kpi, :root[data-theme="light"] .asset, :root[data-theme="light"] .stat {
  background: var(--card-2);
}
.kpi .label, .asset .lbl, .stat .lbl {
  color: var(--muted); font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
}
.kpi .value, .asset .val, .stat .val {
  margin-top: 3px; font-size: 1.16rem; font-weight: 750; font-variant-numeric: tabular-nums;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.asset .val { font-size: 1.06rem; }
.stat .val .sub { font-weight: 500; font-size: .7rem; color: var(--muted); margin-left: 3px; }
.stat.warn .val { color: var(--warn); }
.stat.bad .val { color: var(--err); }
.asset .sub, .kpi .sub { color: var(--muted); font-size: .68rem; margin-top: 2px; }

/* --------------------------------------------------------------- chips */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card-3);
  color: var(--muted);
  font-size: .7rem; font-weight: 650; line-height: 1.5;
  white-space: nowrap;
}
.tag.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--card)); border-color: color-mix(in srgb, var(--ok) 22%, var(--line)); }
.tag.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--card)); border-color: color-mix(in srgb, var(--warn) 22%, var(--line)); }
.tag.err { color: var(--err); background: color-mix(in srgb, var(--err) 9%, var(--card)); border-color: color-mix(in srgb, var(--err) 22%, var(--line)); }
.tag.info { color: var(--info); background: color-mix(in srgb, var(--info) 10%, var(--card)); border-color: color-mix(in srgb, var(--info) 22%, var(--line)); }
.tag.muted { color: var(--muted); background: var(--card-2); border-color: var(--line); }
.tag.violet { color: var(--violet); background: color-mix(in srgb, var(--violet) 10%, var(--card)); border-color: color-mix(in srgb, var(--violet) 22%, var(--line)); }
.tag.chipbtn { cursor: pointer; user-select: none; }
.tag.chipbtn.active { outline: 2px solid currentColor; outline-offset: 1px; }
.tag.chipbtn:hover { filter: brightness(1.12); }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card-2);
  color: var(--ink);
  font: inherit; font-size: .84rem; font-weight: 600;
  line-height: 1.2; cursor: pointer;
  text-decoration: none; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
}
.btn:hover { border-color: color-mix(in srgb, var(--muted) 45%, var(--line)); color: var(--strong); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .ico { width: 16px; height: 16px; flex: none; }

.btn.primary, .btn.brand {
  border-color: transparent;
  color: #041418;
  background: linear-gradient(180deg, #67e8f9, #22d3ee);
  box-shadow: 0 4px 14px rgba(34, 211, 238, .18);
  font-weight: 720;
}
.btn.primary:hover, .btn.brand:hover {
  border-color: transparent;
  color: #041418;
  background: #67e8f9;
  filter: none;
}
:root[data-theme="light"] .btn.primary, :root[data-theme="light"] .btn.brand {
  color: #fff; background: linear-gradient(180deg, #0ea5b7, #0891b2);
}
:root[data-theme="light"] .btn.primary:hover, :root[data-theme="light"] .btn.brand:hover { background: #0e7490; }

.btn.ghost, .btn.light {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}
.btn.ghost:hover, .btn.light:hover { background: var(--card-2); color: var(--strong); }

.btn.danger {
  border-color: color-mix(in srgb, var(--err) 42%, transparent);
  color: #fff1f2; background: linear-gradient(135deg, rgba(239, 68, 68, .3), rgba(127, 29, 29, .26));
}
:root[data-theme="light"] .btn.danger { color: var(--err); background: var(--err-soft); }
.btn.danger:hover { border-color: var(--err); }

.btn.warn {
  border-color: color-mix(in srgb, var(--warn) 45%, transparent);
  color: #fffbeb; background: linear-gradient(135deg, rgba(245, 158, 11, .28), rgba(120, 53, 15, .22));
}
:root[data-theme="light"] .btn.warn { color: var(--warn); background: var(--warn-soft); }

.btn.sm { min-height: 30px; padding: 4px 8px; font-size: .76rem; border-radius: 8px; }
.btn.sm .ico { width: 14px; height: 14px; }
.btn.block { width: 100%; }
.btn.wide-sm { min-width: 44px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.btn-row.end { justify-content: flex-end; }

/* --------------------------------------------------------------- forms */
.field { min-width: 0; margin-bottom: 10px; }
.field > label, .field-label {
  display: block; margin-bottom: 5px;
  color: var(--muted); font-size: .75rem; font-weight: 650; letter-spacing: .01em;
}
input, select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--field);
  color: var(--ink);
  font: inherit; font-size: .86rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
textarea { min-height: 92px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; line-height: 1.55; }
input[type="checkbox"], input[type="radio"] {
  width: 18px; height: 18px; min-height: 0; padding: 0;
  accent-color: var(--brand); flex: none; cursor: pointer;
}
input[type="checkbox"]:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
input[type="date"] { min-height: 38px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 16px, calc(100% - 10px) 16px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }
.row.center { align-items: center; }
.row.between { justify-content: space-between; }
.row .field { flex: 1 1 150px; margin-bottom: 0; }
.row .field.grow { flex: 1 1 240px; }
.field.grow { flex: 1 1 240px; min-width: 0; }

.check {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--ink); font-size: .84rem; cursor: pointer; line-height: 1.35;
}
.check input { margin: 0; }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--ink); cursor: pointer; }
.switch input { width: 16px; height: 16px; }

.invalid, input.invalid, select.invalid {
  border-color: var(--err);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--err) 16%, transparent);
}
.field-error { color: var(--err); font-size: .74rem; margin-top: 3px; }
.field-help { color: var(--muted); font-size: .74rem; margin-top: 4px; }
.field-err { color: var(--err); font-size: .74rem; margin-top: 3px; min-height: 0; }
.field-err.on { font-weight: 650; }

.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.form-grid .wide { grid-column: 1 / -1; }

/* --------------------------------------------------------- segmented tabs */
.seg {
  display: flex; gap: 3px; width: 100%; margin-bottom: 12px; padding: 3px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--card);
}
.seg-btn, .seg > .btn {
  flex: 1 1 0; min-width: 0; min-height: 36px;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 5px 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: .78rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}
.seg-btn:hover, .seg > .btn:hover { color: var(--ink); background: var(--card-2); }
.seg-btn.on, .seg > .btn.on { color: var(--ink); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand-line); }
.seg-btn .meta { color: var(--brand); font-size: .7rem; font-weight: 700; }
.seg .ico { width: 15px; height: 15px; }

/* --------------------------------------------------------------- tables */
.scroll { overflow: auto; max-height: 70vh; }
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left; vertical-align: top;
  font-size: .82rem;
}
th {
  position: sticky; top: 0; z-index: 1;
  background: var(--card-2); color: var(--muted);
  font-size: .69rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--row-hover); }
td.small, th.small { font-size: .76rem; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sortable .dir { color: var(--brand); margin-left: 4px; }

table.kv { width: 100%; }
table.kv th {
  width: 42%; position: static; background: transparent; text-transform: none;
  color: var(--muted); font-size: .78rem; font-weight: 600; letter-spacing: 0;
  padding: 7px 8px; border-bottom: 1px solid var(--line-soft);
}
table.kv td { padding: 7px 8px; border-bottom: 1px solid var(--line-soft); }
table.kv tr:last-child th, table.kv tr:last-child td { border-bottom: 0; }

/* Bảng tự xếp thành thẻ trên điện thoại (dùng data-label). */
@media (max-width: 767px) {
  table.stack { min-width: 0; }
  /* Bảng cầu thủ trong kho / đang bán không được ép cột rộng gây tràn/đè trên mobile. */
  table.stack .col-account,
  table.stack .col-money,
  table.stack .col-status,
  table.stack .col-proxy { min-width: 0; }
  table.stack thead { display: none; }
  table.stack tbody, table.stack tr { display: block; }
  table.stack tr {
    padding: 10px 11px;
    border-bottom: 1px solid var(--line);
    background: var(--card);
  }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td {
    display: flex; gap: 8px; align-items: baseline;
    padding: 2px 0; border: 0; font-size: .8rem;
  }
  table.stack td::before {
    content: attr(data-label);
    flex: 0 0 92px;
    color: var(--muted); font-size: .72rem; font-weight: 600;
  }
  table.stack td:empty { display: none; }
  table.stack td[data-label=""]::before, table.stack td.no-label::before { display: none; }

  /* Kho & lệnh bán: thông tin cầu thủ + giá trên CÙNG một dòng (không thành 2 dòng). */
  #inventory table.stack tr,
  #orders-sell table.stack tr,
  #orders-buy table.stack tr {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
  }
  #inventory table.stack td::before,
  #orders-sell table.stack td::before,
  #orders-buy table.stack td::before { display: none; }
  #inventory table.stack td:first-child,
  #orders-sell table.stack td:first-child,
  #orders-buy table.stack td:first-child { flex: 1 1 auto; min-width: 0; }
  #inventory table.stack td.num,
  #orders-sell table.stack td.num,
  #orders-buy table.stack td.num { flex: 0 0 auto; text-align: right; }
}

/* ---------------------------------------------------------- list cards */
.list { display: flex; flex-direction: column; gap: 8px; }
.rowcard {
  position: relative;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .025), rgba(255, 255, 255, 0));
  min-width: 0;
}
:root[data-theme="light"] .rowcard { background: var(--card-2); }
.rowcard:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.rowcard-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; min-width: 0; }
.rowcard-title { font-weight: 700; font-size: .9rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.rowcard-title a { color: inherit; }
.rowcard-sub { margin-top: 3px; color: var(--muted); font-size: .76rem; line-height: 1.45; }
.rowcard-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 5px; color: var(--muted); font-size: .74rem; font-variant-numeric: tabular-nums; }
.rowcard-meta b { color: var(--ink); font-weight: 650; }
.rowcard-error { margin-top: 5px; color: var(--err); font-size: .75rem; }
.rowcard-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 7px; font-size: .76rem; }
.rowcard-actions a { font-weight: 600; }
.rowcard-side { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.rowcard .check { position: absolute; top: 10px; right: 10px; }
.rowcard.has-check .rowcard-head { padding-right: 26px; }

.roster-row { display: flex; align-items: center; gap: 9px; min-width: 0; }
.roster-main { min-width: 0; flex: 1 1 auto; }
.roster-title { font-weight: 700; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-sub { color: var(--muted); font-size: .74rem; }

.logrow { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); }
.logrow:last-child { border-bottom: 0; }
.logrow-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .72rem; color: var(--muted); }
.logrow-msg { margin-top: 3px; font-size: .8rem; line-height: 1.5; word-break: break-word; }

/* -------------------------------------------------------------- toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end;
}
.toolbar .field { flex: 1 1 150px; margin: 0; min-width: 0; }
.toolbar .btn { flex: 0 0 auto; }
.filter-shell { display: flex; flex-direction: column; gap: 8px; }

/* --------------------------------------------------------------- misc */
.muted { color: var(--muted); }
.small { font-size: .78rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .78rem; }
.nowrap { white-space: nowrap; }
.wrap { flex-wrap: wrap; }
.right { text-align: right; }
.hidden, [hidden] { display: none !important; }
.empty, .empty-state {
  padding: 22px 14px; text-align: center; color: var(--muted); font-size: .82rem;
}
.status-err { color: var(--err); font-weight: 600; }
.status-ok { color: var(--ok); }
.status-warn { color: var(--warn); }
.ok-ink { color: var(--ok); }
.err-ink { color: var(--err); }
.warn-ink { color: var(--warn); }
.divider { height: 1px; background: var(--line); margin: 10px 0; }

.progress { height: 7px; border-radius: 999px; background: var(--card-3); overflow: hidden; }
.progress > div { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), #3b82f6); transition: width .3s ease; }

.kv-list { display: grid; gap: 0; }
.kv-row { display: flex; gap: 10px; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.kv-row:last-child { border-bottom: 0; }
.kv-row .k { color: var(--muted); font-size: .78rem; flex: 0 0 auto; }
.kv-row .v { font-size: .8rem; text-align: right; min-width: 0; overflow-wrap: anywhere; }

.info-dot {
  display: inline-grid; place-items: center;
  width: 15px; height: 15px; border-radius: 50%;
  border: 1px solid var(--line); color: var(--muted);
  font-size: .62rem; font-weight: 700; cursor: help;
}

details summary { cursor: pointer; color: var(--muted); font-size: .8rem; }
details summary:hover { color: var(--ink); }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "›"; display: inline-block; margin-right: 5px; transition: transform .15s ease; }
details[open] > summary::before { transform: rotate(90deg); }

code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre { margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--field); overflow: auto; font-size: .76rem; }

/* ------------------------------------------------------------- overlays */
.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--dock-h) + var(--safe-bottom) + 12px);
  z-index: 200;
  padding: 10px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(20, 20, 26, .97);
  color: #f4f4f5;
  box-shadow: var(--shadow);
  font-size: .84rem;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  max-width: 520px;
}
:root[data-theme="light"] .toast { background: rgba(24, 24, 27, .96); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { border-color: rgba(34, 197, 94, .45); }
.toast.err { border-color: rgba(239, 68, 68, .55); }

@media (min-width: 768px) {
  .toast { left: auto; right: 20px; bottom: 20px; width: auto; min-width: 280px; }
}

.conn-banner {
  position: sticky; top: var(--topbar-h); z-index: 58;
  padding: 8px 14px;
  background: var(--err-soft); color: var(--err);
  border-bottom: 1px solid color-mix(in srgb, var(--err) 45%, transparent);
  font-weight: 650; font-size: .8rem; text-align: center;
}

.last-updated {
  margin-top: 10px; padding: 2px 2px 6px;
  color: var(--muted); font-size: .7rem; text-align: right;
}

dialog.modal {
  width: min(980px, 94vw); max-height: 88vh; overflow: auto;
  padding: 14px;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--card); color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
dialog.modal::backdrop { background: rgba(4, 6, 10, .62); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }

/* ---------------------------------------------------------- login page */
.login-shell {
  min-height: calc(100dvh - var(--topbar-h));
  display: flex; align-items: center; justify-content: center;
  padding: 22px 14px calc(22px + var(--safe-bottom));
}
.login-card {
  width: 100%; max-width: 400px;
  padding: 20px;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.login-brand .brand-mark { width: 38px; height: 38px; font-size: .8rem; }
.login-brand h1 { font-size: 1.1rem; }
.login-brand p { color: var(--muted); font-size: .76rem; margin-top: 1px; }
.login-card .field { margin-bottom: 12px; }
.login-foot { margin-top: 14px; color: var(--muted); font-size: .72rem; line-height: 1.5; }

/* --------------------------------------------------------------- charts */
.chart-grid { stroke: var(--chart-grid); }
.chart-axis { fill: var(--chart-axis); }
.chart-box { margin-bottom: 12px; }

/* ------------------------------------------------------- player cards */
.player-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; margin-top: 8px; }
.player-card {
  display: flex; gap: 9px; align-items: center;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card-2);
}
.player-avatar {
  position: relative; width: 46px; height: 56px; flex: none;
  border-radius: 8px; overflow: hidden; background: var(--card-3);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: var(--muted);
}
.player-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity .15s ease-in; }
.player-avatar img.ready { opacity: 1; }
.player-main { min-width: 0; flex: 1; }
.player-name { font-weight: 650; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-sub { display: flex; align-items: center; gap: 6px; font-size: .72rem; color: var(--muted); margin-top: 2px; }
.player-pos { padding: 0 5px; border-radius: 4px; background: var(--card-3); font-weight: 650; }
.player-foot { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: .72rem; }
.season-chip {
  display: inline-block; padding: 0 5px; height: 18px; line-height: 18px;
  border-radius: 4px; background: var(--card-3); font-size: .68rem; font-weight: 650;
}

/* ---------------------------------------------------------- pickers */
.picker {
  max-height: 280px; overflow: auto;
  border: 1px solid var(--line); border-radius: 10px; padding: 6px;
  background: var(--card-2);
}
.pick-row { display: flex; align-items: center; gap: 8px; padding: 6px 7px; border-radius: 7px; cursor: pointer; }
.pick-row:hover { background: var(--card-3); }
.pick-row span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-row.slim { flex: 0 0 auto; border: 1px solid var(--line); background: var(--card-2); padding: 5px 10px; border-radius: 999px; }
.pick-row.slim span:first-of-type { overflow: visible; text-overflow: clip; }
.pick-row.slim input { width: 16px; height: 16px; }

/* --------------------------------------------------- scenario editor */
.sc-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
.sc-list-pane { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sc-list { display: flex; flex-direction: column; gap: 8px; }
.sc-item {
  position: relative;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  cursor: pointer;
}
.sc-item:hover { border-color: var(--brand-line); }
.sc-item.on { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand-line); background: var(--card-2); }
.sc-item.off .sc-item-name { color: var(--muted); }
.sc-item-top { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.sc-item-name { font-weight: 700; font-size: .9rem; }
.sc-item-sub { margin-top: 5px; font-size: .75rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.sc-menu-btn { min-width: 30px; min-height: 26px; }
.sc-menu {
  position: absolute; right: 8px; top: 38px; z-index: 30;
  min-width: 140px; padding: 4px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); box-shadow: var(--shadow);
}
.sc-menu button {
  display: block; width: 100%; padding: 8px 11px;
  text-align: left; border: 0; border-radius: 7px;
  background: none; color: var(--ink); font: inherit; font-size: .82rem; cursor: pointer;
}
.sc-menu button:hover { background: var(--card-2); }
.sc-menu .danger-text { color: var(--err); font-weight: 650; }
.sc-menu .danger-text:hover { background: var(--err-soft); }
.sc-menu button:disabled { opacity: .5; cursor: not-allowed; }

.sc-back { display: none; margin-bottom: 10px; }
.sc-editor { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sc-ed-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.sc-fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.sc-f-wide { grid-column: 1 / -1; }
.sc-f-wide input { width: 100%; }
.sc-unit-row { display: flex; align-items: center; gap: 8px; }
.sc-unit-row input { max-width: 120px; }
.sc-unit { font-size: .82rem; color: var(--ink); font-weight: 650; }
.sc-req { color: var(--err); }
.sc-check { display: flex; gap: 8px; align-items: center; font-size: .82rem; color: var(--ink); padding: 5px 0; cursor: pointer; }
.sc-check input { width: 18px; height: 18px; }
.sc-switch { display: flex; gap: 6px; align-items: center; font-size: .78rem; color: var(--ink); cursor: pointer; }
.sc-switch input { width: 16px; height: 16px; }
details.sc-adv { margin-top: 8px; }
details.sc-adv summary { font-size: .8rem; font-weight: 650; color: var(--muted); padding: 4px 0; }
details.sc-adv > .sc-fgrid, details.sc-adv > label { margin-top: 8px; }

.sc-step { padding: 0; overflow: visible; border-radius: 11px; }
.sc-step.dragging { opacity: .5; }
.sc-step.off .sc-step-name, .sc-step.off .sc-step-sum { color: var(--muted); font-weight: 500; }
.sc-step.off .sc-step-num { background: var(--card-3); color: var(--muted); }
.sc-step-head { display: flex; align-items: center; gap: 8px; padding: 11px 12px; cursor: pointer; flex-wrap: wrap; }
.sc-step-num {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
  border: 1px solid var(--brand-line);
  font-size: .72rem; font-weight: 750;
}
.sc-step-name { font-weight: 700; font-size: .86rem; }
.sc-step-sum { color: var(--muted); font-size: .74rem; }
.sc-step-ctrls { margin-left: auto; display: flex; align-items: center; gap: 5px; position: relative; flex-wrap: wrap; }
.sc-step-body { padding: 6px 12px 12px; border-top: 1px dashed var(--line); }
.sc-picker { margin-top: 8px; }
.sc-picker-list { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; max-height: 320px; overflow: auto; }
.sc-pick {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 9px 10px; border: 1px solid transparent; border-radius: 9px;
  background: none; color: var(--ink); text-align: left; font: inherit; cursor: pointer;
}
.sc-pick:hover { background: var(--card-2); border-color: var(--line); }
.sc-pick-name { font-weight: 650; font-size: .84rem; }
.sc-plan { margin: 6px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 5px; font-size: .8rem; }
.sc-savebar {
  position: sticky; bottom: calc(var(--dock-h) + var(--safe-bottom) + 8px); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-top: 10px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 11px;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.sc-dirty { font-size: .8rem; color: var(--muted); font-weight: 650; }
.sc-dirty.on { color: var(--warn); }

@media (min-width: 960px) {
  .sc-layout { grid-template-columns: 330px minmax(0, 1fr); }
  .sc-savebar { bottom: 12px; }
}
@media (max-width: 959px) {
  .sc-editor-pane .sc-back { display: inline-flex; }
  body:not(.mobile-editing) .sc-editor-pane { display: none; }
  body.mobile-editing .sc-list-pane { display: none; }
}

/* --------------------------------------------------- features / verify */
.feat {
  padding: 12px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--card);
  margin-bottom: 8px;
}
.feat-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.feat-name { font-weight: 700; font-size: .9rem; }
.feat-desc { margin-top: 4px; color: var(--muted); font-size: .78rem; }
.feat-meta { margin-top: 6px; color: var(--muted); font-size: .73rem; display: flex; flex-wrap: wrap; gap: 4px 10px; }

/* ------------------------------------------------------------ dock/sheet */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  padding: 4px 6px calc(4px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(10, 10, 15, .96);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
:root[data-theme="light"] .dock { background: rgba(255, 255, 255, .96); }
.dock-item {
  position: relative;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-width: 0; min-height: 48px; padding: 4px 2px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: .63rem; font-weight: 650; line-height: 1.1; text-align: center;
  text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dock-item .ico { width: 19px; height: 19px; }
.dock-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dock-item.on { color: var(--brand); background: var(--brand-soft); }
.dock-item.on::before {
  content: ""; position: absolute; top: -4px; left: 50%;
  width: 22px; height: 2px; border-radius: 999px; background: var(--brand); transform: translateX(-50%);
}
.dock-item:active { background: var(--card-2); }
@media (min-width: 768px) { .dock { display: none; } }

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 6, 10, .6);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 101;
  max-height: min(86dvh, 720px);
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  background: var(--card);
  transform: translateY(102%);
  transition: transform .24s cubic-bezier(.22, .61, .36, 1);
  box-shadow: 0 -20px 50px rgba(0, 0, 0, .4);
}
.sheet.open { transform: translateY(0); }
.sheet-grab { width: 38px; height: 4px; margin: 8px auto 0; border-radius: 999px; background: var(--line); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px 8px;
}
.sheet-head h2 { font-size: .98rem; }
.sheet-body { padding: 0 12px 16px; overflow-y: auto; overscroll-behavior: contain; }
.sheet-group { margin-top: 10px; }
.sheet-group-title {
  margin: 0 4px 6px; color: var(--muted);
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
}
.sheet-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.sheet-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  min-width: 0; min-height: 78px; padding: 9px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--card-2); color: var(--ink);
  text-decoration: none; font-size: .76rem;
  -webkit-tap-highlight-color: transparent;
}
.sheet-tile:hover { border-color: var(--brand-line); text-decoration: none; }
.sheet-tile:active { background: var(--brand-soft); }
.sheet-tile.on { border-color: var(--brand-line); background: var(--brand-soft); }
.sheet-tile .tile-ico {
  width: 30px; height: 30px; display: inline-grid; place-items: center;
  border-radius: 8px; background: var(--brand-soft); color: var(--brand);
}
.sheet-tile .tile-ico .ico { width: 17px; height: 17px; }
.sheet-tile strong { font-size: .78rem; font-weight: 700; line-height: 1.15; }
.sheet-tile small { color: var(--muted); font-size: .66rem; line-height: 1.2; }
@media (min-width: 768px) { .sheet, .sheet-backdrop { display: none; } }

/* ----------------------------------------- farm summary / state chips */
.summary-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.summary-note { margin-top: 6px; color: var(--muted); font-size: .74rem; }
.state-note { margin-top: 6px; color: var(--muted); font-size: .78rem; }
.state-note.on { color: var(--ok); }

/* ------------------------------------------------------- settings rows */
.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}
.setting-row:last-child { border-bottom: 0; }
.setting-label { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .8rem; font-weight: 650; color: var(--ink); }
.setting-label code { color: var(--muted); font-size: .68rem; font-weight: 500; }
.setting-control { min-width: 0; }
.setting-control input:not([type="checkbox"]), .setting-control select { max-width: 360px; }
.hint-details { display: inline-block; }
.hint-details > summary {
  display: inline-grid; place-items: center;
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid var(--line); color: var(--muted);
  font-size: .62rem; font-weight: 700; line-height: 1;
  cursor: pointer; list-style: none;
}
.hint-details > summary::before { content: "?"; margin: 0; }
.hint-details[open] > summary { color: var(--brand); border-color: var(--brand-line); }
.hint-details .hint-body { margin-top: 5px; color: var(--muted); font-size: .76rem; line-height: 1.5; }
@media (min-width: 760px) {
  .setting-row { grid-template-columns: minmax(200px, 38%) minmax(0, 1fr); gap: 12px; align-items: start; }
  .setting-label { padding-top: 8px; }
}

/* ------------------------------------------------------------ devices */
@media (max-width: 767px) {
  .topbar { gap: 8px; }
  .btn { min-height: 40px; }
  .btn.sm { min-height: 34px; }
  .page-actions.full { width: 100%; }
  .page-actions.full .btn { flex: 1 1 auto; }
  .page-sub.state-note.on { color: var(--ok); }
  .who { display: none; }
  .page-head h1 { font-size: 1.24rem; }
  .page-actions .btn { flex: 1 1 auto; }
  .card { padding: 11px; border-radius: 11px; }
  .row .field { flex: 1 1 100%; }
  .toolbar .field { flex: 1 1 160px; }
  .toolbar .field.grow { flex: 1 1 100%; }
  .btn-row .btn { flex: 1 1 auto; }
  th, td { padding: 7px 8px; }
  .table-wrap { border-radius: 9px; }
  .summary-chips .tag { font-size: .68rem; }
  .sc-savebar { bottom: calc(var(--dock-h) + var(--safe-bottom) + 6px); }
}

@media (max-width: 400px) {
  main { padding-inline: 9px; }
  .topbar { padding-inline: 9px; }
  .btn { padding: 7px 10px; }
  h1 { font-size: 1.15rem; }
  .kpi-grid, .asset-grid, .statbar { gap: 6px; }
  .kpi, .asset, .stat { padding: 9px; }
  .kpi .value, .asset .val, .stat .val { font-size: 1.02rem; }
  .sheet-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seg-btn { font-size: .72rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; animation-duration: .001ms !important; }
}

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* --------------------------------------------------- spinner / status */
.spinner {
  display: inline-block; width: 13px; height: 13px; margin-right: 6px; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: fco-spin .8s linear infinite;
}
@keyframes fco-spin { to { transform: rotate(360deg); } }

/* ----------------------------------- khu vực có thanh toán/ghi chú nhỏ */
.meta-line { color: var(--muted); font-size: .74rem; margin-top: 6px; }
.warn-box {
  padding: 9px 11px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  background: var(--warn-soft); color: var(--warn);
  font-size: .8rem;
}
.err-box {
  padding: 9px 11px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--err) 35%, transparent);
  background: var(--err-soft); color: var(--err);
  font-size: .8rem;
}
.ok-box {
  padding: 9px 11px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent);
  background: var(--ok-soft); color: var(--ok);
  font-size: .8rem;
}

/* Nút đổi nền: chỉ hiện một biểu tượng theo chế độ hiện tại. */
#theme-toggle .theme-moon { display: none; }
#theme-toggle .theme-sun { display: block; }
#theme-toggle[data-mode="moon"] .theme-sun { display: none; }
#theme-toggle[data-mode="moon"] .theme-moon { display: block; }

/* Trang đăng nhập: không cần rail/dock, nội dung căn giữa. */
body.login-page .rail,
body.login-page .dock,
body.login-page .last-updated { display: none; }
body.login-page main { padding: 0; }


/* Rail trên desktop cao ~44px ⇒ banner lỗi phải nằm dưới cả rail. */
@media (min-width: 768px) {
  .conn-banner { top: calc(var(--topbar-h) + var(--nav-h)); }
}

/* Trang đăng nhập vẫn giữ nút đổi nền nhưng không cần nút đăng xuất. */
body.login-page .topbar-actions .who,
body.login-page .topbar-actions .icon-btn[aria-label="Đăng xuất"] { display: none; }

@media (max-width: 359px) {
  .brand-name { display: none; }
}

/* =====================================================================
   Lớp dữ liệu chuyên nghiệp (bảng desktop + thẻ có nhãn trên mobile)
   ===================================================================== */

/* ---------------------------------------------------------- trạng thái */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 650;
  line-height: 1.35;
  white-space: nowrap;
}
.status .dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent);
}
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.err { color: var(--err); }
.status.info { color: var(--info); }
.status.muted { color: var(--muted); }
.status.sm { font-size: .72rem; font-weight: 600; }
.status.sm .dot { width: 6px; height: 6px; box-shadow: none; }
.status.plain { color: var(--ink); }

/* ------------------------------------------------------------ dải tổng */
.summary-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
@media (min-width: 640px) {
  .summary-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1000px) {
  .summary-strip { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
.summary-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-2);
  color: var(--ink);
  font: inherit;
  text-align: left;
}
.summary-item .k {
  color: var(--muted);
  font-size: .7rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.summary-item strong {
  color: var(--ink);
  font-size: 1.12rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.summary-item.ok strong { color: var(--ok); }
.summary-item.warn strong { color: var(--warn); }
.summary-item.err strong { color: var(--err); }
.summary-item.info strong { color: var(--info); }
button.summary-item,
a.summary-item { cursor: pointer; text-decoration: none; }
button.summary-item:hover,
a.summary-item:hover { border-color: var(--brand-line); background: var(--card-3); text-decoration: none; }
.summary-item.is-active { border-color: var(--brand-line); box-shadow: inset 0 0 0 1px var(--brand-line); background: var(--brand-soft); }

/* ------------------------------------------------------- bộ lọc gọn */
.list-filters { padding: 12px 14px; }
.filters-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}
.filters-head .field { margin: 0; flex: 1 1 220px; min-width: 0; }
.filters-head .filter-toggle { display: none; }
.filter-panel { margin-top: 10px; }
.filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}
@media (min-width: 720px) {
  .filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1100px) {
  .filter-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
.filter-grid .field { margin: 0; min-width: 0; }
.filter-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; align-items: center; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.active-filters:empty { display: none; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--brand-line);
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font: inherit;
  font-size: .73rem;
  font-weight: 650;
  cursor: pointer;
}
.filter-chip:hover { filter: brightness(1.12); }
.filter-chip .x { font-size: .9rem; line-height: 1; opacity: .75; }
.filter-chip .x:hover { opacity: 1; }

@media (max-width: 899px) {
  .filters-head .filter-toggle { display: inline-flex; flex: 1 1 auto; }
  .filters-head .apply-btn { flex: 1 1 auto; }
  .filter-panel { display: none; }
  .filter-panel.open { display: block; }
  .filter-panel .filter-actions { display: none; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------------------------------------------------- khối thu gọn */
.collapsible-toggle { display: none; }
@media (max-width: 899px) {
  .collapsible-toggle { display: inline-flex; }
  .collapsible-body:not(.open) { display: none; }
}
@media (min-width: 900px) {
  .collapsible-body { display: block !important; }
  .collapsible-toggle { display: none; }
}

/* ------------------------------------------------------- bảng dữ liệu */
.table-shell {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  overflow-x: auto;
}
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}
.data-table thead th {
  position: static;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--card-2);
  color: var(--muted);
  font-size: .67rem;
  font-weight: 750;
  letter-spacing: .045em;
  text-transform: uppercase;
  white-space: nowrap;
}
.data-table tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line-soft);
  font-size: .82rem;
  line-height: 1.45;
  vertical-align: middle;
  color: var(--ink);
}
.data-table tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--card-2) 38%, transparent);
}
.data-table tbody tr:hover td {
  background: var(--row-hover);
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .col-check { width: 34px; padding-right: 0; }
.data-table .col-check input { display: block; margin: 0 auto; }
.data-table .col-account { min-width: 170px; }
.data-table .col-status { min-width: 100px; }
.data-table .col-run { min-width: 160px; }
.data-table .col-money { min-width: 100px; }
.data-table .col-proxy { min-width: 145px; }
.data-table .col-health { min-width: 130px; }
.data-table .col-actions { min-width: 135px; text-align: right; }
.data-table .cell-main {
  color: var(--strong);
  font-size: .88rem;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.data-table .cell-main a { color: var(--strong); font-weight: 700; }
.data-table .cell-main a:hover { color: var(--brand); }
.data-table .cell-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.45;
}
.data-table .cell-sub.err { color: var(--err); }
.data-table .cell-sub.warn { color: var(--warn); }
.data-table .cell-sub.ok { color: var(--ok); }
.data-table .cell-sub.truncate {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.data-table .cell-value { min-width: 0; }
.data-table .money { color: var(--strong); font-weight: 700; font-variant-numeric: tabular-nums; }
.data-table .muted { color: var(--muted); }
.data-table .mono { font-size: .74rem; }
.data-table .tag { font-size: .67rem; padding: 1px 7px; }
.data-table .status { font-size: .76rem; }
.data-table .status .dot { width: 6px; height: 6px; box-shadow: none; }

/* Hành động dạng liên kết gọn, dễ thấy nhưng không phá bố cục. */
.row-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 11px;
}
.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand);
  font: inherit;
  font-size: .75rem;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.link-btn:hover { color: #67e8f9; text-decoration: none; }
.link-btn.muted, .link-btn.muted:hover { color: var(--muted); }
.link-btn.danger, .link-btn.danger:hover { color: var(--err); }
:root[data-theme="light"] .link-btn:hover { color: #0e7490; }

/* Icon hành động trong bảng (thay nút chữ — gọn, cùng bộ SVG nội tuyến). */
.row-actions .icon-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  color: var(--muted);
  text-decoration: none;
}
.row-actions .icon-act:hover { background: var(--card-2); color: var(--brand); }
.row-actions .icon-act.danger:hover { color: var(--err); }
.row-actions .icon-act .ico { width: 16px; height: 16px; }

/* Tài khoản bị khóa/banned: tên đỏ + gạch ngang (bảng Tài khoản). */
.data-table .cell-main a.locked { color: var(--err); text-decoration: line-through; }
.data-table .cell-main a.locked:hover { color: var(--err); }

/* Bảng -> thẻ có nhãn trên điện thoại */
@media (max-width: 899px) {
  .table-shell {
    border: 0;
    border-radius: 0;
    background: transparent;
    overflow: visible;
  }
  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td { display: block; width: auto; }
  .data-table thead { display: none; }
  .data-table tbody { display: flex; flex-direction: column; gap: 10px; }
  .data-table tbody tr {
    position: relative;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    box-shadow: 0 1px 0 rgba(255, 255, 255, .02);
  }
  .data-table tbody tr:nth-child(even) td { background: transparent; }
  .data-table tbody tr:hover td { background: transparent; }
  .data-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    padding: 4px 0;
    border: 0;
    text-align: left;
    font-size: .82rem;
  }
  .data-table tbody td::before {
    content: attr(data-label);
    flex: 0 0 92px;
    padding-top: 2px;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 650;
  }
  .data-table tbody td.col-check {
    position: absolute;
    top: 12px;
    right: 12px;
    width: auto;
    padding: 0;
    z-index: 1;
  }
  .data-table tbody td.col-check::before { display: none; }
  .data-table tbody td.col-account {
    display: block;
    padding: 0 28px 9px 0;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--line-soft);
  }
  .data-table tbody td.col-account::before { display: none; }
  .data-table tbody td.col-account .cell-main { font-size: .95rem; }
  .data-table tbody td.col-actions {
    display: block;
    margin-top: 9px;
    padding: 9px 0 0;
    border-top: 1px solid var(--line-soft);
  }
  .data-table tbody td.col-actions::before { display: none; }
  .data-table tbody td.col-actions .row-actions { justify-content: flex-start; gap: 16px; }
  .data-table tbody td.num { text-align: left; }
  .data-table tbody td .cell-value,
  .data-table tbody td .cell-main,
  .data-table tbody td .cell-sub { min-width: 0; }
  .data-table tbody td > .cell-value,
  .data-table tbody td > .status,
  .data-table tbody td > .mono { text-align: right; overflow-wrap: anywhere; }
  .data-table tbody td.col-run .cell-sub,
  .data-table tbody td.col-health .cell-sub { text-align: right; }
  .data-table .cell-sub.truncate { max-width: none; white-space: normal; }
  .data-table tbody td .tag { white-space: normal; }
}

/* ---------------------------------------------------------- phân trang */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 2px 0;
}
.pagination-info { color: var(--muted); font-size: .78rem; }
.pagination-info b { color: var(--ink); font-variant-numeric: tabular-nums; }
.pagination-actions { display: flex; align-items: center; gap: 8px; }
.page-counter { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.page-jump { display: flex; align-items: center; gap: 5px; }
.page-jump input { width: 72px; min-height: 32px; padding: 4px 8px; font-size: .78rem; }
@media (max-width: 899px) {
  .pagination { flex-direction: column; align-items: stretch; }
  .pagination-actions { justify-content: space-between; flex-wrap: wrap; }
  .pagination-actions .btn { flex: 1 1 auto; }
  .pagination .col-chooser { display: none; }
  .page-jump { display: none; }
}

/* ---------------------------------------------------- sự kiện / nhãn nhỏ */
.event-list { display: flex; flex-wrap: wrap; gap: 5px 10px; }
.event-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: .73rem;
  font-weight: 600;
  white-space: nowrap;
}
.event-item i {
  width: 6px; height: 6px; flex: none; border-radius: 50%; background: currentColor;
}
.event-item.ok { color: var(--ok); }
.event-item.err { color: var(--err); }
.event-item.warn { color: var(--warn); }
.event-item.info { color: var(--info); }
.event-item.muted { color: var(--muted); }

/* ------------------------------------------------------- tab con cuộn */
.seg-wrap { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.seg-wrap .seg-btn { white-space: normal; }
@media (min-width: 700px) {
  .seg-wrap { display: flex; }
  .seg-wrap .seg-btn { flex: 1 1 0; }
}

/* --------------------------------------------------------- tiện ích */
.mobile-only { display: none; }
@media (max-width: 899px) {
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none !important; }
}
.summary-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: center;
  color: var(--muted);
  font-size: .76rem;
}
.summary-line b { color: var(--ink); font-variant-numeric: tabular-nums; }
.section-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--ink);
  font-size: .95rem;
  font-weight: 720;
}
.section-title .count { color: var(--muted); font-weight: 600; }

/* Nút hành động trong bảng nhỏ hơn; form trong bảng vẫn đủ cao. */
.data-table .btn.sm { min-height: 28px; padding: 3px 7px; font-size: .72rem; }
.data-table input[type="text"],
.data-table input[type="number"] { min-height: 30px; padding: 4px 7px; font-size: .78rem; }

/* Ô dữ liệu tiền tệ có nhãn phụ */
.money-stack { display: flex; flex-direction: column; gap: 1px; align-items: flex-end; }
@media (max-width: 899px) {
  .money-stack { align-items: flex-end; }
}

.task-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}
@media (min-width: 640px) {
  .task-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.task-stats > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.task-stats .k { color: var(--muted); font-size: .68rem; font-weight: 650; }
.task-stats .v { color: var(--ink); font-size: .78rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-stats .v.err { color: var(--err); }

/* Nhãn cột dài (nội dung log, lỗi) phải căn trái trên mobile để đọc được. */
@media (max-width: 899px) {
  .data-table tbody td.cell-text { display: block; text-align: left; }
  .data-table tbody td.cell-text::before { display: block; margin-bottom: 2px; }
  .data-table tbody td.cell-text .cell-value { text-align: left; }
  .filters-head.filters-stack .field { flex: 1 1 100%; }
  .filters-head.filters-stack .filter-toggle,
  .filters-head.filters-stack .apply-btn { flex: 1 1 0; }
  .summary-strip .summary-item { padding: 8px 10px; }
}

.data-table th.sortable .sort-arrow { color: var(--brand); font-size: .62rem; margin-left: 3px; }
.data-table th.sorted { color: var(--ink); }

.data-table .col-time { min-width: 132px; white-space: nowrap; }

/* =====================================================================
   Hàng dữ liệu gọn: desktop 1–2 dòng, mobile lưới 2 cột có nhãn nhỏ.
   ===================================================================== */

.data-table tbody td { padding: 7px 10px; }
.data-table .cell-sub { margin-top: 1px; font-size: .7rem; line-height: 1.35; }
.data-table .cell-main { font-size: .87rem; }
.run-line, .health-line { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.run-step {
  color: var(--muted);
  font-size: .72rem;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.health-line .cell-sub { margin-top: 0; }
.account-status-mobile { margin-left: 4px; }
.account-proxy-mobile { display: none; }

@media (max-width: 899px) {
  /* --- Tài khoản: thẻ 2 cột, không lặp nhãn dài --- */
  .accounts-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 14px;
    row-gap: 2px;
    padding: 10px 12px;
  }
  .accounts-table tbody td { display: block; padding: 2px 0; text-align: left; }
  .accounts-table tbody td::before { display: block; margin-bottom: 1px; }
  .accounts-table tbody td.col-account {
    grid-column: 1 / -1;
    padding: 0 28px 5px 0;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--line-soft);
  }
  .accounts-table tbody td.col-run,
  .accounts-table tbody td.col-health,
  .accounts-table tbody td.col-actions { grid-column: 1 / -1; }
  .accounts-table tbody td.col-status,
  .accounts-table tbody td.col-proxy { display: none; }
  .accounts-table tbody td.col-actions {
    margin-top: 4px;
    padding: 7px 0 0;
    border-top: 1px solid var(--line-soft);
  }
  .accounts-table tbody td.col-check { position: absolute; top: 9px; right: 11px; width: auto; padding: 0; }
  .accounts-table tbody td.col-check::before { display: none; }
  .accounts-table .cell-value, .accounts-table .status, .accounts-table .cell-sub { text-align: left; }
  .accounts-table td.num { text-align: left; }
  .accounts-table .cell-sub { font-size: .7rem; }
  .accounts-table .account-status-mobile { display: inline-flex; }
  .accounts-table .account-proxy-mobile { display: block; margin-top: 2px; }
  .accounts-table .run-step { max-width: none; white-space: normal; }

  /* --- Nuôi: thẻ 2 cột --- */
  .farming-table tbody tr {
    display: grid;
    grid-auto-flow: dense;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 14px;
    row-gap: 2px;
    padding: 10px 12px;
  }
  .farming-table tbody td { display: block; padding: 2px 0; text-align: left; }
  .farming-table tbody td::before { display: block; margin-bottom: 1px; }
  .farming-table tbody td.col-account,
  .farming-table tbody td.col-run,
  .farming-table tbody td.col-proxy,
  .farming-table tbody td.col-actions { grid-column: 1 / -1; }
  .farming-table tbody td.col-account {
    padding: 0 0 5px;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--line-soft);
  }
  .farming-table tbody td.col-actions {
    margin-top: 4px;
    padding: 7px 0 0;
    border-top: 1px solid var(--line-soft);
  }
  .farming-table .cell-value, .farming-table .cell-sub { text-align: left; }
  .farming-table .cell-sub { font-size: .7rem; }

  /* --- Proxy: thẻ 2 cột --- */
  .proxies-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 14px;
    row-gap: 2px;
    padding: 10px 12px;
  }
  .proxies-table tbody td { display: block; padding: 2px 0; text-align: left; }
  .proxies-table tbody td::before { display: block; margin-bottom: 1px; }
  .proxies-table tbody td.col-account,
  .proxies-table tbody td.col-actions { grid-column: 1 / -1; }
  .proxies-table tbody td.col-account {
    padding: 0 28px 5px 0;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--line-soft);
  }
  .proxies-table tbody td.col-actions {
    margin-top: 4px;
    padding: 7px 0 0;
    border-top: 1px solid var(--line-soft);
  }
  .proxies-table tbody td.col-check { position: absolute; top: 9px; right: 11px; width: auto; padding: 0; }
  .proxies-table tbody td.col-check::before { display: none; }
  .proxies-table .cell-value, .proxies-table .cell-sub { text-align: left; }
  .proxies-table .cell-sub { font-size: .7rem; }

  /* --- Sự kiện: thẻ 2 cột --- */
  .events-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 14px;
    row-gap: 2px;
    padding: 10px 12px;
  }
  .events-table tbody td { display: block; padding: 2px 0; text-align: left; }
  .events-table tbody td::before { display: block; margin-bottom: 1px; }
  .events-table tbody td.col-account,
  .events-table tbody td[data-label="Sự kiện"] { grid-column: 1 / -1; }
  .events-table tbody td.col-account {
    padding: 0 28px 5px 0;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--line-soft);
  }
  .events-table tbody td.col-check { position: absolute; top: 9px; right: 11px; width: auto; padding: 0; }
  .events-table tbody td.col-check::before { display: none; }
  .events-table .cell-value, .events-table .status, .events-table .cell-sub { text-align: left; }
  .events-table .cell-sub { font-size: .7rem; }

  /* --- Nhật ký: thời gian + chức năng cùng dòng, nội dung chiếm cả dòng --- */
  .logs-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 14px;
    row-gap: 2px;
    padding: 10px 12px;
  }
  .logs-table tbody td { display: block; padding: 2px 0; text-align: left; }
  .logs-table tbody td::before { display: block; margin-bottom: 1px; }
  .logs-table tbody td.col-account { grid-column: 1 / -1; padding-bottom: 5px; border-bottom: 1px solid var(--line-soft); }
  .logs-table tbody td[data-label="Nội dung"] { grid-column: 1 / -1; }
  .logs-table .cell-value, .logs-table .cell-sub { text-align: left; }
}

/* Gọn hơn nữa cho thẻ tài khoản trên mobile: kiểm tra nằm ngay dưới tên. */
@media (max-width: 899px) {
  .accounts-table tbody td.col-health { display: none; }
  .accounts-table tbody td .cell-value,
  .accounts-table tbody td .cell-sub { text-align: left; }
  .accounts-table .account-status-mobile { margin-left: 3px; }
  .accounts-table .account-health-mobile {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 3px;
    white-space: nowrap;
  }
  .accounts-table .account-health-mobile .cell-sub { margin: 0; font-size: .7rem; }
  .accounts-table td.col-account .account-proxy-mobile {
    display: block;
    margin-top: 2px;
    text-align: left;
    color: var(--muted);
  }
  .accounts-table .run-today { margin-left: 0; }
  .accounts-table .run-line { gap: 3px; }
}

/* Trong thẻ mobile của các bảng danh sách, mọi giá trị đều căn trái. */
@media (max-width: 899px) {
  .accounts-table tbody td .cell-main,
  .accounts-table tbody td .cell-value,
  .accounts-table tbody td .cell-sub,
  .farming-table tbody td .cell-main,
  .farming-table tbody td .cell-value,
  .farming-table tbody td .cell-sub,
  .proxies-table tbody td .cell-main,
  .proxies-table tbody td .cell-value,
  .proxies-table tbody td .cell-sub,
  .events-table tbody td .cell-main,
  .events-table tbody td .cell-value,
  .events-table tbody td .cell-sub,
  .logs-table tbody td .cell-main,
  .logs-table tbody td .cell-value,
  .logs-table tbody td .cell-sub { text-align: left; }
}

/* Header tài khoản gọn: badge nằm cùng dòng tên. */
.data-table .cell-main .tag { margin-left: 4px; vertical-align: 1px; font-size: .65rem; padding: 0 6px; }
.accounts-table .account-meta-mobile { display: none; }
.accounts-table .account-money-mobile { display: none; }
.accounts-table .run-short { display: none; }
.accounts-table .account-health-mobile { display: inline-flex; align-items: center; gap: 3px; margin-left: 4px; }
.accounts-table .account-health-mobile .cell-sub { margin: 0; font-size: .7rem; }
@media (max-width: 899px) {
  .accounts-table .account-meta-mobile { display: block; margin-top: 2px; }
  .accounts-table .account-health-mobile .cell-sub { display: inline; }
}

/* Dải tổng quan trên điện thoại: lưới 2 cột, ẩn ô "Tổng" (đã có ở dòng phụ đề). */
@media (max-width: 899px) {
  .summary-strip { gap: 6px; }
  .summary-strip .summary-item { padding: 8px 10px; min-height: 52px; }
  .summary-strip .summary-item .k { font-size: .66rem; white-space: normal; line-height: 1.2; }
  .summary-strip .summary-item strong { font-size: 1.05rem; }
  #health-chips .summary-total { display: none; }
}

@media (max-width: 899px) {
  .accounts-table tbody td .mono,
  .farming-table tbody td .mono,
  .proxies-table tbody td .mono,
  .events-table tbody td .mono,
  .logs-table tbody td .mono { text-align: left; }
}

.log-feature { display: block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulk-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.bulk-row .field { flex: 0 1 220px; min-width: 170px; }
.bulk-row .btn-row { flex: 1 1 auto; }
@media (max-width: 899px) {
  .log-feature { max-width: 100%; }
  .bulk-row .field { flex: 1 1 100%; max-width: none !important; }
}

.sort-metric { color: var(--brand); font-weight: 650; }

/* =====================================================================
   PHA 1 + PHA 2 — Ops Design System (token ngữ nghĩa, vỏ 6 tab,
   HealthStrip, Metric, DataTable, ImpactDialog, Job panel, Settings).
   Mọi màu đi qua token; không thêm hex ngoài bảng 6.2.1.
   ===================================================================== */

/* ---------------------------------------------------------- typography */
body { font-size: var(--font-body); }
.data-table tbody td { font-size: var(--font-table); }
.data-table thead th { font-size: .69rem; }
.btn { font-size: .84rem; }
input, select, textarea { font-size: .86rem; }
@media (max-width: 899px) {
  body { font-size: 15px; }
  .data-table tbody td { font-size: .875rem; }
  .data-table thead th { font-size: .75rem; }
  input, select, textarea, .btn { font-size: .9375rem; }
}

/* Density: compact (desktop mặc định) / comfortable (mobile + tuỳ chọn) */
:root[data-density="compact"] { --row-pad-y: 6px; --card-pad: 12px; --control-h: 32px; }
:root[data-density="comfortable"] { --row-pad-y: 10px; --card-pad: 14px; --control-h: 44px; }
:root[data-density="comfortable"] .data-table tbody td { padding-top: 10px; padding-bottom: 10px; }
:root[data-density="comfortable"] .data-table tbody td { font-size: .875rem; }
@media (max-width: 899px) {
  :root { --control-h: 44px; }
}

/* ------------------------------------------------------------- app shell */
.topbar { gap: 8px; min-height: var(--topbar-h); padding-top: calc(6px + var(--safe-top)); padding-bottom: 6px; }
.brand-mark { width: 32px; height: 32px; }
.topbar-status { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.topbar-status .status { font-size: .76rem; }
.topbar-status .status .dot { width: 7px; height: 7px; }
.freshness {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card-2); color: var(--muted);
  font-size: .7rem; font-weight: 600; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.freshness::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.freshness.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); }
.freshness.warn::before { background: var(--warn); }
.freshness.stale { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.freshness.stale::before { background: var(--warn); }
.emergency-btn {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 34px; padding: 5px 10px;
  border: 1px solid color-mix(in srgb, var(--err) 42%, transparent);
  border-radius: 9px; background: var(--err-soft); color: var(--err);
  font: inherit; font-size: .76rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.emergency-btn:hover { border-color: var(--err); background: color-mix(in srgb, var(--err) 18%, var(--card)); }
.emergency-btn .ico { width: 15px; height: 15px; }
@media (max-width: 640px) {
  .brand-name { display: none; }
  .freshness span { display: none; }
  .freshness { padding: 5px 7px; }
}

/* MỘT hàng tab phẳng — MỌI trang hiện ngay, không còn gom 6 nhóm + subnav.
   14 tab ⇒ chữ .74rem + padding gọn để vừa màn 1280px; hẹp hơn thì ẩn icon
   (nhãn vẫn còn, không mất tên trang) và chỉ cuộn ngang khi thật cần. */
.rail { gap: 2px; padding: 5px 12px; flex-wrap: nowrap; align-items: center; }
.rail a { padding: 6px 8px; font-size: .74rem; border-radius: 9px; min-height: 34px; }
.rail a .ico { width: 14px; height: 14px; }
.rail a[aria-current="page"] { color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand-line); }
.rail-sep { flex: none; width: 1px; height: 18px; margin: 0 5px; background: var(--line); }
@media (max-width: 1279px) {
  .rail a { padding: 6px 7px; gap: 3px; }
  .rail a .ico { display: none; }
}
@media (min-width: 1280px) {
  .rail a { padding: 6px 9px; }
}


/* --------------------------------------------------------- HealthStrip */
.health-strip {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
  margin-bottom: 12px;
}
@media (min-width: 640px) { .health-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .health-strip { grid-template-columns: 1.15fr repeat(3, minmax(0, 1fr)) 1.1fr; } }
.health-cell {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--card); color: var(--ink);
  text-align: left; text-decoration: none; font: inherit;
}
a.health-cell:hover, button.health-cell:hover { border-color: var(--brand-line); text-decoration: none; }
.health-cell .h-top { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: .7rem; font-weight: 650; }
.health-cell .h-top .ico { width: 14px; height: 14px; }
.health-cell .h-value { font-size: 1.06rem; font-weight: 750; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.health-cell .h-sub { color: var(--muted); font-size: .7rem; line-height: 1.35; overflow-wrap: anywhere; }
.health-cell.ok .h-value { color: var(--ok); }
.health-cell.warn { border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); background: color-mix(in srgb, var(--warn) 7%, var(--card)); }
.health-cell.warn .h-value { color: var(--warn); }
.health-cell.err { border-color: color-mix(in srgb, var(--err) 38%, var(--line)); background: color-mix(in srgb, var(--err) 7%, var(--card)); }
.health-cell.err .h-value { color: var(--err); }
.health-cell.info .h-value { color: var(--info); }
.health-cta { display: flex; align-items: stretch; }
.health-cta .btn { width: 100%; min-height: 44px; }
.health-strip.skeleton .health-cell { min-height: 72px; background: var(--card-2); }
.skeleton-line {
  display: block; height: 10px; border-radius: 999px;
  background: linear-gradient(90deg, var(--card-3), var(--card-2), var(--card-3));
  background-size: 200% 100%; animation: fco-skeleton 1.4s linear infinite;
}
.skeleton-line + .skeleton-line { margin-top: 7px; }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w35 { width: 35%; }
@keyframes fco-skeleton { to { background-position: -200% 0; } }

/* ------------------------------------------------------------- metrics */
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 900px) { .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.metric {
  min-width: 0; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card);
}
.metric .m-label { color: var(--muted); font-size: .72rem; font-weight: 650; }
.metric .m-value { margin-top: 2px; font-size: 1.24rem; font-weight: 750; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric .m-unit { font-size: .72rem; color: var(--muted); font-weight: 600; margin-left: 3px; }
.metric .m-sub { margin-top: 2px; color: var(--muted); font-size: .7rem; }
.metric.ok .m-value { color: var(--ok); }
.metric.warn .m-value { color: var(--warn); }
.metric.err .m-value { color: var(--err); }


/* ---------------------------------------------------------- danh sách việc */
.task-list { display: flex; flex-direction: column; gap: 2px; }
.task-row {
  display: flex; align-items: center; gap: 9px; min-height: 44px;
  padding: 8px 2px; border-bottom: 1px solid var(--line-soft);
  color: var(--ink); text-decoration: none; font: inherit; text-align: left;
}
.task-row:last-child { border-bottom: 0; }
.task-row:hover { text-decoration: none; }
.task-row .t-ico {
  width: 26px; height: 26px; flex: none; display: inline-grid; place-items: center;
  border-radius: 8px; background: var(--card-3); color: var(--muted);
}
.task-row .t-ico .ico { width: 15px; height: 15px; }
.task-row.warn .t-ico { background: var(--warn-soft); color: var(--warn); }
.task-row.err .t-ico { background: var(--err-soft); color: var(--err); }
.task-row.ok .t-ico { background: var(--ok-soft); color: var(--ok); }
.task-row .t-main { min-width: 0; flex: 1 1 auto; }
.task-row .t-title { font-weight: 650; font-size: .84rem; overflow-wrap: anywhere; }
.task-row .t-sub { color: var(--muted); font-size: .72rem; line-height: 1.4; overflow-wrap: anywhere; }
.task-row .t-go { color: var(--brand); font-size: .76rem; font-weight: 700; white-space: nowrap; }

/* -------------------------------------------------- trạng thái / rỗng */
.state-empty, .state-error, .state-loading {
  padding: 22px 14px; text-align: center; color: var(--muted); font-size: .84rem;
}
.state-error { color: var(--err); }
.state-empty .state-title { color: var(--ink); font-weight: 700; margin-bottom: 4px; }
.state-empty .btn, .state-error .btn { margin-top: 8px; }
[aria-busy="true"] { cursor: progress; }

/* ---------------------------------------------------------- table frame */
.table-frame { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); overflow-x: auto; }
.table-frame > .data-table { border-radius: inherit; }

/* --------------------------------------------------- command bar / tiles */
.command-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
}
.command-bar .c-main { min-width: 0; flex: 1 1 260px; }
.command-bar .c-title { font-weight: 720; font-size: .95rem; }
.command-bar .c-sub { color: var(--muted); font-size: .76rem; margin-top: 1px; }
.command-bar .c-actions { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.state-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 0 0 10px; }
@media (min-width: 640px) { .state-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .state-tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.state-tiles .summary-item { min-height: 60px; }

/* ------------------------------------------------------------ job panel */
.job-panel {
  position: fixed; left: 12px; bottom: calc(var(--dock-h) + var(--safe-bottom) + 12px);
  z-index: 150; width: min(360px, calc(100vw - 24px));
  padding: 10px 12px; border: 1px solid var(--brand-line); border-radius: 12px;
  background: color-mix(in srgb, var(--card) 96%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: var(--shadow); font-size: .78rem;
}
@media (min-width: 768px) { .job-panel { left: 18px; bottom: 18px; } }
.job-panel-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.job-panel-head strong { font-size: .82rem; }
.job-panel .job-meta { color: var(--muted); font-size: .72rem; margin-top: 3px; line-height: 1.4; }
.job-panel .progress { margin-top: 7px; height: 6px; }
.job-panel .job-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.job-panel .job-warn { color: var(--warn); font-size: .72rem; margin-top: 5px; }

/* -------------------------------------------------------- impact dialog */
dialog.modal.impact-dialog { width: min(620px, 94vw); }
.impact-count { font-size: 1.6rem; font-weight: 800; line-height: 1.15; color: var(--strong); font-variant-numeric: tabular-nums; }
.impact-count.err { color: var(--err); }
.impact-warn { margin-top: 8px; padding: 8px 10px; border-radius: 9px; border: 1px solid color-mix(in srgb, var(--err) 35%, transparent); background: var(--err-soft); color: var(--err); font-size: .8rem; }
.impact-sample { margin: 8px 0 0; padding-left: 18px; columns: 2; column-gap: 20px; color: var(--muted); font-size: .78rem; }
@media (max-width: 520px) { .impact-sample { columns: 1; } }
.impact-cons { margin-top: 9px; color: var(--ink); font-size: .82rem; line-height: 1.5; }
.impact-confirm { margin-top: 10px; }
.impact-confirm label { display: block; color: var(--muted); font-size: .76rem; margin-bottom: 4px; }
.impact-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.safety-options { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.safety-option {
  display: flex; gap: 9px; align-items: flex-start; text-align: left;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card-2); color: var(--ink); font: inherit; cursor: pointer;
}
.safety-option:hover { border-color: var(--brand-line); }
.safety-option strong { display: block; font-size: .86rem; }
.safety-option span { color: var(--muted); font-size: .76rem; line-height: 1.4; }
.safety-option.danger { border-color: color-mix(in srgb, var(--err) 35%, var(--line)); }
.safety-option.danger strong { color: var(--err); }

/* --------------------------------------------------------- detail tabs */
.detail-tabs {
  display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none;
  padding: 3px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--card);
}
.detail-tabs::-webkit-scrollbar { display: none; }
.detail-tab {
  flex: 0 0 auto; min-height: 40px; padding: 7px 12px;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  font: inherit; font-size: .8rem; font-weight: 700; white-space: nowrap; cursor: pointer;
}
.detail-tab:hover { color: var(--ink); background: var(--card-2); }
.detail-tab[aria-selected="true"] { color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand-line); }
.detail-panel[hidden] { display: none !important; }

/* Tab “Kho cầu thủ / Lệnh bán” chỉ có ở màn hình hẹp — desktop vẫn 2 cột như cũ */
.seg.asset-switch { display: none; }
@media (max-width: 899px) {
  .seg.asset-switch { display: flex; }
  .grid.c2 > [data-asset-card].asset-off { display: none; }
}

/* Icon trạng thái bán cạnh tên cầu thủ (đỏ = khó bán, vàng = giá chưa chuẩn) */
.sell-flag {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 5px; vertical-align: middle; flex: 0 0 auto;
}
.sell-flag.flag-err { background: var(--err); box-shadow: 0 0 0 2px var(--err-soft); }
.sell-flag.flag-info { background: var(--info); box-shadow: 0 0 0 2px var(--info-soft); }
.flag-legend { margin: 2px 0 6px; line-height: 1.6; }
.flag-legend .sell-flag { margin-left: 8px; }
.diagnosis-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
@media (min-width: 900px) { .diagnosis-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.diagnosis-card { min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card-2); }
.diagnosis-card .d-title { color: var(--muted); font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.diagnosis-card .d-main { margin-top: 3px; font-size: .88rem; font-weight: 700; overflow-wrap: anywhere; }
.diagnosis-card .d-sub { margin-top: 2px; color: var(--muted); font-size: .74rem; line-height: 1.45; overflow-wrap: anywhere; }

/* ------------------------------------------------------------- settings */
.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
@media (min-width: 1000px) { .settings-layout { grid-template-columns: 250px minmax(0, 1fr); } }
.settings-index {
  position: sticky; top: calc(var(--topbar-h) + var(--nav-h) + 10px);
  padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  display: flex; flex-direction: column; gap: 7px;
}
.settings-index .field { margin: 0; }
.settings-index .idx-list { display: flex; flex-direction: column; gap: 1px; max-height: 60vh; overflow: auto; }
.settings-index .idx-list a { padding: 6px 8px; border-radius: 7px; color: var(--muted); font-size: .78rem; font-weight: 600; text-decoration: none; }
.settings-index .idx-list a:hover { color: var(--ink); background: var(--card-2); }
.settings-index .idx-count { color: var(--text-3); font-weight: 500; }
.risk-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.risk-chip {
  min-height: 34px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card-2); color: var(--muted); font: inherit; font-size: .74rem; font-weight: 650; cursor: pointer;
}
.risk-chip.on { border-color: var(--brand-line); background: var(--brand-soft); color: var(--brand); }
.risk-chip[data-risk="C"].on, .risk-chip[data-risk="C"]:hover { border-color: color-mix(in srgb, var(--err) 45%, var(--line)); color: var(--err); background: var(--err-soft); }
.settings-group { scroll-margin-top: calc(var(--topbar-h) + var(--nav-h) + 10px); }
.settings-group[hidden] { display: none !important; }
.settings-group > summary {
  display: flex; align-items: center; gap: 8px; min-height: 44px;
  font-size: .95rem; font-weight: 720; color: var(--ink); cursor: pointer; list-style: none;
}
.settings-group > summary::-webkit-details-marker { display: none; }
.settings-group > summary .g-count { color: var(--muted); font-weight: 600; font-size: .76rem; }
.settings-group > summary .g-chev { margin-left: auto; color: var(--muted); }
.settings-rows { padding-top: 2px; }
.setting-row { position: relative; }
.setting-row[hidden] { display: none !important; }
.setting-row.risk-C { border-left: 3px solid var(--err); padding-left: 10px; }
.setting-row.risk-B { border-left: 3px solid var(--warn); padding-left: 10px; }
.setting-row.risk-A { border-left: 3px solid var(--ok); padding-left: 10px; }
.setting-risk { font-size: .66rem; padding: 0 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.risk-C .setting-risk { border-color: color-mix(in srgb, var(--err) 40%, var(--line)); color: var(--err); }
.risk-B .setting-risk { border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); color: var(--warn); }
.setting-advanced { margin-top: 4px; }
.setting-advanced > summary { font-size: .7rem; color: var(--text-3); }
.setting-advanced code { font-size: .7rem; }
.setting-impact { margin-top: 4px; color: var(--muted); font-size: .72rem; line-height: 1.45; }
.setting-impact strong { color: var(--ink); }
.settings-savebar {
  position: sticky; bottom: calc(var(--dock-h) + var(--safe-bottom) + 8px); z-index: 25;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 11px;
  background: color-mix(in srgb, var(--card) 95%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: var(--shadow);
}
@media (min-width: 768px) { .settings-savebar { bottom: 12px; } }
.settings-savebar .s-summary { flex: 1 1 240px; min-width: 0; font-size: .78rem; color: var(--muted); }
.settings-savebar .s-summary strong { color: var(--warn); }
.settings-savebar .s-summary .s-diff { color: var(--ink); font-family: ui-monospace, Menlo, monospace; font-size: .72rem; overflow-wrap: anywhere; }

/* ------------------------------------------------------- touch ergonomics */
.icon-btn { width: 44px; height: 44px; }
@media (max-width: 767px) {
  .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; }
  .icon-btn { width: 44px; height: 44px; }
  .link-btn { min-height: 44px; padding: 10px 0; align-items: center; }
  .check { min-height: 44px; }
  .check input { width: 22px; height: 22px; }
  input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; }
  .tag.chipbtn { min-height: 36px; padding: 6px 10px; }
  .seg-btn { min-height: 40px; }
  .hint-details > summary { width: 24px; height: 24px; font-size: .72rem; }
  .dock-item { min-height: 52px; }
  .pagination-actions .btn { min-height: 40px; }
  .page-jump input { min-height: 40px; }
}
.summary-item { min-height: 44px; }
.tag.chipbtn { min-height: 32px; padding: 4px 9px; }
.seg-btn { min-height: 40px; }
.hint-details > summary { width: 24px; height: 24px; font-size: .72rem; }

/* --------------------------------------------------------- word wrapping */
.data-table td, .data-table .cell-sub, .data-table .mono,
.mono, .logrow-msg, .feat-meta > span, .kv-row .v, .impact-cons,
.impact-sample, .job-panel .job-meta, .setting-impact {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.log-feature { overflow-wrap: anywhere; }

/* --------------------------------------------------------- mobile cards */
@media (max-width: 899px) {
  .data-table tbody tr { padding: 10px 11px; border-radius: 11px; }
  .data-table tbody td { padding: 3px 0; }
  .data-table tbody td::before { flex-basis: 88px; font-size: .7rem; }
  .data-table tbody td.col-account { padding-bottom: 6px; margin-bottom: 3px; }
  .data-table tbody td.col-actions { padding-top: 7px; margin-top: 4px; }
  .accounts-table tbody tr { row-gap: 0; padding: 9px 11px; }
  .accounts-table tbody td.col-account { padding-bottom: 4px; }
  .accounts-table tbody td.col-actions { padding-top: 5px; margin-top: 2px; }
  .farming-table tbody tr { padding: 9px 11px; }
  .farming-table tbody td.col-account { padding-bottom: 4px; }
  .farming-table tbody td.col-actions { padding-top: 5px; margin-top: 2px; }
  .summary-strip .summary-item { min-height: 56px; }
  .health-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .health-cta { grid-column: 1 / -1; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .settings-index { position: static; order: -1; }
  .settings-index .idx-list { flex-direction: row; flex-wrap: wrap; max-height: none; }
  .settings-index .idx-list a { border: 1px solid var(--line); }
}

@media (max-width: 400px) {
  main { padding-inline: 10px; }
  .topbar { padding-inline: 10px; }
  .health-strip { gap: 6px; }
  .health-cell { padding: 8px 9px; }
  .health-cell .h-value { font-size: .98rem; }
  .health-cell .h-top { font-size: .66rem; }
  .health-cell .h-sub { font-size: .66rem; }
  .data-table tbody td::before { flex-basis: 78px; }
  .summary-item strong { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-line { animation: none; }
}

/* --------------------------------------------------- gọn hoá mobile (đo 390) */
@media (max-width: 899px) {
  /* Density "comfortable" không được phình bảng trên điện thoại. */
  :root[data-density="comfortable"] .data-table tbody td {
    padding-top: 3px;
    padding-bottom: 3px;
  }
  :root[data-density="comfortable"] .data-table tbody td { font-size: .82rem; }

  /* Tài khoản: MỘT dòng/tài khoản — tên · BP · cầu thủ · lần chạy · icon.
     Bỏ 2 cột .col-money, dồn tiền vào dòng tên để màn hẹp hiện được nhiều tài khoản. */
  .accounts-table .col-money { display: none; }
  .accounts-table .run-today { display: none; }
  .accounts-table tbody { gap: 5px; }
  .accounts-table tbody tr {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    row-gap: 0;
    padding: 2px 6px;
    border-radius: 9px;
  }
  .accounts-table tbody td { display: block; padding: 0; border: 0; }
  .accounts-table tbody td::before { display: none; }
  /* Cột tuỳ chọn Cấp/FC/SP không chen vào dòng 1 hàng (xem ở trang chi tiết). */
  .accounts-table tbody td.col-extra { display: none; }
  .accounts-table tbody td.col-check { order: -1; position: static; width: auto; padding: 0; }
  .accounts-table tbody td.col-check input { width: 16px; height: 16px; margin: 0; }
  .accounts-table tbody td.col-account {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: baseline;
    gap: 0 6px;
    padding: 0;
    margin: 0;
    border: 0;
  }
  .accounts-table tbody td.col-account .cell-main {
    flex: 1 1 auto;
    min-width: 0;
    font-size: .78rem;
    line-height: 1.35;
  }
  .accounts-table tbody td.col-account .cell-main a {
    display: block;
    min-height: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .accounts-table .account-money-mobile {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: baseline;
    gap: 5px;
    margin: 0;
    font-size: .64rem;
    white-space: nowrap;
  }
  .accounts-table .account-money-mobile .money-pair {
    display: inline-flex;
    align-items: baseline;
    gap: 2px;
    min-width: 0;
  }
  .accounts-table .account-money-mobile .k {
    color: var(--muted);
    font-size: .56rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .02em;
  }
  .accounts-table .account-money-mobile .money {
    color: var(--ink);
    font-size: .68rem;
    font-weight: 750;
  }
  /* Chỉ khi chọn sắp xếp theo Cấp/FC/SP mới có dòng phụ; màn hẹp ẩn để giữ 1 dòng
     (thứ tự danh sách vẫn phản ánh tiêu chí, số liệu xem ở trang chi tiết). */
  .accounts-table .sort-metric { display: none; }
  .accounts-table tbody td.col-run {
    flex: 0 0 30px;
    min-width: 0;
    overflow: hidden;
    font-size: .62rem;
    color: var(--muted);
    text-align: right;
    white-space: nowrap;
  }
  .accounts-table tbody td.col-run .status { font-size: .62rem; gap: 3px; }
  .accounts-table tbody td.col-run .status .dot { width: 5px; height: 5px; }
  .accounts-table .run-long { display: none; }
  .accounts-table .run-short { display: inline; }
  .accounts-table tbody td.col-actions {
    flex: 0 0 auto;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }
  .accounts-table tbody td.col-actions .row-actions { gap: 1px; }
  .accounts-table tbody td.col-actions .icon-act { width: 19px; height: 19px; }
  .accounts-table tbody td.col-actions .icon-act .ico { width: 13px; height: 13px; }

  /* Nuôi: proxy gộp vào dòng tên; bỏ cột Bắt đầu. */
  .farming-table .col-proxy { display: none; }
  .farming-table tbody td[data-label="Bắt đầu"] { display: none; }
  .farming-table .account-proxy-mobile { display: block; margin-top: 1px; color: var(--muted); }
  .farming-table tbody td.col-account .cell-main a { display: inline-flex; align-items: center; min-height: 32px; }

  /* Health chips: trang Tài khoản chỉ còn tổng + nhóm lỗi (khoá / sai pass 2 / không tồn tại)
     — luôn hiện đủ, không cắt bớt trên điện thoại. */

  /* Nuôi: 4 ô quyết định (chạy/chờ/xong/lỗi) đều được hiện — mỗi ô chỉ là 1 chip. */

  /* Tuỳ chọn chạy: thu gọn sau nút “Tuỳ chọn” ở command bar. */
  #farm-options-card { display: none; }
  #farm-options-card.open { display: block; }

  .command-bar { padding: 8px 10px; }
  .command-bar .c-actions .btn { flex: 1 1 auto; }
  .command-bar .c-actions .btn.danger { display: none; }
  .page-head .page-actions .desktop-only { display: none; }
}

@media (max-width: 899px) {
  #farm-options-card.open #farm-options { display: block; }
}

/* Mobile gọn hơn nữa: command bar 1 hàng, ẩn bớt cột phụ của Nuôi. */
@media (max-width: 899px) {
  .command-bar { flex-wrap: nowrap; align-items: center; }
  .command-bar .c-main { flex: 1 1 auto; }
  .command-bar .c-actions { flex: 0 0 auto; }
  .command-bar .c-actions .btn { flex: 0 0 auto; }
  #btn-pause-safe { display: none; }
  .page-actions .btn { min-height: 44px; }
  #farming-summary .summary-line { display: none; }
  .farming-table .col-status[data-label="Trạng thái"],
  .farming-table .col-actions { display: none; }
  .farming-table .account-status-mobile { display: inline-flex; }
}

/* Mobile: Worker & Proxy trước danh sách việc (nguyên nhân gốc trước hậu quả). */
@media (max-width: 899px) {
  .dashboard-priority #worker-card { order: 1; }
  .dashboard-priority #task-card { order: 2; }
}

.safety-option.on {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: inset 0 0 0 1px var(--brand-line);
}
body.login-page .emergency-btn,
body.login-page .freshness { display: none; }

/* ------------------------------------------------------- Phase 3 shared */
.command-dialog { width: min(620px, 94vw); }
.command-dialog #command-input { margin: 2px 0 10px; }
.command-list { display: flex; flex-direction: column; gap: 3px; max-height: min(52vh, 420px); overflow: auto; }
.command-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 44px; padding: 8px 10px; border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--ink); font: inherit; font-size: .84rem; text-align: left; cursor: pointer;
}
.command-item:hover, .command-item.on { border-color: var(--brand-line); background: var(--brand-soft); }
.command-item small { color: var(--muted); font-size: .7rem; white-space: nowrap; }
.command-dialog .meta-line { margin-top: 10px; }
.login-password-wrap { position: relative; }
.login-password-wrap input { padding-right: 48px; }
.login-password-wrap .icon-btn { position: absolute; right: 2px; top: 2px; width: 38px; height: 38px; border: 0; background: transparent; }
.caps-warn { margin-top: 4px; color: var(--warn); font-size: .74rem; }
.login-note { margin-top: 10px; color: var(--muted); font-size: .74rem; line-height: 1.45; }
.audit-json { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--field); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; font-size: .72rem; }
.preflight {
  margin-top: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--card-2); color: var(--muted); font-size: .78rem;
}
.preflight strong { color: var(--ink); }
.sc-impact { margin: 8px 0 0; padding: 8px 10px; border: 1px solid var(--brand-line); border-radius: 9px; background: var(--brand-soft); color: var(--ink); font-size: .78rem; }
.proxy-ratio { color: var(--muted); font-size: .7rem; }
.live-steps { margin-top: 8px; }
.live-steps > summary { font-size: .78rem; }
@media (max-width: 899px) {
  .command-dialog { width: 96vw; }
  .login-password-wrap .icon-btn { width: 44px; height: 44px; }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Phase 3 — gọn mobile cho Proxy và Nhật ký */
@media (max-width: 899px) {
  .proxies-table tbody td[data-label="Đầu ra"],
  .proxies-table tbody td[data-label="Kiểm tra"] { display: none; }
  .proxies-table .proxy-exit-mobile { display: block; margin-top: 2px; }
  .proxies-table tbody tr { padding: 9px 11px; }
  .proxies-table tbody td { padding: 2px 0; }

  .logs-table tbody tr { display: block; padding: 9px 11px; }
  .logs-table tbody td { display: inline; padding: 0; border: 0; font-size: .82rem; }
  .logs-table tbody td::before { display: none; }
  .logs-table tbody td.col-account { display: block; margin-bottom: 2px; }
  .logs-table tbody td.col-time { margin-right: 8px; }
  .logs-table tbody td.col-status { margin-right: 8px; }
  .logs-table tbody td.cell-text { display: block; margin-top: 3px; }
  .logs-table .cell-main, .logs-table .cell-value { display: inline; }
  .logs-table .cell-sub { display: inline; }
  .logs-table tbody td .link-btn { min-height: 28px; padding: 2px 0; }
}
.proxy-exit-mobile { display: none; }

/* Màn rất hẹp (<360px, iPhone 5/SE cũ): không đủ chỗ cho tên + 2 số tiền trên
   một hàng — cho tên chiếm trọn dòng 1, tiền xuống dòng 2 để không bị cắt cụt. */
@media (max-width: 359px) {
  .accounts-table tbody td.col-account { flex-wrap: wrap; }
  .accounts-table tbody td.col-account .cell-main { flex: 1 0 100%; }
}

/* ================================================ tài khoản: menu 3 chấm (mobile)
   4 icon hành động của mỗi dòng gom vào 1 nút ⋮ để dòng tài khoản chỉ còn
   [checkbox] tên · BP · CT · lần chạy · ⋮. Desktop vẫn hiện 4 icon như cũ. */
.accounts-table .row-menu-toggle {
  display: none; background: transparent; border: 0; padding: 0;
  color: var(--muted); cursor: pointer;
}
.accounts-table .row-menu-toggle:hover { color: var(--brand); background: var(--card-2); }
.row-menu-pop {
  position: fixed; z-index: 80; min-width: 172px; padding: 4px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  box-shadow: var(--shadow);
}
.row-menu-pop[hidden] { display: none !important; }
.row-menu-item {
  display: flex; align-items: center; width: 100%; min-height: 36px;
  padding: 6px 10px; border: 0; border-radius: 7px;
  background: transparent; color: var(--ink);
  font: inherit; font-size: .82rem; font-weight: 600; text-align: left;
  cursor: pointer;
}
.row-menu-item:hover, .row-menu-item:focus-visible { background: var(--card-2); }
.row-menu-item.danger { color: var(--err); }

@media (max-width: 899px) {
  .accounts-table .row-actions { display: none; }
  .accounts-table tbody td.col-actions .row-menu-toggle {
    display: inline-flex; width: 24px; height: 24px;
  }
  .accounts-table tbody td.col-actions .row-menu-toggle .ico { width: 16px; height: 16px; }
}

/* ======================================= chi tiết tài khoản: gọn cho điện thoại
   Yêu cầu 02/11: danh sách cầu thủ (tên + giá) nhỏ hơn để thấy nhiều dòng hơn,
   nút quay lại nhỏ, khối Tài sản + tab + thẻ Kho/Lệnh bán không chiếm diện tích. */
@media (max-width: 899px) {
  .detail-head { margin-bottom: 8px; gap: 8px; flex-wrap: nowrap; align-items: flex-start; }
  .detail-head .page-title-wrap { flex: 1 1 auto; min-width: 0; }
  .detail-head .page-actions { flex: 0 0 auto; }
  .detail-head h1 { font-size: 1.08rem; }
  .detail-head .page-sub { margin-top: 2px; font-size: .72rem; }
  .page-head .page-actions .detail-back {
    min-height: 30px; padding: 3px 9px; font-size: .76rem; border-radius: 8px;
  }

  #acc-tabs { margin-bottom: 8px; padding: 2px; gap: 2px; border-radius: 9px; }
  #acc-tabs .detail-tab { min-height: 30px; padding: 4px 9px; font-size: .73rem; border-radius: 7px; }

  #acc-info { padding: 7px 9px; margin-bottom: 8px; border-radius: 10px; }
  #acc-info .diagnosis-grid { gap: 6px; }
  #acc-info .diagnosis-card { padding: 5px 8px; border-radius: 8px; }
  #acc-info .diagnosis-card .d-title { font-size: .58rem; }
  #acc-info .diagnosis-card .d-main { margin-top: 1px; font-size: .78rem; }
  #acc-info .diagnosis-card .d-sub { margin-top: 1px; font-size: .64rem; }
  #acc-info .setting-advanced { margin-top: 3px !important; }
  #acc-info .setting-advanced > summary { min-height: 26px; font-size: .72rem; }

  .seg.asset-switch { margin-bottom: 7px; padding: 2px; border-radius: 9px; }
  .seg.asset-switch .seg-btn { min-height: 30px; padding: 4px 8px; font-size: .73rem; }

  .detail-panel .grid.c2 { gap: 8px; }
  .detail-panel [data-asset-card] { padding: 7px 8px; margin-bottom: 0; border-radius: 10px; }
  .detail-panel [data-asset-card] .card-head { margin-bottom: 2px; }
  .detail-panel [data-asset-card] .card-head h2 { font-size: .82rem; }
  .detail-panel [data-asset-card="lenh"] h3 { margin: 2px 0 2px !important; font-size: .64rem; }
  #inventory-stats, #inventory-note { font-size: .62rem; }
  .flag-legend { margin: 0 0 3px; font-size: .62rem; line-height: 1.35; }

  /* Một dòng/cầu thủ: tên + badge mùa/vị trí/thẻ/OVR + giá; chữ và badge nhỏ lại. */
  #inventory table.stack tr,
  #orders-sell table.stack tr,
  #orders-buy table.stack tr { padding: 2px 7px; gap: 6px; align-items: center; }
  #inventory table.stack td,
  #orders-sell table.stack td,
  #orders-buy table.stack td { padding: 0; font-size: .7rem; line-height: 1.2; }
  #inventory table.stack td.col-account,
  #orders-sell table.stack td.col-account,
  #orders-buy table.stack td.col-account {
    display: flex; align-items: center; gap: 5px; min-width: 0; justify-content: flex-start;
  }
  #inventory table.stack td.col-account .cell-main,
  #orders-sell table.stack td.col-account .cell-main,
  #orders-buy table.stack td.col-account .cell-main {
    flex: 0 1 auto; min-width: 0; font-size: .74rem; font-weight: 650; line-height: 1.25;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  #inventory table.stack td.col-account .cell-sub,
  #orders-sell table.stack td.col-account .cell-sub,
  #orders-buy table.stack td.col-account .cell-sub {
    flex: 0 0 auto; display: inline-flex; align-items: center; gap: 3px;
    margin: 0; font-size: .6rem; line-height: 1.1;
  }
  #inventory table.stack td.num,
  #orders-sell table.stack td.num,
  #orders-buy table.stack td.num { font-size: .7rem; font-weight: 650; justify-content: flex-end; }

  /* Badge thu nhỏ giữ đúng tỉ lệ sprite (background-size theo cùng tỉ lệ).
     06/11: `#sell-history` vào cùng nhóm — lịch sử bán nay dùng đúng bộ badge
     mùa/vị trí/thẻ/OVR như bảng Kho nên phải thu nhỏ y nhau trên điện thoại. */
  #inventory .season-badge,
  #orders-sell .season-badge,
  #orders-buy .season-badge,
  #sell-history .season-badge { width: 22px; height: 18px; background-size: 396px 176px; border-radius: 2px; }
  #inventory .season-chip,
  #orders-sell .season-chip,
  #orders-buy .season-chip,
  #sell-history .season-chip { font-size: .55rem; padding: 0 3px; }
  #inventory .badgedgrade,
  #orders-sell .badgedgrade,
  #orders-buy .badgedgrade,
  #sell-history .badgedgrade { width: 22px; height: 14px; flex: 0 0 22px; min-width: 22px; background-size: 22px 190px; }
  #inventory .fco-pos-badge, #inventory .fco-ovr-badge,
  #orders-sell .fco-pos-badge, #orders-sell .fco-ovr-badge,
  #orders-buy .fco-pos-badge, #orders-buy .fco-ovr-badge,
  #sell-history .fco-pos-badge, #sell-history .fco-ovr-badge {
    min-width: 22px; height: 15px; padding: 0 4px; font-size: 9px; border-radius: 3px;
  }
  #inventory .sell-flag, #orders-sell .sell-flag, #orders-buy .sell-flag {
    width: 7px; height: 7px; margin-right: 3px;
  }
}

/* ============================================ lịch sử bán (giống Kho & lệnh bán) */
.sales-filters {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-left: auto;
}
.sales-filters input,
.sales-filters select {
  width: auto; min-height: 30px; padding: 3px 8px; font-size: .76rem;
}
.sales-filters input { width: 112px; }
.sales-filters select {
  padding-right: 26px;
  background-position: calc(100% - 13px) 12px, calc(100% - 8px) 12px;
}
#sell-history table.stack td.when,
#sell-history table.stack .cell-sub { white-space: nowrap; }
#sell-history .cell-sub { display: inline-flex; align-items: center; gap: 3px; }

/* ================================================== mật độ hiển thị mobile
   Yêu cầu 03/11: nút bấm, nhãn đếm (đang chờ/đã xong/bị lỗi/đang sống…),
   danh sách tài khoản tab Nuôi và tab Lịch sử bán đều nhỏ gọn để một màn hình
   điện thoại hiện được nhiều nội dung. Đặt CUỐI file để thắng khối
   "touch ergonomics" phía trên (min-height 44px). */
.farming-table .farming-line { display: none; }
.locked-name { color: var(--err); text-decoration: line-through; }
#acc-name .tag { font-size: .66rem; padding: 1px 7px; vertical-align: middle; }

@media (max-width: 899px) {
  /* ---- nút: đồng hoá nhỏ gọn ở mọi trang ---- */
  .btn { min-height: 30px; padding: 4px 9px; font-size: .76rem; border-radius: 8px; }
  .btn .ico { width: 14px; height: 14px; }
  .btn.sm { min-height: 28px; padding: 3px 8px; font-size: .73rem; }
  .btn-row { gap: 5px; }
  .page-head { gap: 6px; }
  .page-actions { gap: 5px; flex-wrap: wrap; }
  .page-actions .btn { flex: 0 0 auto; min-height: 30px; }
  .btn-row .btn { flex: 0 0 auto; }
  .card-head { gap: 5px; }
  .card-head h2 { font-size: .92rem; }
  .link-btn { min-height: 22px; padding: 2px 0; align-items: center; }
  .pagination-actions .btn { flex: 0 0 auto; }

  /* ---- nhãn đếm: chip 1 dòng thay cho ô cao 56–60px ---- */
  .summary-strip,
  #farming-summary .state-tiles { display: flex; flex-wrap: wrap; gap: 4px; }
  .summary-strip .summary-item,
  #farming-summary .state-tiles .summary-item {
    flex: 0 1 auto;
    flex-direction: row;
    align-items: baseline;
    gap: 4px;
    min-height: 0;
    padding: 2px 8px;
    border-radius: 999px;
  }
  .summary-item .k { font-size: .62rem; }
  .summary-item strong { font-size: .76rem; }
  #farming-summary .state-tiles { margin: 4px 0 6px; }
  #health-chips { gap: 4px; }

  /* ---- Nuôi: mỗi tài khoản MỘT hàng gọn như tab Tài khoản ---- */
  .farming-table tbody { gap: 4px; }
  .farming-table tbody tr {
    display: flex; flex-wrap: nowrap; align-items: center; gap: 4px;
    padding: 2px 6px; border-radius: 9px;
  }
  .farming-table tbody td { display: block; padding: 0; border: 0; }
  .farming-table tbody td::before { display: none; }
  .farming-table tbody td.col-account {
    flex: 1 1 auto; min-width: 0;
    display: flex; flex-wrap: nowrap; align-items: center;
    gap: 0 5px; padding: 0; margin: 0; border: 0;
  }
  .farming-table tbody td.col-account .cell-main {
    flex: 0 1 auto; min-width: 0; font-size: .78rem; line-height: 1.35;
  }
  .farming-table tbody td.col-account .cell-main a {
    display: block; min-height: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .farming-table .farming-sub,
  .farming-table .account-proxy-mobile { display: none; }
  .farming-table .farming-line {
    display: flex; flex: 1 1 auto; min-width: 0; align-items: center; gap: 4px;
    overflow: hidden; white-space: nowrap; color: var(--muted); font-size: .62rem;
  }
  .farming-table .farming-line .status { flex: none; font-size: .62rem; gap: 3px; }
  .farming-table .farming-line .status .dot { width: 5px; height: 5px; }
  .farming-table .farming-today { flex: none; font-variant-numeric: tabular-nums; }
  .farming-table .farming-step {
    flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  }
  /* Các cột còn lại đã gộp vào dòng mobile (trạng thái/bước/mốc bắt đầu/proxy).
     Cần đủ `tbody td` để thắng `.data-table tbody td.cell-text|td.col-actions`
     (cùng 2 class nhưng thêm 2 thẻ ⇒ specificity cao hơn). */
  .farming-table tbody td.col-status,
  .farming-table tbody td.col-run,
  .farming-table tbody td.col-proxy,
  .farming-table tbody td.col-actions { display: none; }

  /* ---- Lịch sử bán: bỏ nhãn mô tả, mỗi lệnh một hàng gọn ---- */
  #sell-history table.stack tr {
    display: flex; align-items: baseline; gap: 6px; padding: 2px 7px;
  }
  #sell-history table.stack td { display: block; padding: 0; border: 0; font-size: .7rem; }
  #sell-history table.stack td::before { display: none; }
  #sell-history table.stack td.col-account {
    flex: 1 1 auto; min-width: 0;
    display: flex; align-items: baseline; gap: 5px; justify-content: flex-start;
  }
  #sell-history table.stack td.col-account .cell-main {
    flex: 0 1 auto; min-width: 0; font-size: .72rem; font-weight: 650;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  #sell-history table.stack td.col-account .cell-sub {
    /* 06/11: cùng kiểu dòng phụ badge như `#inventory … .cell-sub` (inline-flex,
       không margin, .6rem) — lịch sử bán dùng đúng badge mùa/vị trí/thẻ/OVR. */
    flex: 0 0 auto; display: inline-flex; align-items: center; gap: 3px;
    margin: 0; font-size: .6rem; line-height: 1.1; white-space: nowrap;
  }
  #sell-history table.stack td.num { flex: 0 0 auto; text-align: right; font-weight: 650; }
  #sell-history table.stack td.when { flex: 0 0 auto; color: var(--muted); }

  /* ---- Chi tiết tài khoản: tên + nhãn + tài sản trên dòng gọn ---- */
  #acc-name { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
  #acc-info .diagnosis-card .d-main { font-size: .74rem; line-height: 1.45; }
  /* Bỏ dòng breadcrumb "← Tài khoản / Chi tiết" (đã có nút "← Danh sách"). */
  .detail-head .page-title-wrap > .muted.small { display: none; }
  /* 5 tab phải vừa 1 hàng: thu padding/cỡ chữ. */
  #acc-tabs { gap: 2px; padding: 2px; }
  #acc-tabs .detail-tab { padding: 3px 6px; font-size: .68rem; min-height: 28px; }
  #inventory table.stack td.col-account .cell-sub .mono { font-size: .58rem; }
}

/* Màn rất hẹp (<360px, iPhone SE đời cũ): bỏ phần ít quan trọng để dòng Nuôi
   vẫn nằm gọn 1 hàng. */
@media (max-width: 359px) {
  .farming-table .farming-today { display: none; }
}

/* =====================================================================
   Tổng quan — PHÂN BỔ TÀI KHOẢN THEO SỐ DƯ BP
   Biểu đồ cột ngang: mỗi hàng = một mức BP (bậc), độ dài cột = số tài khoản.
   Đặt ở CUỐI file để các luật thu nhỏ mobile ở trên không đè mất.
   ===================================================================== */
.dist-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dist-field {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: .74rem; font-weight: 650;
}
.dist-field select {
  width: auto; min-height: 30px; padding: 3px 24px 3px 8px; font-size: .78rem;
  background-position: calc(100% - 13px) 13px, calc(100% - 8px) 13px;
}
.dist-check {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  color: var(--muted); font-size: .74rem; font-weight: 650;
}
.dist-check input[type="checkbox"] { width: 15px; height: 15px; }

.dist-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

/* Khoản thiệt hại của tài khoản bị khoá/banned: KHÔNG nằm trong các tổng ở trên. */
.asset-loss {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px;
  margin-top: 10px; padding: 6px 10px; border-radius: 8px;
  background: var(--warn-soft);
  color: var(--ink); font-size: .76rem;
}
.asset-loss-title { font-weight: 700; color: var(--warn); }
.asset-loss-item { color: var(--muted); }
.asset-loss-item strong { color: var(--ink); font-weight: 750; font-variant-numeric: tabular-nums; }

.dist-chip {
  display: inline-flex; align-items: baseline; gap: 6px; min-width: 0;
  padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card-2); color: var(--muted); font-size: .72rem;
}
.dist-chip .k { font-weight: 650; white-space: nowrap; }
.dist-chip .n { color: var(--text-3); font-size: .68rem; white-space: nowrap; }
.dist-chip strong {
  color: var(--ink); font-weight: 750; font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.dist-list { display: flex; flex-direction: column; gap: 3px; max-height: 430px; overflow-y: auto; }
.dist-row {
  display: grid; grid-template-columns: 100px minmax(0, 1fr) 58px 50px;
  align-items: center; gap: 8px;
  min-height: 24px; padding: 3px 4px; border-radius: 7px;
}
.dist-row:hover { background: var(--row-hover); }
.dist-row .d-label {
  color: var(--muted); font-size: .76rem; font-weight: 650;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.dist-row .d-track { height: 9px; border-radius: 999px; background: var(--card-3); overflow: hidden; }
.dist-row .d-fill {
  height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--brand) 45%, var(--info)), var(--brand));
  transition: width .25s ease;
}
.dist-row .d-count {
  text-align: right; font-size: .84rem; font-weight: 750; font-variant-numeric: tabular-nums;
}
.dist-row .d-pct { text-align: right; color: var(--muted); font-size: .7rem; font-variant-numeric: tabular-nums; }
.dist-row.is-most .d-label { color: var(--ink); }
.dist-row.is-most .d-fill {
  background: linear-gradient(90deg, color-mix(in srgb, var(--brand) 60%, #fff), var(--brand));
  box-shadow: 0 0 10px color-mix(in srgb, var(--brand) 30%, transparent);
}
.dist-row.is-most .d-count { color: var(--brand); }

@media (max-width: 599px) {
  .dist-tools { gap: 8px; }
  .dist-summary { gap: 4px; margin-bottom: 8px; }
  .dist-chip { padding: 2px 8px; font-size: .66rem; }
  .dist-chip .n { display: none; }
  .dist-row { grid-template-columns: 74px minmax(0, 1fr) 40px 42px; gap: 5px; padding: 2px 1px; }
  .dist-row .d-label { font-size: .7rem; }
  .dist-row .d-track { height: 8px; }
  .dist-row .d-count { font-size: .76rem; }
  .dist-row .d-pct { font-size: .64rem; }
  .dist-list { max-height: 52vh; }
}

/* ============================== Tác vụ lẻ — chọn tác vụ (24/11/2026)
   Thẻ chọn tác vụ + khung cài đặt sinh từ ParamSpec do server trả về.
   Mọi màu lấy từ biến trong :root ⇒ Dark/Light đều đúng (bẫy 23). */
.task-picker {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px; margin-bottom: 12px;
}
.task-option {
  position: relative;
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px 14px 12px 40px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card-2); cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.task-option:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.task-option.on {
  border-color: var(--brand-line);
  background: color-mix(in srgb, var(--brand-soft) 60%, var(--card-2));
  box-shadow: inset 0 0 0 1px var(--brand-line);
}
.task-option input[type="radio"] {
  position: absolute; top: 14px; left: 13px; width: 16px; height: 16px; accent-color: var(--brand);
}
.task-option-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.task-option-title { font-size: .95rem; font-weight: 750; color: var(--ink); }
.task-option-sub { color: var(--muted); font-size: .76rem; line-height: 1.45; }
.task-option-meta {
  margin-top: 2px; color: var(--muted); font-size: .72rem; font-variant-numeric: tabular-nums;
}
.settings-grid {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px;
  padding: 12px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--card-2);
}
@media (min-width: 720px) { .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.settings-grid:empty { display: none; }
.settings-grid .wide { grid-column: 1 / -1; }
.preview-box {
  padding: 8px 10px; border-radius: 9px; font-size: .78rem; line-height: 1.5;
  color: var(--muted); background: var(--card-3); border: 1px dashed var(--line);
}
.preview-box b { color: var(--ink); font-weight: 750; }
.advanced-box {
  margin-top: 12px; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 11px;
  background: var(--card);
}
.advanced-box > summary {
  cursor: pointer; font-size: .8rem; font-weight: 700; color: var(--muted); list-style: none;
}
.advanced-box > summary::-webkit-details-marker { display: none; }
.advanced-box[open] > summary { color: var(--ink); margin-bottom: 4px; }
