/**
 * ============================================================================
 * viewer3d.css - Styles du viewer 3D pour PrestaShop (v3)
 * ============================================================================
 *
 * La position de la toolbar est pilotee par une classe sur le wrapper :
 *   .v3d-toolbar-left   → colonne gauche
 *   .v3d-toolbar-right  → colonne droite
 *   .v3d-toolbar-top    → barre horizontale en haut
 *   .v3d-toolbar-bottom → barre horizontale en bas
 *   .v3d-toolbar-hidden → toolbar masquee
 *
 * La hauteur est definie inline par le JS (data-config).
 *
 * ============================================================================
 */

/* =========================================================================
   Conteneur principal
   ========================================================================= */
.v3d-viewer3d-wrapper {
    position: relative;
    width: 100%;
    /* La hauteur est definie inline par le JS */
    height: 600px;
    margin: 20px 0;
    border-radius: 8px;
    overflow: hidden;
    background: #d0d0d0;
    display: flex;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* =========================================================================
   Zone de rendu (canvas)
   ========================================================================= */
.v3d-canvas-container {
    flex: 1;
    position: relative;
    min-width: 0;
    min-height: 0;
}

.v3d-canvas-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* =========================================================================
   Toolbar - styles de base (communs a toutes les positions)
   ========================================================================= */
.v3d-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(30, 30, 30, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    flex-shrink: 0;
}

/* =========================================================================
   POSITION : LEFT (toolbar verticale a gauche)
   ========================================================================= */
.v3d-toolbar-left {
    flex-direction: row;
}

.v3d-toolbar-left .v3d-toolbar {
    flex-direction: column;
    padding: 10px 6px;
    order: 0;
}

.v3d-toolbar-left .v3d-canvas-container {
    order: 1;
}

.v3d-toolbar-left .v3d-toolbar-separator {
    width: 24px;
    height: 1px;
    margin: 4px 0;
}

.v3d-toolbar-left .v3d-dropdown-up,
.v3d-toolbar-left .v3d-model-info-tooltip {
    left: calc(100% + 8px);
    top: 50%;
    bottom: auto;
    right: auto;
    transform: translateY(-50%);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
}

/* =========================================================================
   POSITION : RIGHT (toolbar verticale a droite)
   ========================================================================= */
.v3d-toolbar-right {
    flex-direction: row;
}

.v3d-toolbar-right .v3d-toolbar {
    flex-direction: column;
    padding: 10px 6px;
    order: 1;
}

.v3d-toolbar-right .v3d-canvas-container {
    order: 0;
}

.v3d-toolbar-right .v3d-toolbar-separator {
    width: 24px;
    height: 1px;
    margin: 4px 0;
}

.v3d-toolbar-right .v3d-dropdown-up,
.v3d-toolbar-right .v3d-model-info-tooltip {
    right: calc(100% + 8px);
    left: auto;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.4);
}

/* =========================================================================
   POSITION : TOP (toolbar horizontale en haut)
   ========================================================================= */
.v3d-toolbar-top {
    flex-direction: column;
}

.v3d-toolbar-top .v3d-toolbar {
    flex-direction: row;
    justify-content: center;
    padding: 6px 10px;
    order: 0;
}

.v3d-toolbar-top .v3d-canvas-container {
    order: 1;
}

.v3d-toolbar-top .v3d-toolbar-separator {
    width: 1px;
    height: 20px;
    margin: 0 4px;
}

