/**
 * Smart Data Tables - Frontend Styles
 *
 * @package SmartDataTables\PublicView
 */

/* Container */
.sdt-table {
    width: 100%;
    min-height: 120px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: #1d2327;
    margin: 20px 0;
}

/* Elementor widget wrapper */
.elementor-widget-smart_data_table .sdt-table {
    margin: 0;
}

.sdt-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Loading State */
.sdt-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #6c7781;
    background: #f6f7f7;
    border: 1px solid #dcdcde;
    border-radius: 4px;
}

.sdt-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f0f0f1;
    border-top-color: #2271b1;
    border-radius: 50%;
    animation: sdt-spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes sdt-spin {
    to {
        transform: rotate(360deg);
    }
}

.sdt-loading p {
    margin: 0;
    font-size: 14px;
}

/* Error State */
.sdt-error {
    padding: 20px;
    color: #d63638;
    background: #fcf0f1;
    border: 1px solid #d63638;
    border-radius: 4px;
}

.sdt-error p {
    margin: 0;
}

/* Empty State */
.sdt-empty {
    padding: 40px;
    text-align: center;
    color: #6c7781;
    background: #f6f7f7;
    border: 1px solid #dcdcde;
    border-radius: 4px;
}

.sdt-empty p {
    margin: 0;
    font-size: 16px;
}

/* Global Search */
.sdt-search {
    margin-bottom: 16px;
}

.sdt-search-input {
    width: 100%;
    max-width: 400px;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    background: #fff;
    transition: border-color 0.2s;
}

.sdt-search-input:focus {
    outline: none;
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
}

/* Table */
.sdt-table-main {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    overflow: hidden;
}

/* Ensure table cells don't wrap unnecessarily on mobile/tablet */
@media (max-width: 992px) {
    .sdt-table-main th,
    .sdt-table-main td {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 300px; /* Maximum width before ellipsis */
    }
}

/* Allow wrapping on larger screens if needed */
@media (min-width: 993px) {
    .sdt-table-main th,
    .sdt-table-main td {
        white-space: normal; /* Allow wrapping on desktop */
        max-width: none;
    }
}

.sdt-table-main thead {
    background: #2271b1;
}

.sdt-table-main thead th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: #fff;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    position: relative;
    cursor: pointer;
    user-select: none;
}

.sdt-table-main thead th:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sdt-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sdt-header-text {
    flex: 1;
}

.sdt-sort-icon {
    display: inline-block;
    font-size: 12px;
    opacity: 0.7;
    transition: opacity 0.2s;
    min-width: 16px;
    text-align: center;
}

.sdt-sortable:hover .sdt-sort-icon {
    opacity: 1;
}

.sdt-sort-icon.sdt-sort-asc,
.sdt-sort-icon.sdt-sort-desc {
    opacity: 1;
    font-weight: bold;
}

.sdt-sort-icon.sdt-sort-none {
    opacity: 0.5;
}

.sdt-table-main tbody tr {
    border-bottom: 1px solid #c3c4c7;
    transition: background-color 0.2s;
}

.sdt-table-main tbody tr:last-child {
    border-bottom: none;
}

.sdt-table-main tbody tr:nth-child(even) {
    background: #f6f7f7;
}

.sdt-table-main tbody tr:hover {
    background: #f0f0f1;
}

.sdt-table-main td {
    padding: 12px;
    border-right: 1px solid #c3c4c7;
}

.sdt-table-main td:last-child {
    border-right: none;
}

/* Sorting icons are handled above */

/* Pagination */
.sdt-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding: 16px;
    background: #f6f7f7;
    border: 1px solid #dcdcde;
    border-radius: 4px;
    flex-wrap: wrap;
    gap: 12px;
}

.sdt-pagination-info {
    color: #6c7781;
    font-size: 14px;
}

.sdt-pagination-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.sdt-pagination-btn {
    padding: 6px 12px;
    font-size: 14px;
    color: #2271b1;
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 36px;
}

.sdt-pagination-btn:hover {
    background: #f0f0f1;
    border-color: #2271b1;
}

.sdt-pagination-btn.active {
    background: #2271b1;
    color: #fff;
    border-color: #2271b1;
}

.sdt-pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sdt-pagination-ellipsis {
    padding: 6px 8px;
    color: #6c7781;
}

/* Responsive - Horizontal Scroll on All Devices */

/* Mobile devices (up to 576px) */
@media (max-width: 576px) {
    .sdt-table {
        margin: 10px 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    .sdt-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    .sdt-table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    .sdt-table-main {
        font-size: 12px;
        min-width: 600px; /* Minimum width to ensure columns don't compress too much */
        width: 100%;
    }

    .sdt-table-main th,
    .sdt-table-main td {
        padding: 8px;
        white-space: nowrap; /* Prevent text wrapping in cells */
    }

    .sdt-pagination {
        flex-direction: column;
        align-items: stretch;
        padding: 12px;
    }

    .sdt-pagination-info {
        text-align: center;
        margin-bottom: 10px;
        font-size: 12px;
    }

    .sdt-pagination-controls {
        justify-content: center;
        flex-wrap: wrap;
        gap: 4px;
    }

    .sdt-pagination-btn {
        padding: 8px 12px;
        font-size: 13px;
        min-width: 40px;
    }

    .sdt-search-input {
        max-width: 100%;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Tablet devices (577px to 768px) */
@media (min-width: 577px) and (max-width: 768px) {
    .sdt-table {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    .sdt-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    .sdt-table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    .sdt-table-main {
        font-size: 13px;
        min-width: 700px; /* Minimum width for tablet */
        width: 100%;
    }

    .sdt-table-main th,
    .sdt-table-main td {
        padding: 10px;
        white-space: nowrap; /* Prevent text wrapping */
    }

    .sdt-pagination {
        flex-wrap: wrap;
        padding: 14px;
    }

    .sdt-pagination-controls {
        gap: 6px;
    }

    .sdt-pagination-btn {
        padding: 7px 14px;
        font-size: 13px;
    }

    .sdt-search-input {
        max-width: 100%;
    }
}

/* Small desktop (769px to 992px) */
@media (min-width: 769px) and (max-width: 992px) {
    .sdt-table-main {
        font-size: 13px;
    }

    .sdt-table-main th,
    .sdt-table-main td {
        padding: 11px;
    }
}

/* Responsive table wrapper for horizontal scroll - applies to all screen sizes */
.sdt-table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    position: relative;
}

.sdt-table-responsive .sdt-table-main {
    min-width: 100%; /* Will expand based on content */
}

/* Ensure wrapper handles overflow correctly */
.sdt-wrapper.sdt-table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Add scrollbar styling for better UX */
.sdt-table-responsive::-webkit-scrollbar,
.sdt-wrapper::-webkit-scrollbar {
    height: 8px;
}

.sdt-table-responsive::-webkit-scrollbar-track,
.sdt-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.sdt-table-responsive::-webkit-scrollbar-thumb,
.sdt-wrapper::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.sdt-table-responsive::-webkit-scrollbar-thumb:hover,
.sdt-wrapper::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Print Styles */
@media print {
    .sdt-search,
    .sdt-filter,
    .sdt-pagination {
        display: none;
    }

    .sdt-table-main {
        border: 1px solid #000;
    }

    .sdt-table-main thead th {
        background: #000 !important;
        color: #fff !important;
    }
}
