/* =============================================================
   Tennis Vic - Ajustes responsive globales para Backpack/Tabler.
   Mobile-first: optimizado para uso en tablet y movil por
   tecnicos en pista.
   ============================================================= */

/* ---------- Cabeceras de operacion (list/show/edit) ---------- */
.header-operation {
    flex-wrap: wrap !important;
    gap: 8px;
    align-items: center !important;
}
.header-operation [bp-section="page-heading"] {
    min-width: 0;
    word-break: break-word;
    font-size: 1.4rem;
    line-height: 1.25;
}
@media (min-width: 768px) {
    .header-operation [bp-section="page-heading"] { font-size: 1.6rem; }
}

/* Botones de la cabecera y de acciones: tamano de tap minimo */
.header-operation .btn,
.header-operation .btn-group .btn {
    min-height: 38px;
}

/* ---------- Cards (formularios y show) ---------- */
.card .card-body { padding: 1rem; }
@media (min-width: 768px) {
    .card .card-body { padding: 1.25rem; }
}

/* Asegurar que las filas dentro de cards permitan respiracion en movil */
@media (max-width: 575.98px) {
    .card .card-body .row { --bs-gutter-y: 0.75rem; }
}

/* ---------- Form elements: tap-friendly en movil ---------- */
@media (max-width: 767.98px) {
    .form-control,
    .form-select,
    .select2-container--bootstrap-5 .select2-selection {
        min-height: 42px;
        font-size: 1rem; /* evita zoom de iOS al focus */
    }
    .form-control-sm { min-height: 38px; }
    textarea.form-control { min-height: 80px; }

    .btn { min-height: 40px; }
    .btn-sm { min-height: 36px; }
    .btn-xs { min-height: 32px; }
}

/* ---------- DataTables Responsive: boton + de expansion ----------
   Backpack inserta server-side un <div class="dtr-control"> al inicio de
   la primera columna. Por defecto se renderiza con un icono pequeno de
   tres puntos verticales que no comunica que es un control de expansion.
   Lo convertimos en un boton circular con "+" para que sea evidente. */
.crud-table > tbody > tr > td > div.dtr-control {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #0d6f5e;
    color: #fff;
    cursor: pointer;
    margin-right: 8px;
    vertical-align: middle;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: transform 0.15s, background 0.15s;
    flex-shrink: 0;
}
.crud-table > tbody > tr > td > div.dtr-control:hover {
    background: #095646;
    transform: scale(1.08);
}
.crud-table > tbody > tr > td > div.dtr-control.d-none {
    display: none !important;
}
/* Sobrescribe el icono nativo de Backpack (tres puntos) por un "+" claro */
.crud-table.dtr-none > tbody > tr > td > div.dtr-control:before {
    content: '+' !important;
    color: #fff !important;
    font-family: inherit !important;
    font-size: 1.15rem !important;
    font-weight: 700 !important;
    line-height: 1 !important;
    width: auto !important;
    margin: 0 !important;
    top: -1px !important;
    left: 0 !important;
}

/* Cuando una fila tiene los detalles abiertos, mostramos "−" */
.crud-table > tbody > tr.parent > td > div.dtr-control,
.crud-table > tbody > tr.dtr-expanded > td > div.dtr-control {
    background: #c0392b;
}
.crud-table.dtr-none > tbody > tr.parent > td > div.dtr-control:before,
.crud-table.dtr-none > tbody > tr.dtr-expanded > td > div.dtr-control:before {
    content: '−' !important;
}

/* Modal de detalles: mas legible y comodo de cerrar */
.dtr-modal {
    background: rgba(15, 23, 30, 0.55) !important;
}
.dtr-modal .dtr-modal-display {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    max-width: 540px;
    width: calc(100% - 24px);
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Reservamos espacio inferior para el boton "Tancar" sticky */
    padding-bottom: 64px !important;
}
.dtr-modal .dtr-modal-content {
    padding: 18px 14px 6px !important;
}
.dtr-modal .dtr-modal-content table {
    margin-bottom: 0;
}
.dtr-modal .dtr-modal-content table > tbody > tr > td:first-child {
    font-weight: 600;
    color: #455162;
    width: 38%;
    padding-right: 8px;
}

/* Boton de cierre (X) muy visible y tap-friendly */
.dtr-modal .dtr-modal-close {
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    width: 40px !important;
    height: 40px !important;
    line-height: 38px !important;
    text-align: center !important;
    border-radius: 50% !important;
    background: #fff !important;
    color: #455162 !important;
    font-size: 1.5rem !important;
    font-weight: 400 !important;
    border: 1px solid #e3e6ea !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12) !important;
    cursor: pointer !important;
    transition: background 0.15s, color 0.15s, transform 0.15s !important;
    z-index: 10 !important;
}
.dtr-modal .dtr-modal-close:hover,
.dtr-modal .dtr-modal-close:focus {
    background: #c0392b !important;
    color: #fff !important;
    border-color: #c0392b !important;
    transform: scale(1.05) !important;
    outline: none !important;
}

