/* ================================================================
   WHERE THE MONEY STOPS · DIAGRAMAS
   Cinco diagramas en HTML/CSS, sin imágenes rasterizadas.
   Prefijo: dg-  ·  Tokens de master.css y preventa.css.
   Esquinas rectas. Sin animaciones. El texto es texto real.
   Contraste medido con Playwright (ver capturas/diagramas/).
   ================================================================ */

:root {
    /* Rojo de "aquí se para": sobre negro, el token #E11D48 no pasa 4.5:1 */
    --dg-red-dark: #FB7185;
    --dg-red-light: #BE123C;
    --dg-line-dark: #3F3F46;
}

.dg-fig { margin: 0; }
.dg-cap {
    margin: 14px 0 0;
    font-size: 15px;
    line-height: 1.5;
    color: var(--mm-gray);
}
.dg-cap strong { color: var(--mm-white); font-weight: 600; }
.wms-paper .dg-cap { color: var(--mm-text-muted); }
.wms-paper .dg-cap strong { color: var(--mm-text-light); }

/* ================================================================
   1. OLD WAY contra NEW WAY (#how)
   El viejo baja 7 pasos y una flecha lo regresa al paso 1.
   El nuevo baja 4 pasos y termina en el resultado.
   ================================================================ */
.wms-way .dg-flow { list-style: none; margin: 0 0 24px; padding: 0; counter-reset: f; position: relative; }
.wms-way .dg-flow li {
    counter-increment: f;
    position: relative;
    margin: 0;
    padding: 10px 12px 10px 42px;
    border: 1px solid var(--mm-border);
    background: var(--mm-black-card);
    font-size: 16px;
    line-height: 1.4;
}
.wms-way .dg-flow li::before {
    content: counter(f, decimal-leading-zero);
    position: absolute;
    left: 12px;
    top: 12px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    font-weight: 500;
}
/* Conector con flecha entre pasos */
.wms-way .dg-flow li + li { margin-top: 20px; }
.wms-way .dg-flow li + li::after {
    content: "";
    position: absolute;
    left: 24px;
    top: -21px;
    width: 12px;
    height: 20px;
    background-repeat: no-repeat;
    background-position: center;
}

/* Viejo: gris, conectores punteados, flecha de regreso al paso 1 */
.wms-way.old .dg-flow { margin-right: 24px; }
.wms-way.old .dg-flow li { color: var(--mm-gray); }
.wms-way.old .dg-flow li::before { color: var(--dg-red-dark); }
.wms-way.old .dg-flow li + li::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='20' viewBox='0 0 12 20'%3E%3Cpath d='M6 0v14' stroke='%2385858E' stroke-width='1.5' stroke-dasharray='3 3'/%3E%3Cpath d='M1.5 13.5 6 19l4.5-5.5' fill='none' stroke='%2385858E' stroke-width='1.5'/%3E%3C/svg%3E");
}
.wms-way.old .dg-flow li:last-child { border-color: rgba(251, 113, 133, 0.45); }
/* La flecha que regresa: sale del paso 7 y entra al paso 1 por la derecha */
.wms-way.old .dg-flow::after {
    content: "";
    position: absolute;
    top: 21px;
    bottom: 22px;
    right: -22px;
    width: 22px;
    border: 1.5px dashed var(--dg-red-dark);
    border-left: none;
    pointer-events: none;
}
.wms-way.old .dg-flow::before {
    content: "";
    position: absolute;
    top: 16px;
    right: -8px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 8px solid var(--dg-red-dark);
    z-index: 1;
}
.wms-way.old .wms-way-result strong { color: var(--dg-red-dark); }

