:root {
  --bg: #f1ede6; --ink: #23252f; --muted: #666a78; --panel: #fff; --line: #e0dbd1;
  --accent: #3d6fb4; --accent-ink: #fff; --ok: #1f7a4d; --ok-bg: #e6f4ec; --bad: #a3261f; --bad-bg: #fbeceb;
  --info-bg: #e7effa; --info: #2c5a99; --warn-bg: #fff4d6; --warn-line: #f0d58a; --warn-ink: #6a5200;
}
@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --bg: #1b1d24; --ink: #eceae5; --muted: #a3a6b3; --panel: #262932; --line: #3a3e4a;
    --accent: #6c9be0; --accent-ink: #10131a; --ok: #7fd1a4; --ok-bg: #1d3328; --bad: #f4a19b; --bad-bg: #3a2224;
    --info-bg: #1f2a3c; --info: #9dbcec; --warn-bg: #3a3218; --warn-line: #6b5a24; --warn-ink: #f3dc93; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.55 "Be Vietnam Pro", system-ui, "Segoe UI", sans-serif; }
.top, main { max-width: 820px; margin: 0 auto; padding-inline: 16px; }
.top { padding-block: 24px 8px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
small { display: block; margin-top: 4px; }
code { background: color-mix(in srgb, var(--line) 55%, transparent); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; word-break: break-all; }
main { display: flex; flex-direction: column; gap: 14px; padding-bottom: 40px; }
#app { display: flex; flex-direction: column; gap: 14px; }
#app[hidden] { display: none; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.between h2 { margin: 0; }
input, select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
.row input { flex: 1; min-width: 180px; width: auto; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button { font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 8px 16px; cursor: pointer; background: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.small { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }
.field { margin-top: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 18px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
details { margin-top: 12px; }
summary { cursor: pointer; color: var(--accent); }
details .steps { margin-top: 8px; }
.copyrow { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.notice { border-radius: 10px; padding: 12px 14px; }
.notice.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.err { color: var(--bad); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 12px 0; }
.stat { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12.5px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td, th { text-align: left; padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
.tablewrap { overflow-x: auto; }
[data-for][hidden] { display: none !important; }

/* Danh sách phòng ban */
.hint { margin: 6px 0 12px; }
.depts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.dept { --c: #999; border: 1px solid var(--line); border-left: 5px solid var(--c); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.dept-head { display: flex; gap: 8px; align-items: center; }
.dept-head .d-name { flex: 1; min-width: 0; font-weight: 600; }
.d-color { width: 36px; height: 36px; padding: 2px; flex: none; cursor: pointer; }
.d-state { flex: none; white-space: nowrap; }
.d-state[hidden] { display: none; }
button.icon { flex: none; width: 34px; height: 34px; padding: 0; font-size: 20px; line-height: 1; background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.icon:hover:not(:disabled) { color: var(--bad); border-color: var(--bad); background: var(--bad-bg); }
.d-more summary { font-size: 13px; }
.d-more .grid2 .field { margin-top: 8px; }
.d-result:empty { display: none; }
.d-result .notice { padding: 8px 12px; }
.d-result details { margin-top: 6px; }
p.small, .small { font-size: 12.5px; margin: 0 0 4px; }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.info { background: var(--info-bg); color: var(--info); }
@media (max-width: 560px) { .dept-head { flex-wrap: wrap; } .dept-head .d-name { flex-basis: calc(100% - 90px); } }

/* Thanh lưu dính đáy */
.savebar { position: sticky; bottom: 0; padding: 10px 16px 14px; background: linear-gradient(transparent, var(--bg) 35%); }
.savebar-in { max-width: 788px; margin: 0 auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 10px 14px; box-shadow: 0 6px 20px rgb(0 0 0 / .12); }
.savebar-in #save-msg { flex: 1; min-width: 160px; font-weight: 500; }
.savebar[hidden] { display: none; }

/* Hộp thoại xoá */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px; max-width: min(460px, calc(100vw - 32px)); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin-bottom: 10px; }
.warnlist { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.actions.end { justify-content: flex-end; }
button.danger { background: var(--bad); color: #fff; }
@media (prefers-color-scheme: dark) { button.danger { color: #1b1d24; } }

/* Khoá kết nối */
.key { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.key-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }
.key-head small { display: inline; margin: 0 0 0 4px; }
.key textarea { font: 12.5px/1.45 ui-monospace, Consolas, monospace; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; resize: vertical; }
.key .k-edit { display: flex; flex-direction: column; gap: 8px; }
.key .k-edit[hidden], .key .k-actions[hidden], .key [hidden] { display: none !important; }
.key details { margin-top: 0; }
.k-msg { white-space: pre-line; }
.k-msg:empty { display: none; }
.wai { border-top: 1px dashed var(--line, #ddd); margin-top: 12px; padding-top: 10px; }
.k-msg.ok { color: var(--ok); } .k-msg.err { color: var(--bad); }
.filebtn { display: inline-flex; align-items: center; font-weight: 600; border-radius: 8px; padding: 4px 10px; font-size: 13px; cursor: pointer; color: var(--accent); border: 1px solid var(--accent); }
.filebtn:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
button.danger-text { color: var(--bad); border-color: var(--bad); }
#card-sp .key { margin-top: 14px; }
.dept textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; resize: vertical; }
.dept textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.d-more .field:first-of-type { margin-top: 8px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; color: var(--muted); border-radius: 8px 8px 0 0; padding: 8px 14px; border: 1px solid transparent; border-bottom: 0; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); background: var(--panel); border-color: var(--line); }
.tabpane { display: flex; flex-direction: column; gap: 14px; }
.tabpane[hidden] { display: none; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
label.check input { width: auto; accent-color: var(--accent); }

/* Ô số liệu */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0 4px; }
.tile { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.tile b { font-size: 26px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile span { font-weight: 600; font-size: 13px; }
.tile small { color: var(--muted); font-size: 12px; margin: 2px 0 0; }
.tile.warn { border-color: var(--warn-line); background: var(--warn-bg); }
.tile.warn b, .tile.warn span { color: var(--warn-ink); }

/* Biểu đồ */
.charts { margin-top: 12px; align-items: start; }
.chart { margin: 0; min-width: 0; }
.chart figcaption { font-weight: 600; margin-bottom: 8px; }
.cols { --n: 30; display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 2px; height: 130px; align-items: end;
  border-bottom: 1px solid var(--line); background: linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 100% 50%; }
.cols .col { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; outline: none; }
.cols .col i { display: block; width: 100%; max-width: 14px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 0; }
.cols .col i.miss { position: absolute; bottom: 0; background: repeating-linear-gradient(135deg, var(--warn-line) 0 3px, var(--warn-bg) 3px 6px); border-radius: 0; }
.cols .col:hover i:not(.miss), .cols .col:focus-visible i:not(.miss) { filter: brightness(1.15); }
.cols .col:hover::after, .cols .col:focus-visible::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--panel); font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; z-index: 2; pointer-events: none; }
.cols-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.hbars { display: flex; flex-direction: column; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.hbar .track { height: 12px; }
.hbar .track i { display: block; height: 100%; background: var(--c); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .val { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.dchip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dchip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
#st-miss td:first-child, #st-down td:first-child, #st-top td:first-child { font-weight: 500; }
h2 small { display: inline; font-weight: 400; font-size: 13px; }
@media (max-width: 560px) { .hbar { grid-template-columns: 1fr auto; } .hbar .track { grid-column: 1 / -1; order: 3; } }
.row select { width: auto; }

/* Tài liệu tải lên */
.d-docs { border-top: 1px dashed var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.d-docs-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.d-docs-head b { font-size: 13px; }
.d-docs-used { flex: 1; }
.d-docs-used.warn-text { color: var(--warn-ink); font-weight: 600; }
.d-doclist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.d-doclist li { display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 2px 0; }
.d-doclist li.empty { padding: 0; }
.d-doclist .doc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.icon.small-icon { width: 24px; height: 24px; font-size: 15px; }
.d-docs-msg { white-space: pre-line; margin: 0; }
.d-docs-msg:empty { display: none; }
.d-docs-msg.ok { color: var(--ok); } .d-docs-msg.err { color: var(--bad); }
.filebtn.disabled { opacity: .5; cursor: default; pointer-events: none; }

/* Chọn nguồn tài liệu */
.d-src { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.d-src .seg { background: transparent; color: var(--muted); border: 1px solid var(--line); font-weight: 600; font-size: 13px; padding: 5px 12px; border-radius: 999px; }
.d-src .seg[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.d-src .seg:not([aria-pressed="true"]):hover { border-color: var(--accent); color: var(--accent); }
.d-link { display: flex; flex-direction: column; gap: 8px; }
.d-link[hidden], .d-docs[hidden] { display: none; }
.d-link-note:empty { display: none; }
.d-link-note { margin: 0; }
.d-docs { border-top: 0; padding-top: 0; }

/* Nút × xoá (phòng ban, file): to, đỏ, dễ thấy */
button.icon { width: 36px; height: 36px; font-size: 24px; font-weight: 700; line-height: 1; color: var(--bad);
  border: 1.5px solid color-mix(in srgb, var(--bad) 45%, transparent); background: transparent; }
button.icon:hover:not(:disabled), button.icon:focus-visible { color: #fff; background: var(--bad); border-color: var(--bad); }
button.icon:disabled { color: var(--muted); border-color: var(--line); }
button.icon.small-icon { width: 30px; height: 30px; font-size: 20px; }

/* Nhóm "Đọc thư mục qua link": Drive / SharePoint chung một khung, chọn bằng tab */
.key.flat { border: 0; padding: 0; margin: 0; }
.key-group .ftab { display: flex; flex-direction: column; gap: 8px; border-top: 1px dashed var(--line); padding-top: 10px; }
.key-group .ftab[hidden] { display: none; }
.key-group .ftab .grid2 .field { margin-top: 0; }
.seg .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 4px; background: var(--line); vertical-align: middle; }
.seg .dot.on { background: var(--ok); }
.seg[aria-pressed="true"] .dot.on { background: #fff; }

/* ---------- Đăng nhập ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
body[data-view="login"] .top, body[data-view="login"] main, body[data-view="loading"] .top, body[data-view="loading"] main { display: none; }
body:not([data-view="login"]) #login { display: none; }
#login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 500px at 50% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%), var(--bg); }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 32px 28px 22px; box-shadow: 0 1px 2px rgb(0 0 0 / .04), 0 12px 32px -12px rgb(0 0 0 / .18);
  display: flex; flex-direction: column; align-items: stretch; text-align: center; }
.login-logo { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 14px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, var(--panel)); color: var(--accent); }
.login-card h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.login-sub { margin: 2px 0 22px; color: var(--muted); }
.pw { position: relative; }
.pw input { height: 46px; padding: 0 44px 0 14px; border-radius: 10px; font-size: 15px; }
.pw-eye { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); width: 34px; height: 34px; padding: 0;
  display: grid; place-items: center; background: transparent; color: var(--muted); border-radius: 8px; }
.pw-eye:hover, .pw-eye[aria-pressed="true"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
label.check.login-remember { font-weight: 400; justify-content: flex-start; margin: 12px 2px 0; color: var(--muted); font-size: 13.5px; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.login-remember input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.login-err { margin: 12px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--bad-bg); color: var(--bad); font-size: 13.5px; text-align: left; }
.login-err[hidden] { display: none; }
.login-btn { margin-top: 16px; height: 46px; border-radius: 10px; font-size: 15px; }
.login-back { margin-top: 16px; font-size: 13px; color: var(--muted); text-decoration: none; }
.login-back:hover { color: var(--accent); text-decoration: underline; }
/* thanh trên cùng khi đã đăng nhập */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.top h1 { margin: 0; }
.top-links { display: flex; align-items: center; gap: 14px; font-size: 13.5px; }
.top-links a { text-decoration: none; }
