/* ========== VARIABLES COULEURS v1.5 ========== */
:root {
    /* Couleurs principales - Bleu + Rouge MB TECH */
    --primary-color: #1e40af;
    --primary-dark: #1e3a8a;
    --accent-red: #dc2626;
    --accent-red-light: #fee2e2;
    
    /* Couleurs fonctionnelles */
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0369a1;
    
    /* Neutres */
    --white: #ffffff;
    --bg-light: #f9fafb;
    --bg-lighter: #f3f4f6;
    --border: #e5e7eb;
    --text-dark: #111827;
    --text-gray: #6b7280;
    --text-light: #9ca3af;
    
    /* Ombres */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    
    /* Transition */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;
    
    /* Radius */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

/* ========== RESET ET BASE ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Aptos', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ========== LAYOUT PRINCIPAL ========== */
.container {
    width: 100%;
    min-height: 100vh;
    background: var(--white);
    display: flex;
    flex-direction: column;
}

/* ========== HEADER ========== */
.header {
    background: var(--white);
    color: var(--primary-dark);
    padding: 16px 24px;
    border-bottom: 2px solid var(--primary-color);
    position: sticky;
    top: 0;
    z-index: 99;
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    flex-shrink: 0;
    border-bottom: 2px solid var(--primary-color);
}

.header img.logo {
    height: 48px;
    width: auto;
    flex-shrink: 0;
    transition: var(--transition);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
}

.header h1 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.header-buttons {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* ========== NAVIGATION ONGLETS ========== */
.nav-tabs {
    display: flex;
    background: var(--white);
    gap: 4px;
    overflow-y: visible;
    overflow-x: auto;
    flex-shrink: 0;
    position: relative;
    z-index: 98;
    align-items: flex-start;
}

.nav-tab {
    padding: 8px 14px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #4b5563;
    border-bottom: 3px solid transparent;
    transition: var(--transition);
    white-space: nowrap;
    position: relative;
}

.nav-tab:hover {
    color: var(--primary-color);
    background-color: var(--bg-lighter);
}

.nav-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 600;
}

/* ========== DROPDOWN NAVIGATION ========== */
#listeWrapper {
    position: relative;
    display: inline-block;
    align-self: center;
}

#listeMenuBtn {
    position: relative;
}

.liste-dropdown {
    position: fixed;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
    z-index: 10000;
    min-width: 220px;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-12px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    display: none;
    top: 0;
    left: 0;
}

.liste-dropdown.active {
    display: flex !important;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.liste-dropdown.hide {
    display: none !important;
}

.nav-subtab {
    display: block;
    width: 100%;
    padding: 14px 18px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dark);
    text-align: left;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

.nav-subtab::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--primary-color);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.2s ease;
}

.nav-subtab:hover {
    background-color: rgba(30, 64, 175, 0.05);
    color: var(--primary-color);
    padding-left: 22px;
}

.nav-subtab:hover::before {
    transform: scaleX(1);
}

.nav-subtab.active {
    background-color: rgba(30, 64, 175, 0.1);
    color: var(--primary-color);
    font-weight: 600;
    padding-left: 22px;
}

.nav-subtab.active::before {
    transform: scaleX(1);
}

/* ========== CONTENU DES ONGLETS ========== */
.tab-content {
    display: none;
    padding: 32px 24px;
    flex: 1;
    overflow-y: auto;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tab-content.active {
    display: block;
}

/* ========== SECTIONS ET HEADERS ========== */
.section-header {
    margin-bottom: 32px;
}

.section-header h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 16px;
    letter-spacing: -0.5px;
}

