/* ============================================
   EduuMatch Unified Loading System
   Single source of truth for all loading states
   ============================================ */

/* ─── CSS Custom Properties ─────────────── */

:root {
  --loading-base:       #f5f0eb;
  --loading-highlight:  #ede5db;
  --loading-overlay:    rgba(255,255,255,0.85);
  --loading-accent:     #c9952c;
  --loading-text:       #9ca3af;
  --loading-speed:      1.5s;
}

@keyframes eduumatch-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes eduumatch-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes eduumatch-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

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

@keyframes eduumatch-progress {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

@media (prefers-reduced-motion: reduce) {
  .em-shimmer,
  .em-shimmer-line,
  .em-shimmer-circle,
  .em-spinner,
  .em-progress-indeterminate::after {
    animation: none !important;
  }
  .em-global-loader {
    opacity: 1;
  }
}

/* ─── Shimmer Base ─────────────────────── */

.em-shimmer {
  background: linear-gradient(90deg, var(--loading-base) 25%, var(--loading-highlight) 50%, var(--loading-base) 75%);
  background-size: 200% 100%;
  animation: eduumatch-shimmer var(--loading-speed) ease-in-out infinite;
}

/* ─── A. Global App Loader ─────────────── */

.em-global-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--loading-overlay);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.em-global-loader.active {
  opacity: 1;
  pointer-events: all;
}

.em-global-loader .em-brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  margin-bottom: 16px;
}

.em-global-loader .em-brand-text {
  font-size: 20px;
  font-weight: 700;
  color: #1a2744;
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.em-global-loader .em-loading-caption {
  font-size: 13px;
  color: var(--loading-text);
}

/* ─── B. Page Skeleton ─────────────────── */

.em-page-skeleton {
  display: none;
  padding: 24px;
  animation: eduumatch-fade-in 0.2s ease;
}

.em-page-skeleton.active {
  display: block;
}

.em-page-skeleton .em-sk-row {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.em-page-skeleton .em-sk-card {
  flex: 1;
  background: #fff;
  border: 1px solid var(--loading-base);
  border-radius: 12px;
  padding: 20px;
}

.em-page-skeleton .em-sk-card-lg {
  background: #fff;
  border: 1px solid var(--loading-base);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
}

.em-shimmer-line {
  height: 14px;
  border-radius: 7px;
  margin-bottom: 10px;
  width: 100%;
}

.em-shimmer-line.short {
  width: 60%;
}

.em-shimmer-line.thin {
  height: 10px;
  width: 40%;
}

.em-shimmer-line.medium {
  width: 75%;
}

.em-shimmer-line.long {
  width: 90%;
}

.em-shimmer-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
}

.em-shimmer-block {
  height: 120px;
  border-radius: 8px;
  margin-bottom: 16px;
}

/* ─── C. Card Skeleton ─────────────────── */

.em-card-skeleton {
  display: none;
  animation: eduumatch-fade-in 0.2s ease;
}

.em-card-skeleton.active {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 5;
  background: var(--bg, #f8f9fc);
}

.em-card-skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.em-card-skeleton .em-sk-card {
  background: #fff;
  border: 1px solid var(--loading-base);
  border-radius: 12px;
  padding: 20px;
}

.em-card-skeleton .em-sk-card-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

/* ─── D. Table Skeleton ────────────────── */

.em-table-skeleton {
  display: none;
  animation: eduumatch-fade-in 0.2s ease;
}

.em-table-skeleton.active {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 5;
  background: var(--bg, #f8f9fc);
}

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

.em-table-skeleton th {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 2px solid var(--loading-base);
}

.em-table-skeleton td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--loading-base);
}

/* ─── E. Button Loading ────────────────── */

.em-btn-loading {
  position: relative;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.em-btn-loading .em-btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: eduumatch-spin 0.7s linear infinite;
  flex-shrink: 0;
}

.em-btn-loading .em-btn-text {
  opacity: 0.7;
}

/* ─── F. File Upload Progress ──────────── */

.em-upload-progress {
  display: none;
  margin-top: 12px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--loading-base);
  border-radius: 8px;
}

