/* ============================================
   MOBILE & TABLET RESPONSIVE STYLES
   Optimizado para uso en tablets y celulares
   ============================================ */

/* Hide products cards by default (show only on mobile) */
.products-cards-view {
  display: none;
}

/* ============================================
   MODAL DE CANTIDAD/DESCUENTO - GLOBAL (desktop y mobile)
   ============================================ */
.product-qty-modal {
  position: fixed;
  inset: 0;
  z-index: 10600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.product-qty-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
}

.product-qty-modal-content {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.product-qty-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
}

.product-qty-modal-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.btn-close-modal {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-close-modal:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

.product-qty-modal-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-product-info {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
}

.modal-qty-row,
.modal-discount-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.modal-qty-row label,
.modal-discount-row label {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
}

.modal-qty-controls,
.modal-discount-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-modal-qty {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.5rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-modal-qty:hover {
  background: #0d6efd;
  color: white;
  border-color: #0d6efd;
}

.modal-qty-input,
.modal-discount-input {
  width: 4rem;
  height: 2.5rem;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  background: var(--color-surface-alt);
  color: var(--text-primary);
}

.modal-qty-input:focus,
.modal-discount-input:focus {
  outline: none;
  border-color: #0d6efd;
}

.modal-discount-suffix {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: -0.25rem;
}

/* Ocultar spinners de inputs numéricos */
.modal-qty-input::-webkit-outer-spin-button,
.modal-qty-input::-webkit-inner-spin-button,
.modal-discount-input::-webkit-outer-spin-button,
.modal-discount-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.modal-qty-input[type=number],
.modal-discount-input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.modal-price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-border);
}

.modal-price-label {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.modal-price-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: #22c55e;
}

.product-qty-modal-footer {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--color-border);
}