.v3d-toolbar-top .v3d-dropdown-up,
.v3d-toolbar-top .v3d-model-info-tooltip {
    top: calc(100% + 8px);
    bottom: auto;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* =========================================================================
   POSITION : BOTTOM (toolbar horizontale en bas)
   ========================================================================= */
.v3d-toolbar-bottom {
    flex-direction: column;
}

.v3d-toolbar-bottom .v3d-toolbar {
    flex-direction: row;
    justify-content: center;
    padding: 6px 10px;
    order: 1;
}

.v3d-toolbar-bottom .v3d-canvas-container {
    order: 0;
}

.v3d-toolbar-bottom .v3d-toolbar-separator {
    width: 1px;
    height: 20px;
    margin: 0 4px;
}

.v3d-toolbar-bottom .v3d-dropdown-up,
.v3d-toolbar-bottom .v3d-model-info-tooltip {
    bottom: calc(100% + 8px);
    top: auto;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

/* =========================================================================
   POSITION : HIDDEN (toolbar masquee)
   ========================================================================= */
.v3d-toolbar-hidden .v3d-toolbar {
    display: none;
}

/* =========================================================================
   Boutons de la toolbar
   ========================================================================= */
.v3d-toolbar-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.8);
    padding: 0;
    transition: background 0.15s, color 0.15s;
    position: relative;
    flex-shrink: 0;
}

.v3d-toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.v3d-toolbar-btn.v3d-active {
    background: rgba(102, 126, 234, 0.3);
    color: #667eea;
}

.v3d-toolbar-btn svg {
    width: 20px;
    height: 20px;
    pointer-events: none;
}

/* =========================================================================
   Separateur (defaut pour vertical, surcharge par position)
   ========================================================================= */
.v3d-toolbar-separator {
    background: rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

/* =========================================================================
   Wrapper pour un bouton + son dropdown
   ========================================================================= */
.v3d-toolbar-btn-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

/* =========================================================================
   Dropdowns - styles de base
   ========================================================================= */
.v3d-dropdown-up {
    position: absolute;
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 8px;
    padding: 12px;
    max-height: 400px;
    overflow-y: auto;
    color: #fff;
    display: none;
    z-index: 1010;
    min-width: 200px;
}

.v3d-dropdown-up.v3d-open {
    display: block;
}

/* =========================================================================
   Tooltip info modele - styles de base
   ========================================================================= */
.v3d-model-info-tooltip {
    position: absolute;
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 8px;
    padding: 10px 14px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 12px;
    line-height: 1.6;
    white-space: nowrap;
    display: none;
    z-index: 1010;
}

.v3d-model-info-tooltip.v3d-open {
    display: block;
}

/* =========================================================================
   Grille de textures (dans le dropdown materiaux)
   ========================================================================= */
.v3d-texture-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    min-width: 260px;
}

.v3d-texture-item {
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
}

.v3d-texture-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    border-color: rgba(102, 126, 234, 0.5);
}

.v3d-texture-item.v3d-selected {
    border-color: #667eea;
}

.v3d-texture-item img {
    width: 100%;
    height: 70px;
    object-fit: cover;
    display: block;
}

.v3d-texture-name {
    padding: 4px 6px;
    font-size: 10px;
    text-align: center;
    background: rgba(0, 0, 0, 0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.v3d-texture-reset-btn {
    width: 100%;
    margin-top: 8px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s;
}

.v3d-texture-reset-btn:hover {
    background: rgba(245, 87, 108, 0.3);
}

/* =========================================================================
   Panneau de clipping
   ========================================================================= */
.v3d-clipping-panel {
    width: 220px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.v3d-clipping-axes {
    display: flex;
    gap: 6px;
}

.v3d-clipping-axis-btn {
    flex: 1;
    padding: 6px 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-align: center;
}

.v3d-clipping-axis-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.v3d-clipping-axis-btn.v3d-active {
    background: rgba(102, 126, 234, 0.3);
    border-color: #667eea;
    color: #667eea;
}

.v3d-clipping-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.v3d-clipping-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
}

.v3d-clipping-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
}

/* =========================================================================
   Panneau de rotation eclairage
   ========================================================================= */
.v3d-light-panel {
    width: 200px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.v3d-light-panel label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
}

.v3d-light-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.v3d-light-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffc107;
    cursor: pointer;
}

.v3d-light-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffc107;
    cursor: pointer;
    border: none;
}

/* =========================================================================
   Labels de mesure
   ========================================================================= */
