/* Property 3D Viewer — Frontend */

.p3dv-wrapper {
    --p3dv-bg: #ffffff;
    --p3dv-fg: #111827;
    --p3dv-muted: #6b7280;
    --p3dv-border: #e5e7eb;
    --p3dv-sidebar-bg: #f9fafb;
    --p3dv-accent: #2563eb;

    box-sizing: border-box;
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: 1fr;
    height: var(--p3dv-height, 600px);
    /* Iter 35.2 — fallback de altura mínima para evitar que el wrapper
       colapse cuando el host page lo monta en un contenedor flex/grid
       sin altura explícita. */
    min-height: 320px;
    width: 100%;
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
    color: var(--p3dv-fg);
    background: var(--p3dv-bg);
    border: 1px solid var(--p3dv-border);
    border-radius: 8px;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

.p3dv-wrapper *, .p3dv-wrapper *::before, .p3dv-wrapper *::after { box-sizing: inherit; }

/* Dark theme */
.p3dv-theme-dark {
    --p3dv-bg: #1a1a2e;
    --p3dv-fg: #f3f4f6;
    --p3dv-muted: #9ca3af;
    --p3dv-border: #2a2a3e;
    --p3dv-sidebar-bg: #1f1f33;
    --p3dv-accent: #60a5fa;
}

/* ============ Sidebar ============ */

.p3dv-sidebar {
    background: var(--p3dv-sidebar-bg);
    border-right: 1px solid var(--p3dv-border);
    padding: 1rem;
    overflow-y: auto;
    font-size: 14px;
    -webkit-overflow-scrolling: touch;
}

.p3dv-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    gap: 8px;
}

.p3dv-sidebar-title {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.p3dv-close-sidebar {
    display: none;
    background: transparent;
    border: none;
    font-size: 18px;
    line-height: 1;
    padding: 4px 8px;
    cursor: pointer;
    color: var(--p3dv-muted);
    order: -1;
}

.p3dv-close-sidebar:hover { color: var(--p3dv-fg); }

.p3dv-reset-filters {
    background: transparent;
    border: 1px solid var(--p3dv-border);
    border-radius: 4px;
    padding: 4px 8px;
    color: var(--p3dv-fg);
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}

.p3dv-reset-filters:hover {
    background: var(--p3dv-border);
}

.p3dv-legend,
.p3dv-filter-group {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--p3dv-border);
}

.p3dv-legend:last-child,
.p3dv-filter-group:last-child {
    border-bottom: none;
}

.p3dv-legend h4,
.p3dv-filter-group h4 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--p3dv-muted);
    margin: 0 0 0.5rem;
    font-weight: 700;
}

.p3dv-legend-row,
.p3dv-filter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 13px;
}

.p3dv-filter-item {
    cursor: pointer;
}

.p3dv-filter-item input[type="checkbox"] {
    margin: 0;
    accent-color: var(--p3dv-accent);
}

.p3dv-filter-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.p3dv-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.p3dv-filter-range {
    padding: 4px 0;
}

.p3dv-range-row {
    display: flex;
    gap: 6px;
}

.p3dv-range-row label {
    flex: 1;
    font-size: 12px;
    color: var(--p3dv-muted);
}

.p3dv-range-row input {
    width: 100%;
    margin-top: 2px;
    padding: 4px 6px;
    border: 1px solid var(--p3dv-border);
    border-radius: 3px;
    background: var(--p3dv-bg);
    color: var(--p3dv-fg);
    /* Fijamos font-size para que el input no herede el ~16px por defecto del
       navegador y quede dos tallas por encima de la etiqueta "Min/Max" (12px),
       que resultaba muy desproporcionado. Variables CSS para permitir override
       desde admin (Tab Visual → Sidebar) en el futuro. */
    font-size: var(--p3dv-sb-input-fs, 13px);
    font-family: inherit;
    line-height: 1.3;
    box-sizing: border-box;
}

/* ============ Canvas wrapper ============ */

.p3dv-canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--p3dv-bg);
}

.p3dv-canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    touch-action: none;
}

.p3dv-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.75);
    color: var(--p3dv-fg);
    font-size: 14px;
    z-index: 5;
}

