/*
 * ═══════════════════════════════════════════════════════════════
 *  MONTERO MOBILE — Capa de compatibilidad iOS/Safari
 *  Aplica después de adminlte.min.css + custom.css
 *  NO rompe la experiencia de escritorio.
 * ═══════════════════════════════════════════════════════════════
 */

/* ─────────────────────────────────────────────────────────────
   1. CSS CUSTOM PROPERTIES + SAFE AREAS (Notch / Dynamic Island)
   ───────────────────────────────────────────────────────────── */
:root {
  --navbar-height: 57px;
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);
}

/* ─────────────────────────────────────────────────────────────
   2. SCROLL SUAVE NATIVO + OVERSCROLL CONTENCIÓN
   ───────────────────────────────────────────────────────────── */
html {
  scroll-behavior: smooth;
}

.main-sidebar {
  overscroll-behavior: contain;
}

/* ─────────────────────────────────────────────────────────────
   3. TOUCH-ACTION: MANIPULATION — elimina delay 300ms en iOS
   ───────────────────────────────────────────────────────────── */
button,
a,
label,
input[type="submit"],
input[type="button"],
input[type="reset"],
[role="button"],
.btn,
.nav-link,
.sidebar-item,
.filter-tab {
  touch-action: manipulation;
}

/* ─────────────────────────────────────────────────────────────
   4. PREFERS-REDUCED-MOTION — respeta accesibilidad del usuario
   ───────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration:       0.01ms !important;
    animation-iteration-count: 1     !important;
    transition-duration:      0.01ms !important;
    scroll-behavior:          auto   !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   5. PREVENCIÓN DE ZOOM EN iOS — font-size ≥ 16px en inputs
      Safari hace zoom automático si font-size < 16px al enfocar
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  input,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="search"],
  input[type="date"],
  input[type="time"],
  select,
  textarea,
  .form-control,
  .custom-select,
  .select2-selection,
  .select2-search__field {
    font-size: 16px !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   6. -webkit-overflow-scrolling: touch — scroll con inercia iOS
   ───────────────────────────────────────────────────────────── */
.table-responsive,
.main-sidebar .sidebar,
.sidebar-wrapper,
.content-wrapper,
[style*="overflow:auto"],
[style*="overflow: auto"],
[style*="overflow-y:auto"],
[style*="overflow-y: auto"] {
  -webkit-overflow-scrolling: touch;
}

/* ─────────────────────────────────────────────────────────────
   7. SAFE AREAS — padding para notch y home indicator
   ───────────────────────────────────────────────────────────── */
.main-header.navbar {
  padding-left:  max(0.5rem, var(--safe-left));
  padding-right: max(0.5rem, var(--safe-right));
}

/* Home indicator (iOS) — evita que botones queden debajo */
.main-footer {
  padding-bottom: max(0.5rem, var(--safe-bottom));
}

/* Sidebar bajo notch */
.main-sidebar {
  padding-top: var(--safe-top);
}

