:root {
  --brand: #3b6fd8; --brand-2: #c92643; --ink: #111827; --text: #1f2937; --muted: #6b7280; --faint: #9ca3af;
  --line: #e5e7eb; --line-2: #f0f1f4; --bg: #f5f6f8; --panel: #fff; --hover: #f8f9fb;
  --ok: #16a34a; --ok-bg: #ecfdf3; --warn: #d97706; --warn-bg: #fffbeb; --bad: #dc2626; --bad-bg: #fef2f2; --off: #6b7280; --off-bg: #f3f4f6;
  --teal: #14a08c; --r: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06); --shadow-lg: 0 20px 50px rgba(16,24,40,.18);
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif; color: var(--text); color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
i[data-i] { display: inline-flex; width: 16px; height: 16px; flex: none; }
i[data-i] svg { width: 100%; height: 100%; }
.sp { flex: 1; }

/* Thanh trên */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; height: 60px; padding: 0 24px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 800; font-size: 16px; color: var(--ink); }
.brand img { width: 30px; height: 30px; }
em { font-style: normal; color: var(--brand); }
.top .sep { width: 1px; height: 22px; background: var(--line); }
.crumb { color: var(--muted); font-weight: 500; }
.ghost { text-decoration: none; color: var(--muted); font-weight: 500; padding: 6px 10px; border-radius: 8px; }
.ghost:hover { background: var(--hover); color: var(--text); }
.me { display: flex; align-items: center; gap: 9px; padding-left: 6px; }
.me .av { width: 32px; height: 32px; font-size: 12px; }
.me div b { display: block; font-size: 13px; line-height: 1.2; color: var(--ink); }
.me div span { display: block; font-size: 11.5px; color: var(--muted); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 26px 24px 40px; }
.head { display: flex; align-items: flex-end; gap: 20px; margin-bottom: 20px; }
.head h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; color: var(--ink); }
.head .sub { margin: 4px 0 0; color: var(--muted); max-width: 640px; }
.head .acts { margin-left: auto; display: flex; gap: 10px; }

.btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; font-size: 13.5px; cursor: pointer; text-decoration: none; box-shadow: var(--shadow); white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(226,52,79,.3), 0 4px 12px rgba(226,52,79,.25); }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { height: 32px; padding: 0 11px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }

/* Thẻ thống kê */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { position: relative; text-align: left; padding: 16px 18px; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); cursor: pointer; transition: border-color .15s, transform .15s; }
.stat:hover { border-color: #d1d5db; transform: translateY(-1px); }
.stat.on { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 15%, transparent); }
.stat .ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 12%, #fff); color: var(--c); margin-bottom: 10px; }
.stat .ic i { width: 18px; height: 18px; }
.stat b { display: block; font-size: 26px; line-height: 1.1; color: var(--ink); letter-spacing: -.02em; }
.stat span { display: block; margin-top: 2px; color: var(--muted); font-weight: 500; font-size: 13px; }
.stat small { display: block; margin-top: 6px; color: var(--faint); font-size: 11.5px; }

