/* Admin Dashboard – base & glassmorphism (Phase 3) + CSS upgrade (Sếp chọn 9 gói) */
/* Font Outfit loaded via <link> in index.html + login.html */

:root {
  --glass-bg: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.18);
  --glass-blur: 18px;
  --sidebar-width: 240px;
  --header-height: 56px;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.35);
  --transition: 0.22s ease;
  /* Spacing scale (bổ sung) */
  --space-4: 4px;
  --space-8: 8px;
  --space-12: 12px;
  --space-16: 16px;
  --space-24: 24px;
  --space-32: 32px;
}

/* Neumorphism theme: biến khi data-theme="neumorphism" */
[data-theme="neumorphism"] {
  --neu-bg: #2a2a2e;
  --neu-bg-light: #36363c;
  --neu-shadow-outset: 8px 8px 16px rgba(0, 0, 0, 0.35), -4px -4px 12px rgba(255, 255, 255, 0.04);
  --neu-shadow-inset: inset 4px 4px 8px rgba(0, 0, 0, 0.3), inset -2px -2px 6px rgba(255, 255, 255, 0.03);
  --neu-radius: 18px;
  --neu-border: 1px solid rgba(255, 255, 255, 0.06);
  --text: #e4e4e7;
  --text-muted: #a1a1aa;
}

[data-theme="neumorphism"][data-color-scheme="light"] {
  --neu-bg: #e0e0e0;
  --neu-bg-light: #ebebeb;
  --neu-shadow-outset: 8px 8px 16px rgba(0, 0, 0, 0.12), -4px -4px 12px rgba(255, 255, 255, 0.9);
  --neu-shadow-inset: inset 4px 4px 8px rgba(0, 0, 0, 0.1), inset -2px -2px 6px rgba(255, 255, 255, 0.7);
  --neu-border: 1px solid rgba(0, 0, 0, 0.06);
  --text: #1f2937;
  --text-muted: #6b7280;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Outfit', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  min-height: 100vh;
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}

/* Neumorphism: nền đồng màu, không gradient */
[data-theme="neumorphism"] body {
  background: var(--neu-bg);
  color: var(--text);
}

/* [3] Glass mạnh hơn: blur + viền sáng + shadow đậm */
.glass {
  background: var(--glass-border);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--glass-border) inset;
  transition: box-shadow var(--transition), border-color var(--transition);
}

/* Neumorphism: card/panel dùng shadow lồi mềm */
[data-theme="neumorphism"] .glass {
  background: var(--neu-bg-light);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: var(--neu-border);
  border-radius: var(--neu-radius);
  box-shadow: var(--neu-shadow-outset);
}
[data-theme="neumorphism"] .glass:focus-within {
  box-shadow: var(--neu-shadow-outset), 0 0 0 2px var(--accent-glow);
}

/* Layout */
.admin-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  border-bottom: 1px solid var(--glass-border);
  transition: border-color var(--transition);
}

.admin-main {
  display: flex;
  min-height: calc(100vh - var(--header-height));
}

.admin-sidebar {
  width: var(--sidebar-width);
  padding: 1rem 0;
  border-right: 1px solid var(--glass-border);
  transition: border-color var(--transition);
}

.admin-content {
  flex: 1;
  padding: 1.5rem;
  overflow: auto;
  max-width: 1400px;
  margin: 0 auto;
}

[data-theme="neumorphism"] .admin-header,
[data-theme="neumorphism"] .admin-sidebar {
  border-color: var(--neu-border);
}
[data-theme="neumorphism"] .admin-header {
  background: var(--neu-bg-light);
  box-shadow: var(--neu-shadow-outset);
}
[data-theme="neumorphism"] .nav-link {
  color: var(--text-muted);
}
[data-theme="neumorphism"] .nav-link:hover {
  color: var(--text);
  background: rgba(99, 102, 241, 0.08);
}
[data-theme="neumorphism"] .nav-link.active {
  color: var(--text-main);
  background: rgba(99, 102, 241, 0.2);
}

/* [10] Nav active viền trái accent + [12] transition */
.nav-link {
  display: block;
  padding: 0.6rem 1rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 8px;
  margin: 0 0.5rem;
  border-left: 3px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
}

.nav-link:hover {
  background: var(--glass-border);
  color: var(--text-main);
}

.nav-link.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--text-main);
  border-left-color: var(--accent);
}

.nav-icon {
  display: inline-block;
  width: 1.25em;
  margin-right: 0.5rem;
  text-align: center;
  opacity: 0.9;
}

/* Forms + [12] transition, [7] input focus có trong Login section */
input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--text-main);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* [6] Nút primary gradient + hover/active scale + focus visible */
button.primary {
  padding: 0.6rem 1.25rem;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: var(--text-main);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

button.primary:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 20px var(--accent-glow);
  opacity: 1;
}

button.primary:active {
  transform: translateY(0) scale(0.98);
}

