:root {
  --ink: #1f2a37; --muted: #6b7280; --line: #e5e7eb; --bg: #f5f6f8; --card: #fff;
  --brand: #f7931e; --brand-ink: #7a3e00; --ok: #15803d; --ok-bg: #dcfce7; --warn: #b45309; --warn-bg: #fef3c7; --bad: #b91c1c; --bad-bg: #fee2e2;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: #0b61c4; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* khung */
.topbar { background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 5; }
.topbar .row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; max-width: 1180px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; color: #fff; white-space: nowrap; }
.brand img { width: 28px; height: 28px; }
.spacer { flex: 1; }
.who { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.who .name { font-weight: 600; }
.nav { background: #2b3745; }
.nav .row { display: flex; gap: 2px; padding: 0 12px; max-width: 1180px; margin: 0 auto; overflow-x: auto; }
.nav a { color: #cbd5e1; text-decoration: none; padding: 10px 14px; white-space: nowrap; border-bottom: 3px solid transparent; }
.nav a:hover { color: #fff; }
.nav a.on { color: #fff; border-bottom-color: var(--brand); }
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .grow { flex: 1; min-width: 200px; }

/* nút & biểu mẫu */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--line); background: #fff; border-radius: 9px; cursor: pointer; text-decoration: none; color: var(--ink); min-height: 38px; }
.btn:hover { border-color: #cbd5e1; background: #f9fafb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #2b1600; font-weight: 600; }
.btn.primary:hover { filter: brightness(.96); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--bad); border-color: #fecaca; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 3px; }
.field input, .field select, .field textarea { width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; min-height: 38px; }
.field input:focus, .field select:focus { outline: 2px solid rgba(247, 147, 30, .45); border-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.error { color: var(--bad); background: var(--bad-bg); padding: 8px 10px; border-radius: 8px; margin: 8px 0; }
.notice { background: var(--warn-bg); color: #78350f; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; }

/* thẻ ứng dụng */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card .top { display: flex; gap: 12px; align-items: flex-start; }
.logo { width: 44px; height: 44px; border-radius: 11px; background: var(--ink); color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; flex: none; }
.logo.website { background: #0b61c4; color: #fff; }
.card h2 { margin: 0; font-size: 1.05rem; }
.card .host { color: var(--muted); font-size: .85rem; word-break: break-all; }
.card .foot { display: flex; align-items: center; gap: 8px; margin-top: auto; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.off { background: #e5e7eb; color: #4b5563; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: .78rem; background: #eef2ff; color: #3730a3; margin: 1px 2px 1px 0; }
.badge.super { background: #fff1d6; color: var(--brand-ink); }

/* bảng */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafafa; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
tr.inactive td { opacity: .55; }
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; }
.matrix th:first-child { background: #fafafa; }
.matrix select { padding: 5px 6px; border: 1px solid #d1d5db; border-radius: 7px; background: #fff; max-width: 170px; }
.matrix select.granted { border-color: var(--brand); background: #fff8ec; font-weight: 600; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); background: var(--card); border: 1px dashed #d1d5db; border-radius: var(--radius); }

/* hộp thoại */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(15, 23, 42, .5); }
dialog header { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
dialog header h2 { margin: 0; flex: 1; }
dialog .body { padding: 16px; max-height: 70vh; overflow: auto; }
dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.code { font-family: ui-monospace, Consolas, monospace; background: #f3f4f6; padding: 2px 6px; border-radius: 5px; word-break: break-all; }
.secret-box { background: #111827; color: #f9fafb; padding: 12px; border-radius: 10px; font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem; text-align: center; letter-spacing: .04em; user-select: all; }

/* đăng nhập */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #1f2a37 0%, #2d3a4a 55%, #5a3b0f 100%); }
.login-card { background: #fff; width: min(400px, 100%); border-radius: 16px; padding: 28px 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.login-card .logo { margin: 0 auto 12px; width: 54px; height: 54px; }
.login-card h1 { text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 18px; }

/* thông báo nhanh */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(440px, calc(100vw - 24px)); }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .3); }
.toast.bad { background: var(--bad); }
