/* Table Styles */

/* ============================================
   Table Container avec Scroll Horizontal
   ============================================ */

.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--white);
}

/* Indicateur de scroll à gauche */
.table-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    background: linear-gradient(to right, rgba(0,0,0,0.06), transparent);
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 6;
}

/* Indicateur de scroll à droite */
.table-container::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    background: linear-gradient(to left, rgba(0,0,0,0.06), transparent);
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 6;
}

.table-container.can-scroll-left::before { opacity: 1; }
.table-container.can-scroll-right::after { opacity: 1; }

/* ============================================
   Table Layout
   ============================================ */

.contacts-table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

/* ============================================
   Table Headers avec Resize
   ============================================ */

th {
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--gray-50);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
    min-width: 100px;
}

th:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

/* Handle de redimensionnement */
.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    background: transparent;
    z-index: 12;
    transition: background 0.15s ease;
}

.resize-handle:hover {
    background: var(--primary-light);
}

.resize-handle.resizing {
    background: var(--primary);
}

/* Pendant le redimensionnement */
body.resizing-column {
    cursor: col-resize !important;
    user-select: none !important;
}

body.resizing-column * {
    cursor: col-resize !important;
    user-select: none !important;
}

/* Première colonne - largeur minimale */
.contacts-table th:first-child,
.contacts-table td:first-child {
    min-width: 180px;
}

/* ============================================
   Cellules avec Overflow
   ============================================ */

.contacts-table td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

/* Sort Icons */
th .sort-icon {
    display: inline-block;
    margin-left: 4px;
    opacity: 0.4;
    font-size: 10px;
}

th.sort-asc .sort-icon,
th.sort-desc .sort-icon {
    opacity: 1;
    color: var(--primary);
}

th.sort-asc .sort-icon::after { content: '\25B2'; }
th.sort-desc .sort-icon::after { content: '\25BC'; }
th:not(.sort-asc):not(.sort-desc) .sort-icon::after { content: '\21C5'; }

/* Non-sortable columns */
th.no-sort {
    cursor: default;
}

th.no-sort:hover {
    background: var(--gray-50);
    color: var(--gray-500);
}

/* ============================================
   Vendeur Legend + Period Filter Bar
   ============================================ */

.vendeur-legend-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 0;
    margin-bottom: 8px;
}

.vendeur-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.vendeur-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--gray-600);
    white-space: nowrap;
}

.vendeur-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Period quick filter */
.period-filter {
    display: flex;
    gap: 4px;
}

.period-filter-btn {
    padding: 5px 12px;
    border: 1px solid var(--gray-300);
    background: var(--white);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.period-filter-btn:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
    color: var(--gray-800);
}

.period-filter-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

/* ============================================
   Table Rows
   ============================================ */

tbody tr {
    transition: background 0.1s ease;
    cursor: pointer;
}

tbody tr:hover td {
    background: var(--gray-50);
}

tbody tr.selected td {
    background: rgba(79, 70, 229, 0.08);
}

/* Cell types */
td.text-muted {
    color: var(--gray-500);
}

td.numeric {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* ============================================
   Contact Cell avec Avatar
   ============================================ */

.contact-cell {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 180px;
}

.contact-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--white);
    flex-shrink: 0;
    background: var(--primary);
}

.contact-avatar.has-image {
    background: none;
}

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

.contact-info {
    min-width: 0;
    flex: 1;
}

.contact-name {
    font-weight: 500;
    color: var(--gray-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-company {
    font-size: 12px;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   Email and Phone Cells
   ============================================ */

.email-cell, .phone-cell {
    font-size: 13px;
    min-width: 140px;
}

.email-cell a, .phone-cell a {
    color: var(--gray-700);
    text-decoration: none;
}

.email-cell a:hover, .phone-cell a:hover {
    color: var(--primary);
}

/* ============================================
   Status Badges
   ============================================ */

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.status-badge.active {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.status-badge.inactive {
    background: rgba(156, 163, 175, 0.1);
    color: var(--gray-500);
}

.status-badge.pending {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

/* ============================================
   Table Footer
   ============================================ */

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    flex-wrap: wrap;
    gap: 16px;
}

.table-info {
    font-size: 13px;
    color: var(--gray-500);
}

/* ============================================
   Pagination
   ============================================ */

.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pagination-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--gray-300);
    background: var(--white);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--gray-700);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.pagination-ellipsis {
    padding: 0 8px;
    color: var(--gray-400);
}

/* Per page selector */
.per-page {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--gray-600);
}

.per-page select {
    padding: 6px 10px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--white);
    cursor: pointer;
}

/* ============================================
   Responsive - Tablet
   ============================================ */

@media (max-width: 768px) {
    .vendeur-legend-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .period-filter {
        flex-wrap: wrap;
    }

    .period-filter-btn {
        padding: 4px 10px;
        font-size: 11px;
    }

    th, td {
        padding: 10px 12px;
        font-size: 13px;
    }

    .table-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .pagination {
        justify-content: center;
    }

    .per-page {
        justify-content: center;
    }

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

/* ============================================
   Responsive - Mobile
   ============================================ */

@media (max-width: 480px) {
    th, td {
        padding: 8px 10px;
        font-size: 12px;
    }

    .contact-avatar {
        width: 30px;
        height: 30px;
        font-size: 11px;
    }

    .contact-cell {
        gap: 8px;
        min-width: 150px;
    }

    .pagination-btn {
        min-width: 32px;
        height: 32px;
        padding: 0 8px;
        font-size: 12px;
    }

    .resize-handle {
        width: 10px;
    }
}
