﻿@media (max-width: 992px) {
    /*BOTONES*/
    .btn {
        padding: 2px !important;
        font-size: 14px !important;
    }
    .btn-header-white {
        padding: 2px !important;
        font-size: 10px !important;
    }
    /*FORMULARIO*/
    .form-control {
        font-size: 14px !important;
    }
    label {
        font-size: 15px;
        color: #27436e;
        margin-bottom: 0px;
        margin-top: 0px;
    }
    .error {
        font-size: 12px;
    }
    /*ICONOS*/
    .icon {
        margin: 0px !important;
        padding-inline: 2px !important;
    }
}

@media (max-width: 768px) {
    /*HEADER*/
    .navbar-toggler {
        display: block;
    }

    .navbar-menu {
        position: absolute;
        top: 70px;
        left: 0;
        right: 0;
        flex-direction: column;
        background-color: #343a40;
        display: none;
    }

        .navbar-menu.show {
            display: flex;
        }

    .navbar-nav {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem 0;
    }
    /*BOTONES*/
    .btn {
        padding: 2px !important;
        font-size: 12px !important;
    }
    /*FORMULARIO*/
    .form-control {
        font-size: 12px !important;
    }
    label {
        font-size: 13px;
        color: #27436e;
        margin-bottom: 0px;
        margin-top: 0px;
    }
    .error {
        font-size: 11px;
    }

    /*CALENDARIO*/
    .calendar-day-title {
        font-size: 8px;
        padding: 4px !important;
    }

    .calendar-day {
        padding: 0px !important;
    }
}

@media (max-width: 576px) {
    /*BOTONES*/
    .btn {
        padding: 2px !important;
        font-size: 10px !important;
    }
    /*FORMULARIO*/
    .form-control {
        font-size: 10px !important;
    }
    label {
        font-size: 11px;
        color: #27436e;
        margin-bottom: 0px;
        margin-top: 0px;
    }
    .error {
        font-size: 10px;
    }
}

@media (max-width: 992px) {

    .card-header-obras {
        margin:0px;
        padding:0px;
    }

    body {
        font-size: 10px;
    }

    .logo-layout {
        height: 40px !important;
        margin: 0rem;
    }

    .navbar-toggler-icon {
        height: 20px !important;
        color: white !important;
    }

    .navbar-toggler {
        height: 30px !important;
        width: 60px !important;
        color: white !important;
    }

    h3 {
        font-size: 20px;
    }

    .container {
        margin-top: 0px !important;
        padding-top: 0px !important;
    }

    .titulo-filtro {
        margin-top: 0px !important;
        padding-top: 0px !important;
    }

    .search-container {
        display: flex;
        justify-content: center;
    }

    .search-encargos {
        margin-top: 0px;
        width: 95%;
        height: 28px;
        font-size: 14px;
    }

    .card-encargo {
        padding-top: 7px;
        padding-bottom: 7px;
    }

    .card-header {
        padding-bottom: 0px !important;
        margin-bottom: 7px !important;
        margin-top: 0px !important;
        padding-top: 0px !important;
        margin-left: 0px !important;
        padding-left: 5px !important;
        font-size: 14px !important;
        margin-bottom: 8px;
    }

    .enunciadosEncargos {
        margin-top: 0px;
        font-size: 10px;
    }

    .valoresEncargos {
        font-size: 9px;
    }

    .text-truncate {
        max-width: 60%;
    }

    /* Botón de subir */
    #btnScrollTop {
        right: 8%;
        bottom: 6%;
    }

    #btnScrollTop > i {
        font-size: 1.75rem;
    }

    .header-title {
        font-size: 10px;
    }

    .header-right label {
        margin-top: 7px;
        font-size: 10px;
    }

    .select-gremio {
        padding: 2px 2px;
        font-size: 12px;
    }

    .btn-crearnota {
        padding: 2px 2px;
        font-size: 12px;
    }

    /* Título de sección subrayado */
    .filas-tablas-titulo {
        padding: 7px !important;
        font-size: 8px !important;
    }

    .filas-tablas {
        padding: 5px !important;
        font-size: 7px !important;
    }

    .section-title {
        font-size: 16px;
    }

    .info-col {
        flex: 0 0 100%;
    }


    .col-fecha {
        width: 20%;
    }

    .col-usuario {
        width: 3%;
    }

    .col-acciones {
        width: 3%;
    }

    .texto-tablas {
        font-size: 8px;
    }

    /*DETALLES ENCARGO*/
    /* Botón de subir */
    .btnBack {
        bottom: 1%;
    }
}

/* =========================================================
   RESPONSIVE TABLET + MOVIL - SIN CAMBIOS DE FUNCIONALIDAD
   ========================================================= */

