@charset "UTF-8";

/*
|--------------------------------------------------------------------------
| الملف: public_html/assets/css/shared/components/tables.css
| الوصف:
|   أنماط الجداول المشتركة في المنصة.
|
| الهدف:
|   - توحيد شكل الجداول العامة والإدارية.
|   - دعم الجداول القياسية، المدمجة، المخططة، ذات الحدود، والقابلة للتمرير.
|   - دعم حالات الصفوف، الأعمدة، العناوين، الفراغ، والتحميل.
|   - دعم responsive behavior للشاشات الصغيرة بشكل عملي واحترافي.
|
| القواعد:
|   - هذا الملف خاص بمكونات الجداول فقط.
|   - لا توضع فيه أنماط صفحات.
|   - لا توضع فيه أنماط layout عامة.
|   - يعتمد على tokens.css و base.css.
|--------------------------------------------------------------------------
*/

/* -------------------------------------------------------------------------
 * Table Wrapper
 * ---------------------------------------------------------------------- */
.table-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-xl);
}

.table-wrap--bordered {
  border: var(--border-width-1) solid var(--color-border-default);
  background-color: var(--color-bg-surface);
}

.table-wrap--shadow {
  box-shadow: var(--shadow-sm);
}

.table-wrap--sticky-header {
  max-height: 32rem;
  overflow: auto;
}

/* -------------------------------------------------------------------------
 * Base Table
 * ---------------------------------------------------------------------- */
.table {
  --table-local-bg: var(--color-bg-surface);
  --table-local-header-bg: var(--color-bg-surface-muted);
  --table-local-header-text: var(--color-text-primary);
  --table-local-text: var(--color-text-secondary);
  --table-local-border: var(--color-border-default);
  --table-local-row-hover: var(--color-gray-50);
  --table-local-row-stripe: rgba(148, 163, 184, 0.06);
  --table-local-cell-padding-x: var(--table-cell-padding-x);
  --table-local-cell-padding-y: var(--table-cell-padding-y);
  --table-local-row-height: var(--table-row-min-height);

  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  background-color: var(--table-local-bg);
}

.table caption {
  padding: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  text-align: start;
}

.table thead th {
  position: relative;
  min-height: var(--table-local-row-height);
  padding: var(--table-local-cell-padding-y) var(--table-local-cell-padding-x);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semi-bold);
  line-height: var(--line-height-snug);
  color: var(--table-local-header-text);
  text-align: start;
  vertical-align: middle;
  white-space: nowrap;
  background-color: var(--table-local-header-bg);
  border-bottom: var(--border-width-1) solid var(--table-local-border);
}

.table tbody td,
.table tfoot td,
.table tfoot th {
  min-height: var(--table-local-row-height);
  padding: var(--table-local-cell-padding-y) var(--table-local-cell-padding-x);
  color: var(--table-local-text);
  vertical-align: middle;
  border-bottom: var(--border-width-1) solid var(--table-local-border);
}

.table tbody th {
  min-height: var(--table-local-row-height);
  padding: var(--table-local-cell-padding-y) var(--table-local-cell-padding-x);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semi-bold);
  color: var(--color-text-primary);
  vertical-align: middle;
  border-bottom: var(--border-width-1) solid var(--table-local-border);
  background-color: transparent;
}

.table tfoot th {
  font-weight: var(--font-weight-semi-bold);
  color: var(--color-text-primary);
}

.table th,
.table td {
  text-align: start;
}

.table td > *:last-child,
.table th > *:last-child {
  margin-bottom: 0;
}

/* -------------------------------------------------------------------------
 * Variants
 * ---------------------------------------------------------------------- */
.table--compact {
  --table-local-cell-padding-x: var(--table-cell-padding-x-sm);
  --table-local-cell-padding-y: var(--table-cell-padding-y-sm);
  --table-local-row-height: 2.75rem;
}

.table--comfortable {
  --table-local-cell-padding-x: var(--table-cell-padding-x);
  --table-local-cell-padding-y: var(--table-cell-padding-y);
  --table-local-row-height: var(--table-row-min-height);
}

