/* Design tokens: giao dien cong cu ky thuat, mat do thong tin cao, "ban lam viec yen tinh": khung lui lai, ban ve la nhan vat chinh.
   4 nen (html[data-theme]) de do moi mat khi gan nhan ca ngay: sang / diu / toi / cad. Nen cung doi cach to ban ve tren canvas (THEMES trong app.js).
   Mau nhan (do / xanh la / cam) va do to sang layer giu nguyen o moi nen; mau nhan giao dien = xanh muc, khong trung mau nhan.
   Quy uoc: mau chi viet thang trong cac khoi :root; component chi dung var(--...). Chu >= 4.5:1, icon / vien o nhap >= 3:1 o ca 4 nen
   (scripts/ui_check.py do tu dong). --text-3 la chu phu, van >= 4.5:1; --ctl-border la vien o nhap / o tim kiem, >= 3:1. */
:root, :root[data-theme="sang"] {
  --bg: #e9ecef; --surface: #f8f9fa; --surface-2: #f1f3f5; --hover: #e4e8ec;
  --border: #d5dadf; --border-strong: #b9c0c7; --ctl-border: #7a848e;
  --text: #1b2128; --text-2: #3d4751; --text-3: #566069;
  --primary: #2a52be; --primary-hover: #21429c; --primary-soft: #e2e8f6; --on-primary: #ffffff;
  --danger: #b3261e; --danger-soft: #f8e5e5; --success: #1f6f2a; --warning: #8a5200; --warning-soft: #f7ecd9;
  --sel-ink: #b3261e; --folder: #8a5f00;
  --canvas: #b4bbc2;
  --seg-track: #e2e6ea; --seg-on: #ffffff;
  --toast-bg: #1b2128; --toast-ink: #f8f9fa; --toast-err-bg: #7f1d1d; --toast-err-ink: #ffffff;
  --scrim: rgba(15, 23, 42, .45); --badge-ink: #ffffff; --thumb: #ffffff;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-2: 0 10px 30px rgba(15, 23, 42, .18);
  /* thang chu (6 muc), khoang cach, bo goc, do cao o dieu khien */
  --fs-xs: 11px; --fs-sm: 12px; --fs-md: 13px; --fs-lg: 14px; --fs-xl: 16px; --fs-2xl: 22px;
  --s0: 2px; --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-pill: 999px;
  --ctl: 32px; --ctl-sm: 28px; --ctl-xs: 24px;
  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);
  /* IBM Plex (fonts/, tu chua, khong tai tu mang): Sans cho giao dien, Mono cho so trang / so dem / duong dan; du dau tieng Viet */
  --font: "IBM Plex Sans", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --num: "IBM Plex Mono", "Cascadia Code", Consolas, ui-monospace, monospace;
  --mono: "IBM Plex Mono", "Cascadia Code", Consolas, ui-monospace, monospace;
  --t-fast: 120ms; --t-med: 180ms;
  color-scheme: light;
}
/* Diu: xam nhat, khong co mang trang lon nao; ban ve phu xam (giay can) */
:root[data-theme="diu"] {
  --bg: #d5d9dc; --surface: #e2e5e8; --surface-2: #dadee1; --hover: #cfd4d8;
  --border: #c0c6cb; --border-strong: #a7aeb5; --ctl-border: #6a747e;
  --text: #1c2228; --text-2: #39434d; --text-3: #4d5761;
  --primary: #2a4fa8; --primary-hover: #213f88; --primary-soft: #cbd4e6; --on-primary: #ffffff;
  --danger: #a82020; --danger-soft: #ecd3d3; --success: #1f6325; --warning: #7a4800; --warning-soft: #e8dcc6;
  --sel-ink: #a82020; --folder: #7a5400;
  --canvas: #9aa2a9;
  --seg-track: #cdd2d6; --seg-on: #eceef0;
  --shadow-1: 0 1px 2px rgba(20, 26, 32, .08); --shadow-2: 0 10px 30px rgba(20, 26, 32, .2);
}
/* Toi + Toi CAD: xam than xanh nhu model space AutoCAD (#212830), chu sang vua, khong trang tinh */
:root[data-theme="toi"], :root[data-theme="cad"] {
  --bg: #1a1f25; --surface: #22282f; --surface-2: #1e242a; --hover: #2c333b;
  --border: #343c45; --border-strong: #46505a; --ctl-border: #7a8590;
  --text: #d6dce2; --text-2: #b0bac4; --text-3: #98a3ae;
  --primary: #86a6f2; --primary-hover: #a1bbf6; --primary-soft: #2a3550; --on-primary: #141a22;
  --danger: #f08a8a; --danger-soft: #3d2224; --success: #6cc070; --warning: #e0aa55; --warning-soft: #3b3020;
  --sel-ink: #f08a8a; --folder: #e0b45a;
  --canvas: #15191e;
  --seg-track: #1a1f25; --seg-on: #343c46;
  --toast-bg: #d6dce2; --toast-ink: #14181d; --toast-err-bg: #f5b5b5; --toast-err-ink: #3d0f0f;
  --scrim: rgba(0, 0, 0, .6);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4); --shadow-2: 0 12px 34px rgba(0, 0, 0, .55);
  color-scheme: dark;
}
:root[data-theme="cad"] { --canvas: #181d24; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 1ms !important; } }

* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); font-size: var(--fs-md); line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -.01em; } h2 { font-size: var(--fs-xl); font-weight: 600; } h3 { font-size: var(--fs-lg); font-weight: 600; }
p { margin: 0; }
.muted { color: var(--text-3); } .small { font-size: var(--fs-sm); }
.grow { flex: 1; } .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; gap: var(--s2); }
kbd { font-family: var(--mono); font-size: var(--fs-xs); line-height: 16px; padding: 0 var(--s1); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: var(--s1); background: var(--surface-2); color: var(--text-3); }