/* Nuevo: verde, conectores sólidos, termina en el resultado */
.wms-way.new .dg-flow { margin-bottom: 0; }
.wms-way.new .dg-flow li { color: var(--mm-light); border-color: rgba(16, 185, 129, 0.35); }
.wms-way.new .dg-flow li::before { color: var(--mm-green); }
.wms-way.new .dg-flow li + li::after,
.wms-way.new .dg-end::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='20' viewBox='0 0 12 20'%3E%3Cpath d='M6 0v18' stroke='%2310B981' stroke-width='1.5'/%3E%3Cpath d='M1.5 13.5 6 19l4.5-5.5' fill='none' stroke='%2310B981' stroke-width='1.5'/%3E%3C/svg%3E");
}
.wms-way.new .dg-end {
    position: relative;
    margin-top: 20px;
    padding: 12px 14px;
    border: 1px solid var(--mm-green);
    background: rgba(16, 185, 129, 0.08);
    color: var(--mm-white);
}
.wms-way.new .dg-end::after {
    content: "";
    position: absolute;
    left: 24px;
    top: -21px;
    width: 12px;
    height: 20px;
    background-repeat: no-repeat;
    background-position: center;
}
.wms-way.new .dg-end strong { color: var(--mm-green); }

/* ================================================================
   2. THE MONEY TRAIL (#what-is)
   8 etapas en un camino. Ancho: horizontal. Angosto: vertical.
   ================================================================ */
.dg-trail { margin: 8px 0 32px; container-type: inline-size; }
.dg-trail-box { border: 1px solid var(--mm-border); background: var(--mm-black-card); padding: 26px 18px 22px; }
.dg-trail-ends { display: flex; justify-content: space-between; margin: 0 0 14px; font-family: 'IBM Plex Mono', monospace; font-size: 13px; color: var(--mm-gray); }
.dg-trail-ends span:last-child { color: var(--mm-green); }
.dg-trail-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); }
.dg-trail-list li { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 2px; }
.dg-trail-list .dg-n { font-family: 'IBM Plex Mono', monospace; font-size: 13px; color: var(--mm-gray); height: 18px; }
.dg-trail-list .dg-dot { position: relative; z-index: 1; width: 14px; height: 14px; margin: 6px 0 10px; background: var(--mm-green); }
.dg-trail-list .dg-name { font-size: 15px; font-weight: 600; line-height: 1.25; color: var(--mm-white); }
/* La línea que une las etapas */
.dg-trail-list li::before,
.dg-trail-list li::after {
    content: "";
    position: absolute;
    top: 30px;
    height: 2px;
}
.dg-trail-list li::before { left: 0; right: 50%; background: var(--mm-green); }
.dg-trail-list li::after { left: 50%; right: 0; background: var(--mm-green); }
.dg-trail-list li:first-child::before { display: none; }
.dg-trail-list li:last-child::after { display: none; }
/* Después del punto donde se para: línea punteada y etapas apagadas */
.dg-trail-list li.is-stop::after,
.dg-trail-list li.is-after::before,
.dg-trail-list li.is-after::after {
    background: repeating-linear-gradient(90deg, var(--mm-darker) 0 5px, transparent 5px 9px);
}
.dg-trail-list li.is-after .dg-dot { background: var(--mm-black-card); border: 2px solid var(--mm-darker); }
.dg-trail-list li.is-after .dg-name { color: var(--mm-dim); font-weight: 500; }
.dg-trail-list li.is-after .dg-n { color: var(--mm-dim); }
.dg-trail-list li.is-stop .dg-dot {
    width: 22px;
    height: 22px;
    margin: 2px 0 6px;
    background: var(--dg-red-dark);
    display: flex;
    align-items: center;
    justify-content: center;
}
.dg-trail-list li.is-stop .dg-dot::before { content: "✕"; font-family: 'IBM Plex Mono', monospace; font-size: 13px; font-weight: 600; line-height: 1; color: var(--mm-black); }
.dg-trail-list li.is-stop .dg-n { color: var(--dg-red-dark); }
.dg-stop {
    display: block;
    margin-top: 8px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    line-height: 1.35;
    white-space: nowrap;
    color: var(--dg-red-dark);
}

