:root {
  --bg: #f4f6fa; --card: #ffffff; --line: #e1e6ef; --fg: #1b2333; --muted: #667085;
  --pri: #1a56db; --pri2: #1446b8; --ok: #127a43; --warn: #b54708; --err: #c0262d; --soft: #eef3ff;
  --code: #f2f4f7; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1420; --card: #161e2d; --line: #2a3446; --fg: #e4e9f2; --muted: #98a2b3;
    --pri: #4a7dff; --pri2: #3a6aea; --ok: #3ccb7f; --warn: #f5a524; --err: #f97066; --soft: #1b2740; --code: #1f293a; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--pri); }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 0 12px; height: 42px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); outline: none; }
textarea { height: auto; padding: 10px 12px; }
select { appearance: none; -webkit-appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px; background-size: 5px 5px; background-repeat: no-repeat; }
input[type=checkbox] { height: auto; width: auto; }
.btn { height: 42px; display: inline-flex; align-items: center; justify-content: center; }
.btn.small { height: 32px; }
input:focus, select:focus, textarea:focus { border-color: var(--pri); }
.btn { border: 0; border-radius: 8px; padding: 10px 16px; background: var(--pri); color: #fff; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--pri2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { background: var(--err); }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--err); font-size: 14px; min-height: 20px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.login-card .sub { text-align: center; margin-bottom: 18px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.login-card .btn { width: 100%; margin-top: 18px; }
.otp-input { letter-spacing: 6px; text-align: center; font-size: 20px; }
.brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 8px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--pri); color: #fff; display: grid; place-items: center; font-weight: 800; }

/* App */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top .brand { margin: 0; justify-content: flex-start; font-weight: 700; }
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { background: none; border: 0; padding: 12px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; white-space: nowrap; }
.tab.active { color: var(--pri); border-bottom-color: var(--pri); }
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.mode { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; margin-bottom: 12px; }
.mode button { border: 0; background: transparent; padding: 8px 14px; cursor: pointer; font-weight: 600; color: var(--muted); }
.mode button.active { background: var(--soft); color: var(--pri); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1 1 260px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.check input { width: auto; }
.status { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 8px; background: var(--soft); margin-top: 12px; font-size: 14px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--pri); border-radius: 50%; animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--code); color: var(--muted); }
.badge.done { color: var(--ok); } .badge.error { color: var(--err); } .badge.running, .badge.queued { color: var(--warn); }

/* Báo cáo */
.report { overflow-wrap: anywhere; }
.report h1, .report h2, .report h3, .report h4 { line-height: 1.3; margin: 18px 0 8px; }
.report h1 { font-size: 20px; } .report h2 { font-size: 18px; } .report h3 { font-size: 16px; } .report h4 { font-size: 15px; }
.report table { border-collapse: collapse; width: 100%; margin: 8px 0 14px; font-size: 14px; display: block; overflow-x: auto; }
.report th, .report td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.report th { background: var(--code); }
.report code { background: var(--code); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.report pre { background: var(--code); padding: 12px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; }
.report ul, .report ol { padding-left: 22px; }
.lark-box { white-space: pre-wrap; background: var(--code); border-radius: 8px; padding: 12px; font-size: 14px; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; margin-top: 8px; }

/* Bảng danh sách */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 13px; }
.tbl-wrap { overflow-x: auto; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover { background: var(--soft); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 12px; align-items: end; }
.grid2 > div { display: flex; flex-direction: column; min-width: 0; }
.grid2 label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid2 .span2 { grid-column: span 2; }
.grid2 .field-btn .btn { width: 100%; }
.hint { color: var(--muted); font-weight: 400; opacity: .85; }
@media (max-width: 520px) { .grid2 .span2 { grid-column: auto; } }
.tbl-users td { vertical-align: middle; }
.tbl-users input.ids { height: 34px; min-width: 200px; }
.actions { display: flex; gap: 6px; flex-wrap: nowrap; justify-content: flex-start; }
.tbl-users { min-width: 980px; }
.tbl-users td, .tbl-users th { white-space: nowrap; }
.tbl-users td:nth-child(4) { width: 100%; }
.tbl-users input.ids { width: 100%; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; }
.stat { background: var(--soft); border-radius: 10px; padding: 10px 14px; min-width: 140px; }
.stat b { display: block; font-size: 20px; }
@media (max-width: 600px) {
  .top { padding: 10px 12px; } .tabs { padding: 0 8px; } main { padding: 14px 10px 40px; }
  .row > .btn { flex: 1 1 auto; }
}
.center { text-align: center; }
.result-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.result-actions:has(.btn.hidden) { margin-bottom: 0; }
