/* style.css — Gestionnaire de Collections */
/* Thème : sobre, violet et gris */

/* ============================================================
   VARIABLES & RESET
   ============================================================ */
:root {
    --violet-dark:   #3b1f5e;
    --violet-main:   #6b3fa0;
    --violet-light:  #9b6fd0;
    --violet-pale:   #ede4f7;
    --violet-border: #c4a3e8;

    --grey-dark:     #2c2c2e;
    --grey-mid:      #5a5a5f;
    --grey-light:    #b0b0b8;
    --grey-pale:     #f4f4f6;
    --grey-border:   #d8d8de;

    --white:         #ffffff;
    --green:         #2e7d52;
    --green-light:   #d4edda;
    --red:           #b5291e;
    --red-light:     #fddcda;

    --font-main:     'Segoe UI', system-ui, sans-serif;

    --radius:        8px;
    --radius-sm:     4px;
    --shadow:        0 2px 8px rgba(0,0,0,0.10);
    --shadow-lg:     0 8px 32px rgba(0,0,0,0.18);

    --transition:    0.18s ease;

    --sidebar-width: 260px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: var(--font-main);
    font-size: 15px;
    color: var(--grey-dark);
    background: var(--grey-pale);
}

/* ============================================================
   PAGE DE LOGIN
   ============================================================ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--violet-dark) 0%, var(--violet-main) 100%);
}

.login-container { width: 100%; max-width: 380px; padding: 1rem; }

.login-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
}

.login-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--violet-main);
    text-align: center;
    margin-bottom: 0.25rem;
}

.login-subtitle {
    text-align: center;
    color: var(--grey-mid);
    font-size: 0.875rem;
    margin-bottom: 1.75rem;
}

.login-form .form-group { margin-bottom: 1.1rem; }

/* ============================================================
   COMPOSANTS DE BASE
   ============================================================ */
label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--grey-mid);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

input[type="text"],
input[type="password"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1.5px solid var(--grey-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
    font-size: 0.95rem;
    color: var(--grey-dark);
    background: var(--white);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--violet-main);
    box-shadow: 0 0 0 3px rgba(107, 63, 160, 0.15);
}

input:disabled, select:disabled {
    background: var(--grey-pale);
    color: var(--grey-light);
    cursor: not-allowed;
}

textarea { resize: vertical; min-height: 80px; }

/* Boutons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary  { background: var(--violet-main); color: var(--white); }
.btn-primary:hover { background: var(--violet-dark); }

.btn-secondary {
    background: var(--grey-pale);
    color: var(--grey-dark);
    border: 1.5px solid var(--grey-border);
}
.btn-secondary:hover { background: var(--grey-border); }

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

.btn-icon  { padding: 0.35rem 0.55rem; font-size: 1rem; }
.btn-full  { width: 100%; }

/* Alertes */
.alert {
    padding: 0.65rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}
.alert-error   { background: var(--red-light);   color: var(--red); }
.alert-success { background: var(--green-light);  color: var(--green); }

/* ============================================================
   LAYOUT GLOBAL
   ============================================================ */
#app {
    height: 100vh;      /* fallback anciens navigateurs */
    height: 100dvh;     /* valeur moderne — écrase la précédente si supportée */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Topbar */
.topbar {
    background: var(--violet-dark);
    color: var(--white);
    padding: 0 1.25rem;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    flex-shrink: 0;
    z-index: 10;
}

.topbar-title { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.03em; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }

.topbar a.logout {
    font-size: 0.8rem;
    color: var(--violet-pale);
    text-decoration: none;
    opacity: 0.8;
}
.topbar a.logout:hover { opacity: 1; text-decoration: underline; }

/* ============================================================
   MAIN BODY : sidebar + tableau côte à côte
   ============================================================ */
.main-body {
    display: flex;
    flex: 1;
    overflow: hidden; /* chaque enfant scroll indépendamment */
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--white);
    border-right: 1.5px solid var(--grey-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 1rem 0.9rem;
    gap: 0;
}

.sidebar-section {
    margin-bottom: 1rem;
}

/* Case à cocher collections terminées */
.sidebar-check { margin-bottom: 1rem; }

.check-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--grey-mid);
    text-transform: none;
    letter-spacing: 0;
    cursor: pointer;
    user-select: none;
}

.check-label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    accent-color: var(--violet-main);
    cursor: pointer;
}

/* Boutons dans la sidebar */
.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Recherche */
.search-wrapper {
    position: relative;
}

.search-wrapper input { padding-right: 2rem; }

.search-clear {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--grey-light);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    display: none;
}
.search-clear.visible { display: block; }
.search-clear:hover { color: var(--grey-dark); }

