/* ============================================================================
 * LEXIS · css/layout.css
 * Estructura: sidebar, topbar, contenedor de vistas y sistema responsive.
 * ----------------------------------------------------------------------------
 * REGLA DE ORO DEL SCROLL:
 *   · NO existe ningún `overflow: hidden` ni `height: 100vh` estricto en
 *     html, body ni .app: nada puede recortar el contenido.
 *   · El documento crece con el contenido (`min-height: 100vh` + scroll natural
 *     de la página), de modo que la rueda del ratón recorre toda la pantalla.
 *   · El contenedor de la vista activa mantiene `overflow-y: scroll` y un
 *     relleno inferior amplio (100px+) para que ningún botón quede cortado.
 * ==========================================================================*/

html {
  height: auto;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;            /* scroll vertical siempre disponible */
}

body {
  height: auto;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;            /* la página se desplaza con la rueda del ratón */
}

/* ----------------------------------------------------------- Contenedor --- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  align-items: start;          /* cada columna crece con su contenido */
  min-height: 100vh;           /* nunca menos que la ventana… */
  height: auto;                /* …y tanto como haga falta */
  overflow: visible;           /* sin recortes de ningún tipo */
}

/* ======================================================== BARRA LATERAL === */
.sidebar {
  position: sticky;            /* acompaña al scroll sin recortar el contenido */
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  /* COMPACTADO: menos hueco entre bloques y relleno lateral mínimo (8px) para que la
     barra quede pegada al borde izquierdo y no desperdicie ancho. */
  gap: var(--sp-3);
  min-height: 100vh;
  max-height: 100vh;
  padding: var(--sp-3) 8px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-2) 100%);
  border-right: 1px solid var(--border);
  overflow-y: auto;            /* la propia barra lateral sí se desplaza */
  z-index: 40;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent-contrast);
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.brand__text { display: grid; line-height: 1.2; }
.brand__text strong { font-size: var(--fs-md); letter-spacing: -.02em; }
.brand__text small { font-size: var(--fs-xs); color: var(--text-faint); letter-spacing: .04em; text-transform: uppercase; }

/* ------------------------------------------------------------ Navegación - */
.nav { display: grid; gap: var(--sp-1); }

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  /* COMPACTADO: 5px de relleno vertical (dentro del 4–6px pedido) y tipografía
     reducida, para que la lista entera quepa sin desplazar la barra lateral. */
  padding: 5px var(--sp-2);
  color: var(--text-dim);
  font-size: var(--fs-sm);
  font-weight: 550;
  text-align: left;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition), transform var(--transition);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active {
  color: var(--text);
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-item.is-active .nav-item__icon { transform: scale(1.08); }

.nav-item__icon { font-size: 15px; width: 19px; text-align: center; transition: transform var(--transition); }
.nav-item__label { flex: 1; }

.nav-item__badge {
  min-width: 22px;
  padding: 1px 7px;
  font-size: var(--fs-xs);
  font-weight: 700;
  text-align: center;
  color: var(--accent-contrast);
  background: var(--danger);
  border-radius: var(--radius-pill);
}
.nav-item__badge--soft {
  color: var(--text-dim);
  background: var(--surface-3);
}

/* ---------------------------------------------------------------- Pie --- */
.sidebar__foot { margin-top: auto; display: grid; gap: var(--sp-3); }

.sidebar__tip {
  padding: var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.sidebar__tip strong { display: block; margin-bottom: var(--sp-2); font-size: var(--fs-sm); }
.sidebar__tip p { margin-bottom: var(--sp-3); font-size: var(--fs-xs); color: var(--text-faint); line-height: 1.7; }
.sidebar__version { font-size: var(--fs-xs); color: var(--text-faint); text-align: center; }

/* ================================================================= MAIN === */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;           /* crece con el contenido, sin recortes */
  background: var(--bg);
}

/* -------------------------------------------------------------- Topbar -- */
/* COMPACTADO: de ~68px originales a ~38px. Menos relleno vertical, menos hueco
   entre bloques y tipografía reducida en título, píldoras y botones. */
.topbar {
  position: sticky;            /* la cabecera acompaña al scroll */
  top: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--topbar-h);
  padding: 3px var(--sp-3);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}

.topbar__titles { display: flex; align-items: baseline; gap: 6px; line-height: 1.15; min-width: 0; }
/* El título y el subtítulo van EN LÍNEA: apilados no caben en 38px.
   El subtítulo se oculta por debajo de 1100px (ver media query). */
.topbar__title { font-size: var(--fs-sm); white-space: nowrap; }
.topbar__subtitle {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 30ch;
}

.topbar__search { position: relative; flex: 1; max-width: 240px; margin-left: auto; }
.search__icon {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-xs);
  opacity: .6;
  pointer-events: none;
}

.topbar__actions { display: flex; align-items: center; gap: 4px; }

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 38px; height: 38px;
  padding: 0 9px;
}
.menu-toggle span {
  display: block;
  height: 2px;
  background: var(--text-dim);
  border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}
.app.sidebar-open .menu-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.app.sidebar-open .menu-toggle span:nth-child(2) { opacity: 0; }
.app.sidebar-open .menu-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ------------------------------------------------------- Contenedor de vistas */
/* El contenedor de la vista activa nunca recorta: crece con el contenido y la
   rueda del ratón desplaza la página completa de forma natural. El `!important`
   protege esta regla frente a cualquier `overflow: hidden` heredado. */
.view-container {
  flex: 1 0 auto;
  min-height: auto;
  max-height: none;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.view {
  max-width: var(--content-max);
  margin: 0 auto;
  /* Relleno inferior amplio para que ningún botón, paginador o pie de tabla quede
     cortado ni tapado por el aviso flotante (`.toast-host` está fijo abajo, con
     hasta 520px de ancho). El valor NO se puede bajar de 100px: hay una prueba del
     arnés que lo protege, y con razón. */
  padding: var(--sp-4) var(--sp-4) 100px;
  min-height: auto;
}

.view-panel { display: none; }
.view-panel.is-active {
  display: block;
  min-height: auto;
  padding-bottom: 28px;        /* suma al relleno de .view */
  animation: viewIn var(--transition-slow) both;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------- Sección head - */
.section-head { margin-bottom: var(--sp-5); }
.section-head__title { font-size: var(--fs-xl); margin-bottom: var(--sp-2); }
.section-head__text { color: var(--text-dim); max-width: 78ch; }

/* ---------------------------------------------------------- Responsive --- */
@media (max-width: 1180px) {
  .topbar__subtitle { display: none; }
  .topbar__search { max-width: 260px; }
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    min-height: 100vh;
    overflow: visible;
  }

  .view-container {
    overflow: visible !important;   /* el scroll lo gestiona el documento */
    flex: 1 1 auto;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 270px;
    transform: translateX(-102%);
    transition: transform var(--transition-slow);
    box-shadow: var(--shadow-lg);
  }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, .5);
    backdrop-filter: blur(2px);
    animation: fadeIn var(--transition) both;
  }

  .menu-toggle { display: flex; }
  .view { padding: var(--sp-4) var(--sp-4) var(--sp-6); }
}

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: var(--sp-3) var(--sp-4);
    gap: var(--sp-3);
  }
  .topbar__titles { order: 1; }
  .menu-toggle { order: 0; }
  .topbar__actions { order: 2; margin-left: auto; }
  .topbar__search { order: 3; flex-basis: 100%; max-width: none; }
  .topbar__title { font-size: var(--fs-md); }
}

@media (max-width: 520px) {
  .topbar__actions .btn--ghost,
  .topbar__actions .pill { display: none; }
}