/* ─────────────────────────────────────────────────────────────
   8. LAYOUT-FIXED FIX — 100dvh en vez de 100vh para Safari iOS
      La barra de URL de Safari cambia de tamaño al hacer scroll,
      provocando que 100vh sea mayor que la ventana visible.
      100dvh es el viewport dinámico (siempre correcto).
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  body.layout-fixed .content-wrapper {
    /* Fallback para navegadores sin dvh */
    min-height: calc(100vh - var(--navbar-height));
    min-height: calc(100dvh - var(--navbar-height));
    overflow: initial !important;
  }

  body.layout-fixed .wrapper {
    overflow: initial !important;
  }

  body.layout-fixed {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Sticky card-header: usa la CSS var del navbar en vez de 55px fijo */
  .card-header.position-sticky[style*="top:55px"],
  .card-header.position-sticky[style*="top: 55px"] {
    top: var(--navbar-height) !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   9. TOUCH TARGETS MÍNIMO 44×44px — estándar Apple HIG
      .btn-xs existe en AdminLTE pero mide ~20px de alto
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .btn-xs {
    min-height:    44px !important;
    min-width:     44px !important;
    padding:       10px 10px !important;
    font-size:     0.85rem !important;
    display:       inline-flex !important;
    align-items:   center !important;
    justify-content: center !important;
    border-radius: 6px !important;
  }

  /* Columna de acciones: apilar botones en columna con gap */
  table td:last-child .btn-xs {
    display:       flex !important;
    width:         100% !important;
    margin-bottom: 3px !important;
    margin-right:  0 !important;
  }

  table td:last-child {
    min-width: 52px;
    vertical-align: top;
  }

  /* Modal footer: botones apilados en pantallas muy pequeñas */
  .modal-footer {
    flex-wrap: wrap;
    gap: 8px;
  }
}

@media (max-width: 400px) {
  .modal-footer {
    flex-direction: column;
  }
  .modal-footer .btn {
    width: 100%;
  }
}

/* ─────────────────────────────────────────────────────────────
   10. CARD-HEADER CON BOTONES ABSOLUTOS — evita solapamiento
       Los títulos cortos en mobile se tapaban con los botones
   ───────────────────────────────────────────────────────────── */
@media (max-width: 576px) {
  .card-header {
    padding-right: 110px;
  }
  .card-header h5,
  .card-header .card-title {
    max-width:     100%;
    white-space:   normal;
    overflow:      hidden;
    text-overflow: ellipsis;
    padding-right: 0;
    font-size:     0.95rem;
    line-height:   1.3;
  }
}

/* ─────────────────────────────────────────────────────────────
   11. SEARCH BOXES ABSOLUTOS — responsive en mobile
       #cont-buscliente, #cont-busempresa: position:absolute + width:250px
       #cont-busproducto: position:absolute + right:110px + width:50%
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  #cont-buscliente,
  #cont-busempresa {
    position:   relative !important;
    top:        auto !important;
    right:      auto !important;
    width:      100% !important;
    max-width:  100% !important;
    margin-top: 0.5rem;
    z-index:    10;
  }

  #cont-busproducto {
    position:      relative !important;
    right:         auto !important;
    width:         100% !important;
    max-width:     100% !important;
    margin-bottom: 0.5rem;
    z-index:       10;
  }

  /* Dropdowns de resultados de búsqueda: ancho completo */
  #cont-resultadobuscliente,
  #cont-resultadobusempresa {
    width:    100% !important;
    left:     0 !important;
    right:    0 !important;
    max-width: 100vw;
  }
}

/* ─────────────────────────────────────────────────────────────
   12. MODALES — fullscreen en mobile + scroll interno
       modal-xl y modal-lg ocupan pantalla completa en iOS
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .modal-dialog.modal-xl,
  .modal-dialog.modal-lg {
    margin:       0 !important;
    max-width:    100% !important;
    width:        100% !important;
    height:       100% !important;
    /* 100dvh asegura que el modal nunca quede cortado por la barra de URL */
    height:       100dvh !important;
  }

  .modal-dialog.modal-xl .modal-content,
  .modal-dialog.modal-lg .modal-content {
    height:        100%;
    border-radius: 0 !important;
    border:        none !important;
    display:       flex;
    flex-direction: column;
  }

  .modal-dialog.modal-xl .modal-body,
  .modal-dialog.modal-lg .modal-body {
    overflow-y:                  auto !important;
    -webkit-overflow-scrolling:  touch !important;
    flex:                        1;
  }

  /* Modal estándar: también fullscreen pero con bordes redondeados arriba */
  .modal-dialog:not(.modal-xl):not(.modal-lg) {
    margin:    0.5rem auto !important;
    max-width: calc(100% - 1rem) !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   13. TINYMCE / TEXTAREA — font-size 16px + altura adaptable
       14px provoca zoom automático en Safari iOS
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  #continforme,
  #contrecibo,
  .tinymce,
  .mce-edit-area,
  .tox-edit-area {
    height:     auto !important;
    min-height: 140px !important;
    font-size:  16px !important;
  }

  /* El panel split col-sm-4 / col-sm-8 se apila en mobile */
  .col-12.col-sm-4[style*="overflow:auto"],
  .col-12.col-sm-8[style*="overflow:auto"] {
    max-height:                  none !important;
    overflow:                    visible !important;
    -webkit-overflow-scrolling:  touch;
  }

  /* Contenedor de informe/recibo preview */
  #cont-informe {
    max-height: none !important;
    margin:     4px 0 !important;
    max-width:  100% !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   14. TABLE-RESPONSIVE — sin max-height en mobile
       Evita el "scroll dentro de scroll" en iPhone
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .table-responsive[style*="max-height"] {
    max-height:  none !important;
    overflow-x:  auto !important;
    overflow-y:  visible !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   15. DATATABLE ORDENES — columnas de baja prioridad ocultas
       Se muestran expandidas con el botón "+" de DataTables Responsive
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  /* Ocultar: Cotización(3), Empresa(5), Dirección(6), Servicio(7),
              Pagado(9), Monto(11), Resta(12) */
  #tabla thead th:nth-child(3),
  #tabla tbody td:nth-child(3),
  #tabla tfoot th:nth-child(3),
  #tabla thead th:nth-child(5),
  #tabla tbody td:nth-child(5),
  #tabla tfoot th:nth-child(5),
  #tabla thead th:nth-child(6),
  #tabla tbody td:nth-child(6),
  #tabla tfoot th:nth-child(6),
  #tabla thead th:nth-child(7),
  #tabla tbody td:nth-child(7),
  #tabla tfoot th:nth-child(7),
  #tabla thead th:nth-child(9),
  #tabla tbody td:nth-child(9),
  #tabla tfoot th:nth-child(9),
  #tabla thead th:nth-child(11),
  #tabla tbody td:nth-child(11),
  #tabla tfoot th:nth-child(11),
  #tabla thead th:nth-child(12),
  #tabla tbody td:nth-child(12),
  #tabla tfoot th:nth-child(12) {
    display: none !important;
  }

  /* Tabla más compacta en mobile */
  #tabla.table-sm th,
  #tabla.table-sm td {
    padding: 6px 4px;
    font-size: 0.8rem;
  }

  /* DataTable toolbar: reducir espacio */
  div.dataTables_wrapper div.dataTables_length,
  div.dataTables_wrapper div.dataTables_filter {
    text-align: left;
    float: none;
  }
}

