/* ============================================================
   LAYOUT.CSS — Sidebar, Header, Estructura principal
   Mobile First · Centir · Centro de Psicología · Dashboard
   ============================================================ */

/* ── Wrapper principal ───────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  max-width: 100vw;
  overflow-x: hidden;
}

/* ════════════════════════════════════════════════════════════
   OVERLAY — backdrop del drawer mobile
   ════════════════════════════════════════════════════════════ */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 44, 61, 0.50);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* ════════════════════════════════════════════════════════════
   SIDEBAR — off-canvas drawer (mobile) / fijo (desktop)
   ════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  height: 100dvh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.3s ease;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.sidebar.is-open {
  transform: translateX(0);
  box-shadow: 4px 0 40px rgba(151, 135, 163, 0.22);
}

/* ── Logo + botón cerrar (mobile) ──────────────────────────── */
.sidebar-logo {
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-logo img {
  width: 120px;
  height: auto;
}

.sidebar-close {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  transition: var(--ease);
  flex-shrink: 0;
}

.sidebar-close:hover {
  background: var(--bg);
  color: var(--text);
}

.sidebar-close svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Navegación ──────────────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: var(--space-4) var(--space-3) var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  color: var(--text-medium);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--ease);
  position: relative;
  text-decoration: none;
  min-height: 48px;
}

.nav-item:hover {
  background: var(--primary-lighter);
  color: var(--primary-dark);
}

.nav-item.active {
  background: linear-gradient(135deg, var(--primary-lighter), var(--secondary-lighter));
  color: var(--secondary-dark);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  background: linear-gradient(180deg, var(--primary), var(--secondary));
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-item .nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.nav-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.nav-divider {
  height: 1px;
  background: var(--border-light);
  margin: var(--space-2) var(--space-3);
}

/* ── Usuario al pie del sidebar ──────────────────────────────── */
.sidebar-user {
  padding: var(--space-4) var(--space-4);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  transition: var(--ease);
  flex-shrink: 0;
}

.sidebar-user:hover { background: var(--bg); }

.sidebar-user-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }

.sidebar-user-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.75rem;
  color: var(--text-light);
}

.sidebar-logout-btn {
  color: var(--text-light);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--ease);
  flex-shrink: 0;
}

.sidebar-logout-btn:hover { color: var(--danger); background: var(--danger-light); }

.sidebar-logout-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ════════════════════════════════════════════════════════════
   MAIN CONTENT
   ════════════════════════════════════════════════════════════ */
.main-content {
  flex: 1;
  margin-left: 0;
  min-height: 100vh;
  min-width: 0;      /* evita que flex-item desborde en contenedores flex */
  max-width: 100%;   /* no excede el ancho del viewport */
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
}

/* ── Header mobile ───────────────────────────────────────────── */
.top-header {
  height: var(--header-height-mobile);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  /* respeta safe-area en dispositivos con notch lateral (iPad landscape) */
  padding-left: max(var(--space-4), env(safe-area-inset-left, var(--space-4)));
  padding-right: max(var(--space-4), env(safe-area-inset-right, var(--space-4)));
  gap: var(--space-3);
  position: sticky;
  top: 0;
  z-index: 50;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* Botón hamburger — visible solo en mobile */
.header-hamburger {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-medium);
  transition: var(--ease);
  flex-shrink: 0;
}

.header-hamburger:hover {
  background: var(--bg);
  color: var(--text);
}

.header-hamburger svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-title-area {
  flex: 1;
  min-width: 0;
}

.header-page-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Breadcrumb — oculto en mobile */
.header-breadcrumb {
  display: none;
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 1px;
}

.header-breadcrumb span { color: var(--primary-dark); }

/* Búsqueda — oculta en mobile */
.header-search {
  display: none;
  position: relative;
  flex-shrink: 0;
}

.header-search input {
  width: 240px;
  padding: var(--space-2) var(--space-4) var(--space-2) 36px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  color: var(--text);
  transition: var(--ease);
  outline: none;
}

.header-search input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(156, 195, 192, 0.2);
}

.header-search input::placeholder { color: var(--text-light); }

.header-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
}

.header-search-icon svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Acciones del header */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.header-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-medium);
  transition: var(--ease);
  position: relative;
}

.header-icon-btn:hover {
  background: var(--bg);
  color: var(--secondary-dark);
}