.table--spacious {
  --table-local-cell-padding-x: var(--space-5);
  --table-local-cell-padding-y: var(--space-4);
  --table-local-row-height: 4rem;
}

.table--striped tbody tr:nth-child(even) {
  background-color: var(--table-local-row-stripe);
}

.table--hover tbody tr:hover {
  background-color: var(--table-local-row-hover);
}

.table--bordered {
  border: var(--border-width-1) solid var(--table-local-border);
}

.table--bordered th,
.table--bordered td {
  border-inline-end: var(--border-width-1) solid var(--table-local-border);
}

.table--bordered tr > *:last-child {
  border-inline-end: 0;
}

.table--borderless,
.table--borderless th,
.table--borderless td {
  border: 0;
}

.table--headless thead {
  display: none;
}

.table--fixed {
  table-layout: fixed;
}

.table--auto {
  table-layout: auto;
}

/* -------------------------------------------------------------------------
 * Sticky Header
 * ---------------------------------------------------------------------- */
.table-wrap--sticky-header .table thead th,
.table--sticky thead th {
  position: sticky;
  top: 0;
  z-index: var(--z-index-sticky);
  background-color: var(--table-local-header-bg);
}

/* -------------------------------------------------------------------------
 * Column Helpers
 * ---------------------------------------------------------------------- */
.table__col--fit {
  width: 1%;
  white-space: nowrap;
}

.table__col--truncate {
  max-width: 1px;
}

.table__cell--truncate,
.table__col--truncate {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.table__cell--nowrap {
  white-space: nowrap;
}

.table__cell--wrap {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.table__cell--muted {
  color: var(--color-text-muted);
}

.table__cell--strong {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semi-bold);
}

.table__cell--numeric {
  font-variant-numeric: tabular-nums;
}

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

.table__cell--end,
.table__head--end {
  text-align: end;
}

/* -------------------------------------------------------------------------
 * Row States
 * ---------------------------------------------------------------------- */
.table__row--selected {
  background-color: var(--color-brand-50);
}

.table__row--success {
  background-color: rgba(18, 183, 106, 0.08);
}

.table__row--warning {
  background-color: rgba(247, 144, 9, 0.08);
}

.table__row--danger,
.table__row--error {
  background-color: rgba(240, 68, 56, 0.08);
}

.table__row--info {
  background-color: rgba(46, 144, 250, 0.08);
}

.table__row--disabled {
  opacity: var(--opacity-disabled);
}

/* -------------------------------------------------------------------------
 * Sortable Header
 * ---------------------------------------------------------------------- */
.table-sort {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
  padding: 0;
  color: inherit;
  font: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.table-sort:hover {
  color: var(--color-text-primary);
}

.table-sort:focus-visible {
  outline: none;
  box-shadow: 0 0 0 var(--focus-ring-width) var(--focus-ring-color);
  border-radius: var(--radius-sm);
}

.table-sort__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.875rem;
  height: 0.875rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.table-sort.is-active {
  color: var(--color-text-primary);
}

.table-sort.is-active .table-sort__icon {
  color: var(--color-brand-600);
}

/* -------------------------------------------------------------------------
 * Selection / Actions Cells
 * ---------------------------------------------------------------------- */
.table-select-cell,
.table-actions-cell {
  white-space: nowrap;
}

.table-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.table-actions--start {
  justify-content: flex-start;
}

.table-actions--center {
  justify-content: center;
}

/* -------------------------------------------------------------------------
 * Media / Meta in Cells
 * ---------------------------------------------------------------------- */
.table-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.table-item__media {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  overflow: hidden;
  background-color: var(--color-bg-surface-muted);
  border-radius: var(--radius-lg);
  flex-shrink: 0;
}

.table-item__media img,
.table-item__media svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.table-item__content {
  min-width: 0;
  flex: 1 1 auto;
}

.table-item__title {
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semi-bold);
  line-height: var(--line-height-snug);
}

.table-item__meta {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-snug);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* -------------------------------------------------------------------------
 * Empty / Loading / Summary States
 * ---------------------------------------------------------------------- */
.table-empty-row td,
.table-loading-row td,
.table-summary-row td,
.table-summary-row th {
  padding-top: var(--space-6);
  padding-bottom: var(--space-6);
}

.table-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
}

