/* ==========================================================================
   LMS System - Application Styles
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --success: #16a34a;
  --success-light: #22c55e;
  --warning: #ea580c;
  --danger: #dc2626;
  --info: #0891b2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  color: var(--gray-800);
  background: var(--gray-50);
  min-height: 100vh;
}

/* ==========================================================================
   Header & Navigation
   ========================================================================== */

header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

header nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
}

header a { color: white; text-decoration: none; }
header h1 { font-size: 1.25rem; font-weight: 600; }

.nav-links { display: flex; align-items: center; gap: 1.5rem; }
.nav-links a { opacity: 0.9; transition: opacity 0.2s; }
.nav-links a:hover { opacity: 1; }

.user-menu {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-name {
  font-size: 0.9rem;
  opacity: 0.9;
}

.btn-logout {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
}

.btn-logout:hover {
  background: rgba(255,255,255,0.25);
}

/* ==========================================================================
   Breadcrumb
   ========================================================================== */

.breadcrumb {
  background: var(--gray-100);
  padding: 0.75rem 2rem;
  border-bottom: 1px solid var(--gray-200);
}

.breadcrumb-inner {
  max-width: 1200px;
  margin: 0 auto;
  font-size: 0.9rem;
  color: var(--gray-600);
}

.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ==========================================================================
   Main Layout
   ========================================================================== */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.page-title {
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
  color: var(--gray-800);
}

.page-subtitle {
  font-size: 1rem;
  color: var(--gray-600);
  margin-bottom: 2rem;
}

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body {
  padding: 1.5rem;
}

/* ==========================================================================
   Forms
   ========================================================================== */

.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--gray-700);
}

.form-input,
.form-select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder {
  color: var(--gray-400);
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
  background: var(--gray-200);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: var(--success-light);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

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

/* ==========================================================================
   Tables
   ========================================================================== */

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

.table th {
  font-weight: 600;
  color: var(--gray-600);
  background: var(--gray-50);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table tr:hover td {
  background: var(--gray-50);
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-admin {
  background: #fef3c7;
  color: #92400e;
}

.badge-learner {
  background: #dbeafe;
  color: #1e40af;
}

.badge-success {
  background: #dcfce7;
  color: #166534;
}

.badge-warning {
  background: #ffedd5;
  color: #9a3412;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

/* ==========================================================================
   Progress
   ========================================================================== */

.progress-bar {
  height: 8px;
  background: var(--gray-200);
  border-radius: 9999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--success);
  border-radius: 9999px;
  transition: width 0.3s;
}

.progress-text {
  font-size: 0.85rem;
  color: var(--gray-600);
  margin-top: 0.25rem;
}

/* ==========================================================================
   Learning Path Sections (Dashboard)
   ========================================================================== */

.path-section {
  margin-bottom: 2rem;
}

.path-section-header {
  margin-bottom: 1rem;
}

.path-section-header h2 {
  font-size: 1.25rem;
  color: var(--gray-800);
  margin: 0 0 0.5rem 0;
}

.path-section-header .path-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 400px;
}

.path-section-header .progress-bar {
  flex: 1;
}

.path-section-header .progress-text {
  font-size: 0.85rem;
  color: var(--gray-500);
  white-space: nowrap;
  margin: 0;
}

/* ==========================================================================
   Module Cards (Dashboard)
   ========================================================================== */

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.module-card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.module-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.module-card-header {
  padding: 1.5rem;
  color: white;
}

.module-card-header h3 {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}

.module-card-header span {
  font-size: 0.85rem;
  opacity: 0.9;
}

.module-card-body {
  padding: 1.5rem;
}

.module-card-body p {
  color: var(--gray-600);
  margin-bottom: 1rem;
  font-size: 0.95rem;
  line-height: 1.5;
}

.module-progress {
  margin-bottom: 1rem;
}

/* ==========================================================================
   Login Page
   ========================================================================== */

.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--gray-800), var(--gray-900));
}

.login-card {
  background: white;
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header h1 {
  font-size: 1.5rem;
  color: var(--gray-800);
  margin-bottom: 0.5rem;
}

.login-header p {
  color: var(--gray-600);
}

.login-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  display: none;
}

.login-error.show {
  display: block;
}