/* ========== FILTRES ========== */
.filters {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.search-bar {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    margin-bottom: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.search-bar .search-input {
    flex: 1;
    min-width: 250px;
}

/* Barre de recherche principale de la Liste des Affaires */
#searchInput {
    width: 400px;
}

.search-input, .filter-select {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    transition: var(--transition);
    background: var(--white);
}

/* Harmoniser la taille des filtres recherchables (Client, Lieu, Interlocuteur) */
.filter-searchable {
    width: 300px;
}
.filter-searchable input.filter-select {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
}

.search-input:focus, .filter-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.search-input::placeholder {
    color: var(--text-light);
}

/* ========== TABLEAUX REDESIGNÉS ========== */
.table-wrapper {
    background: var(--white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    overflow-y: hidden;
    margin-bottom: 24px;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead {
    background: linear-gradient(to right, var(--bg-lighter), var(--bg-light));
    border-bottom: 2px solid var(--border);
}

.data-table th {
    padding: 16px 18px;
    text-align: center;
    font-weight: 600;
    color: var(--text-dark);
    letter-spacing: 0.3px;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
}

.data-table tbody tr:hover {
    background-color: var(--bg-lighter);
}

.data-table td {
    padding: 14px 18px;
    color: var(--text-gray);
    vertical-align: middle;
}

.data-table td strong {
    color: var(--text-dark);
    font-weight: 600;
}

/* Alternance de couleurs */
.data-table tbody tr:nth-child(odd) {
    background-color: var(--white);
}

.data-table tbody tr:nth-child(even) {
    background-color: rgba(249, 250, 251, 0.5);
}

/* ========== BOUTONS ========== */
.btn {
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: var(--white);
}

.btn-primary:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    background: var(--bg-lighter);
    color: var(--primary-dark);
    border: 1.5px solid var(--border);
    font-weight: 500;
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: var(--white);
    border-color: var(--primary-color);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background: #b91c1c;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

.btn-success:hover {
    background: #047857;
    box-shadow: var(--shadow-md);
}

.btn-icon {
    padding: 8px 12px;
    font-size: 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    white-space: nowrap;
}

.btn-edit {
    color: #3b82f6;
}

.btn-edit:hover {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    transform: translateY(-1px);
}

.btn-edit:active {
    transform: translateY(0);
}

.btn-delete {
    color: #ef4444;
}

.btn-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    transform: translateY(-1px);
}

.btn-delete:active {
    transform: translateY(0);
}

.btn-danger {
    color: #ffffff;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    transform: translateY(-1px);
}

.btn-danger:active {
    transform: translateY(0);
}

.btn-intervention-badge {
    background: linear-gradient(135deg, rgba(30, 64, 175, 0.1) 0%, rgba(30, 64, 175, 0.05) 100%);
    border: 1.5px solid var(--primary-color);
    color: var(--primary-color);
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-intervention-badge:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
}

.btn-intervention-badge:active {
    transform: translateY(0);
}

/* ========== FORMULAIRES ========== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
    font-size: 14px;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
    background: var(--white);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
    background: var(--white);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    gap: 12px;
    grid-column: 1 / -1;
    margin-top: 20px;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.form-actions .btn {
    min-width: 120px;
    height: 44px;
    padding: 10px 20px;
}

/* ========== SELECT AVEC BOUTON ADD (Nouvelle Affaire seulement) ========== */
#nouveau .select-container {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

#nouveau .select-container select {
    flex: 1;
    min-width: 0;
}

.btn-quick {
    min-width: 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 16px;
    flex-shrink: 0;
}

#nouveau .btn-quick {
    padding: 0;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ========== STATUT BADGES ========== */
.status-badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    transition: var(--transition);
}

.status-badge.En\ cours {
    background: rgba(59, 130, 246, 0.1);
    color: #1e40af;
}

.status-badge.Terminé {
    background: rgba(5, 150, 105, 0.1);
    color: var(--success);
}

.status-badge.Facturé {
    background: rgba(139, 92, 246, 0.1);
    color: #7c3aed;
}

.status-badge.Annulé {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
}

/* ========== EMPTY STATE ========== */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-gray);
}

.empty-state p {
    margin: 8px 0;
    font-size: 15px;
}

.empty-state p:first-child {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
}

.text-muted {
    color: var(--text-light);
}

