/**
 * PV DOCUMENTS - Styles pour le système de recherche et pagination
 * Version: 2.0
 * Theme: Laborex (#1e293b, #11b300)
 * Prefix: pv (évite les conflits CSS)
 * Mobile-first, responsive design
 */

/* ============================================================================
   VARIABLES CSS (facilite la maintenance)
   ========================================================================= */

:root {
    --pv-primary: #1e293b;      /* Bleu foncé Laborex */
    --pv-accent: #11b300;       /* Vert Laborex */
    --pv-accent-hover: #0d8f00; /* Vert foncé au hover */
    --pv-border: #e2e8f0;       /* Bordures subtiles */
    --pv-background: #f8fafc;   /* Fond clair */
    --pv-text: #334155;         /* Texte principal */
    --pv-text-muted: #64748b;   /* Texte secondaire */
    --pv-error: #dc2626;        /* Rouge erreur */
    --pv-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --pv-shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    --pv-radius: 8px;           /* Arrondi des bordures */
    --pv-transition: all 0.2s ease;
}

/* ============================================================================
   CONTENEUR PRINCIPAL
   ========================================================================= */

.pv-wrapper {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    font-family: inherit;
    color: var(--pv-text);
    background: #fff;
    border-radius: var(--pv-radius);
    box-shadow: var(--pv-shadow);
}

@media (min-width: 768px) {
    .pv-wrapper {
        padding: 2rem;
    }
}

/* ============================================================================
   BARRE DE RECHERCHE ET FILTRES
   ========================================================================= */

.pv-search-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
    .pv-search-container {
        flex-direction: row;
        align-items: center;
    }
}

/* Boîte de recherche textuelle */
.pv-search-box,
.pv-filter-box {
    position: relative;
    flex: 1;
    min-width: 0; /* Permet le shrink correctement */
}

.pv-search-icon,
.pv-filter-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--pv-text-muted);
    pointer-events: none;
    z-index: 1;
}

/* Champ de recherche */
.pv-search-field,
.pv-select-field {
    width: 100%;
    padding: 0.75rem 3rem 0.75rem 3rem;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--pv-text);
    background: #fff;
    border: 2px solid var(--pv-border);
    border-radius: var(--pv-radius);
    transition: var(--pv-transition);
    outline: none;
}

.pv-search-field:focus,
.pv-select-field:focus {
    border-color: var(--pv-accent);
    box-shadow: 0 0 0 3px rgba(17, 179, 0, 0.1);
}

.pv-search-field::placeholder {
    color: var(--pv-text-muted);
}

/* Select personnalisé */
.pv-select-field {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 16px;
    cursor: pointer;
}

/* Boutons "Effacer" (X) */
.pv-clear-btn {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--pv-text-muted);
    cursor: pointer;
    transition: var(--pv-transition);
    z-index: 2;
}

.pv-clear-btn:hover {
    background: var(--pv-background);
    color: var(--pv-error);
}

.pv-clear-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* ============================================================================
   INDICATEUR DE CHARGEMENT (OVERLAY)
   ========================================================================= */

.pv-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: var(--pv-radius);
}

.pv-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--pv-border);
    border-top-color: var(--pv-accent);
    border-radius: 50%;
    animation: pv-spin 0.8s linear infinite;
}

@keyframes pv-spin {
    to { transform: rotate(360deg); }
}

/* ============================================================================
   TABLEAU RESPONSIVE
   ========================================================================= */

.pv-table-wrapper {
    position: relative;
    overflow-x: auto;
    border-radius: var(--pv-radius);
    border: 1px solid var(--pv-border);
    background: #fff;
}

.pv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

/* En-tête du tableau */
.pv-table-head {
    background: var(--pv-primary);
    color: #fff;
}

.pv-table-head th {
    padding: 1rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

@media (min-width: 768px) {
    .pv-table-head th {
        padding: 1rem 1.25rem;
    }
}

/* Colonnes spécifiques */
.pv-col-icon {
    width: 50px;
    text-align: center;
}

.pv-col-type {
    width: 180px;
}

.pv-col-action {
    width: 160px;
    text-align: center;
}

@media (max-width: 767px) {
    .pv-col-type,
    .pv-col-action {
        width: auto;
    }
}

/* Corps du tableau */
.pv-table-body tr {
    border-bottom: 1px solid var(--pv-border);
    transition: var(--pv-transition);
}

.pv-table-body tr:last-child {
    border-bottom: none;
}

.pv-table-body tr:hover {
    background: var(--pv-background);
}

.pv-table-body td {
    padding: 1rem 0.75rem;
    vertical-align: middle;
}

@media (min-width: 768px) {
    .pv-table-body td {
        padding: 1rem 1.25rem;
    }
}

/* Cellule icône */
.pv-cell-icon {
    text-align: center;
}

.pv-cell-icon svg {
    display: inline-block;
    vertical-align: middle;
}

/* Cellule titre */
.pv-cell-title {
    font-weight: 500;
    color: var(--pv-primary);
    word-break: break-word;
}

/* Cellule type (badge) */
.pv-cell-type {
    font-size: 0.85rem;
}

.pv-badge {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    background: var(--pv-background);
    color: var(--pv-text);
    border-radius: 50px;
    font-weight: 500;
    white-space: nowrap;
}

/* Cellule action */
.pv-cell-action {
    text-align: center;
}

/* Bouton télécharger */
.pv-btn-download {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--pv-accent);
    color: #fff;
    text-decoration: none;
    border-radius: var(--pv-radius);
    font-size: 0.85rem;
    font-weight: 600;
    transition: var(--pv-transition);
}