.em-upload-progress.active {
  display: block;
}

.em-upload-label {
  font-size: 12px;
  color: var(--loading-text);
  margin-bottom: 6px;
}

.em-upload-track {
  height: 6px;
  background: var(--loading-base);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}

.em-upload-fill {
  height: 100%;
  background: var(--loading-accent);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

.em-upload-percent {
  font-size: 11px;
  color: var(--loading-text);
  text-align: right;
}

/* ─── Empty State (shared) ─────────────── */

.em-empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--loading-text);
}

.em-empty-state .em-empty-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.em-empty-state .em-empty-text {
  font-size: 13px;
}

/* ─── Error State ──────────────────────── */

.em-error-state {
  text-align: center;
  padding: 32px 16px;
  border: 1px dashed #fca5a5;
  border-radius: 8px;
  background: #fef2f2;
  color: #dc2626;
}

.em-error-state .em-error-text {
  font-size: 13px;
  margin-bottom: 8px;
}

.em-error-state .em-error-retry {
  font-size: 12px;
  color: var(--loading-accent);
  cursor: pointer;
  text-decoration: underline;
}

/* ─── G. Retry State ───────────────────── */

.em-retry-state {
  text-align: center;
  padding: 32px 16px;
  animation: eduumatch-fade-in 0.2s ease;
}

.em-retry-state .em-retry-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.em-retry-state .em-retry-message {
  font-size: 13px;
  color: var(--loading-text);
  margin-bottom: 4px;
}

.em-retry-state .em-retry-attempt {
  font-size: 11px;
  color: var(--loading-text);
  opacity: 0.7;
  margin-bottom: 12px;
}

.em-retry-state .em-retry-btn {
  font-size: 13px;
  padding: 8px 20px;
  background: var(--loading-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.em-retry-state .em-retry-btn:hover {
  opacity: 0.9;
}

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

/* ─── H. Processing Overlay ────────────── */

.em-processing-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.em-processing-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.em-processing-overlay .em-processing-card {
  background: #fff;
  border-radius: 12px;
  padding: 32px 40px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
  text-align: center;
  max-width: 320px;
}

.em-processing-overlay .em-processing-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--loading-base);
  border-top-color: var(--loading-accent);
  border-radius: 50%;
  animation: eduumatch-spin 0.7s linear infinite;
  margin: 0 auto 16px;
}

.em-processing-overlay .em-processing-text {
  font-size: 14px;
  color: #1a2744;
  font-weight: 600;
  margin-bottom: 4px;
}

.em-processing-overlay .em-processing-hint {
  font-size: 12px;
  color: var(--loading-text);
}

/* ─── I. Inline Success Badge ───────────── */

.em-success-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #16a34a;
  animation: eduumatch-fade-in 0.2s ease;
}

.em-success-badge .em-success-check {
  font-size: 14px;
  font-weight: 700;
}

/* ─── J. Disabled State ────────────────── */

.em-disabled-wrapper {
  position: relative;
  display: inline-block;
}

.em-disabled-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: not-allowed;
}

.em-disabled-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a2744;
  color: #fff;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 2;
}

.em-disabled-overlay:hover + .em-disabled-tooltip,
.em-disabled-overlay:focus + .em-disabled-tooltip {
  opacity: 1;
}

/* ─── K. Spinner (standalone) ──────────── */

.em-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--loading-base);
  border-top-color: var(--loading-accent);
  border-radius: 50%;
  animation: eduumatch-spin 0.7s linear infinite;
}

.em-spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

/* ─── L. Transitions between content states ── */

.em-state-transition {
  animation: eduumatch-fade-in 0.2s ease;
}

.em-state-exit {
  animation: eduumatch-fade-out 0.15s ease forwards;
}

/* Ensure content hidden during skeleton load */
.em-content-hidden {
  display: none;
}

/* ─── Inline Error (for form fields) ────── */

.em-field-error {
  font-size: 11px;
  color: #dc2626;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.em-field-error::before {
  content: '✗';
  font-size: 10px;
}
