/* ============================================================
   miPymeCRM — Responsive Design
   Mobile: < 768px | Tablet: 768-1023px | Desktop: >= 1024px
   Desktop queda intacto — solo se agregan reglas para abajo.
   ============================================================ */

/* ── TOPBAR MOBILE (hamburguesa) ─────────────────────────────
   Visible solo en mobile/tablet. Oculto en desktop via JS class.  */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  background: #0b1628;
  position: sticky;
  top: 0;
  z-index: 200;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.mobile-topbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  color: #fff;
  padding: 0;
}

.mobile-topbar-btn:hover {
  background: rgba(255,255,255,0.08);
}

.mobile-topbar-logo {
  font-size: 0.9rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
}

.mobile-topbar-logo span {
  color: #0ea5e9;
}

/* ── SIDEBAR OVERLAY (drawer mobile) ─────────────────────────*/
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 298;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
  display: block;
}

/* ── TABLAS RESPONSIVE ────────────────────────────────────── */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive table {
  min-width: 600px;
}

/* ── MOBILE (< 768px) ──────────────────────────────────────── */
@media (max-width: 767px) {

  /* Mostrar topbar mobile */
  .mobile-topbar {
    display: flex;
  }

  /* Layout principal: columna */
  .app-layout {
    flex-direction: column;
  }

  /* Sidebar: drawer deslizante */
  .app-sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 260px !important;
    height: 100vh !important;
    z-index: 299;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .app-sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }

  /* Main: ancho completo, sin margen del sidebar */
  .app-main {
    width: 100%;
    min-width: 0;
  }

  /* Reducir padding del contenido */
  .app-main .max-w-7xl {
    padding-left: 12px !important;
    padding-right: 12px !important;
    padding-top: 16px !important;
  }

  /* Dashboard: apilar columnas */
  .dashboard-layout {
    flex-direction: column !important;
    gap: 16px !important;
  }

  .dashboard-panel {
    width: 100% !important;
  }

  /* Mensajes: layout vertical */
  .mensajes-layout {
    flex-direction: column !important;
    height: auto !important;
    min-height: calc(100vh - 52px);
  }

  .mensajes-lista {
    width: 100% !important;
    height: 260px !important;
    border-right: none !important;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0 !important;
  }

  .mensajes-detalle {
    flex: 1;
    min-height: 400px;
  }

  /* KPI cards: 2 columnas en mobile (ya está, refuerzo) */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Ocultar columnas secundarias en tablas mobile */
  .hide-mobile {
    display: none !important;
  }

  /* Notificaciones toasts: ancho adaptado */
  #notification-toasts {
    width: calc(100vw - 24px) !important;
    right: 12px !important;
    top: 60px !important;
  }

  /* Banner de impersonación: texto más corto */
  .impersonation-banner span {
    font-size: 0.75rem;
  }

  /* Formularios: campos full width */
  .form-grid-2 {
    grid-template-columns: 1fr !important;
  }
}

/* ── TABLET (768px – 1023px) ──────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {

  /* Mostrar topbar mobile en tablet también */
  .mobile-topbar {
    display: flex;
  }

  /* Sidebar: drawer en tablet también */
  .app-sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 240px !important;
    height: 100vh !important;
    z-index: 299;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .app-sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }

  /* Main: ancho completo */
  .app-main {
    width: 100%;
  }

  /* Dashboard: apilar panel lateral debajo */
  .dashboard-layout {
    flex-wrap: wrap !important;
  }

  .dashboard-panel {
    width: 100% !important;
  }
}

/* ── DESKTOP (>= 1024px) — SIN CAMBIOS ───────────────────── */
@media (min-width: 1024px) {

  /* Sidebar siempre visible — ocultar topbar mobile */
  .mobile-topbar {
    display: none !important;
  }

  /* Overlay nunca activo en desktop */
  .sidebar-overlay {
    display: none !important;
  }

  /* Sidebar fijo (comportamiento original) */
  .app-sidebar {
    position: sticky !important;
    transform: translateX(0) !important;
    width: 224px !important; /* w-56 = 14rem = 224px */
  }
}

/* ── KANBAN MOBILE ───────────────────────────────────────────── */
@media (max-width: 767px) {
  /* Board: scroll horizontal con snap por columna */
  .kanban-board {
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1rem;
    /* Ocultar scrollbar visualmente en mobile */
    scrollbar-width: none;
  }
  .kanban-board::-webkit-scrollbar { display: none; }

  /* Cada columna ocupa el ancho de la pantalla */
  .kanban-col {
    width: calc(100vw - 2.5rem) !important;
    min-width: calc(100vw - 2.5rem) !important;
    scroll-snap-align: start;
    max-height: calc(100vh - 14rem);
    overflow-y: auto;
  }

  /* Tabs de navegación de etapas */
  .kanban-stage-nav {
    scrollbar-width: none;
  }
  .kanban-stage-nav::-webkit-scrollbar { display: none; }

  /* Altura mínima del tablero en mobile */
  .kanban-board.min-h-\[calc\(100vh-10rem\)\] {
    min-height: auto !important;
  }
}
