/**
 * Bootstrap 5 DataTable Styles - Exact Match to Screenshot
 * Clean, modern design with Bootstrap 5 native classes
 * Version: 2.0
 */

/* ============================================
   DataTable Container
   ============================================ */

.bs5-datatable-wrapper {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
    margin-bottom: 24px;
    padding-bottom: 0;
    position: relative;
    overflow-x: auto;
}

/* ============================================
   Header with Search and Actions
   ============================================ */

.datatable-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    gap: 12px;
    flex-wrap: wrap;
    background: transparent;
}

.datatable-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.datatable-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Search Box with Icon */
.datatable-search-wrapper {
    position: relative;
    flex: 0 1 200px;
    max-width: 200px;
}

/* Entries per page dropdown in header */
.datatable-length-wrapper-header {
    display: flex;
    align-items: center;
}

.datatable-length-wrapper-header select {
    width: 70px;
    padding: 7px 10px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 14px;
    background-color: #ffffff;
    cursor: pointer;
    transition: all 0.15s ease;
}

.datatable-length-wrapper-header select:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.1);
    outline: 0;
}

/* Export dropdown styling */
.datatable-header-right .dropdown-menu {
    min-width: 160px;
    padding: 4px 0;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.datatable-header-right .dropdown-menu li {
    list-style: none;
}

.datatable-header-right .dropdown-menu .dropdown-item,
.datatable-header-right .dropdown-menu li a {
    display: block;
    padding: 6px 12px;
    font-size: 13px;
    color: #333;
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.datatable-header-right .dropdown-menu .dropdown-item:hover,
.datatable-header-right .dropdown-menu li a:hover {
    background-color: #f5f5f5;
    color: #333;
}

.datatable-header-right .dropdown-menu .dropdown-item i,
.datatable-header-right .dropdown-menu li a i {
    margin-right: 6px;
    width: 14px;
    text-align: center;
}

.datatable-header-right .dropdown-menu .divider {
    height: 1px;
    margin: 4px 0;
    overflow: hidden;
    background-color: #e5e5e5;
}

.datatable-search-wrapper .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    pointer-events: none;
}

.datatable-search-wrapper input {
    width: 100%;
    padding: 9px 14px 9px 38px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 14px;
    background-color: #f8f9fa;
    transition: all 0.2s ease;
}

.datatable-search-wrapper input:focus {
    background-color: #ffffff;
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.1);
    outline: 0;
}

/* Filter Buttons */
.btn-filters {
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid #dee2e6;
    background-color: #ffffff;
    color: #212529;
    border-radius: 6px;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-filters:hover {
    background-color: #f8f9fa;
    border-color: #adb5bd;
    color: #212529;
}

/* Status Dropdown */
.status-dropdown select {
    padding: 9px 36px 9px 14px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 14px;
    background-color: #ffffff;
    min-width: 120px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23212529' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
}

.status-dropdown select:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.1);
    outline: 0;
}

/* Action Buttons */
.btn-actions {
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 6px;
}

/* ============================================
   DataTable Styling
   ============================================ */

.bs5-datatable {
    width: 100% !important;
    margin: 0 !important;
    border-collapse: separate;
    border-spacing: 0;
}

/* Table Header */
.bs5-datatable thead {
    background-color: #f8f9fa;
}

.bs5-datatable thead th {
    padding: 14px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #dee2e6;
    border-top: none;
    white-space: nowrap;
    vertical-align: middle;
}

.bs5-datatable thead th:first-child {
    padding-left: 24px;
}

.bs5-datatable thead th:last-child {
    padding-right: 24px;
}

/* Sortable Columns */
.bs5-datatable thead th.sorting,
.bs5-datatable thead th.sorting_asc,
.bs5-datatable thead th.sorting_desc {
    cursor: pointer;
    position: relative;
    padding-right: 32px;
}

.bs5-datatable thead th.sorting:after,
.bs5-datatable thead th.sorting_asc:after,
.bs5-datatable thead th.sorting_desc:after {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.3;
    font-family: 'Font Awesome 5 Free', 'FontAwesome';
    font-weight: 900;
    font-size: 10px;
}

.bs5-datatable thead th.sorting:after {
    content: '\f0dc';
}

.bs5-datatable thead th.sorting_asc:after {
    content: '\f0de';
    opacity: 1;
    color: #0d6efd;
}

