:root {
  --bg-void: #14141c;
  --surface: #1e1e29;
  --surface-raised: #272736;
  --border: rgba(255, 255, 255, 0.08);
  --gold: #f5b942;
  --gold-dim: #a9812f;
  --live: #ff4468;
  --text-primary: #f2f0ea;
  --text-muted: #8d8ca0;
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg-void);
  color: var(--text-primary);
  font-family: var(--font-body);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, var(--gold), var(--gold-dim));
  color: #14141c;
  flex-shrink: 0;
}
.brand h1 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(245, 185, 66, 0.08), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(255, 68, 104, 0.08), transparent 40%),
    var(--bg-void);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
}
.login-card .brand { margin-bottom: 28px; }
#loginForm { display: flex; flex-direction: column; gap: 10px; }
#loginForm label { font-size: 13px; color: var(--text-muted); margin-bottom: 2px; }
#loginForm input {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 14px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 14px;
}
#loginForm input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
#loginForm button {
  margin-top: 8px;
  background: var(--gold);
  color: #14141c;
  border: none;
  padding: 12px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
}
#loginForm button:hover { background: #ffcb66; }
.error { color: var(--live); font-size: 13px; min-height: 18px; margin: 4px 0 0; }

/* ---------- App shell ---------- */
.topbar {
  display: flex; align-items: center; gap: 32px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand-small h1 { font-size: 17px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: 9px;
  cursor: pointer;
}
.tab-btn:hover { color: var(--text-primary); background: var(--surface-raised); }
.tab-btn.active { color: #14141c; background: var(--gold); font-weight: 600; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 9px 14px;
  border-radius: 9px;
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--surface-raised); }

.btn-primary {
  background: var(--gold);
  border: 1px solid var(--gold);
  color: #14141c;
  padding: 9px 16px;
  border-radius: 9px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover:not(:disabled) { background: #ffc95c; }

.btn-danger {
  background: transparent;
  border: 1px solid rgba(255, 68, 104, 0.45);
  color: var(--live);
  padding: 9px 16px;
  border-radius: 9px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger:hover:not(:disabled) { background: rgba(255, 68, 104, 0.12); }

.btn-primary:disabled,
.btn-danger:disabled { opacity: 0.4; cursor: not-allowed; }

/* Số quà đang chờ duyệt, hiện cạnh chữ "Người dùng" trên thanh tab */
.tab-badge {
  display: inline-block;
  min-width: 19px;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--live);
  color: #fff;
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  vertical-align: 1px;
}
/* Tab đang mở có nền vàng -> viền trắng mỏng cho số đỏ vẫn nổi */
.tab-btn.active .tab-badge { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.85); }

/* ---------- Khung "Yêu cầu xin quà" (đầu trang chi tiết khách) ---------- */

.request-box {
  background: var(--surface);
  border: 1px solid rgba(255, 68, 104, 0.35);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 22px;
}

.request-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.request-head h3 {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0 0 5px;
}
.req-count {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--live);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
}

.request-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 340px;
  overflow-y: auto;
  margin-bottom: 14px;
}

.request-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  cursor: pointer;
}
.request-row:hover { border-color: var(--gold-dim); }
.request-row:has(.req-check:checked) {
  border-color: var(--gold);
  background: rgba(245, 185, 66, 0.08);
}

.req-check { width: 17px; height: 17px; accent-color: var(--gold); cursor: pointer; flex: none; }

.req-icon { width: 34px; height: 34px; flex: none; }
.req-icon img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; display: block; }
.req-icon-empty {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--bg-void); color: var(--text-muted); font-size: 15px;
}