/* ─────────────────────────────────────────────────────────────
   16. DASHBOARD: GRID FIXES
       col-md-6 y col-md-4 sin col-12 colapsaban a 50% en mobile
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .row > .col-md-6,
  .row > .col-md-4 {
    flex:      0 0 100% !important;
    max-width: 100% !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   17. KPI CARDS — ajuste de tamaños en mobile
   ───────────────────────────────────────────────────────────── */
@media (max-width: 576px) {
  .kpi-box {
    padding: 0.6rem 0.4rem;
  }

  .kpi-box .kpi-icon {
    font-size: 1.8rem !important;
  }

  .kpi-box .kpi-val {
    font-size: 1.1rem !important;
  }

  .kpi-box .kpi-label {
    font-size: 0.68rem;
    line-height: 1.2;
  }
}

/* ─────────────────────────────────────────────────────────────
   18. PROGRESS BAR — más alta en mobile para mejor visibilidad
   ───────────────────────────────────────────────────────────── */
@media (max-width: 576px) {
  .progress {
    height: 20px !important;
    border-radius: 4px;
  }

  .progress-bar {
    line-height: 20px;
    font-size: 0.7rem;
  }
}

/* ─────────────────────────────────────────────────────────────
   19. content-visibility: auto — mejora de render en tablas largas
       El navegador omite el layout de filas fuera del viewport
   ───────────────────────────────────────────────────────────── */
@supports (content-visibility: auto) {
  /* Solo aplica a tablas NO gestionadas por DataTables */
  .dash-table tbody {
    content-visibility:       auto;
    contain-intrinsic-size:   0 400px;
  }
}

/* ─────────────────────────────────────────────────────────────
   20. CSS CONTAINER QUERIES — cards del dashboard se adaptan
       según el tamaño de su contenedor, no solo del viewport
   ───────────────────────────────────────────────────────────── */
@supports (container-type: inline-size) {
  .card {
    container-type: inline-size;
    container-name: montero-card;
  }

  /* Cuando la card es estrecha (< 380px): layout compacto */
  @container montero-card (max-width: 380px) {
    .dash-table {
      font-size: 0.72rem;
    }

    .dash-table th,
    .dash-table td {
      padding: 4px 3px;
    }

    .facturacion-row {
      flex-direction: column;
      align-items: flex-start;
    }

    .facturacion-monto {
      font-size: 0.9rem;
    }

    .kpi-box {
      padding: 0.5rem 0.3rem;
    }

    .kpi-icon {
      font-size: 1.5rem !important;
    }
  }

  /* Cuando la card es muy estrecha (< 260px): mínima expresión */
  @container montero-card (max-width: 260px) {
    .kpi-label {
      display: none;
    }

    .kpi-val {
      font-size: 1.3rem !important;
    }
  }
}

