/**
 * nra.css — Estilos PWA Móvil: Control Mensual NRM (Formulario)
 * @version 4.2 — Tablas semánticas y scroll horizontal local estable
 */
:root {
    --nrm-primary: #0d6efd;
    --nrm-primary-dark: #0d47a1;
    --nrm-success: #198754;
    --nrm-warning: #e65c00;
    --nrm-danger: #dc3545;
    --nrm-info: #0dcaf0;
    --nrm-bg: #f8f9fa;
    --nrm-card-radius: 14px;
    --nrm-shadow: 0 3px 12px rgba(0, 0, 0, 0.09);
    --nrm-header-h: 52px;
    --nrm-status-h: 28px;
    --nrm-tabs-h: 50px;
    --nrm-action-h: 64px;
    --nrm-top-offset: calc(
        var(--nrm-header-h) + var(--nrm-status-h) + var(--nrm-tabs-h)
    );
}

*,
*::before,
*::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    background: var(--nrm-bg);
    font-family:
        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
        sans-serif;
    overflow-x: hidden;
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

/* Header fijo */
.nrm-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1040;
    height: var(--nrm-header-h);
    background: linear-gradient(90deg, #0d47a1 0%, #1565c0 50%, #0d6efd 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
.nrm-header-title {
    font-size: clamp(0.86rem, 3.9vw, 0.96rem);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    text-align: center;
    min-width: 0;
}
.nrm-header-badge {
    font-size: clamp(0.64rem, 2.9vw, 0.72rem);
    padding: 3px 8px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.35);
    white-space: nowrap;
    cursor: default;
}

/* Barra de estado */
.nrm-status-bar {
    position: fixed;
    top: var(--nrm-header-h);
    left: 0;
    right: 0;
    z-index: 1039;
    height: var(--nrm-status-h);
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
    font-size: clamp(0.66rem, 2.9vw, 0.72rem);
    color: #4a6085;
    border-bottom: 1px solid #dee2e6;
}
.nrm-status-bar small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nrm-status-bar small:first-child {
    flex: 1;
}
.nrm-status-bar small:last-child {
    flex: 0 0 auto;
}

/* Tabs */
.nrm-tabs {
    position: fixed;
    top: calc(var(--nrm-header-h) + var(--nrm-status-h));
    left: 0;
    right: 0;
    z-index: 1038;
    height: var(--nrm-tabs-h);
    background: #fff;
    border-bottom: 1px solid #dee2e6;
}
.nrm-tabs .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    border: none;
    padding: 0 4px;
    height: 100%;
    display: flex;
    align-items: stretch;
}
.nrm-tabs .nav-tabs::-webkit-scrollbar {
    display: none;
}
.nrm-tabs .nav-link {
    border: none;
    border-bottom: 3px solid transparent;
    flex: 1 1 0;
    min-width: 0;
    padding: 7px 3px;
    font-size: clamp(0.66rem, 3vw, 0.77rem);
    font-weight: 600;
    color: #6c757d;
    white-space: nowrap;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    height: 100%;
}
.nrm-tabs .nav-link i {
    font-size: clamp(0.98rem, 4.3vw, 1.1rem);
}
.nrm-tabs .nav-link.active {
    color: var(--nrm-primary);
    border-bottom-color: var(--nrm-primary);
    background: transparent;
}
.tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 17px;
    height: 17px;
    border-radius: 9px;
    background: var(--nrm-primary);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    padding: 0 5px;
    margin-left: 2px;
}

/* ===== CONTENEDOR PRINCIPAL ===== */
.nrm-wrapper {
    overflow-x: hidden;
    overflow-y: auto;
    margin-top: var(--nrm-top-offset);
    margin-bottom: 0;
    padding: 12px 10px calc(var(--nrm-action-h) + 18px + env(safe-area-inset-bottom)) 10px;
    min-height: calc(100vh - var(--nrm-top-offset));
    background: var(--nrm-bg);
    -webkit-overflow-scrolling: touch; /* suavizado en iOS */
}

/* Tablas anchas: scroll horizontal local en su contenedor */
.nrm-tbl-presiones,
.nrm-tbl-checklist {
    min-width: 680px;
    width: max-content;
    white-space: nowrap;
    border-collapse: collapse;
    margin-bottom: 0;
}
.nrm-tbl-presiones th,
.nrm-tbl-presiones td,
.nrm-tbl-checklist th,
.nrm-tbl-checklist td {
    white-space: nowrap;
    vertical-align: middle;
}
.nrm-tbl-checklist {
    min-width: 500px;
}

/* Contenedores de tablas: scroll propio para no deformar toda la vista */
.table-responsive {
    overflow-x: auto !important;
    overflow-y: visible !important;
    width: 100%;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

/* Barras de scroll personalizadas (opcional, solo estética) */
.nrm-wrapper::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.nrm-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}
.nrm-wrapper::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}
.nrm-wrapper::-webkit-scrollbar-thumb:hover {
    background: #555;
}
.nrm-wrapper {
    scrollbar-width: thin;
    scrollbar-color: #888 #f1f1f1;
}