@container (max-width: 560px) {
    .dg-trail-box { padding: 20px 16px 18px; }
    .dg-trail-ends { display: none; }
    .dg-trail-list { grid-template-columns: 1fr; }
    .dg-trail-list li {
        display: grid;
        grid-template-columns: 26px 30px minmax(0, 1fr);
        align-items: center;
        text-align: left;
        min-height: 40px;
        padding: 0;
    }
    .dg-trail-list .dg-dot { grid-column: 1; grid-row: 1; margin: 0 auto; }
    .dg-trail-list .dg-n { grid-column: 2; grid-row: 1; height: auto; }
    .dg-trail-list .dg-name { grid-column: 3; grid-row: 1; font-size: 16px; }
    .dg-trail-list li.is-stop .dg-dot { margin: 0 auto; }
    .dg-stop { grid-column: 3; grid-row: 2; margin: 2px 0 6px; font-size: 13px; white-space: normal; }
    /* Línea vertical */
    .dg-trail-list li::before,
    .dg-trail-list li::after {
        top: auto;
        left: 12px;
        right: auto;
        width: 2px;
        height: auto;
    }
    .dg-trail-list li::before { top: 0; bottom: 50%; }
    .dg-trail-list li::after { top: 50%; bottom: 0; }
    .dg-trail-list li.is-stop::before { bottom: auto; height: 20px; }
    .dg-trail-list li.is-stop::after { top: 20px; }
    .dg-trail-list li.is-stop::after,
    .dg-trail-list li.is-after::before,
    .dg-trail-list li.is-after::after {
        background: repeating-linear-gradient(180deg, var(--mm-darker) 0 5px, transparent 5px 9px);
    }
}

/* ================================================================
   3. LA FÓRMULA, con el ejemplo (#new-way, columna derecha)
   La brecha en barras y la multiplicación en vertical.
   ================================================================ */