/* ==========================================================================
   Admin Tabs
   ========================================================================== */

.tabs {
  display: flex;
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: 2rem;
}

.tab {
  padding: 1rem 1.5rem;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab:hover {
  color: var(--primary);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ==========================================================================
   Modal
   ========================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.25rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-500);
}

.modal-close:hover {
  color: var(--gray-700);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ==========================================================================
   Loading
   ========================================================================== */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--gray-500);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 0.75rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   Footer
   ========================================================================== */

footer {
  background: var(--gray-800);
  color: white;
  text-align: center;
  padding: 2rem;
  margin-top: 4rem;
}

footer p {
  opacity: 0.7;
  font-size: 0.9rem;
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* ==========================================================================
   Locked Module States
   ========================================================================== */

.module-card.locked {
  opacity: 0.6;
  cursor: not-allowed;
  position: relative;
}

.module-card.locked:hover {
  transform: none;
  box-shadow: var(--shadow);
}

.module-card.locked .module-card-body {
  pointer-events: none;
}

.lock-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  z-index: 10;
}

.lock-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-800);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 20;
  margin-bottom: 0.5rem;
}

.lock-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--gray-800);
}

.module-card.locked:hover .lock-tooltip {
  opacity: 1;
  visibility: visible;
}

/* ==========================================================================
   Learning Paths Admin
   ========================================================================== */

.path-modules-list {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
}

.path-module-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  background: white;
  cursor: grab;
  transition: background 0.2s;
}

.path-module-item:last-child {
  border-bottom: none;
}

.path-module-item:hover {
  background: var(--gray-50);
}

.path-module-item.dragging {
  opacity: 0.5;
  background: var(--gray-100);
}

.path-module-item .drag-handle {
  color: var(--gray-400);
  cursor: grab;
  font-size: 1rem;
}

.path-module-item .module-name {
  flex-grow: 1;
  font-weight: 500;
}

.path-module-item .module-order {
  width: 24px;
  height: 24px;
  background: var(--gray-200);
  color: var(--gray-600);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
}

.path-module-item .linear-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--gray-600);
}

.path-module-item .linear-toggle input {
  width: 16px;
  height: 16px;
}

.empty-path-message {
  padding: 2rem;
  text-align: center;
  color: var(--gray-500);
}

.path-actions {
  display: flex;
  gap: 0.5rem;
}

/* ==========================================================================
   Full-screen Path Editor
   ========================================================================== */

.path-editor {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--gray-50);
  flex-direction: column;
}

.path-editor.open {
  display: flex;
}

.path-editor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.path-editor-topbar h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.path-editor-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

.path-editor-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--gray-200);
  overflow: hidden;
  min-height: 0;
}

.path-editor-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.path-editor-panel {
  padding: 1rem 1.25rem;
}

.path-editor-panel.path-panel-fixed {
  flex-shrink: 0;
}

.path-editor-panel.path-panel-flex {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.path-editor .path-modules-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  max-height: none;
}

/* Category group in available modules */
.path-category-group {
  border-bottom: 1px solid var(--gray-100);
}

.path-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--gray-100);
  cursor: pointer;
  user-select: none;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.path-category-header:hover {
  background: var(--gray-200);
}

.path-category-header .chevron {
  transition: transform 0.2s;
  font-size: 0.7rem;
  color: var(--gray-400);
}

.path-category-group.collapsed .chevron {
  transform: rotate(-90deg);
}

.path-category-group.collapsed .path-category-items {
  display: none;
}

.path-category-count {
  font-weight: 400;
  color: var(--gray-400);
  margin-left: 0.5rem;
}

.path-search-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--gray-400);
  font-size: 0.9rem;
}

/* Learning Path assignment dropdown */
.path-select-wrapper {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--gray-200);
}

.path-select-wrapper label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--gray-700);
}

.path-select-wrapper select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 1rem;
}

/* Module list with order indicators in assign modal */
.module-assign-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.module-assign-item .order-badge {
  width: 20px;
  height: 20px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
}

.module-assign-item .order-badge.no-order {
  background: var(--gray-300);
  color: var(--gray-600);
}

.module-assign-item .lock-indicator {
  font-size: 0.8rem;
  color: var(--warning);
}
