/* 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;
}

*, *::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.8rem;
    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;
    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), box-shadow 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%; justify-content: center; }

/* 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 PRINCIPAL
   ============================================================ */
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* 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;
}

.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; }

/* Barre de contrôles */
.controls-bar {
    background: var(--white);
    border-bottom: 1.5px solid var(--grey-border);
    padding: 0.75rem 1.25rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.controls-bar select { max-width: 220px; width: auto; }

/* Recherche */
.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 160px;
    max-width: 320px;
}

.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); }

/* Boutons d'action */
.actions-bar {
    background: var(--white);
    padding: 0.5rem 1.25rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--grey-border);
}

/* Zone illustration + stats */
.collection-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
    background: var(--violet-pale);
    border-bottom: 1.5px solid var(--violet-border);
}

.collection-illustration {
    width: 100px;
    height: 100px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--violet-border);
    flex-shrink: 0;
}

.collection-info { flex: 1; }

.collection-name {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--violet-dark);
    margin-bottom: 0.2rem;
}

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

.stats-bar-outer {
    margin-top: 0.35rem;
    height: 6px;
    background: var(--violet-border);
    border-radius: 99px;
    overflow: hidden;
    max-width: 220px;
}

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

/* ============================================================
   TABLEAU
   ============================================================ */
.table-wrapper {
    flex: 1;
    overflow: auto;
    padding: 1rem 1.25rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    font-size: 0.9rem;
}

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

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

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: ' ⇅'; }

td {
    padding: 0.55rem 0.85rem;
    border-bottom: 1px solid var(--grey-border);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--violet-pale); }

/* Cellule éditable */
td.editable {
    cursor: pointer;
    position: relative;
}
td.editable:hover::after {
    content: '✎';
    position: absolute;
    right: 0.4rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--violet-light);
    font-size: 0.75rem;
}

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

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

.badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 99px;
    font-size: 0.78rem;
    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;
    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: 44px; text-align: center; }

/* Photos */
.photo-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform var(--transition);
}
.photo-thumb:hover { transform: scale(1.06); }

/* 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 PHOTO
   ============================================================ */
.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); }

/* ============================================================
   ÉTAT ACCUEIL (pas de collection sélectionnée)
   ============================================================ */
.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; }

/* ============================================================
   RESPONSIVE — 3 paliers
   > 1024px  : PC grand écran  (défaut, styles de base)
   768-1024px : PC petit / tablette
   < 768px   : mobile
   ============================================================ */

/* ----------------------------------------------------------
   Correctifs communs à toutes tailles :
   évite le débordement horizontal du tableau
   ---------------------------------------------------------- */
.table-wrapper {
    -webkit-overflow-scrolling: touch; /* scroll fluide iOS */
}

table {
    /* Le tableau peut scroller horizontalement sans casser la mise en page */
    min-width: 320px;
}

td {
    /* Coupe les très longs textes sans casser le layout */
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 340px;
}

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

/* ----------------------------------------------------------
   PC PETIT / TABLETTE  768px – 1024px
   ---------------------------------------------------------- */
@media (max-width: 1024px) {
    /* Controls : les selects rétrécissent un peu */
    .controls-bar select { max-width: 180px; }

    /* La barre de recherche prend l'espace restant sans dépasser */
    .search-wrapper { max-width: 260px; }

    /* Tableau : padding légèrement réduit */
    th { padding: 0.6rem 0.7rem; font-size: 0.75rem; }
    td { padding: 0.5rem 0.7rem; font-size: 0.88rem; }

    /* Boutons d'action : texte un poil plus compact */
    .actions-bar .btn { font-size: 0.85rem; padding: 0.45rem 0.9rem; }

    /* Stats bar moins large pour ne pas prendre trop de place */
    .stats-bar-outer { max-width: 180px; }
}

/* ----------------------------------------------------------
   MOBILE  < 768px
   ---------------------------------------------------------- */
@media (max-width: 767px) {

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

    /* --- Controls : empilés verticalement --- */
    .controls-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding: 0.65rem 0.85rem;
    }
    .controls-bar select {
        max-width: 100%;
        width: 100%;
    }
    .search-wrapper {
        max-width: 100%;
        width: 100%;
    }

    /* --- Barre d'actions : boutons sur 2 lignes si besoin --- */
    .actions-bar {
        flex-wrap: wrap;
        gap: 0.4rem;
        padding: 0.5rem 0.85rem;
    }
    /* Sur très petit écran chaque bouton prend toute la largeur */
    @media (max-width: 400px) {
        .actions-bar .btn { flex: 1 1 100%; justify-content: center; }
    }

    /* --- En-tête collection --- */
    .collection-header {
        flex-direction: row;   /* reste en ligne mais compacte */
        align-items: center;
        padding: 0.6rem 0.85rem;
        gap: 0.75rem;
    }
    .collection-illustration { width: 56px; height: 56px; }
    .collection-name { font-size: 1rem; }
    .collection-stats { font-size: 0.8rem; }
    .stats-bar-outer { max-width: 140px; }

    /* --- Tableau : scroll horizontal, cellules compactes --- */
    .table-wrapper { padding: 0.75rem 0.5rem; }

    th {
        padding: 0.5rem 0.5rem;
        font-size: 0.72rem;
        white-space: nowrap; /* en-têtes ne se cassent pas */
    }
    td {
        padding: 0.45rem 0.5rem;
        font-size: 0.82rem;
        max-width: 200px;
    }

    /* Icône d'édition cachée sur mobile (tap suffit) */
    td.editable:hover::after { display: none; }

    /* Badge possédé plus compact */
    .badge { padding: 0.15rem 0.45rem; font-size: 0.72rem; }

    /* Filtre possédé : boutons plus petits */
    .possede-filter button { padding: 0.08rem 0.3rem; font-size: 0.6rem; }

    /* Miniature photo légèrement plus petite */
    .photo-thumb { width: 50px; height: 50px; }

    /* --- Modales : pleine largeur, collées en bas sur mobile --- */
    .modal-overlay {
        align-items: flex-end;  /* modal glisse depuis le bas */
        padding: 0;
    }
    .modal {
        max-width: 100%;
        border-radius: var(--radius) var(--radius) 0 0;
        max-height: 85vh;
    }

    /* --- Boutons globaux --- */
    .btn { font-size: 0.85rem; padding: 0.45rem 0.85rem; }

    /* --- Message d'accueil --- */
    .welcome-msg { padding: 3rem 1rem; }
    .welcome-msg .welcome-icon { font-size: 2.5rem; }
}
