:root {
  --bg: #f4f7f9; 
  --panel: #ffffff; 
  --line: #e2e8f0; 
  --fg: #0f172a;
  --muted: #64748b; 
  --accent: #0d9488; 
  --accent-hover: #0f766e;
  --accent-bg: #f0fdfa;
  --accent-fg: #ffffff;
  --ok: #059669; --ok-bg: #d1fae5;
  --warn: #d97706; --warn-bg: #fef3c7;
  --bad: #dc2626; --bad-bg: #fee2e2;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body { 
  margin: 0; 
  background: var(--bg); 
  color: var(--fg);
  font: 14px/1.6 "Plus Jakarta Sans", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; /* Ngăn chặn scroll ngang toàn trang (vấn đề mất 1 phần bên phải) */
}

h1, h2 { font-weight: 700; color: #1e293b; letter-spacing: -0.02em; }
h1 { font-size: 24px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }

button { 
  font: inherit; 
  padding: 8px 16px; 
  border-radius: var(--radius-sm); 
  border: 1px solid var(--line);
  background: var(--panel); 
  color: var(--fg); 
  cursor: pointer; 
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); 
  font-weight: 600; 
  display: inline-flex; 
  align-items: center; 
  justify-content: center; 
  gap: 8px;
  box-shadow: var(--shadow-sm);
}
button:hover { background: #f8fafc; border-color: #cbd5e1; transform: translateY(-1px); }
button:active { transform: translateY(0); }

button.primary { 
  background: var(--accent); 
  border-color: var(--accent); 
  color: var(--accent-fg); 
  box-shadow: 0 4px 12px -4px rgba(13, 148, 136, 0.4); 
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

button.ghost { 
  background: transparent; 
  border-color: transparent; 
  box-shadow: none; 
  color: var(--muted); 
}
button.ghost:hover { background: #f1f5f9; color: var(--fg); }

button.danger { 
  background: var(--bad-bg); 
  border-color: transparent; 
  color: var(--bad); 
  box-shadow: none;
}
button.danger:hover { background: #fca5a5; color: #991b1b; }

input, select { 
  font: inherit; 
  padding: 10px 14px; 
  border-radius: var(--radius-sm);
  border: 1px solid var(--line); 
  background: var(--panel); 
  color: var(--fg); 
  transition: all 0.2s; 
  box-shadow: var(--shadow-sm);
}
input:focus, select:focus { 
  outline: none; 
  border-color: var(--accent); 
  box-shadow: 0 0 0 3px var(--accent-bg); 
}
input::placeholder { color: #94a3b8; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #f4f7f9 0%, #e0e7ff 100%); }
.login .card { 
  background: var(--panel); 
  border: 1px solid #ffffff; 
  border-radius: var(--radius-lg);
  padding: 40px; 
  width: 100%;
  max-width: 400px; 
  display: flex; 
  flex-direction: column; 
  gap: 16px; 
  box-shadow: var(--shadow-lg); 
}
.login h1 { font-size: 24px; margin-bottom: 4px; text-align: center; }
.login p.muted { text-align: center; margin-bottom: 8px; }
.login-or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 8px 0; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
.login-or::before, .login-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Topbar */
.topbar { 
  background: rgba(255, 255, 255, 0.85); 
  backdrop-filter: blur(12px); 
  border-bottom: 1px solid var(--line); 
  position: sticky; 
  top: 0; 
  z-index: 40; 
  box-shadow: 0 1px 3px 0 rgba(0,0,0,0.02);
}
.topbar-container {
  display: flex; 
  align-items: center; 
  flex-wrap: wrap; 
  gap: 16px; 
  padding: 12px 24px;
  max-width: 1200px;
  margin: 0 auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 18px;
  color: #0f172a;
  letter-spacing: -0.01em;
  margin-right: 16px;
}
.brand .badge {
  font-size: 10px;
  background: var(--accent-bg);
  color: var(--accent);
  padding: 4px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  vertical-align: middle;
}
.logo-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { 
  border: 0; 
  background: transparent; 
  color: var(--muted); 
  padding: 8px 16px; 
  font-weight: 600; 
  border-radius: var(--radius-full);
  box-shadow: none;
}
.tab:hover { background: #f1f5f9; transform: none; }
.tab.active { background: var(--fg); color: var(--panel); }

#who { font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }

/* Main */
main { padding: 32px 24px; max-width: 1200px; margin: 0 auto; }
.tabpane { display: block; animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.row { display: flex; gap: 12px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }

/* Toolbar & Filters */
.toolbar { 
  background: var(--panel); 
  border: 1px solid var(--line); 
  border-radius: var(--radius-md); 
  padding: 16px; 
  margin-bottom: 24px; 
  display: flex; 
  flex-direction: column; 
  gap: 16px; 
  box-shadow: var(--shadow-sm); 
}
.toolbar .row { margin-bottom: 0; }
.filters { flex: 1; display: flex; gap: 12px; flex-wrap: wrap; }
.filters select { flex: 1; min-width: 140px; font-size: 13px; }
.filters #search { flex: 2; min-width: 240px; }
.actions { justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 16px; }

@media (min-width: 860px) {
  .toolbar { flex-direction: row; align-items: center; justify-content: space-between; gap: 24px; padding: 12px 16px; }
  .actions { border-top: none; padding-top: 0; }
  .filters { flex-wrap: nowrap; }
}

/* Grid/Table */
.table-container {
  width: 100%;
  overflow-x: auto;
  background: var(--panel);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}
.grid { width: 100%; min-width: 800px; border-collapse: separate; border-spacing: 0; }
.grid th, .grid td { text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.grid th { 
  color: var(--muted); 
  font-weight: 700; 
  font-size: 12px; 
  text-transform: uppercase; 
  letter-spacing: 0.5px; 
  background: #f8fafc;
  position: sticky;
  top: 0;
}
.grid tr:last-child td { border-bottom: none; }
.grid tr { transition: background-color 0.2s; }
.grid tr:hover td { background: #f8fafc; }
.mono { font-family: "Fira Code", ui-monospace, Consolas, monospace; font-size: 13px; letter-spacing: -0.3px; color: #334155; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--fg); background: #f1f5f9; }
th.sortable span { display: inline-block; width: 12px; margin-left: 4px; color: var(--accent); }

.pill { 
  display: inline-flex; 
  align-items: center; 
  padding: 4px 12px; 
  border-radius: var(--radius-full); 
  font-size: 12px; 
  font-weight: 700; 
  letter-spacing: 0.5px; 
}
.pill.active { background: var(--ok-bg); color: var(--ok); }
.pill.revoked { background: var(--bad-bg); color: var(--bad); }
.pill.suspended { background: var(--warn-bg); color: var(--warn); }
.pill.deactivated { background: #f1f5f9; color: var(--muted); }
.pill.expired { background: #fee2e2; color: #b91c1c; }

/* Drawer & Cards */
.drawer { 
  position: fixed; 
  inset: 0; 
  background: rgba(15, 23, 42, 0.4); 
  display: flex; 
  align-items: stretch; 
  justify-content: flex-end; 
  z-index: 100; 
  backdrop-filter: blur(4px); 
}
.drawer-card { 
  width: 500px; 
  max-width: 100%; 
  height: 100%; 
  overflow-y: auto; 
  overflow-x: hidden;
  background: var(--panel); 
  border-left: 1px solid var(--line); 
  padding: 40px; 
  box-shadow: -10px 0 30px rgba(0,0,0,0.1); 
  animation: slideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1); 
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.card { 
  background: var(--panel); 
  border: 1px solid var(--line); 
  border-radius: var(--radius-lg); 
  padding: 40px; 
  box-shadow: var(--shadow-lg); 
}
.drawer-card h2 { margin: 0 0 16px; font-size: 22px; }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; min-width: 0; }
.field label { font-size: 13px; color: var(--fg); font-weight: 600; }
.field input, .field select { width: 100%; min-width: 0; background: #f8fafc; }
.field input:focus, .field select:focus { background: #ffffff; }
.field-row { display: flex; gap: 16px; }
.field-row .field { flex: 1; }
.keybox { 
  background: #f8fafc; 
  border: 1px dashed #cbd5e1; 
  border-radius: var(--radius-sm); 
  padding: 16px;
  word-break: break-all; 
  font-family: "Fira Code", ui-monospace, Consolas, monospace; 
  font-size: 14px; 
  color: var(--accent); 
  font-weight: 600;
  text-align: center;
}
.drawer-actions { display: flex; gap: 12px; margin-top: 32px; flex-wrap: wrap; }
.sect { border-top: 1px solid var(--line); margin-top: 32px; padding-top: 24px; }

/* Toast */
.toast { 
  position: fixed; 
  bottom: 32px; 
  left: 50%; 
  transform: translateX(-50%);
  background: var(--panel); 
  border: 1px solid var(--line); 
  padding: 14px 24px; 
  border-radius: var(--radius-full); 
  z-index: 200; 
  box-shadow: var(--shadow-lg); 
  display: flex; 
  align-items: center; 
  gap: 12px; 
  font-weight: 600; 
  font-size: 14px;
  animation: toastIn 0.4s cubic-bezier(0.16, 1, 0.3, 1); 
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px) scale(0.95); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
.toast.bad { border-color: var(--bad); color: var(--bad); background: var(--bad-bg); }
.toast.good { border-color: var(--ok); color: var(--ok); background: var(--ok-bg); }
