/* ============================================================
   mobile.css — Mejoras responsive para vista móvil
   Activa solo en viewport <= 768px. Desktop intacto.
   Incluido en todas las páginas vía global-layout.css o link directo.
   ============================================================ */

/* -----------------------------------------------------------
   1) TABLAS → CARDS APILADAS EN MÓVIL
   Aplicar class="table-mobile-cards" a la tabla. La JS
   mobile-tables.js inyecta data-label en cada <td>.
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .table-mobile-cards {
    border: 0;
  }
  .table-mobile-cards thead {
    display: none;
  }
  .table-mobile-cards,
  .table-mobile-cards tbody,
  .table-mobile-cards tr {
    display: block;
    width: 100%;
  }
  .table-mobile-cards tbody tr {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  }
  .table-mobile-cards tbody tr:hover {
    background: #f9fafb;
  }
  .table-mobile-cards td {
    display: block !important;
    padding: 5px 0 !important;
    border: none !important;
    text-align: left !important;
    white-space: normal !important;
    width: auto !important;
    min-width: 0 !important;
  }
  .table-mobile-cards td::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    color: #6b7280;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
  }
  .table-mobile-cards td[data-label=""]::before,
  .table-mobile-cards td:not([data-label])::before {
    content: none;
  }
  /* Celda vacía: ocultar */
  .table-mobile-cards td:empty {
    display: none !important;
  }
  /* Permitir que columna de checkbox/acciones quede inline */
  .table-mobile-cards td.cell-inline {
    display: inline-block !important;
    margin-right: 8px;
  }
}

/* -----------------------------------------------------------
   2) BARRA INFERIOR PEGADA (acciones primarias siempre visibles)
   Aplicar class="sticky-bottom-actions" al contenedor de
   botones primarios en formularios/listados.
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .sticky-bottom-actions {
    position: sticky;
    bottom: 0;
    z-index: 50;
    background: white;
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
    margin-left: -12px;
    margin-right: -12px;
  }
  .sticky-bottom-actions .btn {
    width: 100%;
  }
}

/* -----------------------------------------------------------
   3) BOTONES TAP-FRIENDLY EN MÓVIL (min 44px alto)
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .btn {
    min-height: 44px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  .btn-sm {
    min-height: 36px;
    padding-top: 6px;
    padding-bottom: 6px;
  }
  /* Excepción: chips/badges no se agrandan */
  .badge.btn,
  .btn-chip {
    min-height: 0;
    padding: 4px 10px;
  }
}

/* -----------------------------------------------------------
   4) NAVBAR / HEADER MÁS COMPACTO
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  /* Buscador del header: prioridad a expandirse */
  .app-header .search-wrap,
  .header-search {
    flex: 1 1 auto;
    min-width: 0;
  }
  /* Texto del título: tamaño reducido */
  .app-header h1,
  .app-header .h4,
  .app-header .page-title {
    font-size: 1rem;
    margin: 0;
  }
  /* Botones del header: solo icono cuando hay class btn-icon-mobile */
  .btn-icon-mobile .btn-label {
    display: none;
  }
  .btn-icon-mobile i {
    margin: 0 !important;
  }
}

/* -----------------------------------------------------------
   5) CARDS Y SECCIONES: relajar padding y margin
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .card,
  .liq-detail-card,
  .liq-info-card {
    border-radius: 10px;
  }
  .card-body,
  .page-content {
    padding: 12px !important;
  }
  /* Headers con grid de info: stack en una columna */
  .liq-info-grid,
  .info-grid,
  .row-2col {
    grid-template-columns: 1fr !important;
  }
  /* Header de detalle de liquidación: stack title + badge */
  .liq-detail-header > div,
  .liq-header {
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* -----------------------------------------------------------
   6) FILTROS Y BARRAS DE ACCIÓN: wrap mejor
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .filter-row,
  .filtros-bar,
  .d-flex.gap-2.flex-wrap {
    gap: 6px !important;
  }
  /* Inputs de fecha/select: ancho completo dentro del wrap */
  .filter-row input,
  .filter-row select,
  .filtros-bar input,
  .filtros-bar select {
    min-width: 0;
    flex: 1 1 100px;
  }
}

/* -----------------------------------------------------------
   7) MODAL: full-width en móvil
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .modal-dialog:not(.modal-fullscreen):not(.modal-sm) {
    margin: 8px;
    max-width: calc(100vw - 16px);
  }
  .modal-body {
    padding: 14px;
  }
  .modal-header {
    padding: 12px 14px;
  }
  .modal-footer .btn {
    width: 100%;
    margin: 4px 0;
  }
}

/* -----------------------------------------------------------
   8) TIPOGRAFÍA RESPONSIVA
   ----------------------------------------------------------- */
@media (max-width: 480px) {
  body {
    font-size: 14px;
  }
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.2rem; }
  h3, h4 { font-size: 1.05rem; }
  .small,
  small {
    font-size: 0.78rem;
  }
}

