/**
 * SPVSMA — Patrones móviles reutilizables (presentación).
 * Teléfono ≤991px; tablet/escritorio conservan layout AdminLTE.
 */

@media (max-width: 991px) {
  body.spvsma-sm-theme {
    --sm-mobile-pad: 12px;
    --sm-mobile-field-h: 44px;
    --sm-mobile-footer-h: 56px;
  }

  /* ========== DataTables: controles apilados + sin huecos ========== */
  body.spvsma-sm-theme .box-body {
    min-height: 0 !important;
    padding-bottom: 12px !important;
  }

  body.spvsma-sm-theme .dataTables_wrapper {
    position: relative !important;
    min-height: 0 !important;
    width: 100% !important;
    clear: both;
  }

  body.spvsma-sm-theme .dataTables_wrapper .dataTables_length,
  body.spvsma-sm-theme .dataTables_wrapper .dataTables_filter {
    float: none !important;
    width: 100% !important;
    text-align: left !important;
    margin: 0 0 10px 0 !important;
    clear: both !important;
  }

  body.spvsma-sm-theme .dataTables_wrapper .dataTables_length select {
    min-height: var(--sm-mobile-field-h);
    font-size: 16px;
    width: 100%;
    max-width: 100%;
  }

  body.spvsma-sm-theme .dataTables_wrapper .dataTables_filter input {
    width: 100% !important;
    max-width: none !important;
    min-height: var(--sm-mobile-field-h);
    font-size: 16px;
    box-sizing: border-box;
  }

  body.spvsma-sm-theme .dataTables_wrapper .dataTables_info,
  body.spvsma-sm-theme .dataTables_wrapper .dataTables_paginate {
    float: none !important;
    width: 100% !important;
    text-align: center !important;
    margin-top: 10px !important;
    clear: both !important;
  }

  body.spvsma-sm-theme .dataTables_wrapper .dataTables_processing {
    position: absolute !important;
    top: 40% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 10px 14px !important;
    height: auto !important;
    z-index: 20;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.96) !important;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  }

  body.spvsma-sm-theme table.dataTable {
    margin-top: 0 !important;
    width: 100% !important;
  }

  /* Responsive: fila principal compacta */
  body.spvsma-sm-theme table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control,
  body.spvsma-sm-theme table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control {
    position: relative;
    padding-left: 36px !important;
    cursor: pointer;
  }

  body.spvsma-sm-theme table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
  body.spvsma-sm-theme table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before {
    top: 50%;
    left: 8px;
    transform: translateY(-50%);
    color: #5e35b1;
    font-weight: 700;
    border: 1px solid #c7d2fe;
    background: #eef2ff;
    border-radius: 6px;
    width: 22px;
    height: 22px;
    line-height: 20px;
    text-align: center;
  }

  body.spvsma-sm-theme table.dataTable > tbody > tr.child {
    background: #f8fafc !important;
  }

  body.spvsma-sm-theme table.dataTable > tbody > tr.child ul.dtr-details {
    width: 100%;
    margin: 0;
    padding: 8px 0;
  }

  body.spvsma-sm-theme table.dataTable > tbody > tr.child span.dtr-title {
    display: block;
    font-weight: 600;
    color: #374151;
    font-size: 12px;
    margin-bottom: 2px;
  }

  body.spvsma-sm-theme table.dataTable > tbody > tr.child span.dtr-data {
    display: block;
    color: #111827;
    font-size: 14px;
    word-break: break-word;
  }

  body.spvsma-sm-theme table.dataTable > tbody > tr.child .btn-group .btn {
    min-height: 40px;
    min-width: 40px;
    margin: 2px;
  }

  /* Sin scroll horizontal como UX principal */
  body.spvsma-sm-theme .sm-mobile-page .table-responsive,
  body.spvsma-sm-theme .sm-mobile-datatable-wrap {
    overflow-x: hidden !important;
  }

  /* ========== Barra de acciones superior ========== */
  body.spvsma-sm-theme .sm-mobile-action-row {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    width: 100% !important;
  }

  body.spvsma-sm-theme .sm-mobile-action-row .btn,
  body.spvsma-sm-theme .sm-mobile-action-row a.btn {
    width: 100% !important;
    max-width: 100% !important;
    white-space: normal !important;
    min-height: var(--sm-mobile-field-h);
    font-size: 15px;
  }

  body.spvsma-sm-theme .sm-mobile-action-row > span,
  body.spvsma-sm-theme .box-header .sm-mobile-legend {
    display: block !important;
    width: 100% !important;
    margin: 4px 0 0 !important;
    font-size: 14px !important;
    line-height: 1.35 !important;
    word-break: break-word;
  }

  /* ========== Formularios: una columna ========== */
  body.spvsma-sm-theme .sm-mobile-form-stack .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  body.spvsma-sm-theme .sm-mobile-form-stack .row > [class*="col-"] {
    width: 100% !important;
    max-width: 100% !important;
    float: none !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  body.spvsma-sm-theme .sm-mobile-form-stack .form-control,
  body.spvsma-sm-theme .sm-mobile-form-stack .input-lg,
  body.spvsma-sm-theme .sm-mobile-form-stack select.form-control {
    width: 100% !important;
    max-width: 100% !important;
    min-height: var(--sm-mobile-field-h);
    font-size: 16px !important;
    box-sizing: border-box;
  }

  body.spvsma-sm-theme .sm-mobile-form-stack textarea.form-control {
    min-height: 88px;
    font-size: 16px !important;
  }

  body.spvsma-sm-theme .sm-mobile-form-stack .select2-container {
    width: 100% !important;
    max-width: 100% !important;
  }

  body.spvsma-sm-theme .sm-mobile-form-stack label.control-label {
    font-size: 14px;
    margin-bottom: 6px;
  }

  /* ========== Modales pantalla completa ========== */
  body.spvsma-sm-theme.sm-mobile-modal-open .sm-bottom-nav {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel.in,
  body.spvsma-sm-theme .modal.sm-mobile-modal-panel.show {
    padding: 0 !important;
  }

  /* Modales sin .modal-dialog (legacy apartados) */
  body.spvsma-sm-theme .modal.sm-mobile-modal-panel > .modal-content {
    width: 100vw !important;
    max-width: 100vw !important;
    margin: 0 !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .modal-dialog {
    width: 100vw !important;
    max-width: 100vw !important;
    margin: 0 !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    padding: 0 !important;
    transform: none !important;
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .modal-content {
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .modal-header {
    flex: 0 0 auto;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px !important;
    min-height: 52px;
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .modal-header .close {
    display: none !important;
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .sm-mobile-header-salir {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 6px 12px;
    font-weight: 600;
    border-radius: 8px;
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .modal-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 16px !important;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0 !important;
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .modal-body {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-height: none !important;
    padding: 12px var(--sm-mobile-pad) !important;
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .modal-footer,
  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .sm-mobile-form-actions {
    flex: 0 0 auto;
    display: flex !important;
    flex-direction: row !important;
    gap: 10px !important;
    align-items: center !important;
    justify-content: stretch !important;
    margin: 0 !important;
    padding: 10px var(--sm-mobile-pad) calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    background: #fff !important;
    border-top: 1px solid #e5e7eb !important;
    position: sticky !important;
    bottom: 0 !important;
    z-index: 5 !important;
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.06);
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .modal-footer .btn,
  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .sm-mobile-form-actions .btn {
    flex: 1 1 0 !important;
    float: none !important;
    min-height: var(--sm-mobile-field-h) !important;
    font-size: 15px !important;
    margin: 0 !important;
  }

  body.spvsma-sm-theme .modal.sm-mobile-modal-panel .modal-footer .pull-left {
    float: none !important;
  }

  /* ========== Perfiles: tabla → tarjetas ========== */
  body.spvsma-sm-theme .perfiles-acl-wrap .table-responsive {
    overflow-x: hidden !important;
  }

  body.spvsma-sm-theme .perfiles-acl-wrap table.table thead {
    display: none;
  }

  body.spvsma-sm-theme .perfiles-acl-wrap table.table tbody tr {
    display: block;
    margin-bottom: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
    padding: 12px;
  }

  body.spvsma-sm-theme .perfiles-acl-wrap table.table tbody td {
    display: block;
    border: 0 !important;
    padding: 4px 0 !important;
    text-align: left !important;
  }

  body.spvsma-sm-theme .perfiles-acl-wrap table.table tbody td:nth-child(1) {
    font-size: 12px;
    color: #6b7280;
  }

  body.spvsma-sm-theme .perfiles-acl-wrap table.table tbody td:nth-child(2) {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
    padding-bottom: 8px !important;
  }

  body.spvsma-sm-theme .perfiles-acl-wrap table.table tbody td:nth-child(3) {
    font-size: 13px;
    line-height: 1.4;
    max-height: 120px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #f9fafb;
    border-radius: 8px;
    padding: 8px !important;
    margin-bottom: 8px;
    word-break: break-word;
  }

  body.spvsma-sm-theme .perfiles-toolbar {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    margin-bottom: 12px !important;
  }

  body.spvsma-sm-theme .perfiles-toolbar .btn {
    width: 100% !important;
    min-height: var(--sm-mobile-field-h);
  }

  body.spvsma-sm-theme .perfiles-acl-wrap table.table tbody td:nth-child(4) .btn {
    min-height: 40px;
    margin: 2px 4px 2px 0;
  }

  /* ========== Inicio: alertas y dashboard ========== */
  body.spvsma-sm-theme .sm-mobile-alert-stack {
    max-width: 100% !important;
    overflow: hidden !important;
    word-wrap: break-word !important;
    overflow-wrap: anywhere !important;
  }

  body.spvsma-sm-theme .sm-mobile-alert-stack ul {
    padding-left: 18px !important;
    margin-bottom: 10px !important;
  }

  body.spvsma-sm-theme .sm-mobile-alert-stack li {
    margin-bottom: 6px;
    line-height: 1.35;
  }

  body.spvsma-sm-theme .dashboard-modern .row > [class*="col-"] {
    width: 100% !important;
    float: none !important;
    max-width: 100% !important;
  }

  body.spvsma-sm-theme .content-header h1 {
    font-size: 18px !important;
    line-height: 1.25 !important;
    word-break: break-word;
  }

  body.spvsma-sm-theme .sm-inicio-dash-pro .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  body.spvsma-sm-theme .sm-inicio-dash-pro .card-modern,
  body.spvsma-sm-theme .sm-inicio-dash-pro .sm-pro-chart-shell {
    max-width: 100% !important;
    box-sizing: border-box;
  }

  body.spvsma-sm-theme .sm-mobile-page .content,
  body.spvsma-sm-theme .sm-mobile-page.content-wrapper {
    padding-left: var(--sm-mobile-pad) !important;
    padding-right: var(--sm-mobile-pad) !important;
  }
}

/* Tablet+: tabla tradicional */
@media (min-width: 992px) {
  body.spvsma-sm-theme .sm-mobile-header-salir {
    display: none !important;
  }
}
