/* ============================================================
   blog.css
   Complementa a style.css
   Estrategia: Mobile First → Tablet (768px) → Desktop (1024px)
   ============================================================ */


/* ============================================================
   1. LAYOUT CON ÍNDICE
   ============================================================ */

.pages_box.blog_with-indice {

    .content-wrapper {
        display: flex;
        flex-direction: column; /* móvil: columna */
        gap: 2rem;
        max-width: 100%;
        margin: 0 auto;
        padding: 4rem 1rem 0;

        /* Tablet → fila */
        @media (min-width: 768px) {
            flex-direction: row;
            padding: 6rem 1rem 0;
        }
    }

    .table-of-contents {
        width: 100%;
        position: static; /* móvil: flujo normal */
        padding: 1.5rem;
        border-radius: 8px;
        max-height: none;
        overflow-y: visible;

        h3 {
            margin-top: 0;
            margin-bottom: 1rem;
            font-size: 2.4rem;
            text-transform: uppercase;
            color: #333;
        }

        /* Desktop → sticky */
        @media (min-width: 1024px) {
            flex: 0 0 40rem;
            position: sticky;
            top: 2rem;
            align-self: flex-start;
            max-height: calc(100vh - 4rem);
            overflow-y: auto;
        }
    }

    .main-content {
        flex: 1;
        min-width: 0;
    }
}


/* ============================================================
   2. NAVEGACIÓN DEL ÍNDICE (#indice-nav)
   ============================================================ */

#indice-nav {
    font-size: 0.9rem;
    counter-reset: h2-counter h3-counter h4-counter h5-counter h6-counter;

    ul {
        list-style: none;
        padding: 0;
        margin: 0;

        ul {
            counter-reset: h3-counter h4-counter h5-counter h6-counter;
            padding-left: 1.5rem; /* reducido en móvil */

            ul {
                counter-reset: h4-counter h5-counter h6-counter;
                padding-left: 1.5rem;

                ul {
                    counter-reset: h5-counter h6-counter;
                    padding-left: 1.5rem;

                    ul {
                        counter-reset: h6-counter;
                        padding-left: 1.5rem;
                    }
                }
            }
        }

        /* Tablet → más indentado */
        @media (min-width: 768px) {
            ul {
                padding-left: 2rem;

                ul { padding-left: 2rem; }
                ul ul { padding-left: 2rem; }
                ul ul ul { padding-left: 2rem; }
            }
        }
    }

    li {
        margin-bottom: 0.5rem;
        display: flex;
        align-items: baseline;
        gap: 0.5rem;
        flex-wrap: wrap;
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        

        &::before {
            display: inline-block;
            min-width: 2rem;
            text-align: right;
            color: var(--dark);
            font-weight: normal;
        }

        &.indice-h2 {
            counter-increment: h2-counter;
            counter-reset: h3-counter h4-counter h5-counter h6-counter;
            font-weight: bold;

            &::before {
                content: counter(h2-counter) ".";
                min-width: 2rem;
				max-width: 10%;
                color: var(--dark);
                font-weight: bold;
                font-size: 1.6rem;
            }
        }

        &.indice-h3 {
            counter-increment: h3-counter;
            counter-reset: h4-counter h5-counter h6-counter;

            a {
                font-size: 1.5rem;
                flex-basis: min-content;
            }

            &::before {
                content: counter(h2-counter) "." counter(h3-counter) ".";
                min-width: 2.8rem;
                color: #666;
                font-size: 1.5rem;
            }
        }

        &.indice-h4 {
            counter-increment: h4-counter;
            counter-reset: h5-counter h6-counter;
            font-size: 0.85rem;

            a {
                font-size: 1.4rem;
                flex-basis: min-content;
            }

            &::before {
                content: counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) ".";
                min-width: 3.6rem;
                color: #999;
                font-size: 1.4rem;
            }
        }

        &.indice-h5 {
            counter-increment: h5-counter;
            counter-reset: h6-counter;
            font-size: 0.8rem;

            a {
                font-size: 1.4rem;
                flex-basis: min-content;
            }

            &::before {
                content: counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) "." counter(h5-counter) ".";
                min-width: 4.4rem;
                color: #999;
                font-size: 1.4rem;
            }
        }

        &.indice-h6 {
            counter-increment: h6-counter;
            font-size: 0.75rem;

            a {
                font-size: 1.4rem;
                flex-basis: min-content;
            }

            &::before {
                content: counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) "." counter(h5-counter) "." counter(h6-counter) ".";
                min-width: 5.2rem;
                color: #999;
                font-size: 1.4rem;
            }
        }
    }

    a {
        text-decoration: none;
        text-align: left;
        line-height: 1.5;
        color: #666;
        flex: 1;
        padding: 0;
        transition: color 0.3s;
        flex-basis: min-content;
		min-width: 89%;
        &:hover {
            color: var(--red);
        }

        &.active {
            color: var(--red);
            font-weight: bold;
        }
    }
}


