:root {
  --bg: #f4f6fa; --panel: #ffffff; --panel-2: #f8fafc; --border: #e3e8ef; --text: #1d2433; --muted: #667085;
  --primary: #2563eb; --primary-600: #1d4ed8; --primary-soft: #e8efff; --danger: #dc2626; --danger-soft: #fdecec;
  --ok: #16a34a; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fff4e0; --hover: #f1f5fb; --sel: #e6eeff;
  --shadow: 0 8px 30px rgba(16, 24, 40, .12); --radius: 10px; --unread: #111827;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c; --panel: #161c26; --panel-2: #1b2230; --border: #2a3342; --text: #e6ebf2; --muted: #98a2b3;
    --primary: #5b8cff; --primary-600: #7aa2ff; --primary-soft: #1e2a44; --danger: #f87171; --danger-soft: #3a1d1d;
    --ok: #4ade80; --ok-soft: #173326; --warn: #fbbf24; --warn-soft: #3a2e14; --hover: #1f2735; --sel: #22304d;
    --shadow: 0 8px 30px rgba(0, 0, 0, .45); --unread: #ffffff; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141c; --panel: #161c26; --panel-2: #1b2230; --border: #2a3342; --text: #e6ebf2; --muted: #98a2b3;
  --primary: #5b8cff; --primary-600: #7aa2ff; --primary-soft: #1e2a44; --danger: #f87171; --danger-soft: #3a1d1d;
  --ok: #4ade80; --ok-soft: #173326; --warn: #fbbf24; --warn-soft: #3a2e14; --hover: #1f2735; --sel: #22304d;
  --shadow: 0 8px 30px rgba(0, 0, 0, .45); --unread: #ffffff; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); cursor: pointer; white-space: nowrap; text-decoration: none !important; color: var(--text); }
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.icon { width: 34px; padding: 0; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.sm.icon { width: 28px; padding: 0; }
.btn svg, .ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.input, select.input, textarea.input { width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); outline: none; }
textarea.input { height: auto; padding: 8px 11px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.card .card-h { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; align-items: center; gap: 10px; }
.card .card-b { padding: 18px; }

.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.badge.blue { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge.green { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.amber { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

.alert { padding: 10px 14px; border-radius: 8px; background: var(--primary-soft); color: var(--text); border: 1px solid transparent; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--panel-2); }
table.grid tr:hover td { background: var(--hover); }

/* Hộp thoại */
.modal-back { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal.wide { width: min(860px, 100%); }
.modal-h { padding: 16px 20px; font-weight: 600; font-size: 16px; display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.modal-b { padding: 18px 20px; overflow: auto; }
.modal-f { padding: 14px 20px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* Thông báo nổi */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 9px; box-shadow: var(--shadow); max-width: 90vw; pointer-events: auto; animation: tin .18s ease-out; }
.toast.error { background: #b91c1c; }
.toast.ok { background: #15803d; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-switch button { border: 0; background: transparent; padding: 4px 10px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.lang-switch button.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.code { font-family: Consolas, "Cascadia Mono", Menlo, monospace; font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; word-break: break-all; }
.copyline { display: flex; gap: 6px; align-items: center; }
.copyline .code { flex: 1; padding: 7px 9px; }

/* Trang xác thực (đăng nhập / đăng ký) */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; }
.auth-card.wide { width: min(560px, 100%); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #3b82f6, #6d28d9); display: grid; place-items: center; color: #fff; }
.brand .logo svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2; }
