/* Global box-sizing reset for consistent cross-browser rendering */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* CSS Custom Properties for Theming */
:root {
    /* Colors */
    --at-primary: #3498db;
    --at-primary-light: #e3f2fd;
    --at-primary-dark: #2980b9;
    --at-secondary: #f8f8f8;
    --at-border: #e0e0e0;
    --at-text: #333;
    --at-text-light: #666;
    --at-error: #c62828;
    --at-error-bg: #ffebee;
    --at-success: #2e7d32;
    --at-success-bg: #e8f5e9;
    
    /* Spacing */
    --at-spacing-xs: 4px;
    --at-spacing-sm: 8px;
    --at-spacing-md: 12px;
    --at-spacing-lg: 20px;
    
    /* Borders */
    --at-border-radius-sm: 4px;
    --at-border-radius-md: 8px;
    --at-border-width: 1px;
    --at-shadow: 0 4px 8px rgba(0,0,0,0.05);
    
    /* Typography */
    --at-font-family: 'Inter', Tahoma, Arial, sans-serif;
    --at-font-size-sm: 0.875rem;
    --at-font-size-md: 1rem;
    --at-font-size-lg: 1.125rem;
    
    /* Transitions */
    --at-transition-fast: 0.2s ease-in-out;
    --at-transition-med: 0.3s ease-in-out;
    
    /* Layout */
    --min-width-tablet: 768px;
}

/* Controls styling */
.agent-table-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--at-spacing-lg);
    gap: var(--at-spacing-lg);
    flex-wrap: wrap;
}

.agent-table-search {
    flex: 1;
    max-width: 400px;
    padding: var(--at-spacing-sm) var(--at-spacing-md);
    border: var(--at-border-width) solid var(--at-border);
    border-radius: var(--at-border-radius-sm);
    font-size: var(--at-font-size-sm);
    font-family: var(--at-font-family);
    transition: border-color var(--at-transition-fast);
}