/* -----------------------------------------------------------
   9) UTILIDADES MOBILE-ONLY / DESKTOP-ONLY
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .desktop-only {
    display: none !important;
  }
}
@media (min-width: 769px) {
  .mobile-only {
    display: none !important;
  }
}

/* -----------------------------------------------------------
   10) TABS RESPONSIVE — Efectivo / Electronico full-width
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .tipo-tabs {
    display: flex !important;
    width: 100%;
  }
  .tipo-tab {
    flex: 1;
    text-align: center;
    padding: 12px !important;
    font-size: 0.9rem;
  }
}

/* -----------------------------------------------------------
   11) ASEG-CARD (liquidaciones por aseguradora + abiertas)
   Stack vertical en móvil + botones full-width
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .aseg-card {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 14px !important;
    gap: 12px;
  }
  .aseg-card .aseg-info {
    width: 100%;
  }
  .aseg-card .aseg-info h6 {
    font-size: 0.95rem;
    line-height: 1.3;
    word-break: break-word;
  }
  .aseg-card .aseg-stats {
    flex-wrap: wrap !important;
    justify-content: space-between !important;
    gap: 8px !important;
    width: 100%;
  }
  .aseg-card .aseg-stat {
    flex: 0 1 auto;
    min-width: 80px;
  }
  /* Botones Ver/Depositar: ocupan ancho completo en su propio row */
  .aseg-card .aseg-stats > .btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 120px;
  }
  /* USD totalDisplay: tipografía más chica */
  .aseg-card .aseg-stat .num {
    font-size: 1rem;
  }
  .aseg-card .aseg-stat small {
    font-size: 0.7rem;
  }
}

/* -----------------------------------------------------------
   12) HEADER DE DASHBOARD: botones de acción en grid 2 columnas
   en móvil, en vez de stack vertical de 1 columna.
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .liq-header .d-flex.gap-2.flex-wrap {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 6px !important;
    width: 100%;
  }
  .liq-header .d-flex.gap-2.flex-wrap > .btn {
    width: 100%;
    margin: 0 !important;
    font-size: 0.82rem;
    padding: 8px 6px;
    min-height: 40px;
  }
  .liq-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
}

/* -----------------------------------------------------------
   13) DASHBOARD HOME (index.html) — widgets responsive
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .dashboard-grid {
    padding: 10px !important;
    grid-gap: 10px !important;
  }
  .widget {
    padding: 12px !important;
    border-radius: 10px;
  }
  .widget-header {
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 6px;
    margin-bottom: 8px;
  }
  .widget-header h5 {
    font-size: 0.95rem !important;
    flex: 1 1 auto;
    min-width: 0;
  }
  .widget-header small {
    font-size: 0.7rem;
  }
  /* TC widget: layout más compacto */
  .tc-row {
    margin: 4px 0 !important;
    gap: 8px;
  }
  .tc-row .label {
    font-size: 0.85rem !important;
  }
  .tc-row .value {
    font-size: 1.15rem !important;
    text-align: right;
    flex-shrink: 0;
  }
  .tc-meta {
    font-size: 0.7rem !important;
    margin-top: 4px !important;
  }
  /* Empty states más sutiles */
  .widget-empty {
    padding: 10px !important;
    font-size: 0.85rem !important;
  }
  /* Cobranza/Pagos: tabs y badges más chicos */
  .cobranza-tabs {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    white-space: nowrap;
  }
  .cobranza-tab {
    flex-shrink: 0;
    font-size: 0.82rem !important;
    padding: 6px 10px !important;
  }
}

/* -----------------------------------------------------------
   14) PAGE-HEADER (top bar fijo) — compactar en móvil
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .page-header,
  #app-header {
    padding: 0 0.75rem !important;
    min-height: 52px;
  }
  /* Welcome message: truncar si excede */
  #welcome-message {
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100vw - 130px);
    display: block;
  }
  .page-header .btn,
  #app-header .btn {
    font-size: 0.78rem;
    padding: 4px 10px;
    min-height: 36px;
  }
}


/* -----------------------------------------------------------
   16) CONTENCIÓN HORIZONTAL — Evita overflow-x en mobile
   Causa típica: tablas dinámicas dentro de widgets que tienen
   overflow:visible empujan el ancho del padre. Forzar overflow-x
   hidden en body + widgets contiene el scroll horizontal a las
   wraps que sí lo necesitan (con overflow-x: auto explícito).
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  html, body {
    overflow-x: hidden !important;
    max-width: 100vw;
  }
  .dashboard-grid,
  #panel-view,
  .page-content,
  .main-content {
    max-width: 100%;
    overflow-x: hidden;
  }
  .widget {
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }
  /* Pagos table: respetar wrap interno con overflow-x: auto sin empujar el padre */
  .widget-pagos > div,
  .widget-cobranza > div {
    max-width: 100%;
    min-width: 0;
  }
  .pagos-table,
  .cobranza-table {
    table-layout: auto;
    font-size: 0.75rem !important;
  }
  .pagos-table th,
  .pagos-table td,
  .cobranza-table th,
  .cobranza-table td {
    padding: 4px 6px !important;
    white-space: nowrap;
  }
  /* Dashboard refresh bar: compactar */
  .dashboard-refresh-bar {
    padding: 8px 10px !important;
    font-size: 0.78rem;
  }
}
