/* =========================================================================
   TRANG QUẢN TRỊ & ĐĂNG NHẬP (dùng chung style.css)
   ========================================================================= */
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a.btn { text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; height: 44px; font-size: 15px; }
.hint { margin: 12px 0 0; font-size: 12px; color: var(--text-muted); }
.small { font-size: 12px; }

/* ---------------- Đăng nhập ---------------- */
.auth-body { min-height: 100vh; background: radial-gradient(1200px 600px at 10% -10%, var(--primary-soft), transparent 60%), var(--bg); }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 24px 48px -24px rgba(15,23,42,.25); padding: 28px; }
.auth-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.auth-head h1 { margin: 0; font-size: 20px; font-weight: 800; }
.auth-head p { margin: 2px 0 0; }
.auth-note { padding: 12px 14px; margin-bottom: 16px; border-radius: 10px; background: var(--c-amber-soft); color: var(--c-amber); font-size: 13px; line-height: 1.55; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .select { height: 44px; font-size: 15px; }
.pw-wrap { position: relative; display: block; }
.pw-wrap .select { padding-right: 44px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; background: none; color: var(--text-muted); display: grid; place-items: center; cursor: pointer; border-radius: 6px; }
.pw-toggle:hover { background: var(--muted-bg); }
.pw-meter { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-muted); }
.pw-meter i { flex: 1; height: 6px; border-radius: 999px; background: var(--muted-bg); position: relative; overflow: hidden; }
.pw-meter i::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 999px; background: var(--c-red); transition: width .2s; }
.pw-meter[data-level="1"] i::after { width: 20%; }
.pw-meter[data-level="2"] i::after { width: 40%; background: var(--c-amber); }
.pw-meter[data-level="3"] i::after { width: 60%; background: var(--c-amber); }
.pw-meter[data-level="4"] i::after { width: 80%; background: var(--c-green); }
.pw-meter[data-level="5"] i::after { width: 100%; background: var(--c-green); }
.auth-msg { margin: 0; min-height: 18px; font-size: 13px; font-weight: 600; color: var(--c-red); }
.auth-back { display: inline-flex; align-items: center; gap: 6px; margin-top: 18px; font-size: 13px; color: var(--text-muted); text-decoration: none; }
.auth-back:hover { color: var(--primary); }
.auth-back svg { width: 16px; height: 16px; }