/* ─────────────────────────────────────────────────────────────
   21. CSS :has() — estados interactivos sin JavaScript
       Solo activos en navegadores que lo soportan (Safari 15.4+,
       Chrome 105+, Firefox 121+)
   ───────────────────────────────────────────────────────────── */
@supports selector(:has(*)) {
  /* Highlight de grupo al enfocar input */
  .form-group:has(input:focus),
  .form-group:has(select:focus),
  .form-group:has(textarea:focus) {
    background-color: rgba(0, 123, 255, 0.03);
    border-left:      3px solid #007bff;
    padding-left:     calc(1.25rem - 3px);
    border-radius:    0 4px 4px 0;
    transition:       border-color 0.15s ease, background-color 0.15s ease;
  }

  /* Card con sombra al hacer hover sobre su contenido */
  .card:has(.card-body:hover) {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
    transition: box-shadow 0.2s ease;
  }

  /* Fila de tabla resaltada al hacer hover */
  .table:has(tbody tr:hover) tbody tr:hover {
    background-color: rgba(0, 123, 255, 0.05) !important;
    cursor: pointer;
  }

  /* Modal-footer: si tiene más de 2 botones en pantalla pequeña, apilar */
  @media (max-width: 480px) {
    .modal-footer:has(.btn ~ .btn ~ .btn) {
      flex-direction: column;
    }
    .modal-footer:has(.btn ~ .btn ~ .btn) .btn {
      width: 100%;
    }
  }
}

/* ─────────────────────────────────────────────────────────────
   22. SIDEBAR RUBBER BANDING iOS — overscroll fix
   ───────────────────────────────────────────────────────────── */
.main-sidebar .sidebar {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ─────────────────────────────────────────────────────────────
   23. POSITION: FIXED EN iOS SAFARI — fix de teclado virtual
       Cuando aparece el teclado, los fixed elements se quedan
       flotando. Usamos transform para forzar re-stack.
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  /* Forzar GPU layer en el header fijo */
  .main-header {
    -webkit-transform: translateZ(0);
    transform:         translateZ(0);
    will-change:       transform;
  }
}