/* Bloc illustration + stats en bas de sidebar */
.sidebar-collection-info {
    padding-top: 1rem;
    border-top: 1.5px solid var(--violet-border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Illustration cliquable */
.collection-illustration {
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--violet-border);
    background: var(--violet-pale);
    cursor: zoom-in;
    transition: opacity var(--transition);
}
.collection-illustration:hover { opacity: 0.85; }

.collection-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--violet-dark);
}

.collection-stats {
    font-size: 0.82rem;
    color: var(--violet-main);
    font-weight: 600;
}

.stats-bar-outer {
    height: 6px;
    background: var(--violet-border);
    border-radius: 99px;
    overflow: hidden;
}

.stats-bar-inner {
    height: 100%;
    background: var(--violet-main);
    border-radius: 99px;
    transition: width 0.4s ease;
}

/* ============================================================
   ZONE TABLEAU (droite)
   ============================================================ */
.table-wrapper {
    flex: 1;
    overflow: hidden;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
}

.table-scroll {
    overflow-y: scroll;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    border-radius: 0 0 var(--radius) var(--radius);
}

.table-wrapper table thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--violet-dark);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* ============================================================
   TABLEAU
   ============================================================ */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    min-width: 320px;
    table-layout: fixed;
}

thead { background: var(--violet-dark); color: var(--white);}

th {
    padding: 0.7rem 1rem;
    text-align: center;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
    user-select: none;
}

/* En-tête colonne possédé : centré */
th.th-possede {
    text-align: center;
}

th.sortable { cursor: pointer; }
th.sortable:hover { background: var(--violet-main); }

th .sort-icon { margin-left: 0.3rem; opacity: 0.5; font-style: normal; }
th.sort-asc  .sort-icon::after { content: ' ▲'; opacity: 1; }
th.sort-desc .sort-icon::after { content: ' ▼'; opacity: 1; }
th:not(.sort-asc):not(.sort-desc) .sort-icon::after { content: ' ⇅'; }

/* Cellules */
td {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--grey-border);
    text-align: center;
    vertical-align: middle;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 340px;
}

tbody tr:last-child td { border-bottom: none; }

/* Alternance légère pour mieux voir les lignes */
tbody tr:nth-child(odd)  { background: var(--white); }
tbody tr:nth-child(even) { background: var(--grey-pale); }
tbody tr:hover           { background: var(--violet-pale) !important; }

/* Séparateur vertical entre colonnes */
td + td { border-left: 1px solid rgba(0,0,0,0.06); }
th + th { border-left: 1px solid rgba(255,255,255,1); }

/* Cellule éditable */
td.editable {
    cursor: pointer;
    position: relative;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: break-word;
}

td.editable:hover::after {
    content: '\00A0\00A0\00A0\00A0\00A0\00A0\00A0\00A0✒️';
    color: var(--violet-light);
    font-size: 0.75rem;
    vertical-align: middle;
    position: static;
    display: inline;
    width: 0;
    overflow: visible;
}

td.editable input,
td.editable textarea {
    margin: -0.2rem;
    width: calc(100% + 0.4rem);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

/* Colonne numéros (picsou) : texte long */
td[data-field="numeros"] {
    max-width: 420px;
    white-space: pre-wrap;
}

/* Cellule possédé — centrée */
.possede-cell { text-align: center; }

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity var(--transition);
    border: none;
    outline: none;
}
.badge-oui  { background: var(--green-light); color: var(--green); }
.badge-non  { background: var(--red-light);   color: var(--red); }
.badge:hover { opacity: 0.75; }

/* Filtre possédé dans l'en-tête */
.possede-filter {
    display: flex;
    justify-content: center;
    gap: 0.2rem;
    margin-top: 0.25rem;
}
.possede-filter button {
    padding: 0.1rem 0.4rem;
    font-size: 0.65rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 99px;
    background: transparent;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    transition: background var(--transition);
}
.possede-filter button.active,
.possede-filter button:hover {
    background: rgba(255,255,255,0.25);
    color: var(--white);
}

/* Colonne suppression */
.col-delete { width: 70px; text-align: center; padding-right: 0.5rem; }

/* Largeurs des colonnes : première colonne (Nom) plus large */
table col:first-child  { width: 45%; }
table col:last-child   { width: 70px; }




/* Photos dans le tableau — plus grandes, ligne auto-haute */
td.photo-cell {
    padding: 0.4rem 1rem;
    text-align: center;
}
.photo-thumb {
    width: 200px;
    height: 240px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    cursor: zoom-in;
    transition: transform var(--transition), box-shadow var(--transition);
    margin: 0 auto;  /* ← centrage horizontal */
}
.photo-thumb:hover {
    transform: scale(1.04);
    box-shadow: var(--shadow);
}

/* Message vide */
.empty-msg {
    text-align: center;
    padding: 2.5rem;
    color: var(--grey-light);
    font-size: 0.95rem;
}