.bs5-datatable thead th.sorting_desc:after {
    content: '\f0dd';
    opacity: 1;
    color: #0d6efd;
}

/* Table Body */
.bs5-datatable tbody tr {
    transition: background-color 0.15s ease;
    border-bottom: 1px solid #f1f3f5;
}

.bs5-datatable tbody tr:hover {
    background-color: #f8f9fa;
}

.bs5-datatable tbody tr:last-child {
    border-bottom: none;
}

.bs5-datatable tbody td {
    padding: 16px;
    vertical-align: middle;
    color: #212529;
    border-top: none;
    font-size: 14px;
    position: relative; /* For absolute positioned dropdowns */
}

.bs5-datatable tbody td:first-child {
    padding-left: 24px;
}

.bs5-datatable tbody td:last-child {
    padding-right: 24px;
}

/* Checkbox Styling */
.bs5-datatable .form-check-input {
    width: 18px;
    height: 18px;
    cursor: pointer;
    border: 2px solid #dee2e6;
}

.bs5-datatable .form-check-input:checked {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

/* ============================================
   Ticket/Item Display
   ============================================ */

.ticket-title {
    font-weight: 600;
    font-size: 14px;
    color: #212529;
    margin-bottom: 4px;
    line-height: 1.5;
}

.ticket-subtitle {
    font-size: 13px;
    color: #6c757d;
    margin-bottom: 8px;
}

.ticket-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

/* ============================================
   Badge Styling - Exact Match to Screenshot
   ============================================ */

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.status-badge i {
    font-size: 11px;
}

/* Resolved - Green */
.status-resolved {
    background-color: #d1e7dd;
    color: #0f5132;
    border: 1px solid #badbcc;
}

.status-resolved i {
    color: #198754;
}

/* Open - Blue/Purple */
.status-open {
    background-color: #e7e7ff;
    color: #383895;
    border: 1px solid #c5c5ff;
}

.status-open i {
    color: #5b5bca;
}

/* Closed - Gray */
.status-closed {
    background-color: #e9ecef;
    color: #495057;
    border: 1px solid #dee2e6;
}

.status-closed i {
    color: #6c757d;
}

/* Pending - Yellow */
.status-pending {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffe69c;
}

.status-pending i {
    color: #ffc107;
}

/* Tag Badges */
.tag-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 9px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
}

.tag-badge i {
    font-size: 10px;
}

/* Security - Purple */
.tag-security {
    background-color: #e8d5f2;
    color: #6c2e9c;
}

/* User Management - Green */
.tag-user-management {
    background-color: #c8e6c9;
    color: #2e7d32;
}

/* API Integration - Blue */
.tag-api-integration {
    background-color: #cfe2ff;
    color: #084298;
}

/* Multi-Account - Orange */
.tag-multi-account {
    background-color: #ffe5d0;
    color: #cc5500;
}

/* ============================================
   User Column
   ============================================ */

.user-display {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #e9ecef;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    color: #495057;
    flex-shrink: 0;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: #212529;
}

/* ============================================
   Actions Dropdown
   ============================================ */

/* Actions dropdown - basic styles */
.actions-dropdown,
td .actions-dropdown,
.bs5-datatable tbody td .actions-dropdown,
.bs5-datatable tbody td .dropdown,
.bs5-datatable tbody td .btn-group {
    position: relative;
}

.actions-dropdown .btn {
    padding: 6px 14px;
    font-size: 13px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Dropdown menu styling */
.bs5-datatable .dropdown-menu,
.bs5-datatable tbody .dropdown-menu,
.actions-dropdown .dropdown-menu {
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.08);
    padding: 6px 0;
    min-width: 160px;
    z-index: 1050;
    margin-top: 2px;
    background: #fff;
}

/* Dropdown menus moved to body for table actions */
.dropdown-menu[data-dropdown-moved="true"] {
    position: fixed;
    z-index: 9999;
}

/* When dropdown is open, ensure it's visible */
.bs5-datatable .dropdown.show .dropdown-menu,
.bs5-datatable tbody .dropdown.show .dropdown-menu {
    display: block;
}

.actions-dropdown .dropdown-item {
    padding: 8px 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.actions-dropdown .dropdown-item i {
    width: 14px;
    text-align: center;
    font-size: 13px;
}

/* ============================================
   Footer with Pagination
   ============================================ */

.datatable-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: transparent;
    flex-wrap: wrap;
    gap: 12px;
}