.btn-modal-delete {
  flex: 0 0 auto;
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  border: none;
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-modal-delete:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* ============================================
   CRITICAL: Prevent zoom on mobile devices
   ============================================ */
@media screen and (max-width: 767px) {
  /* Force everything to fit in viewport */
  html, body, .app-layout, .main-content, main {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    width: 100% !important;
  }

  /* Topbar: single row, no wrap, reduced height */
  .topbar {
    padding: 0.35rem 0 !important;
  }

  .topbar .container-fluid {
    flex-wrap: nowrap !important;
    padding: 0.35rem 0.5rem !important;
  }

  /* Hamburger button: no background, larger, more prominent */
  #sidebarToggle {
    background: transparent !important;
    border: none !important;
    width: auto !important;
    height: auto !important;
    padding: 0.25rem !important;
    margin-right: 0.75rem !important;
  }

  #sidebarToggle i {
    font-size: 1.5rem !important;
    color: var(--text-primary) !important;
  }

  /* Hide inline search on mobile, show search button instead */
  .topbar-search {
    display: none !important;
  }

  .topbar-search-btn {
    display: flex !important;
  }

  /* Reduce space between topbar and content - aggressive */
  .main-content {
    padding-top: 0.25rem !important;
  }

  .main-content > .container-fluid,
  .main-content > .container {
    padding-top: 0.25rem !important;
  }

  /* Reduce filter form heights - only in app layout, not login */
  .app-layout .card-header {
    padding: 0.5rem 0.75rem !important;
  }

  .app-layout .form-select,
  .app-layout .form-control {
    padding: 0.35rem 0.5rem !important;
    font-size: 0.85rem !important;
    height: auto !important;
    min-height: 32px !important;
  }

  .app-layout .btn-sm {
    padding: 0.3rem 0.6rem !important;
    font-size: 0.8rem !important;
  }

  /* Client lists: hide address column on mobile */
  .client-address-col {
    display: none !important;
  }

  /* Quotations: hide date and total columns on mobile */
  .quotation-date-col,
  .quotation-total-col {
    display: none !important;
  }

  /* Optimize table spacing on mobile */
  .table {
    font-size: 0.85rem !important;
  }

  .table th,
  .table td {
    padding: 0.5rem 0.25rem !important;
    vertical-align: middle !important;
  }

  /* Client names: single row, smaller font, ellipsis for very long names */
  .table td {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 200px !important;
  }

  /* Reduce city column width */
  .table td:nth-child(3) {
    max-width: 80px !important;
    font-size: 0.75rem !important;
  }

  /* Reduce Nro column width in quotations and invoices */
  .table td:first-child {
    max-width: 70px !important;
    font-size: 0.75rem !important;
  }

  /* Reduce status badge column width */
  .table td:last-child {
    max-width: 42px !important;
    padding: 0.25rem 0.15rem !important;
  }

  .table td:last-child .badge {
    font-size: 0.65rem !important;
    padding: 0.2rem 0.3rem !important;
    min-width: 24px !important;
  }

  /* Reduce Estado header text size */
  .table th:last-child {
    font-size: 0.7rem !important;
    padding: 0.4rem 0.15rem !important;
  }

  /* Invoices: hide date and balance columns on mobile */
  .invoice-date-col,
  .invoice-balance-col {
    display: none !important;
  }

  /* Client detail tabs: proper horizontal table, override ALL global .table td rules */
  .cdf-tabs .table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .cdf-tabs .table th,
  .cdf-tabs .table td,
  .cdf-tabs .table td:first-child,
  .cdf-tabs .table td:nth-child(2),
  .cdf-tabs .table td:nth-child(3),
  .cdf-tabs .table td:last-child,
  .cdf-tabs .table th:last-child {
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: unset !important;
    max-width: none !important;
    display: table-cell !important;
    font-size: 0.78rem !important;
    padding: 0.35rem 0.5rem !important;
  }
  .cdf-tabs .table td:last-child .badge {
    font-size: 0.7rem !important;
    min-width: auto !important;
  }

  /* Products: hide table, show cards - CRITICAL */
  .table-responsive.products-table-view,
  .products-table-view,
  div.products-table-view {
    display: none !important;
    visibility: hidden !important;
  }

  div.products-cards-view,
  .products-cards-view {
    display: flex !important;
    visibility: visible !important;
    flex-direction: column !important;
    gap: 0.4rem !important;
    padding: 0.5rem !important;
  }

  .product-card {
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 0.5rem 0.6rem;
    transition: all 0.2s;
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    grid-template-rows: auto auto;
    column-gap: 0.5rem;
    row-gap: 0.3rem;
    align-items: center;
  }

  .product-code {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    grid-column: 1;
    grid-row: 1;
    color: #2563eb;
    text-decoration: none;
    cursor: pointer;
  }

  .product-code:hover {
    color: #1d4ed8;
    text-decoration: underline;
  }

  .product-card-size {
    grid-column: 2;
    grid-row: 1;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
  }

  .product-price {
    font-size: 1.15rem;
    font-weight: 700;
    white-space: nowrap;
    color: var(--text-primary);
    text-align: right;
    grid-column: 3;
    grid-row: 1;
  }

  .product-card-row2 {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    grid-column: 1 / 4;
    grid-row: 2;
    flex-wrap: wrap;
    font-size: 0.75rem;
  }

  .product-card-linea {
    color: #2563eb;
    white-space: nowrap;
  }

  .product-card-sublinea {
    color: #7c3aed;
    white-space: nowrap;
  }

  .product-card-stock {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    white-space: nowrap;
  }

  .product-card-stock.stock-ok {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
  }

  .product-card-stock.stock-low {
    background: rgba(234, 179, 8, 0.15);
    color: #eab308;
  }

  .product-card-stock.stock-out {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
  }

  .product-card-action {
    grid-column: 4;
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
  }

  .btn-add-cart {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.5rem;
    border: none;
    background: #0d6efd;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .btn-add-cart:hover {
    background: #0b5ed7;
    transform: scale(1.05);
  }

  .btn-add-cart:active {
    transform: scale(0.95);
  }

  .btn-add-cart.in-cart {
    background: #22c55e;
  }

  .cart-qty-badge {
    font-size: 0.75rem;
    font-weight: 700;
    color: #22c55e;
    text-align: center;
  }

  /* Modal de cantidad/descuento */
  .product-qty-modal {
    position: fixed;
    inset: 0;
    z-index: 10600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
  }

  .product-qty-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
  }

  .product-qty-modal-content {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  }

  .product-qty-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
  }

  .product-qty-modal-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
  }

  .btn-close-modal {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
  }

  .btn-close-modal:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
  }

  .product-qty-modal-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .modal-product-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
  }

  .modal-qty-row,
  .modal-discount-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .modal-qty-row label,
  .modal-discount-row label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
  }

  .modal-qty-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .btn-modal-qty {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.5rem;
    border: 1px solid var(--color-border);
    background: var(--color-surface-alt);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.15s;
  }

  .btn-modal-qty:hover {
    background: #0d6efd;
    color: white;
    border-color: #0d6efd;
  }

  .modal-qty-input {
    width: 4rem;
    height: 2.5rem;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    background: var(--color-surface-alt);
    color: var(--text-primary);
  }

  .modal-qty-input:focus {
    outline: none;
    border-color: #0d6efd;
  }

  .modal-discount-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .modal-discount-input {
    width: 4rem;
    height: 2.5rem;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    background: var(--color-surface-alt);
    color: var(--text-primary);
  }

  .modal-discount-input:focus {
    outline: none;
    border-color: #0d6efd;
  }

  .modal-discount-suffix {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-left: -0.25rem;
  }

  /* Ocultar spinners de inputs numéricos */
  .modal-qty-input::-webkit-outer-spin-button,
  .modal-qty-input::-webkit-inner-spin-button,
  .modal-discount-input::-webkit-outer-spin-button,
  .modal-discount-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }

  .modal-qty-input[type=number],
  .modal-discount-input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
  }

  .modal-price-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
  }

  .modal-price-label {
    font-size: 0.95rem;
    color: var(--text-secondary);
  }

  .modal-price-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #22c55e;
  }

  .product-qty-modal-footer {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--color-border);
  }

  .btn-modal-delete {
    flex: 0 0 auto;
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    border: none;
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
  }

  .btn-modal-delete:hover {
    background: #ef4444;
    color: white;
  }

  .btn-modal-confirm {
    flex: 1;
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    border: none;
    background: #0d6efd;
    color: white;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
  }

  .btn-modal-confirm:hover {
    background: #0b5ed7;
  }
  
  /* Container must not exceed screen width */
  .container-xxl, .container-xl, .container-lg, 
  .container-md, .container-sm, .container,
  .container-fluid {
    max-width: 100% !important;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
    width: 100% !important;
  }
  
  /* Cards and shells */
  .dashboard-shell, .products-shell, .card {
    max-width: 100% !important;
    width: 100% !important;
  }
  
  /* Tables must scroll horizontally, not expand page */
  .table-responsive {
    display: block !important;
    width: 100% !important;
    overflow-x: auto !important;
    max-width: 100% !important;
  }
  
  table.table {
    min-width: 0 !important;
    width: 100% !important;
  }
  
  /* Force all table cells to not have fixed widths */
  table th, table td {
    width: auto !important;
    min-width: auto !important;
  }
}