/* icon */
.ic { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.ic.sm { width: 14px; height: 14px; } .ic.lg { width: 20px; height: 20px; } .ic.xl { width: 40px; height: 40px; stroke-width: 1.5; }
.ic.inline { vertical-align: -2px; }

/* controls: moi nut co 4 trang thai ro rang (thuong / hover / nhan / chon), chi doi mau, khong doi kich thuoc */
button, input, select { font: inherit; color: inherit; }
.btn, .icon-btn, .seg button, .chip, .tabs button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.btn { height: var(--ctl); padding: 0 var(--s3); border-radius: var(--r-sm); border: 1px solid var(--border-strong); background: var(--surface); white-space: nowrap; font-weight: 500; box-shadow: var(--shadow-1); }
.btn:hover { background: var(--hover); border-color: var(--ctl-border); }
.btn:active, .icon-btn:active, .chip:active { background: var(--border); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.primary:active { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn:disabled, .icon-btn:disabled, .chip:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { width: var(--ctl); height: var(--ctl); border-radius: var(--r-sm); border: 1px solid transparent; background: transparent; color: var(--text-2); }
.icon-btn:hover { background: var(--hover); color: var(--text); }
:focus-visible { outline: none; box-shadow: var(--focus); }
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]), select {
  height: var(--ctl); border: 1px solid var(--ctl-border); border-radius: var(--r-sm); background: var(--surface); padding: 0 var(--s2);
}
input:not([type=checkbox]):not([type=radio]):not([type=range]):hover, select:hover { border-color: var(--text-3); }
input:not([type=checkbox]):not([type=radio]):not([type=range]):focus-visible, select:focus-visible { border-color: var(--primary); }
input::placeholder { color: var(--text-3); opacity: 1; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
input[type=range] { accent-color: var(--primary); width: 96px; }
.search { display: flex; align-items: center; gap: var(--s2); height: var(--ctl); padding: 0 var(--s2); border: 1px solid var(--ctl-border); border-radius: var(--r-sm); background: var(--surface); color: var(--text-3); }
.search:hover { border-color: var(--text-3); }
.search:focus-within { border-color: var(--primary); box-shadow: var(--focus); }
.search input { border: 0 !important; height: 100% !important; padding: 0 !important; background: none !important; flex: 1; min-width: 0; box-shadow: none !important; color: var(--text); }
.field { display: inline-flex; align-items: center; gap: var(--s2); color: var(--text-2); white-space: nowrap; }
.field select { height: var(--ctl-sm); }
.divider { width: 1px; height: 20px; background: var(--border-strong); flex: none; }
.chip { height: var(--ctl-sm); padding: 0 var(--s3); border-radius: var(--r-pill); border: 1px solid var(--border-strong); background: var(--surface); font-size: var(--fs-sm); color: var(--text-2); }
.chip:hover { background: var(--hover); color: var(--text); }
.count { min-width: 18px; height: 18px; padding: 0 var(--s1); border-radius: 9px; background: var(--primary-soft); color: var(--primary); font-size: var(--fs-xs); display: inline-flex; align-items: center; justify-content: center; }
.count:empty { display: none; }

/* segmented */
.seg { display: inline-flex; border-radius: var(--r-md); background: var(--seg-track); padding: var(--s0); gap: var(--s0); }
.seg button { height: var(--ctl-sm); padding: 0 var(--s3); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.seg button:hover { background: color-mix(in srgb, var(--seg-on) 60%, transparent); color: var(--text); }
.seg button.on { background: var(--seg-on); color: var(--primary); box-shadow: var(--shadow-1); }
.seg button:disabled { opacity: .35; cursor: not-allowed; }
.seg button kbd { margin-left: var(--s0); }
.seg button.on kbd { color: var(--primary); border-color: currentColor; }

/* topbar: trai = ve nha + ten file; giua = trang + bai toan; phai = viec dang chay + nen + hanh dong */
.view { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: var(--s2); height: 48px; padding: 0 var(--s3); background: var(--surface); border-bottom: 1px solid var(--border); flex: none; }
.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 650; font-size: var(--fs-lg); color: var(--text); }
.brand .ic { color: var(--primary); }
.brand-logo { width: 24px; height: 24px; display: block; }
/* nut chi chu may dung duoc (qua tunnel thi an; backend van chan) */
.member .owner-only { display: none !important; }
body:not(.member) .member-only { display: none !important; }
.conn-input { width: min(340px, 60vw); }
.conn-msg { color: var(--danger); }
.doc-title { display: flex; flex-direction: column; min-width: 0; max-width: 26vw; flex: 0 1 auto; line-height: 1.25; }
.doc-title #docName { font-weight: 600; }
#docPath { font-family: var(--mono); font-size: var(--fs-xs); }
.pager { display: flex; align-items: center; gap: var(--s0); margin-left: var(--s3); padding: var(--s0); border-radius: var(--r-md); background: var(--seg-track); }
.pager .icon-btn { width: var(--ctl-sm); height: var(--ctl-sm); }
.pager .icon-btn:hover { background: var(--seg-on); }
.pg-input { display: inline-flex; align-items: center; gap: var(--s2); padding: 0 var(--s1); color: var(--text-2); font-size: var(--fs-sm); }
.pg-input input { width: 56px; text-align: center; height: var(--ctl-sm) !important; font-family: var(--num); font-size: var(--fs-md); }
.pg-input #pgTotal { font-family: var(--num); font-size: var(--fs-md); }

/* job progress */
.job { display: flex; align-items: center; gap: var(--s2); width: 310px; }
.job-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--s1); }
.job-text { font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 4px; border-radius: var(--s0); background: var(--border); overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--primary); transition: width var(--t-med); }

