/* ============================================================
   Buuble — layout.css
   Estructura global de la aplicación: shell de pantalla completa,
   sidebar colapsable (claro/oscuro) y topbar fija.
   ============================================================ */

/* ============================================================
   1. SHELL DE PANTALLA COMPLETA
   ============================================================ */
.app-shell {
  display: flex;
  width: 100vw;
  height: 100vh;
  height: 100dvh;             /* respeta barra de URL del navegador móvil */
  overflow: hidden;            /* h-screen overflow-hidden */
  background: var(--bg-page);
}

/* Columna de contenido a la derecha del sidebar */
.app-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;               /* permite truncado interno */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Zona de contenido con scroll vertical independiente */
.content-zone {
  flex: 1;
  position: relative; /* contexto para el cuadro inline de "Nueva tarea" */
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-6) var(--space-8);
}

/* ============================================================
   2. SIDEBAR (220px fijo, colapsable a 56px)
   ============================================================ */
.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  transition: width 200ms ease;
  overflow: hidden;
}

/* Botón hamburguesa (topbar) y overlay: ocultos en desktop, activos <900px */
.topbar-menu-btn { display: none; }
.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.sidebar.collapsed {
  width: var(--sidebar-width-collapsed);
}

/* ─── Cabecera del sidebar (logo) ─── */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--topbar-height);
  padding: 0 var(--space-5);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7C6CF0 0%, #4F46E5 55%, #4338CA 100%);
  color: #FFFFFF;
  font-weight: 700;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.35);
}
.sidebar-brand {
  font-size: var(--text-md);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  white-space: nowrap;
}
.sidebar-collapse-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: background 120ms ease, color 120ms ease;
}
.sidebar-collapse-btn:hover { background: var(--bg-overlay); color: var(--text-primary); }

/* ─── Cuerpo de navegación (scrollable) ─── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) var(--space-2);
}
.sidebar-section { margin-bottom: var(--space-4); }
.sidebar-section-label {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  white-space: nowrap;
}

/* ─── Ítem de navegación ─── */
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 36px;
  padding: 0 var(--space-3);
  margin-bottom: 2px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-base);
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms ease, color 150ms ease;
}
.nav-item:hover { background: var(--bg-overlay); color: var(--text-primary); }
.nav-item .nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.nav-item .nav-icon svg { width: 20px; height: 20px; }
.nav-item .nav-label { flex: 1; }

/* Ítem activo: fondo accent-light, texto accent y barra izquierda */
.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: var(--fw-medium);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: var(--radius-pill);
  background: var(--accent);
}

/* Badge contador a la derecha del ítem (Inbox) */
.nav-item .nav-badge { margin-left: auto; }

/* ─── Pie del sidebar: perfil de usuario ─── */
.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: var(--space-3);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  transition: background 120ms ease;
}
.sidebar-user-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms ease;
}
.sidebar-user-link:hover { background: var(--bg-overlay); }
.sidebar-user-info { min-width: 0; flex: 1; }
.sidebar-user-name {
  font-size: var(--text-base);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-email {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: background 120ms ease, color 120ms ease;
}
.sidebar-logout:hover { background: var(--error-bg); color: var(--error); }

/* ─── Estado colapsado: ocultar textos ─── */
.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .sidebar-section-label,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-user-info,
.sidebar.collapsed .sidebar-logout {
  display: none;
}
/* En colapsado el contador no se oculta: se convierte en un punto rojo
   sobre la esquina del icono para que las notificaciones sin leer
   sigan siendo visibles siempre. */
.sidebar.collapsed .nav-item { position: relative; }
.sidebar.collapsed .nav-badge {
  position: absolute;
  top: 4px;
  right: 8px;
  min-width: 9px;
  width: 9px;
  height: 9px;
  padding: 0;
  margin: 0;
  font-size: 0;            /* oculta el número, deja solo el punto */
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
  box-sizing: content-box;
}
.sidebar.collapsed .sidebar-header {
  height: auto;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) 0;
  justify-content: center;
}
/* El botón sigue visible y la flecha apunta a la derecha (expandir) */
.sidebar.collapsed .sidebar-collapse-btn { margin-left: 0; }
.sidebar.collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }
.sidebar.collapsed .nav-item { justify-content: center; padding: 0; }
.sidebar.collapsed .sidebar-user { justify-content: center; padding: var(--space-2) 0; }

/* ============================================================
   3. SIDEBAR — VARIANTE OSCURA (#0F172A)
   ============================================================ */