/* Tablets (768px - 1024px) */
@media (max-width: 1024px) {
  /* Reducir padding en containers */
  .dashboard-shell {
    padding: 0.75rem;
  }
  
  .card {
    margin-bottom: 0.75rem;
  }
  
  /* Hacer tablas scrolleables horizontalmente */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Reducir tamaño de fuentes en tablas */
  .table {
    font-size: 0.85rem;
  }
  
  .table th,
  .table td {
    padding: 0.4rem 0.35rem;
    white-space: nowrap;
  }
  
  /* Botones más compactos pero touch-friendly */
  .btn {
    min-height: 40px;
    padding: 0.4rem 0.75rem;
  }
  
  /* Forms más amigables */
  .form-control,
  .form-select {
    min-height: 40px;
    font-size: 16px; /* Evita zoom en iOS */
    padding: 0.4rem 0.6rem;
  }

  /* Topbar: evitar que se rompa en varias líneas en tablet/móvil */
  .topbar .container-fluid {
    flex-wrap: nowrap;
    gap: 0.5rem;
  }

  /* Barra de búsqueda más corta para que quepa junto con logo y acciones */
  .topbar-search {
    width: auto !important;
    max-width: 45vw;
    min-width: 8rem;
    margin-inline: 0.25rem;
  }

  .topbar-search .form-control {
    height: 2.1rem;
    font-size: 0.85rem;
  }

  /* En anchos <=1024, el topbar no debe ser fixed para no tapar contenido */
  .topbar {
    position: static;
  }

  .app-layout {
    padding-top: 0;
    min-height: auto;
  }
}

