/* ============================================================
   RESPONSIVE PERSONALIZADO — SOLO CELULAR
   ============================================================ */

@media (max-width: 768px) {

    .d-flex {
        flex-wrap: wrap !important;
    }

    /* Header móvil */
    .header-mobile-stack,
    .header-mobile-stack~.p-2.ms-auto,
    .header-mobile-stack * {
        flex-wrap: nowrap !important;
    }

    .header-mobile-stack,
    .header-mobile-badges {
        width: 100% !important;
        margin-bottom: 12px !important;
    }

    .header-mobile-stack {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        padding: 8px 0 !important;
        font-size: 0.9rem !important;
        line-height: 1.3 !important;
    }

    .header-mobile-info {
        width: 100% !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 10px !important;
    }

    .header-mobile-stack .badge {
        font-size: 0.78rem !important;
        padding: 5px 10px !important;
        line-height: 1.2 !important;
        white-space: nowrap !important;
    }

    .header-mobile-stack a[href="#myProfile"] {
        font-size: 0.85rem !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        white-space: nowrap !important;
    }

    .p-2.ms-auto {
        width: 100% !important;
        display: flex !important;
        justify-content: flex-end !important;
        align-items: center !important;
        padding-top: 4px !important;
    }

    .p-2.ms-auto a {
        font-size: 1.3rem !important;
        display: inline-flex !important;
        align-items: center !important;
        white-space: nowrap !important;
    }

    /* Corrección de columnas */
    .col-lg-12.col-12.mb-3.position-relative {
        display: block !important;
        width: 100% !important;
    }

    /* Botones de órdenes */
    .order-buttons {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        width: 100% !important;
        margin-top: 10px !important;
    }

    .order-buttons .btn {
        width: 75% !important;
        display: block !important;
        margin-bottom: 6px !important;
    }

    .order-buttons .btn:last-child {
        margin-bottom: 0 !important;
    }

    .orderpurch-buttons {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
    }

    .orderpurch-buttons>* {
        margin-bottom: 14px !important;
    }

    .orderpurch-buttons>*:last-child {
        margin-bottom: 0 !important;
    }

    .orderpurch-buttons .btn {
        width: 100% !important;
        display: block !important;
        margin: 0 !important;
    }

    /* Fila de 4 campos */
    .row.mb-2 .col-3:nth-child(1),
    .row.mb-2 .col-3:nth-child(2) {
        width: 50% !important;
        flex: 0 0 50% !important;
    }

    .row.mb-2 .col-3:nth-child(3),
    .row.mb-2 .col-3:nth-child(4) {
        width: 100% !important;
        flex: 0 0 100% !important;
    }

    .row.mb-2 .col-3 {
        margin-bottom: 14px !important;
    }

    .row.mb-2 .form-control {
        font-size: 0.9rem !important;
        padding: 10px 12px !important;
    }

    .row.mb-2 .select2-selection {
        min-height: 42px !important;
        padding-top: 6px !important;
        padding-bottom: 6px !important;
        font-size: 0.9rem !important;
        display: flex !important;
        align-items: center !important;
    }

    .row.mb-2 label.mb-1 {
        margin-bottom: 4px !important;
        font-size: 0.85rem !important;
    }

    .row.mb-2 .bi-calendar {
        font-size: 1rem !important;
        right: 10px !important;
    }

    #observationOrderpurch {
        font-size: 0.9rem !important;
        padding: 10px 12px !important;
    }

    /* Botón pequeño */
    .small-action-btn {
        font-size: 0.75rem !important;
        padding: 4px 8px !important;
        margin-top: 2px !important;
        float: none !important;
        display: inline-block !important;
    }

    .label-with-button {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        width: 100% !important;
    }

    .select2+.select2 {
        margin-top: 6px !important;
    }

    /* Producto móvil */
    .product-row-mobile .col-10,
    .product-row-mobile .col-2 {
        width: 100% !important;
        flex: 0 0 100% !important;
    }

    .product-row-mobile .col-2 {
        margin-top: 6px !important;
    }

    .product-row-mobile .add-btn-mobile {
        width: 100% !important;
        font-size: 0.9rem !important;
        padding: 10px !important;
    }

    /* ============================================================
       SOLO CELULAR: Productos Añadidos / Cantidades / Limpiar
       ============================================================ */

    .product-summary {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        margin-top: 10px !important;
    }

    .product-summary-line1 {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        font-size: 0.95rem !important;
        margin-bottom: 6px !important;
    }

    .product-summary-line2 {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        font-size: 0.95rem !important;
    }

    #cleanListProductpurch {
        font-size: 0.9rem !important;
        margin-left: 12px !important;
    }

    .product-label-row {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    /* ============================================================
       TABLA DETALLE DE PRODUCTOS (Ajustes, Compras y Ventas) RESPONSIVE
       ============================================================ */
    .table-responsive {
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
        border-radius: 6px;
    }

    .table-responsive .table {
        min-width: 580px;
        /* Garantiza legibilidad sin deformar las columnas en celulares */
        margin-bottom: 0;
    }

    .table-responsive .table th {
        font-size: 0.78rem !important;
        white-space: nowrap !important;
        padding: 0.5rem 0.35rem !important;
    }

    .table-responsive .table td {
        padding: 0.4rem 0.35rem !important;
        vertical-align: middle !important;
    }

    .table-responsive .table td img {
        width: 50px !important;
        height: 50px !important;
    }

    .table-responsive .table td div div.ms-2,
    .table-responsive .table td .float-start.ms-2 {
        max-width: 150px;
        white-space: normal;
        word-break: break-word;
    }

    .table-responsive .table td h6 {
        font-size: 0.8rem !important;
        line-height: 1.25 !important;
        margin-bottom: 2px !important;
        word-break: break-word;
    }

    .table-responsive .table td small {
        font-size: 0.72rem !important;
        line-height: 1.1 !important;
        display: block;
    }

    /* ============================================================
       MODALES DE BÚSQUEDA — MODO CELULAR (TABLE-TO-CARD UNIVERSAL)
       Formato Card para móviles idéntico a AppIC / appic
       ============================================================ */
    .modal[id*="Search"] .modal-dialog,
    .modal[id*="search"] .modal-dialog,
    .modal-dialog-search {
        margin: 0.5rem auto !important;
        max-width: 98vw !important;
        width: 98% !important;
    }

    .modal[id*="Search"] .modal-body,
    .modal[id*="search"] .modal-body {
        padding: 0.75rem !important;
    }

    .modal[id*="Search"] .table-responsive,
    .modal[id*="search"] .table-responsive {
        overflow-x: hidden !important;
        border: none !important;
        background: transparent !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    .modal[id*="Search"] table thead,
    .modal[id*="search"] table thead {
        display: none !important;
    }

    .modal[id*="Search"] table,
    .modal[id*="search"] table,
    .modal[id*="Search"] .table-responsive .table,
    .modal[id*="search"] .table-responsive .table,
    .modal[id*="Search"] table tbody,
    .modal[id*="search"] table tbody {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    .modal[id*="Search"] table tbody tr,
    .modal[id*="search"] table tbody tr,
    .card-search-item {
        display: flex !important;
        flex-direction: column !important;
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 14px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
        margin-bottom: 12px !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        transition: border-color 0.2s ease, box-shadow 0.2s ease;
    }

    .modal[id*="Search"] table tbody tr:active,
    .modal[id*="Search"] table tbody tr:hover,
    .card-search-item:active,
    .card-search-item:hover {
        border-color: #cbd5e1 !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
    }

    .card-s-mobile-header {
        display: block !important;
        background-color: #f8fafc !important;
        border-bottom: 1px solid #e2e8f0 !important;
        padding: 12px 14px !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        font-weight: 600 !important;
    }

    /* Anular anchos fijos de escritorio en celdas para evitar cuadros o huecos en blanco a la derecha */
    .card-search-item>td,
    .modal[id*="Search"] table tbody tr td,
    .modal[id*="search"] table tbody tr td {
        max-width: 100% !important;
        min-width: 0 !important;
        width: 100% !important;
    }

    /* Ocultar columna índice # en móvil */
    .card-search-item>td:first-child:not(.card-s-mobile-header)[data-label="#"],
    .card-search-item>td:first-child:not(.card-s-mobile-header):not([data-label]) {
        display: none !important;
    }

    .card-s-field,
    .modal[id*="Search"] table tbody tr td.card-s-field,
    .modal[id*="search"] table tbody tr td.card-s-field {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 8px 14px !important;
        border-bottom: 1px solid #f1f5f9 !important;
        width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        text-align: right !important;
        font-size: 0.84rem !important;
        white-space: normal !important;
        gap: 10px !important;
    }

    .card-s-field::before,
    .modal[id*="Search"] table tbody tr td.card-s-field::before,
    .modal[id*="search"] table tbody tr td.card-s-field::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.72rem;
        color: #64748b;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        text-align: left;
        margin-right: 8px;
        flex-shrink: 0;
        max-width: 48% !important;
    }

    /* Contenido/valor dentro de la celda siempre visible y auto-ajustado */
    .card-s-field>*,
    .modal[id*="Search"] table tbody tr td.card-s-field>*,
    .modal[id*="search"] table tbody tr td.card-s-field>* {
        max-width: 60% !important;
        text-align: right !important;
        white-space: normal !important;
        word-break: break-word !important;
        margin-left: auto !important;
    }

    .modal[id*="Search"] table tbody tr td:not(.card-s-actions):not(.card-s-mobile-header):not(.card-s-field),
    .modal[id*="search"] table tbody tr td:not(.card-s-actions):not(.card-s-mobile-header):not(.card-s-field) {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 8px 14px !important;
        border-bottom: 1px solid #f1f5f9 !important;
        width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        text-align: right !important;
        font-size: 0.84rem !important;
        white-space: normal !important;
        gap: 10px !important;
    }

    .modal[id*="Search"] table tbody tr td:not(.card-s-actions):not(.card-s-mobile-header):not(.card-s-field)::before,
    .modal[id*="search"] table tbody tr td:not(.card-s-actions):not(.card-s-mobile-header):not(.card-s-field)::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.72rem;
        color: #64748b;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        text-align: left;
        margin-right: 8px;
        flex-shrink: 0;
        max-width: 48% !important;
    }

    .col-audit-cell,
    [data-label*="Creado"],
    [data-label*="creado"],
    [data-label*="Modificac"],
    [data-label*="modificac"],
    [data-label*="Última mod"],
    [data-label*="Ultima mod"],
    [data-label*="Fecha mod"],
    [data-label*="Fecha Mod"] {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
    }

    .modal[id*="Search"] table tbody tr td:last-child,
    .modal[id*="search"] table tbody tr td:last-child,
    .card-s-actions {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        position: static !important;
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        right: auto !important;
        box-shadow: none !important;
        background-color: #f8fafc !important;
        border-top: 1px solid #e2e8f0 !important;
        border-bottom: none !important;
        padding: 10px 14px !important;
        box-sizing: border-box !important;
        overflow: visible !important;
    }

    .card-s-actions .btn,
    .modal[id*="Search"] table tbody tr td:last-child .btn,
    .modal[id*="search"] table tbody tr td:last-child .btn {
        padding: 6px 12px !important;
        font-size: 0.85rem !important;
    }

    .card-s-actions>div,
    .modal[id*="Search"] table tbody tr td:last-child>div,
    .modal[id*="search"] table tbody tr td:last-child>div {
        width: auto !important;
        display: inline-flex !important;
        gap: 6px !important;
        justify-content: flex-end !important;
        overflow: visible !important;
    }

    #searchModalImagePreviewFloating {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
}

@media (min-width: 769px) {

    .product-summary {
        display: block !important;
        width: 100% !important;
        margin: 10px 0 !important;
    }

    .product-summary-line1,
    .product-summary-line2 {
        display: inline-flex !important;
        align-items: center !important;
        gap: 6px !important;
        margin: 0 !important;
        padding: 0 !important;
        vertical-align: middle !important;
    }

    .product-summary-line2 {
        float: right !important;
    }
}