/* ═══════════════════════════════════════════════════════
   EduPlatform Admin Dashboard — Design System
   ═══════════════════════════════════════════════════════ */

/* ─── CSS Custom Properties ─── */
:root {
  /* Colors */
  --primary-start: #102a43;
  --primary-start-rgb: 16, 42, 67;
  --primary-mid: #243b55;
  --primary-end: #486581;
  --primary-end-rgb: 72, 101, 129;
  --accent: #829ab1;
  --accent-rgb: 130, 154, 177;
  --accent-glow: rgba(130, 154, 177, 0.25);
  --neon-purple: #bcccdc;
  --neon-purple-rgb: 188, 204, 220;
  --neon-blue: #829ab1;
  --success: #00E676;
  --success-rgb: 0, 230, 118;
  --warning: #FFD740;
  --warning-rgb: 255, 215, 64;
  --error: #FF5252;
  --error-rgb: 255, 82, 82;
  --medical: #26A69A;
  --medical-rgb: 38, 166, 154;

  /* Light Theme */
  --bg: #F0F4F8;
  --surface: #FFFFFF;
  --surface-variant: #E2E8F0;
  --text: #102A43;
  --text-secondary: #486581;
  --text-tertiary: #829AB1;
  --border: #BCCCDC;
  --card-shadow: rgba(16, 42, 67, 0.08);

  /* Sizes Normalized & Robust */
  --sidebar-width: 300px;
  --topbar-height: 80px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-3xl: 28px;

  /* Fonts */
  --font: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Transitions */
  --transition-fast: 200ms ease;
  --transition-normal: 350ms ease;
  --transition-slow: 500ms ease;
}

[data-theme="dark"] {
  --bg: #102A43;
  --surface: #1D2D44;
  --surface-variant: #243B55;
  --text: #F0F4F8;
  --text-secondary: #BCCCDC;
  --text-tertiary: #829AB1;
  --border: #486581;
  --card-shadow: rgba(0, 0, 0, 0.4);
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 100%;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

/* ─── Large Screen Scaling ─── */
/* Scale up the entire UI on 2K / 4K / HiDPI displays */
@media (min-width: 1920px) {
  html { font-size: 112%; }
  :root {
    --sidebar-width: 320px;
    --topbar-height: 88px;
  }
}
@media (min-width: 2200px) {
  html { font-size: 130%; }
  :root {
    --sidebar-width: 360px;
    --topbar-height: 96px;
  }
}
@media (min-width: 2560px) {
  html { font-size: 150%; }
  :root {
    --sidebar-width: 400px;
    --topbar-height: 108px;
  }
}
@media (min-width: 3000px) {
  html { font-size: 175%; }
  :root {
    --sidebar-width: 460px;
    --topbar-height: 120px;
  }
}


body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  outline: none;
}

img {
  max-width: 100%;
  display: block;
}

/* ─── Typography Personalized (Standard Large) ─── */
.h1 { font-size: 2.5rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.5px; }
.h2 { font-size: 2rem; font-weight: 700; line-height: 1.25; }
.h3 { font-size: 1.75rem; font-weight: 600; line-height: 1.3; }
.h4 { font-size: 1.4rem; font-weight: 600; line-height: 1.35; }
.h5 { font-size: 1.2rem; font-weight: 600; line-height: 1.4; }
.body-lg { font-size: 1.15rem; line-height: 1.5; }
.body { font-size: 1.0625rem; line-height: 1.5; }
.body-sm { font-size: 0.95rem; line-height: 1.5; }
.caption { font-size: 0.875rem; line-height: 1.4; letter-spacing: 0.3px; }

.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error { color: var(--error); }
.text-accent { color: var(--accent); }

/* ─── Gradients ─── */
.gradient-text {
  background: linear-gradient(135deg, var(--primary-start), var(--primary-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.gradient-bg {
  background: linear-gradient(135deg, var(--primary-start), var(--primary-end));
}

.gradient-bg-accent {
  background: linear-gradient(135deg, var(--accent), var(--neon-blue));
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 28px;
  border-radius: var(--radius-lg);
  font-weight: 600;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background var(--transition-fast);
}

.btn:hover::after {
  background: rgba(255,255,255,0.1);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-start), var(--primary-end));
  color: white;
  box-shadow: 0 8px 24px rgba(26, 35, 126, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 12px 32px rgba(26, 35, 126, 0.4);
  transform: translateY(-1px);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), var(--neon-blue));
  color: #0D0D2B;
  box-shadow: 0 8px 24px rgba(0, 229, 255, 0.25);
}

.btn-outline {
  background: transparent;
  color: var(--primary-start);
  border: 2px solid var(--primary-start);
}

