/* ====================================
   MOBILE TOUCH ENHANCEMENTS
   Mejoras para experiencia táctil
   ==================================== */

/* Aumentar área de toque en elementos interactivos */
@media (max-width: 1023px) {

  /* Botones más grandes en móvil */
  .btn {
    min-height: 48px;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    border-radius: 8px;
  }

  .btn-sm {
    min-height: 44px;
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
  }

  /* Links y navegación */
  .nav-item {
    min-height: 52px;
    padding: 1rem 1.25rem;
    font-size: 1rem;
  }

  /* Inputs más grandes */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  select,
  textarea {
    min-height: 48px;
    padding: 0.875rem 1rem;
    font-size: 16px;
    /* Previene zoom automático en iOS */
    border-radius: 8px;
  }

  /* Checkboxes y radios más grandes */
  input[type="checkbox"],
  input[type="radio"] {
    width: 22px;
    height: 22px;
    cursor: pointer;
  }

  /* Tabs más grandes */
  .tab {
    min-height: 48px;
    padding: 0.875rem 1.25rem;
  }

  /* Dropdown items */
  .dropdown-item {
    min-height: 48px;
    padding: 0.875rem 1rem;
  }

  /* Table cells más espaciadas */
  td,
  th {
    padding: 0.875rem 1rem;
  }
}

/* ====================================
   SCROLL IMPROVEMENTS
   ==================================== */

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Mejorar scroll en iOS */
.scrollable {
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
}

/* Scroll horizontal para tablas */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) var(--dark-tertiary);
}

.table-container::-webkit-scrollbar {
  height: 8px;
}

.table-container::-webkit-scrollbar-track {
  background: var(--dark-tertiary);
  border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
  background: var(--secondary-color);
}

/* ====================================
   MOBILE NAVIGATION IMPROVEMENTS
   ==================================== */

/* Bottom navigation bar para móvil */
@media (max-width: 767px) {
  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--dark-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 0.5rem;
    z-index: 50;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    min-width: 60px;
    transition: all 0.3s ease;
  }

  .mobile-nav-item.active {
    color: var(--primary-color);
  }

  .mobile-nav-icon {
    font-size: 1.5rem;
  }

  /* Ajustar contenido para navegación inferior */
  .main-content {
    padding-bottom: 5rem;
  }
}

/* ====================================
   MODAL IMPROVEMENTS MOBILE
   ==================================== */

@media (max-width: 767px) {

  /* Modales optimizados para móvil */
  .modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    animation: slideUpModal 0.3s ease-out;
  }

  @keyframes slideUpModal {
    from {
      transform: translateY(100%);
    }

    to {
      transform: translateY(0);
    }
  }

  .modal-header {
    flex-shrink: 0;
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--dark-secondary);
  }

  .modal-header h2,
  .modal-header h3 {
    font-size: 1.25rem;
    margin: 0;
  }

  .modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.25rem;
    background: var(--dark-bg);
  }

  .modal-footer {
    flex-shrink: 0;
    padding: 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
    background: var(--dark-secondary);
    position: sticky;
    bottom: 0;
  }

  .modal-footer .btn {
    flex: 1;
    min-height: 48px;
  }

  /* Cerrar modal con gesto */
  .modal-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--text-muted);
    border-radius: 2px;
    opacity: 0.4;
  }
}

/* ====================================
   FORM IMPROVEMENTS MOBILE
   ==================================== */

@media (max-width: 767px) {

  /* Labels flotantes en móvil */
  .form-group {
    position: relative;
    margin-bottom: 1.5rem;
  }

  .form-group label {
    position: absolute;
    top: -0.5rem;
    left: 0.75rem;
    background-color: var(--dark-secondary);
    padding: 0 0.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    z-index: 1;
  }

  /* Stack buttons verticalmente */
  .form-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .form-actions .btn {
    width: 100%;
  }

  /* Date y time pickers nativos en móvil */
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"] {
    -webkit-appearance: none;
    appearance: none;
  }
}

/* ====================================
   CARDS IMPROVEMENTS MOBILE
   ==================================== */

@media (max-width: 767px) {

  /* Cards con efecto de elevación al tocar */
  .card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }

  .card:active {
    transform: scale(0.98);
  }

  /* Appointment cards */
  .appointment-card {
    position: relative;
    padding-left: 1rem;
  }

  .appointment-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary-color);
    border-radius: 4px 0 0 4px;
  }

  /* Stat cards en grid compacto */
  .stat-card {
    min-height: 120px;
  }
}

/* ====================================
   TABLE ALTERNATIVES FOR MOBILE
   ==================================== */