/* Search modal (mobile only) */
.search-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
}

.search-modal.show {
  display: flex;
}

.search-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
}

.search-modal-content {
  position: relative;
  z-index: 1;
  background: var(--color-surface);
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.search-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.search-modal-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.btn-close-search {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.25rem;
  padding: 0.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.btn-close-search:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-primary);
}

.search-modal-body {
  padding: 1.5rem 1.25rem;
}

.search-modal-body .form-control {
  font-size: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
}

/* Hide search button on desktop */
@media (min-width: 768px) {
  .topbar-search-btn {
    display: none !important;
  }

  /* Hide product cards on desktop */
  .products-cards-view {
    display: none !important;
  }
}

/* Móviles (< 768px) */
@media (max-width: 767px) {
  /* Reducir márgenes laterales globalmente */
  .dashboard-shell,
  .products-shell {
    padding: 0.25rem;
  }
  
  /* Hero sections más compactos */
  .dashboard-hero {
    padding: 1rem 0.75rem;
  }
  
  .dashboard-hero__title {
    font-size: 1.35rem;
  }
  
  .dashboard-hero__subtitle {
    font-size: 0.85rem;
  }
  
  /* 1) En móvil (<=767px), la primera columna en ocultarse debe ser Nombre */
  .table .d-none-mobile-name {
    display: none !important;
  }

  /* Hacer cards de módulos en columna única */
  .products-modules__grid,
  .clients-modules__grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
  }
  
  /* Paginación más compacta */
  .pagination {
    font-size: 0.8rem;
  }
  
  .pagination .page-link {
    padding: 0.3rem 0.5rem;
    min-height: 36px;
    min-width: 36px;
  }
  
  /* Filtros en columna única */
  .row.g-3 > [class*="col-"] {
    width: 100%;
    margin-bottom: 0.5rem;
  }
  
  /* Navbar más compacto */
  .navbar-brand {
    font-size: 1rem;
  }

  /* Topbar: single row */
  .topbar .container-fluid {
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding: 0.5rem;
  }
  
  /* Cards más compactos - REDUCIR PADDING LATERAL */
  .card-body {
    padding: 0.6rem;
  }
  
  .card-header {
    padding: 0.5rem 0.6rem;
  }
  
  /* Badges y códigos más legibles */
  code {
    font-size: 0.8rem;
    padding: 0.15rem 0.35rem;
  }
  
  .badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.45rem;
  }

  /* En móvil, el topbar no debe ser fixed para que no tape el contenido */
  .topbar {
    position: static;
  }

  .app-layout {
    padding-top: 0;
    min-height: auto;
  }
  
  /* Botones en cards header stack verticalmente */
  .card-header .row {
    flex-direction: column;
    gap: 0.35rem;
  }
  
  .card-header .text-end {
    text-align: left !important;
  }
  
  /* Formularios de búsqueda más amigables */
  #search,
  input[type="search"] {
    font-size: 16px; /* Evita zoom en iOS */
    padding: 0.5rem;
  }
  
  /* Mejorar touch targets - más pequeños pero funcionales */
  a,
  button,
  .btn,
  .page-link,
  .form-check-input {
    min-height: 38px;
    min-width: 38px;
  }
  
  /* TABLAS OPTIMIZADAS PARA MÓVIL */
  .table-dark {
    font-size: 0.8rem;
  }
  
  .table-dark th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 0.4rem 0.25rem;
    white-space: nowrap;
  }
  
  .table-dark td {
    padding: 0.4rem 0.25rem;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  /* Hacer tablas con scroll horizontal suave */
  .table-responsive {
    border-radius: 0.375rem;
    margin: 0 -0.6rem;
    padding: 0 0.6rem;
  }
  
  /* Forms más compactos en móvil */
  .form-control,
  .form-select {
    min-height: 38px;
    padding: 0.35rem 0.5rem;
    font-size: 15px;
  }
  
  .form-label {
    font-size: 0.8rem;
    margin-bottom: 0.2rem;
  }
  
  /* Filtros de formulario más compactos */
  .row.g-3 {
    --bs-gutter-y: 0.5rem;
    --bs-gutter-x: 0.5rem;
  }
}

