:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger: #c62828;
  --radius: 10px;
  --gutter: clamp(12px, 3vw, 32px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --border: #2c3440;
    --primary: #4f8cff;
    --danger: #ef7070;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
[hidden] { display: none !important; }
.brand { font-weight: 700; font-size: 20px; letter-spacing: 0.2px; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: var(--gutter); }
.login-card { width: min(360px, 100%); display: grid; gap: 10px; }
.login-card h1 { margin: 0; }
.login-card p.muted { margin: 0 0 8px; }
input {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.btn { font: inherit; border-radius: 8px; padding: 9px 14px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.6; cursor: default; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px var(--gutter); background: var(--surface); border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tab { font: inherit; background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--text); background: var(--bg); font-weight: 600; }
.content { padding: var(--gutter); }
.panel h2 { margin-top: 0; font-size: 18px; }
.version { position: fixed; left: 8px; bottom: 6px; font-size: 11px; color: var(--muted); opacity: 0.7; pointer-events: none; }

/* --- Nội dung các tab --- */
:root { --warn: #b45309; --ok: #15803d; --row-hover: rgba(37, 99, 235, 0.05); }
@media (prefers-color-scheme: dark) { :root { --warn: #f0b35a; --ok: #4ade80; --row-hover: rgba(79, 140, 255, 0.08); } }
.content { display: block; }
.panel { display: grid; gap: 16px; }
.card h2 { margin: 0; font-size: 17px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.stack { display: grid; gap: 8px; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.small { font-size: 13px; }
.note { color: var(--muted); margin: 8px 0; }
code { font-size: 12px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
textarea, select {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
select { width: auto; max-width: 100%; }
textarea { resize: vertical; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input[type="search"] { width: auto; flex: 1 1 200px; }
.btn.small { padding: 4px 9px; font-size: 13px; white-space: nowrap; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; border: 0; background: var(--surface); color: var(--muted); padding: 7px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--primary); color: var(--primary-text); }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
.grid td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.grid tbody tr:hover td { background: var(--row-hover); }
.grid .num { text-align: right; white-space: nowrap; }
.grid .wide { min-width: 260px; }
.grid .title a { color: var(--text); text-decoration: none; }
.grid .title a:hover { color: var(--primary); text-decoration: underline; }
.grid a { color: var(--primary); }
.grid .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.empty-row { color: var(--muted); text-align: center; padding: 24px; }
.thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; display: block; background: var(--bg); }
.thumb.empty { border: 1px dashed var(--border); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--bg); }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 18px; font-weight: 600; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--muted); }

.progress { position: relative; height: 22px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); margin-top: 10px; overflow: hidden; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--primary); opacity: 0.25; transition: width 0.3s; }
.progress span { position: relative; padding: 0 8px; line-height: 22px; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(440px, 92vw); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.toast { position: fixed; right: 16px; bottom: 16px; max-width: min(420px, 92vw); background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: 8px; padding: 10px 14px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); z-index: 10; }
.toast.bad { border-left-color: var(--danger); }
@media (max-width: 600px) {
  .card { padding: 14px; }
  .grid th, .grid td { padding: 6px; }
}
/* Lưới không bị bảng rộng kéo giãn: bảng tự cuộn trong .table-wrap. */
.panel > *, .card { min-width: 0; }
@media (max-width: 600px) {
  .topbar { gap: 8px; }
  .topbar .brand { margin-right: auto; }
  .tabs { order: 3; flex-basis: 100%; }
  .filters > * { flex: 1 1 140px; }
}