/* ============================================================
   3. CONTENIDO PRINCIPAL (.main-content)
   ============================================================ */

.main-content {
    max-width: 100%;
    color: var(--dark);

    /* ----------------------------------
       Espaciado vertical base
       ---------------------------------- */

    > * {
        margin-bottom: 2rem;

        &:last-child {
            margin-bottom: 0;
        }
    }


    /* ----------------------------------
       Títulos
       ---------------------------------- */

    h1, h2, h3, h4, h5, h6 {
        font-family: var(--font-secondary);
        color: var(--dark);
        line-height: 1.3;
        margin-bottom: 2rem;

        &:first-child {
            margin-top: 0;
        }

        a {
            color: inherit;

            &:hover {
                color: var(--blue);
                text-decoration: underline;
            }
        }
    }

    h1 {
        font-size: 3.2rem;
        font-weight: 600;

        @media (min-width: 768px) { font-size: 4rem; }
    }

    h2 {
        font-size: 2.8rem;
        font-weight: 500;

        @media (min-width: 768px) { font-size: 3.2rem; }
    }

    h3 {
        font-size: 2.4rem;
        font-weight: 400;

        @media (min-width: 768px) { font-size: 2.8rem; }
    }

    h4 {
        font-size: 1.8rem;
        font-weight: 300;

        @media (min-width: 768px) { font-size: 2.4rem; }
    }

    h5 {
        font-size: 1.6rem;
        font-weight: 500;
        font-family: var(--font-primary);

        @media (min-width: 768px) { font-size: 1.8rem; }
    }

    h6 {
        font-size: 1.4rem;
        font-weight: 400;
        font-family: var(--font-primary);
        text-transform: uppercase;
        letter-spacing: 0.05em;

        @media (min-width: 768px) { font-size: 1.6rem; }
    }


    /* ----------------------------------
       Párrafos
       ---------------------------------- */

    p {
        text-align: left;

        &.has-drop-cap:first-letter {
            font-size: 4.8rem;
            font-weight: 700;
            float: left;
            line-height: 1;
            margin-right: 1rem;
            color: var(--dark);
            font-family: var(--font-secondary);
        }

        @media (min-width: 1024px) {
            line-height: 2.8rem;
        }
    }


    /* ----------------------------------
       Texto destacado
       ---------------------------------- */

    mark,
    .highlight {
        background-color: var(--yellow);
        padding: 0.2rem 0.4rem;
        border-radius: 0.3rem;
        color: var(--dark);
    }


    /* ----------------------------------
       Enlaces
       ---------------------------------- */

    a:not(.wp-block-button__link) {
        color: var(--blue);
        text-decoration: underline;
        text-underline-offset: 0.2rem;
        transition: color 0.2s ease;

        &:hover {
            color: var(--blue-dark);
            text-decoration: none;
        }

        &:focus {
            outline: 2px solid var(--blue);
            outline-offset: 2px;
        }
    }


    /* ----------------------------------
       Listas
       ---------------------------------- */

    ul, ol {
        margin-bottom: 2rem;
        padding-left: 3rem;

        li {
            margin-left: 0;
            margin-bottom: 0.8rem;
            text-align: left;

            &:last-child {
                margin-bottom: 0;
            }
        }

        ul, ol {
            margin-top: 0.8rem;
            margin-bottom: 0;
        }
    }

    ul {
        list-style-type: disc;

        ul {
            list-style-type: circle;

            ul {
                list-style-type: square;
            }
        }
    }

    ol {
        list-style-type: decimal;

        ol {
            list-style-type: lower-alpha;

            ol {
                list-style-type: lower-roman;
            }
        }
    }


    /* ----------------------------------
       Citas
       ---------------------------------- */

    blockquote,
    .wp-block-quote {
        margin: 3rem 0;
        padding: 2rem 3rem;
        border-left: 4px solid var(--blue);
        background: var(--gray-1);
        font-style: italic;
        color: var(--gray-8);

        p {
            margin-bottom: 1rem;
            color: inherit;

            &:last-child {
                margin-bottom: 0;
            }
        }

        cite,
        .wp-block-quote__citation {
            display: block;
            margin-top: 1rem;
            font-size: 1.4rem;
            font-style: normal;
            color: var(--dark);

            &::before {
                content: "— ";
            }
        }

        &.is-style-large {
            font-size: 2rem;

            @media (min-width: 768px) { font-size: 2.4rem; }
        }
    }


    /* ----------------------------------
       Código
       ---------------------------------- */

    code, kbd, pre, samp {
        font-family: monospace;
        font-size: 1.4rem;
    }

    code {
        padding: 0.2rem 0.4rem;
        background: var(--gray-2);
        border-radius: 0.3rem;
        color: var(--red);
    }

    pre {
        margin: 2rem 0;
        padding: 2rem;
        background: var(--gray-1);
        border: 1px solid var(--gray-3);
        border-radius: 0.6rem;
        overflow-x: auto;
        white-space: pre-wrap;
        word-wrap: break-word;

        code {
            padding: 0;
            background: transparent;
            color: inherit;
            font-size: inherit;
        }
    }

    kbd {
        padding: 0.2rem 0.4rem;
        background: var(--gray-3);
        border-radius: 0.3rem;
        color: var(--dark);
    }


    /* ----------------------------------
       Tablas
       ---------------------------------- */

    table,
    .wp-block-table {
        width: 100%;
        margin: 3rem 0;
        border-collapse: collapse;
        font-size: 1.4rem;

        @media (min-width: 768px) { font-size: 1.6rem; }

        caption {
            margin-bottom: 1rem;
            font-weight: 600;
            text-align: left;
            color: var(--dark);
        }

        thead {
            border-bottom: 2px solid var(--gray-4);

            th {
                font-weight: 600;
                background: var(--gray-1);
            }
        }

        th, td {
            padding: 1rem 1.5rem;
            border: 1px solid var(--gray-3);
            text-align: left;
        }

        tbody tr:hover {
            background: var(--gray-1);
        }

        tfoot {
            border-top: 2px solid var(--gray-4);
            background: var(--gray-1);
        }

        &.is-style-stripes {
            tbody tr:nth-child(odd) {
                background: var(--gray-1);
            }
        }
    }


    /* ----------------------------------
       Imágenes y figuras
       ---------------------------------- */

    img,
    figure,
    .wp-block-image {
        max-width: 100%;
        height: auto;
        margin: 0 0 1rem;
        border-radius: 2rem;

        &.alignleft {
            float: none;    /* móvil: sin float */
            margin: 2rem 0;

            @media (min-width: 480px) {
                float: left;
                margin: 0 2rem 2rem 0;
            }
        }

        &.alignright {
            float: none;    /* móvil: sin float */
            margin: 2rem 0;

            @media (min-width: 480px) {
                float: right;
                margin: 0 0 2rem 2rem;
            }
        }

        &.aligncenter {
            display: block;
            margin-left: auto;
            margin-right: auto;
            clear: both;
        }
    }

    .wp-block-image {

        figcaption {
            margin-top: 1rem;
            font-size: 1.4rem;
            color: var(--gray-7);
            text-align: center;
        }

        &.alignfull {
            width: 100vw;
            position: relative;
            left: 50%;
            right: 50%;
            margin-left: -50vw;
            margin-right: -50vw;
            max-width: none;
        }

        &.alignwide {
            @media (min-width: 768px) {
                margin-left: -5%;
                margin-right: -5%;
                width: 110%;
                max-width: 110%;
            }

            @media (min-width: 1024px) {
                margin-left: -15%;
                margin-right: -15%;
                width: 130%;
                max-width: 130%;
            }
        }
    }


    /* ----------------------------------
       Galerías
       ---------------------------------- */

    .wp-block-gallery {
        display: flex;
        flex-wrap: wrap;
        gap: 2rem;
        margin: 3rem 0;
        padding: 0;
        list-style: none;

        .blocks-gallery-item {
            flex: 1 1 calc(50% - 2rem);
            margin: 0;

            @media (min-width: 768px) {
                flex-basis: calc(33.333% - 2rem);
            }

            figure {
                margin: 0;
                height: 100%;

                img {
                    width: 100%;
                    height: auto;
                    object-fit: cover;
                }
            }

            figcaption {
                margin-top: 1rem;
                font-size: 1.2rem;
                color: var(--gray-7);
            }
        }

        &.columns-1 .blocks-gallery-item { flex-basis: 100%; }
        &.columns-2 .blocks-gallery-item { flex-basis: calc(50% - 2rem); }
        &.columns-3 .blocks-gallery-item { flex-basis: calc(33.333% - 2rem); }
        &.columns-4 .blocks-gallery-item { flex-basis: calc(25% - 2rem); }
    }


    /* ----------------------------------
       Videos y embeds
       ---------------------------------- */

    .wp-block-embed {
        margin: 3rem 0;

        &.is-type-video {
            .wp-block-embed__wrapper {
                position: relative;
                padding-bottom: 56.25%; /* 16:9 */
                height: 0;
                overflow: hidden;
                max-width: 100%;

                iframe, object, embed {
                    position: absolute;
                    top: 0;
                    left: 0;
                    width: 100%;
                    height: 100%;
                }
            }
        }

        figcaption {
            margin-top: 1rem;
            font-size: 1.4rem;
            color: var(--gray-7);
        }
    }


    /* ----------------------------------
       Notas al pie
       ---------------------------------- */

    .footnotes,
    .wp-block-footnotes {
        margin-top: 5rem;
        padding-top: 3rem;
        border-top: 2px solid var(--gray-3);
        font-size: 1.4rem;

        ol {
            margin-bottom: 0;
        }

        a {
            word-break: break-word;
        }

        .footnote-backref {
            font-family: monospace;
            margin-left: 0.5rem;
        }
    }


    /* ----------------------------------
       Alertas y cajas destacadas
       ---------------------------------- */

    .alert,
    .wp-block-alert {
        margin: 3rem 0;
        padding: 2rem 3rem;
        border-left: 4px solid;
        border-radius: 0.4rem;

        p {
            margin-bottom: 0;
            text-align: left;

            & + p {
                margin-top: 1rem;
            }
        }

        &-info {
            background: var(--blue);
            border-left-color: var(--blue-dark);
            color: var(--white);

            p { color: var(--white); }
        }

        &-success {
            background: var(--green);
            border-left-color: var(--green-dark);
            color: var(--white);

            p { color: var(--white); }
        }

        &-warning {
            background: var(--orange);
            border-left-color: var(--orange-dark);
            color: var(--white);

            p { color: var(--white); }
        }

        &-error {
            background: var(--red);
            border-left-color: var(--red-dark);
            color: var(--white);

            p { color: var(--white); }
        }
    }


    /* ----------------------------------
       Botones (Gutenberg)
       ---------------------------------- */

    .wp-block-button {
        margin: 2rem 0;

        .wp-block-button__link {
            display: inline-block;
            padding: 1rem 2rem;
            background: var(--blue);
            color: var(--white);
            text-decoration: none;
            border-radius: 0.4rem;
            transition: all 0.2s ease;
            font-size: 1.6rem;
            border: none;
            cursor: pointer;
            font-weight: 400;

            &:hover {
                background: var(--blue-dark);
                transform: translateY(-2px);
            }

            &:focus {
                outline: 2px solid var(--blue);
                outline-offset: 2px;
            }
        }

        &.is-style-outline {
            .wp-block-button__link {
                background: transparent;
                color: var(--blue);
                border: 2px solid var(--blue);

                &:hover {
                    background: var(--blue);
                    color: var(--white);
                }
            }
        }
    }


    /* ----------------------------------
       Columnas (Gutenberg)
       ---------------------------------- */

    .wp-block-columns {
        display: flex;
        flex-wrap: wrap;    /* móvil: apiladas */
        gap: 2rem;
        margin: 3rem 0;

        @media (min-width: 768px) {
            flex-wrap: nowrap;
            gap: 3rem;
        }

        @media (min-width: 1024px) {
            gap: 4rem;
        }

        .wp-block-column {
            flex: 1 1 100%;     /* móvil: ancho completo */

            @media (min-width: 768px) {
                flex: 1;
            }

            > *:first-child { margin-top: 0; }
            > *:last-child  { margin-bottom: 0; }
        }
    }


    /* ----------------------------------
       Separadores
       ---------------------------------- */

    hr,
    .wp-block-separator {
        margin: 5rem auto;
        border: none;
        border-top: 2px solid var(--gray-3);
        width: 10rem;

        &.is-style-wide {
            width: 100%;
        }

        &.is-style-dots {
            width: 100%;
            border: none;
            text-align: center;

            &::before {
                content: "···";
                font-size: 2.4rem;
                letter-spacing: 2rem;
                color: var(--gray-6);
            }
        }
    }


    /* ----------------------------------
       Bloques Gutenberg específicos
       ---------------------------------- */

    .wp-block-group {
        margin: 3rem 0;

        .wp-block-group__inner-container {
            > *:first-child { margin-top: 0; }
            > *:last-child  { margin-bottom: 0; }
        }

        &.has-background {
            padding: 3rem;
            border-radius: 0.8rem;
        }
    }

    .wp-block-cover {
        min-height: 30rem;
        margin: 3rem 0;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--white);

        .wp-block-cover__inner-container {
            max-width: 80rem;
            margin: 0 auto;
            padding: 3rem;
        }
    }
}