/* 2) En pantallas más angostas (<=575.98px), ocultar también Línea */
@media (max-width: 575.98px) {
  .table .d-none-mobile-line {
    display: none !important;
  }
}

/* Móviles pequeños (< 480px) */
@media (max-width: 479px) {
  /* Reducir aún más el padding */
  .dashboard-shell {
    padding: 0.35rem;
  }
  
  .card {
    border-radius: 0.5rem;
  }
  
  .card-body {
    padding: 0.5rem;
  }
  
  /* Hero aún más compacto */
  .dashboard-hero {
    padding: 0.75rem 0.5rem;
  }
  
  .dashboard-hero__title {
    font-size: 1.15rem;
  }
  
  .dashboard-hero__subtitle {
    font-size: 0.8rem;
    display: none; /* Ocultar subtítulo en pantallas muy pequeñas */
  }
  
  /* Tablas ultra compactas */
  .table {
    font-size: 0.75rem;
  }
  
  .table th,
  .table td {
    padding: 0.3rem 0.2rem;
  }
  
  /* Códigos más pequeños */
  code {
    font-size: 0.7rem;
    padding: 0.1rem 0.25rem;
  }
  
  /* Paginación minimalista */
  .pagination {
    font-size: 0.75rem;
  }
  
  .pagination .page-link {
    padding: 0.2rem 0.4rem;
    min-height: 32px;
    min-width: 32px;
  }
  
  /* 3) En el ancho más estrecho, ocultar también Sublínea */
  .table .d-none-mobile {
    display: none !important;
  }
  
  /* Forms ultra compactos */
  .form-control,
  .form-select {
    min-height: 36px;
    padding: 0.3rem 0.4rem;
    font-size: 14px;
  }
  
  /* Ocultar columna SALDO en tablas de cotizaciones/facturas en móvil pequeño */
  .table th:nth-child(4),
  .table td:nth-child(4) {
    display: none;
  }
}

/* Landscape en móviles */
@media (max-width: 767px) and (orientation: landscape) {
  /* Aprovechar más el ancho en landscape */
  .dashboard-shell {
    padding: 0.5rem;
  }
  
  .dashboard-hero {
    padding: 1rem;
  }
  
  /* Tablas pueden mostrar más columnas */
  .table {
    font-size: 0.85rem;
  }
}

