.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}

.glass-sidebar {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--glass-border);
    width: 340px !important;
}

.glass-card {
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.glass-btn {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(5px);
    border: 1px solid var(--glass-border);
    transition: all 0.3s ease;
}

.glass-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.generate-btn {
    background: linear-gradient(135deg, #0d6efd, #6610f2);
    border: none;
    transition: all 0.3s ease;
}

.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(13, 110, 253, 0.4) !important;
}

.image-wrapper {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    width: 100%;
    max-width: 800px;
    height: 100%;
    max-height: 100%;
}

#resultImage {
    background-color: #1a1d21;
    background-image:
        linear-gradient(45deg, #24282d 25%, transparent 25%, transparent 75%, #24282d 75%, #24282d),
        linear-gradient(45deg, #24282d 25%, transparent 25%, transparent 75%, #24282d 75%, #24282d);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
}

/* --- MENU D'ACTIONS (opaque pour rester lisible sur image claire) --- */
#actionBar .dropdown-menu {
    --bs-dropdown-min-width: 12rem;
    background: rgba(24, 27, 31, 0.98);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
}
#actionBar .dropdown-item {
    color: #e9ecef;
    border-radius: 8px;
}
#actionBar .dropdown-item:hover:not(.disabled),
#actionBar .dropdown-item:focus:not(.disabled) {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}
#actionBar .dropdown-item.disabled {
    opacity: 0.5;
}

/* --- TEMPLATE CARDS --- */
.template-card {
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
}

.template-card:hover {
    transform: translateY(-4px);
    border-color: rgba(13, 110, 253, 0.5);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2), inset 0 0 0 1px rgba(13, 110, 253, 0.2);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
}

.nav-pills .nav-link.active {
    background-color: #0d6efd;
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
}

/* --- SIDEBAR : LARGEUR & COMPACITÉ --- */
@media (min-width: 992px) {
    .glass-sidebar { width: 320px !important; }
}
.glass-sidebar .offcanvas-body { padding: 1rem !important; }
.glass-sidebar .glass-card { padding: 0.7rem !important; }
.glass-sidebar .mb-3, .glass-sidebar .mb-4 { margin-bottom: 0.55rem !important; }
.glass-sidebar .row.g-2 { margin-bottom: 0.55rem !important; }
.glass-sidebar .form-label { margin-bottom: 0.2rem !important; }
.glass-sidebar .form-range { margin-bottom: 0.35rem !important; }
.glass-sidebar .generate-btn,
.glass-sidebar #importFile + button,
.glass-sidebar button[onclick*="importFile"] { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }

/* ==========================================================================
   HISTORIQUE — tiroir droit collapsable + vignettes en grille
   ========================================================================== */
.history-drawer {
    width: 340px !important;
    /* the drawer opens on the right, so mirror the divider side */
    border-right: none;
    border-left: 1px solid var(--glass-border);
}
.history-drawer .offcanvas-body { padding: 0.9rem !important; }

.history-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}
.history-empty { grid-column: 1 / -1; }

.history-item {
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
.history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
}
.history-item.active {
    border-color: #0d6efd;
    box-shadow: 0 0 0 1px rgba(13, 110, 253, 0.45);
}

/* Thumbnail fills the card, square crop — works for both <img> and video wrapper */
.history-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    cursor: pointer;
    background: #1a1d21;
}

/* Video thumbnails: wrapper keeps the play icon centered */
.gallery-video {
    position: relative;
    overflow: hidden;
    background: #1a1d21;
    cursor: pointer;
}
.gallery-video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.gallery-video .gallery-play {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 1rem;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

.history-actions {
    border-top: 1px solid var(--glass-border);
}
.history-actions button {
    flex: 1 1 0;
    border: none;
    background: rgba(255, 255, 255, 0.04);
    color: #cfd3d8;
    padding: 0.4rem 0;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}
.history-actions button + button { border-left: 1px solid var(--glass-border); }
.history-actions button:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.history-actions .btn-del:hover { color: #ff6b6b; background: rgba(255, 107, 107, 0.12); }

/* Bouton d'ouverture de l'historique */
.main-toolbar .btn { border: 1px solid var(--glass-border); }
#historyCount { font-size: 0.65rem; }

/* ==========================================================================
   ÉDITION — aperçu source + zone de dépôt de la référence
   ========================================================================== */
.edit-img-preview,
.edit-ref-dropzone {
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.edit-img-preview img { width: 100%; height: 100%; object-fit: contain; }

.edit-ref-dropzone {
    border-style: dashed;
    cursor: pointer;
    text-align: center;
    color: #9aa0a6;
    padding: 0.5rem;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.edit-ref-dropzone:hover,
.edit-ref-dropzone.dragover {
    border-color: #0d6efd;
    background: rgba(13, 110, 253, 0.08);
    color: #cfd3d8;
}
.edit-ref-dropzone img { width: 100%; height: 100%; object-fit: contain; }

.edit-ref-clear {
    position: absolute;
    top: 6px; right: 6px;
    width: 26px; height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    z-index: 2;
}
.edit-ref-clear:hover { background: rgba(220, 53, 69, 0.85); }

/* ==========================================================================
   OUTPAINT — plan de travail interactif
   ========================================================================== */
.outpaint-stage {
    width: 100%;
    min-height: 240px;
    background: #15181c;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 8px;
}
#outpaintCanvas {
    max-width: 100%;
    max-height: 460px;
    display: block;
    cursor: grab;
    border-radius: 6px;
    touch-action: none; /* let pointer drag pan the image without scrolling */
    background: #7f7f7f;
}
#outpaintCanvas.grabbing { cursor: grabbing; }
