/* ============================================================
   SmartAdmin Bootstrap 5 - Tables
   CSS Module: Table Styles, Responsive, Data Tables
   ============================================================ */

/* Base Table */
table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  background-color: var(--bs-body-bg);
}

.table {
  width: 100%;
  margin-bottom: 1rem;
  color: var(--bs-body-color);
  border-collapse: collapse;
}

.table > :not(caption) > * > * {
  padding: 0.75rem;
  background-color: var(--bs-body-bg);
  border-bottom: 1px solid var(--bs-gray-200);
}

.table > tbody {
  vertical-align: inherit;
}

.table > thead {
  vertical-align: bottom;
}

.table > thead th {
  background-color: var(--bs-gray-100);
  border-bottom: 2px solid var(--bs-gray-300);
  font-weight: 600;
  vertical-align: bottom;
  color: inherit;
}

[data-bs-theme="dark"] .table > thead th {
  background-color: var(--bs-gray-800);
  border-bottom-color: var(--bs-gray-700);
}

.table > tfoot th {
  background-color: var(--bs-gray-100);
  border-top: 2px solid var(--bs-gray-300);
  font-weight: 600;
  vertical-align: top;
  color: inherit;
}

/* Table Variants */
.table-striped > tbody > tr:nth-of-type(odd) {
  background-color: rgba(0, 0, 0, 0.02);
}

[data-bs-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) {
  background-color: rgba(255, 255, 255, 0.02);
}

.table-hover > tbody > tr:hover {
  background-color: rgba(0, 0, 0, 0.05);
  cursor: pointer;
}

[data-bs-theme="dark"] .table-hover > tbody > tr:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.table-bordered {
  border: 1px solid var(--bs-gray-300);
}

.table-bordered > :not(caption) > * {
  border-width: 1px 0;
}

.table-bordered > :not(caption) > * > * {
  border-width: 0 1px;
}

.table-borderless > :not(caption) > * > * {
  border-bottom-width: 0;
}

.table-borderless > :not(caption) > tr:first-child > * {
  border-top-width: 0;
}

/* Table Sizes */
.table-sm > :not(caption) > * > * {
  padding: 0.4rem;
}

.table-lg > :not(caption) > * > * {
  padding: 1rem;
}

/* Table Backgrounds */
.table-primary {
  background-color: #e3f2fd;
}

.table-primary th,
.table-primary td,
.table-primary thead th,
.table-primary tbody + tbody {
  border-color: #90caf9;
}

.table-success {
  background-color: #e8f5e9;
}

.table-success th,
.table-success td,
.table-success thead th,
.table-success tbody + tbody {
  border-color: #81c784;
}

.table-danger {
  background-color: #ffebee;
}

.table-danger th,
.table-danger td,
.table-danger thead th,
.table-danger tbody + tbody {
  border-color: #ef9a9a;
}

.table-warning {
  background-color: #fff3e0;
}

.table-warning th,
.table-warning td,
.table-warning thead th,
.table-warning tbody + tbody {
  border-color: #ffb74d;
}

.table-info {
  background-color: #e0f2f1;
}

.table-info th,
.table-info td,
.table-info thead th,
.table-info tbody + tbody {
  border-color: #80deea;
}

.table-active {
  background-color: rgba(0, 0, 0, 0.075);
}

/* Responsive Table */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive > .table {
  margin-bottom: 0;
}

/* Table Actions */
.table .btn {
  font-size: 0.875rem;
  padding: 0.25rem 0.5rem;
  margin-right: 0.25rem;
}

.table .btn-sm {
  padding: 0.15rem 0.3rem;
  font-size: 0.75rem;
}

.table-actions {
  white-space: nowrap;
  text-align: center;
}

/* Table Toolbar */
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
}

.table-toolbar-search {
  flex: 1;
  max-width: 300px;
}

.table-toolbar-actions {
  display: flex;
  gap: 0.5rem;
}

/* Table Header Sorting */
.table th[data-sortable] {
  cursor: pointer;
  user-select: none;
  padding-right: 2rem;
  position: relative;
}

.table th[data-sortable]::after {
  content: "";
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath d='M3 2a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1H3zm5 9V5.41L5.7 7.7a.5.5 0 1 1-.4-.8l3-3a.5.5 0 0 1 .8 0l3 3a.5.5 0 0 1-.4.8L8 5.41V11a.5.5 0 0 1-1 0z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0.3;
}

.table th[data-sort="asc"]::after {
  opacity: 1;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath d='M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5z'/%3e%3c/svg%3e");
}

.table th[data-sort="desc"]::after {
  opacity: 1;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath d='M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z'/%3e%3c/svg%3e");
}

/* Table Pagination */
.table-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  padding: 1rem;
  background-color: var(--bs-gray-100);
  border-radius: var(--bs-border-radius);
}

[data-bs-theme="dark"] .table-pagination {
  background-color: var(--bs-gray-800);
}

.table-pagination .pagination {
  margin: 0;
}

.pagination {
  display: flex;
  padding-left: 0;
  list-style: none;
  border-radius: var(--bs-border-radius);
  gap: 0.25rem;
}

.pagination .page-link {
  position: relative;
  display: block;
  padding: 0.5rem 0.75rem;
  margin-left: -1px;
  line-height: 1.25;
  color: var(--bs-primary);
  background-color: var(--bs-body-bg);
  border: 1px solid var(--bs-gray-300);
  text-decoration: none;
  transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  cursor: pointer;
}

.pagination .page-link:hover {
  color: var(--bs-primary);
  background-color: var(--bs-gray-100);
  border-color: var(--bs-gray-300);
}

.pagination .page-link:focus {
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(33, 150, 243, 0.25);
  color: var(--bs-primary);
  background-color: var(--bs-gray-100);
  border-color: var(--bs-gray-300);
}

.pagination .page-link.active {
  z-index: 1;
  color: #fff;
  background-color: var(--bs-primary);
  border-color: var(--bs-primary);
}

.pagination .page-link.disabled {
  color: var(--bs-gray-500);
  pointer-events: none;
  cursor: auto;
  background-color: var(--bs-body-bg);
  border-color: var(--bs-gray-300);
}

.pagination-sm .page-link {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
}

.pagination-lg .page-link {
  padding: 0.75rem 1rem;
  font-size: 1.25rem;
}

/* Table Empty State */
.table-empty {
  text-align: center;
  padding: 3rem !important;
  color: var(--bs-gray-600);
}

.table-empty svg {
  width: 64px;
  height: 64px;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.table-empty h5 {
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
  color: var(--bs-body-color);
}

/* Thead Sticky */
.table-sticky thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: var(--bs-gray-100);
}

[data-bs-theme="dark"] .table-sticky thead {
  background-color: var(--bs-gray-800);
}

/* Selectable Rows */
.table-selectable tbody tr {
  cursor: pointer;
}

.table-selectable tbody tr.selected {
  background-color: rgba(33, 150, 243, 0.1);
}

.table-selectable .form-check {
  margin-bottom: 0;
}