/* ============ Spinner de cálculo solar (Iter 31.2 / 31.6) ============
   Overlay translúcido y MINIMALISTA — horizontal compacto estilo notificación.
   Sol pequeño + anillo de rayos girando + texto al lado. */
.p3dv-sun-spinner {
    display: none;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 14px 10px 12px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    pointer-events: none;
    background: rgba(20, 20, 30, 0.88);
    color: #fff;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    font-size: 12.5px;
    font-weight: 500;
    letter-spacing: 0.01em;
    line-height: 1;
    white-space: nowrap;
}
.p3dv-sun-spinner.is-visible {
    display: flex;
}
/* Disco — pequeño "sol" central con anillo punteado de rayos girando.
   Reemplaza el gran círculo con halo del diseño anterior. */
.p3dv-sun-spinner-disk {
    width: 20px;
    height: 20px;
    position: relative;
    flex-shrink: 0;
}
.p3dv-sun-spinner-disk::before {
    content: '';
    position: absolute;
    inset: 5px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fde047 0%, #f59e0b 70%, #d97706 100%);
    box-shadow: 0 0 5px rgba(253, 224, 71, 0.55);
}
.p3dv-sun-spinner-disk::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1.5px dashed rgba(253, 224, 71, 0.7);
    animation: p3dv-sun-rays 1.4s linear infinite;
}
.p3dv-sun-spinner-text {
    color: #fff;
}
@keyframes p3dv-sun-rays {
    to { transform: rotate(360deg); }
}
.p3dv-theme-dark .p3dv-sun-spinner {
    background: rgba(40, 40, 56, 0.92);
}

.p3dv-theme-dark .p3dv-loading {
    background: rgba(26, 26, 46, 0.85);
}

.p3dv-loading.is-error {
    color: #b91c1c;
    font-weight: 600;
}

.p3dv-controls-hint {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.55);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    pointer-events: none;
    z-index: 6;
    white-space: nowrap;
}

.p3dv-controls-hint .mobile-hint { display: none; }

.p3dv-reset-camera {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--p3dv-border);
    background: rgba(255, 255, 255, 0.92);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    color: #111;
    z-index: 7;
    transition: transform 0.2s;
}

.p3dv-theme-dark .p3dv-reset-camera {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.p3dv-reset-camera:hover { transform: rotate(-90deg); }

/* ============ Fullscreen button ============ */

.p3dv-fullscreen {
    position: absolute;
    top: 10px;
    right: 56px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--p3dv-border);
    background: rgba(255, 255, 255, 0.92);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    color: #111;
    z-index: 7;
    transition: transform 0.15s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.p3dv-theme-dark .p3dv-fullscreen {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}
.p3dv-fullscreen:hover { transform: scale(1.08); }
.p3dv-fullscreen .p3dv-fs-icon-exit { display: none; }
.p3dv-fullscreen.is-fullscreen .p3dv-fs-icon-enter { display: none; }
.p3dv-fullscreen.is-fullscreen .p3dv-fs-icon-exit  { display: inline; }

/* ============ Toggle labels button (Iter 30.1) ============
   Mismo look que .p3dv-fullscreen pero más a la izquierda (right:102px).
   Visible solo cuando displayConfig.show_labels=true — JS le quita el
   display:none inline al inicializar el viewer. */
.p3dv-toggle-labels {
    position: absolute;
    top: 10px;
    right: 102px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--p3dv-border);
    background: rgba(255, 255, 255, 0.92);
    cursor: pointer;
    color: #111;
    z-index: 7;
    transition: transform 0.15s, background 0.2s, opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.p3dv-theme-dark .p3dv-toggle-labels {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}
.p3dv-toggle-labels:hover { transform: scale(1.08); }
.p3dv-toggle-labels.is-inactive { opacity: 0.55; }
.p3dv-toggle-labels.is-inactive:hover { opacity: 0.85; }

/* Cuando el wrapper está en fullscreen, garantizamos que ocupe TODA la
   pantalla sin que un height fijo del shortcode lo limite. */
.p3dv:fullscreen,
.p3dv:-webkit-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    background: var(--p3dv-bg);
}
.p3dv:fullscreen .p3dv-canvas-wrapper,
.p3dv:-webkit-full-screen .p3dv-canvas-wrapper {
    height: 100vh !important;
}

/* ============ Compass (rosa de los vientos) ============ */

