/* Explain: Tri Photos Gallery */
/* ============================================================
   Tri Photos — grille, vignettes, visionneuse et contrôles
   ============================================================ */
.tri-main { max-width: 1800px; margin: 0 auto; padding: 20px clamp(1rem, 3vw, 1.5rem) 100px; }

.section { margin-bottom: 40px; scroll-margin-top: 90px; }

.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.section-title { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.3px; }

.section-stats { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; color: var(--text-dim); font-size: 13px; }

.section-stats .pill {
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.section-stats .pill.target { color: var(--accent); border-color: rgba(192, 132, 87, 0.3); }
.section-stats .pill.ok { color: var(--success); border-color: rgba(74, 222, 128, 0.3); background: rgba(74, 222, 128, 0.08); }
.section-stats .pill.over { color: var(--danger); border-color: rgba(248, 113, 113, 0.3); background: rgba(248, 113, 113, 0.08); }
.section-stats .pill.under { color: var(--warning); border-color: rgba(251, 191, 36, 0.3); background: rgba(251, 191, 36, 0.08); }

.section-actions { display: flex; gap: 6px; }
.section-actions button { padding: 5px 10px; font-size: 12px; }

/* ---------- Grille ---------- */
.tri-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--thumb-size), 1fr)); gap: 8px; }

.tile {
    position: relative;
    aspect-ratio: 3 / 2;
    background: var(--panel-2);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.1s ease, transform 0.1s ease;
}

.tile.selected { border-color: var(--accent); }
.tile.selected::after { content: ""; position: absolute; inset: 0; background: rgba(192, 132, 87, 0.1); pointer-events: none; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity 0.3s ease; }
.tile img.loaded { opacity: 1; }

.tile.loading::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, var(--panel-2) 0%, var(--border) 50%, var(--panel-2) 100%);
    background-size: 200% 100%;
    animation: triShimmer 1.5s infinite;
}

@keyframes triShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.tile .checkbox {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(15, 17, 21, 0.7);
    backdrop-filter: blur(6px);
    border: 2px solid rgba(255, 255, 255, 0.5);
    transition: all 0.15s ease;
}

.tile.selected .checkbox { background: var(--accent); border-color: #fff; }
.tile .checkbox i { font-size: 12px; color: #fff; opacity: 0; }
.tile.selected .checkbox i { opacity: 1; }

.tile .label {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 20px 8px 6px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
    color: #fff;
    font-size: 10px;
    font-family: ui-monospace, SF Mono, Monaco, monospace;
    opacity: 0;
    transition: opacity 0.15s ease;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
}

.tile:hover .label { opacity: 1; }

.tile .burst-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 2;
    display: none;
    padding: 2px 7px;
    background: rgba(15, 17, 21, 0.7);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    color: #fff;
    font-size: 10px;
    font-weight: 500;
}

.tile.in-burst .burst-badge { display: block; }
.tile:hover { transform: scale(1.02); }

.tile.unsupported { background: repeating-linear-gradient(45deg, var(--panel-2) 0 10px, var(--border) 10px 20px); }

.tile .unsupported-badge {
    position: absolute;
    inset: 50% 0 auto 0;
    transform: translateY(-50%);
    text-align: center;
    color: var(--text-mute);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

/* ---------- Cible modifiable ---------- */
.target-input {
    width: 48px;
    padding: 0;
    background: transparent;
    border: none;
    color: inherit;
    font: inherit;
    font-weight: 600;
    text-align: center;
    font-variant-numeric: tabular-nums;
    -moz-appearance: textfield;
}

.target-input::-webkit-outer-spin-button,
.target-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.target-input:focus { outline: none; background: var(--panel); border-radius: 4px; }
.pill.target { cursor: text; }
.pill.target:hover { background: var(--panel); }

/* ---------- Aperçu au survol ---------- */
#hoverPreview {
    position: fixed;
    z-index: 95;
    padding: 8px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-strong);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.12s ease;
}

#hoverPreview.show { opacity: 1; visibility: visible; }
#hoverPreview img { display: block; width: auto; height: auto; max-width: 520px; max-height: 520px; border-radius: var(--radius-sm); background: #000; }

#hoverPreview .meta {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 6px;
    padding: 0 4px;
    font-size: 11px;
    color: var(--text-dim);
    font-family: ui-monospace, SF Mono, Monaco, monospace;
}

@media (max-width: 720px) { #hoverPreview { display: none !important; } }

/* ---------- Visionneuse ---------- */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 40px;
    background: rgba(0, 0, 0, 0.92);
}

.lightbox.show { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-sm); box-shadow: var(--shadow-strong); }

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.15s ease;
}

.lightbox-nav:hover { background: rgba(255, 255, 255, 0.2); }
.lightbox-nav.prev { left: 24px; }
.lightbox-nav.next { right: 24px; }

.lightbox-info {
    position: absolute;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: calc(100% - 32px);
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 999px;
    color: #fff;
    font-size: 13px;
    font-family: ui-monospace, SF Mono, Monaco, monospace;
    backdrop-filter: blur(10px);
}

.lightbox-toggle {
    padding: 6px 14px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
}

.lightbox-toggle.unselect { background: var(--panel-2); color: var(--text); }

.lightbox-close {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.lightbox-close:hover { background: rgba(255, 255, 255, 0.2); }

/* ---------- Barre d'export ---------- */
.export-bar {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 20px;
    max-width: calc(100% - 32px);
    padding: 10px 10px 10px 24px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: var(--shadow-strong);
}

.export-bar .summary { font-size: 14px; color: var(--text-dim); }
.export-bar .summary b { color: var(--text); font-variant-numeric: tabular-nums; }
.export-bar button.primary { padding: 10px 20px; }

/* ---------- Notification ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 100px;
    z-index: 1100;
    padding: 12px 20px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-strong);
    font-size: 14px;
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
    transition: all 0.3s ease;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: rgba(74, 222, 128, 0.4); }
.toast.error { border-color: rgba(248, 113, 113, 0.4); color: var(--danger); }

/* ---------- Divers ---------- */
.tri-root .hidden { display: none !important; }

.tri-root ::-webkit-scrollbar { width: 10px; height: 10px; }
.tri-root ::-webkit-scrollbar-track { background: transparent; }
.tri-root ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

@media (max-width: 720px) {
    .tri-root { --thumb-size: 110px; }
    .tri-header { padding: 10px 16px; }
    .tri-main { padding: 16px 16px 120px; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .export-bar { left: 16px; right: 16px; transform: none; border-radius: var(--radius); padding: 12px 16px; }
    .count-badge { font-size: 12px; padding: 6px 10px; }
    .count-badge .big { font-size: 16px; }
    .lightbox { padding: 16px; }
    .lightbox-nav { width: 44px; height: 44px; }
    .lightbox-nav.prev { left: 8px; }
    .lightbox-nav.next { right: 8px; }
}