/* ══════════════════════════════════════════════════════════════════════
   PAAN · Hệ thống thiết kế dùng chung cho trang giới thiệu và trang quản trị
   Sáng / tối đầy đủ, biến màu khai báo một lần ở :root và đảo ở [data-theme]
   ══════════════════════════════════════════════════════════════════════ */

:root {
  /* Thương hiệu */
  --brand: #6c5ce7;
  --brand-2: #7b6ef0;
  --brand-3: #a78bfa;
  --cyan: #22b8cf;
  --teal: #12b886;
  --amber: #f59f00;
  --rose: #fa5252;

  /* Nền & bề mặt — chế độ SÁNG */
  --bg: #f6f7fb;
  --bg-soft: #eef0f8;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #f0f2f8;
  --overlay: rgba(16, 18, 32, 0.42);

  /* Chữ */
  --text: #14162b;
  --text-2: #4a4f6a;
  --text-3: #767c96;
  --text-inv: #ffffff;

  /* Viền */
  --line: #e3e6f0;
  --line-2: #d3d7e6;

  /* Trạng thái */
  --ok: #0ca678;
  --ok-bg: #e6f8f2;
  --warn: #e8890c;
  --warn-bg: #fdf3e3;
  --danger: #e03131;
  --danger-bg: #fdeded;
  --info: #1c7ed6;
  --info-bg: #e7f2fd;

  /* Đổ bóng */
  --sh-1: 0 1px 2px rgba(20, 22, 43, .06), 0 1px 3px rgba(20, 22, 43, .04);
  --sh-2: 0 4px 12px rgba(20, 22, 43, .07), 0 1px 3px rgba(20, 22, 43, .05);
  --sh-3: 0 12px 32px rgba(20, 22, 43, .12), 0 2px 8px rgba(20, 22, 43, .06);
  --sh-brand: 0 8px 24px rgba(108, 92, 231, .28);

  /* Hình học */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --r-xl: 26px;
  --r-full: 999px;

  --header-h: 66px;
  --sidebar-w: 258px;
  --maxw: 1200px;

  --ease: cubic-bezier(.4, 0, .2, 1);
  --dur: .22s;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b0d1a;
  --bg-soft: #0f1222;
  --surface: #151829;
  --surface-2: #1b1f33;
  --surface-3: #232840;
  --overlay: rgba(4, 5, 12, .66);

  --text: #eef0f8;
  --text-2: #a9b0cc;
  --text-3: #767e9e;
  --text-inv: #0b0d1a;

  --line: #262b44;
  --line-2: #333a58;

  --brand: #8b7cf6;
  --brand-2: #a78bfa;
  --brand-3: #c4b5fd;

  --ok: #38d9a9;
  --ok-bg: rgba(56, 217, 169, .13);
  --warn: #ffc078;
  --warn-bg: rgba(255, 192, 120, .13);
  --danger: #ff8787;
  --danger-bg: rgba(255, 135, 135, .13);
  --info: #74c0fc;
  --info-bg: rgba(116, 192, 252, .13);

  --sh-1: 0 1px 2px rgba(0, 0, 0, .4);
  --sh-2: 0 4px 14px rgba(0, 0, 0, .45);
  --sh-3: 0 16px 40px rgba(0, 0, 0, .55);
  --sh-brand: 0 8px 26px rgba(139, 124, 246, .32);

  color-scheme: dark;
}

/* ── Nền tảng ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* clip (không phải hidden) để các lớp trượt ngoài màn hình — ngăn kéo menu,
     quầng sáng nền — không kéo rộng tài liệu ra và làm lệch hộp thoại trên điện thoại */
  overflow-x: hidden;
  overflow-x: clip;
}
/* Máy có bật "Giảm chuyển động" trong hệ điều hành.
   KHÔNG ép animation-duration: .01ms cho mọi thứ như cách làm cũ — với hiệu ứng lặp
   vô hạn thì nó không dừng mà quay vòng cực nhanh, còn khó chịu hơn. Ở đây chỉ tắt
   cuộn mượt và các hiệu ứng chạy một lần. Hiệu ứng trang trí lặp vô hạn (nền nơ-ron,
   quầng sáng, dải công nghệ) do nút "hiệu ứng chuyển động" ở chân trang quyết định. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; }
  .reveal { transition: none !important; opacity: 1 !important; transform: none !important; }
  .project, .modal, .modal-back, .toast { animation: none !important; }
}

/* Tắt hiệu ứng chuyển động theo lựa chọn của người xem */
[data-motion="off"] .reveal { transition: none !important; opacity: 1 !important; transform: none !important; }
[data-motion="off"] .project { animation: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  overflow-x: clip;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

h1, h2, h3, h4, h5 {
  margin: 0;
  line-height: 1.22;
  font-weight: 700;
  letter-spacing: -.021em;
  color: var(--text);
}
h1 { font-size: clamp(2.1rem, 5.2vw, 3.6rem); letter-spacing: -.035em; }
h2 { font-size: clamp(1.65rem, 3.6vw, 2.5rem); letter-spacing: -.028em; }
h3 { font-size: clamp(1.15rem, 2vw, 1.4rem); }
p { margin: 0; }

a { color: var(--brand); text-decoration: none; transition: color var(--dur) var(--ease); }
a:hover { color: var(--brand-2); }

img, svg { max-width: 100%; display: block; }

button, input, textarea, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: color-mix(in srgb, var(--brand) 28%, transparent); }

/* Thanh cuộn */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: var(--r-full);
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ── Bố cục ───────────────────────────────────────────────────────── */
.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: 22px; }
@media (max-width: 640px) { .wrap { padding-inline: 18px; } }