/* ===== home ===== */
.home-main { flex: 1; overflow: auto; padding: var(--s5) var(--s6); max-width: 1280px; width: 100%; margin: 0 auto; }
.home-head { display: flex; align-items: flex-end; gap: var(--s4); margin-bottom: var(--s4); }
.home-head > div { flex: 1; } .home-head p { margin-top: var(--s0); }
.home-head .search { width: 280px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s3); }
.doc-card { position: relative; display: flex; flex-direction: column; gap: var(--s2); padding: var(--s4); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-1); cursor: pointer; text-align: left; transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.doc-card:hover { border-color: var(--primary); box-shadow: var(--shadow-2); }
.doc-card:focus-visible { box-shadow: var(--focus); }
.doc-card .top { display: flex; gap: var(--s3); align-items: flex-start; }
.doc-card .file-ic { width: 40px; height: 40px; border-radius: var(--r-md); background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; flex: none; }
.doc-card .file-ic .ic { width: 20px; height: 20px; }
.doc-card .name { font-weight: 600; word-break: break-word; line-height: 1.35; padding-right: var(--s5); }
.doc-card .path { font-family: var(--mono); font-size: var(--fs-xs); line-height: 1.5; margin-top: var(--s0); color: var(--text-3); word-break: break-all; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); margin-top: auto; padding-top: var(--s3); border-top: 1px solid var(--border); }
.stat b { display: block; font-family: var(--num); font-size: var(--fs-xl); font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.stat span { font-size: var(--fs-xs); color: var(--text-3); }
.doc-card .meta { display: flex; flex-wrap: wrap; gap: var(--s2); }
.tag { display: inline-flex; align-items: center; gap: var(--s1); height: 22px; padding: 0 var(--s2); border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--border-strong); font-size: var(--fs-sm); color: var(--text-2); }
.tag.ok { color: var(--success); } .tag.warn { color: var(--warning); background: var(--warning-soft); border-color: transparent; }
.doc-card .del { position: absolute; top: var(--s2); right: var(--s2); color: var(--text-3); }
.doc-card .del:hover { color: var(--danger); background: var(--danger-soft); }
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2); text-align: center; padding: 64px var(--s4); color: var(--text-3); border: 1px dashed var(--ctl-border); border-radius: var(--r-lg); background: var(--surface); }
.empty h2 { color: var(--text); } .empty .btn { margin-top: var(--s2); }
.empty.sm { padding: var(--s5); border: 0; background: none; }
.home-foot { margin-top: var(--s4); }
/* tai PDF cua thanh vien: khung keo tha + nut chon file + dong gioi han; thanh tien do noi (hien o ca man lam viec) */
.upload-box { margin-bottom: var(--s4); }
.drop-area { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s4); padding: var(--s4) var(--s5); border: 2px dashed var(--ctl-border); border-radius: var(--r-lg); background: var(--surface); transition: border-color var(--t-fast); }
.dragging .drop-area { border-color: var(--primary); }
.drop-area > .ic { color: var(--primary); flex: none; }
.drop-text { flex: 1 1 280px; min-width: 0; } .drop-text p { margin-top: var(--s0); }
.upload-limits-warn { color: var(--warning); font-weight: 600; }
.upload-prog { position: fixed; top: var(--s4); left: 50%; transform: translateX(-50%); z-index: 45; width: min(420px, calc(100vw - var(--s6))); display: flex; flex-direction: column; gap: var(--s2); padding: var(--s3) var(--s4); border-radius: var(--r-md); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); box-shadow: var(--shadow-2); }
.upload-prog-text { display: flex; justify-content: space-between; gap: var(--s3); font-size: var(--fs-sm); }
.upload-prog .pct { font-family: var(--num); font-variant-numeric: tabular-nums; color: var(--text-2); }
.upload-prog .bar { height: 6px; }