.btn-outline:hover {
  background: var(--primary-start);
  color: white;
}

.btn-danger {
  background: linear-gradient(135deg, var(--error), #D32F2F);
  color: white;
  box-shadow: 0 8px 24px rgba(255, 82, 82, 0.25);
}

.btn-sm { padding: 10px 20px; font-size: 0.85rem; border-radius: var(--radius-md); }
.btn-lg { padding: 18px 36px; font-size: 1.1rem; }
.btn-icon { width: 44px; height: 44px; padding: 0; border-radius: var(--radius-md); }
.btn-icon-sm { width: 36px; height: 36px; padding: 0; border-radius: var(--radius-sm); }

/* --- Action Buttons --- */
.action-group {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.action-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  background: var(--surface-variant);
  color: var(--text-secondary);
}

.action-btn span {
  font-size: 18px;
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.action-btn.edit {
  color: var(--accent);
}

.action-btn.edit:hover {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.action-btn.delete {
  color: var(--error);
}

.action-btn.delete:hover {
  background: var(--error);
  color: white;
  box-shadow: 0 4px 12px rgba(255, 82, 82, 0.3);
}

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: 0 4px 20px var(--card-shadow);
  transition: all var(--transition-normal);
}

.card:hover {
  box-shadow: 0 8px 30px var(--card-shadow);
}

.card-glass {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-2xl);
  padding: 32px;
}

/* ─── Inputs ─── */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

.input {
  width: 100%;
  padding: 14px 18px;
  background: var(--surface-variant);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text);
  font-size: 0.875rem;
  transition: all var(--transition-fast);
}

.input:focus {
  border-color: var(--primary-start);
  box-shadow: 0 0 0 4px rgba(26, 35, 126, 0.1);
}

.input-icon {
  position: relative;
}

.input-icon .icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: 1.25rem;
  transition: color var(--transition-fast);
}

.input-icon .input {
  padding-left: 48px;
}

.input-icon:focus-within .icon {
  color: var(--primary-start);
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 18px;
  padding-right: 44px;
}

textarea.input {
  resize: vertical;
  min-height: 100px;
}

/* ─── Tables ─── */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: 0 4px 20px var(--card-shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 16px 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: var(--surface-variant);
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 16px 20px;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr {
  transition: background var(--transition-fast);
}

tbody tr:hover {
  background: var(--surface-variant);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* ─── Badges ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.6875rem;
  font-weight: 600;
}

.badge-primary { background: rgba(26, 35, 126, 0.1); color: var(--primary-start); }
.badge-primary-start { background: rgba(var(--primary-start-rgb), 0.1); color: var(--primary-start); }
.badge-primary-end { background: rgba(var(--primary-end-rgb), 0.1); color: var(--primary-end); }
.badge-success { background: rgba(0, 230, 118, 0.12); color: var(--success); }
.badge-warning { background: rgba(255, 215, 64, 0.15); color: #E6A800; }
.badge-error { background: rgba(255, 82, 82, 0.12); color: var(--error); }
.badge-accent { background: rgba(0, 229, 255, 0.12); color: var(--accent); }
.badge-neon-purple { background: rgba(var(--neon-purple-rgb), 0.18); color: var(--primary-end); }
.badge-medical { background: rgba(var(--medical-rgb), 0.12); color: var(--medical); }

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-2xl);
  padding: 32px;
  max-width: 600px;
  width: 95%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.9) translateY(20px);
  transition: transform var(--transition-normal);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  overflow: visible;
}

.modal-lg {
  max-width: 800px;
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-shrink: 0;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 8px;
    margin-right: -8px;
    min-height: 0;
}

.modal-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--surface-variant);
  color: var(--text);
}

/* ─── Toast ─── */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 30px var(--card-shadow);
  border-left: 4px solid var(--success);
  min-width: 300px;
  transform: translateX(120%);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
  transform: translateX(0);
}

.toast-error { border-left-color: var(--error); }
.toast-warning { border-left-color: var(--warning); }
.toast-info { border-left-color: var(--accent); }

/* ─── Stat Cards ─── */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  box-shadow: 0 4px 20px var(--card-shadow);
  transition: all var(--transition-normal);
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 30px var(--card-shadow);
}

.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 4px;
}

.stat-change.up {
  color: var(--success);
  background: rgba(0, 230, 118, 0.1);
}

/* ─── Avatar ─── */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  object-fit: cover;
}

.avatar-sm { width: 32px; height: 32px; border-radius: var(--radius-sm); }
.avatar-lg { width: 56px; height: 56px; border-radius: var(--radius-lg); }
.avatar-round { border-radius: 50%; }