/* ---------------- Khung quản trị ---------------- */
.admin-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 18px 14px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.side-brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 14px; border-bottom: 1px solid var(--border); }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a, .side-links a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text-2); text-decoration: none; font-weight: 600; font-size: 14px; }
.side-nav a:hover, .side-links a:hover { background: var(--muted-bg); color: var(--text); }
.side-nav a.active { background: var(--primary-soft); color: var(--primary); }
.side-nav svg, .side-links svg { width: 18px; height: 18px; }
.nav-dot { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--c-blue); animation: pulse 1s infinite; }
.side-links { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.side-links a { font-size: 13px; color: var(--text-muted); }
.side-links .ext { width: 13px; height: 13px; margin-left: auto; opacity: .6; }

.admin-main { min-width: 0; display: flex; flex-direction: column; }
.admin-top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; height: 64px; padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--border); }
.admin-top h1 { margin: 0; font-size: 19px; font-weight: 800; }
.admin-top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--muted-bg); font-size: 13px; font-weight: 600; color: var(--text-2); }
.user-chip svg { width: 14px; height: 14px; color: var(--c-green); }
.menu-btn { display: none; }
.admin-content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1280px; width: 100%; }
.sec { display: flex; flex-direction: column; gap: 20px; }
.sec[hidden] { display: none; }
.card-narrow { max-width: 720px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; padding: 12px 16px; border-radius: 10px; background: var(--text); color: var(--surface); font-size: 13px; font-weight: 600; box-shadow: 0 12px 24px -8px rgba(0,0,0,.35); max-width: 420px; }
.toast.err { background: var(--c-red); color: #fff; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi { display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.kpi small { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.kpi strong { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi strong.kpi-sm { font-size: 17px; }
.kpi span { font-size: 12px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-btn { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--subtle); text-align: left; cursor: pointer; }
.quick-btn:hover { border-color: var(--primary); background: var(--primary-soft); }
.quick-btn svg { grid-row: span 2; width: 22px; height: 22px; color: var(--primary); }
.quick-btn b { font-size: 14px; }
.quick-btn span { font-size: 12px; color: var(--text-muted); }

/* Cập nhật */
.update-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 14px 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--muted-bg); color: var(--text-2); }
.pill.ok { background: var(--c-green-soft); color: var(--c-green); }
.pill.err { background: var(--c-red-soft); color: var(--c-red); }
.pill.run { background: var(--c-blue-soft); color: var(--c-blue); }
.pill.run::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.progress { margin-bottom: 12px; }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.progress-track { height: 8px; border-radius: 999px; background: var(--muted-bg); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--c-blue); transition: width .3s; }
.log-box summary { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-2); }
.log-box summary svg { width: 16px; height: 16px; }
.log-box pre { margin: 10px 0 0; max-height: 300px; overflow: auto; padding: 12px; border-radius: var(--radius-sm); background: #0f172a; color: #cbd5e1; font-family: var(--mono); font-size: 11.5px; line-height: 1.55; white-space: pre-wrap; }
.kind { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.kind-new { background: var(--c-green-soft); color: var(--c-green); }
.kind-amd { background: var(--c-amber-soft); color: var(--c-amber); }
.kind-abo { background: var(--c-red-soft); color: var(--c-red); }
.diff { font-size: 12px; color: var(--text-muted); }
.diff b { color: var(--text-2); font-weight: 600; }

/* Biểu mẫu */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.span-2 { grid-column: 1 / -1; }
.form-grid .field[hidden] { display: none; }
.switch-inline { margin: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-foot { display: flex; align-items: center; gap: 12px; }
.kiosk-form { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.kiosk-form .card:nth-child(4) { grid-row: span 2; }
.sticky-bar { grid-column: 1 / -1; position: sticky; bottom: 0; display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 -8px 20px -14px rgba(15,23,42,.3); }
.sticky-bar .muted { margin-right: auto; }
.inline-form { display: flex; align-items: flex-end; gap: 10px; margin: 18px 0 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.inline-form .field { flex: 1; }

/* Phiên đăng nhập */
.sessions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.session { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; color: var(--text-muted); }
.session b { color: var(--text); font-size: 13px; }
.session .cur { margin-left: 6px; padding: 1px 6px; border-radius: 999px; background: var(--c-green-soft); color: var(--c-green); font-weight: 700; font-size: 11px; }
.table-tall { max-height: 420px; }
.ev-fail { color: var(--c-red); font-weight: 700; }

/* Cơ quan bị loại trừ */
.excl-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.excl-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 10px; border-radius: 999px; background: var(--c-red-soft); color: var(--c-red); font-size: 13px; font-weight: 600; border: 1px solid transparent; }
.excl-chip svg { width: 14px; height: 14px; }
.excl-chip button { width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent; color: inherit; font-size: 16px; line-height: 1; cursor: pointer; }
.excl-chip button:hover { background: rgba(210,35,42,.15); }
.excl-add { display: flex; align-items: flex-end; gap: 10px; }
.excl-add .field { flex: 1; max-width: 560px; }

/* Lịch sử thao tác */
.card-head-row { justify-content: space-between; }
.link-more { font-size: 13px; font-weight: 600; color: var(--primary); text-decoration: none; }
.link-more:hover { text-decoration: underline; }
.audit-filter { display: grid; grid-template-columns: 2fr repeat(5, 1fr) auto; gap: 10px; align-items: end; margin: 14px 0 6px; padding: 14px; background: var(--subtle); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.input-ico { position: relative; display: block; }
.input-ico svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); }
.input-ico .select { padding-left: 34px; }
.audit-table td { vertical-align: top; }
.audit-table .name { font-weight: 600; color: var(--text); }
.nowrap { white-space: nowrap; }
.row-fail td { background: var(--c-red-soft); }
.cat { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.cat-cfg { background: var(--c-violet-soft); color: var(--c-violet); }
.cat-data { background: var(--c-blue-soft); color: var(--c-blue); }
.cat-login { background: var(--muted-bg); color: var(--text-2); }
.cat-sec { background: var(--c-amber-soft); color: var(--c-amber); }
.cat-other { background: var(--muted-bg); color: var(--text-muted); }
.chg { font-size: 12px; line-height: 1.6; color: var(--text-2); }
.chg b { font-weight: 600; }
.chg-from { color: var(--c-red); text-decoration: line-through; text-decoration-color: rgba(210,35,42,.4); }
.chg-to { color: var(--c-green); font-weight: 600; }
.chg-arrow { color: var(--text-muted); }
.recent-ops { display: flex; flex-direction: column; }
.op { padding: 10px 0; border-bottom: 1px solid var(--border); }
.op:last-child { border-bottom: 0; }
.op-main { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 13px; }
.op-meta { margin-top: 2px; font-size: 12px; color: var(--text-muted); }
.op-changes { margin-top: 4px; padding-left: 10px; border-left: 2px solid var(--border); }
.op-fail .op-main b { color: var(--c-red); }

/* Màn hình nhỏ */
@media (max-width: 1280px) { .audit-filter { grid-template-columns: repeat(3, 1fr); } .audit-q { grid-column: 1 / -1; } }
@media (max-width: 1080px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .grid-2, .kiosk-form { grid-template-columns: 1fr; }
    .kiosk-form .card:nth-child(4) { grid-row: auto; }
}
@media (max-width: 860px) {
    .admin-shell { grid-template-columns: 1fr; }
    .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.25); }
    .side.open { transform: none; }
    .menu-btn { display: grid; }
    .admin-top { padding: 0 14px; }
    .admin-top .btn span, .user-chip span { display: none; }
    .admin-content { padding: 16px 14px 40px; }
    .quick, .form-grid, .audit-filter { grid-template-columns: 1fr; }
}