.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.wrapped { flex-wrap: wrap; }
.hide { display: none !important; }

/* ── Logo (dùng chung cho trang giới thiệu và trang quản trị) ─────── */
.logo { display: flex; align-items: center; gap: 10px; flex: none; }
.logo-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-3) 50%, var(--cyan) 100%);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 1.02rem;
  letter-spacing: -.04em;
  box-shadow: var(--sh-brand);
  flex: none;
}
.logo-text {
  font-size: 1.24rem;
  font-weight: 800;
  letter-spacing: -.045em;
  color: var(--text);
}
.logo-text span { color: var(--brand); }

/* ── Lưới biểu mẫu hai cột, tự gộp một cột trên điện thoại ────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* ── Ô thông tin phụ trong hộp thoại chi tiết ─────────────────────── */
.pd-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.pd-meta > div {
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.pd-meta span { display: block; font-size: .74rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.pd-meta b { font-size: .95rem; }

/* ── Nút ──────────────────────────────────────────────────────────── */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-line: var(--line-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--r-full);
  border: 1px solid var(--btn-line);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: .94rem;
  font-weight: 600;
  letter-spacing: -.005em;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              background var(--dur) var(--ease), border-color var(--dur) var(--ease), opacity var(--dur);
}
.btn svg { width: 17px; height: 17px; flex: none; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--sh-2); color: var(--btn-fg); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary {
  --btn-bg: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 55%, var(--brand-3) 100%);
  --btn-fg: #fff;
  --btn-line: transparent;
  box-shadow: var(--sh-brand);
}
.btn-primary:hover { box-shadow: 0 12px 30px rgba(108, 92, 231, .38); }

.btn-ghost { --btn-bg: transparent; --btn-line: var(--line-2); }
.btn-ghost:hover { --btn-bg: var(--surface-3); }

.btn-soft { --btn-bg: var(--surface-3); --btn-line: transparent; }

.btn-danger { --btn-bg: var(--danger-bg); --btn-fg: var(--danger); --btn-line: transparent; }

.btn-sm { padding: 7px 14px; font-size: .85rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-icon { padding: 9px; width: 38px; height: 38px; border-radius: var(--r); }
.btn-block { width: 100%; }

/* ── Thẻ ──────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease),
              border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.card-pad { padding: 22px; }

/* ── Nhãn ─────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.chip-ok { background: var(--ok-bg); color: var(--ok); }
.chip-warn { background: var(--warn-bg); color: var(--warn); }
.chip-danger { background: var(--danger-bg); color: var(--danger); }
.chip-info { background: var(--info-bg); color: var(--info); }
.chip-brand { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.chip-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

/* ── Biểu mẫu ─────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 7px; }
.field > label { font-size: .84rem; font-weight: 600; color: var(--text-2); }

.input, .select, .textarea {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--r);
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: .95rem;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.textarea { resize: vertical; min-height: 108px; line-height: 1.6; }
.select {
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23767c96' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
}
[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a9b0cc' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* ── Nút đổi giao diện sáng / tối ─────────────────────────────────── */
.theme-btn {
  position: relative;
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--r);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  flex: none;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.theme-btn:hover { color: var(--brand); transform: rotate(-14deg); }
.theme-btn svg { width: 19px; height: 19px; }
.theme-btn .i-moon { display: none; }
[data-theme="dark"] .theme-btn .i-moon { display: block; }
[data-theme="dark"] .theme-btn .i-sun { display: none; }

/* ── Thanh tiến độ ────────────────────────────────────────────────── */
.bar {
  height: 7px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--brand), var(--brand-3));
  transition: width .6s var(--ease);
}

/* ── Vụn tiện ích ─────────────────────────────────────────────────── */
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.small { font-size: .86rem; }
.tiny { font-size: .78rem; }
.bold { font-weight: 700; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.mono { font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace; font-size: .9em; }

.gradient-text {
  background: linear-gradient(120deg, var(--brand) 0%, var(--brand-3) 42%, var(--cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.spinner {
  width: 18px; height: 18px;
  border: 2.4px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Thông báo nổi ────────────────────────────────────────────────── */
#toasts {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 9px;
  align-items: center;
  pointer-events: none;
  width: min(440px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: var(--sh-3);
  font-size: .9rem;
  font-weight: 600;
  animation: toast-in .3s var(--ease);
  max-width: 100%;
}
.toast.ok { border-color: color-mix(in srgb, var(--ok) 45%, transparent); color: var(--ok); }
.toast.err { border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to { opacity: 1; transform: none; }
}

/* ── Hộp thoại ────────────────────────────────────────────────────── */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--overlay);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade .2s var(--ease);
  overflow-y: auto;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(620px, 100%);
  max-height: calc(100dvh - 40px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop .26s var(--ease);
}
@keyframes pop {
  from { opacity: 0; transform: translateY(18px) scale(.97); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.modal-head h3 { font-size: 1.1rem; }
.modal-body { padding: 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  flex: none;
}
.x-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--r);
  border: none;
  background: var(--surface-3);
  color: var(--text-2);
  cursor: pointer;
  flex: none;
  transition: background var(--dur), color var(--dur);
}
.x-btn:hover { background: var(--danger-bg); color: var(--danger); }

@media (max-width: 560px) {
  .modal-back { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%;
    max-height: 92dvh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    border-bottom: none;
    animation: sheet-up .3s var(--ease);
  }
  .modal-foot { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  @keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
}

/* ── Trạng thái rỗng ──────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 20px;
  text-align: center;
  color: var(--text-3);
}
.empty svg { width: 42px; height: 42px; opacity: .5; }
.empty b { color: var(--text-2); font-size: .98rem; }