/* ===== workspace ===== */
.work-body { flex: 1; display: flex; min-height: 0; }
aside { background: var(--surface); overflow: auto; }
#left { width: 168px; flex: none; border-right: 1px solid var(--border); }
.side-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; height: 32px; padding: 0 var(--s3); background: var(--surface); border-bottom: 1px solid var(--border); font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
#right { width: 384px; flex: none; border-left: 1px solid var(--border); display: flex; flex-direction: column; }
#pageList { list-style: none; margin: 0; padding: var(--s1); display: flex; flex-direction: column; gap: var(--s0); }
#pageList li { display: flex; align-items: center; gap: var(--s2); min-height: 30px; padding: 0 var(--s2); border-radius: var(--r-sm); cursor: pointer; color: var(--text-2); }
#pageList li:hover { background: var(--hover); }
#pageList li.cur { background: var(--primary-soft); color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
#pageList li.cur .pl-no { font-weight: 500; }
#pageList li.skip { color: var(--text-3); }
#pageList li.skip::after { content: "bỏ"; margin-left: auto; font-size: var(--fs-xs); line-height: 16px; padding: 0 var(--s1); border: 1px solid var(--border-strong); border-radius: var(--s1); }
.pl-no { width: 24px; flex: none; text-align: right; font-family: var(--num); font-size: var(--fs-md); font-variant-numeric: tabular-nums; }
.pl-badges { display: flex; flex-wrap: wrap; gap: var(--s0) var(--s2); min-width: 0; }
.pl-b, .pl-ed { display: inline-flex; align-items: center; gap: var(--s1); font-family: var(--num); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.pl-b i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.pl-ed { margin-left: auto; color: var(--text-3); }
#pageList li.cur .pl-b, #pageList li.cur .pl-ed { color: var(--primary); }
.badge { font-size: var(--fs-xs); line-height: 16px; padding: 0 var(--s1); border-radius: 8px; color: var(--badge-ink); font-weight: 600; }

#center { flex: 1; display: flex; flex-direction: column; min-width: 0; }
/* thanh cong cu 1 hang (cong cu, hoan tac, class, zoom); an/hien nhan + hinh ve noi tren vung ve, do dam + bo trang o thanh trang thai: vung ve duoc nhieu cho nhat */
#toolbar { display: flex; flex-direction: column; padding: var(--s1) var(--s3); background: var(--surface); border-bottom: 1px solid var(--border); flex: none; }
.tb-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1) var(--s3); min-width: 0; min-height: 36px; }
#editClass { width: 152px; }
/* khoi phu cua tab Layer thu gon de danh sach layer (noi dung chinh) len cao */
.more > summary { cursor: pointer; padding: var(--s1) var(--s1); color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; border-radius: var(--r-sm); }
.more > summary:hover { background: var(--hover); color: var(--text); }
.more > :not(summary) { margin: var(--s2) var(--s1) 0; }
.more .copy-box { border: 0; padding: 0; background: none; }
#viewport { flex: 1; position: relative; overflow: hidden; background: var(--canvas); }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; touch-action: none; }
.vp-top { position: absolute; top: var(--s2); left: var(--s2); right: var(--s2); z-index: 3; display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--s2); pointer-events: none; }
.vp-top > * { pointer-events: auto; }
.vp-pill, .draw-opts { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); padding: var(--s1); max-width: 100%; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--shadow-1); }
.draw-opts:not(:has(> :not([hidden]))) { display: none; }
.draw-opts .seg { border: 0; padding: 0; }
.statusbar .field { flex: none; }
.statusbar { display: flex; align-items: center; gap: var(--s3); height: 28px; padding: 0 var(--s3); background: var(--surface); border-top: 1px solid var(--border); font-size: var(--fs-sm); flex: none; overflow: hidden; white-space: nowrap; }
.statusbar > span { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.statusbar > .small { flex: none; }
.busy { position: absolute; top: var(--s3); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: var(--s2); background: var(--toast-bg); color: var(--toast-ink); padding: var(--s1) var(--s4); border-radius: var(--r-pill); font-size: var(--fs-sm); box-shadow: var(--shadow-2); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.popup { position: absolute; z-index: 5; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--shadow-2); padding: var(--s1); min-width: 280px; max-width: 440px; max-height: 70%; overflow: auto; }
.popup .hit { padding: var(--s2); border-radius: var(--r-sm); }
.popup .hit:hover { background: var(--hover); }
.popup .hit-name { font-weight: 600; word-break: break-all; cursor: pointer; display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.popup .hit-cls { display: flex; flex-wrap: wrap; gap: var(--s1); margin-top: var(--s2); }
.popup .hit-cls button { height: var(--ctl-sm); padding: 0 var(--s2); font-size: var(--fs-sm); border-radius: var(--r-pill); border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; display: inline-flex; align-items: center; gap: var(--s2); }
.popup .hit-cls button:hover { background: var(--hover); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 var(--s2); flex: none; }
.tabs button { flex: 1 1 auto; height: 40px; padding: 0 var(--s2); border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.tabs button:hover { color: var(--text); background: var(--hover); }
.tabs button.on { border-bottom-color: var(--primary); color: var(--primary); }
.tab { padding: var(--s3); overflow: auto; flex: 1; display: flex; flex-direction: column; gap: var(--s3); }
.tab > * { flex-shrink: 0; }
.chip-row { display: flex; gap: var(--s0); padding: var(--s0); border-radius: var(--r-md); background: var(--seg-track); }
.chip-row .chip { flex: 1 1 0; min-width: 0; border: 0; border-radius: var(--r-sm); background: transparent; padding: 0 var(--s2); gap: var(--s1); }
.chip-row .chip:hover { background: var(--seg-on); color: var(--text); box-shadow: var(--shadow-1); }
.copy-box { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s3); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border-strong); }
.copy-box select { flex: 1; min-width: 0; }

#layerList { display: flex; flex-direction: column; gap: var(--s0); margin: 0 calc(-1 * var(--s1)); }
.lrow { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto 112px 24px 24px; align-items: center; gap: var(--s1); min-height: 32px; padding: var(--s0) var(--s1); border-radius: var(--r-sm); }
.lrow:hover { background: var(--hover); }
.lrow.sel { background: color-mix(in srgb, var(--sel-ink) 10%, var(--surface)); box-shadow: inset 3px 0 0 var(--sel-ink); }
.lrow.sel .lname { color: var(--sel-ink); font-weight: 650; }
.lname b { font-weight: 500; }
.lrow.mapped .lname b { font-weight: 600; }
.lrow.off .lname { text-decoration: line-through; color: var(--text-3); }
.lrow .vis { width: var(--ctl-xs); height: var(--ctl-xs); color: var(--text-2); }
.lrow .vis.hidden-layer { color: var(--text-3); }
/* ten layer: ngat o dau gach / khoang trang (khong cat giua chu), toi da 2 dong, thua thi ... (ten day du o tooltip) */
.lname { overflow-wrap: anywhere; cursor: pointer; font-size: var(--fs-sm); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lname .pre { color: var(--text-3); font-size: var(--fs-xs); }
.lcount { font-family: var(--num); font-size: var(--fs-sm); color: var(--text-3); font-variant-numeric: tabular-nums; }
.lrow select { width: 112px; height: var(--ctl-sm); font-size: var(--fs-sm); padding: 0 var(--s1); }
.lrow .loff { width: var(--ctl-xs); height: var(--ctl-xs); }
.lrow .loff.on { color: var(--danger); }

#classList { display: flex; flex-direction: column; gap: var(--s2); }
.crow { padding: var(--s3); border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface-2); display: flex; flex-direction: column; gap: var(--s2); }
.crow .head { display: flex; align-items: center; gap: var(--s2); }
.crow .head input[data-k=name] { flex: 1; min-width: 0; }
.crow .mode-row { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--text-3); }
.crow .mode-row select { flex: 1; min-width: 0; }
.crow .cerr { color: var(--danger); font-size: var(--fs-sm); }
.crow input[aria-invalid=true] { border-color: var(--danger) !important; }
.crow details.adv > .params { margin-top: var(--s2); }
.row.wrap { flex-wrap: wrap; }
#classAdd { margin-bottom: var(--s2); }
.crow input[type=color] { width: var(--ctl); height: var(--ctl); padding: var(--s0); border: 1px solid var(--ctl-border); border-radius: var(--r-sm); background: var(--surface); cursor: pointer; }
.crow .params { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); align-items: end; }
.crow .params label { display: flex; flex-direction: column; gap: var(--s0); font-size: var(--fs-sm); color: var(--text-3); }
.crow .params input { width: 100%; height: var(--ctl-sm) !important; }