/* Touch-friendly: aumentar áreas clickeables */
@media (hover: none) and (pointer: coarse) {
  /* Dispositivos táctiles */
  .table tbody tr {
    cursor: pointer;
  }
  
  .table tbody tr:active {
    background-color: rgba(59, 130, 246, 0.1);
  }
  
  /* Botones más grandes */
  .btn {
    min-height: 48px;
    padding: 0.75rem 1.25rem;
  }
  
  /* Links más espaciados */
  a {
    padding: 0.25rem;
  }
  
  /* Form controls más grandes */
  .form-control,
  .form-select {
    min-height: 48px;
    font-size: 16px;
  }
  
  /* Checkboxes y radios más grandes */
  .form-check-input {
    width: 1.5rem;
    height: 1.5rem;
  }
}

/* Optimizaciones de performance para móvil */
@media (max-width: 767px) {
  /* Reducir animaciones en móvil */
  * {
    animation-duration: 0.2s !important;
    transition-duration: 0.2s !important;
  }
  
  /* Simplificar sombras */
  .card,
  .btn {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
  }
  
  /* Desactivar efectos hover en touch */
  .table tbody tr:hover {
    background-color: inherit;
  }
}

/* Light mode adjustments para móvil */
@media (max-width: 767px) {
  .card {
    border: 1px solid var(--color-border);
  }
}

/* Utilidades responsive */
.mobile-only {
  display: none;
}

@media (max-width: 767px) {
  .mobile-only {
    display: block;
  }
  
  .desktop-only {
    display: none !important;
  }
}

/* Sticky headers en tablas para móvil (sin scroll interno) */
@media (max-width: 767px) {
  .table thead th {
    position: sticky;
    top: 0;
    background-color: var(--color-surface);
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  }
  /* Forzar que no haya scroll interno en el contenedor de la tabla */
  .card .table-responsive {
    max-height: none !important;
    overflow-y: visible !important;
  }
}

/* Mejoras de accesibilidad en móvil */
@media (max-width: 767px) {
  /* Aumentar tamaño de texto para mejor legibilidad */
  body {
    font-size: 16px;
    line-height: 1.6;
  }
  
  /* Mejorar contraste de texto secundario */
  .text-muted {
    color: var(--text-secondary) !important;
  }
  
  /* Espaciado entre elementos interactivos */
  .btn + .btn,
  .form-control + .form-control {
    margin-top: 0.5rem;
  }
}

/* Optimización de tabla de productos para móvil */
@media (max-width: 767px) {
  /* Ocultar Línea y Sublínea en tablets/móvil */
  .products-table-quick .cr-hide-line,
  .products-table-quick .cr-hide-subline {
    display: none !important;
  }
  
  .products-table-quick {
    font-size: 0.8rem;
  }
  
  .products-table-quick th,
  .products-table-quick td {
    padding: 0.4rem 0.3rem;
  }
  
  .products-table-quick code {
    font-size: 0.75rem;
  }
}

@media (max-width: 575px) {
  /* Ocultar también Stock */
  .products-table-quick .cr-hide-stock {
    display: none !important;
  }
  
  .products-table-quick {
    font-size: 0.75rem;
  }
  
  .products-table-quick th,
  .products-table-quick td {
    padding: 0.35rem 0.2rem;
  }
}

@media (max-width: 479px) {
  /* Ocultar también Size - solo quedan: Código, Cant, Precio */
  .products-table-quick .cr-hide-size {
    display: none !important;
  }
  
  .products-table-quick {
    font-size: 0.7rem;
  }
  
  .products-table-quick th,
  .products-table-quick td {
    padding: 0.3rem 0.15rem;
  }
  
  .products-table-quick code {
    font-size: 0.65rem;
  }
}

/* ============================================
   ESTILOS ESPECÍFICOS PARA TABLAS DE COTIZACIONES/FACTURAS
   ============================================ */

