/* Botón intercambiar */
.btn-swap {
    padding: 0.65rem 1.25rem;
    border-radius: 10px;
    border: 1.5px solid var(--color-border, #e5e7eb);
    background: transparent;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-muted, #6b7280);
    cursor: pointer;
    transition: all .18s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

.btn-swap:hover {
    border-color: #2563eb;
    color: #2563eb;
}

table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
}

table th,
table td {
    padding: 0.5rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    word-break: break-word;
    overflow-wrap: break-word;
    vertical-align: top;
}

/* Anchos de columna para 4 cols (suman 100%) */
table th:nth-child(1),
table td:nth-child(1) {
    width: 36%;
}

table th:nth-child(2),
table td:nth-child(2) {
    width: 16%;
    text-align: center;
}

table th:nth-child(3),
table td:nth-child(3) {
    width: 32%;
    text-align: right;
}

table th:nth-child(4),
table td:nth-child(4) {
    width: 16%;
    text-align: right;
    font-size: 0.75rem;
    color: var(--color-text-muted, #6b7280);
}

table thead th {
    background: #2563eb;
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    vertical-align: middle;
}

/* Contenedor de la tabla con scroll interno */
#tablaWrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

#formulaBox code,
#formulaTexto {
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    font-size: 0.85rem;
    line-height: 1.7;
}

#contextoGrid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)) !important;
    gap: 0.65rem;
    box-sizing: border-box;
}

/* Tarjeta de contexto */
.ctx-card {
    padding: 0.7rem 0.9rem;
    background: var(--color-bg-subtle, #f9fafb);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 10px;
    font-size: 0.82rem;
    line-height: 1.4;
    box-sizing: border-box;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: break-word;
}

.ctx-card .ctx-icon {
    font-size: 1.2rem;
    margin-bottom: 3px;
}

.ctx-card .ctx-label {
    font-weight: 700;
    color: var(--color-text, #374151);
}

.ctx-card .ctx-req {
    color: var(--color-text-muted, #6b7280);
}

.ctx-card.ctx-ok {
    border-color: #86efac;
    background: #f0fdf4;
}

.ctx-card.ctx-no {
    border-color: #fca5a5;
    background: #fef2f2;
    opacity: 0.7;
}

@media (max-width: 480px) {

    /*  Tabla: fuente y padding más compactos  */
    table th,
    table td {
        font-size: 0.75rem;
        padding: 0.45rem 0.35rem;
    }

    table thead th {
        font-size: 0.68rem;
        letter-spacing: 0.02em;
    }

    table th:nth-child(1),
    table td:nth-child(1) {
        width: 32%;
    }

    table th:nth-child(3),
    table td:nth-child(3) {
        width: 34%;
    }

    /*  Fórmula: fuente más pequeña en móvil  */
    #formulaBox code,
    #formulaTexto {
        font-size: 0.78rem;
    }

    /*  Btn swap: ocupa todo el ancho si el contenedor es estrecho  */
    .btn-swap {
        width: 100%;
        justify-content: center;
        font-size: 0.85rem;
    }

    /*  Tarjetas de contexto: 1 col en 375px  */
    #contextoGrid {
        grid-template-columns: 1fr !important;
    }

    .ctx-card {
        font-size: 0.78rem;
        padding: 0.6rem 0.75rem;
    }
}