/* Base: evita desbordes generales y mantiene las vistas trabajables */
* {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

img,
iframe,
canvas,
video {
    max-width: 100%;
}

main.container-fluid,
main.container {
    width: 100%;
}

.gap-2 {
    gap: .5rem !important;
}

/* Tablas: usable en tablet/movil sin cambiar estructura ni JS */
.table,
.tabla-notas,
.table-separada,
.tabla-semana,
.presu-lineas table {
    min-width: 760px;
}

.table-responsive,
.lineas-scroll,
.datos-scroll,
.card-body,
.encargo-body,
.body-notas,
.facturas,
.situacionesEncargo,
.dialogosEncargo,
.notasEncargo,
.modal-body,
#contenedorLista,
#contenidoGestionMovimientos,
#contenedorCalendario,
#contenedorTrabajos,
#contenedorActivos,
#contenedorInactivos,
#contenedorListaObras,
#contenedorListaUsuarios,
#contenedorListaPresupuestos {
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
}

.card-body:has(> table),
.encargo-body:has(table),
.body-notas:has(table),
.facturas:has(table),
.situacionesEncargo:has(table),
.dialogosEncargo:has(table),
.notasEncargo:has(table),
.presupuestos:has(table),
#contenedorLista:has(table),
#contenidoGestionMovimientos:has(table),
.modal-body:has(table) {
    overflow-x: auto;
    overflow-y: visible;
    max-width: 100%;
}

/* Fallback para navegadores sin :has: la tabla conserva su propio scroll horizontal. */
@media (max-width: 992px) {
    table:not(.month-calendar-detail table),
    .table:not(.month-calendar-detail .table),
    .tabla-notas,
    .table-separada,
    .tabla-semana {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }
}

/* El calendario no debe comportarse como una tabla de datos: cabe siempre en el ancho disponible. */
.month-calendar-detail {
    width: 100%;
    max-width: 100%;
}

.month-calendar-detail .table {
    display: table !important;
    overflow: visible !important;
    min-width: 0 !important;
    width: 100%;
    table-layout: fixed;
    margin-bottom: 0;
}

.month-calendar-detail th,
.month-calendar-detail td {
    width: 14.285%;
}

.month-calendar-detail .calendar-day-title,
.month-calendar-detail .calendar-day {
    min-width: 0 !important;
    max-width: none !important;
    word-break: break-word;
}

