/* ===================================================
   CALCULADORA REBT — Estilos Base y Optimización Móvil
   =================================================== */

/* Base del body */
body {
    background-color: #f8fafc;
    /* dvh para compatibilidad con iOS Safari (evita salto de barra de dirección) */
    min-height: 100dvh;
}

/* Respeta áreas seguras (notch/barras del sistema) en móviles modernos */
header {
    padding-top: calc(0.75rem + env(safe-area-inset-top));
}

main {
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
}

/* ========================
   TABLA DE DATOS — Inputs
   ======================== */
.table-input {
    width: 100%;
    min-width: 70px;
    padding: 0.5rem 0.4rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.25rem;
    /* CRÍTICO: 16px mínimo para evitar auto-zoom en iOS Safari */
    font-size: 16px;
    background-color: transparent;
    color: #1e293b;
    box-sizing: border-box;
}

.table-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.table-input[readonly] {
    background-color: #f1f5f9;
    cursor: not-allowed;
    color: #1d4ed8;
    font-weight: 600;
}

th {
    white-space: nowrap;
    font-size: 0.7rem;
}

/* ========================
   SCROLL HORIZONTAL TABLA
   ======================== */
.table-scroll-wrap {
    overflow-x: auto;
    /* Scroll suave en iOS */
    -webkit-overflow-scrolling: touch;
    /* Indicador visual de scroll en móvil */
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

#rebtTable {
    width: 100%;
    min-width: 0;
}

.table-scroll-wrap::-webkit-scrollbar {
    height: 4px;
}

.table-scroll-wrap::-webkit-scrollbar-track {
    background: transparent;
}

.table-scroll-wrap::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 4px;
}

/* Indicador de scroll horizontal (solo visible en móvil cuando hay overflow) */
.scroll-hint {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 4px 12px 2px;
    font-size: 0.65rem;
    color: #94a3b8;
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
}

@media (max-width: 768px) {
    .scroll-hint {
        display: none;
    }

    .table-scroll-wrap {
        overflow-x: visible;
    }

    #rebtTable thead {
        display: none;
    }

    #tableBody {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 8px;
    }

    #tableBody tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        padding: 10px;
        background: #ffffff;
    }

    #tableBody td {
        display: flex;
        flex-direction: column;
        gap: 4px;
        border-right: 0 !important;
        padding: 0 !important;
    }

    #tableBody td::before {
        content: attr(data-label);
        font-size: 0.62rem;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: #64748b;
        font-weight: 700;
    }

    #tableBody td.mobile-wide,
    #tableBody td.actions-cell {
        grid-column: 1 / -1;
    }

    #tableBody tr.is-collapsed td[data-label="Cantidad"],
    #tableBody tr.is-collapsed td[data-label="F. Sim"],
    #tableBody tr.is-collapsed td[data-label="Longitud (m)"],
    #tableBody tr.is-collapsed td[data-label="% c.d.t. Máx"] {
        display: none;
    }

    #tableBody tr.is-collapsed {
        gap: 6px;
    }

    #tableBody tr.is-collapsed td::before {
        font-size: 0.58rem;
    }

    #tableBody td.actions-cell {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-end;
        align-items: center;
        gap: 6px;
        margin-top: 2px;
    }

    #tableBody td.actions-cell::before {
        content: none;
    }

    .mobile-row-summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-basis: 100%;
        padding: 6px 8px;
        border-radius: 8px;
        font-size: 0.68rem;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
    }

    .mobile-row-summary .summary-main {
        color: #0f172a;
        font-weight: 700;
        letter-spacing: 0.01em;
    }

    .mobile-row-summary .summary-status {
        font-weight: 700;
    }

    .mobile-row-summary.is-ok .summary-status {
        color: #15803d;
    }

    .mobile-row-summary.is-warning .summary-status,
    .mobile-row-summary.is-pending .summary-status {
        color: #b45309;
    }

    .mobile-row-summary.is-danger .summary-status {
        color: #dc2626;
    }

    /* Reducir tamaño de inputs en la tabla para ganar espacio */
    .table-input {
        min-width: 60px;
        padding: 0.4rem 0.3rem;
    }

    th {
        font-size: 0.6rem;
        padding: 0.4rem 0.5rem !important;
    }

    #tableBody td.actions-cell button {
        min-width: 40px;
    }

    #tableBody td.actions-cell .mobile-accordion-toggle {
        margin-right: auto;
    }

    /* Pie de tabla más legible en viewport estrecho */
    #rebtTable tfoot {
        display: block;
        margin-top: 6px;
    }

    #rebtTable tfoot tr {
        display: block;
    }

    #rebtTable tfoot td {
        display: block;
        width: 100% !important;
        border-right: 0 !important;
    }

    #rebtTable tfoot td:first-child {
        text-align: left !important;
        border-bottom: 0;
    }

    #rebtTable tfoot td:last-child > div {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }

    #totalPotenciaCalculo {
        font-size: 0.95rem;
        line-height: 1.25rem;
    }

    #totalPotenciaDetalle {
        font-size: 0.65rem;
    }
}

/* ========================
   HEADER — Botones móvil
   ======================== */
@media (max-width: 639px) {
    /* Texto de botones oculto — solo iconos */
    .header-btn-text {
        display: none;
    }

    /* Boto "Añadir Fila" — solo icono en pantallas muy pequeñas */
    .header-btn-add-text {
        display: none;
    }

    .header-actions {
        max-width: 58vw;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .header-actions::-webkit-scrollbar {
        display: none;
    }

    .header-btn {
        flex: 0 0 auto;
        min-width: 42px;
        justify-content: center;
    }
}

/* ========================
   MODAL — Usabilidad móvil
   ======================== */
@media (max-width: 640px) {
    /* El modal ocupa casi toda la pantalla en móvil */
    #configModal > div,
    #projectModal > div,
    #changelogModal > div {
        margin: 0 1rem;
        max-height: 90dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================
   ANIMACIONES
   ======================== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.card-enter {
    animation: fadeIn 0.3s ease-out forwards;
}

/* ========================
   MEJORAS TÁCTILES GLOBALES
   ======================== */
button, select, input {
    /* Eliminar tap highlight en iOS */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Targets táctiles mínimos de 44px (heurística WCAG) */
button {
    min-height: 44px;
}