.p3dv-compass {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    z-index: 7;
    pointer-events: none;
}

.p3dv-theme-dark .p3dv-compass {
    background: rgba(0, 0, 0, 0.6);
}

.p3dv-compass svg {
    width: 100%;
    height: 100%;
    display: block;
}

.p3dv-compass-ring {
    fill: none;
    stroke: rgba(0, 0, 0, 0.15);
    stroke-width: 1;
}

.p3dv-theme-dark .p3dv-compass-ring {
    stroke: rgba(255, 255, 255, 0.2);
}

.p3dv-compass-rose {
    /* La rotación se aplica mediante SVG `transform` attribute desde JS,
       con centro explícito (0,0) (viewBox centrado). */
    transform-origin: 0 0;
}

.p3dv-compass-n {
    fill: #dc2626;
}

.p3dv-compass-s {
    fill: #9ca3af;
}

.p3dv-compass-label {
    font-size: 8px;
    font-weight: 800;
    fill: #fff;
    font-family: system-ui, sans-serif;
    paint-order: stroke fill;
    stroke: #dc2626;
    stroke-width: 0.6;
}

/* ============ Pan HUD ============ */

.p3dv-pan-hud {
    position: absolute;
    bottom: 14px;
    right: 14px;
    display: grid;
    grid-template-columns: 32px 32px 32px;
    grid-template-rows: 32px 32px 32px;
    gap: 2px;
    z-index: 7;
}

/* CSS defensiva: usamos !important en propiedades CRÍTICAS (background,
   color, cursor, pointer-events, display) para resistir temas de producción
   con reglas globales sobre `button` (p. ej. background: blue de "block
   editor" themes que dejaba TODOS los botones en azul y aparentemente
   bloqueados). Sin !important, esa cascada externa anulaba nuestros
   estilos de hover/normal y el botón aparecía permanentemente con la
   variante "hover" azul → daba sensación de estar deshabilitado. */
