/* ====== Custom CSS Variables ====== */
:root {
  --primary: #2563eb;
  --secondary: #3b82f6;
  --accent: #0ea5e9;
  --brand: #10b981;
  --brand-hover: #059669;
  --bg-light: #f8fafc;
  --bg-white: #FFFFFF;
  --text-dark: #0f172a;
  --text-muted: #475569;
  --radius: 0.75rem;
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --transition-speed: 0.3s;
  --transition-timing: ease-in-out;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --bottom-nav-height: 0px;
}

/* ====== PWA Install Banner ====== */
.pwa-install-banner {
  position: fixed;
  bottom: 80px;
  left: 1rem;
  right: 1rem;
  z-index: 9999;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(12px);
  border-radius: 1rem;
  padding: 0.875rem 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.05);
  animation: slideUpBanner 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUpBanner {
  from {
    transform: translateY(100%);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (min-width: 768px) {
  .pwa-install-banner {
    bottom: 1.5rem;
    left: auto;
    right: 1.5rem;
    max-width: 360px;
  }
}

/* ====== Performance Optimizations ====== */
* {
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

.fixed {
  transform: translateZ(0);
  will-change: transform, opacity;
}

/* للحاويات ذات التمرير العمودي */
.overflow-y-auto {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  transform: translateZ(0);
}

/* للحاويات ذات التمرير الأفقي (مثل الجداول) */
.overflow-x-auto {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  transform: translateZ(0);
}

/* ====== Base Layout ====== */
html {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  height: 100%;
  width: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior-y: none;
  font-family: 'Cairo', system-ui, sans-serif;
  color: var(--text-dark);
  background-color: var(--bg-light);
  -webkit-font-smoothing: antialiased;
  margin: 0;
  padding: 0;
  padding-bottom: var(--bottom-nav-height);
}

/* Touch-friendly interactive elements */
a,
button,
input,
select,
textarea,
[role="button"] {
  touch-action: manipulation;
}

.content-visibility-auto {
  content-visibility: auto;
  contain-intrinsic-size: 1px 500px;
}

.gradient-text {
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ====== Buttons ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: var(--radius);
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition-speed) var(--transition-timing);
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 0.875rem;
  min-height: 44px;
  /* Touch-friendly minimum */
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  background: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  background-color: var(--bg-white);
  color: var(--text-dark);
  border-color: #e2e8f0;
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
  background-color: #f8fafc;
}

.btn-brand {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-md);
}

.btn-brand:hover {
  background: var(--brand-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

/* ====== Form Inputs ====== */
.form-input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  font-size: 1rem;
  /* 16px prevents iOS zoom */
  transition: all var(--transition-speed) var(--transition-timing);
  background-color: white;
  min-height: 44px;
  /* Touch-friendly */
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input:disabled {
  background-color: #f9fafb;
  color: #6b7280;
  cursor: not-allowed;
}

/* ====== Status Badges ====== */
.status-available {
  background-color: #dcfce7;
  color: #166534;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-pending {
  background-color: #fef3c7;
  color: #92400e;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-completed {
  background-color: #dbeafe;
  color: #1e40af;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

/* ====== Animations ====== */
@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.6s var(--transition-timing) forwards;
  opacity: 0;
}

.animate-fadeIn {
  animation: fadeIn 0.3s ease-out forwards;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0);
  }
}

/* ====== Scrollbar ====== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ====== Toast Container ====== */
#toast-container>div {
  animation: slideInRight 0.3s ease-out forwards;
}

/* ====== Glassmorphism Cards ====== */
.glass-card {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

/* ====== Table Header ====== */
.table-header {
  padding: 0.75rem 1rem;
  text-align: right;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background-color: #f9fafb;
}

/* ====== Skeleton Loading ====== */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite ease-in-out;
  border-radius: 6px;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
}

.skeleton-text-sm {
  height: 0.75rem;
  margin-bottom: 0.25rem;
}

.skeleton-title {
  height: 1.5rem;
  width: 60%;
  margin-bottom: 1rem;
}

.skeleton-card {
  height: 100px;
  border-radius: 12px;
}

.skeleton-row {
  height: 3rem;
  margin-bottom: 0.5rem;
  border-radius: 8px;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton-stat {
  height: 2.5rem;
  width: 60%;
}

.skeleton-header {
  height: 8rem;
  border-radius: 16px;
}

.skeleton-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
}

/* ====== Pending Item Indicator ====== */
.item-pending {
  opacity: 0.7;
  position: relative;
}

.item-pending::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0.5rem;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  background: #fbbf24;
  border-radius: 50%;
  animation: pulse 1s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }

  50% {
    opacity: 0.5;
    transform: translateY(-50%) scale(0.8);
  }
}

/* ====== Wizard/Stepper Styles ====== */
.wizard-steps {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.wizard-step {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  background: #e2e8f0;
  color: #64748b;
  transition: all 0.3s ease;
}

.wizard-step.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
}

.wizard-step.completed {
  background: var(--brand);
  color: white;
}

.wizard-content {
  display: none;
}

.wizard-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

/* ====== SweetAlert2 RTL ====== */
.swal2-rtl {
  direction: rtl;
}

.swal2-popup {
  font-family: 'Cairo', system-ui, sans-serif !important;
}