/* Cards y formularios */
.nrm-card {
    background: #fff;
    border-radius: var(--nrm-card-radius);
    box-shadow: var(--nrm-shadow);
    margin-bottom: 12px;
    overflow: visible;
    border: 1px solid rgba(0, 0, 0, 0.04);
}
.nrm-card-header {
    gap: 8px;
    padding: 10px 12px;
    font-weight: 700;
    font-size: clamp(0.78rem, 3.4vw, 0.86rem);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.nrm-card-header > span {
    min-width: 0;
    overflow-wrap: anywhere;
}
.nrm-card-header .btn {
    flex: 0 0 auto;
    min-width: 0;
    padding: 6px 8px;
    font-size: clamp(0.72rem, 3vw, 0.82rem);
}
.nrm-card-body {
    overflow: visible;
    padding: 12px;
}
.nrm-card-body.p-0 {
    padding: 0;
}

.form-group {
    margin-bottom: 12px;
}
.form-group label {
    display: block;
    font-size: clamp(0.7rem, 3vw, 0.76rem);
    font-weight: 700;
    color: #4a5568;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.form-control {
    min-width: 0;
    font-size: 16px;
    border-radius: 9px;
    border: 1.5px solid #d0dae8;
    padding: 9px 12px;
    background: #fff;
    width: 100%;
    height: 45px;
}
.form-control:focus {
    border-color: var(--nrm-primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12);
    outline: none;
}
input[type='number'] {
    -moz-appearance: textfield;
    appearance: textfield;
}
input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Tabla de equipos (lista de dispensadores/compresores) */
.table-equipo {
    width: 100% !important;
    min-width: 0;
    table-layout: fixed;
    font-size: clamp(0.75rem, 3.2vw, 0.85rem);
    margin-bottom: 0;
}
.table-equipo thead th {
    background: var(--nrm-primary-dark);
    color: #fff;
    font-weight: 700;
    font-size: clamp(0.64rem, 2.9vw, 0.72rem);
    padding: 7px 4px;
    text-transform: uppercase;
}
.table-equipo tbody td {
    vertical-align: middle;
    padding: 6px 4px;
    font-size: clamp(0.72rem, 3vw, 0.78rem);
    min-width: 0;
}
.table-equipo tbody tr:nth-child(even) {
    background: #f8fafd;
}
.table-equipo tbody tr:hover {
    background: #ebf2ff;
}

/* Toggle elegante */
.toggle-elegante-container {
    text-align: center;
}
.toggle-switch-elegante {
    display: inline-block;
    width: 42px;
    height: 42px;
    border-radius: 21px;
    background: #e9ecef;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.toggle-switch-elegante.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.toggle-switch-elegante.enabled {
    background: #d4edda;
}
.toggle-switch-elegante.active {
    background: #28a745;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.3);
}
.toggle-knob {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #495057;
}
.toggle-switch-elegante.active .toggle-knob {
    color: #fff;
}

/* Barra de acciones inferior */
.nrm-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    min-height: var(--nrm-action-h);
    gap: 6px;
    padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    z-index: 1050;
}
.nrm-action-bar .btn {
    flex: 1;
    min-width: 0;
    font-size: clamp(0.78rem, 3.4vw, 0.95rem);
    padding: 9px 4px;
    border-radius: 10px;
    font-weight: 600;
    line-height: 1.15;
    white-space: normal;
}
.nrm-action-bar .btn:active {
    transform: scale(0.97);
}

/* Spinner */
.nrm-spinner {
    display: inline-block;
    width: 17px;
    height: 17px;
    border: 2.5px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: nrm-spin 0.7s linear infinite;
}
@keyframes nrm-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Estado vacío */
.empty-state {
    text-align: center;
    padding: 28px 14px;
    color: #b0bec5;
}
.empty-state i {
    font-size: 2.8rem;
    margin-bottom: 12px;
    display: block;
}

.table-equipo > thead {
    display: table-header-group;
}

.table-equipo > tbody {
    display: table-row-group;
}

.table-equipo > thead > tr,
.table-equipo > tbody > .dispensador-row,
.table-equipo > tbody > .compresor-row,
.table-equipo > tbody > .formulario-row {
    display: table-row;
}

.table-equipo > thead > tr > th,
.table-equipo > tbody > .dispensador-row > td,
.table-equipo > tbody > .compresor-row > td {
    display: table-cell;
}

.table-equipo > thead > tr > th:nth-child(1),
.table-equipo > tbody > .dispensador-row > td:nth-child(1),
.table-equipo > tbody > .compresor-row > td:nth-child(1) {
    width: 28px !important;
}

.table-equipo > thead > tr > th:nth-child(2),
.table-equipo > tbody > .dispensador-row > td:nth-child(2),
.table-equipo > tbody > .compresor-row > td:nth-child(2) {
    width: auto !important;
}

