/* ═══════════════════════════════════════════
   LAYOUT
═══════════════════════════════════════════ */
body {
  font-family: var(--font-family);
  background: var(--bg-app);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow: hidden; /* Prevents body scroll; scrolling happens inside .view-container */
}

/* ── APP SHELL ── */
.app {
  display: flex;
  height: 100dvh;
  position: relative;
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-width);
  height: 100dvh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform var(--transition-slow);
  will-change: transform;
}
.sidebar.open { transform: translateX(0); }

.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-md) var(--space-sm);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar__brand { display: flex; align-items: center; gap: var(--space-sm); }
.sidebar__brand-name { font-weight: 700; font-size: var(--font-size-md); color: var(--text-primary); }
.sidebar__close { display: flex; }

.sidebar__nav {
  flex: 1;
  padding: var(--space-sm);
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar__footer {
  flex-shrink: 0;
  padding: var(--space-sm) var(--space-sm) calc(var(--space-sm) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}
.sidebar__theme { display: flex; justify-content: center; padding: var(--space-sm) 0 var(--space-xs); }

/* ── OVERLAY ── */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.overlay.visible { opacity: 1; pointer-events: all; }

/* ── MAIN ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  min-width: 0; /* Prevents flex overflow */
}

/* ── TOPBAR ── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 var(--space-md);
  padding-top: env(safe-area-inset-top, 0px);
  z-index: 100;
  flex-shrink: 0;
}
.topbar__title {
  flex: 1;
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* El list-switch ocupa el espacio del título en la topbar */
#listSwitchBtn { flex: 1; max-width: 240px; }
.topbar__actions { display: flex; gap: var(--space-xs); flex-shrink: 0; }

/* ── OFFLINE BANNER ── */
.offline-banner {
  position: fixed;
  top: var(--topbar-height);
  left: 0; right: 0;
  z-index: 95;
  background: #E67E22;
  color: #fff;
  font-size: var(--font-size-xs);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 7px var(--space-md);
  transform: translateY(-110%);
  transition: transform 0.3s cubic-bezier(.4,0,.2,1);
}
.offline-banner.visible { transform: translateY(0); }
@media (min-width: 768px) {
  .offline-banner { left: var(--sidebar-width); }
}

/* ── SEARCH BAR ── */
.searchbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition-base);
  flex-shrink: 0;
}
.searchbar.open { max-height: 56px; }
.searchbar__inner {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 8px var(--space-md);
  color: var(--text-secondary);
}
.searchbar__input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--font-size-md);
  color: var(--text-primary);
}
.searchbar__input::placeholder { color: var(--text-tertiary); }

/* ── VIEW CONTAINER ── */
.view-container {
  flex: 1;
  overflow-y: auto;
  /* Sin overflow-x: hidden — bloquearía el scroll táctil horizontal
     de los chips de filtro en iOS Safari. El contenido no desborda
     horizontalmente porque .view tiene width:100% */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
  padding-bottom: calc(var(--bottom-nav-height) + 96px + env(safe-area-inset-bottom, 0px));
}

/* ── VIEWS ── */
.view {
  display: none;
  padding: var(--space-md);
  max-width: var(--content-max);
  margin: 0 auto;
  width: 100%;
  animation: fadeSlideIn 0.2s both;
}
.view.active { display: block; }

.view__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
  gap: var(--space-sm);
  flex-wrap: wrap;
}
.view__title { font-size: var(--font-size-2xl); font-weight: 800; color: var(--text-primary); }
.view__subtitle { font-size: var(--font-size-sm); color: var(--text-secondary); margin-top: 2px; }

/* ── BOTTOM NAV (mobile only) ── */
.bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  z-index: 100;
}
.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 500;
  position: relative;
  transition: color var(--transition-fast);
  padding-top: 4px;
  min-width: 0;
  /* iOS: prevent tap highlight */
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav__item svg { width: 22px; height: 22px; flex-shrink: 0; transition: transform var(--transition-fast); }
.bottom-nav__item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bottom-nav__item.active { color: var(--brand-primary); }
.bottom-nav__item.active svg { transform: scale(1.1); }
.bottom-nav__badge {
  position: absolute;
  top: 5px;
  right: calc(50% - 20px);
  min-width: 16px;
  height: 16px;
  background: var(--brand-secondary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  border-radius: var(--radius-full);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}
.bottom-nav__badge.visible { display: flex; }

/* ── BOTTOM NAV: botón central Análisis ── */
.bottom-nav__item--center {
  position: relative;
  margin-top: -14px;
  color: var(--brand-primary);
}
.bottom-nav__item--center span {
  font-size: 10px;
  font-weight: 700;
  color: var(--brand-primary);
}
.bottom-nav__center-pill {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(124,74,158,0.45);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.bottom-nav__center-pill svg {
  width: 24px;
  height: 24px;
  stroke: #fff;
}
.bottom-nav__item--center.active .bottom-nav__center-pill {
  background: var(--brand-primary-h, #6B3A8E);
  box-shadow: 0 6px 20px rgba(124,74,158,0.6);
}
.bottom-nav__item--center:active .bottom-nav__center-pill {
  transform: scale(0.93);
}
/* El icono suelto no se muestra en el botón central */
.bottom-nav__item--center > svg { display: none; }

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 10px);
  right: var(--space-md);
  width: 50px;
  height: 50px;
  border-radius: var(--radius-full);
  background: var(--brand-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-brand);
  z-index: 90;
  transition: transform var(--transition-fast), background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.fab:hover  { transform: scale(1.06); background: var(--brand-primary-h); }
.fab:active { transform: scale(0.93); }

/* ══════════════════════════════════════════
   DESKTOP (≥768px)
══════════════════════════════════════════ */
@media (min-width: 768px) {
  body { overflow: hidden; }

  .sidebar {
    transform: translateX(0);
    position: fixed;
  }
  .sidebar__close { display: none; }
  .overlay { display: none !important; }

  .main { margin-left: var(--sidebar-width); }
  .topbar__menu { display: none; }

  .bottom-nav { display: none; }

  .fab {
    bottom: var(--space-lg);
    right: var(--space-xl);
  }

  .view-container {
    padding-bottom: calc(var(--space-2xl) + 60px);
  }

  .view { padding: var(--space-xl) var(--space-lg); }
}

@media (min-width: 1024px) {
  :root { --sidebar-width: 280px; }
  .view { padding: var(--space-xl); }
}

/* ── LIST HEADER RESPONSIVE ── */
/* En pantallas muy pequeñas, ocultar las etiquetas de texto de los
   botones secundarios del list-header para evitar desbordamiento.
   Los iconos (svg) siguen visibles, los tooltips explican la función. */
@media (max-width: 400px) {
  .list-header__actions .btn-lbl { display: none; }
  .list-header__actions .btn--ghost.btn--sm { padding: 7px 9px; }
}