.month-calendar-detail .calendar-day .badge {
    display: block;
    width: 100%;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.view-detail-page {
    width: 100%;
    max-width: 100%;
}

.view-detail-title-row {
    align-items: center;
}

.view-detail-title {
    overflow-wrap: anywhere;
    line-height: 1.25;
}

/* Formularios y selects cómodos para dedo, evitando zoom iOS */
@media (max-width: 992px) {
    main.container-fluid,
    main.container {
        max-width: 100% !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    .container-fluid {
        overflow-x: hidden;
    }

    .form-control,
    .form-select,
    .bootstrap-select > .dropdown-toggle,
    input,
    select,
    textarea {
        min-height: 38px;
        font-size: 16px !important;
    }

    textarea.form-control {
        min-height: 72px;
    }

    .btn,
    button,
    .action-btn,
    .btn-header-white,
    .btn-crearnota,
    .select-gremio {
        min-height: 36px;
        line-height: 1.2;
        white-space: normal;
    }

    .icon,
    .fa-solid,
    .fa-regular {
        min-width: 28px;
        min-height: 28px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Cabeceras con acciones */
    .d-flex.justify-content-between,
    .card-header-obras,
    .card-header-encargo,
    .calendario-header,
    .presu-header,
    .header-avisos-encargo,
    .btn-obras-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .presu-header > div:last-child,
    .d-flex.justify-content-end,
    .btn-container,
    .btn-group-custom {
        flex-wrap: wrap;
        justify-content: flex-start !important;
    }

    h1, .h1 { font-size: 1.65rem; }
    h2, .h2 { font-size: 1.45rem; }
    h3, .h3 { font-size: 1.25rem; }
    h4, .h4 { font-size: 1.1rem; }

    /* Listados tipo tarjeta */
    .card-custom,
    .card-encargo,
    .job-card {
        padding: 12px !important;
    }

    .btn-group-custom {
        position: static;
        transform: none;
        margin-top: 10px;
        gap: 8px;
    }

    .text-truncate {
        max-width: 100% !important;
        display: inline-block;
    }

    /* Detalles de encargos/obras/usuarios/clientes */
    .encargo-header {
        align-items: flex-start;
        gap: 8px;
    }

    .header-left,
    .header-right {
        width: 100%;
    }

    .header-right {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }

    .view-detail-page .encargo-header {
        justify-content: space-between;
        padding: 6px 8px;
        min-height: auto;
    }

    .view-detail-page .encargo-header .header-left {
        display: flex !important;
        width: auto;
        flex: 0 0 auto;
        align-self: center;
    }

    .view-detail-page .encargo-header .header-right {
        width: auto;
        max-width: 100%;
        margin-left: auto;
        justify-content: flex-end;
        gap: 5px;
    }

    .view-detail-page .encargo-header .header-right label {
        display: none !important;
    }

    .view-detail-page .encargo-header .header-title {
        display: inline !important;
        margin-right: 5px;
        font-size: 14px;
        line-height: 1.15;
        white-space: nowrap;
    }

    .view-detail-page .encargo-header .btn-header-white {
        flex: 0 0 auto;
        width: auto;
        min-height: 30px;
        padding: 4px 7px;
        font-size: 11px !important;
        line-height: 1.15;
        white-space: nowrap;
    }

    .view-detail-page .encargo-header .select-gremio {
        flex: 0 1 auto;
        width: auto;
        max-width: 42vw;
        min-height: 30px;
        padding: 3px 6px !important;
        font-size: 11px !important;
    }

    .view-detail-page .encargo-detalle-resumen .encargo-detalle-toolbar {
        flex-wrap: nowrap;
        gap: 4px;
    }

    .view-detail-page .encargo-detalle-resumen .encargo-detalle-acciones {
        flex: 1 1 auto;
        flex-wrap: nowrap;
        min-width: 0;
        gap: 4px;
    }

    .view-detail-page .encargo-detalle-resumen .encargo-accion {
        width: 30px;
        min-width: 30px;
        min-height: 30px;
        padding: 0;
    }

    .view-detail-page .encargo-detalle-resumen .encargo-gremio-control {
        flex: 1 1 72px;
        min-width: 0;
    }

    .view-detail-page .encargo-detalle-resumen .encargo-gremio-control .select-gremio {
        width: 100%;
        min-width: 0;
        max-width: none;
    }

    .info-line {
        gap: 0;
    }

    .info-col,
    .info-col-large {
        flex: 0 0 50% !important;
        max-width: 50% !important;
        word-break: break-word;
    }

    .archivo-visor {
        height: min(55vh, 460px);
    }

    /* Modales: ocupan mejor la pantalla */
    .modal-dialog,
    .modal-lg,
    .modal-xl {
        max-width: calc(100vw - 20px) !important;
        margin: 10px auto !important;
    }

    .modal-regal .modal-body,
    .modal-body {
        max-height: calc(100vh - 140px);
        overflow-y: auto;
        padding: 1rem;
    }

    .modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Calendario mensual/semanal */
    .month-tile,
    .month-tile-selected {
        padding: 8px 10px;
        min-width: 72px;
    }

    .calendar-day-title,
    .calendar-day {
        min-width: 42px;
        max-width: none !important;
    }

    .month-calendar-detail .calendar-day-title,
    .month-calendar-detail .calendar-day {
        min-width: 0 !important;
    }

    .calendar-day {
        height: 3.5rem !important;
        overflow: hidden;
    }

    .tabla-semana,
    .calendario-header + div,
    #calendario,
    #contenedorCalendario {
        overflow-x: auto;
    }

    /* Editores de presupuesto y factura */
    .presu-editor {
        height: auto !important;
        min-height: calc(100vh - 120px);
        overflow: visible;
    }

    .presu-body {
        display: grid;
        grid-template-columns: 1fr !important;
        gap: 14px;
        overflow: visible;
    }

    .presu-datos,
    .presu-lineas,
    .datos-scroll,
    .lineas-scroll {
        height: auto !important;
        max-height: none;
        overflow: visible;
    }

    .lineas-scroll {
        overflow-x: auto;
        overflow-y: visible;
        max-width: 100%;
    }

    .presu-lineas table {
        min-width: 980px;
    }

    .totales-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .t-item {
        padding: 10px;
    }

    /* Remesas/movimientos con alturas fijas */
    [style*="height: calc(100vh - 280px)"] {
        height: auto !important;
        min-height: 0 !important;
    }
}

@media (max-width: 768px) {
    body {
        font-size: 14px !important;
    }

    header .navbar {
        margin-bottom: .5rem !important;
    }

    .navbar-nav {
        gap: .25rem;
    }

    .navbar-nav .nav-link {
        padding: .55rem .75rem;
        border-top: 1px solid rgba(255,255,255,.08);
    }

    main.container-fluid,
    main.container {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

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

    .row > [class*="col-"] {
        padding-left: 6px;
        padding-right: 6px;
    }

    /* En móvil los formularios pasan a una columna útil */
    .row > .col,
    .row > .col-auto,
    .row > [class*="col-md-"],
    .row > [class*="col-lg-"],
    .row > [class*="col-xl-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .row > .col-6:not(.keep-mobile-half),
    .row > .col-5:not(.keep-mobile-half),
    .row > .col-4:not(.keep-mobile-half),
    .row > .col-3:not(.keep-mobile-half),
    .row > .col-2:not(.keep-mobile-half),
    .row > .col-1:not(.keep-mobile-half) {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .row > .col-11 + .col-1,
    .row > .col-10 + .col-2 {
        flex: 0 0 auto;
        max-width: none;
    }

    .view-detail-title-row > .col-2 {
        display: none;
    }

    .view-detail-title-row > .col-8,
    .view-detail-title-row > .col {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .d-flex,
    .presu-header > div:last-child {
        min-width: 0;
    }

    .d-flex.justify-content-between.align-items-center.mb-3,
    .card-header-obras,
    .card-header-encargo {
        align-items: stretch !important;
    }

    .d-flex.justify-content-between.align-items-center.mb-3 > *,
    .card-header-obras > *,
    .card-header-encargo > * {
        width: 100%;
    }

    .btn,
    .btn-header-white,
    .btn-crearnota,
    .select-gremio {
        width: auto;
        min-height: 40px;
        padding: 8px 10px !important;
        font-size: 14px !important;
    }

    .btn-container .btn,
    .presu-header .btn,
    .modal-footer .btn,
    .card-header-obras .btn,
    .card-header-encargo .btn {
        flex: 1 1 140px;
    }

    .search-container,
    .search-encargos {
        width: 100% !important;
    }

    .search-encargos {
        height: 40px;
    }

    .card-header {
        font-size: 1rem !important;
        line-height: 1.25;
    }

    .info-col,
    .info-col-large {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        padding: 4px 0;
    }

    .section-title {
        margin-top: 18px;
        font-size: 18px;
    }

    .encargo-body,
    .body-notas {
        padding: 10px;
    }

    .col-fecha,
    .col-usuario,
    .col-acciones {
        width: auto !important;
    }

    .trabajos-actions-cell {
        width: 1% !important;
        min-width: max-content;
        white-space: nowrap !important;
    }

    .trabajos-acciones {
        display: inline-flex !important;
        flex-wrap: nowrap !important;
        align-items: center;
        justify-content: flex-start;
        gap: .25rem;
        white-space: nowrap !important;
    }

    .trabajos-acciones .icon {
        flex: 0 0 auto;
        min-width: 24px !important;
        min-height: 24px !important;
        padding-inline: 1px !important;
    }

    .filas-tablas,
    .filas-tablas-titulo,
    .filas-tablas-dialogos {
        font-size: 12px !important;
        padding: 8px !important;
    }

    .table,
    .tabla-notas,
    .table-separada,
    .tabla-semana {
        min-width: 680px;
    }

    .presu-lineas table {
        min-width: 920px;
    }

    .totales-grid {
        grid-template-columns: 1fr !important;
    }

    .presu-totales {
        padding: 8px;
    }

    .t-row {
        gap: 8px;
    }

    .modal-header-custom,
    .modal-regal .modal-header {
        padding: .65rem 2.5rem .65rem .75rem;
    }

    .modal-regal .modal-title {
        font-size: .95rem;
    }

    .archivo-visor {
        height: 45vh;
    }

    #canvasFirma {
        height: 220px;
    }

    #btnScrollTop,
    .btnBack {
        bottom: 12px !important;
        z-index: 1050;
    }

    #btnScrollTop {
        right: 12px !important;
    }

    .btnBack {
        left: 12px !important;
    }
}

@media (max-width: 576px) {
    body {
        font-size: 13px !important;
    }

    .logo-layout {
        height: 36px !important;
    }

    h3,
    .h3 {
        font-size: 1.15rem !important;
    }

    .btn,
    .btn-header-white,
    .btn-crearnota,
    .select-gremio {
        font-size: 13px !important;
    }

    .form-control,
    .form-select,
    .bootstrap-select > .dropdown-toggle,
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    .card,
    .card-custom,
    .encargo-container,
    .job-card {
        border-radius: 8px;
    }

    .card-body,
    .modal-body {
        padding: .75rem;
    }

    .calendar-day-title,
    .calendar-day {
        min-width: 36px;
        font-size: 11px !important;
    }

    .month-calendar-detail .calendar-day-title,
    .month-calendar-detail .calendar-day {
        min-width: 0 !important;
        padding-left: 2px !important;
        padding-right: 2px !important;
    }

    .calendar-day {
        height: 3rem !important;
    }

    .month-calendar-detail .calendar-day {
        height: 4.25rem !important;
        font-size: 11px !important;
    }

    .month-calendar-detail .calendar-day .badge {
        font-size: 9px;
        padding: 2px 3px;
        white-space: nowrap;
    }

    .month-tile,
    .month-tile-selected {
        min-width: 58px;
        padding: 7px 8px;
        font-size: 12px !important;
    }

    .table,
    .tabla-notas,
    .table-separada,
    .tabla-semana {
        min-width: 620px;
    }

    .presu-lineas table {
        min-width: 880px;
    }

    .t-label {
        font-size: 11px;
    }

    .t-value {
        font-size: 15px;
    }
}

/* Bootstrap puede reducir de nuevo los search con form-control-sm. */
@media (max-width: 992px) {
    input[type="search"],
    input[type="search"].form-control,
    input[type="search"].form-control-sm,
    .bootstrap-select .bs-searchbox input,
    .bootstrap-select .bs-searchbox .form-control,
    .select2-container .select2-search__field {
        font-size: 16px !important;
        -webkit-text-size-adjust: 100%;
    }
}

/* En pantallas estrechas el documento se desplaza dentro de su propia superficie. */
@media (max-width: 992px) {
    body.document-editor-page {
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        overflow: hidden !important;
    }

    .document-editor-page .layout-main {
        width: 100% !important;
        max-width: 100% !important;
        height: calc(100vh - 1.9rem);
        height: calc(100dvh - 1.9rem);
        min-height: 0;
        overflow: hidden !important;
    }

    .document-editor-page .document-editor.presu-editor {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        min-height: 0 !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
    }

    .document-editor-page .document-editor .presu-body {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 auto;
        min-height: 0;
    }

    .document-editor-page .presu-datos,
    .document-editor-page .presu-lineas {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 0 .75rem !important;
    }

    .document-editor-page .datos-scroll {
        overflow-x: hidden !important;
    }

    .document-editor-page .lineas-scroll {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .document-editor-page .presu-datos > .card-body {
        width: 100% !important;
        padding: .75rem !important;
    }

    .document-editor-page .presu-header {
        width: 100%;
        max-width: 100%;
    }

    .document-editor-page .presu-header > .d-flex {
        width: 100%;
    }

    .document-editor-page .presu-header .btn {
        flex: 1 1 9rem;
        margin-inline: 0 !important;
    }
}

@media (max-width: 420px) {
    .document-editor-page .presu-header .btn {
        flex-basis: calc(50% - .25rem);
    }

    .document-editor-page .presu-datos > .card-body {
        padding: .65rem !important;
    }

}

/* Tablet y navegadores móviles con viewport de escritorio: evita mezclar
   la tipografía móvil reducida con la rejilla de escritorio. */
@media (min-width: 769px) and (max-width: 1099.98px) {
    body {
        font-size: 16px;
    }

    .layout-main {
        padding-top: 5.25rem !important;
        padding-right: 1.25rem !important;
        padding-left: 1.25rem !important;
    }

    .layout-actions-list > .nav-item {
        display: flex;
        align-items: center;
        height: 3.25rem;
        line-height: 1;
    }

    .layout-actions-list .layout-menu-toggle,
    .layout-actions-list .layout-action-button,
    .layout-actions-list #btnNotificationsBell {
        flex: 0 0 3.25rem;
        width: 3.25rem;
        height: 3.25rem;
        margin-block: 0 !important;
        font-size: 1.05rem !important;
    }

    .titulo-filtro {
        font-size: 1.5rem;
    }

    .search-encargos,
    .form-control {
        min-height: 2.75rem;
        font-size: 16px !important;
    }

    .btn-container {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: .65rem;
    }

    .btn-container .filter-btn {
        min-height: 2.75rem;
        padding: .55rem .7rem !important;
        font-size: 15px !important;
        white-space: normal;
    }

    .encargos-select-filters .btn,
    .encargos-count-summary {
        min-height: 2.75rem;
        font-size: 15px !important;
    }

    .gestion-card-grid.encargos-card-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 1rem;
    }

    .encargos-card-grid .card-custom {
        padding: 1rem !important;
    }

    .encargos-card-grid .card-header {
        font-size: 1.1rem !important;
    }

    .encargos-card-grid .card-enunciados,
    .encargos-card-grid .card-encargos {
        font-size: .9rem;
        line-height: 1.4;
    }
}
