:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-muted: #f0f1f7;
  --text: #1e1b2e;
  --muted: #6b6580;
  --border: #e6e8f0;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --danger: #dc2626;
  --ok: #047857;
  --warn: #b45309;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.04);
  --sidebar-bg: #0b2447;
  --amber: #f59e0b;
}
[data-theme="dark"] {
  --bg: #14121f;
  --surface: #1f1b33;
  --surface-muted: #2a2450;
  --text: #eceaf6;
  --muted: #a9a3c4;
  --border: #3b3562;
  --accent: #a5b4fc;
  --accent-2: #c4b5fd;
  --danger: #f87171;
  --ok: #6ee7b7;
  --warn: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.3);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ------------------------------------------------------------------ */
/* Khung dashboard: sidebar + vùng chính                              */
/* ------------------------------------------------------------------ */
.shell { display: flex; min-height: 100vh; align-items: stretch; }
.sidebar {
  width: 252px; flex-shrink: 0;
  background: var(--sidebar-bg); color: #fff;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  padding: 20px 14px;
}
.side-brand { font-weight: 800; font-size: 18px; padding: 2px 10px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.14); margin-bottom: 16px; }
.side-brand span { display: block; font-size: 12px; font-weight: 400; opacity: 0.65; margin-top: 4px; line-height: 1.5; }
.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left; background: transparent; border: none;
  color: rgba(255, 255, 255, 0.82); border-radius: 10px;
  padding: 11px 12px; font-weight: 600; font-size: 14px;
  display: flex; gap: 10px; align-items: center; cursor: pointer;
}
.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255, 255, 255, 0.08); }
.nav-item.on { background: rgba(255, 255, 255, 0.14); color: #fff; box-shadow: inset 3px 0 0 var(--amber); }
.nav-item.on:hover { background: rgba(255, 255, 255, 0.14); }
.side-foot, .drawer-foot { border-top: 1px solid rgba(255, 255, 255, 0.14); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.side-foot button, .drawer-foot button {
  background: rgba(255, 255, 255, 0.12); color: #fff; border-color: transparent;
  text-align: left; border-radius: 10px;
}
.main { flex: 1; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; font-size: 20px; line-height: 1; padding: 8px 13px; }
.topbar-title { font-weight: 800; font-size: 17px; }
.topbar-spacer { flex: 1; }
.key-dot { display: none; width: 11px; height: 11px; border-radius: 50%; background: #9ca3af; flex-shrink: 0; }
.key-dot.ok { background: #059669; }
.key-dot.bad { background: #dc2626; }
.content { max-width: 1060px; margin: 0 auto; padding: 20px 24px 40px; }

/* ------------------------------------------------------------------ */
/* Thành phần chung                                                   */
/* ------------------------------------------------------------------ */
.pill {
  display: inline-block;
  font-size: 12px; font-weight: 700;
  border-radius: 999px; padding: 5px 12px;
  background: var(--surface-muted); border: 1px solid var(--border); color: var(--muted);
  white-space: nowrap;
}
.pill.ok { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.pill.bad { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
[data-theme="dark"] .pill.ok { background: #064e3b; color: #a7f3d0; }
[data-theme="dark"] .pill.bad { background: #450a0a; color: #fecaca; }
button {
  font: inherit; cursor: pointer;
  border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text);
  padding: 8px 16px; font-weight: 700; font-size: 13.5px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); border-color: #fecaca; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 18px 20px; margin-bottom: 16px;
}
/* Thẻ lồng trong thẻ (vd: từng lô mã trong thẻ Mã khuyến mãi) dùng nền phụ để tách lớp rõ. */
.card .card { background: var(--surface-muted); box-shadow: none; }
.card h2 { margin: 0 0 4px; font-size: 17px; }
[data-panel] > h2 { font-size: 24px; margin: 2px 0 6px; }
.card h3 { margin: 14px 0 6px; font-size: 12px; letter-spacing: 0.6px; color: var(--accent-2); text-transform: uppercase; }
.note {
  font-size: 13px; line-height: 1.65; color: var(--muted);
  background: var(--surface-muted); border-radius: 12px; padding: 11px 13px; margin: 10px 0;
}
.note strong { color: var(--text); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 2px solid var(--border); }
td { padding: 8px; border-bottom: 1px dashed var(--border); vertical-align: top; }
td:last-child, th:last-child { text-align: right; }
input[type="text"], input[type="number"], input[type="url"], textarea, select {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 8px 10px; width: 100%;
}
input[type="number"] { width: 110px; }
textarea { min-height: 110px; font-family: ui-monospace, monospace; font-size: 12.5px; }
label { font-size: 13px; font-weight: 700; display: block; margin: 10px 0 4px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 2px 0 8px; line-height: 1.5; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.field-row > div { flex: 1; min-width: 150px; }
.mono { font-family: ui-monospace, monospace; font-size: 12.5px; word-break: break-all; }
.code-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.code-row .code { font-family: ui-monospace, monospace; font-weight: 700; }
.code-row input { flex: 1; min-width: 140px; }
.msg { font-size: 13.5px; font-weight: 700; margin: 10px 0; line-height: 1.5; }
.msg.ok { color: var(--ok); }
.msg.bad { color: var(--danger); }
.msg.warn { color: var(--warn); }
pre {
  background: var(--surface-muted); border-radius: 12px; padding: 13px;
  overflow: auto; font-size: 12px; line-height: 1.5; max-height: 420px;
  white-space: pre-wrap; word-break: break-all;
}
.badge { font-size: 11px; font-weight: 800; border-radius: 999px; padding: 3px 9px; background: var(--surface-muted); color: var(--muted); white-space: nowrap; }
.badge.red { background: #fef2f2; color: #dc2626; }
.badge.green { background: #ecfdf5; color: #047857; }
[data-theme="dark"] .badge.red { background: #450a0a; color: #fecaca; }
[data-theme="dark"] .badge.green { background: #064e3b; color: #a7f3d0; }
details summary { cursor: pointer; font-weight: 700; font-size: 14px; }
.footer { font-size: 12.5px; color: var(--muted); text-align: center; padding: 18px 8px 30px; line-height: 1.6; }

/* ------------------------------------------------------------------ */
/* Thẻ KPI (Thống kê)                                                 */
/* ------------------------------------------------------------------ */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 12px 0; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 16px;
  display: flex; gap: 12px; align-items: center;
}
.stat-icon {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 12px; background: var(--surface-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; line-height: 1;
}

/* Thẻ mini trên trang Tổng quan (bấm vào để sang Thống kê). */
.mini-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 12px 0; }
.mini-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: flex; gap: 10px; align-items: center;
  cursor: pointer;
}
.mini-card:hover { background: var(--surface-muted); }
.mini-icon {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 10px; background: var(--surface-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; line-height: 1;
}
.mini-label { font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.mini-value { font-size: 20px; font-weight: 800; margin-top: 2px; word-break: break-all; }
.stat-label { font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.stat-value { font-size: 24px; font-weight: 800; margin-top: 2px; word-break: break-all; }

/* ------------------------------------------------------------------ */
/* Ngăn kéo mobile (bản mobile của sidebar)                            */
/* ------------------------------------------------------------------ */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 61;
  width: 280px; max-width: 85vw; overflow-y: auto;
  background: var(--sidebar-bg); color: #fff; box-shadow: var(--shadow);
  padding: 16px 14px; display: flex; flex-direction: column; gap: 4px;
  transform: translateX(-105%); transition: transform 0.2s;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; padding: 2px 4px 12px; border-bottom: 1px solid rgba(255, 255, 255, 0.14); }
.drawer-head button { min-height: 0; padding: 6px 12px; background: rgba(255, 255, 255, 0.12); color: #fff; border-color: transparent; }
.drawer .nav-item { width: 100%; }
.drawer-foot { margin-top: auto; padding-top: 14px; }

/* ------------------------------------------------------------------ */
/* Cổng mã PIN                                                         */
/* ------------------------------------------------------------------ */
.pin-gate {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg); overflow-y: auto;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px;
}
.pin-gate[hidden] { display: none; }
.pin-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px; width: 100%; max-width: 420px; margin-top: 8vh;
}
.pin-card h2 { margin: 0 0 6px; font-size: 19px; }
.pin-card button { margin-top: 10px; }

/* ------------------------------------------------------------------ */
/* Mobile                                                             */
/* ------------------------------------------------------------------ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .menu-btn { display: block; }
  .topbar { padding: 10px 16px; }
  .topbar .pill { display: none; }
  .key-dot { display: block; }
  .content { padding: 16px 16px 32px; }
  .card { padding: 14px 16px; }
  button { min-height: 44px; }
  .field-row > div { flex-basis: 100%; min-width: 0; }
  input[type="number"] { width: 100%; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 20px; }
  .mini-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 769px) {
  .drawer, .drawer-backdrop { display: none; }
}
@media (max-width: 640px) {
  td:last-child, th:last-child { text-align: left; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { border-bottom: 1px solid var(--border); padding: 4px 0; }
  th { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