/* ─────────────────────────────────────────────────────────────
   24. BADGE Y TEXTO PEQUEÑO — mínimo 12px para legibilidad
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .badge {
    font-size: max(0.65rem, 11px) !important;
    padding:   3px 7px !important;
  }

  .badge-estado {
    font-size: max(0.65rem, 11px) !important;
  }

  /* Textos inline muy pequeños del dashboard */
  small,
  .small {
    font-size: max(0.78rem, 12px) !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   25. FLATPICKR — calendario responsive en mobile
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .flatpickr-calendar {
    width:     calc(100vw - 32px) !important;
    max-width: 320px;
    left:      50% !important;
    transform: translateX(-50%) !important;
    font-size: 14px;
  }

  .flatpickr-day {
    max-width:   none !important;
    height:      34px !important;
    line-height: 34px !important;
  }

  .dayContainer {
    width:     calc(100vw - 48px) !important;
    min-width: unset !important;
    max-width: 300px !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   26. SELECT2 — touch-friendly en mobile
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .select2-container .select2-selection--single {
    height:      44px !important;
    line-height: 42px !important;
  }

  .select2-container .select2-selection--single .select2-selection__rendered {
    line-height: 42px !important;
  }

  .select2-container .select2-selection--single .select2-selection__arrow {
    height: 42px !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   27. TABLA SCROLL HORIZONTAL — indicador visual
       Un degradado sutil indica que la tabla se puede scrollear
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .table-responsive {
    background:
      linear-gradient(to right, white 20%, rgba(255,255,255,0)) left  center / 20px 100% no-repeat,
      linear-gradient(to left,  white 20%, rgba(255,255,255,0)) right center / 20px 100% no-repeat,
      radial-gradient(ellipse at left,  rgba(0,0,0,0.12) 0%, rgba(0,0,0,0) 70%) left  center / 8px 100% no-repeat,
      radial-gradient(ellipse at right, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0) 70%) right center / 8px 100% no-repeat;
    background-attachment: local, local, scroll, scroll;
  }
}

/* ─────────────────────────────────────────────────────────────
   28. TABLE → CARDS EN MOBILE
       Cada <tr> se convierte en una tarjeta vertical.
       La clase .table-to-cards se asigna por JS automáticamente.
       El <td>::before muestra el label de columna (data-label).
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {

  /* Ocultar thead visualmente (sigue en DOM, no rompe DataTables) */
  .table-to-cards thead {
    position:    absolute;
    width:       1px;
    height:      1px;
    overflow:    hidden;
    clip:        rect(0,0,0,0);
    white-space: nowrap;
    border:      0;
  }

  /* Ocultar tfoot */
  .table-to-cards tfoot {
    display: none;
  }

  /* Cada <tbody> deja de ser tabla */
  .table-to-cards tbody {
    display: block;
  }

  /* Cada <tr> se convierte en card */
  .table-to-cards tbody tr {
    display:        block;
    margin-bottom:  12px;
    border-radius:  10px;
    box-shadow:     0 1px 6px rgba(0,0,0,0.10);
    padding:        10px 14px;
    background:     #fff;
    border:         1px solid #e5e7eb;
    animation:      fadeInCard 0.2s ease;
  }

  @keyframes fadeInCard {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0);   }
  }

  /* Cada <td> se convierte en fila label:valor */
  .table-to-cards tbody td {
    display:         flex;
    justify-content: space-between;
    align-items:     flex-start;
    padding:         5px 0;
    border:          none;
    border-bottom:   1px solid #f1f5f9;
    font-size:       0.83rem;
    gap:             8px;
  }

  .table-to-cards tbody td:last-child {
    border-bottom: none;
    padding-top:   8px;
  }

  /* Label de la columna (inyectado con data-label via JS) */
  .table-to-cards tbody td::before {
    content:        attr(data-label);
    font-weight:    600;
    color:          #64748b;
    font-size:      0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space:    nowrap;
    flex-shrink:    0;
    padding-top:    1px;
  }

  /* Celda sin label o con label vacío: no mostrar separador */
  .table-to-cards tbody td[data-label=""]::before {
    display: none;
  }
  .table-to-cards tbody td[data-label=""] {
    justify-content: flex-end;
  }

  /* Primera celda (Id / referencia) — más prominente */
  .table-to-cards tbody td:first-child {
    font-weight:    600;
    font-size:      0.9rem;
    border-bottom:  2px solid #e5e7eb;
    padding-bottom: 8px;
    margin-bottom:  2px;
  }

  /* Botones de acción — inline */
  .table-to-cards tbody td:last-child .btn-xs,
  .table-to-cards tbody td:last-child .btn {
    margin:  2px 3px 0 0;
    display: inline-flex;
  }

  /* Restaurar layout completo para el td */
  .table-to-cards tbody td > * {
    max-width:  65%;
    word-break: break-word;
  }

  /* Quitar border de tabla */
  .table-to-cards {
    border: none !important;
  }

  .table-to-cards.table-bordered tbody td {
    border:        none;
    border-bottom: 1px solid #f1f5f9;
  }

  /* Progress bar dentro de cell */
  .table-to-cards .progress {
    min-width: 80px;
    flex:      1;
  }
}

/* ─────────────────────────────────────────────────────────────
   29. BOTONES COMPARTIR PDF — WhatsApp, Telegram, Email
       Visibles en todos los dispositivos.
   ───────────────────────────────────────────────────────────── */
.share-btns {
  display:     flex;
  align-items: center;
  gap:         6px;
  margin-top:  8px;
  flex-wrap:   wrap;
}

.btn-share {
  display:         inline-flex;
  align-items:     center;
  justify-content: center;
  width:           36px;
  height:          36px;
  border-radius:   50%;
  font-size:       1rem;
  color:           #fff;
  text-decoration: none;
  transition:      opacity 0.15s ease, transform 0.12s ease;
  flex-shrink:     0;
  cursor:          pointer;
  touch-action:    manipulation;
}

.btn-share:hover {
  opacity:         0.85;
  transform:       scale(1.10);
  color:           #fff;
  text-decoration: none;
}

.btn-share:active {
  transform: scale(0.93);
}

