/* Modern Corporate Dashboard Design */
:root {
    --primary-color: #d4af37; /* Guinness Gold */
    --primary-dark: #b8941f;
    --accent-color: #e3691e; /* Guinness Red */
    --accent-dark: #c4581e;
    --text-primary: #1a1a1a;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --background: #f8fafc;
    --background-secondary: #f1f5f9;
    --white: #ffffff;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 14px;
    overflow-x: hidden;
}

/* Floating Navbar */
.navbar-floating {
    position: fixed;
    top: 20px;
    left: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.navbar-floating:hover {
    box-shadow: var(--shadow-xl);
    transform: translateY(-1px);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.navbar-brand h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0;
}

.navbar-menu {
    display: flex;
    list-style: none;
    gap: 8px;
    margin: 0;
    padding: 0;
}

.navbar-link {
    padding: 8px 16px;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s ease;
    position: relative;
}

.navbar-link:hover {
    color: var(--primary-color);
    background: rgba(212, 175, 55, 0.1);
}

.navbar-link.active {
    color: var(--primary-color);
    background: rgba(212, 175, 55, 0.15);
    font-weight: 600;
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

.logout-btn {
    padding: 6px 12px;
    background: var(--background-secondary);
    color: var(--text-primary);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    background: var(--accent-color);
    color: var(--white);
}

/* Main Layout */
.admin-layout, .supervisor-layout {
    min-height: 100vh;
    padding-top: 100px;
}

.admin-main, .supervisor-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px 40px;
}

/* Page Header */
.page-header {
    margin-bottom: 32px;
    text-align: center;
}

.page-header h1 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.025em;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 16px;
    max-width: 600px;
    margin: 0 auto;
}

/* KPI Section */
.kpi-section {
    margin-bottom: 32px;
}