/* ========== MODALS ========== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s ease;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--white);
    padding: 32px;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-xl);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-content h3 {
    font-size: 22px;
    margin-bottom: 20px;
    color: var(--text-dark);
    font-weight: 700;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    justify-content: flex-end;
}

/* ========== TOAST ========== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    background: var(--white);
    color: #111827;
    border: 1px solid #e5e7eb;
    font-size: 14px;
    font-weight: 500;
    z-index: 2000;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateX(24px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
}

.toast.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(24px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ========== SPINNER ========== */
.spinner {
    border: 3px solid var(--bg-lighter);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========== ICÔNES SVG ========== */
.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.icon-sm {
    width: 16px;
    height: 16px;
}

.icon-lg {
    width: 24px;
    height: 24px;
}

/* ========== RESPONSIVE ========== */
.text-right {
    text-align: right;
    white-space: nowrap;
}

/* ===== ORDINATEURS PORTABLES (13-15 pouces, ~1280-1440px) ===== */
@media (max-width: 1440px) {
    /* Filtres Affaires : un peu plus étroits pour tenir sans scroll excessif */
    .filter-searchable {
        width: 220px;
    }
    #searchInput {
        width: 280px;
    }

    /* Un peu moins de marge/padding pour gagner de la place */
    .table-wrapper {
        margin-bottom: 16px;
    }
    .data-table th, .data-table td {
        padding: 10px 12px;
    }
}

@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .header {
        padding: 12px 16px;
    }
    
    .header h1 {
        font-size: 18px;
    }
    
    .section-header h2 {
        font-size: 22px;
    }
    
    .tab-content {
        padding: 20px 16px;
    }
    
    .nav-tabs {
        padding: 0 16px;
    }
    
    .table-wrapper {
        border-radius: 0;
        overflow-x: auto;
    }
    
    .data-table {
        font-size: 13px;
    }
    
    .data-table th,
    .data-table td {
        padding: 12px 12px;
    }
    
    .modal-content {
        width: 95%;
        padding: 24px;
    }
    
    .filters {
        flex-direction: column;
        gap: 12px;
    }
    
    .search-input,
    .filter-select {
        width: 100%;
        font-size: 16px;
        padding: 12px 14px;
    }
    
    .btn {
        font-size: 14px;
        padding: 10px 16px;
        min-height: 44px;
    }
    
    .btn-sm {
        min-height: 36px;
        padding: 8px 12px;
    }
}