.agent-table-search:focus {
    outline: none;
    border-color: var(--at-primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.agent-table-search::placeholder {
    color: var(--at-text-light);
    opacity: 0.7;
}

.rows-per-page {
    display: flex;
    align-items: center;
    gap: var(--at-spacing-sm);
}

.rows-per-page label {
    font-size: var(--at-font-size-sm);
    color: var(--at-text-light);
    white-space: nowrap;
    cursor: default; /* Ensures the default cursor is shown */
    user-select: none; /* Prevents text selection on repeated clicks */
}

.agent-table-rows {
    padding: var(--at-spacing-sm);
    border: var(--at-border-width) solid var(--at-border);
    border-radius: var(--at-border-radius-sm);
    font-size: var(--at-font-size-sm);
    font-family: var(--at-font-family);
    background-color: white;
    cursor: pointer;
    transition: border-color var(--at-transition-fast);
}

.agent-table-rows:focus {
    outline: none;
    border-color: var(--at-primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.agent-table-rows:hover {
    border-color: var(--at-primary-dark);
}

/* Pagination styling */
.agent-table-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    background: white;
    margin-top: var(--at-spacing-lg);
    padding: var(--at-spacing-md) var(--at-spacing-lg);
    border: 1px solid var(--at-border);
    border-radius: var(--at-border-radius-md);
    box-shadow: var(--at-shadow);
}

/* Hide pagination when printing */
@media print {
    .agent-table-pagination {
        display: none;
    }
}

.pagination-button {
    padding: 8px 16px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.pagination-button:hover {
    background: #f5f5f5;
}

.pagination-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.page-numbers {
    display: flex;
    gap: 5px;
}

.page-number {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    min-width: 35px;
    text-align: center;
}

.page-number.active {
    background: #e3f2fd;
    border-color: #90caf9;
}

/* Loading state styling */
.table-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.table-error-message {
    background-color: #ffebee;
    color: #c62828;
    padding: 12px;
    margin: 10px 0;
    border-radius: 4px;
    border-left: 4px solid #c62828;
    font-size: 14px;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* General table styling */
.agent-table-wrapper {
    position: relative;
    margin-top: var(--at-spacing-lg);
    margin-bottom: var(--at-spacing-lg);
}

.agent-table-container {
    position: relative; /* For loading overlay positioning */
    border-radius: var(--at-border-radius-md);
    box-shadow: var(--at-shadow);
    background-color: white;
    
    /* Improved horizontal scrolling */
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--at-primary) transparent; /* Firefox */
    
    /* Add scroll shadows */
    background-image: 
        linear-gradient(to right, white 30%, rgba(255, 255, 255, 0)),
        linear-gradient(to left, white 30%, rgba(255, 255, 255, 0));
    background-position: left center, right center;
    background-repeat: no-repeat;
    background-size: 20px 100%, 20px 100%;
    background-attachment: local, local;
}

/* Customizing scrollbar for WebKit browsers */
.agent-table-container::-webkit-scrollbar {
    height: 8px;
}

.agent-table-container::-webkit-scrollbar-track {
    background: var(--at-secondary);
    border-radius: var(--at-border-radius-sm);
}

.agent-table-container::-webkit-scrollbar-thumb {
    background-color: var(--at-primary);
    border-radius: var(--at-border-radius-sm);
    border: 2px solid var(--at-secondary);
}

.agent-table-container::-webkit-scrollbar-thumb:hover {
    background-color: var(--at-primary-dark);
}
.agent-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--at-font-family);
    table-layout: fixed; /* Fixed table layout for better control */
    
    /* Set a consistent minimum width to ensure all columns are visible */
    min-width: 800px; /* Minimum width to accommodate all columns comfortably */
}

/* Define column widths - optimized for readability across all devices */
.agent-table th:nth-child(1) { width: 60px; }   /* ردیف - fixed width */
.agent-table th:nth-child(2) { width: 180px; }  /* نام نماینده - fixed width */
.agent-table th:nth-child(3) { width: 120px; }  /* استان - fixed width */
.agent-table th:nth-child(4) { width: 120px; }  /* شهر - fixed width */
.agent-table th:nth-child(5) { width: 120px; }  /* تلفن - fixed width */
.agent-table th:nth-child(6) { width: 200px; }  /* آدرس - fixed width */

/* Ensure all cells maintain their width and handle overflow properly */
.agent-table th,
.agent-table td {
    min-width: 0;
    max-width: none;
    border: 1px solid #e0e0e0;
    padding: 15px 10px;
    text-align: right;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.agent-table th {
    background-color: #f8f8f8; /* Light gray background for headers */
    font-weight: bold;
    color: #333;
    text-transform: uppercase; /* Optional: Make headers uppercase */
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    transition: background-color 0.2s ease-in-out;
}

/* Highlight for sorted column */
.agent-table.highlight-col-0 tr td:nth-child(1),
.agent-table.highlight-col-0 tr th:nth-child(1),
.agent-table.highlight-col-1 tr td:nth-child(2),
.agent-table.highlight-col-1 tr th:nth-child(2),
.agent-table.highlight-col-2 tr td:nth-child(3),
.agent-table.highlight-col-2 tr th:nth-child(3),
.agent-table.highlight-col-3 tr td:nth-child(4),
.agent-table.highlight-col-3 tr th:nth-child(4),
.agent-table.highlight-col-4 tr td:nth-child(5),
.agent-table.highlight-col-4 tr th:nth-child(5),
.agent-table.highlight-col-5 tr td:nth-child(6),
.agent-table.highlight-col-5 tr th:nth-child(6) {
    background-color: #e3f2fd !important;
    transition: background-color 0.2s ease-in-out;
}
.agent-table tbody tr:nth-child(odd) {
    background-color: white;
}

.agent-table tbody tr:nth-child(even) {
    background-color: var(--at-secondary);
}

.agent-table tbody tr:hover {
    background-color: var(--at-primary-light);
    transition: background-color var(--at-transition-fast);
}

.agent-table td {
    color: var(--at-text);
    font-size: var(--at-font-size-sm);
    transition: background-color var(--at-transition-fast);
}

/* Row highlight animation */
.agent-table tbody tr.highlight-new {
    animation: highlightRow var(--at-transition-med);
}

@keyframes highlightRow {
    0% { background-color: var(--at-success-bg); }
    100% { background-color: transparent; }
}

/* Print styles */
@media print {
    .agent-table-controls,
    .agent-table-pagination,
    .sort-icon {
        display: none !important;
    }

    .agent-table-container {
        box-shadow: none;
        margin: 0;
        padding: 0;
    }

    .agent-table {
        width: 100% !important;
        min-width: unset !important;
        border-collapse: collapse !important;
    }

    .agent-table th,
    .agent-table td {
        border: 1px solid #000 !important;
        padding: 0.5cm !important;
        font-size: 10pt !important;
    }

    .agent-table th {
        background-color: #f0f0f0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    @page {
        margin: 1cm;
    }
}

/* Add scroll indicators */
.agent-table-container::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 60px;
    height: 100%;
    background: linear-gradient(to left, 
        rgba(255,255,255,0.9) 0%,
        rgba(255,255,255,0) 100%);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--at-transition-fast);
}

.agent-table-container.has-more-content::after {
    opacity: 1;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .agent-table-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .agent-table-search {
        max-width: none;
    }

    .rows-per-page {
        justify-content: flex-end;
    }

    .agent-table {
        min-width: var(--min-width-tablet);
    }
}

@media (max-width: 768px) {
    :root {
        --at-spacing-lg: 15px;
        --at-spacing-md: 10px;
        --at-spacing-sm: 6px;
    }

    /* Adjust column widths for mobile */
    .agent-table th:nth-child(1) { width: 50px; }   /* ردیف - smaller */
    .agent-table th:nth-child(2) { width: 140px; }  /* نام نماینده - smaller */
    .agent-table th:nth-child(3) { width: 100px; }  /* استان - smaller */
    .agent-table th:nth-child(4) { width: 100px; }  /* شهر - smaller */
    .agent-table th:nth-child(5) { width: 100px; }  /* تلفن - smaller */
    .agent-table th:nth-child(6) { width: 150px; }  /* آدرس - smaller */

    .agent-table th,
    .agent-table td {
        padding: var(--at-spacing-sm) var(--at-spacing-md);
        font-size: var(--at-font-size-sm);
    }

    /* Improved cell content handling for touch devices */
    .agent-table td {
        position: relative;
    }

    /* Show full content on tap/click for mobile */
    .agent-table td:active,
    .agent-table td:focus {
        white-space: normal;
        overflow: visible;
        position: relative;
        z-index: 1;
        background-color: var(--at-primary-light);
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        min-width: 200px;
    }

    .page-numbers {
        gap: var(--at-spacing-xs);
    }

    .page-number {
        padding: var(--at-spacing-sm);
        min-width: 30px;
    }

    /* Add hint for horizontal scroll */
    .agent-table-container::before {
        content: attr(data-scroll-hint);
        position: absolute;
        bottom: -25px;
        right: 0;
        font-size: var(--at-font-size-sm);
        color: var(--at-text-light);
        opacity: 0.8;
        pointer-events: none;
    }
}

@media (max-width: 480px) {
    .agent-table th,
    .agent-table td {
        font-size: calc(var(--at-font-size-sm) - 0.1rem);
        padding: var(--at-spacing-xs) var(--at-spacing-sm);
    }

    /* Further reduce column widths for micro screens */
    .agent-table th:nth-child(1) { width: 40px; }   /* ردیف */
    .agent-table th:nth-child(2) { width: 100px; }  /* نام نماینده */
    .agent-table th:nth-child(3) { width: 80px; }   /* استان */
    .agent-table th:nth-child(4) { width: 80px; }   /* شهر */
    .agent-table th:nth-child(5) { width: 80px; }   /* تلفن */
    .agent-table th:nth-child(6) { width: 120px; }  /* آدرس */

    .pagination-button {
        padding: var(--at-spacing-sm);
        font-size: var(--at-font-size-sm);
    }

    .agent-table-controls {
        gap: var(--at-spacing-md);
    }

    /* Stack search and rows per page on very small screens */
    .rows-per-page {
        flex-wrap: wrap;
        justify-content: flex-start;
    }
}

/* Empty state styling */
.empty-state {
    background: none !important;
}

.empty-state-message {
    text-align: center;
    padding: var(--at-spacing-lg) var(--at-spacing-md);
    color: var(--at-text-light);
}

.empty-state-message .empty-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: var(--at-spacing-md);
}

.empty-state-message p {
    margin: var(--at-spacing-sm) 0;
    font-size: var(--at-font-size-md);
}

.empty-state-message .empty-state-hint {
    font-size: var(--at-font-size-sm);
    color: var(--at-primary);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --at-primary: #64b5f6;
        --at-primary-light: rgba(100, 181, 246, 0.2);
        --at-primary-dark: #42a5f5;
        --at-secondary: #2c2c2c;
        --at-border: #404040;
        --at-text: #e0e0e0;
        --at-text-light: #a0a0a0;
        --at-error: #ef5350;
        --at-error-bg: rgba(239, 83, 80, 0.2);
        --at-success: #81c784;
        --at-success-bg: rgba(129, 199, 132, 0.2);
    }

    .agent-table-container {
        background-color: #1c1c1c;
    }

    .agent-table tbody tr:nth-child(odd) {
        background-color: #1c1c1c;
    }

    .agent-table tbody tr:nth-child(even) {
        background-color: #242424;
    }

    .agent-table-search,
    .agent-table-rows {
        background-color: #2c2c2c;
        color: var(--at-text);
    }
}