.dg-calc { margin: 16px 0; }
.dg-gap { padding: 0 0 16px; }
.dg-gap-row { display: grid; grid-template-columns: 82px minmax(0, 1fr); align-items: center; gap: 10px; margin: 0 0 8px; }
.dg-gap-label { font-size: 14px; line-height: 1.3; color: var(--mm-text-medium); }
.dg-gap-track { position: relative; height: 26px; background: #F4F4F5; }
.dg-gap-fill { position: absolute; left: 0; top: 0; bottom: 0; display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; font-family: 'IBM Plex Mono', monospace; font-size: 13px; font-weight: 600; }
.dg-gap-fill.best { width: 93%; background: #D4D4D8; color: var(--mm-text-light); }
.dg-gap-fill.today { width: 67%; background: var(--wms-green-text-light); color: #FFFFFF; }
.dg-gap-hole {
    position: absolute;
    left: 67%;
    width: 26%;
    top: 0;
    bottom: 0;
    background: repeating-linear-gradient(135deg, rgba(190, 18, 60, 0.18) 0 5px, transparent 5px 10px);
    border: 1.5px dashed var(--dg-red-light);
}
.dg-gap-note { margin: 2px calc((100% - 92px) * 0.07) 0 0; text-align: right; white-space: nowrap; font-family: 'IBM Plex Mono', monospace; font-size: 13px; line-height: 1.4; color: var(--dg-red-light); }
.dg-gap-note::before { content: "↑ "; }

.dg-calc-rows { background: var(--mm-black); padding: 6px 16px 14px; }
.dg-calc-row { display: grid; grid-template-columns: 18px minmax(0, 1fr); column-gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--mm-border); }
.dg-calc-row:last-child { border-bottom: none; }
.dg-calc-op { grid-row: 1 / span 2; font-family: 'IBM Plex Mono', monospace; font-size: 15px; line-height: 1.5; color: var(--mm-green); }
.dg-calc-v { font-family: 'IBM Plex Mono', monospace; font-size: 16px; font-weight: 500; line-height: 1.5; color: var(--mm-white); }
.dg-calc-k { font-size: 13px; line-height: 1.4; color: var(--mm-gray); }
.dg-calc-row.total { border-top: 2px solid var(--mm-green); border-bottom: none; margin-top: 2px; }
.dg-calc-row.total .dg-calc-v { font-size: 20px; font-weight: 600; color: var(--mm-green); }
.dg-calc-tag { margin: 0 0 10px; font-family: 'IBM Plex Mono', monospace; font-size: 12px; line-height: 1.4; color: var(--mm-text-muted); }

/* ================================================================
   4. LO QUE TE LLEVAS (#get): tus números, el taller, tu resumen de una página
   ================================================================ */
.dg-take { margin: 28px 0 28px; container-type: inline-size; }
.dg-take-row { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr 1fr 1.3fr; column-gap: 26px; align-items: stretch; }
.dg-take-row > li { position: relative; background: var(--wms-paper-card); border: 1px solid var(--mm-border-light); padding: 14px 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.dg-take-row > li + li::before {
    content: "";
    position: absolute;
    left: -24px;
    top: 50%;
    width: 22px;
    height: 12px;
    margin-top: -6px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='12' viewBox='0 0 22 12'%3E%3Cpath d='M0 6h20' stroke='%23047857' stroke-width='1.5'/%3E%3Cpath d='M15 1.5 21 6l-6 4.5' fill='none' stroke='%23047857' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
}
.dg-k { font-family: 'IBM Plex Mono', monospace; font-size: 13px; font-weight: 600; line-height: 1.35; color: var(--wms-green-text-light); }
.dg-d { font-size: 15px; line-height: 1.45; color: var(--mm-text-medium); }
.dg-take-row > li.dg-take-mid { border-color: var(--wms-green-text-light); box-shadow: inset 0 3px 0 var(--wms-green-text-light); }
.dg-take-row > li.dg-take-out { background: var(--mm-black); border-color: var(--mm-black); }
.dg-take-out .dg-k { color: var(--mm-green); }
.dg-slide { margin-top: 4px; aspect-ratio: 16 / 10; border: 1px solid var(--mm-darkest); background: var(--mm-black-card); padding: 10px 10px; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.dg-slide-line { display: flex; flex-direction: column; gap: 3px; font-size: 13px; line-height: 1.3; color: var(--mm-light); }
.dg-slide-line i { display: block; height: 8px; background: var(--mm-darkest); }
.dg-slide-line.money i { width: 60%; background: var(--mm-green); }

@container (max-width: 620px) {
    .dg-take-row { grid-template-columns: 1fr; row-gap: 26px; }
    .dg-take-row > li + li::before {
        left: 50%;
        top: -24px;
        width: 12px;
        height: 22px;
        margin: 0 0 0 -6px;
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='22' viewBox='0 0 12 22'%3E%3Cpath d='M6 0v20' stroke='%23047857' stroke-width='1.5'/%3E%3Cpath d='M1.5 15 6 21l4.5-6' fill='none' stroke='%23047857' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
    }
    .dg-d { font-size: 16px; }
    .dg-slide { aspect-ratio: auto; padding: 14px; }
    .dg-slide-line { font-size: 14px; }
}

/* ================================================================
   5. LOS DOS CAMINOS DESPUÉS DE ENCONTRAR LA FUGA (#get)
   ================================================================ */
.dg-fork { margin: 24px 0 8px; }
.dg-fork-root { position: relative; max-width: 340px; margin: 0 auto; padding: 12px 16px; background: var(--mm-black); color: var(--mm-white); text-align: center; }
.dg-fork-root .dg-k { display: block; color: var(--mm-green); }
.dg-fork-root .dg-d { display: block; color: var(--mm-light); }
.dg-fork-branches { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding-top: 40px; }
/* Tronco, rama horizontal y bajadas */
.dg-fork-branches::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 0;
    width: 0;
    height: 20px;
    border-left: 1.5px solid var(--mm-text-muted);
}
.dg-fork-branches::after {
    content: "";
    position: absolute;
    left: calc(25% - 4px);
    right: calc(25% - 4px);
    top: 20px;
    border-top: 1.5px solid var(--mm-text-muted);
}
.dg-fork-b { margin: 0; position: relative; background: var(--wms-paper-card); border: 1px solid var(--mm-border-light); padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; }
.dg-fork-b::before {
    content: "";
    position: absolute;
    left: 50%;
    top: -21px;
    width: 12px;
    height: 20px;
    margin-left: -6px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='20' viewBox='0 0 12 20'%3E%3Cpath d='M6 0v18' stroke='%2352525B' stroke-width='1.5'/%3E%3Cpath d='M1.5 13.5 6 19l4.5-5.5' fill='none' stroke='%2352525B' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
}
.dg-fork-b .dg-k { color: var(--mm-text-light); }
.dg-fork .dg-cap { text-align: center; }

@media (max-width: 600px) {
    .dg-cap { font-size: 15px; }
    .wms-way .dg-flow li { font-size: 16px; }
    .dg-fork-b { padding: 12px 12px 14px; }
    .dg-fork-b .dg-d { font-size: 15px; }
}