@media (max-width: 480px) {
    /* ===== HEADER ET NAVIGATION ===== */
    .header {
        flex-direction: column;
        align-items: flex-start;
        padding: 12px;
        gap: 12px;
    }

    /* ===== TABLEAU DE BORD ===== */
    .dashboard-card {
        padding: 16px;
    }
    .dashboard-pending-value {
        font-size: 24px;
    }
    .dashboard-pending-label {
        font-size: 13px;
    }
    .dashboard-legend-item {
        font-size: 12px;
    }
    #dashboardEvolution svg text {
        font-size: 8px;
    }
    .dashboard-donut-wrapper svg {
        width: 140px;
        height: 140px;
    }

    /* Boutons des popups (modales) : empilés, pleine largeur, faciles à toucher */
    .modal-actions {
        flex-direction: column;
    }
    .modal-actions .btn {
        width: 100%;
        justify-content: center;
    }

    /* Barre de filtres Affaires : chaque champ prend toute la largeur,
       empilés verticalement (300px/400px fixes ne rentrent pas sur téléphone) */
    #searchInput,
    .filter-searchable,
    #filterStatut,
    #addAffaireBtn,
    #resetFiltersBtn {
        width: 100% !important;
        margin-left: 0 !important;
    }
    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    /* Masquer le nom d'utilisateur et les boutons Synchroniser/Exporter/Déconnexion */
    #currentUserName, #syncBtn, #exportBtn, #logoutBtn {
        display: none !important;
    }

    .nav-tabs {
        position: static;
    }

    .nav-tabs {
        display: none;
    }

    .mobile-nav-dropdown {
        display: block;
        width: 100%;
        position: relative;
    }

    .mobile-nav-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 14px 16px;
        background: #f9fafb;
        border: 1.5px solid #e5e7eb;
        border-radius: 10px;
        font-size: 16px;
        font-weight: 600;
        color: var(--primary-color, #1e40af);
        cursor: pointer;
    }

    .mobile-nav-arrow {
        transition: transform 0.2s;
        color: #9ca3af;
    }

    .mobile-nav-dropdown.open .mobile-nav-arrow {
        transform: rotate(180deg);
    }

    .mobile-nav-list {
        display: none;
        position: absolute;
        top: calc(100% + 6px);
        left: 0;
        right: 0;
        background: white;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        box-shadow: 0 8px 24px rgba(0,0,0,0.15);
        overflow: hidden;
        z-index: 300;
        max-height: 60vh;
        overflow-y: auto;
    }

    .mobile-nav-dropdown.open .mobile-nav-list {
        display: block;
    }

    .mobile-nav-item {
        display: block;
        width: 100%;
        text-align: left;
        padding: 16px 18px;
        background: white;
        border: none;
        border-bottom: 1px solid #f3f4f6;
        font-size: 15px;
        font-weight: 500;
        color: #374151;
        cursor: pointer;
    }

    .mobile-nav-item:last-child {
        border-bottom: none;
    }

    .mobile-nav-item.active {
        background: #eff6ff;
        color: var(--primary-color, #1e40af);
        font-weight: 700;
    }

    .mobile-nav-item:active {
        background: #f3f4f6;
    }

    .sticky-header-group {
        position: static;
    }

    .searchable-option {
        padding: 14px 16px !important;
        font-size: 15px !important;
    }

    .searchable-dropdown-list {
        max-height: 260px !important;
    }

    .btn-quick {
        min-width: 44px;
        min-height: 44px;
    }

    /* Sections sans vue "cartes" dédiée (Analytique) : lecture confortable au doigt */
    #analytique .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    #analytique .data-table th,
    #analytique .data-table td {
        padding: 10px 8px;
        font-size: 12px;
    }

    .header-content {
        flex-direction: column;
        width: 100%;
        gap: 8px;
    }
    
    .header h1 {
        font-size: 16px;
        font-weight: 600;
    }
    
    .header-buttons {
        width: 100%;
        margin-left: 0;
        gap: 8px;
    }
    
    .nav-tabs {
        padding: 0 12px 6px 12px;
        gap: 4px;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        width: 100%;
    }

    .nav-tab {
        font-size: 13px;
        padding: 8px 12px;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    /* ===== SECTIONS ===== */
    .section-header {
        padding: 16px 12px;
    }
    
    .section-header h2 {
        font-size: 18px;
        margin-bottom: 12px;
    }
    
    .tab-content {
        padding: 12px;
    }
    
    /* ===== FILTRES ===== */
    .filters {
        flex-direction: column;
        gap: 10px;
        padding: 0;
    }
    
    .search-input,
    .filter-select {
        width: 100%;
        font-size: 16px;
        padding: 12px;
        border-radius: 8px;
        border: 1px solid var(--border);
    }
    
    .search-input::placeholder {
        font-size: 14px;
    }
    
    /* ===== TABLEAUX RESPONSIVE ===== */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
        margin: 0 -12px;
        padding: 0 12px;
    }
    
    .data-table {
        font-size: 12px;
        width: auto;
        min-width: 100%;
    }
    
    .data-table thead {
        background-color: var(--bg-lighter);
        position: sticky;
        top: 0;
    }
    
    .data-table th {
        padding: 10px 8px;
        font-size: 11px;
        font-weight: 600;
        white-space: nowrap;
        border-bottom: 2px solid var(--border);
    }
    
    .data-table td {
        padding: 10px 8px;
        white-space: nowrap;
    }
    
    .data-table tr:nth-child(odd) {
        background-color: var(--bg-light);
    }
    
    .data-table tr:hover {
        background-color: var(--bg-lighter);
    }
    
    /* ===== FORMULAIRES ===== */
    .form-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .form-group {
        margin-bottom: 0;
    }
    
    .form-group label {
        font-size: 14px;
        font-weight: 500;
        margin-bottom: 8px;
    }
    
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="date"],
    input[type="url"],
    select,
    textarea {
        width: 100%;
        font-size: 16px;
        padding: 12px;
        border-radius: 8px;
        border: 1px solid var(--border);
    }
    
    textarea {
        min-height: 100px;
        resize: vertical;
    }
    
    /* ===== BOUTONS ===== */
    .btn {
        width: 100%;
        font-size: 14px;
        padding: 12px 16px;
        min-height: 44px;
        border-radius: 8px;
        justify-content: center;
    }
    
    .btn-sm {
        width: auto;
        min-height: 36px;
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .btn-icon {
        width: auto;
        padding: 8px;
        min-height: 36px;
        min-width: 36px;
    }
    
    .form-actions {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .form-actions .btn {
        width: 100%;
        min-width: auto;
    }
    
    .form-actions .btn {
        width: 100%;
    }
    
    /* ===== MODALES ===== */
    .modal-content {
        width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 90vh;
        overflow-y: auto;
        padding: 20px;
        padding-bottom: 40px;
    }
    
    .modal-header {
        font-size: 16px;
        padding: 16px 0;
        border-bottom: 1px solid var(--border);
    }
    
    /* ===== ACTIONS TABLE ===== */
    .table-actions {
        flex-direction: row;
        gap: 8px;
    }
    
    .btn-edit, .btn-delete {
        font-size: 12px;
        padding: 6px 8px;
    }
    
    /* ===== CARDS ET CONTENEURS ===== */
    .settings-card,
    .data-card {
        padding: 16px;
        margin-bottom: 12px;
    }
    
    .settings-card h3 {
        font-size: 14px;
        margin-bottom: 12px;
    }
    
    .settings-card p {
        font-size: 13px;
    }
    
    /* ===== BADGES ===== */
    .btn-intervention-badge {
        font-size: 12px;
        padding: 6px 10px;
        white-space: nowrap;
    }
    
    /* ===== TOASTS ===== */
    .toast {
        bottom: 20px;
        right: 12px;
        left: 12px;
        width: auto;
        font-size: 14px;
        padding: 12px 16px;
    }
    
    /* ===== TEXTE ===== */
    .text-muted {
        font-size: 13px;
    }
    
    .text-right {
        text-align: right;
    }
    
    /* ===== DROPDOWN LISTE ===== */
    .liste-dropdown {
        position: fixed;
        width: auto;
        min-width: 180px;
        max-width: 90vw;
        z-index: 10001;
    }
    
    .nav-subtab {
        font-size: 14px;
        padding: 12px 16px;
    }
    
    /* ===== SCROLL SMOOTH ===== */
    * {
        -webkit-tap-highlight-color: transparent;
    }
    
    input, select, textarea, button {
        -webkit-appearance: none;
        appearance: none;
        border-radius: 8px;
    }
    
    /* ===== ICONS TAILLE MOBILE ===== */
    .btn-icon::before {
        font-size: 16px;
    }
    
    /* ===== SPACING ===== */
    body {
        font-size: 14px;
    }
    
    h1 {
        font-size: 18px;
    }
    
    h2 {
        font-size: 16px;
    }
    
    h3 {
        font-size: 14px;
    }
}

/* ========== OPTIMISATIONS MOBILE ADDITIONNELLES ========== */

/* Safe area pour iPhone avec notch */
@supports (padding: max(0px)) {
    body {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-top: max(0px, env(safe-area-inset-top));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
    
    .modal-content {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* Disable double tap zoom sur inputs */
input, select, textarea, button {
    font-size: 16px;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Better touch support */
@media (hover: none) and (pointer: coarse) {
    .btn, button, a {
        min-width: 44px;
        min-height: 44px;
        padding: 12px 16px;
    }
    
    .btn-icon {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Enlever hover sur tactile */
    .btn:hover, button:hover, a:hover {
        transform: none;
    }
}

/* Keyboard support for iOS */
@supports (-webkit-touch-callout: none) {
    input, select, textarea {
        font-size: 16px;
        background-color: rgba(255, 255, 255, 0.5);
    }
    
    body {
        -webkit-user-select: none;
        -webkit-user-select: text;
        user-select: text;
    }
}

/* Android specific optimizations */
@media (prefers-color-scheme: light) {
    body {
        background-color: #fafbfc;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ========== PAGE DE LOGIN ========== */
.login-page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: 40px;
    text-align: center;
}

.login-header {
    margin-bottom: 30px;
}

.login-logo {
    max-width: 120px;
    height: auto;
    display: block;
    margin: 0 auto 15px;
}

.login-header p {
    font-size: 14px;
    color: var(--text-gray);
    margin: 8px 0 0 0;
}

.login-form {
    margin-bottom: 20px;
}

.login-form .form-group {
    margin-bottom: 18px;
    text-align: left;
}

.login-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-dark);
}

.login-form input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.btn-login {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    font-weight: 600;
}

.login-error {
    color: #ef4444;
    font-size: 13px;
    margin-top: 12px;
    padding: 10px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 6px;
    border-left: 3px solid #ef4444;
}

.login-footer {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-gray);
}

.login-footer p {
    margin: 0;
}

/* Logout Button */
.logout-btn {
    background: #ef4444 !important;
    color: white !important;
}

.logout-btn:hover {
    background: #dc2626 !important;
}

/* ========== IMPRESSION ==========*/
@media print {
    .header,
    .nav-tabs,
    .filters,
    .header-buttons {
        display: none;
    }
    
    .tab-content {
        padding: 0;
    }
    
    .btn {
        display: none;
    }
}

/* ========== FORMULAIRE PLEIN ÉCRAN (Intervention) ========== */
.fullpage-form {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5000;
    background: #f9fafb;
    overflow-y: auto;
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    padding: 30px 40px !important;
    box-sizing: border-box;
}

.fullpage-form .form-grid {
    max-width: 900px;
    margin: 0 auto;
}

.fullpage-form h2,
.fullpage-form h3 {
    max-width: 900px;
    margin: 0 auto 20px auto;
}

/* ========== HEADER : titre à côté du logo ========== */

.header-buttons .btn {
    padding: 7px 12px;
    font-size: 13px;
}

/* ========== MENU DÉROULANT DE NAVIGATION MOBILE ========== */
/* Caché par défaut, ne s'affiche QUE sur écran ≤480px (voir media query plus haut) */
@media (min-width: 481px) {
    .mobile-nav-dropdown {
        display: none !important;
    }
}

/* ========== GROUPE FIXE : header + barre d'onglets ensemble ========== */
.sticky-header-group {
    position: sticky;
    top: 0;
    z-index: 99;
    background: var(--white);
}
.sticky-header-group .header {
    position: static;
}
.sticky-header-group .nav-tabs {
    position: static;
}

/* ========== TRI DES COLONNES (Affaires) ========== */
.header .logo {
    cursor: pointer;
}
.header a {
    display: inline-flex;
    line-height: 0;
}

.sortable-th {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.sortable-th:hover {
    background: rgba(255,255,255,0.15);
}
.sort-icon {
    font-size: 13px;
    font-weight: 700;
    opacity: 0.85;
    margin-left: 4px;
}
.sort-icon.active {
    opacity: 1;
    font-weight: 900;
    color: #fbbf24;
}

/* ========== VUE MOBILE EN CARTES (tout le site) ========== */
.mobile-card-list {
    display: none;
}

@media (max-width: 768px) {
    #affaires .table-wrapper,
    #interventions .table-wrapper,
    #factures .table-wrapper,
    #societes .table-wrapper,
    #interlocuteurs .table-wrapper,
    #representants .table-wrapper,
    #lieux .table-wrapper {
        display: none;
    }
    #affaires .mobile-card-list,
    #interventions .mobile-card-list,
    #factures .mobile-card-list,
    #societes .mobile-card-list,
    #interlocuteurs .mobile-card-list,
    #representants .mobile-card-list,
    #lieux .mobile-card-list {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
}

.mobile-card, .affaire-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.mobile-card-header, .affaire-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f3f4f6;
    gap: 8px;
}
.mobile-card-title, .affaire-card-title {
    font-weight: 700;
    font-size: 16px;
    color: var(--text-dark, #111827);
}
.mobile-card-row, .affaire-card-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
    padding: 4px 0;
}
.mobile-card-row .label, .affaire-card-row .label {
    color: #9ca3af;
    flex-shrink: 0;
}
.mobile-card-row .value, .affaire-card-row .value {
    text-align: right;
    color: #374151;
    font-weight: 500;
}
.mobile-card-row .value.wrap {
    white-space: normal;
    max-width: 65%;
}
.mobile-card-actions, .affaire-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}
.mobile-card-actions .btn, .affaire-card-actions .btn {
    flex: 1;
    min-width: 100px;
    justify-content: center;
}

/* ========== SELECT RECHERCHABLE (Interlocuteur) ========== */
.searchable-dropdown-list {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 44px;
    max-height: 220px;
    overflow-y: auto;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 200;
    margin-top: 2px;
}
.searchable-option {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
}
.searchable-option:hover {
    background: #f0f4ff;
}
.searchable-empty {
    color: #9ca3af;
    cursor: default;
}
.searchable-empty:hover {
    background: none;
}

/* ========== ALERTE COMMENTAIRE (Affaires) ========== */
.btn-comment-alert {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid #e5e7eb;
    background: #ffffff;
    color: #6b7280;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s;
}
.btn-comment-alert:hover {
    background: #f3f4f6;
    transform: scale(1.1);
}

/* ========== BOUTON COMPTEUR INTERVENTIONS (pilule) ========== */
.btn-intervention-count {
    display: inline-block;
    background: white;
    color: #2563eb;
    border: 1.5px solid #2563eb;
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.btn-intervention-count:hover {
    background: #2563eb;
    color: white;
}

/* Colonnes centrées : N° BC, N° Affaire, Engagement, Représentant, Interventions (nouvel ordre) */
#affairesTable td:nth-child(2),
#affairesTable td:nth-child(3),
#affairesTable td:nth-child(4),
#affairesTable td:nth-child(8),
#affairesTable td:nth-child(15) {
    text-align: center;
}
#affairesTable td:nth-child(15) .btn-intervention-count {
    display: inline-flex;
    justify-content: center;
}

/* Rep. compact, plus de place pour Référence */
#affairesTable td:nth-child(8) {
    width: 55px;
    max-width: 55px;
}
#affairesTable th:nth-child(11),
#affairesTable td:nth-child(11) {
    min-width: 260px;
}

