/* components.css */
/* Reusable atomic components: cards, tables, badges, modals, toasts, forms and skeletons. */

/* Button Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-xl);
  font-size: var(--font-size-sm);
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.btn:active {
  transform: scale(0.98);
}

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

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

.btn--secondary {
  background-color: var(--color-border);
  color: var(--color-text-primary);
}

.btn--secondary:hover {
  background-color: rgba(51, 65, 85, 0.8);
}

/* Badge Components */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xxs) var(--spacing-sm);
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-radius: var(--radius-full);

  /* Critical: Arabic text must NEVER wrap between characters.
     white-space: nowrap keeps the whole label on one line.
     min-width reserves space for the longest Arabic label (قيد المعالجة).
     width: max-content allows the badge to grow naturally beyond min-width. */
  white-space: nowrap;
  min-width: 90px;
  width: max-content;
}

.status--new {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--color-status-new);
}

.status--in-progress {
  background-color: rgba(14, 165, 233, 0.15);
  color: var(--color-status-in-progress);
}

.status--resolved {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--color-status-resolved);
}

.status--rejected {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--color-status-rejected);
}

.status--closed {
  background-color: rgba(100, 116, 139, 0.15);
  color: var(--color-status-closed);
}

/* Status column in data tables: reserve minimum width so the column
   is never squeezed narrow enough to force badge text to wrap.
   Apply this class to <th> and <td> elements in the Status column. */
.table__col--status {
  white-space: nowrap;
  min-width: 110px;
  width: 110px;
}

/* Data Table Components */
.table-container {
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  overflow-x: auto;
  box-shadow: var(--shadow-md);
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: right; /* RTL Default alignment */
}

.table th, .table td {
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--color-border-light);
}

.table th {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  background-color: rgba(15, 23, 42, 0.3);
  user-select: none;
}

.table__header--sortable {
  cursor: pointer;
}

.table__header--sortable:hover {
  color: var(--color-text-primary);
  background-color: rgba(15, 23, 42, 0.5);
}

.table__sort-indicator {
  margin-right: var(--spacing-xxs);
  font-size: var(--font-size-xs);
}

.table__sort-indicator--inactive {
  opacity: 0.3;
}

.table__row {
  transition: background-color var(--transition-fast);
  cursor: pointer;
}

.table__row:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.table__cell--align-center {
  text-align: center;
}

.table__empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xxl) 0;
  gap: var(--spacing-sm);
}

.table__empty-icon {
  font-size: var(--font-size-xxl);
}

.table__empty-text {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

/* Modal Dialog Components */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--spacing-md);
  opacity: 1;
  transition: opacity var(--transition-normal);
}

.modal {
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
  transform: translateY(0);
}

.modal__header {
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal__title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text-primary);
}

.modal__close-btn {
  font-size: var(--font-size-lg);
  color: var(--color-text-secondary);
  transition: color var(--transition-fast);
}

.modal__close-btn:hover {
  color: var(--color-text-primary);
}

.modal__body {
  padding: var(--spacing-lg);
  overflow-y: auto;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.modal__footer {
  padding: var(--spacing-md) var(--spacing-lg);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--spacing-sm);
  justify-content: flex-start;
}

.body--no-scroll {
  overflow: hidden;
}

/* Toast Notification Components */
.toast-container {
  position: fixed;
  bottom: 80px; /* Space above mobile bottom nav */
  left: var(--spacing-xl);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  z-index: 300;
  max-width: 400px;
  width: calc(100% - 48px);
}

@media (min-width: 768px) {
  .toast-container {
    bottom: var(--spacing-xl);
    left: var(--spacing-xl);
  }
}

.toast {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--spacing-md) var(--spacing-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-md);
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  opacity: 0;
  transition: transform var(--transition-normal), opacity var(--transition-normal);
}

.toast--show {
  transform: translateY(0);
  opacity: 1;
}

.toast--hide {
  transform: translateY(-20px);
  opacity: 0;
}

.toast__content {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  font-size: var(--font-size-sm);
  font-weight: 500;
}