.table-equipo > thead > tr > th:nth-child(3),
.table-equipo > tbody > .dispensador-row > td:nth-child(3),
.table-equipo > tbody > .compresor-row > td:nth-child(3) {
    width: 58px !important;
}

.table-equipo > thead > tr > th:nth-child(4),
.table-equipo > tbody > .dispensador-row > td:nth-child(4),
.table-equipo > tbody > .compresor-row > td:nth-child(4) {
    width: 38px !important;
}

.table-equipo > tbody > .formulario-row > td {
    width: auto !important;
}

.table-equipo select.form-control-sm {
    height: 40px;
    padding-right: 24px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table-equipo .toggle-text,
.table-equipo [id^='toggle-text-'] {
    margin-top: 2px !important;
    font-size: 0.58rem !important;
    line-height: 1.05;
    white-space: normal;
}

.table-equipo .btn-outline-danger {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
}

.formato-dinamico-container {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: visible;
}

.formato-dinamico-container.p-3 {
    padding: 10px !important;
}

.nrm-formato-wrapper {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: visible !important;
}

.nrm-formato-wrapper h6 {
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.25;
}

.nrm-formato-wrapper .card {
    border-radius: 8px;
    overflow: hidden;
}

.nrm-formato-wrapper .card-title {
    font-size: clamp(0.78rem, 3.4vw, 0.9rem);
    line-height: 1.25;
}

.nrm-formato-wrapper table {
    font-size: clamp(0.68rem, 2.9vw, 0.78rem);
}

.nrm-formato-wrapper .table-responsive {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    overflow-y: visible !important;
    overscroll-behavior-x: contain;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
}

.nrm-formato-wrapper th,
.nrm-formato-wrapper td {
    padding: 4px;
}

.nrm-formato-wrapper .form-control-sm,
.nrm-formato-wrapper .nrm-label-calc {
    min-height: 34px;
    padding: 4px 6px;
    font-size: 0.82rem;
}

.nrm-formato-wrapper input[type='checkbox'],
.nrm-formato-wrapper input[type='radio'] {
    min-width: 18px;
    min-height: 18px;
}

.nrm-tbl-presiones {
    min-width: 640px !important;
}

.nrm-tbl-checklist {
    min-width: 460px !important;
}

/* Responsive */
@media (max-width: 380px) {
    :root {
        --nrm-header-h: 50px;
        --nrm-status-h: 28px;
        --nrm-tabs-h: 48px;
        --nrm-action-h: 60px;
    }

    .nrm-wrapper {
        padding-right: 8px;
        padding-left: 8px;
    }

    .nrm-tabs .nav-link {
        padding-right: 2px;
        padding-left: 2px;
    }

    .nrm-card {
        border-radius: 10px;
    }

    .nrm-card-body {
        padding: 10px;
    }

    .table-equipo > thead > tr > th:nth-child(1),
    .table-equipo > tbody > .dispensador-row > td:nth-child(1),
    .table-equipo > tbody > .compresor-row > td:nth-child(1) {
        width: 24px !important;
    }

    .table-equipo > thead > tr > th:nth-child(3),
    .table-equipo > tbody > .dispensador-row > td:nth-child(3),
    .table-equipo > tbody > .compresor-row > td:nth-child(3) {
        width: 52px !important;
    }

    .table-equipo > thead > tr > th:nth-child(4),
    .table-equipo > tbody > .dispensador-row > td:nth-child(4),
    .table-equipo > tbody > .compresor-row > td:nth-child(4) {
        width: 36px !important;
    }

    .table-equipo th,
    .table-equipo td {
        padding-right: 2px;
        padding-left: 2px;
    }

    .toggle-switch-elegante {
        width: 36px;
        height: 36px;
    }

    .table-equipo .toggle-text,
    .table-equipo [id^='toggle-text-'] {
        display: none !important;
    }

    .nrm-action-bar .btn {
        padding-right: 2px;
        padding-left: 2px;
    }

    .nrm-action-bar .btn i {
        display: block;
        margin: 0 0 2px;
    }
}

@media (max-width: 340px) {
    .nrm-status-bar {
        padding-right: 8px;
        padding-left: 8px;
    }

    .nrm-tabs .nav-tabs {
        padding-right: 2px;
        padding-left: 2px;
    }

    .table-equipo > thead > tr > th:nth-child(1),
    .table-equipo > tbody > .dispensador-row > td:nth-child(1),
    .table-equipo > tbody > .compresor-row > td:nth-child(1) {
        width: 22px !important;
    }

    .table-equipo > thead > tr > th:nth-child(3),
    .table-equipo > tbody > .dispensador-row > td:nth-child(3),
    .table-equipo > tbody > .compresor-row > td:nth-child(3) {
        width: 48px !important;
    }

    .table-equipo > thead > tr > th:nth-child(4),
    .table-equipo > tbody > .dispensador-row > td:nth-child(4),
    .table-equipo > tbody > .compresor-row > td:nth-child(4) {
        width: 34px !important;
    }

    .nrm-action-bar {
        gap: 4px;
    }
}