.p3dv .p3dv-pan-btn,
.p3dv-pan-btn {
    width: 32px !important;
    height: 32px !important;
    line-height: 1 !important;
    font-size: 12px !important;
    background: rgba(255, 255, 255, 0.92) !important;
    border: 1px solid var(--p3dv-border, #e5e7eb) !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    color: #111 !important;
    padding: 0 !important;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: none !important;
    text-shadow: none !important;
    text-transform: none !important;
    font-family: inherit !important;
    font-weight: normal !important;
    min-width: 0 !important;
    min-height: 0 !important;
}

.p3dv-theme-dark .p3dv-pan-btn {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #fff !important;
}

.p3dv .p3dv-pan-btn:hover,
.p3dv-pan-btn:hover {
    background: var(--p3dv-accent, #2271b1) !important;
    color: #fff !important;
}
.p3dv .p3dv-pan-btn:active,
.p3dv-pan-btn:active { transform: scale(0.92); }

.p3dv-pan-up    { grid-column: 2; grid-row: 1; }
.p3dv-pan-left  { grid-column: 1; grid-row: 2; }
.p3dv-pan-right { grid-column: 3; grid-row: 2; }
.p3dv-pan-down  { grid-column: 2; grid-row: 3; }

/* ============ Tooltip ============ */

.p3dv-tooltip {
    position: absolute;
    background: rgba(17, 24, 39, 0.95);
    color: #fff;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 8;
    opacity: 0;
    transform: translateY(2px);
    transition: opacity 0.15s, transform 0.15s;
    max-width: 220px;
    line-height: 1.35;
}

.p3dv-tooltip.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.p3dv-tooltip-line {
    margin-top: 2px;
    color: #d1d5db;
}

/* ============ Block label (CSS2D) ============ */

.p3dv-block-label {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    padding: 2px 7px;
    border-radius: 3px;
    pointer-events: none;
    transition: opacity 0.15s ease;
    user-select: none;
    text-align: center;
    line-height: 1.15;
    max-width: 160px;
    opacity: 1;
}

/* Etiqueta detrás de otro bloque: muy tenue para no estorbar. */
.p3dv-block-label.is-occluded {
    opacity: 0.18;
}

/* Etiqueta filtrada o de un no-seleccionado cuando hay selección activa. */
.p3dv-block-label.is-hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
}

/* Iter 40.1 — Si el wrapper marca no-labels (device show_labels=false),
   ocultamos TODAS las etiquetas como red de seguridad por si alguna escapa
   al toggle is-hidden. !important garantiza ganar a cualquier inline style
   o regla de tema. */
.p3dv-no-labels .p3dv-block-label {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.p3dv-block-label-title {
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.p3dv-block-label-sub {
    font-size: 10px;
    font-weight: 500;
    opacity: 0.85;
    white-space: nowrap;
    margin-top: 1px;
}

/* ============ Detail panel ============ */

.p3dv-detail-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 100%;
    background: var(--p3dv-bg);
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    padding: 1.25rem;
    z-index: 12;
    color: var(--p3dv-fg);
    -webkit-overflow-scrolling: touch;
}

.p3dv-theme-dark .p3dv-detail-panel {
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.4);
}

.p3dv-detail-panel.is-open { transform: translateX(0); }

.p3dv-close-panel {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    color: var(--p3dv-muted);
}

.p3dv-detail-head {
    padding-right: 32px;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--p3dv-border);
    padding-bottom: 0.75rem;
}
.p3dv-detail-title {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.01em;
}
.p3dv-detail-subtitle {
    margin: 0 0 4px;
    font-size: 14px;
    color: var(--p3dv-muted);
}
.p3dv-detail-ref {
    margin: 0;
    font-size: 12px;
    color: var(--p3dv-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.p3dv-detail-grid {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.p3dv-detail-row {
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: 10px;
    align-items: center;
    padding: 10px 4px;
    border-radius: 6px;
    font-size: 14px;
    transition: background .15s;
}
.p3dv-detail-row:hover { background: rgba(34,113,177,0.04); }
.p3dv-detail-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    color: var(--p3dv-accent);
    background: rgba(34,113,177,0.08);
    border-radius: 6px;
}
.p3dv-detail-icon-empty { background: transparent; }
.p3dv-detail-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.p3dv-detail-key {
    font-size: 11px;
    color: var(--p3dv-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 500;
}
.p3dv-detail-value {
    font-weight: 600;
    color: var(--p3dv-fg);
    word-break: break-word;
    line-height: 1.3;
}

.p3dv-pdf-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 1rem;
    padding: 10px 14px;
    background: var(--p3dv-accent);
    color: #fff !important;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    font-size: 14px;
}

/* ============ Panel de resumen (tras los filtros, en flujo normal) ============ */
.p3dv-summary-panel {
    /* padding / margin / border / radius se aplican inline desde JS según la
       configuración admin (todo editable). Aquí solo defaults de tipografía y
       el sistema de colores via custom properties. */
    background: var(--vs-bg, #ffffff);
    color: var(--vs-text, #0f172a);
    font-size: 13px;
    line-height: 1.4;
}
.p3dv-summary-h {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 8px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--vs-accent, #2271b1);
}
.p3dv-summary-h .p3dv-vs-ic { color: var(--vs-accent, #2271b1); }

.p3dv-summary-total {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.p3dv-summary-total .p3dv-vs-ic { color: var(--vs-accent, #2271b1); }
.p3dv-summary-count {
    font-size: 28px;
    font-weight: 800;
    color: var(--vs-accent, #2271b1);
    line-height: 1;
}
.p3dv-summary-count-label {
    color: var(--vs-text, #0f172a);
    font-weight: 500;
}

.p3dv-summary-priceall {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px 6px;
    margin-bottom: 10px;
    font-size: 13px;
}
.p3dv-summary-priceall .p3dv-vs-ic { color: var(--vs-accent, #2271b1); margin-right: 2px; }
.p3dv-summary-priceall-l { color: var(--p3dv-muted); }
.p3dv-summary-priceall strong { color: var(--vs-text, #0f172a); }

.p3dv-summary-bdr {
    list-style: none;
    padding: 0;
    margin: 8px 0 0;
    border-top: 1px solid var(--vs-border, #e5e7eb);
}
.p3dv-summary-bdr-row {
    display: grid;
    grid-template-columns: 20px auto 1fr;
    gap: 6px 10px;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px dashed var(--vs-border, #e5e7eb);
    font-size: 12.5px;
}
.p3dv-summary-bdr-row:last-child { border-bottom: none; }
.p3dv-summary-bdr-icon { color: var(--vs-accent, #2271b1); display: flex; align-items: center; }
.p3dv-summary-bdr-label { font-weight: 600; }
.p3dv-summary-bdr-count {
    color: var(--vs-accent, #2271b1);
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
}
.p3dv-summary-bdr-price {
    grid-column: 2 / 4;
    font-size: 12px;
    color: var(--p3dv-muted, #6b7280);
}

/* Enlaces clicables en celdas (URL/email/phone) */
.p3dv-cell-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--p3dv-accent) !important;
    text-decoration: none;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(37, 99, 235, 0.08);
    font-weight: 600;
    transition: background 0.12s;
}
.p3dv-cell-link:hover {
    background: rgba(37, 99, 235, 0.18);
    text-decoration: none;
}
.p3dv-link-icon { font-size: 13px; }
.p3dv-link-text { font-size: 13px; }

.p3dv-pdf-btn:hover { filter: brightness(0.93); }

/* ============ Toggle filters button (mobile) ============ */

.p3dv-toggle-filters {
    display: none;
    align-items: center;
    gap: 6px;
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 15;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--p3dv-border);
    border-radius: 20px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--p3dv-fg);
}

.p3dv-theme-dark .p3dv-toggle-filters {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* ============ Error block ============ */

.p3dv-error {
    background: #fee2e2;
    color: #7f1d1d;
    padding: 1rem;
    border: 1px solid #fecaca;
    border-radius: 4px;
}

/* ===================== Responsive ===================== */

/* Tablet */
@media (min-width: 641px) and (max-width: 1024px) {
    .p3dv-wrapper {
        grid-template-columns: 220px 1fr;
    }
    .p3dv-detail-panel { width: 260px; }
}

/* Mobile */
@media (max-width: 640px) {
    .p3dv-wrapper {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;
        /* Iter 35.2 — Defensa contra parents que colapsan la altura
           (flex sin altura, grids con auto-rows, etc.). Antes ocurría que
           en móvil el wrapper se quedaba ~150-200px porque el host page
           ponía el shortcode en un contenedor flex/grid sin altura
           explícita y la regla `height: var(...)` cedía. Forzamos un
           mínimo razonable para que los botones no se superpongan. */
        height: var(--p3dv-height, 500px);
        min-height: 420px;
    }

    .p3dv-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 85%;
        max-width: 300px;
        transform: translateX(-105%);
        transition: transform 0.3s ease;
        border-right: none;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.18);
        z-index: 20;
    }

    .p3dv-sidebar.is-open { transform: translateX(0); }

    .p3dv-toggle-filters { display: inline-flex; }

    .p3dv-close-sidebar { display: inline-block; }

    .p3dv-detail-panel { width: 100%; }

    .p3dv-controls-hint .desktop-hint { display: none; }
    .p3dv-controls-hint .mobile-hint  { display: inline; }

    .p3dv-reset-camera {
        top: 10px;
        right: 10px;
        bottom: auto;
    }

    .p3dv-pan-hud {
        bottom: 50px;
        right: 8px;
        grid-template-columns: 36px 36px 36px;
        grid-template-rows: 36px 36px 36px;
    }
    .p3dv-pan-btn { width: 36px; height: 36px; font-size: 13px; }
}

/* ============================================================
   Iter 37.2 — Landscape de móvil + tablet con poca altura.
   Cuando la altura del viewport es chica (<=500px) y el ancho
   está entre móvil y tablet (<=1024px) — caso típico de phone
   en horizontal o tablet mini — aplicamos los mismos estilos
   que en móvil portrait: sidebar como drawer plegable, botón
   "Filtros" visible y panel solar replegado por defecto. Sin
   esto el sidebar quedaba fijo en 220px (regla de tablet) y
   tapaba el canvas además de impedir plegado.
   ============================================================ */
@media (max-height: 500px) and (max-width: 1024px) {
    .p3dv-wrapper {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;
    }
    .p3dv-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 85%;
        max-width: 300px;
        transform: translateX(-105%);
        transition: transform 0.3s ease;
        border-right: none;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.18);
        z-index: 20;
    }
    .p3dv-sidebar.is-open { transform: translateX(0); }
    .p3dv-toggle-filters { display: inline-flex; }
    .p3dv-close-sidebar { display: inline-block; }
    .p3dv-detail-panel { width: 100%; }
    /* En altura muy baja, el panel solar acerca su posición al borde inferior
       y reduce min-width para que su cuerpo (cuando el usuario lo expanda)
       no tape el canvas completo. Si tiene la clase is-collapsed (default por
       JS en landscape), solo se ve el icono ☀, sin ocupar nada del centro. */
    .p3dv-sun-panel { bottom: 6px; left: 6px; }
    .p3dv-sun-body  { min-width: 200px; max-height: calc(100vh - 60px); overflow:auto; }
}


/* ============================================================
   Sun module — Panel flotante de controles solar
   Esquina inferior-izquierda del canvas. Coherente visualmente
   con .p3dv-compass / .p3dv-reset-camera.
   ============================================================ */

.p3dv-sun-panel {
    position: absolute;
    bottom: 10px;
    left: 10px;
    z-index: 12;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--p3dv-border, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    font-size: 13px;
    color: var(--p3dv-fg, #0f172a);
    backdrop-filter: blur(6px);
    transition: max-width 0.2s, max-height 0.2s;
    overflow: hidden;
    user-select: none;
}

.p3dv-theme-dark .p3dv-sun-panel {
    background: rgba(20, 24, 40, 0.92);
    border-color: #2a2f48;
    color: #e2e8f0;
}

.p3dv-sun-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: linear-gradient(135deg, #fbbf24, #f97316);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    border-radius: 6px;
    margin: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
.p3dv-sun-toggle:hover { filter: brightness(1.1); }

.p3dv-sun-body {
    padding: 6px 12px 10px;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.p3dv-sun-panel.is-collapsed .p3dv-sun-body {
    display: none;
}

.p3dv-sun-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.p3dv-sun-row label {
    font-size: 11px;
    color: var(--p3dv-muted, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.p3dv-sun-val {
    font-size: 12px;
    color: var(--p3dv-fg, #0f172a);
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
}
.p3dv-theme-dark .p3dv-sun-val { color: #e2e8f0; }

.p3dv-sun-row input[type="range"] {
    width: 100%;
    accent-color: #f97316;
    cursor: pointer;
}

.p3dv-sun-row-info {
    margin-top: 2px;
}
.p3dv-sun-info {
    font-size: 11px;
    color: var(--p3dv-muted, #6b7280);
    font-style: italic;
}

.p3dv-sun-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}
.p3dv-sun-btn {
    flex: 1 1 auto;
    min-width: 60px;
    padding: 5px 8px;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid var(--p3dv-border, #e5e7eb);
    border-radius: 5px;
    color: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s;
}
.p3dv-sun-btn:hover {
    background: rgba(249, 115, 22, 0.12);
    border-color: #f97316;
}
.p3dv-sun-btn.is-active {
    background: #f97316;
    color: #fff;
    border-color: #ea580c;
}
.p3dv-theme-dark .p3dv-sun-btn { background: rgba(255,255,255,0.06); }

/* Iter 33.6 — Leyenda gradiente cálido↔frío del modo insolación.
   Visible solo cuando el coloreado por insolación está activo. Refleja la
   LUT actualmente en uso (HSL clásica o termográfica pastel). */
.p3dv-sun-row-legend {
    margin-top: 2px;
}
.p3dv-sun-legend {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}
.p3dv-sun-legend-label {
    font-size: 10px;
    color: var(--p3dv-muted, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    flex: 0 0 auto;
}
.p3dv-sun-legend-bar {
    flex: 1 1 auto;
    height: 10px;
    border-radius: 6px;
    border: 1px solid var(--p3dv-border, #e5e7eb);
    background: linear-gradient(to right, #4d4d9e, #fff2c7);
    box-shadow: inset 0 1px 1px rgba(0,0,0,0.08);
    min-width: 80px;
}
.p3dv-theme-dark .p3dv-sun-legend-bar {
    border-color: #2a2f48;
}

/* En móvil reducimos el ancho mínimo del panel para no comerse el canvas. */
@media (max-width: 640px) {
    .p3dv-sun-panel { bottom: 8px; left: 8px; }
    .p3dv-sun-body { min-width: 210px; padding: 4px 10px 8px; }
}