.btn-share-whatsapp { background-color: #25D366; }
.btn-share-telegram { background-color: #0088cc; }
.btn-share-email    { background-color: #6b7280; }

.share-btns-label {
  font-size:   0.75rem;
  color:       #64748b;
  font-weight: 600;
  white-space: nowrap;
}

/* ─────────────────────────────────────────────────────────────
   30. TABLA ÓRDENES — MODO CARD PERSONALIZADO
       Columnas del #tabla (índice 1-based):
         1=Id, 2=Referencia, 3=Cotización, 4=Cliente,
         5=Empresa, 6=Dirección, 7=Servicio(s), 8=Fecha,
         9=Pagado, 10=Estado, 11=Monto, 12=Resta, 13=Acc.
   ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {

  /* 1. Ocultar Id en la card — Referencia es el identificador visual */
  #tabla.table-to-cards tbody td:nth-child(1) {
    display: none !important;
  }

  /* 2. Resetear estilo td:first-child (que apuntaba al Id, ahora oculto) */
  #tabla.table-to-cards tbody td:first-child {
    font-weight: normal;
    font-size:   0.83rem;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 5px;
    margin-bottom:  0;
  }

  /* 3. Referencia (col 2) como encabezado prominente de la card */
  #tabla.table-to-cards tbody td:nth-child(2) {
    font-size:      1rem !important;
    font-weight:    700 !important;
    color:          #1e3a8a;
    border-bottom:  2px solid #dbeafe !important;
    padding-bottom: 8px !important;
    margin-bottom:  2px;
  }

  #tabla.table-to-cards tbody td:nth-child(2)::before {
    display: none; /* Sin label "REFERENCIA" — es el título de la card */
  }

  /* 4. Mostrar Empresa(5), Dirección(6), Servicio(7), Pagado(9)
        (la sección 15 los ocultaba con display:none !important) */
  #tabla.table-to-cards tbody td:nth-child(5),
  #tabla.table-to-cards tbody td:nth-child(6),
  #tabla.table-to-cards tbody td:nth-child(7),
  #tabla.table-to-cards tbody td:nth-child(9) {
    display: flex !important;
  }

  /* 5. Seguir ocultando Cotización(3), Monto(11), Resta(12) */
  #tabla.table-to-cards tbody td:nth-child(3),
  #tabla.table-to-cards tbody td:nth-child(11),
  #tabla.table-to-cards tbody td:nth-child(12) {
    display: none !important;
  }

  /* 6. Servicio(s) — puede tener <br> con texto largo, alinear arriba */
  #tabla.table-to-cards tbody td:nth-child(7) {
    align-items: flex-start;
  }
  #tabla.table-to-cards tbody td:nth-child(7) > * {
    max-width: 70%;
    line-height: 1.4;
  }

  /* 7. Pagado — centrar el ícono SI/NO */
  #tabla.table-to-cards tbody td:nth-child(9) {
    align-items: center;
  }
}

/* ─────────────────────────────────────────────────────────────
   31. BOTÓN COMPARTIR EN CARD — solo visible en mobile card mode
   ───────────────────────────────────────────────────────────── */

/* Oculto en desktop — el layout de tabla no tiene espacio */
.btn-share-card {
  display: none !important;
}

/* Visible dentro de una card en mobile */
@media (max-width: 767.98px) {
  .table-to-cards .btn-share-card {
    display: inline-flex !important;
    width:  40px;
    height: 40px;
    border: none;
    cursor: pointer;
    margin: 2px 3px 0 0;
  }
}

/* ── Dropdown fallback (desktop / sin soporte navigator.share) ── */
.share-sheet-overlay {
  position:   fixed;
  inset:      0;
  z-index:    9998;
  background: rgba(0, 0, 0, 0.45);
  animation:  fadeOverlay 0.15s ease;
}