.header-icon-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-icon-btn .notif-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 7px;
  height: 7px;
  background: var(--secondary);
  border-radius: var(--radius-full);
  border: 2px solid var(--surface);
}

/* Fecha — oculta en mobile */
.header-date {
  display: none;
  font-size: 0.8125rem;
  color: var(--text-light);
  font-weight: 500;
  white-space: nowrap;
  padding: var(--space-2) var(--space-3);
  background: var(--bg);
  border-radius: var(--radius-md);
}

/* ── Área de contenido ───────────────────────────────────────── */
.content-area {
  flex: 1;
  padding: var(--space-4);
  /* espacio bajo el bottom nav + safe-area iPhone (home indicator) */
  padding-bottom: calc(var(--bottom-nav-height) + var(--space-5) + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  overflow-x: hidden; /* evita que overflow-y:auto cree scroll horizontal implícito */
  max-width: 100%;
  box-sizing: border-box;
}

/* Vistas (mostradas/ocultas por JS) */
.view { display: none; }
.view.active { display: block; }

/* ── Page header dentro de cada vista ───────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-3);
  flex-wrap: wrap;
  min-width: 0;
}

.page-header-left {
  flex: 1;
  min-width: 0;
}

.page-header-left h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  overflow-wrap: break-word;
}

.page-header-left p {
  font-size: 0.875rem;
  color: var(--text-medium);
  margin-top: var(--space-1);
  /* Texto largo (resumen de stats) envuelve en lugar de desbordarse */
  overflow-wrap: break-word;
  word-break: break-word;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* ── Grid de tarjetas ────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

.cards-grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

/* ════════════════════════════════════════════════════════════
   BOTTOM NAVIGATION — solo mobile
   ════════════════════════════════════════════════════════════ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  /* La altura TOTAL incluye el safe-area; padding-bottom lo desplaza para el home indicator */
  height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start; /* items se alinean desde el tope, NO stretch hasta el safe-area */
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(151, 135, 163, 0.10);
  box-sizing: border-box;
}

.bottom-nav-item {
  flex: 1;
  height: var(--bottom-nav-height); /* altura fija = solo la zona de navegación, sin safe-area */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-light);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.3px;
  transition: color 0.2s ease, background 0.2s ease;
  padding: var(--space-2) var(--space-1);
  position: relative;
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

.bottom-nav-item:active {
  background: var(--primary-lighter);
}

.bottom-nav-item.active {
  color: var(--secondary-dark);
}

/* Indicador activo — pill detrás del ícono */
.bottom-nav-item.active::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -58%);
  width: 48px;
  height: 30px;
  background: var(--primary-lighter);
  border-radius: var(--radius-full);
  z-index: 0;
}

.bottom-nav-icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke-width 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.bottom-nav-item span {
  position: relative;
  z-index: 1;
}

.bottom-nav-item.active .bottom-nav-icon {
  stroke-width: 2.5;
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet / Desktop ≥ 900px
   ════════════════════════════════════════════════════════════ */
@media (min-width: 900px) {

  /* Sidebar siempre visible, sin transición */
  .sidebar {
    transform: translateX(0) !important;
    height: 100vh;
    transition: none;
    box-shadow: 2px 0 20px rgba(151, 135, 163, 0.06);
  }

  /* Ocultar elementos exclusivos de mobile */
  .sidebar-overlay  { display: none !important; }
  .sidebar-close    { display: none; }
  .header-hamburger { display: none; }
  .bottom-nav       { display: none; }

  /* Main content desplazado por el sidebar */
  .main-content {
    margin-left: var(--sidebar-width);
  }

  /* Header desktop */
  .top-header {
    height: var(--header-height);
    padding: 0 var(--space-8);
    gap: var(--space-4);
  }

  .header-page-title  { font-size: 1.125rem; }
  .header-breadcrumb  { display: block; }
  .header-search      { display: block; }
  .header-date        { display: flex; }

  /* Contenido sin padding del bottom nav */
  .content-area {
    padding: var(--space-8);
    padding-bottom: var(--space-8);
  }

  /* Grids desktop */
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-5);
  }

  .cards-grid-3 {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-5);
  }

  .page-header {
    flex-wrap: nowrap;
  }

  .page-header-left h2 { font-size: 1.5rem; }
}

@media (min-width: 1280px) {
  .cards-grid-3 { grid-template-columns: repeat(3, 1fr); }
}