.sidebar.dark {
  background: var(--bg-sidebar-dark);
  border-right-color: rgba(255, 255, 255, 0.06);
}
.sidebar.dark .sidebar-header { border-bottom-color: rgba(255, 255, 255, 0.06); }
.sidebar.dark .sidebar-brand { color: #F8FAFC; }
.sidebar.dark .sidebar-section-label { color: #64748B; }
.sidebar.dark .nav-item { color: #94A3B8; }
.sidebar.dark .nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #F8FAFC;
}
.sidebar.dark .nav-item.active {
  background: rgba(255, 255, 255, 0.08);
  color: #FFFFFF;
}
.sidebar.dark .nav-item.active::before { background: var(--accent); }
.sidebar.dark .sidebar-collapse-btn { color: #64748B; }
.sidebar.dark .sidebar-collapse-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #F8FAFC;
}
.sidebar.dark .sidebar-footer { border-top-color: rgba(255, 255, 255, 0.06); }
.sidebar.dark .sidebar-user-link:hover { background: rgba(255, 255, 255, 0.06); }
.sidebar.dark .sidebar-user-name { color: #F8FAFC; }
.sidebar.dark .sidebar-user-email { color: #64748B; }
.sidebar.dark .sidebar-logout { color: #64748B; }
.sidebar.dark .sidebar-logout:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #FCA5A5;
}

/* ============================================================
   4. TOPBAR (56px fija)
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--topbar-height);
  flex-shrink: 0;
  padding: 0 var(--space-6);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

/* Izquierda: título de página */
.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}
.topbar-title {
  font-size: var(--text-lg);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Centro: selector de vistas en pills */
.topbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.view-pills {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--bg-overlay);
  border-radius: var(--radius-md);
}
.view-pill {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.view-pill:hover { color: var(--text-primary); }
.view-pill.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Cuando no hay selector de vistas, el centro sólo empuja la derecha */
.topbar-center.is-empty { flex: 1; }

/* Derecha: buscador, filtros y CTA */
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
}
.topbar-search {
  position: relative;
  display: inline-flex;
  align-items: center;
}
/* Botón de búsqueda compacto: sólo visible en móvil (ver media query) */
.topbar-search-btn { display: none; }
.topbar-search svg {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  pointer-events: none;
}
.topbar-search input {
  width: 240px;
  height: 34px;
  padding: 0 10px 0 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-page);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.topbar-search input::placeholder { color: var(--text-tertiary); }
.topbar-search input:focus {
  background: var(--bg-surface);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.topbar-search .kbd {
  position: absolute;
  right: 8px;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  pointer-events: none;
}

/* ============================================================
   5. PRIMITIVAS DE GRID PARA CONTENIDO
   ============================================================ */
.page-section { margin-bottom: var(--space-8); }
.page-section:last-child { margin-bottom: 0; }

/* Contenedor de scroll horizontal para tablas anchas en móvil/tablet */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.grid {
  display: grid;
  gap: var(--grid-gap);
}
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

/* Dos columnas asimétricas 2/3 + 1/3 */
.grid-asymmetric {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--grid-gap);
}

/* ============================================================
   6. RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-asymmetric { grid-template-columns: 1fr; }
}

/* Tablet/móvil: sidebar off-canvas + hamburguesa */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 220ms ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  /* En off-canvas se ignora el modo colapsado: ancho completo siempre */
  .sidebar.collapsed { width: var(--sidebar-width); }
  .sidebar-collapse-btn { display: none; }
  .topbar-menu-btn { display: inline-flex; }
  .sidebar-overlay.visible { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  body.nav-open .content-zone { overflow: hidden; }
}

@media (max-width: 768px) {
  .content-zone { padding: var(--space-4); }
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4 { grid-template-columns: 1fr; }

  /* Topbar compacta: dos filas, pills en tira deslizable */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: var(--space-3) var(--space-4);
    row-gap: var(--space-2);
  }
  /* Buscador completo → icono que abre la paleta global */
  .topbar-search { display: none; }
  .topbar-search-btn { display: inline-flex; }
  /* CTA sólo icono */
  .topbar-right .btn-primary span { display: none; }
  .topbar-right .btn-primary {
    padding: 0;
    width: 36px;
    height: 36px;
    justify-content: center;
  }
  /* Selector de vistas: segunda fila, scroll horizontal */
  .topbar-center:not(.is-empty) {
    order: 3;
    flex-basis: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .topbar-center.is-empty { display: none; }
  .topbar-center .view-pills { flex-wrap: nowrap; }
}