.kpi-grid-simple {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.kpi-grid-wide {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.kpi-card {
    background: #1a1a1a;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    border: 1px solid #333333;
    transition: all 0.2s ease;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.kpi-card:hover {
    box-shadow: 0 4px 16px rgba(212, 175, 55, 0.2);
    transform: translateY(-2px);
    border-color: var(--primary-color);
}

.kpi-card h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-value {
    font-size: 32px;
    font-weight: 700;
    color: #ffffff;
    margin: 8px 0;
    line-height: 1;
}

.kpi-subtitle {
    font-size: 12px;
    color: #cccccc;
    margin-top: 4px;
}

/* Progress bar horizontal simple */
.kpi-progress-simple {
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 16px;
}

.kpi-progress-simple .kpi-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    transition: width 0.3s ease;
    border-radius: 4px;
}

/* Table container fix */
.table-container {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    max-height: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--white);
    position: relative;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on mobile */
}

.table-container table {
    width: 100%;
    min-width: 1200px; /* Augmenté pour forcer le scroll */
    border-collapse: collapse;
}

/* Ensure table cells don't wrap */
.table-container td,
.table-container th {
    white-space: nowrap;
    padding: 12px 16px;
    text-overflow: ellipsis;
    max-width: 200px;
    overflow: hidden;
}

/* Make sure parent containers don't interfere */
.table-section {
    width: 100%;
    overflow: visible;
}

.supervisor-main,
.admin-main {
    width: 100%;
    overflow-x: visible;
}

/* Top agents simple */
.top-agents-simple {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.top-agent-simple {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.agent-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.agent-rank {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 24px;
}

.agent-name {
    font-weight: 500;
    color: #ffffff;
}

.agent-count {
    font-weight: 600;
    color: var(--primary-color);
    background: rgba(212, 175, 55, 0.2);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 768px) {
    .kpi-grid-simple {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .kpi-grid-wide {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .kpi-card {
        padding: 20px;
        min-height: 100px;
    }
    
    .kpi-value {
        font-size: 28px;
    }
}

/* Filters Section */
.filters-section {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 32px;
    box-shadow: var(--shadow-sm);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.section-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.section-actions {
    display: flex;
    gap: 12px;
}

/* Buttons (corporate minimal) */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid transparent;
    transition: all .15s ease;
    font-family: inherit;
    font-size: 14px;
}
.btn-primary {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}
.btn-primary:hover { filter: brightness(0.95); }
.btn-accent {
    background: var(--accent-color);
    color: #fff;
    border-color: var(--accent-color);
}
.btn-accent:hover { filter: brightness(0.96); }
.btn-outline {
    background: #fff;
    color: var(--text-primary);
    border-color: var(--border);
}
.btn-outline:hover {
    background: var(--background-secondary);
    border-color: #cbd5e1;
}
.btn-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover { filter: brightness(0.95); }

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-select, .form-input {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.2s ease;
}

.form-select:focus, .form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
}

/* Table Section */
.table-section {
    background: var(--white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: visible; /* allow menus to show outside table */
    margin-bottom: 32px;
    padding: 24px;
}

.table-container {
    overflow-x: auto;
    position: relative;
    padding: 0; /* no padding inside table container */
}

/* Modern table styling (TanStack-compatible) */
.table-wrapper table,
.tanstack-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    font-size: 14px;
}

.tanstack-table thead th {
    padding: 14px 16px;
    text-align: left;
    font-weight: 700;
    color: var(--text-primary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    position: relative; /* to position sort icon */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 26px; /* room for sort icon */
}
.tanstack-table thead .sort-indicator {
    line-height: 1;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
}

/* Responsive typography and spacing for tables */
@media (max-width: 1200px) {
  .tanstack-table th { font-size: 11px; padding: 12px 12px; }
  .tanstack-table td { font-size: 13px; padding: 12px 12px; }
}
@media (max-width: 992px) {
  .tanstack-table th { font-size: 10px; padding: 10px 10px; }
  .tanstack-table td { font-size: 12.5px; padding: 10px 10px; }
}
@media (max-width: 768px) {
  .tanstack-table { font-size: 12px; }
  .tanstack-table th { font-size: 10px; letter-spacing: 0.04em; }
  .tanstack-table td { font-size: 12px; }
}
@media (max-width: 600px) {
  .tanstack-table th { font-size: 9.5px; padding: 8px 8px; }
  .tanstack-table td { font-size: 11.5px; padding: 8px 8px; }
}

.tanstack-table .sort-icon,
.tanstack-table .sort-indicator {
    margin-left: 6px;
    font-size: 12px;
    opacity: .7;
}

.table-compact td, .table-compact th { padding: 10px 14px; }
.table-compact tbody tr:hover { background: rgba(0,0,0,0.02); }

.tanstack-table td {
    padding: 14px 16px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-primary);
    vertical-align: middle;
}

.tanstack-table tbody tr:last-child td { border-bottom: none; }
.cell-actions { text-align: right; white-space: nowrap; }
.tanstack-table td.cell-actions,
.data-table td.cell-actions,
.table-container td.cell-actions {
    overflow: visible !important; /* allow dropdowns to overflow cell */
    position: relative;
}

/* Three-dots action menu */
.action-menu { position: relative; display: inline-block; }
.menu-button {
    width: 32px; height: 32px;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    line-height: 1; display: inline-flex; align-items: center; justify-content: center;
    transition: all .15s ease;
}
.menu-button:hover { background: #f8fafc; color: var(--text-primary); border-color: #cbd5e1; }
.menu-dropdown {
    position: absolute; right: 0; top: calc(100% + 6px);
    min-width: 180px; background: var(--white);
    border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: 8px; display: none; z-index: 5000; /* ensure on top */
}
.menu-dropdown.open { display: block; }
.menu-item {
    width: 100%; display: block;
    text-align: left; padding: 10px 12px;
    border: 0; background: transparent; color: var(--text-primary);
    border-radius: 8px; cursor: pointer; text-decoration: none;
    font-size: 14px;
}
.menu-item:hover { background: #f8fafc; }
.menu-item.danger { color: #dc2626; }
.menu-item.danger:hover { background: rgba(220,38,38,0.08); }

/* Utility sizes (minimal Tailwind-like) used by inline SVGs */
.w-4 { width: 1rem !important; }
.h-4 { height: 1rem !important; }
.mr-2 { margin-right: 0.5rem !important; }

/* Ensure menu icons are compact even without utility classes */
.menu-item svg { width: 16px; height: 16px; margin-right: 8px; flex: 0 0 auto; }
.action-menu .menu-button svg { width: 16px; height: 16px; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: var(--white);
}

.data-table thead {
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
}

.data-table th {
    padding: 20px 16px;
    text-align: left;
    font-weight: 700;
    color: #374151;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: none;
    white-space: nowrap;
    position: relative;
}

.data-table th:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 25%;
    height: 50%;
    width: 1px;
    background: #e5e7eb;
}

.data-table td {
    padding: 16px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-primary);
    vertical-align: middle;
    font-size: 14px;
    line-height: 1.5;
}

.data-table tbody tr {
    transition: all 0.2s ease;
}

.data-table tbody tr:hover {
    background-color: #f8fafc;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Status badges */
.status-badge {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.pill {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 6px;
    font-size: 10px;
    border-radius: 999px;
    line-height: 1.2;
    border: 1px solid transparent;
}
.pill-new {
    background: #eef2ff;
    color: #3730a3;
    border-color: #c7d2fe;
}

/* Small numeric badge for tabs */
.badge {
    display: inline-block;
    margin-left: 6px;
    min-width: 18px;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 11px;
    background: #f3f4f6;
    color: #111827;
    border: 1px solid #e5e7eb;
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-badge.cree {
    background-color: #fef7ed;
    color: #ea580c;
    border-color: #fed7aa;
}

.status-badge.cree::before {
    background-color: #ea580c;
}

.status-badge.recense {
    background-color: #f0fdf4;
    color: #16a34a;
    border-color: #bbf7d0;
}

.status-badge.recense::before {
    background-color: #16a34a;
}

.status-badge.theorique {
    background-color: #f9fafb;
    color: #6b7280;
    border-color: #e5e7eb;
}

.status-badge.theorique::before {
    background-color: #6b7280;
}

/* Action buttons */
.action-btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 80px;
    justify-content: center;
}

.action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.action-btn.details {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    border: 1px solid #2563eb;
}

.action-btn.details:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 32px;
    background: var(--white);
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.pagination-info {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.pagination-info strong {
    color: var(--text-primary);
    font-weight: 600;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-btn {
    padding: 10px 16px;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pagination-btn:hover:not(:disabled) {
    background-color: #f8fafc;
    border-color: #cbd5e1;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #f9fafb;
}

.pagination-btn.active {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    border-color: #2563eb;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.pagination-btn.active:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

/* Page numbers */
.page-numbers {
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-ellipsis {
    padding: 10px 8px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Loading state */
.table-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #f3f4f6;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 12px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.table-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.table-empty-icon {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: 16px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .navbar-floating {
        left: 12px;
        right: 12px;
        top: 12px;
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .navbar-menu {
        order: 3;
        width: 100%;
        justify-content: center;
        margin-top: 8px;
        padding-top: 12px;
        border-top: 1px solid var(--border-light);
    }
    
    .admin-layout, .supervisor-layout {
        padding-top: 140px;
    }
    
    .admin-main, .supervisor-main {
        padding: 0 16px 40px;
    }
    
    .page-header h1 {
        font-size: 24px;
    }
    
    .kpi-grid-simple {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .filters-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }
    
    .section-actions {
        justify-content: center;
    }
    
    .data-table {
        font-size: 13px;
    }
    
    .data-table th,
    .data-table td {
        padding: 12px 8px;
    }
}

@media (max-width: 600px) {
    .navbar-floating {
        left: 8px;
        right: 8px;
        top: 8px;
        padding: 10px 12px;
    }
    
    .admin-main, .supervisor-main {
        padding: 0 12px 40px;
    }
    
    .filters-section,
    .table-section {
        padding: 16px;
    }
    
    .kpi-card {
        padding: 20px;
    }
    
    .kpi-value {
        font-size: 28px;
    }
    
    .kpi-full-width .kpi-card {
        padding: 24px 16px;
    }
    
    .kpi-full-width .kpi-value {
        font-size: 36px;
    }
}

/* Tables */
.table-container {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: visible; /* allow dropdowns to escape */
    margin-top: 24px;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border);
    background: var(--background);
}

.table-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.table-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.table-wrapper {
    overflow-x: auto;
    max-height: 600px;
    overflow-y: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: var(--white);
}

.data-table thead {
    background: var(--background);
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table th {
    padding: 16px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.data-table th:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.data-table th.sortable::after {
    content: '↕';
    position: absolute;
    right: 8px;
    opacity: 0.4;
    font-size: 10px;
}

.data-table th.sort-asc::after {
    content: '↑';
    opacity: 1;
    color: var(--primary-color);
}

.data-table th.sort-desc::after {
    content: '↓';
    opacity: 1;
    color: var(--primary-color);
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: all 0.2s ease;
}

.data-table tbody tr:hover {
    background: var(--hover-bg);
}

.data-table tbody tr:last-child {
    border-bottom: none;
}

.data-table td {
    padding: 16px 12px;
    color: var(--text-primary);
    vertical-align: middle;
    line-height: 1.4;
}

.data-table.analyse-table td {
    font-size: 13px;
}

.text-mono {
    font-family: 'Roboto Mono', 'Fira Code', 'SFMono-Regular', Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    letter-spacing: 0.02em;
}

.diag-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid transparent;
    text-transform: none;
}

.diag-pill.success {
    background: #dcfce7;
    color: #166534;
    border-color: #bbf7d0;
}

.diag-pill.warning {
    background: #fef9c3;
    color: #854d0e;
    border-color: #fde68a;
}

.diag-pill.danger {
    background: #fee2e2;
    color: #b91c1c;
    border-color: #fecaca;
}

.diag-pill.alert {
    background: #ede9fe;
    color: #5b21b6;
    border-color: #ddd6fe;
}

.diag-pill.notice {
    background: #e0f2fe;
    color: #075985;
    border-color: #bae6fd;
}

.diag-pill.muted {
    background: #f3f4f6;
    color: #4b5563;
    border-color: #e5e7eb;
}

.timestamp {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    font-size: 13px;
    color: var(--text-primary);
}

.timestamp small,
.timestamp-created {
    font-size: 12px;
    color: var(--text-secondary);
}

.timestamp-created {
    font-weight: 500;
}

.empty-state,
.loading-state,
.error-state {
    padding: 28px;
    text-align: center;
    border-radius: var(--radius-lg);
    border: 1px dashed var(--border-light);
    background: var(--background-secondary);
    color: var(--text-secondary);
}

.error-state {
    color: #b91c1c;
    border-color: #fecaca;
    background: #fef2f2;
}

.loading-state {
    font-style: italic;
}

.data-table td:first-child {
    font-weight: 500;
    color: var(--text-primary);
}

/* Status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid;
}

.status-badge.status-recense {
    background: #f0f9f4;
    color: #166534;
    border-color: #bbf7d0;
}

.status-badge.status-cree {
    background: #fef3c7;
    color: #92400e;
    border-color: #fde68a;
}

.status-badge.status-theorique {
    background: #f3f4f6;
    color: #374151;
    border-color: #d1d5db;
}

/* Action buttons in table */
.table-actions-cell {
    text-align: right;
    white-space: nowrap;
}

.btn-table {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-table.btn-primary {
    background: var(--primary-color);
    color: var(--white);
    border: 1px solid var(--primary-color);
}

.btn-table.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-table.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-table.btn-outline:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* Table pagination */
.table-pagination {
    display: flex;
    justify-content: between;
    align-items: center;
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    background: var(--background);
}

.pagination-info {
    color: var(--text-secondary);
    font-size: 14px;
}

.pagination-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.pagination-controls { margin-top: 8px; }
.tanstack-table + .pagination-controls {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--white);
}
.pagination-controls button {
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text-secondary);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}
.pagination-controls button:hover:not(:disabled) {
    background: var(--background-secondary);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}
.pagination-controls button:disabled { opacity: .5; cursor: not-allowed; }

/* Modal (export form) */
.modal-overlay, .modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.modal-overlay.open, .modal[style*="flex"] { display: flex; }
.modal-card, .modal-content {
    background: var(--white);
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 520px;
    padding: 20px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-content.modal-large {
    max-width: 800px;
}
.modal-header { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { 
    margin: 0; 
    font-size: 18px; 
    font-weight: 600;
    color: var(--text-primary);
}
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    line-height: 1;
}
.modal-close:hover {
    color: var(--text-primary);
}
.modal-body { 
    display: grid; 
    gap: 16px; 
    margin-bottom: 16px;
}
.modal-footer, .modal-actions { 
    display: flex; 
    gap: 12px; 
    justify-content: flex-end; 
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.form-group label {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 14px;
}
.form-help {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Inline spinner for small loading indicators */
.inline-spinner {
    display: inline-block;
    width: 16px; height: 16px;
    margin-left: 8px;
    border: 2px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    vertical-align: middle;
}

.form-select.loading, .form-input.loading { cursor: progress; opacity: .75; }

.pagination-btn {
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.pagination-btn:hover:not(.disabled) {
    background: var(--background-secondary);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.pagination-btn.active {
    background: var(--primary-color);
    color: var(--white);
    border-color: var(--primary-color);
}

.pagination-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading states */
.table-loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2px solid #f3f4f6;
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.table-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.table-empty-icon {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: 16px;
}

/* Responsive table design */
@media (max-width: 768px) {
    .table-header {
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
    }
    
    .table-actions {
        justify-content: center;
    }
    
    .data-table {
        font-size: 13px;
    }
    
    .data-table th,
    .data-table td {
        padding: 12px 8px;
    }
    
    .data-table th {
        font-size: 11px;
    }
    
    .table-pagination {
        flex-direction: column;
        gap: 16px;
    }
    
    .pagination-controls {
        order: -1;
    }
}

@media (max-width: 600px) {
    .data-table th,
    .data-table td {
        padding: 10px 6px;
    }
    
    .btn-table {
        padding: 4px 8px;
        font-size: 11px;
    }
    
    .status-badge {
        font-size: 10px;
        padding: 3px 6px;
    }
}

/* Action Menu Styles */
.action-menu {
    position: relative;
    display: inline-block;
}

.menu-button {
    background: none;
    border: none;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-button:hover {
    background: var(--background-secondary);
    color: var(--text-primary);
}

.menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 5000; /* override lower z-index */
    min-width: 160px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
}

.menu-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    text-align: left;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.menu-item:hover {
    background: var(--background-secondary);
}

.menu-item:first-child {
    border-radius: var(--radius) var(--radius) 0 0;
}

.menu-item:last-child {
    border-radius: 0 0 var(--radius) var(--radius);
}

/* Red menu item styles */
.text-red-600 { color: rgba(220, 38, 38, 1); }
.text-red-800 { color: rgba(153, 27, 27, 1); }
.hover\:text-red-800:hover { color: rgba(153, 27, 27, 1); }
.hover\:bg-red-50:hover { background-color: rgba(254, 242, 242, 1); }

/* Top Agents Styles */
.top-agents-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.top-agent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 6px;
    border-left: 3px solid var(--primary-color);
}

.agent-rank {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 30px;
}

.agent-name {
    flex: 1;
    margin-left: 12px;
    font-weight: 500;
}

.agent-count {
    font-weight: 600;
    color: var(--success-color);
    background: rgba(34, 197, 94, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.875rem;
}

.top-agents-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
    font-style: italic;
}

/* Responsive KPI grids */
@media (max-width: 768px) {
    .kpi-grid-4,
    .kpi-grid-6,
    .kpi-grid-3 {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .kpi-grid-6 .kpi-card,
    .kpi-grid-3 .kpi-card {
        min-height: 80px;
    }
}

/* KPI Dynamic Layouts - Mosaique Style */
.kpi-mosaic {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(6, 80px);
    gap: 16px;
    margin-bottom: 24px;
}

/* KPI Card Variants */
.kpi-card-large {
    grid-column: span 4;
    grid-row: span 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.kpi-card-wide {
    grid-column: span 6;
    grid-row: span 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
}

.kpi-card-tall {
    grid-column: span 3;
    grid-row: span 3;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

.kpi-card-square {
    grid-column: span 3;
    grid-row: span 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.kpi-card-mini {
    grid-column: span 2;
    grid-row: span 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 0.9rem;
}

/* Progress Bar dans les cartes larges */
.kpi-card-wide .kpi-progress-horizontal {
    flex: 1;
    margin-left: 20px;
    height: 8px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.kpi-progress-horizontal .kpi-progress-bar {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

/* Top Agents dans carte tall */
.kpi-card-tall .top-agents-compact {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
}

.kpi-card-tall .top-agent-compact {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    font-size: 0.85rem;
}

/* Responsive Mosaic */
@media (max-width: 1200px) {
    .kpi-mosaic {
        grid-template-columns: repeat(8, 1fr);
        grid-template-rows: repeat(8, 70px);
    }
    
    .kpi-card-large {
        grid-column: span 4;
        grid-row: span 2;
    }
    
    .kpi-card-wide {
        grid-column: span 8;
        grid-row: span 1;
    }
    
    .kpi-card-tall {
        grid-column: span 4;
        grid-row: span 3;
    }
}

@media (max-width: 768px) {
    .kpi-mosaic {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(12, 60px);
        gap: 12px;
    }
    
    .kpi-card-large,
    .kpi-card-wide,
    .kpi-card-tall,
    .kpi-card-square {
        grid-column: span 4;
        grid-row: span 2;
    }
    
    .kpi-card-mini {
        grid-column: span 2;
        grid-row: span 1;
    }
}

/* Horizontal table scroll (contained within card) */
.table-container {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important; /* enable horizontal scroll when needed */
    overflow-y: visible !important; /* allow dropdown menus */
    white-space: normal !important;
    margin: 0; padding: 0;
}

.table-container table {
    width: max-content !important; /* grow to content width */
    min-width: 1200px !important;  /* trigger horizontal scroll when needed */
    border-collapse: collapse;
}

/* Ensure inner wrapper also scrolls horizontally (covers all tables) */
.table-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}

/* Guarantee tables inside wrapper have a minimum width to enable scroll */
.table-wrapper > table,
.table-wrapper .tanstack-table,
.tanstack-table {
    min-width: 1200px !important;
    table-layout: auto;
}

/* Table cell overflow handling: prevent text overlap */
.tanstack-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* Allow action cell dropdowns to overflow */
.tanstack-table td.cell-actions { overflow: visible !important; }
/* Keep wrapper scrollable horizontally (avoid clipping) */
.table-wrapper { overflow-x: auto !important; }
.table-section, .table-container { overflow: visible; }
.table-wrapper .menu-dropdown { z-index: 5000 !important; }

/* Reasonable min-widths per column to avoid collisions */
.tanstack-table th:nth-child(1), .tanstack-table td:nth-child(1) { min-width: 140px; } /* N° Série */
.tanstack-table th:nth-child(2), .tanstack-table td:nth-child(2) { min-width: 150px; } /* Immatriculation */
.tanstack-table th:nth-child(3), .tanstack-table td:nth-child(3) { min-width: 220px; } /* Nom Client */
.tanstack-table th:nth-child(4), .tanstack-table td:nth-child(4) { min-width: 220px; } /* Type Frigo */
.tanstack-table th:nth-child(5), .tanstack-table td:nth-child(5) { min-width: 160px; } /* Nom Agent */
.tanstack-table th:last-child, .tanstack-table td:last-child { min-width: 80px; } /* Actions */

/* Prevent parent section from clipping horizontal scrollbar */
.table-section {
    overflow: visible !important;
}