@keyframes fadeOverlay {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.share-sheet {
  position:      fixed;
  z-index:       9999;
  background:    #fff;
  border-radius: 16px 16px 0 0;
  padding:       20px 16px 28px;
  width:         100%;
  bottom:        0;
  left:          0;
  box-shadow:    0 -4px 32px rgba(0,0,0,0.18);
  animation:     slideUpSheet 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

/* En desktop: aparece centrado como modal pequeño */
@media (min-width: 768px) {
  .share-sheet {
    width:         320px;
    border-radius: 12px;
    top:           50%;
    left:          50%;
    bottom:        auto;
    transform:     translate(-50%, -50%);
    animation:     fadeInScale 0.18s ease;
  }

  @keyframes fadeInScale {
    from { opacity: 0; transform: translate(-50%, -48%) scale(0.96); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1);    }
  }
}

@keyframes slideUpSheet {
  from { transform: translateY(100%); }
  to   { transform: translateY(0);    }
}

.share-sheet-title {
  font-size:     0.8rem;
  font-weight:   600;
  color:         #64748b;
  text-align:    center;
  margin-bottom: 16px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.share-sheet-ref {
  font-size:   1rem;
  font-weight: 700;
  color:       #1e3a8a;
  text-align:  center;
  margin-bottom: 20px;
}

.share-sheet-options {
  display:         flex;
  justify-content: center;
  gap:             24px;
  flex-wrap:       wrap;
  margin-bottom:   20px;
}

.share-sheet-option {
  display:        flex;
  flex-direction: column;
  align-items:    center;
  gap:            6px;
  text-decoration: none;
  color:          #374151;
  font-size:      0.72rem;
  font-weight:    500;
  cursor:         pointer;
  background:     none;
  border:         none;
  padding:        0;
  touch-action:   manipulation;
}

.share-sheet-option:hover { color: #374151; text-decoration: none; }

.share-sheet-icon {
  display:         flex;
  align-items:     center;
  justify-content: center;
  width:           52px;
  height:          52px;
  border-radius:   14px;
  font-size:       1.4rem;
  color:           #fff;
  transition:      transform 0.1s ease;
}

.share-sheet-option:active .share-sheet-icon {
  transform: scale(0.92);
}

.share-icon-wa   { background-color: #25D366; }
.share-icon-tg   { background-color: #0088cc; }
.share-icon-mail { background-color: #6b7280; }
.share-icon-copy { background-color: #374151; }

.share-sheet-cancel {
  width:         100%;
  padding:       12px;
  background:    #f1f5f9;
  border:        none;
  border-radius: 10px;
  font-size:     0.9rem;
  font-weight:   600;
  color:         #374151;
  cursor:        pointer;
  touch-action:  manipulation;
  transition:    background 0.1s;
}

.share-sheet-cancel:active { background: #e2e8f0; }

/* ─────────────────────────────────────────────────────────────
   DATATABLES — Anti-flash + Skeleton loader
   El JS en interfaz.blade.php añade/remueve estas clases
   automáticamente en cada tabla del proyecto.
   ───────────────────────────────────────────────────────────── */

/* Oculto solo mientras DataTables está inicializando.
   Lo agrega preInit.dt, nunca el CSS directamente (evita ocultar
   tablas estáticas que no son DataTables).                        */
.dt-flash-hide {
  opacity: 0;
}

/* Visible con fade-in suave — lo agrega init.dt al terminar */
.dt-loaded {
  opacity: 1;
  transition: opacity 0.3s ease;
}

/* Botones (Copiar, Excel, Imprimir, Ver) — fade-in con leve retardo
   para que aparezcan justo después del contenido de la tabla      */
.dt-buttons {
  opacity: 0;
  transition: opacity 0.3s ease 0.1s;
}
.datatable-ready .dt-buttons {
  opacity: 1;
}

/* Columnas marcadas con className: 'dt-hidden' en columnDefs */
.dt-hidden {
  display: none !important;
}

/* Skeleton shimmer — se inyecta por JS antes de la tabla */
.datatable-skeleton {
  padding: 8px 0 16px;
}
.datatable-skeleton .skeleton-header {
  height: 20px;
  width: 55%;
  border-radius: 4px;
  margin-bottom: 16px;
  background: linear-gradient(90deg, #e2e8f0 25%, #cbd5e1 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: dt-shimmer 1.5s infinite;
}
.datatable-skeleton .skeleton-row {
  height: 14px;
  border-radius: 4px;
  margin-bottom: 10px;
  background: linear-gradient(
    90deg,
    var(--color-bg, #f1f5f9) 25%,
    #e2e8f0 50%,
    var(--color-bg, #f1f5f9) 75%
  );
  background-size: 200% 100%;
  animation: dt-shimmer 1.5s infinite;
}
.datatable-skeleton .skeleton-row:nth-child(even) { width: 100%; }
.datatable-skeleton .skeleton-row:nth-child(odd)  { width: 82%;  }

@keyframes dt-shimmer {
  0%   { background-position:  200% 0; }
  100% { background-position: -200% 0; }
}

/* Respeta prefers-reduced-motion (refuerza la sección 4 del archivo) */
@media (prefers-reduced-motion: reduce) {
  .datatable-skeleton .skeleton-header,
  .datatable-skeleton .skeleton-row {
    animation: none;
    background: #e2e8f0;
  }
}
