/* ═══════════════════════════════════════════════════════════════════════════
   Carenas POS — Mejoras visuales, accesibilidad y diseño móvil (iPhone/iPad)
   Mantiene escritorio familiar y adapta todo el sistema a pantallas pequeñas.
   ═══════════════════════════════════════════════════════════════════════════ */

/* 1. Arreglo global: permitir scroll horizontal real en tablas (.tw) */
.tw {
  overflow-x: auto !important;
  overflow-y: visible !important;
  -webkit-overflow-scrolling: touch;
}

/* 2. Arreglo global de contraste: .btn.bgh legible sobre fondos claros */
.btn.bgh,
.ghost-btn {
  background: #FAF7F2 !important;
  color: #374151 !important;
  border: 1px solid #D7D0C4 !important;
}
.btn.bgh:hover,
.ghost-btn:hover {
  background: #F3ECE0 !important;
  color: #111827 !important;
  border-color: #C4B8A3 !important;
}

/* Mantener estilo claro solo dentro de la barra superior oscura */
.topbar .btn.bgh,
.topbar .ghost-btn {
  background: transparent !important;
  color: #E5E7EB !important;
  border: 1px solid rgba(255, 255, 255, 0.16) !important;
}
.topbar .btn.bgh:hover,
.topbar .ghost-btn:hover {
  color: #FFFFFF !important;
  border-color: #F6D06A !important;
  background: rgba(216, 155, 0, 0.14) !important;
}

/* Botón Menú móvil (oculto en escritorio) */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 11px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #F8FAFC;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.mobile-menu-btn:hover {
  border-color: #F6D06A;
  background: rgba(216, 155, 0, 0.16);
}

/* Drawer de navegación rápida para móvil */
.mobile-drawer-bg {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 950;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  align-items: flex-end;
  justify-content: center;
}
.mobile-drawer-bg.open {
  display: flex;
}
.mobile-drawer {
  width: 100%;
  max-width: 540px;
  max-height: 86vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #FFFFFF;
  border-radius: 22px 22px 0 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -16px 40px rgba(15, 23, 42, 0.25);
  border-top: 1px solid #E7DFD2;
}
.mobile-drawer-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: #D6CFC2;
  margin: 0 auto 12px;
}
.mobile-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.mobile-drawer-title {
  font-size: 16px;
  font-weight: 800;
  color: #1F2937;
}
.mobile-drawer-sub {
  font-size: 12px;
  color: #6B7280;
  margin-top: 2px;
}
.mobile-drawer-close {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid #E5DFD3;
  background: #FAF7F2;
  color: #374151;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.mobile-drawer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.mobile-drawer-item {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #EAE2D5;
  background: #FFFFFF;
  color: #1F2937;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.mobile-drawer-item.active {
  background: #FFF8E8;
  border-color: rgba(216, 155, 0, 0.5);
  color: #1F2937;
  font-weight: 700;
}
.mobile-drawer-item .nav-icon {
  color: #6B7280;
}
.mobile-drawer-item.active .nav-icon {
  color: #B77900;
}
.mobile-drawer-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #EFEAE0;
}
.mobile-drawer-footer .btn {
  min-height: 44px;
  font-size: 13px;
}

