/* Custom CSS Variables */
:root {
  --primary: #2563eb;
  --secondary: #3b82f6;
  --accent: #0ea5e9;
  --brand: #10b981;
  /* emerald-500 */
  --brand-hover: #059669;
  /* emerald-600 */
  --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;
}

/* === Performance Optimizations === */
* {
  -webkit-tap-highlight-color: transparent;
}

.fixed {
  transform: translateZ(0);
  will-change: transform, opacity;
}

.overflow-y-auto,
.overflow-x-auto {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  transform: translateZ(0);
}

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;
}

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;
}

.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-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: 0.875rem;
  transition: all var(--transition-speed) var(--transition-timing);
  background-color: white;
}

.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(15px);
  }

  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;
}

@media (max-width: 767px) {
  #sidebar {
    width: 256px;
  }
}

/* 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 Animation */
#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 */
/* === Responsive Tables for Production === */
@media (max-width: 768px) {
  .overflow-x-auto {
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
  }
  
  table thead {
    display: none;
  }
  
  table tr {
    display: block;
    margin-bottom: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    padding: 0.5rem;
    background: white;
  }
  
  table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0.5rem !important;
    border-bottom: 1px solid #f1f5f9;
    text-align: left;
  }
  
  table td:last-child {
    border-bottom: none;
    justify-content: center;
    gap: 1rem;
  }
  
  table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.825rem;
    margin-left: 1rem;
  }
}

.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 Animation ========== */
.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);
  }
}

/* ========== MOBILE RESPONSIVE STYLES ========== */

/* Tables to Cards on Mobile */
@media (max-width: 768px) {

  /* Hide table headers on mobile */
  .responsive-table thead {
    display: none;
  }

  /* Convert table rows to cards */
  .responsive-table tbody tr {
    display: block;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    margin-bottom: 1rem;
    padding: 1rem;
    border: 1px solid #e2e8f0;
  }

  .responsive-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border: none;
    border-bottom: 1px solid #f1f5f9;
  }

  .responsive-table tbody td:last-child {
    border-bottom: none;
  }

  /* Show data labels on mobile */
  .responsive-table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-left: 1rem;
  }

  /* Action buttons in cards */
  .responsive-table tbody td:last-child {
    justify-content: center;
    padding-top: 1rem;
  }

  /* Collapsible filters */
  .filters-collapsible {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
  }

  .filters-collapsible.expanded {
    max-height: 500px;
  }

  /* Filter toggle button */
  .filter-toggle-btn {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 0.5rem;
  }

  .filter-toggle-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
  }

  /* Smaller modal padding on mobile */
  .modal-content {
    padding: 1rem;
    max-height: 90vh;
  }

  /* Buttons stack on mobile */
  .btn-group-mobile {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .btn-group-mobile .btn {
    width: 100%;
  }

  /* Filter grid on mobile */
  .filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  /* Cards padding on mobile */
  .card-mobile {
    padding: 1rem;
  }

  /* Stats cards responsive */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .btn {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
  }

  .form-input {
    font-size: 16px;
    /* Prevents zoom on iOS */
  }
}

/* Wizard/Stepper styles for long modals */
.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;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* SweetAlert2 RTL support */
.swal2-rtl {
  direction: rtl;
}

.swal2-popup {
  font-family: 'Cairo', system-ui, sans-serif !important;
}