.datatable-info {
    font-size: 14px;
    color: #6c757d;
}

/* Bootstrap 5 Pagination Customization */
.pagination {
    margin: 0;
    gap: 4px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.pagination .page-link {
    border-radius: 6px;
    border: 1px solid #dee2e6;
    color: #495057;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 500;
    min-width: 38px;
    text-align: center;
    transition: all 0.15s ease;
}

.pagination .page-link:hover {
    background-color: #f8f9fa;
    border-color: #adb5bd;
    color: #212529;
}

.pagination .page-item.active .page-link {
    background-color: #0d6efd;
    border-color: #0d6efd;
    color: #ffffff;
}

.pagination .page-item.disabled .page-link {
    color: #adb5bd;
    background-color: #ffffff;
    border-color: #dee2e6;
}

/* ============================================
   Column Visibility Dropdown Styling
   ============================================ */

[data-bs5-column-visibility] {
    max-height: 400px;
    overflow-y: auto;
    min-width: 200px;
}

[data-bs5-column-visibility] li {
    list-style: none;
    padding: 5px 15px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

[data-bs5-column-visibility] li:hover {
    background-color: #f8f9fa;
}

[data-bs5-column-visibility] label {
    margin-bottom: 0;
    cursor: pointer;
    display: block;
    font-weight: normal;
    user-select: none;
}

[data-bs5-column-visibility] input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
    vertical-align: middle;
}

[data-bs5-column-visibility] span {
    vertical-align: middle;
}

/* ============================================
   DataTables Elements Override
   ============================================ */

/* Hide default DataTables controls (we use custom ones) */
.bs5-datatable-wrapper .dataTables_length,
.bs5-datatable-wrapper .dataTables_filter,
.bs5-datatable-wrapper .dataTables_info,
.bs5-datatable-wrapper .dataTables_paginate,
.bs5-datatable-wrapper .dt-buttons,
.bs5-datatable-wrapper .buttons-excel,
.bs5-datatable-wrapper .buttons-csv,
.bs5-datatable-wrapper .buttons-pdf,
.bs5-datatable-wrapper .buttons-print,
.bs5-datatable-wrapper .buttons-collection {
    display: none !important;
}

/* Also hide DT buttons in the DataTables wrapper row */
.bs5-datatable-wrapper .dataTables_wrapper .row:first-child,
.bs5-datatable-wrapper .dataTables_wrapper .row:last-child {
    display: none !important;
}

/* ============================================
   Box Integration - Remove Classic Box Styling
   ============================================ */

/* Remove box styling ONLY for boxes explicitly marked with has-bs5-datatable class */
/* This class is added by JavaScript after confirming it's a DataTable */
.box.has-bs5-datatable {
    box-shadow: none !important;
    border: none !important;
    background: transparent !important;
    border-radius: 0 !important;
}

/* Hide box header for enhanced datatables */
.box.has-bs5-datatable > .box-header {
    display: none !important;
}

/* Remove box-body padding for enhanced datatables */
.box.has-bs5-datatable > .box-body {
    padding: 0 !important;
    background: transparent !important;
}

/* Remove box shadow on hover for enhanced datatables */
.box.has-bs5-datatable:hover {
    box-shadow: none !important;
}

/* ============================================
   DataTables Export Buttons Integration
   ============================================ */

/* Style DT buttons when moved to BS5 header */
.datatable-header-right .dt-buttons-wrapper {
    display: inline-block;
}

.datatable-header-right .dt-buttons-wrapper .dt-button {
    margin-right: 4px;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #dee2e6;
    background: #ffffff;
    color: #495057;
    transition: all 0.15s ease;
}

.datatable-header-right .dt-buttons-wrapper .dt-button:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

.datatable-header-right .dt-buttons-wrapper .dt-button i {
    margin-right: 4px;
}

/* Hide dt-buttons and btn-group only inside DataTables wrapper col-sm-7 */
.bs5-datatable-wrapper .dataTables_wrapper .col-sm-7 .dt-buttons,
.bs5-datatable-wrapper .dataTables_wrapper .col-sm-7 .btn-group {
    display: none !important;
}

/* Remove margin from DataTables wrapper rows */
.bs5-datatable-wrapper .dataTables_wrapper .row {
    margin-bottom: 0 !important;
}

/* Hide default DataTables processing message - we use skeleton loader instead */
.dataTables_processing {
    display: none !important;
}

/* Ensure tables inside BS5 wrapper are always visible */
.bs5-datatable-wrapper table {
    visibility: visible !important;
}

.dataTables_empty {
    text-align: center;
    padding: 48px 24px !important;
    color: #6c757d;
    font-size: 14px;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
    .datatable-header {
        flex-direction: column;
        align-items: stretch;
    }

    .datatable-header-left {
        flex-direction: column;
        width: 100%;
        min-width: 100%;
    }

    .datatable-search-wrapper {
        max-width: 100%;
    }

    .datatable-header-right {
        width: 100%;
        justify-content: space-between;
    }

    .datatable-footer {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .datatable-info {
        text-align: center;
    }

    [data-bs5-pagination] {
        display: flex;
        justify-content: center;
    }

    .bs5-datatable thead th,
    .bs5-datatable tbody td {
        padding: 10px 12px;
        font-size: 13px;
    }

    .bs5-datatable thead th:first-child,
    .bs5-datatable tbody td:first-child {
        padding-left: 16px;
    }

    .bs5-datatable thead th:last-child,
    .bs5-datatable tbody td:last-child {
        padding-right: 16px;
    }
}

/* ============================================
   Utility Classes
   ============================================ */

.text-muted {
    color: #6c757d !important;
}

.text-nowrap {
    white-space: nowrap !important;
}

.fw-semibold {
    font-weight: 600 !important;
}

.fw-medium {
    font-weight: 500 !important;
}

/* ============================================
   Skeleton Loader - Beautiful Loading State
   ============================================ */

.bs5-skeleton-loader {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
    margin-bottom: 24px;
    overflow: hidden;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Skeleton Header */
.bs5-skeleton-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    gap: 12px;
}

.bs5-skeleton-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.bs5-skeleton-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Skeleton Search Box */
.bs5-skeleton-search {
    height: 38px;
    width: 320px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 6px;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Skeleton Length Select */
.bs5-skeleton-length {
    height: 38px;
    width: 70px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 6px;
    animation: shimmer 1.5s infinite;
}

/* Skeleton Buttons */
.bs5-skeleton-button {
    height: 34px;
    width: 100px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 6px;
    animation: shimmer 1.5s infinite;
}

.bs5-skeleton-button.small {
    width: 80px;
}

/* Skeleton Table */
.bs5-skeleton-table {
    width: 100%;
    border-collapse: collapse;
}

.bs5-skeleton-table thead {
    background-color: #f8f9fa;
}

.bs5-skeleton-table thead tr {
    border-bottom: 1px solid #dee2e6;
}

.bs5-skeleton-table thead th {
    padding: 14px 16px;
    text-align: left;
}

.bs5-skeleton-table thead th:first-child {
    padding-left: 24px;
}

.bs5-skeleton-table thead th:last-child {
    padding-right: 24px;
}

.bs5-skeleton-table tbody tr {
    border-bottom: 1px solid #f1f3f5;
}

.bs5-skeleton-table tbody td {
    padding: 16px;
}

.bs5-skeleton-table tbody td:first-child {
    padding-left: 24px;
}

.bs5-skeleton-table tbody td:last-child {
    padding-right: 24px;
}

/* Skeleton Cell Content */
.bs5-skeleton-cell {
    height: 16px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    animation: shimmer 1.5s infinite;
}

.bs5-skeleton-cell.w-100 { width: 100%; }
.bs5-skeleton-cell.w-80 { width: 80%; }
.bs5-skeleton-cell.w-60 { width: 60%; }
.bs5-skeleton-cell.w-40 { width: 40%; }
.bs5-skeleton-cell.w-20 { width: 20%; }

/* Skeleton Footer */
.bs5-skeleton-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    gap: 12px;
}

.bs5-skeleton-info {
    height: 20px;
    width: 200px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    animation: shimmer 1.5s infinite;
}

.bs5-skeleton-pagination {
    display: flex;
    gap: 4px;
}

.bs5-skeleton-page {
    height: 32px;
    width: 38px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 6px;
    animation: shimmer 1.5s infinite;
}

/* Prevent table flash before skeleton loads */
.bs5-datatable-wrapper .dataTables_wrapper {
    min-height: 400px;
}

/* Don't hide tables by default - let JavaScript handle it */
/* This prevents issues with tables not showing if JS fails */

/* Smooth fade-in animation */
@keyframes fadeInTable {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
