/* ==========================================================================
   Khmer E-Learning Platform Design System
   Modern, Vibrant & Child-Friendly Educational UI
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&family=Kantumruy+Pro:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=Outfit:wght@400;500;600;700;800;900&display=swap');

:root {
  --font-base: 'Kantumruy Pro', 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-latin: 'Outfit', sans-serif;
  --font-fun: 'Fredoka', 'Outfit', sans-serif;

  /* Vibrant & Joyful Palette for Kids & Youth */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-border: #c7d2fe;

  --secondary: #06b6d4;
  --secondary-hover: #0891b2;
  --secondary-light: #ecfeff;

  --accent-gold: #f59e0b;
  --accent-amber: #f59e0b;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --accent-violet: #8b5cf6;
  --accent-pink: #ec4899;
  --accent-sky: #0284c7;
  --accent-orange: #fb923c;

  /* Neutrals & Surfaces */
  --bg-body: #f4f7fe;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --border-color: #e2e8f0;
  --border-subtle: #cbd5e1;

  --text-main: #1e1b4b;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --text-inverse: #ffffff;

  /* Sidebar: Modern Royal Indigo-Violet Gradient */
  --sidebar-bg: #1e1b4b;
  --sidebar-hover: rgba(255, 255, 255, 0.1);
  --sidebar-active: #6366f1;
  --sidebar-text: #c7d2fe;
  --sidebar-text-active: #ffffff;

  /* Playful Soft Shadows */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 6px 16px -2px rgba(99, 102, 241, 0.1), 0 2px 6px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 14px 28px -4px rgba(99, 102, 241, 0.14), 0 6px 12px -2px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 24px 40px -8px rgba(99, 102, 241, 0.18), 0 10px 18px -4px rgba(0, 0, 0, 0.05);
  --shadow-hover: 0 18px 36px -6px rgba(99, 102, 241, 0.22), 0 6px 14px -3px rgba(0, 0, 0, 0.06);

  /* Rounded Friendly Radiuses */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-pill: 9999px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-base);
  background-color: var(--bg-body);
  background-image: 
    radial-gradient(circle at 10% 15%, rgba(99, 102, 241, 0.05) 0%, transparent 45%),
    radial-gradient(circle at 90% 80%, rgba(236, 72, 153, 0.05) 0%, transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(6, 182, 212, 0.03) 0%, transparent 60%);
  background-attachment: fixed;
  color: var(--text-main);
  line-height: 1.7;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: all 0.2s ease;
}
a:hover {
  color: var(--primary-hover);
}

/* ==========================================================================
   Layout Structure (App Shell - Independent Scrolling Left & Right)
   ========================================================================== */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.sidebar {
  width: 280px;
  height: 100vh;
  background: linear-gradient(180deg, #1e1b4b 0%, #2e1065 55%, #1e1b4b 100%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.3s ease;
  z-index: 40;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.sidebar-header {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  flex-shrink: 0;
}

.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  background: linear-gradient(135deg, #ec4899, #8b5cf6, #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 22px;
  box-shadow: 0 6px 18px rgba(139, 92, 246, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.3);
  transform: rotate(-3deg);
  transition: transform 0.2s ease;
}

.brand-logo:hover {
  transform: rotate(3deg) scale(1.06);
}

.brand-info h1 {
  font-size: 17px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.brand-info p {
  font-size: 11px;
  color: #c7d2fe;
  font-weight: 600;
  margin-top: 2px;
}

.sidebar-nav {
  padding: 20px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 5px;
}
.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.35);
}

.nav-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a5b4fc;
  padding: 14px 14px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  color: #e0e7ff;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  transform: translateX(4px);
}

.nav-item.active {
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
  font-weight: 700;
}

.nav-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.nav-item.active .nav-icon {
  background: rgba(255, 255, 255, 0.25);
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.18);
  flex-shrink: 0;
}