/* ====== Bottom Navigation Bar ====== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: white;
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  z-index: 40;
  align-items: stretch;
  justify-content: space-around;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 2px;
  padding: 6px 0;
  color: #94a3b8;
  font-size: 0.65rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.2s;
  cursor: pointer;
  border: none;
  background: none;
  min-height: 44px;
}

.bottom-nav-item.active {
  color: var(--primary);
}

.bottom-nav-item i {
  width: 22px;
  height: 22px;
}

/* ============================================================
   MOBILE RESPONSIVE STYLES (max-width: 768px)
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --bottom-nav-height: calc(60px + var(--safe-bottom));
  }

  /* --- Sidebar --- */
  #sidebar {
    width: 280px;
    padding-top: calc(0.5rem + var(--safe-top));
    padding-bottom: calc(1rem + var(--bottom-nav-height));
  }

  #sidebar .space-y-2 li a,
  #sidebar .space-y-2 li button {
    min-height: 48px;
    font-size: 0.95rem;
  }

  /* --- Main Content Area --- */
  main {
    padding: 0.75rem !important;
    padding-bottom: calc(0.75rem + var(--bottom-nav-height)) !important;
    margin-right: 0 !important;
  }

  #page-content {
    padding: 0.75rem !important;
    border-radius: 0.75rem;
    touch-action: pan-y;
    overscroll-behavior-y: auto;
  }

  /* --- Page Title & Actions --- */
  #page-title {
    font-size: 1.25rem !important;
  }

  #page-actions {
    display: none;
    /* Actions moved to FAB on mobile */
  }

  /* --- Filter Panel Mobile --- */
  .mobile-filter-panel {
    background: white;
    border-radius: var(--radius);
    border: 1px solid #e2e8f0;
    overflow: hidden;
  }

  .mobile-filter-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem;
    background: #f8fafc;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    font-family: inherit;
    min-height: 44px;
  }

  .mobile-filter-toggle i {
    transition: transform 0.3s;
  }

  .mobile-filter-toggle.expanded i {
    transform: rotate(180deg);
  }

  .mobile-filter-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease-out;
    padding: 0 0.75rem;
  }

  .mobile-filter-body.expanded {
    max-height: 2000px;
    padding: 0.75rem;
  }

  .mobile-filter-body .grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
  }

  .mobile-filter-body .md\:col-span-2 {
    grid-column: span 2;
  }

  /* --- Tables → Cards on Mobile --- */
  table {
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch;
  }

  table thead {
    display: none !important;
  }

  table tbody {
    touch-action: pan-y !important;
  }

  table tbody tr {
    display: block;
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    border: 1px solid #e5e7eb;
    touch-action: pan-y !important;
  }

  table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.25rem !important;
    border: none;
    border-bottom: 1px solid #f3f4f6;
    text-align: left;
    font-size: 0.85rem;
  }

  table tbody td:last-child {
    border-bottom: none;
    justify-content: center;
    gap: 1rem;
    padding-top: 0.75rem !important;
  }

  table tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: 0.75rem;
    flex-shrink: 0;
    max-width: 40%;
  }

  /* --- Modals Full-screen on Mobile --- */
  #modal-overlay {
    padding: 0 !important;
    align-items: flex-end !important;
  }

  #modal-overlay>div {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 95vh !important;
    border-radius: 1rem 1rem 0 0 !important;
    animation: slideUp 0.3s ease-out;
  }

  #modal-overlay>div>div:last-child {
    padding: 1rem !important;
  }

  /* Modal form grids */
  #modal-overlay .grid {
    grid-template-columns: 1fr !important;
  }

  #modal-overlay .md\:grid-cols-2,
  #modal-overlay .md\:grid-cols-3 {
    grid-template-columns: 1fr !important;
  }

  /* --- Dashboard Cards --- */
  .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
  }

  .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4>div {
    padding: 0.75rem !important;
    flex-direction: column;
    text-align: center;
    gap: 0.25rem !important;
  }

  .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4 i {
    width: 28px !important;
    height: 28px !important;
  }

  .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4 .text-3xl {
    font-size: 1.5rem !important;
  }

  .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4 .text-lg {
    font-size: 0.75rem !important;
  }

  /* --- Action Buttons responsive --- */
  .btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }

  .btn i {
    width: 16px !important;
    height: 16px !important;
  }

  /* --- Pagination Mobile --- */
  .flex.items-center.justify-between.mt-4 {
    flex-direction: column;
    gap: 0.5rem;
  }

  /* --- FAB visible on mobile --- */
  .fab {
    display: flex;
  }

  /* --- Bottom Nav visible on mobile --- */
  .bottom-nav {
    display: flex;
  }

  /* --- Toast position for mobile --- */
  #toast-container {
    bottom: calc(70px + var(--safe-bottom)) !important;
    right: 0.5rem !important;
    left: 0.5rem !important;
  }

  /* --- Grid fixes for trainee file stats --- */
  .grid.grid-cols-2.md\:grid-cols-4 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
  }

  /* --- Confirmation Dialog Mobile --- */
  .confirm-dialog {
    width: calc(100% - 2rem) !important;
    max-width: 100% !important;
  }
}

/* ====== Extra Small Screens (≤ 480px) ====== */
@media (max-width: 480px) {
  .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4 {
    grid-template-columns: 1fr !important;
  }

  .mobile-filter-body .grid {
    grid-template-columns: 1fr !important;
  }

  .mobile-filter-body .md\:col-span-2 {
    grid-column: span 1;
  }
}

/* ====== Print Styles ====== */
@media print {

  .bottom-nav,
  .fab,
  #sidebar,
  #sidebar-overlay,
  #toast-container,
  #loading-bar {
    display: none !important;
  }

  main {
    margin: 0 !important;
    padding: 0 !important;
  }
}