/* ========== PLANNING : calendrier mensuel ========== */
.planning-calendar {
    display: grid;
    grid-template-columns: 44px repeat(6, 1fr);
    gap: 10px;
}

.planning-week-num-header {
    /* case vide au-dessus de la colonne des numéros de semaine */
}

.planning-week-num {
    display: flex;
    align-items: center;
    justify-content: center;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 11px;
    font-weight: 700;
    color: #9ca3af;
    background: #f9fafb;
    border-radius: 6px;
}

.planning-view-selector {
    display: inline-flex;
    background: #f3f4f6;
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}
.planning-view-btn {
    border: none;
    background: none;
    padding: 8px 28px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.15s;
}
.planning-view-btn:hover {
    color: #1e40af;
}
.planning-view-btn.active {
    background: white;
    color: #1e40af;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.planning-day-header {
    text-align: center;
    font-weight: 700;
    font-size: 13px;
    color: #6b7280;
    padding: 6px 0;
    text-transform: uppercase;
}

.planning-day-cell {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    min-height: 160px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: background 0.15s;
}

.planning-day-cell.empty {
    background: #f9fafb;
    border-style: dashed;
}

.planning-day-cell.today {
    border: 2px solid #1e40af;
}

.planning-day-cell.drag-over {
    background: #eff6ff;
    border-color: #1e40af;
}