/* Móvil: Optimizar tabla de cotizaciones/facturas */
@media (max-width: 767px) {
  /* Columna Cliente: truncar nombres largos */
  .table td:nth-child(2) {
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  /* Columna Fecha: formato compacto */
  .table td:nth-child(3) {
    white-space: nowrap;
    font-size: 0.75rem;
  }
  
  /* Columna Total: compacta */
  .table td:nth-child(4) {
    white-space: nowrap;
    font-size: 0.8rem;
  }
  
  /* Badge de estado más compacto */
  .table .badge {
    font-size: 0.65rem;
    padding: 0.2rem 0.35rem;
  }
}

/* Móvil pequeño: ocultar columna SALDO si existe */
@media (max-width: 479px) {
  /* En tablas de facturas, ocultar saldo */
  .table th:contains("SALDO"),
  .table td:nth-child(5):not(:last-child) {
    display: none;
  }
  
  /* Cliente aún más corto */
  .table td:nth-child(2) {
    max-width: 70px;
  }
}

/* ============================================
   ESTILOS ESPECÍFICOS PARA LISTA DE PRODUCTOS
   ============================================ */

@media (max-width: 767px) {
  /* Controles de cantidad más compactos */
  .qty-controls {
    grid-template-columns: 1.2rem 1.5rem 1.2rem !important;
    gap: 0.1rem !important;
  }
  
  .btn-qty-list {
    width: 1.2rem !important;
    height: 1.2rem !important;
    font-size: 0.7rem !important;
  }
  
  .qty-value {
    min-width: 1.5rem !important;
    font-size: 0.8rem !important;
  }
  
  .th-qty, .td-qty {
    width: auto !important;
    min-width: auto !important;
  }
  
  /* Precio más compacto */
  .products-table-quick td:last-child {
    font-size: 0.75rem;
    white-space: nowrap;
  }
}

@media (max-width: 479px) {
  .qty-controls {
    grid-template-columns: 1rem 1.2rem 1rem !important;
  }
  
  .btn-qty-list {
    width: 1rem !important;
    height: 1rem !important;
    font-size: 0.65rem !important;
  }
  
  .qty-value {
    min-width: 1.2rem !important;
    font-size: 0.7rem !important;
  }
}

/* ============================================
   FILTROS DE FORMULARIO OPTIMIZADOS PARA MÓVIL
   ============================================ */

@media (max-width: 767px) {
  /* Filtros en fila horizontal cuando sea posible */
  .card-body .row.g-3 {
    display: flex;
    flex-wrap: wrap;
  }
  
  /* Búsqueda ocupa todo el ancho */
  .card-body .row.g-3 .col-md-5,
  .card-body .row.g-3 .col-md-12 {
    flex: 0 0 100%;
  }
  
  /* Periodo y Estado en 2 columnas */
  .card-body .row.g-3 .col-md-3,
  .card-body .row.g-3 .col-md-4 {
    flex: 0 0 50%;
    max-width: 50%;
  }
  
  /* Botones de acción más compactos */
  .catalog-filter-actions {
    margin-top: 0.25rem !important;
  }
  
  .catalog-filter-actions .btn {
    padding: 0.25rem 0.6rem !important;
    font-size: 0.75rem !important;
    min-height: 32px !important;
  }
}

@media (max-width: 479px) {
  /* En pantallas muy pequeñas, todo en columna */
  .card-body .row.g-3 .col-md-3,
  .card-body .row.g-3 .col-md-4 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* ============================================
   ESTILOS ESPECÍFICOS PARA REPORTES
   ============================================ */

@media (max-width: 767px) {
  /* Reportes: Gráfico de crédito/contado más compacto */
  .col-12.col-lg-4,
  .col-12.col-lg-8 {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }
  
  /* Hacer que las métricas del reporte sean más compactas */
  .col-12.col-lg-4 .p-3,
  .col-12.col-lg-8 .p-3 {
    padding: 0.75rem !important;
  }
  
  /* Gráfico de barras de crédito/contado */
  .col-12.col-lg-8 .position-relative {
    min-height: 20px !important;
  }
  
  .col-12.col-lg-8 .text-center.fw-bold {
    font-size: 14px !important;
  }
  
  /* Barras de crédito/contado más compactas */
  .col-12.col-lg-8 > div > div[style*="height: 52px"] {
    height: 40px !important;
  }
  
  /* Texto dentro de las barras más pequeño */
  .col-12.col-lg-8 [data-report-mix] {
    font-size: 12px !important;
    font-weight: 700 !important;
  }
  
  /* Labels debajo de las barras */
  .col-12.col-lg-8 [data-report-mix-label] span {
    font-size: 0.7rem !important;
  }
  
  /* Métricas en columna en móvil */
  .col-12.col-lg-4 .d-flex.justify-content-between {
    font-size: 0.85rem;
  }
  
  .col-12.col-lg-4 .text-muted.small {
    font-size: 0.75rem !important;
  }
  
  .col-12.col-lg-4 .fw-bold {
    font-size: 0.9rem !important;
  }
  
  /* Tablas de reportes más compactas */
  .col-12.col-lg-6 .table {
    font-size: 0.75rem;
  }
  
  .col-12.col-lg-6 .table th,
  .col-12.col-lg-6 .table td {
    padding: 0.3rem 0.2rem;
  }
  
  /* Títulos de secciones de reportes */
  .col-12.col-lg-6 .text-muted.fw-semibold.fs-6 {
    font-size: 0.9rem !important;
  }
}

@media (max-width: 479px) {
  /* En móvil pequeño, reducir aún más */
  .dashboard-shell,
  .products-shell {
    padding: 0.15rem;
  }
  
  .col-12.col-lg-4 .p-3,
  .col-12.col-lg-8 .p-3 {
    padding: 0.5rem !important;
  }
  
  /* Barras aún más compactas */
  .col-12.col-lg-8 > div > div[style*="height: 52px"],
  .col-12.col-lg-8 > div > div[style*="height: 40px"] {
    height: 35px !important;
  }
  
  .col-12.col-lg-8 [data-report-mix] {
    font-size: 11px !important;
  }
}

/* Optimización para páginas de detalle (cotizaciones, facturas) en móvil */
@media (max-width: 767px) {
  /* Títulos más compactos */
  .card-body h2,
  .card-body .h2 {
    font-size: 1.25rem !important;
  }
  
  .card-body h3,
  .card-body .h3 {
    font-size: 1.1rem !important;
  }
  
  .card-body h4,
  .card-body .h4 {
    font-size: 1rem !important;
  }
  
  /* Párrafos y texto más compactos */
  .card-body p {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
  }
  
  .card-body strong {
    font-size: 0.85rem;
  }
  
  /* Badges más pequeños */
  .badge {
    font-size: 0.75rem !important;
    padding: 0.25rem 0.5rem;
  }
  
  /* Tablas de items en detalle de cotización/factura */
  .card-body .table {
    font-size: 0.75rem;
  }
  
  .card-body .table th,
  .card-body .table td {
    padding: 0.35rem 0.25rem;
  }
  
  /* Totales y subtotales más compactos */
  .card-body .row.mb-4 {
    margin-bottom: 1rem !important;
  }
  
  /* Reducir padding de cards en detalle */
  .card-body {
    padding: 0.75rem;
  }
  
  .card-body.border-bottom {
    padding-bottom: 0.75rem;
  }
  
  /* Botones en header de detalle ya optimizados en el HTML */
  .btn-sm {
    font-size: 0.8rem;
    padding: 0.35rem 0.6rem;
  }
}

/* Para pantallas muy pequeñas, reducir aún más */
@media (max-width: 479px) {
  .card-body h2,
  .card-body .h2 {
    font-size: 1.1rem !important;
  }
  
  .card-body h4,
  .card-body .h4 {
    font-size: 0.95rem !important;
  }
  
  .card-body p {
    font-size: 0.85rem;
  }
  
  .card-body .table {
    font-size: 0.7rem;
  }
  
  .card-body .table th,
  .card-body .table td {
    padding: 0.3rem 0.2rem;
  }
}