#editList { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--s1); }
#editList li { display: flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s2); border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface-2); }
#editList .op-add { color: var(--success); } #editList .op-erase { color: var(--danger); }

/* ===== dialogs ===== */
dialog { border: 1px solid var(--border-strong); border-radius: var(--r-lg); padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-2); max-height: 92vh; overflow: hidden; }
dialog::backdrop { background: var(--scrim); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); background: var(--surface); }
.dlg-foot { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4); border-top: 1px solid var(--border); background: var(--surface); }
/* hop dang form: tieu de va nut o rieng, noi dung cuon o giua (man hinh thap van thay nut Xuat) */
.form { display: flex; flex-direction: column; gap: var(--s3); min-width: 420px; max-height: 92vh; overflow-y: auto; }
.form > .dlg-head { position: sticky; top: 0; z-index: 1; }
.form > .dlg-foot { position: sticky; bottom: 0; margin-top: auto; }
.form > .frow, .form > p { margin: 0 var(--s4); }
.frow { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); color: var(--text-2); }
.frow input[type=number] { width: 120px; }
.frow.check { justify-content: flex-start; gap: var(--s2); }
.frow.check.sub { padding-left: var(--s5); }

/* hop Nguoi dung (chi chu may): bang + o mat khau hien mot lan + form them */
.users-dlg { width: min(860px, 94vw); }
.users-dlg[open] { display: flex; flex-direction: column; }
.users-body { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4); }
.users-web { width: min(420px, 60vw); }
.users-key { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s3); border: 1px solid var(--primary); border-radius: var(--r-md); background: var(--primary-soft); color: var(--text); }
.users-key .frow { color: var(--text); }
.users-key-title { font-weight: 600; }
.users-out { flex: 1; min-width: 0; max-width: 560px; font-family: var(--mono); font-size: var(--fs-sm); }
.users-key-act { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.users-key .muted { color: var(--text-2); }
.users-msg { color: var(--text-2); }
.users-msg.err { color: var(--danger); }
.users-scroll { overflow-x: auto; border: 1px solid var(--border-strong); border-radius: var(--r-md); }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { padding: var(--s2) var(--s3); text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users-table th { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); background: var(--surface-2); white-space: nowrap; }
.users-table tbody tr:last-child td { border-bottom: 0; }
.users-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.users-table td.uid { font-family: var(--mono); }
.users-table tr.off td { color: var(--text-3); }
.users-table .acts { display: flex; gap: var(--s2); flex-wrap: wrap; }
.users-empty { padding: var(--s4); text-align: center; }
.users-add { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.users-add .frow input { width: 160px; }

.fs-dlg { width: min(960px, 94vw); height: min(640px, 88vh); }
.fs-dlg[open] { display: flex; flex-direction: column; }
.fs-body { flex: 1; display: flex; min-height: 0; }
.fs-side { width: 210px; flex: none; border-right: 1px solid var(--border); padding: var(--s2); overflow: auto; background: var(--surface-2); }
.fs-side-title { font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); padding: var(--s2) var(--s2) var(--s1); }
.fs-loc { display: flex; align-items: center; gap: var(--s2); width: 100%; height: var(--ctl); padding: 0 var(--s2); border: 0; border-radius: var(--r-sm); background: none; cursor: pointer; text-align: left; color: var(--text-2); }
.fs-loc:hover { background: var(--hover); color: var(--text); }
.fs-loc.on { background: var(--primary-soft); color: var(--primary); }
.fs-loc span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.fs-bar { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); }
.crumbs { flex: 1; display: flex; align-items: center; gap: var(--s0); overflow-x: auto; white-space: nowrap; min-width: 0; scrollbar-width: none; }
.crumbs button { height: var(--ctl-sm); padding: 0 var(--s2); border: 0; border-radius: var(--s1); background: none; cursor: pointer; color: var(--text-2); }
.crumbs button:hover { background: var(--hover); color: var(--text); }
.crumbs button:last-child { color: var(--text); font-weight: 600; }
.crumbs .sep { color: var(--text-3); }
.fs-filter { width: 180px; }
.fs-path { padding: var(--s2) var(--s3) 0; }
.fs-path input { width: 100%; font-family: var(--mono); font-size: var(--fs-sm); }
.fs-list { flex: 1; overflow: auto; padding: var(--s2); }
.fs-item { display: grid; grid-template-columns: 24px 20px 1fr 90px 130px; align-items: center; gap: var(--s2); height: 34px; padding: 0 var(--s2); border-radius: var(--r-sm); cursor: pointer; user-select: none; }
.fs-item:hover { background: var(--hover); }
.fs-item.sel { background: var(--primary-soft); }
.fs-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-item .dir-ic { color: var(--folder); } .fs-item .pdf-ic { color: var(--danger); }
.fs-item .sz, .fs-item .dt { font-size: var(--fs-sm); color: var(--text-3); text-align: right; font-variant-numeric: tabular-nums; }
.fs-msg { padding: var(--s5); text-align: center; color: var(--text-3); }

