/* =============================================
   ZONAVAG — DESPIECE INTERACTIVO (estilo manual de taller)
   Mobile first. Tokens propios del componente.
   ============================================= */

.despiece, .dp-mini {
    --dp-paper: #fafaf7;
    --dp-paper-2: #f1f0ea;
    --dp-grid: #ecebe4;
    --dp-ink: #111111;
    --dp-muted: #5d5c56;
    --dp-rule: #d8d6cd;
    --dp-accent: #1d4ed8;
    --dp-accent-soft: #dfe7fb;
    --dp-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
    --dp-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

.despiece { font-family: var(--dp-sans); color: var(--dp-ink); }
.despiece .motor-section-title { font-family: var(--dp-sans); font-weight: 600; }
.dp-intro { font-size: 15px; line-height: 1.6; color: var(--dp-muted); max-width: 680px; margin: -4px 0 14px; }

/* ---------- Dibujo ---------- */
.dp-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.dp-figure { min-width: 0; background: var(--dp-paper); border: 1px solid var(--dp-ink); border-radius: 4px; overflow: hidden; }
.dp-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--dp-ink); }
.dp-toolbar__name { min-width: 0; font-family: var(--dp-mono); font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dp-toolbar__actions { display: flex; gap: 4px; flex-shrink: 0; }
.dp-btn, .dp-icon {
    display: inline-flex; align-items: center; justify-content: center; min-height: 40px;
    font-family: var(--dp-sans); font-size: 14px; font-weight: 600; color: var(--dp-ink);
    background: var(--dp-paper); border: 1px solid var(--dp-ink); border-radius: 4px; cursor: pointer;
}
.dp-btn { padding: 0 12px; }
.dp-icon { width: 40px; font-family: var(--dp-mono); font-size: 18px; }
.dp-btn:hover, .dp-icon:hover { color: var(--dp-accent); border-color: var(--dp-accent); }
.dp-btn:focus-visible, .dp-icon:focus-visible, .dp-item:focus-visible, .dp-close:focus-visible { outline: 2px solid var(--dp-accent); outline-offset: 2px; }
.dp-btn--primary { color: #fff; background: var(--dp-accent); border-color: var(--dp-accent); text-decoration: none; }
.dp-btn--primary:hover { color: #fff; background: #1e40af; border-color: #1e40af; }

.dp-stage {
    position: relative; aspect-ratio: 440 / 340; overflow: hidden; touch-action: pan-y;
    background-color: var(--dp-paper);
    background-image: linear-gradient(var(--dp-grid) 1px, transparent 1px), linear-gradient(90deg, var(--dp-grid) 1px, transparent 1px);
    background-size: 20px 20px;
    user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.dp-stage.is-zoomed { touch-action: none; cursor: grab; }
.dp-canvas { width: 100%; height: 100%; transform-origin: 0 0; will-change: transform; }
.dp-svg { display: block; width: 100%; height: 100%; }
.dp-note { padding: 8px 12px; font-size: 12px; color: var(--dp-muted); border-top: 1px solid var(--dp-rule); }

/* Trazos */
.dp-line { fill: none; stroke: var(--dp-ink); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; transition: stroke 0.15s ease, fill 0.15s ease; }
.dp-paper { fill: var(--dp-paper); }
.dp-soft { fill: var(--dp-paper-2); }
.dp-thin { stroke-width: 1; }
.dp-pipe { stroke-width: 3; }
.dp-belt { stroke-width: 2.5; stroke-dasharray: 5 2.5; }
.dp-hp { stroke-width: 2; }
.dp-fuel { stroke-dasharray: 4 3; }
.dp-under { fill: none; stroke: var(--dp-paper); stroke-width: 7; vector-effect: non-scaling-stroke; }
.dp-leader { fill: none; stroke: var(--dp-ink); stroke-width: 0.75; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; }
.dp-badge { fill: var(--dp-paper); stroke: var(--dp-ink); stroke-width: 1.25; vector-effect: non-scaling-stroke; transition: fill 0.15s ease, stroke 0.15s ease; }
.dp-num { font-family: var(--dp-mono); font-size: 11px; font-weight: 600; text-anchor: middle; fill: var(--dp-ink); pointer-events: none; }
.dp-hit { fill: transparent; stroke: none; pointer-events: all; }
.dp-base { transition: opacity 0.15s ease; }

/* Interacción */
.dp-part { cursor: pointer; outline: none; }
.dp-part:hover .dp-badge, .dp-part:focus-visible .dp-badge { stroke: var(--dp-accent); stroke-width: 2.5; }
.dp-part.is-active .dp-line, .dp-part.is-active .dp-leader { stroke: var(--dp-accent); }
.dp-part.is-active .dp-paper, .dp-part.is-active .dp-soft { fill: var(--dp-accent-soft); }
.dp-part.is-active .dp-badge { fill: var(--dp-accent); stroke: var(--dp-accent); }
.dp-part.is-active .dp-num { fill: #fff; }
.has-selection .dp-base, .has-selection .dp-part:not(.is-active) .dp-line { opacity: 0.45; }

/* ---------- Lista numerada ---------- */
.dp-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin: 14px 0 0; padding: 0; list-style: none; }
@media (min-width: 600px) { .dp-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .dp-list { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.dp-item {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 6px 10px;
    font-family: var(--dp-sans); font-size: 15px; text-align: left; color: var(--dp-ink);
    background: var(--dp-paper); border: 1px solid var(--dp-rule); border-radius: 4px; cursor: pointer;
}
.dp-item:hover { border-color: var(--dp-ink); }
.dp-item[aria-pressed="true"] { border-color: var(--dp-accent); background: var(--dp-accent-soft); }
.dp-item__num { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; font-family: var(--dp-mono); font-size: 12px; font-weight: 600; border: 1.25px solid var(--dp-ink); border-radius: 50%; }
.dp-item[aria-pressed="true"] .dp-item__num { color: #fff; background: var(--dp-accent); border-color: var(--dp-accent); }
.dp-item__name { flex: 1; min-width: 0; }
.dp-item__flag { flex-shrink: 0; font-family: var(--dp-mono); font-size: 10px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--dp-accent); }

/* ---------- Panel: hoja inferior en móvil ---------- */
.dp-panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 300;
    max-height: min(72vh, 560px); overflow-y: auto; overscroll-behavior: contain;
    padding: 4px max(16px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    font-family: var(--dp-sans); color: var(--dp-ink); background: var(--dp-paper);
    border-top: 1px solid var(--dp-ink); border-radius: 14px 14px 0 0;
    transform: translateY(105%); visibility: hidden; transition: transform 0.22s ease, visibility 0s linear 0.22s;
}
.dp-panel.is-open { transform: none; visibility: visible; transition: transform 0.22s ease; }
.dp-panel__head { position: sticky; top: 0; display: flex; justify-content: center; align-items: center; height: 36px; margin: 0 -4px; background: var(--dp-paper); }
.dp-panel__grip { width: 40px; height: 4px; border-radius: 2px; background: var(--dp-rule); }
.dp-close { position: absolute; right: 0; top: 0; width: 44px; height: 40px; font-size: 18px; color: var(--dp-muted); background: none; border: 0; cursor: pointer; }
.dp-close:hover { color: var(--dp-ink); }
.dp-panel__empty { font-size: 15px; line-height: 1.6; color: var(--dp-muted); }

.dp-info__num { font-family: var(--dp-mono); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dp-accent); }
.dp-info__title { font-family: var(--dp-sans); font-size: 21px; font-weight: 600; line-height: 1.25; margin: 2px 0 10px; outline: none; }
.dp-info__text { font-size: 15px; line-height: 1.65; }
.dp-info__sub { font-family: var(--dp-mono); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dp-muted); margin: 16px 0 6px; }
.dp-info__list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 15px; line-height: 1.5; }
.dp-fault { margin: 0 0 12px; padding: 10px 12px; font-size: 14px; line-height: 1.55; color: var(--dp-ink); background: var(--dp-accent-soft); border-left: 3px solid var(--dp-accent); border-radius: 2px; }
.dp-fault strong { color: var(--dp-accent); }
.dp-codes { display: flex; flex-wrap: wrap; gap: 6px; }
.dp-code { display: inline-flex; align-items: center; min-height: 36px; padding: 0 10px; font-family: var(--dp-mono); font-size: 14px; font-weight: 600; color: var(--dp-accent); background: var(--dp-paper); border: 1px solid var(--dp-accent); border-radius: 4px; text-decoration: none; }
.dp-code:hover { color: #fff; background: var(--dp-accent); }
.dp-buy { margin-top: 18px; }
.dp-buy .dp-btn { width: 100%; min-height: 46px; }
.dp-buy__note { margin-top: 6px; font-size: 11px; line-height: 1.5; color: var(--dp-muted); }

/* ---------- Escritorio: panel lateral ---------- */
@media (min-width: 1024px) {
    .dp-layout { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
    .dp-panel {
        position: sticky; top: calc(var(--header-h, 64px) + 16px); z-index: 1;
        max-height: calc(100vh - var(--header-h, 64px) - 32px);
        padding: 4px 18px 18px; border: 1px solid var(--dp-ink); border-radius: 4px;
        transform: none; visibility: visible; transition: none;
    }
    .dp-panel__grip { display: none; }
    .dp-close { display: none; }
    .has-selection .dp-close { display: block; }
}

/* ---------- Ampliado a pantalla completa ---------- */
html.dp-lock { overflow: hidden; }
.despiece.is-expanded .dp-figure {
    position: fixed; inset: 0; z-index: 250; display: flex; flex-direction: column; border: 0; border-radius: 0;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.despiece.is-expanded .dp-stage { flex: 1; aspect-ratio: auto; }
@media (min-width: 1024px) {
    .despiece.is-expanded .dp-panel { position: fixed; top: 64px; right: 16px; width: 340px; z-index: 300; }
    .despiece.is-expanded .dp-figure { padding-right: 372px; }
}

/* ---------- Miniatura de la portada (lámina) ---------- */
.dp-mini {
    display: block; max-width: 440px; margin: 22px 0 0; font-family: var(--dp-sans); color: var(--dp-ink);
    background: var(--dp-paper); border: 1.5px solid var(--dp-ink); border-radius: 6px; overflow: hidden; text-decoration: none;
    box-shadow: 6px 6px 0 var(--dp-paper-2), 6px 6px 0 1.5px var(--dp-rule); transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.dp-mini:hover { color: var(--dp-ink); transform: translate(-2px, -2px); box-shadow: 8px 8px 0 var(--dp-accent-soft), 8px 8px 0 1.5px var(--dp-accent); }
.dp-mini:focus-visible { outline: 2px solid var(--dp-accent); outline-offset: 4px; }
.dp-mini__bar {
    display: flex; justify-content: space-between; gap: 12px; padding: 9px 14px; border-bottom: 1.5px solid var(--dp-ink);
    font-family: var(--dp-mono); font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase;
}
.dp-mini__bar span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dp-mini__bar span:last-child { flex: none; color: var(--dp-accent); }
.dp-mini__figure {
    display: block; padding: 6px 8px 2px;
    background-image: linear-gradient(var(--dp-grid) 1px, transparent 1px), linear-gradient(90deg, var(--dp-grid) 1px, transparent 1px);
    background-size: 16px 16px; background-position: -1px -1px;
}
.dp-mini .dp-svg { display: block; width: 100%; height: auto; pointer-events: none; }
.dp-mini .dp-part:not(.is-active) { opacity: 0.55; }
.dp-mini .dp-pulse .dp-badge { animation: dp-pulse 2.2s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes dp-pulse {
    0% { stroke-width: 1.25; stroke-opacity: 1; }
    40% { stroke-width: 9; stroke-opacity: 0.25; }
    100% { stroke-width: 1.25; stroke-opacity: 1; }
}
.dp-mini__callout { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 4px 12px; padding: 12px 14px; border-top: 1.5px solid var(--dp-ink); background: #fff; }
.dp-mini__n { display: grid; place-items: center; width: 30px; height: 30px; font-family: var(--dp-mono); font-size: 13px; font-weight: 600; color: #fff; background: var(--dp-accent); border-radius: 50%; }
.dp-mini__info { display: flex; flex-direction: column; min-width: 0; }
.dp-mini__info strong { font-size: 16px; font-weight: 600; }
.dp-mini__info span { font-family: var(--dp-mono); font-size: 12px; color: var(--dp-muted); }
.dp-mini__go { grid-column: 1 / -1; font-size: 14px; font-weight: 600; color: var(--dp-accent); }
@media (min-width: 480px) {
    .dp-mini__callout { grid-template-columns: auto minmax(0, 1fr) auto; }
    .dp-mini__go { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
    .dp-panel, .dp-line, .dp-badge, .dp-base, .dp-mini { transition: none !important; }
    .dp-mini .dp-pulse .dp-badge { animation: none; }
}
