/**
 * Sneat V2 — Phase 0: tables & DataTables (Sneat-native surfaces)
 * Targets list pages via .bb-v2-table-card and legacy .box fallbacks.
 */

/* ——— Shared table surface ——— */
body.bb-theme-v2 .bb-v2-table-card__body .table-responsive,
body.bb-theme-v2 section.content .box .table-responsive {
  border: 1px solid var(--bb-v2-border);
  border-radius: var(--bb-v2-radius);
  background: var(--bb-v2-surface);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

body.bb-theme-v2 .bb-v2-table-card__body table.table,
body.bb-theme-v2 .bb-v2-table-card__body table.dataTable,
body.bb-theme-v2 .bb-sn-data-card__table-wrap table.table,
body.bb-theme-v2 .bb-sn-data-card__table-wrap table.dataTable,
body.bb-theme-v2 section.content .box .table,
body.bb-theme-v2 section.content .box table.dataTable {
  width: 100% !important;
  margin: 0 !important;
  border-collapse: separate !important;
  border-spacing: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  background: var(--bb-v2-surface) !important;
  color: var(--bb-v2-text);
}

body.bb-theme-v2 .bb-v2-table-card__body table thead th,
body.bb-theme-v2 .bb-sn-data-card__table-wrap table thead th,
body.bb-theme-v2 section.content .box table thead th,
body.bb-theme-v2 table.dataTable thead th {
  background: #f8f8fb !important;
  color: var(--bb-v2-text-strong) !important;
  font-weight: 600 !important;
  font-size: 0.8125rem !important;
  letter-spacing: normal;
  text-transform: none;
  padding: 0.75rem 0.9rem !important;
  padding-inline-end: 1.65rem !important;
  border: 0 !important;
  border-bottom: 1px solid var(--bb-v2-border) !important;
  vertical-align: middle !important;
  white-space: nowrap;
  text-align: start;
  position: relative;
  line-height: 1.35;
}

/* عمود الإجراءات / checkbox — بدون مساحة أيقونة ترتيب */
body.bb-theme-v2 table.dataTable thead th.sorting_disabled,
body.bb-theme-v2 table.dataTable thead th.no-sort,
body.bb-theme-v2 table.dataTable thead th:first-child:has(input[type="checkbox"]) {
  padding-inline-end: 0.9rem !important;
}

body.bb-theme-v2 .bb-v2-table-card__body table tbody td,
body.bb-theme-v2 section.content .box table tbody td,
body.bb-theme-v2 table.dataTable tbody td {
  padding: 0.72rem 0.9rem !important;
  vertical-align: middle !important;
  border: 0 !important;
  border-bottom: 1px solid #eff1f4 !important;
  color: var(--bb-v2-text) !important;
  background: var(--bb-v2-surface) !important;
}

body.bb-theme-v2 .bb-v2-table-card__body table tbody tr:last-child td,
body.bb-theme-v2 section.content .box table tbody tr:last-child td,
body.bb-theme-v2 table.dataTable tbody tr:last-child td {
  border-bottom: 0 !important;
}

body.bb-theme-v2 .bb-v2-table-card__body table tbody tr:hover td,
body.bb-theme-v2 section.content .box table tbody tr:hover td,
body.bb-theme-v2 table.dataTable tbody tr:hover td {
  background: #f9f9ff !important;
}

body.bb-theme-v2 .bb-v2-table-card__body table.table-striped > tbody > tr:nth-of-type(odd) > td,
body.bb-theme-v2 section.content .box table.table-striped > tbody > tr:nth-of-type(odd) > td,
body.bb-theme-v2 table.dataTable.table-striped > tbody > tr:nth-of-type(odd) > td {
  background: #fcfcfd !important;
}

body.bb-theme-v2 .bb-v2-table-card__body table.table-striped > tbody > tr:nth-of-type(odd):hover > td,
body.bb-theme-v2 table.dataTable.table-striped > tbody > tr:nth-of-type(odd):hover > td {
  background: #f9f9ff !important;
}

body.bb-theme-v2 .bb-v2-table-card__body table.table-bordered > thead > tr > th,
body.bb-theme-v2 .bb-v2-table-card__body table.table-bordered > tbody > tr > td,
body.bb-theme-v2 table.dataTable.table-bordered > thead > tr > th,
body.bb-theme-v2 table.dataTable.table-bordered > tbody > tr > td {
  border-color: var(--bb-v2-border) !important;
}

body.bb-theme-v2 table.dataTable tbody tr.selected td,
body.bb-theme-v2 table.dataTable tbody tr.selected:hover td {
  background: var(--bb-v2-primary-soft) !important;
  color: var(--bb-v2-text-strong) !important;
}

/* Sorting — إلغاء أيقونات DataTables الافتراضية (::before + ::after + background) */
body.bb-theme-v2 table.dataTable thead th.sorting,
body.bb-theme-v2 table.dataTable thead th.sorting_asc,
body.bb-theme-v2 table.dataTable thead th.sorting_desc,
body.bb-theme-v2 table.dataTable thead th.sorting_asc_disabled,
body.bb-theme-v2 table.dataTable thead th.sorting_desc_disabled {
  background-image: none !important;
  background-position: center !important;
  cursor: pointer;
  padding-inline-end: 1.65rem !important;
}

body.bb-theme-v2 table.dataTable thead th.sorting::before,
body.bb-theme-v2 table.dataTable thead th.sorting::after,
body.bb-theme-v2 table.dataTable thead th.sorting_asc::before,
body.bb-theme-v2 table.dataTable thead th.sorting_asc::after,
body.bb-theme-v2 table.dataTable thead th.sorting_desc::before,
body.bb-theme-v2 table.dataTable thead th.sorting_desc::after,
body.bb-theme-v2 table.dataTable thead th.sorting_asc_disabled::before,
body.bb-theme-v2 table.dataTable thead th.sorting_asc_disabled::after,
body.bb-theme-v2 table.dataTable thead th.sorting_desc_disabled::before,
body.bb-theme-v2 table.dataTable thead th.sorting_desc_disabled::after {
  content: none !important;
  display: none !important;
  opacity: 0 !important;
  width: 0 !important;
  height: 0 !important;
  border: 0 !important;
  background: none !important;
  position: absolute !important;
  bottom: auto !important;
  left: auto !important;
  right: auto !important;
}

/* أيقونة ترتيب Sneat واحدة — بعيدة عن النص (مناسبة RTL/LTR) */
body.bb-theme-v2 table.dataTable thead th.sorting::after,
body.bb-theme-v2 table.dataTable thead th.sorting_asc::after,
body.bb-theme-v2 table.dataTable thead th.sorting_desc::after {
  content: "" !important;
  display: block !important;
  position: absolute !important;
  top: 50% !important;
  inset-inline-end: 0.55rem !important;
  inset-inline-start: auto !important;
  margin: 0 !important;
  width: 0.35rem !important;
  height: 0.35rem !important;
  border: 0 !important;
  border-inline-end: 2px solid var(--bb-v2-muted) !important;
  border-block-end: 2px solid var(--bb-v2-muted) !important;
  opacity: 0.5;
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

body.bb-theme-v2 table.dataTable thead th.sorting_asc::after {
  transform: translateY(-35%) rotate(-135deg);
  opacity: 1;
  border-color: var(--bb-v2-primary) !important;
}

body.bb-theme-v2 table.dataTable thead th.sorting_desc::after {
  transform: translateY(-65%) rotate(45deg);
  opacity: 1;
  border-color: var(--bb-v2-primary) !important;
}

/* ——— DataTables chrome ——— */
body.bb-theme-v2 .bb-v2-table-card__body .dataTables_wrapper,
body.bb-theme-v2 section.content .box .dataTables_wrapper {
  width: 100%;
  color: var(--bb-v2-text);
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_length,
body.bb-theme-v2 .dataTables_wrapper .dataTables_filter,
body.bb-theme-v2 .dataTables_wrapper .dataTables_info,
body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate {
  color: var(--bb-v2-text);
  font-size: 0.8125rem;
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_length label,
body.bb-theme-v2 .dataTables_wrapper .dataTables_filter label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  color: var(--bb-v2-text);
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_filter input,
body.bb-theme-v2 .dataTables_wrapper .dataTables_length select {
  border: 1px solid var(--bb-v2-border) !important;
  border-radius: var(--bb-v2-radius) !important;
  min-height: 2.35rem;
  padding: 0.35rem 0.75rem !important;
  background: var(--bb-v2-surface) !important;
  color: var(--bb-v2-text-strong) !important;
  box-shadow: none !important;
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_filter input:focus,
body.bb-theme-v2 .dataTables_wrapper .dataTables_length select:focus {
  border-color: var(--bb-v2-primary) !important;
  outline: 0;
  box-shadow: 0 0 0 0.2rem var(--bb-v2-primary-soft) !important;
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate {
  margin-top: 0.85rem;
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: var(--bb-v2-radius) !important;
  border: 1px solid var(--bb-v2-border) !important;
  background: var(--bb-v2-surface) !important;
  color: var(--bb-v2-text) !important;
  margin: 0 0.12rem !important;
  padding: 0.4rem 0.7rem !important;
  min-height: 2.25rem;
  line-height: 1.2;
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate .paginate_button.current,
body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: var(--bb-v2-primary) !important;
  border-color: var(--bb-v2-primary) !important;
  color: #fff !important;
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: #f8f8fb !important;
  border-color: var(--bb-v2-border) !important;
  color: var(--bb-v2-text-strong) !important;
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
  opacity: 0.45;
  cursor: not-allowed;
  background: #f5f5f7 !important;
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate .paginate_button.bb-sn-paginate-empty,
body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate .paginate_button:empty {
  display: none !important;
}

body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate [class*='col-sm']:empty {
  display: none !important;
}

body.bb-theme-v2 .dataTables_processing {
  background: rgba(255, 255, 255, 0.96) !important;
  border: 1px solid var(--bb-v2-border) !important;
  border-radius: var(--bb-v2-radius-lg) !important;
  box-shadow: var(--bb-v2-shadow-lg) !important;
  color: var(--bb-v2-text-strong) !important;
  font-weight: 600;
}

body.bb-theme-v2 .dt-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

body.bb-theme-v2 .dt-buttons .btn,
body.bb-theme-v2 .dt-button {
  margin: 0 !important;
}

/* ——— Row actions (keep visible) ——— */
body.bb-theme-v2 .bb-v2-table-card__body td .btn-group,
body.bb-theme-v2 .bb-v2-table-card__body td .dropdown,
body.bb-theme-v2 section.content .box td .btn-group,
body.bb-theme-v2 section.content .box td .dropdown {
  display: inline-flex !important;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

body.bb-theme-v2 .bb-v2-table-card__body td .btn,
body.bb-theme-v2 section.content .box td .btn {
  min-height: 2rem;
  padding: 0.28rem 0.6rem;
  font-size: 0.8125rem;
}

body.bb-theme-v2 .bb-v2-table-card__body td .dropdown-menu,
body.bb-theme-v2 section.content .box td .dropdown-menu {
  z-index: 1050;
}

/* ——— Legacy .box → Sneat card (pages not yet on widget) ——— */
body.bb-theme-v2 section.content > .box,
body.bb-theme-v2 section.content .box-primary,
body.bb-theme-v2 section.content .box-solid {
  background: var(--bb-v2-surface) !important;
  border: 1px solid var(--bb-v2-border) !important;
  border-radius: var(--bb-v2-radius-lg) !important;
  box-shadow: var(--bb-v2-shadow) !important;
  border-top: 1px solid var(--bb-v2-border) !important;
  margin-bottom: 1rem;
  overflow: hidden;
}

body.bb-theme-v2 section.content .box-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.9rem 1.15rem !important;
  background: #f8f8fb !important;
  border-bottom: 1px solid var(--bb-v2-border) !important;
  color: var(--bb-v2-text-strong) !important;
}

body.bb-theme-v2 section.content .box-header .box-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--bb-v2-text-strong) !important;
}

body.bb-theme-v2 section.content .box-header .box-tools {
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  float: none !important;
  position: static !important;
  margin: 0 !important;
}

body.bb-theme-v2 section.content .box-body {
  padding: 0.85rem 1rem 1rem !important;
  background: var(--bb-v2-surface) !important;
}

/* iCheck / checkboxes in tables */
body.bb-theme-v2 .icheckbox_square-blue,
body.bb-theme-v2 .iradio_square-blue {
  background: var(--bb-v2-surface) !important;
  border: 1px solid var(--bb-v2-border) !important;
  border-radius: 0.25rem !important;
}

body.bb-theme-v2 .icheckbox_square-blue.checked,
body.bb-theme-v2 .iradio_square-blue.checked {
  background: var(--bb-v2-primary) !important;
  border-color: var(--bb-v2-primary) !important;
}

/* Labels in cells */
body.bb-theme-v2 table .label,
body.bb-theme-v2 table .badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25em 0.5em;
}

@media (max-width: 767.98px) {
  body.bb-theme-v2 .bb-v2-table-card__body table thead th,
  body.bb-theme-v2 .bb-v2-table-card__body table tbody td,
  body.bb-theme-v2 table.dataTable thead th,
  body.bb-theme-v2 table.dataTable tbody td {
    padding: 0.6rem 0.65rem !important;
    font-size: 0.8125rem;
  }

  body.bb-theme-v2 .dataTables_wrapper .dataTables_length,
  body.bb-theme-v2 .dataTables_wrapper .dataTables_filter {
    float: none;
    width: 100%;
    text-align: start;
    margin-bottom: 0.5rem;
  }

  body.bb-theme-v2 .dataTables_wrapper .dataTables_filter input {
    width: 100%;
    margin-inline-start: 0;
  }

  body.bb-theme-v2 .dataTables_wrapper .dataTables_paginate {
    text-align: center;
    margin-top: 0.65rem;
  }
}