@media (max-width: 767px) {

  /* Convertir tabla a cards en móvil */
  .table-mobile-cards {
    display: block;
  }

  .table-mobile-cards thead {
    display: none;
  }

  .table-mobile-cards tbody {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .table-mobile-cards tr {
    display: block;
    background-color: var(--dark-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1rem;
  }

  .table-mobile-cards td {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
  }

  .table-mobile-cards td:last-child {
    border-bottom: none;
  }

  .table-mobile-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 1rem;
  }
}

/* ====================================
   SWIPE GESTURES
   ==================================== */

/* Indicador visual de swipe */
.swipeable {
  position: relative;
  touch-action: pan-y;
}

.swipeable::after {
  content: '';
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 2px;
  background: var(--text-muted);
  opacity: 0.3;
  pointer-events: none;
}

/* ====================================
   PULL TO REFRESH INDICATOR
   ==================================== */

.pull-to-refresh {
  position: relative;
}

.pull-indicator {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.pull-indicator.active {
  opacity: 1;
}

.pull-indicator-icon {
  font-size: 1.5rem;
  animation: rotate 1s linear infinite;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* ====================================
   SAFE AREA INSETS (iPhone X+)
   ==================================== */

@supports (padding: max(0px)) {
  .main-content {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .mobile-nav {
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  }

  .modal {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ====================================
   LANDSCAPE MODE
   ==================================== */

@media (max-width: 767px) and (orientation: landscape) {

  /* Reducir altura de header en landscape */
  .page-header h1 {
    font-size: 1.25rem;
  }

  .stat-card {
    padding: 0.75rem;
  }

  .stat-value {
    font-size: 1.25rem;
  }

  /* Modales más compactos */
  .modal-body {
    padding: 0.75rem;
  }
}

/* ====================================
   ACCESSIBILITY IMPROVEMENTS
   ==================================== */

/* Aumentar contraste en modo de alto contraste */
@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }

  .card {
    border: 2px solid var(--border-color);
  }
}

/* Respetar preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible para navegación por teclado */
:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* ====================================
   PERFORMANCE OPTIMIZATIONS
   ==================================== */

/* GPU acceleration para animaciones */
.sidebar,
.modal,
.toast {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Optimizar fonts en móvil */
@media (max-width: 767px) {
  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }
}

/* ====================================
   TABLE RESPONSIVE STACK
   Convierte tablas en tarjetas elegantes en móvil
   ==================================== */
@media (max-width: 767px) {
  .table-responsive-stack {
    display: block;
    width: 100% !important;
  }

  .table-responsive-stack thead {
    display: none;
    /* Ocultar cabeceras en móvil */
  }

  .table-responsive-stack tbody {
    display: block;
  }

  .table-responsive-stack tr {
    display: block;
    margin-bottom: 1.25rem;
    background: var(--dark-secondary, #1e293b);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease;
  }

  .table-responsive-stack tr:active {
    transform: scale(0.99);
  }

  .table-responsive-stack td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    min-height: 40px;
  }

  .table-responsive-stack td:last-child {
    border-bottom: none;
    margin-top: 0.5rem;
    padding-top: 1rem;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 0 0 8px 8px;
  }

  .table-responsive-stack td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-muted, #94a3b8);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 1rem;
  }

  /* Ajustes para celdas con badges o botones */
  .table-responsive-stack td .badge {
    margin: 0;
  }

  .table-responsive-stack td .action-buttons,
  .table-responsive-stack td .btn-group {
    display: flex;
    gap: 0.5rem;
  }

  /* Celda de acciones: sin etiqueta, centrada y full-width */
  .td-actions {
    justify-content: center !important;
    padding-top: 0.75rem !important;
  }

  .td-actions::before {
    display: none !important;
  }

  /* Botones de acción de tabla de productos — cuadrados y compactos en móvil */
  .products-table-actions {
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 6px !important;
  }

  .products-table-actions .btn-sm {
    min-height: 36px !important;
    min-width: auto !important;
    width: auto !important;
    padding: 0.3rem 0.6rem !important;
    font-size: 0.8rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }
}

/* ============================================================
   NÓMINA — TARJETAS POR BARBERO
   ============================================================ */

/* Grid de tarjetas */
.payroll-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

/* Estado vacío */
.payroll-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

/* Tarjeta individual */
.payroll-barber-card {
  background: var(--bg-card, #1e2130);
  border: 1px solid var(--border-color, #2d3448);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, transform 0.15s;
}

.payroll-barber-card:hover {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  transform: translateY(-1px);
}

/* Cabecera de la tarjeta */
.pbc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-alt, #252b3b);
  border-bottom: 1px solid var(--border-color, #2d3448);
  flex-wrap: wrap;
}

.pbc-identity {
  min-width: 0;
}

.pbc-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary, #f1f5f9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pbc-email {
  font-size: 0.78rem;
  color: var(--text-muted, #6b7280);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Fila de estadísticas */
.pbc-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border-color, #2d3448);
  flex: 1;
}

.pbc-stat {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-right: 1px solid var(--border-color, #2d3448);
}

.pbc-stat:last-child {
  border-right: none;
}

.pbc-stat-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted, #6b7280);
}

.pbc-stat-value {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
}

.pbc-stat-sub {
  font-size: 0.73rem;
  color: var(--text-muted, #6b7280);
}

.pbc-advance {
  font-size: 0.73rem;
  color: #ef4444;
  margin-top: 2px;
}

/* Pie de tarjeta: monto + botón */
.pbc-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.pbc-amounts {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.pbc-total {
  font-size: 1.25rem;
  font-weight: 700;
  color: #10b981;
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.pbc-total span {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-muted, #6b7280);
}

.pbc-paid-info {
  font-size: 0.8rem;
  color: #f59e0b;
  font-weight: 600;
  margin-top: 4px;
}

.pbc-log-item {
  font-size: 0.73rem;
  color: #9ca3af;
  margin-top: 1px;
}

.pbc-pending-info {
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 3px;
}

.pbc-complete {
  font-size: 0.83rem;
  color: #6b7280;
  white-space: nowrap;
}

/* ---- Responsive ---- */
@media (max-width: 767px) {
  .payroll-cards-grid {
    grid-template-columns: 1fr;
  }

  /* En mobile: stats en 2+1 layout */
  .pbc-stats {
    grid-template-columns: 1fr 1fr;
  }

  .pbc-stat:nth-child(2) {
    border-right: none;
  }

  .pbc-stat:nth-child(3) {
    grid-column: 1 / -1;
    border-right: none;
    border-top: 1px solid var(--border-color, #2d3448);
  }

  .pbc-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .pbc-footer .btn {
    width: 100%;
    justify-content: center;
  }
}