.table-empty__title {
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semi-bold);
}

.table-empty__text {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.table-summary-row {
  background-color: var(--color-bg-surface-muted);
}

.table-summary-row th,
.table-summary-row td {
  font-weight: var(--font-weight-semi-bold);
  color: var(--color-text-primary);
}

/* -------------------------------------------------------------------------
 * Skeleton Loading
 * ---------------------------------------------------------------------- */
.table-skeleton {
  display: inline-block;
  width: 100%;
  height: 0.875rem;
  background:
    linear-gradient(
      90deg,
      rgba(148, 163, 184, 0.14) 25%,
      rgba(148, 163, 184, 0.24) 37%,
      rgba(148, 163, 184, 0.14) 63%
    );
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: table-skeleton-shimmer 1.4s ease-in-out infinite;
}

.table-skeleton--sm {
  height: 0.75rem;
  max-width: 6rem;
}

.table-skeleton--md {
  height: 0.875rem;
  max-width: 10rem;
}

.table-skeleton--lg {
  height: 1rem;
  max-width: 14rem;
}

/* -------------------------------------------------------------------------
 * Responsive Card Table
 * ---------------------------------------------------------------------- */
.table-responsive-cards {
  width: 100%;
}

@media (max-width: 767.98px) {
  .table-responsive-cards .table,
  .table-responsive-cards .table thead,
  .table-responsive-cards .table tbody,
  .table-responsive-cards .table tfoot,
  .table-responsive-cards .table tr,
  .table-responsive-cards .table th,
  .table-responsive-cards .table td {
    display: block;
    width: 100%;
  }

  .table-responsive-cards .table thead {
    display: none;
  }

  .table-responsive-cards .table tbody tr {
    margin-bottom: var(--space-4);
    overflow: hidden;
    background-color: var(--color-bg-surface);
    border: var(--border-width-1) solid var(--color-border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xs);
  }

  .table-responsive-cards .table tbody td,
  .table-responsive-cards .table tbody th {
    display: grid;
    grid-template-columns: minmax(6rem, 40%) 1fr;
    gap: var(--space-3);
    align-items: start;
    min-height: 0;
    padding: var(--space-3) var(--space-4);
    text-align: start;
    border-bottom: var(--border-width-1) solid var(--color-border-soft);
  }

  .table-responsive-cards .table tbody tr > *:last-child {
    border-bottom: 0;
  }

  .table-responsive-cards .table td::before,
  .table-responsive-cards .table th::before {
    content: attr(data-label);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semi-bold);
    line-height: var(--line-height-snug);
  }

  .table-responsive-cards .table__cell--end,
  .table-responsive-cards .table__head--end,
  .table-responsive-cards .table__cell--center,
  .table-responsive-cards .table__head--center {
    text-align: start;
  }

  .table-responsive-cards .table-actions {
    justify-content: flex-start;
  }
}

/* -------------------------------------------------------------------------
 * Generic Mobile Refinements
 * ---------------------------------------------------------------------- */
@media (max-width: 767.98px) {
  .table-wrap {
    border-radius: var(--radius-lg);
  }

  .table:not(.table--headless) thead th {
    font-size: var(--font-size-xs);
  }

  .table tbody td,
  .table tbody th,
  .table tfoot td,
  .table tfoot th {
    font-size: var(--font-size-sm);
  }

  .table-item {
    gap: var(--space-2);
  }

  .table-item__media {
    width: 2.25rem;
    height: 2.25rem;
  }
}

/* -------------------------------------------------------------------------
 * Desktop Enhancements
 * ---------------------------------------------------------------------- */
@media (min-width: 1024px) {
  .table--hover tbody tr:hover {
    transition: background-color var(--duration-fast) var(--easing-in-out);
  }
}

/* -------------------------------------------------------------------------
 * Reduced Motion
 * ---------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .table-skeleton {
    animation: none !important;
  }
}

/* -------------------------------------------------------------------------
 * Keyframes
 * ---------------------------------------------------------------------- */
@keyframes table-skeleton-shimmer {
  0% {
    background-position: 100% 0;
  }

  100% {
    background-position: 0 0;
  }
}