/* ==========================================================================
   Demos 3D de los productos: las tarjetas (_ProductDemos.cshtml) y el visor
   (js/demo-viewer.js). Usa los tokens de redesign.css.
   ========================================================================== */

/* ----- Tarjetas ---------------------------------------------------------- */
.ms-demos { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 1.6rem; margin-top: 2.2rem; }
.ms-demo-card { display: flex; flex-direction: column; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); overflow: hidden; }

.ms-demo-card__media {
    position: relative; display: block; width: 100%; padding: 0; border: 0; margin: 0;
    aspect-ratio: 16 / 10; background: #eef1f5; overflow: hidden; cursor: pointer;
}
.ms-demo-card__media:disabled { cursor: default; }
.ms-demo-card__media img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.4s ease; }
.ms-demo-card__media:not(:disabled):hover img { transform: scale(1.04); }
.ms-demo-card__media:focus-visible { outline: 3px solid var(--accent-from); outline-offset: -3px; }

.ms-demo-card__play {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    display: inline-flex; align-items: center; gap: 0.5rem;
    font-family: var(--font-head); font-weight: 600; font-size: 0.98rem;
    padding: 0.75rem 1.3rem; border-radius: 999px;
    background: var(--brand-gradient); color: #04121a;
    box-shadow: 0 12px 30px -10px rgba(4, 18, 26, 0.7);
    transition: transform 0.2s ease;
}
.ms-demo-card__media:disabled .ms-demo-card__play { display: none; }
.ms-demo-card__media:not(:disabled):hover .ms-demo-card__play { transform: translate(-50%, -50%) scale(1.05); }

.ms-demo-card__body { padding: 1.3rem 1.5rem 1.5rem; }
.ms-demo-card__title { font-size: 1.25rem; margin: 0 0 0.5rem; }
.ms-demo-card__text { font-size: 0.95rem; color: var(--text-muted); margin: 0; }
.ms-demos__fallback { margin: 1.4rem 0 0; text-align: center; color: var(--text-muted); }

/* ----- Visor ------------------------------------------------------------- */
html.dv-open { overflow: hidden; }

.dv {
    width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none;
    margin: 0; padding: 0; border: 0; inset: 0;
    background: var(--bg); color: var(--text);
}
.dv::backdrop { background: rgba(0, 0, 0, 0.7); }

.dv__shell { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }

.dv__head { display: flex; align-items: center; gap: 1rem; padding: 0.6rem 0.75rem 0.6rem 1.25rem; border-bottom: 1px solid var(--border); }
.dv__title { flex: 1; min-width: 0; margin: 0; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dv__icon-btn {
    display: inline-grid; place-items: center; width: 42px; height: 42px; flex: 0 0 auto;
    border-radius: 12px; border: 1px solid var(--border); background: rgba(255, 255, 255, 0.04);
    color: var(--text); font-size: 1.1rem; cursor: pointer; transition: border-color 0.2s ease, color 0.2s ease;
}
.dv__icon-btn:hover { border-color: var(--border-strong); color: #fff; }
.dv__icon-btn--play { background: var(--brand-gradient); color: #04121a; border-color: transparent; font-size: 1.35rem; }
.dv__icon-btn--play:hover { color: #04121a; }

.dv__main { display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: 0; }

.dv__stage { position: relative; min-width: 0; min-height: 0; background: #eef1f5; overflow: hidden; }
.dv__canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.dv__views { position: absolute; top: 0.75rem; left: 0.75rem; right: 0.75rem; display: flex; flex-wrap: wrap; gap: 0.4rem; pointer-events: none; }
.dv__chip {
    pointer-events: auto; display: inline-flex; align-items: center; gap: 0.4rem;
    font-family: var(--font-head); font-weight: 600; font-size: 0.8rem;
    padding: 0.4rem 0.75rem; border-radius: 999px; cursor: pointer;
    background: rgba(255, 255, 255, 0.92); color: #1d2433; border: 1px solid rgba(15, 18, 27, 0.14);
    box-shadow: 0 4px 14px -8px rgba(15, 18, 27, 0.5);
}
.dv__chip:hover { border-color: #0975EE; color: #0975EE; }
.dv__chip[aria-pressed="true"] { background: #1d2433; color: #fff; border-color: #1d2433; }
.dv__chip[aria-pressed="false"] { text-decoration: line-through; }
.dv__chip[hidden] { display: none; }

.dv .dv__hint { position: absolute; left: 0.75rem; bottom: 0.6rem; right: 0.75rem; margin: 0; font-size: 0.78rem; color: #5b6476; pointer-events: none; }

.dv .dv__status {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); margin: 0;
    max-width: min(90%, 30rem); padding: 0.8rem 1.2rem; border-radius: var(--radius-sm);
    background: rgba(15, 18, 27, 0.88); color: #fff; text-align: center; font-size: 0.95rem;
}
.dv__status[data-kind="event"] { top: auto; bottom: 2.4rem; transform: translateX(-50%); }
.dv__status[data-kind="error"] { background: rgba(120, 20, 40, 0.92); }
.dv__status[hidden] { display: none; }

.dv__end {
    position: absolute; inset: auto 0.75rem 2.4rem; margin-inline: auto; max-width: 30rem;
    padding: 1.2rem 1.4rem; border-radius: var(--radius); text-align: center;
    background: rgba(15, 18, 27, 0.92); border: 1px solid var(--border-strong);
}
.dv__end[hidden] { display: none; }
.dv .dv__end-title { margin: 0 0 0.9rem; color: #fff; font-family: var(--font-head); font-weight: 600; font-size: 1.1rem; }
.dv__end-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.6rem; }

/* Panel: los mecanizados arriba y el G-code abajo; en el celular, con pestañas. */
.dv__side { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); background: var(--bg-soft); }
.dv__tabs { display: none; }
.dv__pane { display: flex; flex-direction: column; min-height: 0; }
.dv__pane--blocks { flex: 0 0 auto; max-height: 40%; border-bottom: 1px solid var(--border); }
.dv__pane--gcode { flex: 1 1 0; }
.dv .dv__pane-title { margin: 0; padding: 0.8rem 1rem 0.5rem; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); }
.dv__scroll { position: relative; overflow-y: auto; min-height: 0; flex: 1 1 auto; overscroll-behavior: contain; }

.dv__blocks { list-style: none; margin: 0; padding: 0 0.5rem 0.6rem; }
.dv-block {
    display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; width: 100%;
    padding: 0.5rem 0.65rem; border: 1px solid transparent; border-radius: 10px;
    background: none; color: var(--text); text-align: left; cursor: pointer;
}
.dv-block:hover { background: rgba(255, 255, 255, 0.04); }
.dv-block__name { font-size: 0.92rem; font-weight: 600; }
.dv-block__meta { font-size: 0.8rem; color: var(--text-dim); }
.dv__blocks .is-current .dv-block { background: rgba(9, 238, 169, 0.1); border-color: rgba(9, 238, 169, 0.4); }

.dv__gcode {
    list-style: none; margin: 0; padding: 0 0 0.8rem;
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 0.8rem; line-height: 1.55;
    color: var(--text-dim);
}
.dv-line { padding: 0 1rem; white-space: pre; }
.dv-line.is-motion { color: var(--text-muted); cursor: pointer; }
.dv-line.is-motion:hover { color: #fff; background: rgba(255, 255, 255, 0.04); }
.dv-line.is-current { color: #04121a; background: var(--accent-from); }

.dv__side-cta { margin: 0.8rem 1rem 1rem; justify-content: center; }

/* Controles */
.dv__controls { display: flex; align-items: center; gap: 0.6rem 0.8rem; padding: 0.7rem 1rem; border-top: 1px solid var(--border); background: var(--surface); }
.dv__clock { font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }

.dv__timeline { flex: 1 1 auto; min-width: 8rem; padding: 0.7rem 0; cursor: pointer; touch-action: none; }
.dv__timeline:focus-visible { outline: 2px solid var(--accent-from); outline-offset: 2px; border-radius: 6px; }
.dv__track { position: relative; height: 12px; border-radius: 6px; background: rgba(255, 255, 255, 0.06); overflow: visible; }
.dv-timeline__block { position: absolute; top: 0; bottom: 0; background: rgba(9, 117, 238, 0.45); border-right: 1px solid var(--surface); }
.dv-timeline__block.is-odd { background: rgba(9, 117, 238, 0.28); }
.dv__progress { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 6px 0 0 6px; background: rgba(9, 238, 169, 0.45); pointer-events: none; }
.dv__playhead { position: absolute; top: -4px; bottom: -4px; width: 4px; margin-left: -2px; border-radius: 2px; background: #fff; box-shadow: 0 0 0 2px rgba(5, 6, 10, 0.6); pointer-events: none; }

.dv__speeds { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.dv__speed { padding: 0.35rem 0.7rem; border: 0; background: none; color: var(--text-muted); font-family: var(--font-head); font-weight: 600; font-size: 0.8rem; cursor: pointer; }
.dv__speed[aria-pressed="true"] { background: var(--brand-gradient); color: #04121a; }

/* Hasta que carga, el panel y los controles no se usan. */
.dv__shell:not(.is-ready) .dv__views,
.dv__shell:not(.is-ready) .dv__hint,
.dv__shell:not(.is-ready) .dv__side,
.dv__shell:not(.is-ready) .dv__controls { visibility: hidden; }

/* ----- Celular ----------------------------------------------------------- */
@media (max-width: 860px) {
    .dv__main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 58fr) minmax(0, 42fr); }
    .dv__side { border-left: 0; border-top: 1px solid var(--border); }

    .dv__tabs { display: flex; border-bottom: 1px solid var(--border); }
    .dv__tab { flex: 1; padding: 0.6rem; border: 0; background: none; color: var(--text-muted); font-family: var(--font-head); font-weight: 600; font-size: 0.88rem; cursor: pointer; border-bottom: 2px solid transparent; }
    .dv__tab[aria-selected="true"] { color: #fff; border-bottom-color: var(--accent-from); }
    .dv .dv__pane-title { display: none; }
    .dv__pane--blocks { max-height: none; border-bottom: 0; }
    .dv__side[data-tab="blocks"] .dv__pane--gcode,
    .dv__side[data-tab="gcode"] .dv__pane--blocks { display: none; }
    .dv__pane { flex: 1 1 auto; padding-top: 0.4rem; }
    .dv__side-cta { margin: 0.5rem 1rem 0.7rem; padding: 0.6rem 1rem; }

    .dv__controls { flex-wrap: wrap; padding: 0.5rem 0.75rem; }
    .dv__timeline { order: -1; flex-basis: 100%; padding: 0.45rem 0; }
    .dv__speeds { margin-left: auto; }
    .dv__hint { display: none; }
    .dv__chip { font-size: 0.75rem; padding: 0.35rem 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
    .ms-demo-card__media img, .ms-demo-card__play { transition: none; }
}
