/**
 * viewer.css — Styles de la visionneuse autonome Anwynn
 * © 2025 Anwynn — anwynn@laposte.net — anwynn.be
 */

/* ── Conteneur principal ───────────────────────────────────────────────────── */
.mod-viewer3d { position: relative; width: 100%; }

.mod-viewer3d-title {
    margin: 0 0 0.5em;
    font-size: 1.1rem;
    font-weight: 400;
}

.mod-viewer3d-wrap {
    position: relative;
    display: flex;
    overflow: hidden;
    background: #191919;
    border-radius: 4px;
}

/* ── Panneau latéral ───────────────────────────────────────────────────────── */
.mv3d-panel {
    width: 220px;
    flex-shrink: 0;
    background: #222;
    display: flex;
    flex-direction: column;
    z-index: 5;
}

.mv3d-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6em 0.8em;
    background: #2a2a2a;
    border-bottom: 1px solid #333;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #888;
    flex-shrink: 0;
}

.mv3d-btn-close {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0 0.2em;
    transition: color 0.2s;
}
.mv3d-btn-close:hover { color: #ccc; }

.mv3d-model-list {
    list-style: none;
    margin: 0;
    padding: 0.3em 0;
    overflow-y: auto;
    flex-grow: 1;
}

.mv3d-panel-footer {
    flex-shrink: 0;
    padding: 0.5em;
    border-top: 1px solid #333;
}

.mv3d-btn-fullwidth {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4em;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    color: #aaa;
    font-size: 0.75rem;
    padding: 0.45em 0.5em;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.mv3d-btn-fullwidth:hover { background: #333; color: #ddd; }
.mv3d-btn-fullwidth.mv3d-btn-fullwidth--active {
    background: #7eb8f7;
    color: #111;
    border-color: #7eb8f7;
}

.mv3d-model-item {
    display: flex;
    flex-direction: column;
    padding: 0.55em 0.8em;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s;
}
.mv3d-model-item:hover  { background: #2d2d2d; padding-left: 25px;}
.mv3d-model-item.active { background: #1e2d3d; border-left-color: #7eb8f7; padding-left: 25px;}

.mv3d-name { font-size: 0.82rem; color: #ddd; word-break: break-all; }
.mv3d-size { font-size: 0.7rem; color: #666; margin-top: 0.1em; }

.mv3d-loading, .mv3d-empty {
    padding: 1em;
    font-size: 0.8rem;
    color: #666;
    font-style: italic;
    list-style: none;
}

/* Bouton ré-afficher le panneau */
.mv3d-btn-show {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    background: #2a2a2a;
    border: 1px solid #444;
    border-left: none;
    color: #ccc;
    font-size: 0.75rem;
    padding: 0.7em 0.4em;
    cursor: pointer;
    writing-mode: vertical-lr;
    border-radius: 0 4px 4px 0;
    transition: background 0.2s;
}
.mv3d-btn-show:hover { background: #383838; }

/* ── Dropdown ──────────────────────────────────────────────────────────────── */
.mv3d-dropdown-wrap {
    position: absolute;
    top: 0.5em;
    left: 0.5em;
    z-index: 10;
}

/* Masquage forcé (modèle unique / forcé en backend) : spécificité (0,2,0) volontairement
   supérieure à la règle ".mv3d-dropdown-wrap { display:block !important; }" du media query
   mobile ci-dessous (0,1,0), pour qu'elle l'emporte même en dessous de 768px. */
.mv3d-dropdown-wrap.mv3d-force-hidden {
    display: none !important;
}

.mv3d-select {
    background: #2a2a2a;
    color: #ddd;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 0.4em 0.6em;
    font-size: 0.85rem;
    cursor: pointer;
    max-width: 200px;
}

/* ── Colonne viewer (zone 3D + commentaire) ────────────────────────────────── */
.mv3d-viewer-col {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ── Zone viewer ───────────────────────────────────────────────────────────── */
.mv3d-viewer-zone {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
}

.mv3d-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.mv3d-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    font-size: 0.9rem;
    text-align: center;
    padding: 2em;
    font-family: sans-serif;
    background-size: contain;
    background-position: center center;
    background-repeat: no-repeat;
}

/* Reprise des styles axes depuis le viewer standalone */
.axes {
    width: 80px;
    height: 80px;
    margin: 12px;
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 10;
    pointer-events: none;
}

/* ── Barre d'outils (bas-droite) ───────────────────────────────────────────── */
.mv3d-toolbar {
    position: absolute;
    bottom: 0.5em;
    right: 0.5em;
    z-index: 20;
    display: flex;
    gap: 0.4em;
}

.mv3d-btn-tool {
    background: rgba(40,40,40,0.85);
    border: 1px solid #444;
    border-radius: 4px;
    color: #ccc;
    padding: 0.35em 0.5em;
    cursor: pointer;
    display: flex;
    align-items: center;
    line-height: 1;
    transition: background 0.2s, color 0.2s;
}
.mv3d-btn-tool:hover { background: #444; color: #fff; }
.mv3d-btn-tool.mv3d-btn-tool--active { background: #7eb8f7; color: #111; border-color: #7eb8f7; }

/* Colonne viewer en plein écran (repli CSS, utilisé si l'API plein écran native est indisponible) */
.mv3d-viewer-col.mv3d-fullscreen {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999;
    border-radius: 0;
}

/* Colonne viewer en plein écran natif (API Fullscreen) : le navigateur gère déjà le
   positionnement/la taille via la couche plein écran, on ajuste juste l'apparence. */
.mv3d-viewer-col:fullscreen,
.mv3d-viewer-col:-webkit-full-screen {
    width: 100%;
    height: 100%;
    border-radius: 0;
    background: #000;
}

/* ── Panneau plans de coupe ─────────────────────────────────────────────────── */
.mv3d-clip-panel {
    position: absolute;
    bottom: 3em;
    right: 0.5em;
    z-index: 20;
    background: rgba(30,30,30,0.92);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 0.7em 0.8em;
    width: 190px;
    font-size: 0.8rem;
    color: #ddd;
}
.mv3d-clip-row {
    display: flex;
    align-items: center;
    gap: 0.4em;
    margin-bottom: 0.5em;
}
.mv3d-clip-axes {
    display: flex;
    gap: 0.3em;
    margin-bottom: 0.5em;
}
.mv3d-clip-axes button {
    flex: 1;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    color: #bbb;
    padding: 0.25em 0;
    cursor: pointer;
    font-size: 0.75rem;
}
.mv3d-clip-axes button.mv3d-clip-axis--active { background: #7eb8f7; color: #111; border-color: #7eb8f7; }
.mv3d-clip-panel input[type="range"] { width: 100%; margin-bottom: 0.5em; }

/* ── Mesure de distances ────────────────────────────────────────────────────── */
.mv3d-measure-line {
    position: absolute;
    height: 2px;
    background: #7eb8f7;
    transform-origin: 0 50%;
    pointer-events: none;
    z-index: 8;
}
.mv3d-measure-point {
    position: absolute;
    width: 8px;
    height: 8px;
    margin: -4px 0 0 -4px;
    border-radius: 50%;
    background: #7eb8f7;
    border: 2px solid rgba(255,255,255,0.9);
    pointer-events: none;
    z-index: 9;
}
.mv3d-measure-label {
    position: absolute;
    transform: translate(-50%, calc(-100% - 8px));
    background: rgba(24,24,24,0.92);
    border: 1px solid #7eb8f7;
    border-radius: 4px;
    padding: 0.2em 0.6em;
    font-size: 0.78rem;
    color: #eee;
    white-space: nowrap;
    pointer-events: auto;
    cursor: pointer;
    z-index: 9;
}
.mv3d-measure-hidden { display: none; }

/* Aperçu d'étalonnage (feuille de réglages) — même style que les mesures,
   teinte différente pour ne pas les confondre visuellement. */
.mv3d-calib-point { background: #f7b84a; }
.mv3d-calib-line  { background: #f7b84a; }

/* ── Panneau des mesures (hors fenêtre de visualisation, à gauche) ──────────── */
.mv3d-measure-panel {
    width: 270px;
    flex-shrink: 0;
    background: #222;
    display: flex;
    flex-direction: column;
    z-index: 5;
    border-right: 1px solid #333;
}

.mv3d-measure-list {
    overflow-y: auto;
    flex-grow: 1;
    padding: 0.4em;
}

.mv3d-measure-clearall-btn {
    font-size: 1.15rem;
    padding: 0.15em 0.4em;
}

.mv3d-measure-empty {
    padding: 0.8em;
    font-size: 0.78rem;
    color: #666;
    font-style: italic;
    margin: 0;
}

.mv3d-measure-row {
    background: #2a2a2a;
    border-radius: 4px;
    padding: 0.5em 0.6em;
    margin-bottom: 0.5em;
}

.mv3d-measure-row-head {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 0.3em;
}

.mv3d-measure-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5em;
    height: 1.5em;
    border-radius: 50%;
    background: #7eb8f7;
    color: #111;
    font-weight: 700;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.mv3d-measure-value {
    flex-grow: 1;
    font-size: 0.85rem;
    color: #eee;
}

.mv3d-measure-del {
    background: #333;
    border: 1px solid #555;
    border-radius: 4px;
    color: #ccc;
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
    width: 1.9em;
    height: 1.9em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.mv3d-measure-del:hover { color: #fff; background: #e57373; border-color: #e57373; }

.mv3d-measure-note {
    font-size: 0.68rem;
    color: #888;
    margin-bottom: 0.3em;
}

.mv3d-measure-legend {
    display: grid;
    grid-template-columns: auto repeat(3, 1fr);
    gap: 0.25em;
    padding: 0 0.15em;
    margin-bottom: 0.4em;
}
.mv3d-measure-legend span {
    text-align: center;
}
.mv3d-measure-legend span:first-child { visibility: hidden; }
.mv3d-axis-dot {
    display: inline-block;
    width: 0.75em;
    height: 0.75em;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.4);
}
.mv3d-axis-x { background: #ff0000; }
.mv3d-axis-y { background: #00ff00; }
.mv3d-axis-z { background: #0000ff; }

.mv3d-measure-coords {
    display: grid;
    grid-template-columns: auto repeat(3, 1fr);
    align-items: center;
    gap: 0.25em;
    margin-top: 0.25em;
}

.mv3d-measure-coords-label {
    font-size: 0.68rem;
    color: #999;
    white-space: nowrap;
}

.mv3d-measure-coord-input {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    background: #1c1c1c;
    border: 1px solid #444;
    border-radius: 3px;
    color: #ddd;
    font-size: 0.7rem;
    padding: 0.25em 0.15em 0.25em 0.35em;
}
.mv3d-measure-coord-input:focus {
    outline: none;
    border-color: #7eb8f7;
}


/* ── Réglages ───────────────────────────────────────────────────────────────── */
.mv3d-btn-settings {
    position: absolute;
    top: 0.5em;
    right: 0.5em;
    z-index: 20;
    background: rgba(40,40,40,0.85);
    border: 1px solid #444;
    border-radius: 4px;
    color: #ccc;
    padding: 0.3em 0.5em;
    text-decoration: none;
    display: flex;
    align-items: center;
    transition: background 0.2s, color 0.2s;
}
.mv3d-btn-settings:hover { background: #444; color: #fff; }

/* ── Cercle de chargement ──────────────────────────────────────────────────── */
.mv3d-loading-circle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 140px;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.mv3d-loading-circle svg {
    position: absolute;
    top: 0; left: 0;
    width: 140px; height: 140px;
}

.mv3d-loading-circle .lc-track {
    fill: none;
    stroke: #2e2e2e;
    stroke-width: 5;
}

.mv3d-loading-circle .lc-arc {
    fill: none;
    stroke: #4caf82;
    stroke-width: 5;
    stroke-linecap: round;
    stroke-dasharray: 110 330;
    animation: mv3d-rotate 1.2s linear infinite;
    transform-origin: 80px 80px;
}

.mv3d-loading-circle .lc-time {
    position: relative;
    z-index: 1;
    font-family: sans-serif;
    font-size: 1.3rem;
    font-weight: 300;
    color: #4caf82;
    font-variant-numeric: tabular-nums;
}

@keyframes mv3d-rotate {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .mv3d-panel { display: none !important; }
    .mv3d-measure-panel { display: none !important; }
    .mv3d-dropdown-wrap { display: block !important; }
}

/* ── Commentaire modèle ────────────────────────────────────────────────────── */
.mv3d-comment-wrap {
    flex-shrink: 0;
    text-align: center;
    padding: 0.55em 1em;
    font-size: 0.82rem;
    line-height: 1.5;
    white-space: pre-line;
    word-break: break-word;
}

/* ── Interaction hint (main animée) ────────────────────────────────────────── */
.mv3d-interaction-hint {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.mv3d-hint-hand {
    width: 25px;
    height: 36px;
    opacity: 0;
    /* La position X et l'opacité sont pilotées intégralement par JS */
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
    will-change: transform, opacity;
}

/* ── Repères cliquables (hotspots) ─────────────────────────────────────────── */
.mv3d-markers-layer {
    position: absolute;
    inset: 0;
    pointer-events: none; /* seuls les enfants (pin, popup) réagissent aux clics */
    overflow: hidden;
    z-index: 8;
}

.mv3d-marker-pin {
    --mv3d-marker-color: #ffb400;
    position: absolute;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border-radius: 50%;
    background: var(--mv3d-marker-color);
    border: 2px solid rgba(255,255,255,0.9);
    box-shadow: 0 0 0 rgba(255,255,255,0.5), 0 1px 4px rgba(0,0,0,0.5);
    cursor: pointer;
    pointer-events: auto;
    animation: mv3d-marker-pulse 2.2s ease-out infinite;
}

.mv3d-marker-pin:hover {
    animation-play-state: paused;
    transform: scale(1.15);
}

.mv3d-marker-pin.mv3d-marker-hidden {
    display: none;
}

.mv3d-marker-popup.mv3d-marker-hidden {
    display: none !important;
}

@keyframes mv3d-marker-pulse {
    0%   { box-shadow: 0 0 0 0    rgba(255,255,255,0.45), 0 1px 4px rgba(0,0,0,0.5); }
    70%  { box-shadow: 0 0 0 10px rgba(255,255,255,0),    0 1px 4px rgba(0,0,0,0.5); }
    100% { box-shadow: 0 0 0 0    rgba(255,255,255,0),    0 1px 4px rgba(0,0,0,0.5); }
}

.mv3d-marker-popup {
    --mv3d-marker-color: #ffb400;
    position: absolute;
    transform: translate(14px, -50%);
    min-width: 160px;
    max-width: 260px;
    background: rgba(24,24,24,0.96);
    border: 1px solid var(--mv3d-marker-color);
    border-radius: 6px;
    padding: 0.6em 0.8em;
    font-size: 0.8rem;
    line-height: 1.45;
    color: #eee;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    pointer-events: auto;
    z-index: 9;
    display: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.mv3d-marker-popup.mv3d-marker-popup--open {
    display: block;
    opacity: 1;
}

.mv3d-marker-popup-title {
    margin: 0 1.4em 0.3em 0;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--mv3d-marker-color);
}

.mv3d-marker-popup-text {
    white-space: pre-line;
    word-break: break-word;
}

.mv3d-marker-popup-close {
    position: absolute;
    top: 0.3em;
    right: 0.4em;
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    padding: 0.2em;
}

.mv3d-marker-popup-close:hover {
    color: #fff;
}

/* ── Repères en mode "trait + titre" ───────────────────────────────────────── */
.mv3d-marker-line {
    --mv3d-marker-color: #ffb400;
    position: absolute;
    height: 2px;
    background: var(--mv3d-marker-color);
    transform-origin: 0 50%;
    pointer-events: none;
    opacity: 0.85;
}

.mv3d-marker-label {
    --mv3d-marker-color: #ffb400;
    position: absolute;
    max-width: 200px;
    padding: 0.15em 0.55em;
    background: rgba(24,24,24,0.88);
    color: #eee;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    pointer-events: auto;
}

.mv3d-marker-label:hover {
    background: rgba(34,34,34,0.95);
}

/* Orientation selon le quadrant de l'écran (diagonales reliant les 4 coins) —
   le titre "s'éloigne" toujours du centre pour rester lisible près des bords. */
.mv3d-marker-label--right {
    transform: translate(6px, -50%);
    border-left: 3px solid var(--mv3d-marker-color);
    border-radius: 0 3px 3px 0;
}
.mv3d-marker-label--left {
    transform: translate(calc(-100% - 6px), -50%);
    border-right: 3px solid var(--mv3d-marker-color);
    border-radius: 3px 0 0 3px;
    text-align: right;
}
.mv3d-marker-label--top {
    transform: translate(-50%, calc(-100% - 6px));
    border-bottom: 3px solid var(--mv3d-marker-color);
    border-radius: 3px 3px 0 0;
}
.mv3d-marker-label--bottom {
    transform: translate(-50%, 6px);
    border-top: 3px solid var(--mv3d-marker-color);
    border-radius: 0 0 3px 3px;
}

.mv3d-marker-line.mv3d-marker-hidden,
.mv3d-marker-label.mv3d-marker-hidden {
    display: none;
}

/* ── Calque de sortie RA (dom-overlay minimal, pas toute la page) ────────────── */
.mv3d-ar-exit-overlay {
    display: none;
    position: fixed;
    inset: 0;
    /* Laisse passer les interactions vers la scène RA partout sauf sur le bouton. */
    pointer-events: none;
    z-index: 999999;
}

.mv3d-ar-exit-btn {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    pointer-events: auto;
    background: rgba(0,0,0,0.7);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.5);
    border-radius: 20px;
    padding: 0.55em 1.1em;
    font-size: 0.85rem;
    font-family: Arial, sans-serif;
    cursor: pointer;
}