.toast { position: fixed; bottom: var(--s5); left: 50%; transform: translateX(-50%); max-width: 640px; display: flex; align-items: flex-start; gap: var(--s2); padding: var(--s3) var(--s4); border-radius: var(--r-md); background: var(--toast-bg); color: var(--toast-ink); box-shadow: var(--shadow-2); z-index: 50; white-space: pre-line; font-size: var(--fs-sm); }
.toast .ic { margin-top: var(--s0); }
.toast.err { background: var(--toast-err-bg); color: var(--toast-err-ink); }
.drop-zone { position: fixed; inset: var(--s3); z-index: 40; border: 2px dashed var(--primary); border-radius: var(--r-lg); background: color-mix(in srgb, var(--primary-soft) 85%, transparent); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2); color: var(--primary); font-size: var(--fs-lg); font-weight: 600; pointer-events: none; }

/* che do "chi layer net den" */
.black-box { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s1) var(--s1) var(--s3); border-bottom: 1px solid var(--border); }
.switch { display: flex; align-items: center; gap: var(--s2); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 30px; height: 18px; border-radius: 9px; background: var(--ctl-border); position: relative; flex: none; transition: background var(--t-fast); }
.switch .thumb { position: absolute; top: var(--s0); left: var(--s0); width: 14px; height: 14px; border-radius: 50%; background: var(--thumb); box-shadow: var(--shadow-1); transition: transform var(--t-fast); }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track .thumb { transform: translateX(12px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }
.swatch { width: 8px; height: 8px; border-radius: var(--s0); border: 1px solid var(--ctl-border); display: inline-block; vertical-align: 0; margin-right: var(--s1); }
.lrow.dim .lname, .lrow.dim .lname b { color: var(--text-3); }
.crow .params label.chk { flex-direction: row; align-items: center; justify-content: space-between; grid-column: 1 / -1; }
.crow .params label.chk input { width: 16px !important; height: 16px !important; }

/* an/hien nhan theo class */
.cls-chips { display: inline-flex; flex-wrap: wrap; gap: var(--s1); }
.cls-chip { height: var(--ctl-sm); padding: 0 var(--s2); border-radius: var(--r-pill); border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--text-2); }
.cls-chip:hover { background: var(--hover); }
.cls-chip.off { color: var(--text-3); text-decoration: line-through; border-style: dashed; }
.cls-chip.off .dot { opacity: .5; }
.cls-chip .n { color: var(--text-3); font-variant-numeric: tabular-nums; }
#editList li.hl { border-color: var(--primary); background: var(--primary-soft); }