/* ============================================================
   MODALES
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(30, 10, 50, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
    background: var(--white);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    transform: translateY(16px);
    transition: transform 0.2s ease;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1.5px solid var(--grey-border);
}

.modal-title { font-size: 1rem; font-weight: 700; color: var(--violet-dark); }

.modal-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--grey-light);
    line-height: 1;
    padding: 0.1rem 0.3rem;
    border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--grey-pale); color: var(--grey-dark); }

.modal-body { padding: 1.1rem 1.25rem; }
.modal-body .form-group { margin-bottom: 1rem; }

.modal-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1.5px solid var(--grey-border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ============================================================
   LIGHTBOX
   ============================================================ */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    cursor: zoom-out;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.lightbox.open { opacity: 1; pointer-events: all; }
.lightbox img {
    max-width: 92vw;
    max-height: 88vh;
    object-fit: contain;
    border-radius: var(--radius);
}

/* ============================================================
   MESSAGE D'ACCUEIL
   ============================================================ */
.welcome-msg {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--grey-light);
}
.welcome-msg .welcome-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.welcome-msg p { font-size: 1rem; }



/* Thead fixe séparé du tbody scrollable */
.table-head-fixed {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    flex-shrink: 0;
    background: var(--violet-dark);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}






















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

/* ----------------------------------------------------------
   PC PETIT / TABLETTE  768px – 1024px
   sidebar légèrement réduite
   ---------------------------------------------------------- */
@media (max-width: 1024px) {
    :root { --sidebar-width: 220px; }

    th { padding: 0.6rem 0.75rem; font-size: 0.74rem; text-align: center;}
    td { padding: 0.55rem 0.75rem; font-size: 0.87rem; text-align: center;}

    .photo-thumb { width: 100px; height: 120px; }
    .collection-illustration { max-height: 140px; }
}






















/* ----------------------------------------------------------
   MOBILE  < 768px
   Layout vertical : contrôles en haut (compacts), tableau en dessous
   ---------------------------------------------------------- */
@media (max-width: 767px) {
    #app {
        height: 100vh;
        height: -webkit-fill-available;
        overflow: hidden;   /* ← AJOUTER */
        display: flex;
        flex-direction: column;
    }
    .main-body {
        flex-direction: column;
        flex: 1;
        min-height: 0;  /* ← crucial */
        display: flex;
    }

    /* --- Topbar --- */
    .topbar { padding: 0 0.85rem; height: 46px; }
    .topbar-title { font-size: 0.9rem; }

    /* --- Sidebar --- */
    .sidebar {
        width: 100%;
        flex-shrink: 0;  /* ← crucial : la sidebar ne rétrécit pas */
        border-right: none;
        border-bottom: 1.5px solid var(--grey-border);
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-end;
        padding: 0.6rem 0.75rem;
        gap: 0.5rem;
        overflow-y: visible;
    }

    .sidebar-section {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 130px;
        margin-bottom: 0;
    }
    .sidebar-check {
        flex: 1 1 100%;
        order: 10;
    }
    .sidebar-actions {
        flex: 1 1 100%;
        flex-direction: row;
        order: 11;
    }
    .sidebar-actions .btn { flex: 1; }
    .sidebar-collection-info {
        flex: 1 1 100%;
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
        margin-top: 0;
        padding-top: 0.5rem;
        order: 12;
    }
    .collection-illustration {
        width: 60px;
        max-height: 60px;
        flex-shrink: 0;
    }
    .collection-name  { font-size: 0.9rem; }
    .collection-stats { font-size: 0.78rem; }
    .stats-bar-outer  { max-width: 120px; }
    .sidebar-section > label:not(.check-label) { display: none; }

    /* --- Tableau --- */
    
    table col:first-child { width: 40%; }
    table col:nth-child(2)   { width: 20%; }
    table col:last-child   { width: 10%; }   
    
    .table-wrapper {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        padding: 0.6rem 0.4rem 0 0.4rem;
        overflow: visible;
    }
    
    .table-scroll {
        flex: 1;
        min-height: 0;
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
    }
    .table-wrapper table thead th {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--violet-dark);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
    th {
        padding: 0.45rem 0.5rem;
        font-size: 0.7rem;
        text-align: center;
    }
    td {
        padding: 0.4rem 0.5rem;
        font-size: 0.8rem;
        max-width: 180px;
        text-align: center;
    }
    
    td.editable {
        white-space: normal;
        word-break: break-word;
        overflow-wrap: break-word;
    }
    
    td.editable:hover::after { display: none; }
    .badge { padding: 0.15rem 0.4rem; font-size: 0.7rem; }
    .possede-filter button { padding: 0.08rem 0.28rem; font-size: 0.58rem; }
    .photo-thumb { width: 80px; height: 100px; }
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal {
        max-width: 100%;
        border-radius: var(--radius) var(--radius) 0 0;
        max-height: 85vh;
    }
    .btn { font-size: 0.85rem; padding: 0.45rem 0.8rem; }
    
    .row-delete-btn {width:100%;}
}