/* ============================================
   RSA Mobile PWA - Estilos específicos v1.3
   Sobrescribe y adapta estilos para móvil
   ============================================ */

/* RSA Mobile Styles */
.mobile-wrapper {
    padding: 0 !important;
    background-color: #f8f9fa;
    min-height: 100vh;
    overflow-x: hidden;
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

.mobile-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr) 72px;
    column-gap: 6px;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.mobile-header::before {
    content: "";
}

.mobile-title {
    margin: 0;
    font-size: clamp(1rem, 4.6vw, 1.15rem);
    font-weight: 600;
    grid-column: 2;
    text-align: center;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#connectionStatusMobile {
    grid-column: 3;
    justify-self: end;
    white-space: nowrap;
    font-size: clamp(0.68rem, 2.8vw, 0.78rem);
    padding: 0.22rem 0.36rem;
}

.mobile-status-bar {
    background: white;
    padding: 7px 12px;
    border-bottom: 1px solid #dee2e6;
    font-size: clamp(0.76rem, 3.4vw, 0.85rem);
}

.mobile-tabs {
    background: white;
    padding: 5px 0 0;
    border-bottom: 1px solid #dee2e6;
}

.mobile-tabs .nav-tabs {
    border-bottom: none;
    flex-wrap: nowrap;
    width: 100%;
}

.mobile-tabs .nav-link {
    min-width: 0;
    padding: 7px 3px;
    font-size: clamp(0.66rem, 3vw, 0.78rem);
    color: #6c757d;
    border: none;
}

.mobile-tabs .nav-link.active {
    color: #007bff;
    background: transparent;
    border-bottom: 2px solid #007bff;
}

.mobile-tab-content {
    padding: 12px;
    margin-bottom: 0;
    padding-bottom: calc(92px + env(safe-area-inset-bottom)); /* Espacio para la barra de acciones fija */
    overflow-x: hidden;
}

.mobile-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)) !important;
    display: flex;
    gap: 6px !important;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
}

.mobile-action-bar .btn {
    flex: 1;
    min-width: 0;
    border-radius: 10px !important;
    padding: 9px 4px !important;
    font-size: clamp(0.78rem, 3.4vw, 0.95rem) !important;
    line-height: 1.15 !important;
    white-space: normal;
}

.cronometro-mobile {
    background: #e9ecef;
    border-radius: 8px;
    padding: 10px;
    margin: 5px 0 15px;
    text-align: center;
}

.mobile-form .row {
    margin-right: -6px;
    margin-left: -6px;
}

.mobile-form [class*='col-'] {
    min-width: 0;
    padding-right: 6px;
    padding-left: 6px;
}

.mobile-form .card {
    border-radius: 8px;
    overflow: hidden;
}

.mobile-form .card-body {
    padding: 12px;
}

.mobile-form .card-header {
    gap: 8px;
    padding: 10px 12px;
    font-size: clamp(0.88rem, 3.7vw, 1rem);
}

.mobile-form .card-header > span {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Ajustes para formularios en móvil */
.form-control {
    font-size: 16px !important; /* Evita zoom en iOS */
    height: 45px;
    min-width: 0;
}

.btn {
    font-size: 14px;
    padding: 10px;
}

/* Signature pad para móvil */
.signature-container-mobile canvas {
    touch-action: none;
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    width: 100%;
    height: 200px;
}

/* Mejoras para la tabla de equipos */
#tblEquipos {
    width: 100% !important;
    min-width: 0;
    table-layout: fixed;
    font-size: clamp(0.76rem, 3.2vw, 0.85rem);
}

#tblEquipos th {
    padding: 6px 4px;
    vertical-align: middle;
}

#tblEquipos td {
    padding: 5px 4px;
    vertical-align: middle;
    min-width: 0;
}

#content-equipos .card-body > .table-responsive {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    overscroll-behavior-x: contain;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
}

#tblEquipos > thead {
    display: table-header-group;
}

#tblEquipos > tbody {
    display: table-row-group;
}

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

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

#tblEquipos > thead > tr > th:nth-child(1),
#tblEquipos > tbody > .equipo-row > td:nth-child(1) {
    width: 26px !important;
    min-width: 0 !important;
}

#tblEquipos > thead > tr > th:nth-child(2),
#tblEquipos > tbody > .equipo-row > td:nth-child(2) {
    width: auto !important;
    min-width: 0 !important;
}

#tblEquipos > thead > tr > th:nth-child(3),
#tblEquipos > tbody > .equipo-row > td:nth-child(3) {
    width: 82px !important;
    min-width: 0 !important;
}

#tblEquipos > thead > tr > th:nth-child(4),
#tblEquipos > tbody > .equipo-row > td:nth-child(4) {
    width: 40px !important;
    min-width: 0 !important;
}

#tblEquipos > thead > tr > th:nth-child(5),
#tblEquipos > tbody > .equipo-row > td:nth-child(5) {
    width: 36px !important;
    min-width: 0 !important;
}

#tblEquipos > tbody > .formulario-row > td {
    width: auto !important;
}