.planning-day-number {
    font-size: 12px;
    font-weight: 700;
    color: #374151;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.planning-add-btn {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 4px;
}
.planning-add-btn:hover {
    background: #eff6ff;
    color: #1e40af;
}

.planning-chantier-group {
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #f9fafb;
}

.planning-group-header {
    font-size: 11.5px;
    font-weight: 700;
    padding: 5px 7px;
    border-radius: 4px;
}

.planning-chantier-card {
    background: #eff6ff;
    border-left: 3px solid #1e40af;
    border-radius: 5px;
    padding: 5px 7px;
    font-size: 11px;
    line-height: 1.3;
    cursor: grab;
    overflow: hidden;
    text-overflow: ellipsis;
}
.planning-chantier-card:active {
    cursor: grabbing;
}
.planning-chantier-card.dragging {
    opacity: 0.4;
}
.planning-chantier-card strong {
    color: #1e40af;
    font-size: 11.5px;
}

.planning-chantier-card.statut-Terminé { border-left-color: #15803d; background: #f0fdf4; }
.planning-chantier-card.statut-Annulé { border-left-color: #b91c1c; background: #fef2f2; text-decoration: line-through; opacity: 0.7; }
.planning-chantier-card.statut-En.cours { border-left-color: #c2410c; background: #fff7ed; }

.planning-weekday-mobile {
    display: none;
}

@media (max-width: 768px) {
    .planning-week-num, .planning-week-num-header {
        display: none;
    }
    .planning-calendar {
        grid-template-columns: repeat(2, 1fr);
    }
    .planning-day-cell {
        min-height: 90px;
    }
}

@media (max-width: 480px) {
    /* Lignes dynamiques (marchés société, remise des clés) : empilées au lieu de serrées */
    .rc-row, .societe-marche-row {
        flex-wrap: wrap;
    }
    .rc-row input, .societe-marche-row input {
        width: 100% !important;
        flex: none !important;
        box-sizing: border-box;
    }

    .planning-nav {
        gap: 10px !important;
        justify-content: center !important;
        width: 100%;
    }
    .planning-nav .btn {
        padding: 8px 12px;
        font-size: 13px;
    }
    .planning-view-selector {
        width: 100%;
        justify-content: center;
    }
    .planning-view-btn {
        flex: 1;
        padding: 10px 4px;
        font-size: 12px;
    }
    #planningMonthLabel {
        width: 100%;
        order: 5;
        font-size: 15px;
        min-width: 0 !important;
    }

    /* Vue liste 1 colonne, plus lisible et tactile sur téléphone */
    .planning-day-header {
        display: none;
    }
    .planning-calendar {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .planning-day-cell.empty {
        display: none;
    }
    .planning-day-cell {
        min-height: unset;
        padding: 10px 12px;
    }
    .planning-weekday-mobile {
        display: inline;
        color: #9ca3af;
        font-weight: 500;
    }
    .planning-day-number {
        font-size: 14px;
        margin-bottom: 6px;
    }
    .planning-add-btn {
        font-size: 20px;
        padding: 4px 10px;
    }
    .planning-chantier-card {
        font-size: 13px;
        padding: 10px 12px;
    }
    .planning-chantier-card strong {
        font-size: 13.5px;
    }
}

/* Réduire l'espace entre le titre "Planning des Équipes" et la navigation des mois */
#planning .section-header {
    margin-bottom: 12px;
}

/* Centrer le contenu des lignes du tableau Sociétés */
#societesTable td {
    text-align: center;
}

/* Poignée de glisser pour réordonner les lignes affaires/activités */
.chantier-drag-handle {
    cursor: grab;
    color: #9ca3af;
    font-size: 18px;
    padding: 10px 4px;
    user-select: none;
    line-height: 1;
}
.chantier-drag-handle:active {
    cursor: grabbing;
}
.chantier-affaire-row.dragging {
    opacity: 0.4;
}
.chantier-affaire-row.drag-over-top {
    border-top: 3px solid var(--primary-color, #1e40af);
}
.chantier-affaire-row.drag-over-bottom {
    border-bottom: 3px solid var(--primary-color, #1e40af);
}

/* ========== TABLEAU DE BORD ========== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.dashboard-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    padding: 22px;
}
.dashboard-card-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6b7280;
    margin: 0 0 18px 0;
}
.dashboard-pending-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.dashboard-pending-label {
    font-size: 15px;
    font-weight: 600;
    color: #111827;
}
.dashboard-pending-value {
    font-size: 32px;
    font-weight: 800;
    color: #dc2626;
    transition: opacity 0.15s;
}
.dashboard-pending-value:hover {
    opacity: 0.7;
}
.dashboard-pending-value-blue {
    color: #2563eb;
}
.dashboard-pending-value-green {
    color: #16a34a;
}
.dashboard-pending-sub {
    margin-top: 14px;
    font-size: 13px;
    color: #6b7280;
}
.dashboard-chart-area {
    min-height: 220px;
}
.dashboard-donut-wrapper {
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}
.dashboard-legend {
    flex: 1;
    min-width: 160px;
}
.dashboard-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 8px;
    color: #374151;
}
.dashboard-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.dashboard-legend-pct {
    margin-left: auto;
    font-weight: 700;
    color: #111827;
}
.dashboard-empty {
    color: #9ca3af;
    text-align: center;
    padding: 40px 0;
}
.dashboard-chart-tooltip {
    position: absolute;
    background: #111827;
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .dashboard-donut-wrapper {
        flex-direction: column;
    }
}