/* doi tuong dang chon (box / vung / duong) */
.btn.sm { height: var(--ctl-sm); padding: 0 var(--s2); font-size: var(--fs-sm); }
.sel-panel { position: absolute; z-index: 4; top: var(--s2); left: var(--s2); max-width: calc(100% - 16px); display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3);
  padding: var(--s1) var(--s2) var(--s1) var(--s3); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--shadow-2); font-size: var(--fs-sm); }
.sel-panel select { height: var(--ctl-sm); padding: 0 var(--s1); }

/* nut An/Hien nhan: dang an -> to nen de thay ro */
#btnLabels .ic { width: 15px; height: 15px; }
#btnLabels.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* nut an nhan cua layer da gan */
.lrow .lview { width: var(--ctl-xs); height: var(--ctl-xs); color: var(--text-2); }
.lrow .lview.on { color: var(--primary); background: var(--primary-soft); }
.lrow .lview:disabled { opacity: .35; }

/* hop xuat: nhom Trang / Anh */
.fset { border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: var(--s2) var(--s3); margin: 0 var(--s4); display: flex; flex-direction: column; gap: var(--s2); }
.fset legend { padding: 0 var(--s1); font-weight: 600; color: var(--text); }
.fset .frow.check { justify-content: flex-start; }
.fset input.num { width: 64px; }
.fset .sub { padding-left: 22px; display: flex; flex-direction: column; gap: var(--s2); }