.req-name { flex: 1; font-size: 14px; min-width: 0; }
.req-diamond {
  display: inline-block;
  margin-left: 8px;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

/* Nút "Chọn file": giấu ô file gốc xấu xí, dùng nhãn bên cạnh làm nút */
.req-file { display: flex; align-items: center; gap: 8px; flex: none; }
.req-audio { width: 106px; font-size: 11.5px; color: var(--text-muted); }
.req-audio::file-selector-button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 7px;
  padding: 5px 9px;
  font-family: var(--font-body);
  font-size: 12px;
  cursor: pointer;
}
.req-audio::file-selector-button:hover { background: var(--bg-void); border-color: var(--gold); }
.req-file-name {
  width: 150px;
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.req-file-name.has-file { color: var(--gold); }

.request-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.req-reason {
  flex: 1;
  min-width: 220px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 9px;
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: 13px;
}
.req-reason:focus { outline: none; border-color: var(--gold-dim); }

@media (max-width: 720px) {
  .request-row { flex-wrap: wrap; }
  .req-file { width: 100%; padding-left: 46px; }
  .req-file-name { width: auto; flex: 1; }
}

.content { max-width: 1080px; margin: 0 auto; padding: 32px 28px 64px; }

.panel-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.panel-head h2 { font-family: var(--font-display); font-size: 22px; margin: 0 0 6px; }
.subtitle { color: var(--text-muted); font-size: 13.5px; margin: 0; max-width: 520px; }

.inline-form { display: flex; gap: 8px; }
.inline-form input {
  width: 72px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 9px 10px;
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.inline-form button, #audioModalUpload {
  background: var(--gold);
  color: #14141c;
  border: none;
  padding: 9px 16px;
  border-radius: 9px;
  font-weight: 600;
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
}
.inline-form button:hover, #audioModalUpload:hover { background: #ffcb66; }

/* ---------- Tables ---------- */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

/* Khung cuộn riêng cho các bảng quà (danh sách dài không làm trang web dài ra).
   Ô tìm kiếm + nút sắp xếp đặt ngoài khung này nên luôn nhìn thấy được. */
.table-scroll {
  max-height: 420px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* Hàng tiêu đề dính ở trên khi cuộn */
.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  /* border-bottom của th không dính khi sticky -> dùng shadow thay cho đường kẻ */
  box-shadow: inset 0 -1px 0 var(--border);
}
.table-scroll::-webkit-scrollbar { width: 10px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb {
  background: var(--surface-raised);
  border-radius: 6px;
  border: 2px solid var(--surface);
}
.table-scroll::-webkit-scrollbar-thumb:hover { background: #3a3a4d; }
td {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
tr:last-child td { border-bottom: none; }
td.mono, .mono { font-family: var(--font-mono); font-size: 13px; }

.empty-state { padding: 32px 20px; text-align: center; color: var(--text-muted); font-size: 13.5px; }

/* Live badge with signature equalizer animation */
.badge { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; padding: 5px 10px; border-radius: 100px; }
.badge-live { background: rgba(255, 68, 104, 0.14); color: var(--live); }
.badge-offline { background: rgba(141, 140, 160, 0.14); color: var(--text-muted); }
.badge-used { background: rgba(141, 140, 160, 0.14); color: var(--text-muted); }
.badge-unused { background: rgba(245, 185, 66, 0.16); color: var(--gold); }

/* Trạng thái thời hạn key */
.badge-ok { background: rgba(70, 200, 120, 0.16); color: #46c878; }
.badge-warn { background: rgba(245, 185, 66, 0.16); color: var(--gold); }
.badge-expired { background: rgba(255, 68, 104, 0.16); color: var(--live); }
.text-danger { color: var(--live); font-weight: 600; }
.text-ok { color: #46c878; font-weight: 600; }
.badge-muted { background: rgba(141, 140, 160, 0.14); color: var(--text-muted); }

/* Dòng đếm số quà thực sự chạy được trên máy khách */
.active-count {
  margin: 0 0 12px;
  font-size: 13.5px;
  color: var(--text-muted);
}
.key-inline { font-size: 11px; }
.last-login { font-size: 11px; opacity: 0.75; }

/* ---------- Bảng khách: gọn lại cho vừa màn hình 1280px ---------- */
#usersTable th, #usersTable td { padding: 12px 14px; vertical-align: top; }
#usersTable td { font-size: 13px; }
.nowrap { white-space: nowrap; }

.cell-user { min-width: 150px; }
.user-name { font-weight: 600; }
.cell-sub { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }

/* Key rút gọn + nút copy nhỏ */
.key-short { font-size: 11.5px; color: var(--text-muted); cursor: help; }
.key-copy {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 12px; padding: 0 4px; line-height: 1;
}
.key-copy:hover { color: var(--gold); }

/* Nhãn ngắn cạnh tên đăng nhập - không được xuống dòng dọc */
#usersTable .badge { white-space: nowrap; }
.unlink-hint { white-space: normal; max-width: 190px; }

/* ---------- Menu "⋯" gom các hành động ---------- */
.col-menu { width: 44px; text-align: right; }
.row-menu-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 8px;
  width: 32px; height: 30px; cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0;
}
.row-menu-btn:hover { background: var(--surface-raised); border-color: var(--gold); }

#usersTable td.col-menu { position: relative; overflow: visible; }
.table-wrap:has(#usersTable) { overflow: visible; }

.row-menu {
  position: absolute; right: 12px; top: 42px; z-index: 40;
  min-width: 210px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  text-align: left;
}
.row-menu button {
  display: block; width: 100%; text-align: left;
  background: none; border: none;
  color: var(--text-primary);
  font-family: var(--font-body); font-size: 13px;
  padding: 9px 12px; border-radius: 7px; cursor: pointer;
  white-space: nowrap;
}
.row-menu button:hover { background: rgba(255, 255, 255, 0.06); }
.row-menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.row-menu .menu-danger { color: var(--live); }
.row-menu .menu-danger:hover { background: rgba(255, 68, 104, 0.1); }
.unlink-hint {
  display: inline-block;
  margin-top: 4px;
  font-family: var(--font-body);
  font-size: 11.5px;
  color: var(--gold);
  line-height: 1.4;
}
.hard-delete-note { font-size: 12px; cursor: help; border-bottom: 1px dotted var(--text-muted); }
.row-actions { white-space: nowrap; }
.row-actions .link-btn { margin-right: 12px; }
.row-actions .link-btn:last-child { margin-right: 0; }

.warn-box {
  background: rgba(245, 185, 66, 0.1);
  border: 1px solid rgba(245, 185, 66, 0.35);
  color: var(--text-primary);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 18px;
  font-size: 13.5px;
  line-height: 1.55;
}

.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.eq span { width: 2.5px; background: var(--live); border-radius: 2px; animation: eq 0.9s ease-in-out infinite; }
.eq span:nth-child(1) { height: 40%; animation-delay: 0s; }
.eq span:nth-child(2) { height: 100%; animation-delay: 0.15s; }
.eq span:nth-child(3) { height: 65%; animation-delay: 0.3s; }
@keyframes eq { 0%, 100% { transform: scaleY(0.4); } 50% { transform: scaleY(1); } }
@media (prefers-reduced-motion: reduce) { .eq span { animation: none; } }

.link-btn {
  background: none; border: none; color: var(--gold);
  font-family: var(--font-body); font-size: 13px; font-weight: 600;
  cursor: pointer; padding: 0;
}
.link-btn:hover { text-decoration: underline; }
.danger-btn { color: var(--live); margin-left: 12px; }
.danger-btn:disabled { opacity: 0.5; cursor: default; text-decoration: none; }
.text-muted { color: var(--text-muted); }

/* ---------- Account detail (bảng quà tặng) ---------- */
.back-btn { margin-bottom: 16px; }

.search-row {
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.sort-btn { white-space: nowrap; }
.search-row input {
  flex: 1 1 220px; max-width: 340px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 9px;
  font-family: var(--font-body);
  font-size: 13.5px;
}
.search-row input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

.col-toggle { width: 70px; text-align: center; }
#giftsTable td.col-toggle { text-align: center; }
.gift-toggle { width: 18px; height: 18px; accent-color: var(--gold); cursor: pointer; }

.gift-audio-name { font-size: 13.5px; }
.file-btn { display: inline-block; cursor: pointer; margin-left: 12px; }

/* Icon quà + badge nguồn dữ liệu */
.col-icon { width: 44px; }
.gift-icon { width: 28px; height: 28px; object-fit: contain; display: block; }
.gift-icon-blank {
  width: 28px; height: 28px; display: block;
  border-radius: 6px; background: var(--surface-raised);
}
.badge-missing {
  background: rgba(245, 185, 66, 0.16); color: var(--gold);
  font-size: 11px; padding: 3px 7px; margin-left: 8px;
}
.badge-noimage {
  background: rgba(255, 68, 104, 0.14); color: var(--live);
  font-size: 11px; padding: 3px 7px; margin-left: 8px;
}
.badge-variants {
  background: rgba(120, 160, 255, 0.16); color: #7ba3ff;
  font-size: 11px; padding: 3px 7px; margin-left: 8px;
}
.link-btn:disabled { color: var(--text-muted); cursor: default; text-decoration: none; }
.badge-preload { background: rgba(141, 140, 160, 0.14); color: var(--text-muted); }
.badge-real { background: rgba(245, 185, 66, 0.16); color: var(--gold); }

.table-note { padding: 10px 20px 14px; margin: 0; font-size: 12.5px; color: var(--text-muted); }
.load-more-row { padding: 0 20px 18px; }
.load-more-row button { width: 100%; }

.global-catalog-box { margin-top: 28px; }
.global-catalog-box h3 { font-family: var(--font-display); font-size: 16px; margin: 0 0 4px; }
.global-catalog-box .panel-head { margin-bottom: 14px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(10, 10, 14, 0.6);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  z-index: 50;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; width: 100%; max-width: 420px;
}
.modal-card h3 { font-family: var(--font-display); margin: 0 0 4px; font-size: 18px; }
.modal-card input[type="file"] {
  width: 100%; margin: 16px 0; color: var(--text-muted); font-size: 13px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Ảnh đại diện tài khoản TikTok ---------- */
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: middle;
}
.avatar-lg { width: 52px; height: 52px; font-size: 22px; }
.avatar-fallback {
  color: #14141c; font-weight: 700; font-family: var(--font-display);
  font-size: 15px; line-height: 1;
}
.acc-cell { display: flex; align-items: center; gap: 10px; }

/* Cột "Tài khoản phần mềm" trong bảng Tài khoản TikTok */
.linked-user { margin-bottom: 8px; }
.linked-user:last-child { margin-bottom: 0; }
.linked-user .link-btn { font-size: 13.5px; }
.dup-warn {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 11px;
  white-space: nowrap;
}
.detail-head { display: flex; align-items: center; gap: 14px; }

/* ---------- Hộp thoại đổi mật khẩu ---------- */
.pw-choice {
  display: block; width: 100%; text-align: left;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-top: 12px;
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--text-primary);
}
.pw-choice:hover { border-color: var(--gold); }
.pw-choice strong { display: block; font-size: 14px; margin-bottom: 4px; }
.pw-choice span { display: block; font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }

#pwManual label { display: block; font-size: 13px; color: var(--text-muted); margin: 16px 0 6px; }
.pw-input-row { display: flex; gap: 8px; }
.pw-input-row input {
  flex: 1;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 11px 13px;
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 14px;
}
.pw-input-row input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
#pwManualSave, #pwResultDone {
  background: var(--gold); color: #14141c; border: none;
  padding: 9px 16px; border-radius: 9px; font-weight: 600;
  font-family: var(--font-body); font-size: 13px; cursor: pointer;
}
#pwManualSave:hover, #pwResultDone:hover { background: #ffcb66; }

.pw-warning {
  background: rgba(255, 68, 104, 0.12);
  border: 1px solid rgba(255, 68, 104, 0.35);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 16px 0 12px;
  font-size: 13px;
  line-height: 1.5;
}
.pw-result-row { display: flex; gap: 8px; align-items: center; }
.pw-value {
  flex: 1;
  background: var(--surface-raised);
  border: 1px dashed var(--gold);
  border-radius: 9px;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 20px;
  letter-spacing: 0.08em;
  color: var(--gold);
  text-align: center;
  user-select: all;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-raised); border: 1px solid var(--border);
  color: var(--text-primary); padding: 12px 20px; border-radius: 10px;
  font-size: 13.5px; z-index: 100;
  max-width: min(520px, calc(100vw - 32px));
  text-align: center;
  display: flex; align-items: center; gap: 12px; justify-content: center;
}
.toast.hidden { display: none !important; }
.toast-undo {
  background: var(--gold); color: #14141c; border: none;
  padding: 6px 14px; border-radius: 8px; font-weight: 600;
  font-family: var(--font-body); font-size: 13px; cursor: pointer;
  flex-shrink: 0;
}
.toast-undo:hover { background: #ffcb66; }
.toast-undo:disabled { opacity: 0.6; cursor: default; }
.toast-countdown {
  font-family: var(--font-mono); font-size: 12px; color: var(--text-muted);
  flex-shrink: 0; min-width: 26px;
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 12px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .content { padding: 24px 16px 48px; }
}

/* ---------- Customer-app visual system ---------- */
:root {
  --bg-void: #0b1020;
  --surface: #151d31;
  --surface-raised: #10182a;
  --border: #283452;
  --gold: #f5bc4b;
  --gold-dim: #b88935;
  --live: #ed3e68;
  --text-primary: #f5f7ff;
  --text-muted: #9cabc8;
  --success: #51d496;
}

body {
  background:
    radial-gradient(circle at 9% 0%, rgba(56, 81, 129, .72), transparent 34rem),
    radial-gradient(circle at 100% 18%, rgba(125, 49, 108, .25), transparent 31rem),
    var(--bg-void);
  color: var(--text-primary);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, rgba(255,255,255,.025), transparent 34%);
}

.brand-logo {
  overflow: hidden;
  padding: 2px;
  background: linear-gradient(145deg, var(--gold), #725324);
  box-shadow: 0 7px 20px rgba(0, 0, 0, .26);
}
.brand-logo img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}
.brand-title-row { display: flex; align-items: center; gap: 8px; }
.admin-chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border: 1px solid rgba(245, 188, 75, .4);
  border-radius: 999px;
  background: rgba(245, 188, 75, .12);
  color: var(--gold);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
}

.login-screen {
  background:
    radial-gradient(circle at 9% 0%, rgba(56, 81, 129, .75), transparent 34rem),
    radial-gradient(circle at 94% 82%, rgba(139, 61, 116, .32), transparent 30rem),
    var(--bg-void);
}
.login-card,
.modal-card {
  background: rgba(21, 29, 49, .96);
  border-color: var(--border);
  box-shadow: 0 22px 60px rgba(0, 0, 0, .34);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 76px;
  padding: 12px max(20px, calc((100vw - 1120px) / 2));
  gap: 28px;
  border-color: var(--border);
  background: rgba(11, 16, 32, .86);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .02);
  backdrop-filter: blur(16px);
}
.brand-small .brand-mark { width: 42px; height: 42px; border-radius: 13px; }
.brand-small h1 { font-size: 17px; }
.brand-small .brand-text p { display: block; font-size: 11.5px; }

.tabs {
  gap: 5px;
  padding: 4px;
  border: 1px solid rgba(40, 52, 82, .7);
  border-radius: 12px;
  background: rgba(10, 16, 31, .74);
}
.tab-btn {
  color: var(--text-muted);
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
}
.tab-btn:hover { color: var(--text-primary); background: rgba(38, 52, 84, .58); }
.tab-btn.active {
  color: var(--text-primary);
  border-color: rgba(125, 149, 203, .16);
  background: #263454;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.07), 0 4px 12px rgba(0,0,0,.16);
}
.tab-btn.active .tab-badge { box-shadow: none; }

.content {
  position: relative;
  max-width: 1120px;
  padding: 28px 20px 64px;
}
.tab-panel.active,
#accountsListView,
#accountDetailView {
  display: grid;
  gap: 16px;
}
#accountsListView.hidden,
#accountDetailView.hidden { display: none !important; }

.panel-head {
  align-items: center;
  margin: 0;
  padding: 19px 21px;
  border: 1px solid var(--border);
  border-radius: 17px;
  background: linear-gradient(135deg, rgba(29, 42, 70, .93), rgba(21, 29, 49, .98));
  box-shadow: 0 14px 30px rgba(0, 0, 0, .13);
}
.panel-head h2 { font-size: 20px; letter-spacing: -.02em; }
.subtitle { color: var(--text-muted); }

.table-wrap {
  border-color: var(--border);
  border-radius: 17px;
  background: rgba(21, 29, 49, .94);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .13);
}
th {
  padding: 13px 18px;
  color: #9cabc8;
  text-transform: none;
  letter-spacing: .01em;
  background: rgba(11, 18, 34, .58);
}
td { padding: 14px 18px; border-color: rgba(40, 52, 82, .78); }
tbody tr { transition: background .16s ease; }
tbody tr:hover { background: rgba(38, 52, 84, .33); }