/* ─── Skeleton Loader ─── */
.skeleton {
  background: linear-gradient(90deg, var(--surface-variant) 25%, var(--surface) 50%, var(--surface-variant) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Animations ─── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.animate-fadeInUp { animation: fadeInUp 0.6s ease forwards; }
.animate-fadeIn { animation: fadeIn 0.5s ease forwards; }
.animate-slideInLeft { animation: slideInLeft 0.5s ease forwards; }

.delay-100 { animation-delay: 100ms; }
.delay-200 { animation-delay: 200ms; }
.delay-300 { animation-delay: 300ms; }
.delay-400 { animation-delay: 400ms; }
.delay-500 { animation-delay: 500ms; }

/* ─── Utilities ─── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-xs { gap: 4px; }
.gap-sm { gap: 8px; }
.gap-md { gap: 12px; }
.gap-lg { gap: 16px; }
.gap-xl { gap: 20px; }
.gap-2xl { gap: 24px; }
.w-full { width: 100%; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ─── RBAC & View Mode Enhancements ─── */
.read-only-view .input:disabled {
  background: var(--surface);
  border-color: transparent;
  padding-left: 0;
  cursor: default;
  font-weight: 500;
  color: var(--text);
  opacity: 1; /* Override default disabled opacity */
}

.read-only-view select.input {
  background-image: none;
}

.read-only-view .input-group label {
  color: var(--primary-start);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.8px;
  margin-bottom: 2px;
}

.read-only-view .image-upload {
  display: none;
}

.view-btn {
  color: var(--accent);
  background: rgba(0, 229, 255, 0.08);
}

.view-btn:hover {
  background: rgba(0, 229, 255, 0.15);
  transform: scale(1.1);
}

.modal.read-only-view {
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 40px rgba(0, 229, 255, 0.15);
}

/* ─── Video Management UI ─── */
.video-type-toggle {
  display: flex;
  background: var(--surface-variant);
  padding: 4px;
  border-radius: var(--radius-md);
  gap: 4px;
}

.video-type-toggle .toggle-btn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.video-type-toggle .toggle-btn.active {
  background: var(--surface);
  color: var(--primary-start);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* ─── Lesson Cards & Quiz Builder ─── */
.lesson-card {
    background: var(--surface-variant);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    transition: all var(--transition-fast);
}

.lesson-card:hover { border-color: var(--primary-end); }

.quiz-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-top: 12px;
}

.question-row {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    position: relative;
}

.question-row:last-child { margin-bottom: 0; }

.video-preview-placeholder {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-tertiary);
  border: 2px solid var(--border);
  margin-top: 12px;
  overflow: hidden;
  position: relative;
}

.video-preview-placeholder .material-symbols-rounded {
  font-size: 3rem;
  opacity: 0.5;
}

.video-upload-box {
  width: 100%;
  padding: 24px;
  background: var(--surface-variant);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.video-upload-box:hover {
  border-color: var(--accent);
  background: rgba(0, 229, 255, 0.03);
}

#videoSection.view-mode {
  padding: 0;
  margin-top: 12px;
}

#videoSection.view-mode .video-preview-placeholder {
  border: none;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  margin-top: 0;
}

/* ─── RTL (Right-to-Left) Support ─── */
[dir="rtl"] {
  direction: rtl;
  text-align: right;
  font-family: 'Poppins', 'Cairo', sans-serif;
}

[dir="rtl"] .topbar-actions {
  margin-left: 0;
  margin-right: auto;
}

@media (max-width: 768px) {
  [dir="rtl"] .sidebar {
    transform: translateX(100%);
  }
}

[dir="rtl"] .topbar-search .material-symbols-rounded {
  margin-right: 0;
  margin-left: 12px;
}

[dir="rtl"] .topbar-actions {
  margin-left: 0;
  margin-right: auto;
}

[dir="rtl"] .sidebar-logo-icon,
[dir="rtl"] .nav-item span {
  margin-right: 0;
  margin-left: 12px;
}

[dir="rtl"] .table-container table th,
[dir="rtl"] .table-container table td {
  text-align: right;
}

[dir="rtl"] .flex.items-center.gap-md {
  flex-direction: row;
}

[dir="rtl"] .modal-close {
  right: auto;
  left: 20px;
}

/* Flip chevron icons in RTL */
[dir="rtl"] .material-symbols-rounded:contains("chevron_right") {
  transform: scaleX(-1);
}

@media (max-width: 992px) {
  [dir="rtl"] .main-content {
    margin-right: 0;
  }
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .h1 { font-size: 1.5rem; }
  .h2 { font-size: 1.25rem; }
  .h3 { font-size: 1.125rem; }
  .stat-card { padding: 16px; gap: 12px; }
  .stat-value { font-size: 1.375rem; }
}