/* Bảng */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.bar { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.search { display: flex; align-items: center; gap: 8px; width: 340px; max-width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--faint); }
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(226,52,79,.12); }
.search input { border: 0; outline: 0; flex: 1; min-width: 0; color: var(--text); background: none; }
.seg { display: inline-flex; padding: 3px; background: var(--off-bg); border-radius: 10px; gap: 2px; }
.seg button { border: 0; background: none; padding: 6px 11px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.seg button em { color: var(--faint); margin-left: 3px; font-weight: 500; }
.sort { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.sort select { height: 34px; border: 1px solid var(--line); border-radius: 9px; padding: 0 8px; background: var(--panel); }
.tablewrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 16px; background: #fafbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid td { padding: 13px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.grid tbody tr { cursor: pointer; transition: background .12s; }
.grid tbody tr:hover { background: var(--hover); }
.grid tbody tr.sel { background: #fff5f6; }
.grid .r { text-align: right; }
.who { display: flex; align-items: center; gap: 11px; min-width: 220px; }
.av { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; flex: none; }
.who b { display: block; color: var(--ink); font-weight: 600; }
.who small { display: block; color: var(--muted); font-size: 12px; }
.code { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 7px; background: var(--off-bg); font: 600 12.5px/1 "Cascadia Mono", Consolas, monospace; letter-spacing: .04em; color: var(--ink); white-space: nowrap; border: 0; cursor: pointer; }
.code:hover { background: #e9eaee; }
.code i { width: 13px; height: 13px; color: var(--faint); }
.term { min-width: 170px; }
.term b { font-weight: 600; color: var(--ink); }
.term small { color: var(--muted); margin-left: 6px; font-size: 12px; }
.meter { height: 5px; border-radius: 3px; background: var(--line-2); margin-top: 6px; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--c); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; color: var(--c); background: var(--cb); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
.check b { display: block; font-weight: 500; }
.check small { color: var(--muted); font-size: 12px; }
.iconbtn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: none; display: inline-grid; place-items: center; color: var(--muted); cursor: pointer; }
.iconbtn:hover { background: var(--panel); border-color: var(--line); color: var(--ink); }
.empty { padding: 50px 20px 56px; text-align: center; }
.empty svg.art { width: 120px; height: 96px; }
.empty h3 { margin: 10px 0 4px; font-size: 17px; color: var(--ink); }
.empty p { margin: 0 auto 18px; color: var(--muted); max-width: 440px; }
.steps { display: flex; justify-content: center; gap: 14px; margin: 0 auto 22px; flex-wrap: wrap; }
.steps div { width: 190px; padding: 14px; border: 1px dashed var(--line); border-radius: 12px; text-align: left; font-size: 12.5px; color: var(--muted); }
.steps b { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 11px; margin-bottom: 6px; }
.foot { color: var(--faint); font-size: 12px; margin: 14px 2px 0; }

/* Ngăn chi tiết */
.scrim { position: fixed; inset: 0; background: rgba(17,24,39,.32); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 480px; max-width: 100%; background: var(--panel); z-index: 31; box-shadow: var(--shadow-lg); transform: translateX(105%); transition: transform .22s ease; display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.dwh { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.dwh .av { width: 44px; height: 44px; font-size: 15px; border-radius: 12px; }
.dwh h3 { margin: 0; font-size: 17px; color: var(--ink); }
.dwh small { color: var(--muted); }
.dwb { flex: 1; overflow: auto; padding: 6px 20px 24px; }
.sec { padding: 16px 0; border-bottom: 1px solid var(--line-2); }
.sec:last-child { border-bottom: 0; }
.sec h4 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--ink); font-weight: 500; overflow-wrap: anywhere; }
.keybox { width: 100%; height: 92px; resize: none; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfc; font: 12px/1.45 "Cascadia Mono", Consolas, monospace; color: var(--text); word-break: break-all; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.renew { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.renew small { color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--faint)); box-shadow: 0 0 0 3px #fff; }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 16px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline b { color: var(--ink); font-weight: 600; }
.timeline small { display: block; color: var(--muted); font-size: 12px; }
.f { display: block; margin-bottom: 14px; }
.f > span { display: flex; align-items: baseline; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.f > span b { color: var(--brand); }
.f > span em { margin-left: auto; font-weight: 500; color: var(--faint); font-size: 12px; }
.f input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); outline: 0; }
.f input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(226,52,79,.12); }
.f small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.danger-zone { border: 1px solid #fecaca; background: #fffafa; border-radius: 12px; padding: 14px; }
.danger-zone p { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; }

/* Hộp thoại */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(17,24,39,.4); }
.dialog { width: 600px; max-width: 100%; max-height: calc(100vh - 40px); overflow: auto; background: var(--panel); border-radius: 16px; box-shadow: var(--shadow-lg); }
.dialog.sm { width: 420px; }
.dh { display: flex; align-items: flex-start; gap: 12px; padding: 20px 24px 6px; }
.dh h2, .dialog h2 { margin: 0; font-size: 19px; color: var(--ink); }
.dh p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.x { margin-left: auto; width: 32px; height: 32px; border: 0; background: none; font-size: 22px; line-height: 1; color: var(--faint); border-radius: 8px; cursor: pointer; }
.x:hover { background: var(--hover); color: var(--ink); }
.db { padding: 16px 24px 22px; }
.dialog.sm .db p { color: var(--muted); }
.df { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mc { position: relative; }
.mc input { height: 50px !important; font: 700 19px "Cascadia Mono", Consolas, monospace !important; letter-spacing: .1em; text-transform: uppercase; text-align: center; }
.mc input.valid { border-color: var(--ok); }
.mc .ok { position: absolute; right: 14px; top: 16px; width: 18px; height: 18px; color: var(--ok); }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pills button { height: 36px; padding: 0 16px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; font-size: 13px; cursor: pointer; }
.pills button.on { border-color: var(--brand); background: #fff5f6; color: var(--brand); }
.err { min-height: 20px; color: var(--bad); font-weight: 600; font-size: 13px; }
.done { text-align: center; }
.done .big { width: 56px; height: 56px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); display: grid; place-items: center; margin: 4px auto 10px; }
.done .big i { width: 28px; height: 28px; }
.done h2 { margin-bottom: 4px; }
.done p { margin: 0 0 14px; color: var(--muted); }
.done .keybox { text-align: left; height: 100px; }
.done .btnrow { justify-content: center; }

.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); animation: up .2s ease; }
.toast.bad { background: var(--bad); }
.toast i { width: 16px; height: 16px; }
@keyframes up { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1100px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px) {
  .top { padding: 0 14px; } .top .crumb, .top .sep, .me div { display: none; }
  .wrap { padding: 18px 14px 30px; } .head { flex-direction: column; align-items: stretch; } .head .acts { margin-left: 0; }
  .stats { grid-template-columns: repeat(2, 1fr); } .row2 { grid-template-columns: 1fr; } .search { width: 100%; }
}

/* ---- Giấy phép công ty ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 18px; }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--brand); }
.tabs em { color: var(--faint); font-weight: 500; margin-left: 4px; }
.stats.co { grid-template-columns: repeat(4, 1fr); }
.stat b em { font-style: normal; font-size: 16px; color: var(--faint); }
.btn.navy { background: #13213c; border-color: #13213c; color: #fff; }
.btn.navy:hover { background: #24365c; }
.tag { display: inline-block; padding: 0 6px; border-radius: 5px; background: #eef2ff; color: #4338ca; font-size: 11px; font-weight: 600; }
.mut { color: var(--muted); font-size: 12.5px; }
.switch { display: inline-flex; align-items: center; gap: 7px; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text); cursor: pointer; font-size: 12.5px; }
.switch input { display: none; }
.switch span { width: 30px; height: 17px; border-radius: 10px; background: #d1d5db; position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { left: 15px; }
.actcode { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.actcode code { flex: 1; text-align: center; padding: 10px 12px; border: 1.5px dashed #c7ccd6; border-radius: 10px; background: #fafbfc; font: 700 18px "Cascadia Mono", Consolas, monospace; letter-spacing: .12em; color: var(--ink); }
.sec > small.mut { display: block; margin-top: 8px; }
.mlist { border: 1px solid var(--line-2); border-radius: 11px; overflow: hidden; }
.mrow { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-bottom: 1px solid var(--line-2); background: var(--panel); }
.mrow:last-child { border-bottom: 0; }
.mrow > div { flex: 1; min-width: 0; }
.mrow b { display: block; font-size: 13px; color: var(--ink); font-weight: 600; }
.mrow small { color: var(--muted); font-size: 11.5px; }
.mrow.off { background: #fafafa; } .mrow.off b { color: var(--faint); text-decoration: line-through; }
.macts { display: flex; }
.addm { display: grid; grid-template-columns: 1.3fr 1fr auto; gap: 8px; margin-top: 10px; }
.addm input { height: 34px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; outline: 0; min-width: 0; }
.addm input[name=machine] { font: 600 12.5px "Cascadia Mono", Consolas, monospace; letter-spacing: .05em; text-transform: uppercase; }
.addm input:focus { border-color: var(--brand); }
.sel { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.chk2 { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 2px 0 6px; cursor: pointer; }
.okimg { color: var(--ok); font-weight: 600; }
.f input[type=file] { height: auto; padding: 8px; }
@media (max-width: 1100px) { .stats.co { grid-template-columns: repeat(2, 1fr); } }
.mrow .code { font-size: 11.5px; padding: 3px 6px; }

/* ---- Quản trị viên, link tải ---- */
.admgrid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.card.pad { padding: 18px 20px; }
.rolechoice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; cursor: pointer; }
.rolechoice:has(input:checked) { border-color: var(--brand); background: #f6f9ff; }
.rolechoice input { width: auto !important; height: auto !important; margin-top: 3px; accent-color: var(--brand); }
.rolechoice b { display: block; font-size: 13px; }
.rolechoice small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.sel.sm { height: 32px; width: auto; font-size: 12.5px; }
.linkbox { background: linear-gradient(180deg, #fff, #f6f9ff); }
@media (max-width: 1000px) { .admgrid { grid-template-columns: 1fr; } }