button.primary:focus-visible,
a.nav-link:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.error-msg {
  color: #f87171;
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* [13] Toast slide-in + shadow đẹp (neumorphism-friendly) */
#toastContainer {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  max-width: 320px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  animation: toastSlideIn 0.3s ease;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.toast.success { background: rgba(34, 197, 94, 0.95); color: var(--text-main); }
.toast.error { background: rgba(239, 68, 68, 0.95); color: var(--text-main); }
.toast.info { background: rgba(99, 102, 241, 0.95); color: var(--text-main); }

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

/* Loading skeleton + shimmer */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--glass-border) 0%,
    rgba(255, 255, 255, 0.12) 50%,
    var(--glass-border) 100%
  );
  background-size: 200% 100%;
  animation: skeletonShimmer 1.2s ease-in-out infinite;
  border-radius: 8px;
}

[data-theme="neumorphism"] .skeleton {
  background: linear-gradient(
    90deg,
    var(--neu-bg) 0%,
    var(--neu-bg-light) 50%,
    var(--neu-bg) 100%
  );
  background-size: 200% 100%;
  animation: skeletonShimmer 1.2s ease-in-out infinite;
}

@keyframes skeletonShimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.skeleton-row {
  height: 40px;
  margin-bottom: 8px;
}
.skeleton-card {
  height: 80px;
  margin-bottom: 1rem;
}

/* [14] Modal blur + animation mở/đóng */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 1;
  transition: opacity 0.2s ease-out;
}

.modal-overlay.hidden { display: none; opacity: 0; }

.modal-overlay .modal-content {
  animation: modalOpen 0.2s ease-out;
}

@keyframes modalOpen {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-content {
  background: rgba(30, 30, 40, 0.95);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
  transition: box-shadow var(--transition);
}

[data-theme="neumorphism"] .modal-content {
  background: var(--neu-bg-light);
  border: var(--neu-border);
  box-shadow: var(--neu-shadow-outset);
}

.modal-content h3 { margin-top: 0; }
.modal-actions { margin-top: 1.25rem; display: flex; gap: 0.75rem; justify-content: flex-end; }

/* [8] Bảng sticky header + zebra + [12] transition */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-modal);
  box-shadow: 0 1px 0 var(--glass-border);
}

.data-table th,
.data-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--glass-border);
  transition: background var(--transition);
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.875rem;
}

/* removed tr background and hover resets */

.data-table input.cell-edit {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text-main);
  font-size: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.data-table input.cell-edit:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Pagination + [12] transition */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.pagination button {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  background: var(--glass-border);
  color: var(--text-main);
  cursor: pointer;
  font-size: 0.875rem;
  transition: background var(--transition), border-color var(--transition);
}

.pagination button:hover:not(:disabled) {
  background: var(--glass-border);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination span {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* [15] Login form: gradient border + focus (input đã có focus chung ở trên) */
.login-wrap {
  position: relative;
  box-shadow: 0 0 0 1px var(--glass-border), 0 8px 32px rgba(0, 0, 0, 0.35),
    0 0 60px -12px rgba(99, 102, 241, 0.25);
}

.login-wrap::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 13px;
  padding: 1px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(139, 92, 246, 0.2), transparent);
  -webkit-mask: linear-gradient(var(--text-main) 0 0) content-box, linear-gradient(var(--text-main) 0 0);
  mask: linear-gradient(var(--text-main) 0 0) content-box, linear-gradient(var(--text-main) 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* Typography: số card, tiêu đề */
.stat-number {
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
}
.module-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 1rem;
}

/* Table: hover rõ, sticky header nền đặc */
/* removed thead and tr hover duplicate overrides */

/* Responsive: sidebar thu gọn / hamburger */
@media (max-width: 768px) {
  .admin-sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    z-index: 800;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .admin-sidebar.open {
    transform: translateX(0);
  }
  .admin-content {
    margin: 0;
    max-width: none;
  }
  .admin-header .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    cursor: pointer;
    color: inherit;
  }
}

.sidebar-toggle {
  display: none;
}

.theme-toggle {
  padding: 0.4rem 0.6rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.2s, transform 0.18s;
}
.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(1.05);
}
.theme-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Dashboard stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.stat-card {
  padding: 1.25rem;
  border-radius: var(--neu-radius, 12px);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}

.stat-card-link:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

[data-theme="neumorphism"] .stat-card-link:hover {
  box-shadow: 12px 12px 24px rgba(0, 0, 0, 0.25), -6px -6px 16px rgba(255, 255, 255, 0.05);
}

.stat-card .stat-icon {
  display: block;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  opacity: 0.9;
}

.stat-card .stat-icon-tasks { color: #22c55e; }
.stat-card .stat-icon-credits { color: #a78bfa; }

.stat-card .stat-label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-muted, var(--text-muted));
  margin-top: 0.25rem;
}

/* Health gauge */
.health-gauge {
  margin-top: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  height: 8px;
  overflow: hidden;
  position: relative;
}
.health-gauge-bar {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #22c55e);
  border-radius: 8px;
  transition: width 0.3s ease;
}
.health-gauge-label {
  font-size: 0.75rem;
  color: var(--text-muted, var(--text-muted));
  display: block;
  margin-top: 0.25rem;
}

/* Plugins: nút Tắt (secondary) */
.plugin-btn-off {
  padding: 0.35rem 0.65rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  color: inherit;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.2s;
}
.plugin-btn-off:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
}

.modal-content p {
  margin: 0.75rem 0;
}
.modal-content label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-muted, var(--text-muted));
  margin-bottom: 0.25rem;
}