/* Boton "Tancar" sticky en la parte inferior del modal */
.dtr-modal .dtr-close-bar {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0 -14px -6px;
    padding: 10px 14px;
    background: #fff;
    border-top: 1px solid #e3e6ea;
    text-align: center;
    z-index: 5;
}
.dtr-modal .dtr-close-bar .btn {
    width: 100%;
    max-width: 320px;
    min-height: 44px;
    font-weight: 600;
}

/* Espaciado entre botones de accion dentro del modal */
.dtr-modal .dtr-modal-content table td .btn,
.dtr-modal .dtr-modal-content table td a.btn,
.dtr-modal .dtr-modal-content table td .btn-group {
    margin: 0 6px 6px 0;
    vertical-align: middle;
}
.dtr-modal .dtr-modal-content table td .btn:last-child {
    margin-right: 0;
}

/* Mobile: el modal ocupa toda la pantalla */
@media (max-width: 575.98px) {
    .dtr-modal .dtr-modal-display {
        border-radius: 0 !important;
        max-height: 100vh !important;
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
    }
    .dtr-modal .dtr-close-bar {
        margin-left: -14px;
        margin-right: -14px;
    }
}

/* ---------- DataTables (list operation) ---------- */
@media (max-width: 767.98px) {
    /* La barra superior de DataTables (search + length) debe stackear */
    .dataTables_wrapper .row:first-child > div {
        margin-bottom: 0.5rem;
    }

    /* Stack pagination + info verticalmente */
    .dataTables_wrapper .row:last-child {
        flex-direction: column;
        gap: 0.5rem;
    }
    .dataTables_wrapper .row:last-child > div {
        text-align: center;
        width: 100%;
    }
    .dataTables_paginate .pagination { justify-content: center; flex-wrap: wrap; }

    /* Botones agrupados arriba (export/create) */
    .dataTables_wrapper .dt-buttons {
        flex-wrap: wrap;
        gap: 4px;
    }
    .dataTables_wrapper .dt-buttons .btn { font-size: 0.85rem; }

    /* Search input mas alto */
    .dataTables_filter input { min-height: 40px; min-width: 0; width: 100%; }
    .dataTables_filter label { width: 100%; }
}

/* ---------- Filtros de Backpack ---------- */
@media (max-width: 767.98px) {
    .backpack-filters-form,
    #datatable_button_stack {
        gap: 6px;
    }
}

/* ---------- Modal: pantalla completa en movil ---------- */
@media (max-width: 575.98px) {
    .modal-dialog:not(.modal-fullscreen) {
        margin: 0;
        max-width: 100%;
        min-height: 100vh;
    }
    .modal-content { border-radius: 0; min-height: 100vh; }
    .modal-footer { flex-wrap: wrap; gap: 6px; }
    .modal-footer .btn { flex: 1 1 auto; }
}

/* ---------- SweetAlert botones tap-friendly ---------- */
@media (max-width: 575.98px) {
    .swal-modal { width: calc(100% - 32px); max-width: 420px; }
    .swal-button { padding: 10px 18px; font-size: 0.95rem; }
    .swal-footer { padding: 12px; }
}

/* ---------- Botones custom de fila (acciones) ----------
   En desktop salen en linea, en movil mejor con icono solo
   o etiqueta corta. Backpack usa dropdown en xs por defecto,
   pero si algun proyecto los muestra inline aplicamos esto. */
@media (max-width: 575.98px) {
    .crud-button-stack {
        flex-wrap: wrap;
        gap: 4px;
    }
}

/* ---------- Desplegable "Accions" de fila: apilar botones ----------
   Backpack convierte los botones nativos (btn-link) en dropdown-item
   (ya apilados), pero los botones con color (btn-info, btn-success...)
   quedan inline dentro del menu y se amontonan en filas. Forzamos que
   ocupen toda la fila para que salgan uno debajo de otro. */
.actions-buttons-column ~ .dropdown .dropdown-menu {
    min-width: 210px;
    padding: 6px;
}
.actions-buttons-column ~ .dropdown .dropdown-menu .btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    margin: 2px 0;
    text-align: left;
}

/* ---------- Tablas (envoltura responsive si falta) ---------- */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* ---------- Sidebar de Backpack: bloquear scroll horizontal en movil ---------- */
body { overflow-x: hidden; }

/* ---------- Print: mantener PDF render limpio ---------- */
@media print {
    .header-operation { display: none !important; }
}
