/*
 * admin-enhanced.css
 * Tinh chỉnh giao diện admin: table nâng cấp + tokens dark/light.
 * Tải sau core theme nên các giá trị ở đây sẽ ghi đè theme gốc khi cần.
 ****************************************************************************/

:root {
  --app-surface: #ffffff;
  --app-surface-alt: #f8f9fc;
  --app-border: rgba(75, 70, 92, 0.12);
  --app-border-strong: rgba(75, 70, 92, 0.2);
  --app-text: #2f2b3d;
  --app-text-muted: #6f6b7d;
  --app-primary: #7367f0;
  --app-primary-soft: rgba(115, 103, 240, 0.12);
  --app-row-hover: rgba(115, 103, 240, 0.06);
  --app-row-stripe: rgba(75, 70, 92, 0.03);
  --app-shadow: 0 6px 24px rgba(75, 70, 92, 0.08);
  --app-shadow-sm: 0 2px 6px rgba(75, 70, 92, 0.06);
  --app-radius: 12px;
}

.dark-style {
  --app-surface: #2f3349;
  --app-surface-alt: #282a42;
  --app-border: rgba(225, 222, 245, 0.12);
  --app-border-strong: rgba(225, 222, 245, 0.2);
  --app-text: #e7e3fc;
  --app-text-muted: #b6bee3;
  --app-primary: #7367f0;
  --app-primary-soft: rgba(115, 103, 240, 0.18);
  --app-row-hover: rgba(115, 103, 240, 0.12);
  --app-row-stripe: rgba(225, 222, 245, 0.03);
  --app-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  --app-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ===== Toggle sáng/tối dạng switch 2 trạng thái ===== */
.app-theme-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  line-height: 1;
}
.app-theme-switch:focus-visible {
  outline: 2px solid var(--app-primary);
  outline-offset: 3px;
  border-radius: 999px;
}
.app-theme-switch__track {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 56px;
  height: 28px;
  padding: 0 6px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffd97a 0%, #ffb24a 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: background 0.35s ease, box-shadow 0.35s ease;
}
.dark-style .app-theme-switch__track {
  background: linear-gradient(135deg, #2b2d4a 0%, #4b4974 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 1px 2px rgba(0, 0, 0, 0.4);
}
.app-theme-switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              background 0.3s ease,
              box-shadow 0.3s ease;
}
.dark-style .app-theme-switch__thumb {
  transform: translateX(28px);
  background: #2f3349;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45), 0 0 12px rgba(115, 103, 240, 0.4);
}
.app-theme-switch__icon {
  font-size: 14px !important;
  line-height: 1;
  position: absolute;
  transition: opacity 0.25s ease, transform 0.35s ease;
}
.app-theme-switch__icon--sun {
  color: #ff9f43;
  opacity: 1;
  transform: rotate(0) scale(1);
}
.app-theme-switch__icon--moon {
  color: #7367f0;
  opacity: 0;
  transform: rotate(-45deg) scale(0.6);
}
.dark-style .app-theme-switch__icon--sun {
  opacity: 0;
  transform: rotate(45deg) scale(0.6);
}
.dark-style .app-theme-switch__icon--moon {
  color: #cdc8ff;
  opacity: 1;
  transform: rotate(0) scale(1);
}
.app-theme-switch:hover .app-theme-switch__thumb {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.dark-style .app-theme-switch:hover .app-theme-switch__thumb {
  box-shadow: 0 4px 14px rgba(115, 103, 240, 0.5);
}

/* ===== Card chứa datatable =====
   Không cần ép border/shadow vì Materio đã có. Ở đây chỉ refine bo góc
   bên trong khi `.card-datatable` là con trực tiếp của `.card`.
*/
.card-datatable {
  padding-top: 0.25rem;
  border-radius: inherit;
}
.card > .card-datatable {
  border-radius: var(--app-radius);
}
.card.module {
  transition: box-shadow 0.2s ease;
}
.card.module:hover {
  box-shadow: var(--app-shadow);
}

/* ===== Bảng (cả thường + DataTables + Bootstrap Table) ===== */
.table,
.dataTable,
.bootstrap-table .table {
  --bs-table-bg: transparent;
  border-collapse: separate !important;
  border-spacing: 0;
  margin-bottom: 0 !important;
  color: var(--app-text);
}

.table > :not(caption) > * > * {
  padding: 0.9rem 1.25rem;
  vertical-align: middle;
  border-bottom-color: var(--app-border);
}

/* Header sạch & rõ */
.table > thead,
.dataTable > thead,
.bootstrap-table .table > thead {
  background: var(--app-surface-alt);
}
.table > thead > tr > th,
.dataTable > thead > tr > th,
.bootstrap-table .table > thead > tr > th {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--app-text-muted);
  background: transparent !important;
  border-bottom: 1px solid var(--app-border-strong);
  white-space: nowrap;
}

/* Override Materio's .table-light cho thead */
.table > thead.table-light {
  background: var(--app-surface-alt) !important;
}
.table > thead.table-light > tr > th {
  color: var(--app-text-muted) !important;
}