/* ============================================================
   4. NAVEGACIÓN ENTRE ENTRADAS (.post-navigation)
   ============================================================ */

.post-navigation {
    display: flex;
    flex-direction: column; /* móvil: columna */
    gap: 1.5rem;
    margin: 3rem 0 2rem;
    padding: 2rem 0;
    border-top: 1px solid var(--gray-3);
    border-bottom: 1px solid var(--gray-3);

    /* Solo un enlace */
    &:has(.nav-previous:only-child),
    &:has(.nav-next:only-child) {
        .nav-previous,
        .nav-next {
            max-width: 100%;
        }
    }

    .nav-previous,
    .nav-next {
        width: 100%;
        max-width: 100%;

        &:empty {
            display: none;
        }

        a {
            display: flex;
            align-items: center;
            justify-content: center; /* móvil: centrado */
            gap: 1rem;
            width: 100%;
            font-family: var(--font-primary);
            font-size: 1.4rem;
            font-weight: 500;
            line-height: 2.2rem;
            color: var(--dark);
            text-decoration: none;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            padding: 1.2rem 1.5rem;
            background: var(--white);
            border: 1px solid var(--gray-2);
            border-radius: 0.8rem;
            transition: all 0.3s ease;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);

            span {
                display: inline-block;
                max-width: 100%;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

            &:hover {
                background: var(--gray-1);
                border-color: var(--blue);
                color: var(--blue);
                transform: translateY(-2px);
                box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            }

            &:active {
                transform: translateY(0);
                box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
            }

            &:focus-visible {
                outline: 2px solid var(--blue);
                outline-offset: 2px;
            }
        }
    }

    /* Flecha: anterior */
    .nav-previous a {
        &::before {
            content: "←";
            font-size: 1.8rem;
            line-height: 1;
            transition: transform 0.3s ease;
        }

        &:hover::before {
            transform: translateX(-4px);
        }
    }

    /* Flecha: siguiente */
    .nav-next a {
        &::after {
            content: "→";
            font-size: 1.8rem;
            line-height: 1;
            transition: transform 0.3s ease;
        }

        &:hover::after {
            transform: translateX(4px);
        }
    }

    /* Tablet → fila */
    @media (min-width: 768px) {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 2rem;
        margin: 4rem 0 2.5rem;
        padding: 2.5rem 0;

        .nav-previous,
        .nav-next {
            flex: 1;
            max-width: 45%;

            a {
                font-size: 1.5rem;
                padding: 1.4rem 2rem;
            }
        }

        .nav-previous a { justify-content: flex-start; }
        .nav-next    a { justify-content: flex-end; margin-left: auto; }

        &:has(.nav-previous:only-child) {
            justify-content: flex-start;
            .nav-previous { max-width: 45%; }
        }

        &:has(.nav-next:only-child) {
            justify-content: flex-end;
            .nav-next { max-width: 45%; }
        }
    }

    /* Desktop */
    @media (min-width: 1024px) {
        margin: 5rem 0 3rem;
        padding: 3rem 0;

        .nav-previous a,
        .nav-next    a {
            font-size: 1.6rem;
            padding: 1.5rem 2.5rem;
        }
    }
}