.v3d-measurement-label {
    position: absolute;
    background: rgba(102, 126, 234, 0.9);
    color: #fff;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    pointer-events: none;
    white-space: nowrap;
    transform: translate(-50%, -50%);
    z-index: 1005;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* =========================================================================
   Labels de cotes (dimensions)
   ========================================================================= */
.v3d-dimension-label {
    position: absolute;
    background: rgba(30, 30, 30, 0.92);
    color: #fff;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 700;
    pointer-events: none;
    white-space: nowrap;
    transform: translate(-50%, -50%);
    z-index: 1005;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(102, 126, 234, 0.6);
    letter-spacing: 0.3px;
}

.v3d-dim-prefix {
    color: #667eea;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    margin-right: 4px;
}

/* =========================================================================
   Overlay de chargement
   ========================================================================= */
.v3d-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(208, 208, 208, 0.95);
    z-index: 1001;
    gap: 12px;
    font-size: 14px;
    color: #333;
}

.v3d-loading.v3d-hidden {
    display: none;
}

.v3d-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(102, 126, 234, 0.2);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: v3d-spin 0.8s linear infinite;
}

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

/* =========================================================================
   View cube (coin haut-droit)
   ========================================================================= */
.v3d-viewcube-canvas {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 120px;
    height: 120px;
    cursor: pointer;
    z-index: 999;
    border-radius: 8px;
}

/* =========================================================================
   Mode plein ecran
   ========================================================================= */
.v3d-viewer3d-wrapper:fullscreen {
    height: 100vh !important;
    border-radius: 0;
}

/* =========================================================================
   Mode dessin (bordure rouge)
   ========================================================================= */
.v3d-viewer3d-wrapper.v3d-draw-mode {
    outline: 3px solid #ff4444;
    outline-offset: -3px;
}

/* =========================================================================
   Barre flottante du mode dessin (dans le viewport)
   ========================================================================= */
.v3d-draw-bar {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: rgba(30, 30, 30, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    z-index: 1010;
    pointer-events: auto;
}

/* Pastilles de couleur */
.v3d-draw-color {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    padding: 0;
    transition: border-color 0.15s, transform 0.15s;
    flex-shrink: 0;
}

.v3d-draw-color:hover {
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.15);
}

.v3d-draw-color.v3d-active {
    border-color: #fff;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

/* Boutons de taille */
.v3d-draw-size {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.6);
    padding: 0;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.v3d-draw-size:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.v3d-draw-size.v3d-active {
    background: rgba(102, 126, 234, 0.3);
    color: #667eea;
}

/* Boutons d'action (undo, clear, close) */
.v3d-draw-action {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.7);
    padding: 0;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.v3d-draw-action:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.v3d-draw-close:hover {
    background: rgba(255, 68, 68, 0.3);
    color: #ff4444;
}

/* Label dans la barre flottante (ex: "Coupe") */
.v3d-clip-label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    white-space: nowrap;
    padding: 0 4px;
}

/* Slider dans la barre flottante de coupe */
.v3d-clip-slider {
    width: 140px;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    flex-shrink: 0;
}

.v3d-clip-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
}

.v3d-clip-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
}

/* Separateur vertical */
.v3d-draw-bar-sep {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
    margin: 0 2px;
}

/* =========================================================================
   Overlay de securite (DevTools detection)
   ========================================================================= */
.v3d-security-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
}

.v3d-security-overlay.v3d-hidden {
    display: none;
}

.v3d-security-msg {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    font-weight: 500;
}

.v3d-security-msg svg {
    opacity: 0.5;
}

/* =========================================================================
   Responsive mobile — ajustements complementaires
   On ne force plus la position toolbar ici (c'est geré par la config),
   mais on adapte les tailles.
   ========================================================================= */
@media (max-width: 768px) {
    .v3d-toolbar-btn {
        width: 32px;
        height: 32px;
    }

    .v3d-toolbar-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Dropdowns plus petits sur mobile */
    .v3d-dropdown-up {
        max-height: 250px;
        max-width: calc(100vw - 24px);
    }

    /* Grille de textures en 2 colonnes */
    .v3d-texture-grid {
        grid-template-columns: repeat(2, 1fr);
        min-width: 180px;
    }

    /* View cube plus petit */
    .v3d-viewcube-canvas {
        width: 80px;
        height: 80px;
        top: 5px;
        right: 5px;
    }
}