/* cong tac bai toan (model) tren thanh tren cung: trang thai quan trong nhat nen to hon cac nut khac */
.model-seg { margin-left: var(--s3); }
.model-seg button { padding: 0 var(--s3); font-weight: 600; }
.model-seg button.on, .model-seg button.on:hover { background: var(--primary); color: var(--on-primary); }

/* ---------- chon nen (do moi mat) ---------- */
.theme-seg { display: inline-flex; gap: var(--s0); padding: var(--s0); border-radius: var(--r-md); background: var(--seg-track); }
.theme-seg button { width: 28px; height: var(--ctl-sm); padding: 0; border: 0; border-radius: var(--r-sm); background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.theme-seg button:hover { background: color-mix(in srgb, var(--seg-on) 60%, transparent); }
.theme-seg button.on { background: var(--seg-on); box-shadow: var(--shadow-1); }
.theme-seg button.on .tsw { box-shadow: 0 0 0 1.5px var(--primary); }
/* mau nho: vien = mau giao dien, ruot = giay, cham giua = mau net ve */
.tsw { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--f); box-shadow: 0 0 0 1px var(--ctl-border);
  background: radial-gradient(circle, var(--i) 0 2px, var(--p) 2.5px); }
#zoomInfo { font-family: var(--num); font-size: var(--fs-md); font-variant-numeric: tabular-nums; }
/* gan layer theo tung trang: goi y (layer tung gan o trang khac) */
.lrow.sugg .lname { font-style: italic; }
.lrow .lsug { width: var(--ctl-xs); height: var(--ctl-xs); color: var(--primary); }
.lrow .lsug:disabled { visibility: hidden; }
.badge.sugg { background: transparent; border: 1px dashed; color: var(--text-2); }
#btnAcceptSugg { margin: 0 0 var(--s2); }

/* man hinh vua (<= 1500): bo goi y phim trong nut de thanh cong cu gon */
@media (max-width: 1500px) {
  #toolSeg button kbd, #btnLabels kbd { display: none; }
  .statusbar > .small { display: none; }
}
@media (max-width: 1280px) {
  .topbar .lbl { display: none; }
  #btnApplyAll, #btnExport { padding: 0 var(--s3); }
}
/* man hinh hep: thu gon cot phu, an goi y phim */
@media (max-width: 1200px) {
  #right { width: 320px; }
  #left { width: 132px; }
  .statusbar .small { display: none; }
  .doc-title { max-width: 22vw; }
}
/* cua so rat hep (vi du trinh duyet phong 200%): bo cot trang, panel phai gon; thanh tren khong de nhau */
@media (max-width: 900px) {
  .job { width: 210px; }
  #left, .doc-title { display: none; }
  #right { width: 280px; }
  .pager, .model-seg { margin-left: 0; }
  .model-seg button { padding: 0 var(--s2); }
  .pg-input { font-size: var(--fs-sm); }
  #work .theme-seg, .tabs .ic { display: none; }
}
