/*
 * RS-TH07 — Unified Data Tables, Lists & Responsive Actions
 * Shared presentation layer for Admin, Public, Auth and standalone pages.
 */

:root {
  --herb-table-radius: 1rem;
  --herb-table-border: var(--theme-border, #d7e2dc);
  --herb-table-border-strong: var(--theme-border-strong, #b9cbc1);
  --herb-table-surface: var(--theme-surface, #fff);
  --herb-table-head-bg: color-mix(in srgb, var(--theme-brand, #137a54) 8%, var(--theme-surface, #fff));
  --herb-table-head-text: color-mix(in srgb, var(--theme-brand-hover, #0f6144) 72%, var(--theme-text, #13251d));
  --herb-table-row-alt: var(--theme-table-stripe, rgba(19, 122, 84, .035));
  --herb-table-row-hover: var(--theme-table-hover, rgba(19, 122, 84, .075));
  --herb-table-row-selected: color-mix(in srgb, var(--theme-brand, #137a54) 14%, var(--theme-surface, #fff));
  --herb-table-shadow: 0 12px 30px rgba(15, 35, 26, .07);
  --herb-table-scroll-shadow: rgba(19, 54, 39, .18);
  --herb-table-cell-x: .9rem;
  --herb-table-cell-y: .78rem;
  --herb-table-toolbar-bg: color-mix(in srgb, var(--theme-brand, #137a54) 3%, var(--theme-surface, #fff));
}

html[data-theme="dark"] {
  --herb-table-border: #365648;
  --herb-table-border-strong: #527565;
  --herb-table-surface: #10241c;
  --herb-table-head-bg: #18372b;
  --herb-table-head-text: #e9fff4;
  --herb-table-row-alt: rgba(255, 255, 255, .025);
  --herb-table-row-hover: rgba(109, 229, 168, .10);
  --herb-table-row-selected: #214b3a;
  --herb-table-shadow: 0 16px 38px rgba(0, 0, 0, .26);
  --herb-table-scroll-shadow: rgba(0, 0, 0, .52);
  --herb-table-toolbar-bg: #132d23;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(
  .table-responsive,
  .table-shell,
  .vc-table-wrap,
  .dq-table-wrap,
  .sh-table-wrap,
  .geo-import-table,
  .debug-users-wrap,
  .th07-table-shell
) {
  position: relative;
  max-width: 100%;
  border: 1px solid var(--herb-table-border);
  border-radius: var(--herb-table-radius);
  background: var(--herb-table-surface);
  box-shadow: var(--herb-table-shadow);
  overflow: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--theme-brand, #137a54) 58%, var(--herb-table-border)) transparent;
  -webkit-overflow-scrolling: touch;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(
  .table-responsive,
  .table-shell,
  .vc-table-wrap,
  .dq-table-wrap,
  .sh-table-wrap,
  .geo-import-table,
  .debug-users-wrap,
  .th07-table-shell
):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--theme-brand, #137a54) 48%, transparent);
  outline-offset: 3px;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table-shell[data-scroll-start="false"] {
  box-shadow: inset 18px 0 16px -18px var(--herb-table-scroll-shadow), var(--herb-table-shadow);
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table-shell[data-scroll-end="false"] {
  box-shadow: inset -18px 0 16px -18px var(--herb-table-scroll-shadow), var(--herb-table-shadow);
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table-shell[data-scroll-start="false"][data-scroll-end="false"] {
  box-shadow: inset 18px 0 16px -18px var(--herb-table-scroll-shadow), inset -18px 0 16px -18px var(--herb-table-scroll-shadow), var(--herb-table-shadow);
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(table, .table, .vc-table, .dq-table, .sh-table).th07-table,
body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table-shell > table {
  width: 100%;
  margin: 0 !important;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--theme-text);
  background: transparent;
  vertical-align: middle;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table :where(th, td) {
  padding: var(--herb-table-cell-y) var(--herb-table-cell-x);
  border-color: var(--herb-table-border) !important;
  color: inherit;
  background-clip: padding-box;
  line-height: 1.45;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table thead :where(th, td) {
  color: var(--herb-table-head-text) !important;
  -webkit-text-fill-color: var(--herb-table-head-text) !important;
  background: var(--herb-table-head-bg) !important;
  border-bottom: 1px solid var(--herb-table-border-strong) !important;
  font-size: .8125rem;
  font-weight: 800;
  letter-spacing: .015em;
  white-space: nowrap;
  vertical-align: middle;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table thead tr:first-child > :first-child {
  border-start-start-radius: calc(var(--herb-table-radius) - 1px);
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table thead tr:first-child > :last-child {
  border-start-end-radius: calc(var(--herb-table-radius) - 1px);
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table tbody > tr:nth-child(even) > * {
  background-color: var(--herb-table-row-alt);
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table.table-hover tbody > tr:hover > *,
body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table tbody > tr:focus-within > * {
  background-color: var(--herb-table-row-hover) !important;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table tbody > tr:is(.is-selected, .selected, [aria-selected="true"]) > * {
  background-color: var(--herb-table-row-selected) !important;
  box-shadow: inset 3px 0 0 var(--theme-brand);
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table tbody > tr:last-child > * {
  border-bottom-width: 0;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table tfoot > * > * {
  color: var(--theme-text-soft);
  background: var(--theme-surface-muted);
  border-top: 1px solid var(--herb-table-border-strong) !important;
  font-weight: 700;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table :where(.th07-cell-actions, th:last-child[data-th07-actions="true"], td:last-child[data-th07-actions="true"]) {
  min-width: 8.5rem;
  text-align: end;
  white-space: nowrap;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table .th07-cell-actions :where(.btn, button, a.btn) {
  min-height: 36px;
  margin: .12rem;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table :where(.th07-cell-number, .text-end) {
  font-variant-numeric: tabular-nums;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table :where(.th07-row-loading, .th07-row-empty, .th07-row-error) > td,
body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table td.th07-state-cell {
  min-height: 7.5rem;
  padding-block: 2.25rem !important;
  text-align: center !important;
  white-space: normal !important;
  color: var(--theme-muted) !important;
  -webkit-text-fill-color: var(--theme-muted) !important;
  background: color-mix(in srgb, var(--theme-surface-muted) 82%, transparent) !important;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table .th07-row-loading > td::before,
body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table td.th07-state-loading::before {
  content: "";
  display: inline-block;
  width: 1rem;
  height: 1rem;
  margin-inline-end: .55rem;
  vertical-align: -.15rem;
  border: 2px solid color-mix(in srgb, var(--theme-brand) 28%, transparent);
  border-top-color: var(--theme-brand);
  border-radius: 50%;
  animation: th07-spin .75s linear infinite;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table .th07-row-error > td,
body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table td.th07-state-error {
  color: var(--theme-danger) !important;
  -webkit-text-fill-color: var(--theme-danger) !important;
  background: color-mix(in srgb, var(--theme-danger) 8%, var(--theme-surface)) !important;
}

@keyframes th07-spin { to { transform: rotate(360deg); } }

/* DataTables controls */
body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_wrapper {
  color: var(--theme-text);
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_wrapper > .row:first-child,
body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_wrapper > .row:last-child {
  margin: 0;
  padding: .75rem .85rem;
  gap: .65rem 0;
  background: var(--herb-table-toolbar-bg);
  border: 1px solid var(--herb-table-border);
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_wrapper > .row:first-child {
  border-radius: var(--herb-table-radius) var(--herb-table-radius) 0 0;
  border-bottom: 0;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_wrapper > .row:last-child {
  border-radius: 0 0 var(--herb-table-radius) var(--herb-table-radius);
  border-top: 0;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(.dataTables_length, .dataTables_filter, .dataTables_info) {
  color: var(--theme-muted) !important;
  font-size: .875rem;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_filter label,
body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_length label {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  margin: 0;
  color: var(--theme-text-soft);
  font-weight: 700;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_filter input,
body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_length select {
  margin: 0 !important;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(.pagination, .dataTables_paginate .pagination) {
  flex-wrap: wrap;
  gap: .3rem;
  margin: 0;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(.page-link, .paginate_button .page-link) {
  display: inline-flex;
  min-width: 40px;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--herb-table-border-strong) !important;
  border-radius: .72rem !important;
  background: var(--theme-surface) !important;
  color: var(--theme-text-soft) !important;
  -webkit-text-fill-color: var(--theme-text-soft) !important;
  font-weight: 700;
  box-shadow: none !important;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(.page-link:hover, .page-link:focus-visible) {
  border-color: var(--theme-brand) !important;
  background: color-mix(in srgb, var(--theme-brand) 10%, var(--theme-surface)) !important;
  color: var(--theme-link-hover) !important;
  -webkit-text-fill-color: var(--theme-link-hover) !important;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(.page-item.active .page-link, .paginate_button.active .page-link) {
  border-color: var(--theme-brand) !important;
  background: var(--theme-brand) !important;
  color: var(--theme-brand-contrast) !important;
  -webkit-text-fill-color: var(--theme-brand-contrast) !important;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(.page-item.disabled .page-link, .paginate_button.disabled .page-link) {
  opacity: .58;
  cursor: not-allowed;
}

/* Shared list presentation */
body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(.list-group, .admin-list, .result-list, .search-results) {
  --bs-list-group-bg: var(--theme-surface);
  --bs-list-group-color: var(--theme-text);
  --bs-list-group-border-color: var(--theme-border);
  --bs-list-group-action-hover-bg: var(--theme-table-hover);
  --bs-list-group-action-hover-color: var(--theme-text);
  --bs-list-group-action-active-bg: var(--herb-table-row-selected);
  --bs-list-group-action-active-color: var(--theme-text);
  border-radius: var(--herb-table-radius);
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table-scroll-hint {
  display: none;
  align-items: center;
  gap: .45rem;
  width: max-content;
  max-width: 100%;
  margin: .45rem 0 0 auto;
  padding: .35rem .65rem;
  border: 1px solid var(--herb-table-border);
  border-radius: 999px;
  background: var(--theme-surface-muted);
  color: var(--theme-muted);
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.3;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table-scroll-hint::before {
  content: "↔";
  color: var(--theme-brand);
  font-size: .95rem;
}

body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table-scroll-hint[hidden] {
  display: none !important;
}

@media (max-width: 991.98px) {
  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) {
    --herb-table-cell-x: .75rem;
    --herb-table-cell-y: .68rem;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table-scroll-hint:not([hidden]) {
    display: inline-flex;
  }
}

@media (max-width: 767.98px) {
  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(
    .table-responsive,
    .table-shell,
    .vc-table-wrap,
    .dq-table-wrap,
    .sh-table-wrap,
    .geo-import-table,
    .debug-users-wrap,
    .th07-table-shell
  ) {
    width: 100%;
    border-radius: .85rem;
    box-shadow: none;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table {
    min-width: var(--th07-table-min-width, 680px);
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table[data-th07-columns="1"],
  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table[data-th07-columns="2"],
  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table[data-th07-columns="3"] {
    min-width: 100%;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table :where(th, td) {
    padding: .68rem .72rem;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table .th07-cell-actions :where(.btn, button, a.btn) {
    min-width: 44px;
    min-height: 44px;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_wrapper > .row:first-child > div,
  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_wrapper > .row:last-child > div {
    width: 100%;
    text-align: start !important;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_filter,
  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_filter label {
    width: 100%;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_filter input {
    flex: 1 1 auto;
    width: 100% !important;
    min-width: 0;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .dataTables_paginate .pagination {
    justify-content: flex-start !important;
  }
}

@media (max-width: 389.98px) {
  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) {
    --herb-table-cell-x: .62rem;
    --herb-table-cell-y: .62rem;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table-scroll-hint {
    width: 100%;
    justify-content: center;
    margin-inline: 0;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(.page-link, .paginate_button .page-link) {
    min-width: 44px;
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table .th07-row-loading > td::before,
  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table td.th07-state-loading::before {
    animation-duration: 1.6s;
  }
}

@media print {
  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) :where(
    .table-responsive,
    .table-shell,
    .vc-table-wrap,
    .dq-table-wrap,
    .sh-table-wrap,
    .geo-import-table,
    .debug-users-wrap,
    .th07-table-shell
  ) {
    overflow: visible !important;
    border: 1px solid #777 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table {
    min-width: 0 !important;
    color: #111 !important;
    font-size: 9pt;
  }

  body:is(.admin-body, .public-shell, .auth-shell, .theme-scope-standalone) .th07-table :where(th, td) {
    color: #111 !important;
    -webkit-text-fill-color: #111 !important;
    background: #fff !important;
    border-color: #777 !important;
  }

  .th07-table-scroll-hint,
  .dataTables_length,
  .dataTables_filter,
  .dataTables_paginate {
    display: none !important;
  }
}