/* Pantalla de PIN responsiva en cualquier celular */
#sessionGate {
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
#sessionGate > div:last-child {
  width: min(92vw, 360px) !important;
  min-width: 0 !important;
  padding: 24px 20px !important;
  border-radius: 18px !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TABLET & CELULAR (<= 900px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .page {
    padding: 14px 12px calc(28px + env(safe-area-inset-bottom));
  }
  .cuadre-grid {
    grid-template-columns: 1fr;
  }
  .mgr-title {
    font-size: 22px;
  }
  .mgr-select,
  .mgr-review-select {
    min-width: 0;
    width: 100%;
  }
  .mgr-toolbar {
    width: 100%;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   IPHONE / CELULAR (<= 767px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  html,
  body {
    overflow-x: hidden;
  }

  /* Evita el zoom automático molesto de Safari en iPhone al tocar campos */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Barra superior limpia de 1 sola fila */
  .topbar {
    height: auto !important;
    min-height: 54px;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
  }
  .topbar-left {
    min-width: 0;
    gap: 6px !important;
  }
  .brand {
    gap: 7px !important;
    font-size: 15px !important;
  }
  .brand-logo {
    width: 30px !important;
    height: 30px !important;
    border-radius: 8px !important;
  }
  .brand-secondary,
  .pos-badge {
    display: none !important;
  }
  .topbar-right {
    gap: 6px !important;
    flex-wrap: nowrap !important;
    flex-shrink: 0;
  }
  .user-chip {
    padding: 4px 8px !important;
    min-height: 34px !important;
    gap: 6px !important;
  }
  .user-avatar {
    width: 22px !important;
    height: 22px !important;
    font-size: 10px !important;
  }
  .status-copy {
    display: none !important;
  }
  #session-label {
    max-width: 64px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* El botón Cambiar turno pasa dentro del Menú ☰ para no saturar la barra */
  .topbar-turn-btn {
    display: none !important;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .topbar .panel-btn {
    padding: 7px 10px !important;
    min-height: 36px;
    font-size: 12px !important;
  }

  /* Barra de navegación: 1 sola fila deslizable (no tapa media pantalla) */
  .nav {
    position: sticky;
    top: 52px;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 8px 10px !important;
    min-height: 50px !important;
    gap: 6px !important;
  }
  .nav::-webkit-scrollbar {
    display: none;
  }
  .nb {
    flex: 0 0 auto;
    min-height: 36px !important;
    padding: 0 12px !important;
    font-size: 12.5px !important;
  }

  /* Restaurar visibilidad limpia de los avisos importantes en iPhone */
  .moroso-banner,
  .moroso-banner.show,
  #cajaBanner {
    padding: 8px 12px !important;
    gap: 6px !important;
  }
  .banner-text,
  .banner-main #morosoCount,
  #cajaBannerMsg {
    display: inline !important;
    font-size: 12px !important;
  }
  .banner-actions {
    width: 100%;
    justify-content: flex-end;
  }

  /* Inicio: cuadrícula limpia de 2 columnas en iPhone */
  .home-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  .hcard {
    padding: 13px 12px !important;
    min-height: 112px !important;
    gap: 6px !important;
    border-radius: 14px !important;
  }
  .hct {
    font-size: 13px !important;
  }
  .hcs {
    font-size: 11px !important;
    line-height: 1.3 !important;
  }
  .hcn {
    font-size: 18px !important;
  }

  /* Resumen del día: 2 columnas cómodas */
  .sgrid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .si {
    min-width: 0 !important;
    padding: 11px 12px !important;
    border-right: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
  }
  .si:last-child {
    grid-column: 1 / -1;
    border-right: none !important;
    border-bottom: none !important;
  }
  .sv {
    font-size: 16px !important;
  }

  /* Tarjetas de métricas y secciones */
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .metric {
    padding: 10px 12px !important;
  }
  .mv {
    font-size: 16px !important;
  }
  .card,
  .owner-section,
  .mgr-hero,
  .mgr-section,
  .client-news-board,
  .tasks-board {
    padding: 14px 12px !important;
    border-radius: 14px !important;
  }

  /* Formularios, botones y acciones fáciles de tocar con el pulgar */
  .fg {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .br {
    gap: 8px !important;
  }
  .br .btn,
  .mgr-actions .btn {
    min-height: 42px;
    flex: 1 1 130px;
  }
  .service-btns {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .svc-btn {
    padding: 11px 8px !important;
  }
  .debt-list {
    grid-template-columns: 1fr !important;
  }
  .debt-grid {
    gap: 6px !important;
  }
  .debt-stat {
    padding: 7px 6px !important;
  }
  .debt-stat-value {
    font-size: 13px !important;
  }

  /* Panel de Dueña: botones de sección en 2 columnas limpias */
  .owner-nav-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .owner-nav-btn {
    padding: 12px 8px !important;
    border-radius: 12px !important;
  }

  /* Cuadre: filas legibles sin desbordar */
  .mgr-row {
    gap: 6px !important;
    padding: 10px 0 !important;
  }
  .mgr-total-value {
    font-size: 22px !important;
  }
  .cuadre-row {
    gap: 8px;
  }

  /* Modales en iPhone */
  .modal-bg {
    padding: 10px !important;
    padding-top: max(12px, env(safe-area-inset-top)) !important;
  }
  .modal {
    padding: 16px 14px !important;
    max-width: 100% !important;
  }
  #modalCerrar .modal > div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Tablas más compactas y fáciles de deslizar */
  table {
    font-size: 12px !important;
  }
  th,
  td {
    padding: 7px 8px !important;
  }

  /* Back link más fácil de tocar */
  .back {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 4px 10px 4px 2px !important;
    font-size: 13px !important;
    margin-bottom: 8px !important;
  }

  .wa-opp-grid {
    grid-template-columns: 1fr !important;
  }
  .wa-opp-item {
    flex-direction: column;
    align-items: flex-start !important;
  }
}

/* ── Oportunidades WhatsApp & Perfil 360° ── */
.wa-opp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
}
.wa-opp-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}
.wa-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
}
.wa-badge.hot {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}
.wa-badge.ok {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* ── Bandeja de Solicitudes Online (Oficina Virtual) ── */
.sol-list {
  display: grid;
  gap: 10px;
}
.sol-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-left: 4px solid #cbd5e1;
  border-radius: 12px;
  padding: 13px 14px;
}
.sol-card.nueva {
  border-left-color: #dc2626;
  background: #fffafa;
}
.sol-card.vialink_enviado {
  border-left-color: #7c3aed;
  background: #faf5ff;
}
.sol-card.en_proceso {
  border-left-color: #2563eb;
}
.sol-card.completada {
  border-left-color: #16a34a;
  opacity: 0.88;
}
.sol-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.sol-code {
  font-weight: 800;
  font-size: 12px;
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 2px 9px;
}
.sol-type {
  font-weight: 700;
  font-size: 12.5px;
  color: #0f172a;
}
.sol-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
}
.sol-pill.nueva { background: #fee2e2; color: #b91c1c; }
.sol-pill.vialink { background: #ede9fe; color: #6d28d9; }
.sol-pill.proceso { background: #dbeafe; color: #1d4ed8; }
.sol-pill.ok { background: #dcfce7; color: #166534; }
.sol-pill.canc { background: #f1f5f9; color: #64748b; }
.sol-client {
  font-size: 13.5px;
  color: #0f172a;
  margin-bottom: 5px;
}
.sol-pay {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
  padding: 1px 8px;
  border-radius: 999px;
}
.sol-details {
  font-size: 12px;
  color: #475569;
  line-height: 1.5;
  margin-bottom: 10px;
}
.sol-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.sol-toast {
  position: fixed;
  right: 16px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 9999;
  background: #0f2544;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-left: 4px solid #22c55e;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.35);
  display: none;
  align-items: center;
  gap: 12px;
  max-width: min(380px, calc(100vw - 24px));
}

/* ── Agrupación limpia de Inicio, Nav y Tablero de Crecimiento ── */
.nav-sep {
  display: inline-block;
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.16);
  margin: 0 4px;
  align-self: center;
  flex-shrink: 0;
}
.home-group-title {
  font-size: 11.5px;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 14px 2px 8px;
}
.home-group-title:first-of-type {
  margin-top: 2px;
}
.drawer-group-label {
  font-size: 10.5px;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 10px 2px 6px;
}
.growth-pulse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.gp-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
}
.gp-lbl {
  font-size: 11px;
  color: #64748b;
  font-weight: 600;
}
.gp-val {
  font-size: 18px;
  font-weight: 800;
  margin-top: 3px;
}
@media (max-width: 767px) {
  .growth-pulse-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .gp-val {
    font-size: 16px;
  }
}

@media print {
  .mobile-drawer-bg,
  .mobile-menu-btn {
    display: none !important;
  }
}