.pv-btn-download svg {
    stroke: currentColor; /* hérite du lien */
}

.pv-btn-download:hover {
    color: #ffffff; /* reste blanc même au hover */
}

.pv-btn-download:hover {
    background: var(--pv-accent-hover) !important;
    transform: translateY(-1px);
    box-shadow: var(--pv-shadow);
}

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

@media (max-width: 767px) {
    .pv-btn-download {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }
    
    .pv-btn-download span {
        display: none; /* Cacher le texte sur mobile, garder juste l'icône */
    }
}

/* ============================================================================
   ÉTATS SPÉCIAUX (AUCUN RÉSULTAT / ERREUR)
   ========================================================================= */

.pv-no-results,
.pv-error-row {
    background: var(--pv-background);
}

.pv-no-results-cell,
.pv-error-cell {
    padding: 3rem 1.5rem !important;
    text-align: center;
    color: var(--pv-text-muted);
}

.pv-no-results-cell svg,
.pv-error-cell svg {
    margin: 0 auto 1rem;
    opacity: 0.5;
}

.pv-no-results-cell p,
.pv-error-cell p {
    font-size: 1.1rem;
    font-weight: 500;
    margin: 0.5rem 0;
    color: var(--pv-text);
}

.pv-no-results-cell small {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--pv-text-muted);
}

.pv-error-cell {
    color: var(--pv-error);
}

/* ============================================================================
   FOOTER (INFO + PAGINATION)
   ========================================================================= */

.pv-footer {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--pv-border);
}

@media (min-width: 768px) {
    .pv-footer {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

/* Texte d'information */
.pv-info-text {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--pv-text-muted);
}

.pv-info-text svg {
    flex-shrink: 0;
}

/* ============================================================================
   PAGINATION
   ========================================================================= */

.pv-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
}

@media (min-width: 768px) {
    .pv-pagination {
        justify-content: flex-end;
    }
}

.pv-pagination-container {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}

/* Boutons de pagination */
.pv-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    height: 2.5rem;
    padding: 0 0.5rem;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--pv-text);
    background: #fff;
    border: 1px solid var(--pv-border);
    border-radius: var(--pv-radius);
    cursor: pointer;
    transition: var(--pv-transition);
}

.pv-page-btn:hover:not(.pv-page-active) {
    background: var(--pv-background);
    border-color: var(--pv-accent);
    color: var(--pv-accent);
}

.pv-page-btn:active {
    transform: scale(0.95);
}

/* Bouton actif */
.pv-page-btn.pv-page-active {
    background: var(--pv-accent);
    border-color: var(--pv-accent);
    color: #fff;
    font-weight: 600;
    cursor: default;
}

/* Ellipsis (...) */
.pv-page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    height: 2.5rem;
    color: var(--pv-text-muted);
    user-select: none;
}

/* Boutons première/dernière page */
.pv-page-first,
.pv-page-last,
.pv-page-prev,
.pv-page-next {
    min-width: 2.5rem;
}

/* ============================================================================
   ÉTAT DE CHARGEMENT (classe ajoutée au wrapper)
   ========================================================================= */

.pv-is-loading .pv-table-body {
    opacity: 0.5;
    pointer-events: none;
}

/* ============================================================================
   ACCESSIBILITÉ
   ========================================================================= */

/* Focus visible pour navigation au clavier */
.pv-search-field:focus,
.pv-select-field:focus,
.pv-clear-btn:focus,
.pv-page-btn:focus,
.pv-btn-download:focus {
    outline: 2px solid var(--pv-accent);
    outline-offset: 2px;
}

/* Cacher visuellement mais garder accessible aux lecteurs d'écran */
.pv-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ============================================================================
   RESPONSIVE - MOBILE OPTIMISATIONS
   ========================================================================= */

@media (max-width: 640px) {
    .pv-wrapper {
        padding: 1rem;
        border-radius: 0;
    }

    .pv-table {
        font-size: 0.85rem;
    }

    .pv-table-head th {
        padding: 0.75rem 0.5rem;
        font-size: 0.75rem;
    }

    .pv-table-body td {
        padding: 0.75rem 0.5rem;
    }

    /* Cacher la colonne icône sur très petits écrans */
    .pv-col-icon,
    .pv-cell-icon {
        display: none;
    }

    /* Empiler les boutons de pagination */
    .pv-pagination-container {
        gap: 0.5rem;
    }

    .pv-page-btn {
        min-width: 2.25rem;
        height: 2.25rem;
        font-size: 0.85rem;
    }
}

/* ============================================================================
   ANIMATIONS ET TRANSITIONS
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Fade in des résultats */
@keyframes pv-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pv-table-body tr {
    animation: pv-fade-in 0.3s ease;
}

/* ============================================================================
   DARK MODE (optionnel - si le thème le supporte)
   ========================================================================= */

@media (prefers-color-scheme: dark) {
    /* 
    Décommenter si tu veux supporter le dark mode automatique
    
    .pv-wrapper {
        background: #1e293b;
        color: #e2e8f0;
    }
    
    .pv-search-field,
    .pv-select-field {
        background: #0f172a;
        border-color: #334155;
        color: #e2e8f0;
    }
    
    ... etc
    */
}

/* ============================================================================
   MESSAGES D'ERREUR SYSTÈME
   ========================================================================= */

.pv-error-message {
    padding: 1rem 1.5rem;
    background: #fee;
    border-left: 4px solid var(--pv-error);
    border-radius: var(--pv-radius);
    color: var(--pv-error);
    font-weight: 500;
}