.toast__close-btn {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.toast__close-btn:hover {
  color: var(--color-text-primary);
}

.toast--success {
  border-right: 4px solid var(--color-status-resolved);
}

.toast--error {
  border-right: 4px solid var(--color-status-rejected);
}

.toast--warning {
  border-right: 4px solid var(--color-status-new);
}

.toast--info {
  border-right: 4px solid var(--color-primary);
}

/* Loading Skeleton Shimmers */
.skeleton-shimmer {
  background: linear-gradient(
    90deg,
    #1e293b 25%,
    #334155 37%,
    #1e293b 63%
  );
  background-size: 400% 100%;
  animation: shimmer-anim 1.4s ease infinite;
  border-radius: var(--radius-xs);
}

@keyframes shimmer-anim {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.loader-skeleton {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.loader-skeleton__header {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.skeleton-shimmer--title {
  height: 24px;
  width: 150px;
}

.skeleton-shimmer--subtitle {
  height: 16px;
  width: 250px;
}

.skeleton-shimmer--paragraph {
  height: 14px;
  width: 100%;
}

.table__skeleton-cell {
  height: 20px;
  width: 100%;
}

/* Full Page Loader Spinner */
.fullpage-loader {
  position: fixed;
  inset: 0;
  background-color: rgba(11, 17, 32, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.fullpage-loader--active {
  opacity: 1;
  pointer-events: auto;
}

.fullpage-loader__spinner-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-md);
}

.fullpage-loader__spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--color-border);
  border-top: 4px solid var(--color-primary);
  border-radius: 50%;
  animation: spinner-spin 0.8s linear infinite;
}

.fullpage-loader__text {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
}

@keyframes spinner-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Form inputs & controls */
.form-group {
  margin-bottom: var(--spacing-lg);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
}

.form-control {
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--spacing-sm);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  width: 100%;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.form-control:disabled {
  background-color: rgba(255, 255, 255, 0.02);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

/* Empty State Widget */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--spacing-xxl) var(--spacing-md);
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  max-width: 500px;
  margin: 0 auto;
  gap: var(--spacing-md);
}

.empty-state__icon {
  font-size: 3rem;
}

.empty-state__title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-primary);
}

.empty-state__description {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  max-width: 320px;
  margin-bottom: var(--spacing-xs);
}

/* ====================================================================
   RESPONSIVE COMPONENT OVERRIDES — MOBILE FIRST
   ==================================================================== */

/* ── Table: graceful mobile degradation ─────────────────────────── */
/*
   The table-container already has overflow-x: auto which allows
   horizontal scroll within the card. On very small screens we add
   -webkit-overflow-scrolling for momentum scrolling on iOS and reduce
   cell padding so columns are less cramped.
*/
@media (max-width: 767px) {
  .table-container {
    -webkit-overflow-scrolling: touch;
    /* Ensure the card itself never exceeds viewport */
    max-width: 100%;
  }

  .table th,
  .table td {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-xs);
    /* Allow long words to break rather than stretch columns */
    word-break: break-word;
    hyphens: auto;
  }

  .table th {
    white-space: nowrap; /* Headers stay on one line — easier to scan */
  }
}

/* ── Modal: full-screen on narrow viewports ─────────────────────── */
@media (max-width: 480px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 90vh;
  }

  .modal__footer {
    flex-direction: column;
  }

  .modal__footer .btn {
    width: 100%;
  }
}

/* ── Toast: repositioned to clear mobile bottom nav ─────────────── */
@media (max-width: 767px) {
  .toast-container {
    /* Already at bottom: 80px in the base rule — this just ensures
       it doesn't exceed viewport width on very narrow phones */
    left: var(--spacing-sm);
    right: var(--spacing-sm);
    width: auto;
    max-width: none;
  }
}

/* ── Form controls: adequate touch targets ───────────────────────── */
.form-control {
  /* Inputs and selects must be at least 44px tall for touch */
  min-height: 44px;
}

textarea.form-control {
  /* Textareas override the 44px min-height — their rows= attribute controls height */
  min-height: auto;
}

/* ── Buttons: block-level on narrow screens where relevant ──────── */
@media (max-width: 480px) {
  .modal__footer .btn,
  .detail-actions .btn {
    min-height: 48px; /* Slightly larger for primary action buttons */
  }
}

/* ── Empty state: full width on mobile ──────────────────────────── */
@media (max-width: 767px) {
  .empty-state {
    max-width: 100%;
    padding: var(--spacing-xl) var(--spacing-md);
  }
}