/* Hàng dữ liệu */
.table > tbody > tr,
.dataTable > tbody > tr,
.bootstrap-table .table > tbody > tr {
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.table > tbody > tr:hover,
.dataTable > tbody > tr:hover,
.bootstrap-table .table > tbody > tr:hover {
  background-color: var(--app-row-hover) !important;
}
.table.table-striped > tbody > tr:nth-of-type(odd),
.dataTable.table-striped > tbody > tr:nth-of-type(odd) {
  background-color: var(--app-row-stripe) !important;
}

.table > tbody > tr > td,
.dataTable > tbody > tr > td {
  border-bottom: 1px solid var(--app-border);
}
.table > tbody > tr:last-child > td,
.dataTable > tbody > tr:last-child > td {
  border-bottom: none;
}

/* ID/code dạng monospace nhẹ */
.table .text-nowrap,
.dataTable .text-nowrap {
  font-variant-numeric: tabular-nums;
}

/* ===== DataTables: search + length + buttons ===== */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
  padding: 0.5rem 0;
}
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
  border: 1px solid var(--app-border-strong);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  background: var(--app-surface);
  color: var(--app-text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.dataTables_wrapper .dataTables_filter input {
  min-width: 220px;
  padding-left: 2.25rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236f6b7d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
  background-repeat: no-repeat;
  background-position: 0.6rem center;
}
.dark-style .dataTables_wrapper .dataTables_filter input {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23b6bee3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
}
.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus {
  outline: none;
  border-color: var(--app-primary);
  box-shadow: 0 0 0 3px var(--app-primary-soft);
}

.dt-action-buttons .btn {
  border-radius: 8px;
  font-weight: 500;
  padding: 0.45rem 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.dt-action-buttons .btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--app-shadow-sm);
}

/* Sorting indicators */
table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc {
  cursor: pointer;
  position: relative;
}
table.dataTable thead .sorting::after,
table.dataTable thead .sorting_asc::after,
table.dataTable thead .sorting_desc::after {
  opacity: 0.5;
  font-weight: 700;
}

/* Pagination */
.dataTables_wrapper .dataTables_paginate .paginate_button,
.bootstrap-table .pagination .page-link {
  border-radius: 8px !important;
  margin: 0 2px;
  border: none !important;
  color: var(--app-text-muted) !important;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover,
.bootstrap-table .pagination .page-link:hover {
  background: var(--app-primary-soft) !important;
  color: var(--app-primary) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover,
.bootstrap-table .pagination .active .page-link {
  background: var(--app-primary) !important;
  color: #fff !important;
  border: none !important;
}

.dataTables_wrapper .dataTables_info {
  color: var(--app-text-muted);
  font-size: 0.85rem;
  padding-top: 0.75rem;
}

/* Checkbox cột đầu DataTables */
table.dataTable input.dt-checkboxes,
table.dataTable input.form-check-input {
  cursor: pointer;
  border-radius: 4px;
}

/* Hàng đã chọn */
table.dataTable tr.selected,
table.dataTable tbody tr:has(input.dt-checkboxes:checked) {
  background-color: var(--app-primary-soft) !important;
}

/* ===== Bootstrap Table ===== */
.fixed-table-toolbar {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--app-border);
}
.fixed-table-toolbar .search input,
.fixed-table-toolbar .columns .btn {
  border-radius: 8px !important;
  border: 1px solid var(--app-border-strong) !important;
  background: var(--app-surface) !important;
  color: var(--app-text) !important;
}
.fixed-table-container {
  border: none !important;
}
.bootstrap-table .fixed-table-pagination {
  padding: 0.75rem 1rem;
}

/* ===== Badge / action icons mượt hơn ===== */
.table .badge {
  font-weight: 500;
  padding: 0.35em 0.7em;
  border-radius: 6px;
}
.table a.text-body i.mdi {
  border-radius: 6px;
  padding: 4px;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.table a.text-body:hover i.mdi {
  background: var(--app-primary-soft);
  color: var(--app-primary);
}

/* Heading nhẹ trên các trang list */
.card-datatable + .card-datatable {
  border-top: 1px solid var(--app-border);
}

/* Đẩy nội dung thoáng hơn trên màn lớn */
@media (min-width: 1200px) {
  .table > :not(caption) > * > * {
    padding: 1rem 1.5rem;
  }
}

/* Empty state đẹp hơn */
.dataTables_empty {
  padding: 3rem 1rem !important;
  text-align: center;
  color: var(--app-text-muted);
  font-style: italic;
}

/* Loading spinner dim trong dark */
.dark-style #spinnerLoading.bg-light {
  background-color: var(--app-surface-alt) !important;
}

/* Scrollbar bên trong table-responsive */
.table-responsive::-webkit-scrollbar {
  height: 8px;
}
.table-responsive::-webkit-scrollbar-track {
  background: transparent;
}
.table-responsive::-webkit-scrollbar-thumb {
  background: var(--app-border-strong);
  border-radius: 4px;
}

/* Fade-in nhẹ khi data table draw */
table.dataTable tbody tr {
  animation: appFadeIn 0.25s ease;
}
@keyframes appFadeIn {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== Sticky thead (lăn dài giữ tiêu đề) ===== */
.card-datatable table.dataTable > thead,
.card-datatable .bootstrap-table table > thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* ===== Tiêu đề trang dạng breadcrumb (h4 phổ biến trong template) ===== */
.content-wrapper h4.fw-bold {
  position: relative;
  padding-left: 0.85rem;
}
.content-wrapper h4.fw-bold::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 1.4em;
  border-radius: 4px;
  background: var(--app-primary);
  opacity: 0.85;
}

/* ===== Responsive details modal (DataTables Responsive) ===== */
.dtr-modal .dtr-modal-content {
  background: var(--app-surface);
  color: var(--app-text);
  border-radius: var(--app-radius);
  border: 1px solid var(--app-border);
}

/* ===== Dropdown nhỏ trong navbar có cảm giác mượt hơn ===== */
.navbar .dropdown-menu {
  border: 1px solid var(--app-border);
  box-shadow: var(--app-shadow);
}