input,
.inline-form input,
.search-row input,
.req-reason,
.pw-input-row input {
  border-color: var(--border);
  background: #0b1222;
}
input:focus,
.inline-form input:focus,
.search-row input:focus,
.req-reason:focus,
.pw-input-row input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(245, 188, 75, .12);
  outline: 0;
}

.btn-ghost,
.row-menu-btn {
  border-color: var(--border);
  background: rgba(11, 18, 34, .36);
}
.btn-ghost:hover,
.row-menu-btn:hover { border-color: #3b4d79; background: #1a2741; }
.btn-primary,
.inline-form button,
#audioModalUpload,
#pwManualSave,
#pwResultDone {
  border-color: var(--gold);
  background: var(--gold);
  color: #1b1508;
  box-shadow: 0 8px 18px rgba(245, 188, 75, .12);
}
.btn-danger { border-color: rgba(237, 62, 104, .56); color: #ff7a92; }

.badge-live { background: rgba(237, 62, 104, .14); color: #ff7088; }
.badge-ok, .text-ok { color: var(--success); }
.badge-ok { background: rgba(81, 212, 150, .14); }
.badge-warn, .badge-unused, .badge-real { color: var(--gold); }
.badge-expired, .text-danger { color: #ff7a92; }
.badge-muted, .badge-offline, .badge-used { background: rgba(72, 91, 134, .25); color: var(--text-muted); }

.request-box,
.warn-box,
.global-catalog-box {
  border-color: var(--border);
  border-radius: 17px;
  background: rgba(21, 29, 49, .94);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .12);
}
.request-box { border-color: rgba(237, 62, 104, .42); }
.warn-box { border-color: rgba(245, 188, 75, .44); background: rgba(44, 35, 15, .62); }
.global-catalog-box { padding: 16px; }
.global-catalog-box .panel-head { box-shadow: none; }

.row-menu {
  border-color: #34476f;
  background: #121c31;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .46);
}
.row-menu button:hover { background: #223150; }
.modal { background: rgba(5, 8, 18, .74); backdrop-filter: blur(7px); }
.toast { border-color: #3b4d79; background: #17233c; box-shadow: 0 14px 34px rgba(0,0,0,.34); }

@media (max-width: 720px) {
  .topbar { padding: 12px 16px; }
  .brand-small .brand-text p, .admin-chip { display: none; }
  .tabs { width: 100%; overflow-x: auto; }
  .tab-btn { white-space: nowrap; }
  .content { padding: 18px 14px 48px; }
  .panel-head { padding: 17px; }
  .table-wrap { overflow-x: auto; }
}

/* ---------- PWA quản trị trên iPhone ---------- */
.install-tip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 18px;
  padding: 12px 13px;
  border: 1px solid rgba(245, 188, 75, .24);
  border-radius: 12px;
  background: rgba(245, 188, 75, .07);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}
.install-tip-icon {
  display: grid;
  place-items: center;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: rgba(245, 188, 75, .16);
  color: var(--gold);
  font-size: 16px;
  font-weight: 800;
}
.install-tip strong,
.install-tip span { display: block; }
.install-tip strong { margin-bottom: 2px; color: var(--text-primary); }

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  color: var(--success);
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}
.connection-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px rgba(81, 212, 150, .1);
}
.connection-status.offline { color: #ff7a92; }
.connection-status.offline::before { box-shadow: 0 0 0 4px rgba(237, 62, 104, .12); }

@supports (padding: max(0px)) {
  body {
    min-height: 100dvh;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .login-screen { min-height: 100dvh; }
}

@media (display-mode: standalone) {
  .install-tip { display: none; }
}

@media (max-width: 720px) {
  html {
    min-height: 100%;
    background: var(--bg-void);
    -webkit-text-size-adjust: 100%;
  }
  body {
    min-width: 0;
    min-height: 100dvh;
    overscroll-behavior-y: none;
  }

  button,
  input,
  select,
  textarea,
  .btn-ghost,
  .btn-primary,
  .btn-danger,
  .link-btn,
  .row-menu button {
    min-height: 44px;
    touch-action: manipulation;
  }
  input,
  select,
  textarea,
  #loginForm input,
  .inline-form input,
  .search-row input,
  .pw-input-row input {
    font-size: 16px;
  }

  .login-screen {
    align-items: center;
    padding:
      max(18px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(18px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }
  .login-card {
    max-width: 420px;
    padding: 24px 20px;
    border-radius: 20px;
  }
  .login-card .brand { margin-bottom: 22px; }
  .login-card .brand-mark { width: 52px; height: 52px; border-radius: 16px; }
  #loginForm button { min-height: 48px; font-size: 15px; }

  .topbar {
    top: 0;
    min-height: 68px;
    flex-wrap: nowrap;
    gap: 10px;
    padding:
      max(10px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      10px
      max(12px, env(safe-area-inset-left));
    /* backdrop-filter tạo containing block khiến nav position:fixed bị ghim
       vào chính topbar trên Safari/iOS. Dùng nền đặc để nav bám đáy màn hình. */
    background: rgba(11, 16, 32, .98);
    backdrop-filter: none;
  }
  .topbar .brand { min-width: 0; flex: 1 1 auto; gap: 9px; }
  .brand-small .brand-mark { width: 40px; height: 40px; border-radius: 12px; }
  .brand-small .brand-text { min-width: 0; }
  .brand-small h1 {
    overflow: hidden;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .brand-small .brand-text p,
  .admin-chip,
  .connection-status { display: none; }
  #logoutBtn {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 8px 11px;
    font-size: 12px;
  }

  .tabs {
    position: fixed;
    z-index: 45;
    right: 0;
    bottom: 0;
    left: 0;
    order: initial;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: auto;
    margin: 0;
    padding:
      7px
      max(8px, env(safe-area-inset-right))
      max(7px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
    overflow: visible;
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: 0;
    background: rgba(11, 16, 32, .96);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .26);
    backdrop-filter: blur(18px);
  }
  .tab-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 48px;
    padding: 7px 5px;
    border-radius: 10px;
    font-size: 11.5px;
    line-height: 1.2;
    text-align: center;
    white-space: normal;
  }
  .tab-badge {
    min-width: 18px;
    margin-left: 4px;
    padding: 0 5px;
    font-size: 10px;
    line-height: 18px;
  }

  .content {
    width: 100%;
    padding:
      14px
      max(12px, env(safe-area-inset-right))
      calc(88px + env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }
  .tab-panel.active,
  #accountsListView,
  #accountDetailView { gap: 12px; }
  .panel-head {
    display: flex;
    align-items: stretch;
    flex-direction: column;
    gap: 13px;
    padding: 16px;
    border-radius: 15px;
  }
  .panel-head h2 { font-size: 18px; }
  .panel-head > button,
  .panel-head .btn-ghost { width: 100%; }
  .subtitle { font-size: 12.5px; line-height: 1.5; }
  .detail-head { align-items: center; }
  .back-btn { width: 100%; margin-bottom: 0; }

  .inline-form,
  .search-row,
  .pw-input-row {
    display: flex;
    align-items: stretch;
    width: 100%;
  }
  .inline-form input { width: 78px; flex: 0 0 78px; }
  .inline-form button { flex: 1 1 auto; }
  .search-row { flex-direction: column; margin-bottom: 0; }
  .search-row input {
    width: 100%;
    max-width: none;
    flex: none;
  }
  .search-row .sort-btn { width: 100%; }
  .global-catalog-box {
    margin-top: 10px;
    padding: 12px;
    border-radius: 15px;
  }
  .global-catalog-box .panel-head { padding: 14px; }

  /* Mỗi hàng trở thành một thẻ có nhãn, tránh cuộn ngang và cuộn lồng nhau. */
  .table-wrap,
  .table-wrap:has(#usersTable) {
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }
  .table-scroll {
    max-height: none;
    overflow: visible;
    overscroll-behavior: auto;
  }
  table,
  tbody,
  tr,
  td { display: block; width: 100%; }
  thead { display: none; }
  tbody {
    display: grid;
    gap: 10px;
  }
  tbody tr {
    position: relative;
    display: block;
    overflow: visible;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: rgba(21, 29, 49, .96);
    box-shadow: 0 10px 24px rgba(0, 0, 0, .12);
  }
  tbody tr:hover { background: rgba(21, 29, 49, .96); }
  td,
  #usersTable td,
  #usersTable th {
    display: grid !important;
    grid-template-columns: minmax(92px, 34%) minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    min-width: 0;
    padding: 8px 3px;
    border: 0;
    font-size: 13px;
    text-align: left;
    overflow-wrap: anywhere;
  }
  td + td { border-top: 1px solid rgba(40, 52, 82, .48); }
  td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 700;
    line-height: 1.45;
    text-transform: uppercase;
    letter-spacing: .04em;
  }
  td[data-label=""] {
    display: flex !important;
    align-items: center;
    padding-top: 5px;
    padding-bottom: 5px;
  }
  td[data-label=""]::before { display: none; }
  td.acc-cell {
    display: grid !important;
    grid-template-columns: minmax(92px, 34%) minmax(0, 1fr);
  }
  td.acc-cell::after { content: none; }
  td.acc-cell .avatar { margin-right: 8px; }
  td.acc-cell > .avatar,
  td.acc-cell > .avatar-fallback { grid-column: 2; grid-row: 1; }
  td.acc-cell > .mono {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    margin-left: 42px;
  }
  td.col-icon {
    position: absolute;
    top: 11px;
    right: 12px;
    display: flex !important;
    width: 38px;
    padding: 0;
    border: 0;
  }
  td.col-icon + td { padding-right: 48px; }
  .gift-icon,
  .gift-icon-blank { width: 34px; height: 34px; }
  .col-toggle { text-align: left; }
  .gift-toggle { width: 24px; height: 24px; }
  .file-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 8px 0 0;
  }
  .row-actions {
    display: flex !important;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .row-actions::before { flex: 0 0 100%; }
  .row-actions .link-btn { flex: 1 1 110px; }
  .cell-user { min-width: 0; }
  .cell-sub { white-space: normal; }
  .col-menu,
  #usersTable td.col-menu {
    position: static;
    display: block !important;
    width: 100%;
    padding-top: 8px;
    text-align: left;
  }
  .col-menu::before { display: none; }
  .row-menu-btn {
    width: 100%;
    height: 44px;
  }
  .row-menu {
    position: static;
    width: 100%;
    min-width: 0;
    margin-top: 8px;
    padding: 7px;
    box-shadow: none;
  }
  .row-menu button {
    min-height: 44px;
    white-space: normal;
  }
  .table-note,
  .load-more-row { padding-right: 4px; padding-left: 4px; }
  .empty-state {
    padding: 24px 14px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: rgba(21, 29, 49, .96);
  }

  .request-box,
  .warn-box { padding: 15px; border-radius: 15px; }
  .request-row { align-items: stretch; flex-direction: column; }

  .modal {
    align-items: flex-end;
    padding:
      max(12px, env(safe-area-inset-top))
      0
      0;
  }
  .modal-card {
    max-width: none;
    max-height: calc(100dvh - max(12px, env(safe-area-inset-top)));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 22px 22px 0 0;
  }
  .modal-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }
  .modal-actions button { width: 100%; }
  .pw-result-row { align-items: stretch; flex-direction: column; }
  .pw-value { width: 100%; font-size: 17px; }

  .toast {
    right: 12px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    left: 12px;
    max-width: none;
    transform: none;
    flex-wrap: wrap;
  }
}
