/* Quản trị TQTK — giao diện gọn cho màn hình laptop (≥ 1280 px). Không phụ thuộc thư viện ngoài. */
:root {
  --bg: #f4f5f7; --panel: #fff; --text: #1d2330; --muted: #6b7385; --line: #e1e4ea; --line2: #eef0f4;
  --primary: #2f6fde; --primary-d: #2258b6; --danger: #d13b3b; --ok: #1f9d55; --warn: #c98400;
  --mod: #fff4d6; --mod-line: #f0c75e; --side: #1f2533; --side-text: #c9cfdb; --side-active: #2f6fde;
  --radius: 6px; font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 12px; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 10px; font-weight: 600; }
h3 { font-size: 14px; margin: 12px 0 6px; font-weight: 600; }
code, pre, .mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
pre { background: #f6f7f9; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; overflow: auto; max-height: 420px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ok { color: var(--ok); } .bad { color: var(--danger); } .warn { color: var(--warn); }

/* ---------- khung */
.shell { display: flex; height: 100vh; }
.sidebar { width: 210px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; }
.brand { font-size: 18px; font-weight: 700; color: #fff; padding: 14px 16px 10px; }
.brand span { font-weight: 400; color: var(--side-text); font-size: 13px; }
#nav { flex: 1; overflow-y: auto; padding-bottom: 8px; }
#nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #7f889b; padding: 12px 16px 4px; }
#nav a { display: flex; justify-content: space-between; color: var(--side-text); padding: 6px 16px; font-size: 13.5px; }
#nav a:hover { background: #2a3142; text-decoration: none; }
#nav a.active { background: var(--side-active); color: #fff; }
#nav .badge { background: var(--warn); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; line-height: 17px; }
.sidebar-foot { padding: 10px 16px; border-top: 1px solid #2c3446; font-size: 12px; display: flex; justify-content: space-between; align-items: center; }
.sidebar-foot .btn.link { color: #9fb6e8; }
main { flex: 1; overflow-y: auto; padding: 18px 22px 40px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* ---------- thẻ, lưới */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.card > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 600; }
.stat .l { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.split { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 14px; align-items: start; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv .k { color: var(--muted); }

/* ---------- nút, ô nhập */
.btn { border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: var(--radius); padding: 5px 12px; font-size: 13px;
  cursor: pointer; line-height: 20px; white-space: nowrap; font-family: inherit; }
.btn:hover { border-color: #b9c0cc; background: #fafbfc; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.warn { color: var(--warn); border-color: var(--mod-line); }
.btn.sm { padding: 2px 8px; font-size: 12px; line-height: 18px; }
.btn.link { border: none; background: none; color: var(--primary); padding: 0; }
.btn.wide { width: 100%; }
input, select, textarea { font-family: inherit; font-size: 13px; border: 1px solid #cdd2db; border-radius: 4px; padding: 4px 7px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd2fb; border-color: var(--primary); }
input[type=number] { width: 110px; }
input.num-s { width: 76px; }
input[type=checkbox] { width: auto; }
textarea { width: 100%; min-height: 60px; resize: vertical; }
textarea.code { font-family: Consolas, monospace; font-size: 12.5px; min-height: 260px; }
label { display: block; margin-bottom: 8px; }
label > input:not([type=checkbox]), label > select, label > textarea { display: block; width: 100%; margin-top: 3px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar input[type=search] { width: 220px; }

/* ---------- bảng */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--panel); font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: 12px; background: #fafbfc; position: sticky; top: 0; z-index: 1; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f5f8ff; }
tr.mod td { background: var(--mod); }
tr.group-row td { background: var(--bg, #f3f5f9); font-weight: 600; color: var(--primary); padding-top: 10px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 8px 0; font-size: 12.5px; color: var(--muted); }
.thumb { width: 44px; height: 44px; object-fit: contain; background: #eef0f4; border-radius: 4px; display: block; }
.thumb.lg { width: 96px; height: 96px; }
.thumb.xl { width: 160px; height: 160px; }
.tag { display: inline-block; padding: 0 7px; border-radius: 9px; font-size: 11.5px; line-height: 18px; background: #eef0f4; color: #4b5366; white-space: nowrap; }
.tag.mod { background: var(--mod); color: #8a6200; border: 1px solid var(--mod-line); }
.tag.ok { background: #e3f6ea; color: var(--ok); }
.tag.bad { background: #fde8e8; color: var(--danger); }
.tag.info { background: #e6efff; color: var(--primary-d); }
.tag.warn { background: #fff4e0; color: var(--warn); }
.dkt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dkt b { font-weight: 600; }

/* ---------- tab */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: none; background: none; padding: 7px 14px; font-size: 13.5px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-family: inherit; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tabs.small button { padding: 5px 10px; font-size: 13px; }

/* ---------- form sửa asset */
.fields { display: grid; grid-template-columns: minmax(170px, 230px) minmax(0, 1fr); gap: 0; border-top: 1px solid var(--line2); }
.fields > .f-label, .fields > .f-val { padding: 6px 8px; border-bottom: 1px solid var(--line2); }
.fields > .f-label { font-weight: 500; font-size: 13px; }
.fields > .f-label .key { display: block; font-family: Consolas, monospace; font-size: 11px; color: var(--muted); font-weight: 400; }
.fields > .f-label.changed, .fields > .f-val.changed { background: var(--mod); }
.fields > .f-label.err, .fields > .f-val.err { background: #fdecec; }
.f-desc { color: var(--muted); font-size: 12px; margin-top: 3px; }
.f-orig { font-size: 12px; color: #8a6200; margin-top: 3px; }
.trip { display: flex; gap: 10px; flex-wrap: wrap; }
.trip label { display: flex; align-items: center; gap: 4px; margin: 0; font-size: 12px; color: var(--muted); }
.trip label > input { width: 84px; display: inline-block; margin: 0; }
.sub { border: 1px solid var(--line2); border-radius: 4px; padding: 6px 8px; background: #fbfcfd; }
.sub .fields { grid-template-columns: minmax(130px, 180px) minmax(0, 1fr); }
table.inner { background: transparent; }
table.inner td, table.inner th { padding: 3px 5px; }
.sprites { display: flex; gap: 8px; flex-wrap: wrap; }
.sprite-box { text-align: center; font-size: 11px; color: var(--muted); cursor: pointer; }
.sprite-box img { margin-bottom: 2px; }
.sprite-box.modified img { outline: 2px solid var(--mod-line); }
.gallery { gap: 12px; }
.gallery .sprite-box { width: 120px; }
.gallery .sprite-box img { margin: 0 auto 2px; }
.gallery .g-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery .g-use { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-row { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; padding: 10px; border-top: 1px solid var(--line); }
.ai-info { width: 220px; }
.ai-c { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }
.ai-c img { cursor: zoom-in; margin-bottom: 4px; }
.ai-c.applied img { outline: 3px solid #2e9d4f; }
.ai-c.rejected img { opacity: .45; }
.ai-progress { height: 10px; background: #e6e8ec; border-radius: 5px; overflow: hidden; }
.ai-progress > div { height: 100%; background: #2f6fde; transition: width .4s; }
.ai-big img { max-width: 480px; max-height: 480px; }
.ai-quick { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; }
.ref-zone { display: flex; gap: 10px; align-items: center; padding: 6px; border: 1px dashed var(--line); border-radius: 6px; outline: none; }
.ref-zone:focus, .ref-zone.drag { border-color: #2f6fde; background: rgba(47,111,222,.06); }
.ref-thumb { width: 72px; height: 72px; display: flex; align-items: center; justify-content: center; background: #1f2329; border-radius: 5px; overflow: hidden; flex: none; }
.ref-thumb img { max-width: 100%; max-height: 100%; }
.ref-box { margin-top: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.troop-list { max-height: 340px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.ai-sheet { max-width: 360px; max-height: 360px; cursor: zoom-in; background: #2a2e36; border-radius: 4px; display: block; margin-bottom: 4px; }
.inpaint-wrap { text-align: center; background: #1f2329; padding: 8px; border-radius: 6px; }
.inpaint-view { max-width: 100%; cursor: crosshair; touch-action: none; border: 1px solid var(--line); }
.ref-chip { display: inline-flex; align-items: center; gap: 6px; }
.formation { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; max-width: 300px; }
.formation .cell { border: 1px dashed #cdd2db; border-radius: 4px; min-height: 76px; padding: 3px; text-align: center; font-size: 11px; color: var(--muted); overflow: hidden; }
.formation .cell.on { border-style: solid; background: #f6f9ff; color: var(--text); }
.formation .cell img { width: 48px; height: 48px; object-fit: contain; }

/* ---------- thông báo */
.error-box { background: #fdecec; border: 1px solid #f3b8b8; color: #9b1c1c; border-radius: var(--radius); padding: 8px 10px; margin: 8px 0; font-size: 13px; }
.error-box ul { margin: 4px 0 0 18px; padding: 0; }
.info-box { background: #eef4ff; border: 1px solid #c9dafc; border-radius: var(--radius); padding: 8px 10px; margin: 8px 0; font-size: 13px; }
.warn-box { background: var(--mod); border: 1px solid var(--mod-line); border-radius: var(--radius); padding: 8px 10px; margin: 8px 0; font-size: 13px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1f2533; color: #fff; padding: 9px 14px; border-radius: var(--radius); box-shadow: 0 4px 14px rgba(0,0,0,.18); font-size: 13px; max-width: 420px; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- hộp thoại */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 24, 34, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 6vh 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 8px; width: 520px; max-width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { width: 900px; }
.modal .m-head { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.modal .m-body { padding: 14px 16px; max-height: 70vh; overflow-y: auto; }
.modal .m-foot { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- đăng nhập */
.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 26px 28px; width: 360px; box-shadow: 0 6px 24px rgba(0,0,0,.06); }
.login-box h1 { text-align: center; margin-bottom: 16px; }

/* ---------- diff, log */
.diff-old { color: var(--danger); text-decoration: line-through; }
.diff-new { color: var(--ok); font-weight: 600; }
.log { background: #12161f; color: #cfd6e4; border-radius: var(--radius); padding: 8px 10px; font-family: Consolas, monospace; font-size: 12px; max-height: 320px; overflow-y: auto; white-space: pre-wrap; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #c9d3e6; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 30px; text-align: center; color: var(--muted); }
details > summary { cursor: pointer; color: var(--primary); font-size: 13px; margin: 4px 0; }
.img-compare { display: flex; gap: 16px; flex-wrap: wrap; }
.img-compare figure { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }
.img-compare img { max-width: 300px; max-height: 300px; background: repeating-conic-gradient(#e6e8ec 0% 25%, #fff 0% 50%) 50% / 16px 16px; border: 1px solid var(--line); }

/* ---------- diễn giải nâng binh / thông tin binh chủng (content.js) */
.nowrap { white-space: nowrap; vertical-align: top; }
table.inner select { max-width: 280px; }
