/* ==========================================================================
   SHARED COMPONENTS — Dùng chung cho tất cả trang
   Load SAU tokens.css, TRƯỚC CSS trang cụ thể
   ========================================================================== */

/* ── Base Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-body);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  height: var(--btn-h);
  padding: 0 var(--sp-4);
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 600;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  white-space: nowrap;
  transition: filter var(--transition), transform var(--transition);
  text-decoration: none;
}
.btn:hover  { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { transform: translateY(0); filter: brightness(.96); }
.btn:disabled, .btn[disabled] {
  opacity: .5; cursor: default; transform: none; filter: none;
}

/* Variants — single dash (chuẩn) */
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-teal    { background: var(--teal);    color: #fff; }
.btn-info    { background: var(--info);    color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-ghost {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--bg-sub); filter: none; }

/* Variants — double dash (legacy HV.html, backward compat) */
.btn--primary { background: var(--primary); color: #fff; }
.btn--danger  { background: var(--danger);  color: #fff; }
.btn--success { background: var(--success); color: #fff; }
.btn--teal    { background: var(--teal);    color: #fff; }
.btn--info    { background: var(--info);    color: #fff; }
.btn--ghost {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn--ghost:hover { background: var(--bg-sub); filter: none; }

/* Size modifiers */
.btn-sm, .btn--sm { height: 30px; padding: 0 var(--sp-3); font-size: 12px; }
.btn-lg, .btn--lg { height: 44px; padding: 0 var(--sp-5); font-size: 14px; }

/* ── Grid Utilities ─────────────────────────────────────────────────────── */
/* Cả hai tên đều hoạt động: .grid-2 (chuẩn mới) và .grid2 (legacy) */
.grid-2, .grid2 { display: grid; grid-template-columns: 1fr 1fr;          gap: var(--sp-5); }
.grid-3, .grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr;      gap: var(--sp-5); }
.grid-4, .grid4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr;  gap: var(--sp-5); }

/* ── Card ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card-header {
  padding: var(--sp-4) var(--sp-5);
  background: var(--bg-sub);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: var(--sp-5); }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #e0f2fe; color: #075985; }
.badge-muted   { background: var(--bg-sub); color: var(--muted); }

/* ── Form Field ─────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-bottom: var(--sp-4);
}
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-600);
}

input:not([type=checkbox]):not([type=radio]),
select,
textarea {
  height: var(--input-h);
  padding: 0 var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg-card);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
textarea { height: auto; padding: var(--sp-2) var(--sp-3); resize: vertical; }
input:not([type=checkbox]):not([type=radio]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--bg-sub);
  color: var(--muted);
  cursor: default;
}
input:not([disabled]):not(:focus):invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(220,38,38,.15);
}

/* ── Toast Notifications ─────────────────────────────────────────────────
   Dùng với public/js/helpers/toast.js
   showToast('Lưu thành công', 'success')
   showToast('Có lỗi xảy ra', 'error')
   ────────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #1f2937;
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  min-width: 260px;
  max-width: 360px;
  border-left: 4px solid var(--success);
  animation: toast-in .22s ease;
}
.toast.toast-error   { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-info    { border-left-color: var(--info); }
.toast.toast-out     { animation: toast-out .2s ease forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { from { opacity: 1; transform: translateX(0); }    to { opacity: 0; transform: translateX(20px); } }

/* ── Accessibility: Focus Ring ──────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Rank Badge Colors (data-rank set by scoring.js) ────────────────────── */
[data-rank="A"] { color: #10b981; font-weight: 800; }   /* Xuất sắc */
[data-rank="B"] { color: #38bdf8; font-weight: 800; }   /* Giỏi */
[data-rank="C"] { color: #fbbf24; font-weight: 800; }   /* Khá */
[data-rank="D"] { color: #f87171; font-weight: 800; }   /* Đạt */

/* Tooltip xếp loại — hover vào badge [data-rank] hiện tiêu chuẩn điểm */
[data-rank] { position: relative; cursor: default; }
[data-rank]:hover::after {
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f8fafc;
  font-size: 11px;
  font-weight: 400;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 999;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
[data-rank="A"]:hover::after { content: "Xuất sắc — ≥ 90 điểm"; }
[data-rank="B"]:hover::after { content: "Giỏi — 80 – 89.99 điểm"; }
[data-rank="C"]:hover::after { content: "Khá — 70 – 79.99 điểm"; }
[data-rank="D"]:hover::after { content: "Đạt — < 70 điểm"; }

/* ── Skeleton Loading ───────────────────────────────────────────────────── */
.skeleton {
  display: inline-block;
  background: linear-gradient(90deg, #e8e8e8 25%, #d0d0d0 50%, #e8e8e8 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.4s ease infinite;
  border-radius: 4px;
  color: transparent;
  user-select: none;
}
@keyframes skeleton-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-row td {
  padding: 12px 16px;
}
.skeleton-row td > .skeleton {
  height: 14px;
  width: 80%;
  display: block;
}
.skeleton-row td:first-child > .skeleton { width: 50px; }
.skeleton-row td:last-child > .skeleton  { width: 160px; }

/* ── Empty State ────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: .6;
}
.empty-state p {
  margin: 0;
  font-size: 14px;
}
.empty-state .empty-sub {
  font-size: 12px;
  margin-top: 4px;
  opacity: .7;
}
.empty-state .empty-clear-filter {
  margin-top: 14px;
}

/* ── Confirm Dialog (thay native confirm()) ─────────────────────────────── */
.cd-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: cd-fade-in .15s ease;
}
@keyframes cd-fade-in { from { opacity: 0; } to { opacity: 1; } }

.cd-modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(420px, calc(100vw - 32px));
  animation: cd-slide-in .18s ease;
}
@keyframes cd-slide-in { from { opacity: 0; transform: scale(.95) translateY(-8px); } to { opacity: 1; transform: none; } }

.cd-header {
  padding: 16px 20px 0;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.cd-body {
  padding: 12px 20px 20px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
}
.cd-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* ── Mobile Touch Targets ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .btn-sm, .btn--sm { min-height: 44px; }
  .small            { min-height: 44px; font-size: 13px; }
}
