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

img,
video,
canvas,
svg {
    max-width: 100%;
    height: auto;
}

.form-control,
.form-select,
textarea,
input,
select,
button {
    max-width: 100%;
}

@media (max-width: 1199px) {
    body.has-sidebar .layout-page {
        margin-left: 0;
    }

    .sidebar {
        width: min(86vw, 320px);
        z-index: 1040;
    }

    .content-wrapper {
        padding: 1rem 0.85rem 1.35rem;
    }

    .top-navbar {
        padding-top: 0.65rem !important;
        padding-bottom: 0.65rem !important;
    }

    .top-navbar .ms-auto {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.45rem !important;
    }

    .top-navbar .btn {
        font-size: 0.8rem;
        padding: 0.38rem 0.58rem;
    }

    .top-navbar .nav-action-btn span {
        display: none;
    }

    .top-navbar .nav-action-btn {
        min-width: 2.2rem;
        justify-content: center;
    }
}

@media (max-width: 991px) {
    .container,
    .container-sm,
    .container-md,
    .container-lg,
    .container-xl,
    .container-xxl,
    .container-fluid {
        padding-right: 0.65rem;
        padding-left: 0.65rem;
    }

    .container-p-y {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    .row {
        --bs-gutter-x: 0.95rem;
    }

    .card .card-header,
    .card .card-body,
    .card .card-footer {
        padding-left: 0.85rem;
        padding-right: 0.85rem;
    }

    .card .card-header {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    .card .card-body,
    .card .card-footer {
        padding-top: 0.85rem;
        padding-bottom: 0.85rem;
    }

    .table-responsive,
    .listado-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        max-width: 100%;
    }

    .table-responsive .table thead th,
    .listado-table thead th {
        overflow-wrap: anywhere;
    }

    .table-responsive .table td,
    .table-responsive .table th,
    .listado-table td,
    .listado-table th {
        vertical-align: middle;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .table-responsive .table {
        min-width: 0;
        width: 100%;
    }

    .table td.d-flex,
    .table th.d-flex {
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: left !important;
        width: 100%;
    }

    .dataTables_wrapper .dataTables_filter {
        margin-top: 0.45rem;
    }

    .dataTables_wrapper .dataTables_filter label,
    .dataTables_wrapper .dataTables_length label {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.35rem;
    }

    .dataTables_wrapper .dataTables_filter input,
    .dataTables_wrapper .dataTables_length select {
        width: 100% !important;
        margin-left: 0 !important;
    }

    .dataTables_wrapper .dataTables_paginate {
        margin-top: 0.6rem;
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .modal-dialog {
        margin: 0.55rem;
    }

    .btn,
    .btn-sm {
        font-size: 0.82rem;
    }

    .form-control,
    .form-select,
    textarea,
    input,
    select {
        font-size: 16px;
    }
}

@media (max-width: 576px) {
    .content-wrapper {
        padding: 0.8rem 0.55rem 1rem;
    }

    .top-navbar .nav-role {
        display: none;
    }

    .top-navbar .ms-auto {
        width: 100%;
        justify-content: flex-start;
    }

    .top-navbar .btn {
        width: 100%;
    }

    .top-navbar .nav-action-btn span {
        display: inline;
    }

    .card .card-header {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .card .card-header .btn,
    .card .card-header .badge {
        width: 100%;
    }

    .breadcrumb,
    .pagination {
        flex-wrap: wrap;
        gap: 0.25rem;
    }
}

/* ── Listados → tarjetas apiladas en móvil ─────────────────────────
   Las tablas DataTables (.dt-cards-mobile, marcadas por
   esquema-datatables.js que también inyecta data-label en cada celda)
   se transforman en tarjetas para que no haya scroll lateral. */
@media (max-width: 767.98px) {
    table.dt-cards-mobile {
        display: block;
        width: 100% !important;
        max-width: 100% !important;
        table-layout: auto !important;
    }

    table.dt-cards-mobile > thead {
        display: none;
    }

    table.dt-cards-mobile > tbody,
    table.dt-cards-mobile > tfoot {
        display: block;
        width: 100%;
    }

    table.dt-cards-mobile > tbody {
        padding: 0.1rem 0;
    }

    table.dt-cards-mobile > tbody > tr {
        display: block;
        border: 1px solid rgba(139, 94, 60, 0.2);
        border-radius: 12px;
        background: #fff;
        padding: 0.55rem 0.8rem;
        margin-bottom: 0.7rem;
        box-shadow: 0 2px 8px rgba(47, 32, 22, 0.05);
    }

    table.dt-cards-mobile > tbody > tr:hover {
        background: #fffdf8;
    }

    table.dt-cards-mobile > tbody > tr > td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem 0.9rem;
        padding: 0.42rem 0 !important;
        border: 0;
        border-bottom: 1px dashed rgba(139, 94, 60, 0.16);
        text-align: right;
        width: 100%;
        overflow-wrap: anywhere;
        word-break: break-word;
        white-space: normal;
    }

    table.dt-cards-mobile > tbody > tr > td::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-size: 0.66rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #8a6a4a;
        margin-right: auto;
        text-align: left;
        min-width: 5.2rem;
        padding-right: 0.4rem;
    }

    table.dt-cards-mobile > tbody > tr > td:last-child {
        border-bottom: 0;
    }

    table.dt-cards-mobile > tbody > tr > td[colspan] {
        display: block;
        text-align: center;
        padding: 0.4rem 0 !important;
        border: 0;
    }

    table.dt-cards-mobile > tbody > tr > td[colspan]::before {
        content: none;
    }

    table.dt-cards-mobile > tfoot > tr {
        display: block;
        border: 1px solid rgba(139, 94, 60, 0.2);
        border-radius: 12px;
        background: #fbf3ea;
        padding: 0.45rem 0.8rem;
        margin-top: 0.25rem;
        text-align: right;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    table.dt-cards-mobile > tfoot > tr > td {
        display: inline-block;
        border: 0 !important;
        padding: 0.15rem 0.25rem !important;
        vertical-align: middle;
        white-space: normal;
        text-align: right;
    }

    table.dt-cards-mobile > tfoot > tr > td[data-tfoot-summary]::before {
        content: attr(data-label);
        font-size: 0.8rem;
        font-weight: 600;
        color: inherit;
        margin-right: 0.4rem;
    }

    table.dt-cards-mobile .listing-money,
    table.dt-cards-mobile .pedido-date {
        white-space: normal;
    }

    table.dt-cards-mobile .btn-group-action,
    table.dt-cards-mobile .pedido-actions {
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .listado-table-wrap:has(table.dt-cards-mobile),
    .table-responsive:has(table.dt-cards-mobile),
    .listado-table-wrap.wrap-cards,
    .table-responsive.wrap-cards {
        overflow: visible;
    }
}