#tblEquipos .select-equipo-dinamico {
    min-width: 0 !important;
    height: 40px;
    padding-right: 22px;
    overflow: hidden;
    text-overflow: ellipsis;
}

#tblEquipos .input-horometro {
    min-width: 0 !important;
    height: 40px;
    padding-right: 4px;
    padding-left: 4px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

#tblEquipos > tbody > .equipo-row > td:nth-child(3) .input-group {
    width: 100%;
    flex-wrap: nowrap;
}

#tblEquipos > tbody > .equipo-row > td:nth-child(3) .input-group::before {
    content: "";
    flex: 0 0 20px;
    height: 40px;
    border: 1px solid #ced4da;
    border-right: 0;
    border-radius: 0.2rem 0 0 0.2rem;
    background-color: #f8f9fa;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%236c757d' d='M12 4a10 10 0 0 0-10 10h3a7 7 0 0 1 14 0h3A10 10 0 0 0 12 4zm1 9.6 4-4-1.4-1.4-4.6 4.6V15h2v-1.4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 13px 13px;
}

#tblEquipos .toggle-elegante-container {
    display: flex;
    justify-content: center;
}

#tblEquipos .toggle-switch-elegante {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e9ecef;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.14);
}

#tblEquipos .toggle-switch-elegante.disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

#tblEquipos .toggle-switch-elegante.enabled {
    background: #d4edda;
    color: #155724;
}

#tblEquipos .toggle-switch-elegante.active {
    background: #28a745;
    box-shadow: 0 0 0 3px rgba(40,167,69,0.22);
}

#tblEquipos .toggle-knob {
    position: relative;
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    color: #495057;
    font-size: 0.95rem;
}

#tblEquipos .toggle-switch-elegante.active .toggle-knob {
    color: #fff;
}

#tblEquipos .toggle-knob > .fas::before {
    content: "\f085";
    font-family: "Font Awesome 6 Free", "Font Awesome 5 Free";
    font-weight: 900;
}

#tblEquipos .format-type-indicator {
    position: absolute;
    top: -4px;
    right: -4px;
    display: flex;
    width: 16px;
    height: 16px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF9800, #E65100);
    color: #fff;
    font-size: 0.58rem;
    font-weight: 700;
    line-height: 1;
}

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

#tblEquipos .btn-remove-equipo {
    width: 30px !important;
    height: 30px !important;
}

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

.formato-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
}

.formato-titulo {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    font-size: clamp(0.78rem, 3.5vw, 0.92rem);
    font-weight: 700;
}

.formato-titulo span {
    overflow-wrap: anywhere;
}

.formato-badge {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.formato-contenido .table-responsive,
.formato-dinamico-container .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;
}

.formato-contenido {
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.formato-contenido table,
.formato-dinamico-container table {
    font-size: clamp(0.72rem, 3vw, 0.82rem);
}

.formato-contenido table[style*='min-width'],
.formato-dinamico-container table[style*='min-width'] {
    min-width: 800px !important;
}

.formato-contenido td,
.formato-contenido th,
.formato-dinamico-container td,
.formato-dinamico-container th {
    padding: 4px;
}

.formato-contenido .form-control-sm,
.formato-dinamico-container .form-control-sm {
    min-height: 34px;
    padding: 4px 6px;
    font-size: 0.82rem !important;
}

/* Ajuste para tabs con texto en móvil */
#rsf-tabs .nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    padding: 7px 2px;
    font-size: clamp(0.62rem, 2.9vw, 0.7rem);
    line-height: 1.2;
}
#rsf-tabs .nav-link i {
    font-size: clamp(1rem, 4.8vw, 1.2rem);
    margin-bottom: 2px;
}
#rsf-tabs .nav-link .tab-label {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#rsf-tabs .nav-link .badge {
    font-size: 0.6rem;
    margin-left: 0 !important;
    margin-top: 2px;
}

@media (max-width: 380px) {
    .mobile-tab-content {
        padding: 10px 8px calc(86px + env(safe-area-inset-bottom));
    }

    .mobile-form .card-body {
        padding: 10px;
    }

    #tblEquipos th,
    #tblEquipos td {
        padding-right: 2px;
        padding-left: 2px;
    }

    #tblEquipos .select-equipo-dinamico,
    #tblEquipos .input-horometro {
        height: 38px;
    }

    #tblEquipos > tbody > .equipo-row > td:nth-child(3) .input-group::before {
        height: 38px;
        flex-basis: 18px;
        background-size: 12px 12px;
    }

    #tblEquipos .toggle-switch-elegante {
        width: 34px;
        height: 34px;
    }

    #tblEquipos [id^='toggle-text-'] {
        display: none !important;
    }

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

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

    #rsf-tabs .nav-link {
        padding-right: 1px;
        padding-left: 1px;
    }

    .mobile-action-bar {
        gap: 4px !important;
    }

    .mobile-action-bar .btn {
        padding-right: 2px !important;
        padding-left: 2px !important;
    }
}