.main-content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: transparent;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.main-content-wrapper::-webkit-scrollbar {
  width: 8px;
}
.main-content-wrapper::-webkit-scrollbar-track {
  background: transparent;
}
.main-content-wrapper::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}
.main-content-wrapper::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.topbar {
  height: 72px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-container {
  padding: 32px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ==========================================================================
   Components: Cards, Stat Badges, Buttons
   ========================================================================== */
.card {
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1.5px solid rgba(226, 232, 240, 0.9);
  box-shadow: var(--shadow-sm);
  padding: 26px;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease, border-color 0.2s ease;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-border);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.card-title {
  font-size: 19px;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1.5px solid rgba(226, 232, 240, 0.9);
  padding: 22px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
}

.stat-card:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: var(--shadow-md);
}

.stat-icon-wrapper {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.stat-icon-blue { 
  background: linear-gradient(135deg, #dbeafe, #eff6ff); 
  color: #2563eb; 
  border: 1px solid #bfdbfe;
}
.stat-icon-emerald { 
  background: linear-gradient(135deg, #d1fae5, #ecfdf5); 
  color: #059669; 
  border: 1px solid #a7f3d0;
}
.stat-icon-amber { 
  background: linear-gradient(135deg, #fef3c7, #fffbeb); 
  color: #d97706; 
  border: 1px solid #fde68a;
}
.stat-icon-violet { 
  background: linear-gradient(135deg, #ede9fe, #f5f3ff); 
  color: #7c3aed; 
  border: 1px solid #ddd6fe;
}
.stat-icon-rose { 
  background: linear-gradient(135deg, #ffe4e6, #fff1f2); 
  color: #e11d48; 
  border: 1px solid #fecdd3;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  font-family: var(--font-fun);
  line-height: 1.1;
  color: var(--text-main);
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 4px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.badge-primary { background: linear-gradient(135deg, #e0e7ff, #eef2ff); color: #4338ca; border: 1px solid #c7d2fe; }
.badge-success { background: linear-gradient(135deg, #d1fae5, #ecfdf5); color: #065f46; border: 1px solid #a7f3d0; }
.badge-warning { background: linear-gradient(135deg, #fef3c7, #fffbeb); color: #92400e; border: 1px solid #fde68a; }
.badge-danger { background: linear-gradient(135deg, #ffe4e6, #fff1f2); color: #9f1239; border: 1px solid #fecdd3; }
.badge-info { background: linear-gradient(135deg, #e0f2fe, #f0f9ff); color: #0369a1; border: 1px solid #bae6fd; }
.badge-neutral { background-color: var(--bg-subtle); color: var(--text-muted); border: 1px solid var(--border-color); }

/* Playful Gamified Buttons (Duolingo / 3D Tactile Touch) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  font-family: var(--font-base);
  text-decoration: none;
  user-select: none;
}

.btn:active {
  transform: translateY(2px);
}

.btn-primary {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: white;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
  border-bottom: 3px solid #3730a3;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #4338ca, #4f46e5);
  color: white;
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.4);
  transform: translateY(-2px);
}
.btn-primary:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
}

.btn-secondary {
  background-color: var(--bg-surface);
  border: 1.5px solid var(--border-color);
  color: var(--text-main);
  border-bottom: 3px solid #cbd5e1;
}
.btn-secondary:hover {
  background-color: #f8fafc;
  border-color: #94a3b8;
  transform: translateY(-2px);
}
.btn-secondary:active {
  transform: translateY(2px);
  border-bottom-width: 1.5px;
}

.btn-ai {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: white;
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.35);
  border: none;
  border-bottom: 3px solid #7c3aed;
}
.btn-ai:hover {
  background: linear-gradient(135deg, #7c3aed, #db2777);
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.45);
  transform: translateY(-2px);
  color: white;
}
.btn-ai:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border-bottom: 3px solid #047857;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.btn-success:hover {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-2px);
}

.btn-danger {
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  color: white;
  border-bottom: 3px solid #be123c;
  box-shadow: 0 4px 12px rgba(244, 63, 94, 0.3);
}
.btn-danger:hover {
  background: linear-gradient(135deg, #e11d48, #be123c);
  transform: translateY(-2px);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 14px 28px;
  font-size: 16px;
  border-radius: var(--radius-lg);
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
}

.data-table th {
  background-color: #f8fafc;
  padding: 14px 18px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border-color);
  letter-spacing: 0.04em;
}

.data-table td {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background-color: #f8fafc;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}

.form-control {
  width: 100%;
  padding: 11px 16px;
  font-size: 14px;
  font-family: var(--font-base);
  color: var(--text-main);
  background-color: #ffffff;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
}

textarea.form-control {
  min-height: 110px;
  resize: vertical;
}

/* Flash alerts */
.alert {
  padding: 16px 20px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.alert-success {
  background-color: #ecfdf5;
  color: #065f46;
  border: 1.5px solid #a7f3d0;
}

.alert-error {
  background-color: #fef2f2;
  color: #991b1b;
  border: 1.5px solid #fecaca;
}

/* Modal */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.modal-backdrop.active {
  display: flex !important;
  animation: modalFadeIn 0.2s ease-out;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-xl);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-color);
  animation: modalScaleIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border-color);
  background: #f8fafc;
}

.modal-body {
  padding: 28px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 18px 28px;
  border-top: 1px solid var(--border-color);
  background: #f8fafc;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* ==========================================================================
   Quiz & Gamification Micro-Styles
   ========================================================================== */
.quiz-choice-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 18px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: #ffffff;
  position: relative;
}

.quiz-choice-card:hover {
  border-color: #818cf8;
  background-color: #f5f7ff;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.12);
}

.quiz-choice-badge {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  font-family: var(--font-latin);
  flex-shrink: 0;
  margin-top: 2px;
  transition: all 0.2s ease;
}

.badge-choice-0 { background: #dbeafe; color: #1d4ed8; }
.badge-choice-1 { background: #d1fae5; color: #047857; }
.badge-choice-2 { background: #fef3c7; color: #b45309; }
.badge-choice-3 { background: #ede9fe; color: #6d28d9; }

.quiz-choice-card input[type="radio"]:checked ~ .quiz-choice-badge {
  transform: scale(1.1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

/* ==========================================================================
   Responsive & Print Breakpoints
   ========================================================================== */
@media (max-width: 900px) {
  html, body {
    height: auto;
    overflow: auto;
  }
  .app-layout {
    height: auto;
    overflow: visible;
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    overflow: visible;
  }
  .sidebar-nav {
    max-height: 280px;
  }
  .main-content-wrapper {
    height: auto;
    overflow: visible;
  }
}

@media print {
  html, body, .app-layout, .main-content-wrapper, .page-container {
    background: #ffffff !important;
    padding: 0 !important;
    margin: 0 !important;
    height: auto !important;
    overflow: visible !important;
    min-height: auto !important;
  }
  .sidebar, .topbar, .no-print, .btn {
    display: none !important;
  }
  .certificate-frame {
    box-shadow: none !important;
    border: 8px double #1e3a8a !important;
    page-break-inside: avoid;
  }
}

