/* layout.css — Sidebar, grid de dashboard, páginas de login */

/* ── App shell (sidebar + main) ────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 5px 1fr;  /* rainbow bar + contenido */
  min-height: 100vh;
}

/* La barra arcoíris ocupa toda la parte superior */
.app-shell > .rainbow-bar {
  grid-column: 1 / -1;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-brand {
  padding: var(--sp-6) var(--sp-4);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand img { height: 36px; }
.sidebar-brand .brand-name {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-top: var(--sp-2);
}
.sidebar-brand .brand-sub {
  font-size: var(--text-xs);
  opacity: 0.6;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: var(--sp-4) 0;
}
.sidebar-nav ul { list-style: none; }

/* Items sueltos antes de cualquier bloque (Dashboard, Mi perfil): sin panel. */
.sidebar-nav .nav-top { padding: 0 var(--sp-2) var(--sp-2); }

.sidebar-nav li a,
.sidebar-nav li button {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  color: rgba(255,255,255,0.75);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.sidebar-nav li a:hover,
.sidebar-nav li button:hover {
  background: rgba(255,255,255,0.1);
  color: var(--white);
  text-decoration: none;
}
.sidebar-nav li a.active {
  background: linear-gradient(90deg, rgba(201,162,39,.22) 0%, rgba(201,162,39,.05) 100%);
  color: var(--white);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--oro-viejo);
  text-decoration: none;
}

.sidebar-nav .nav-disabled {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: rgba(255,255,255,0.3);
  cursor: default;
}

/* ── Bloques del sidebar: cada sección (Gestión, Marketing…) es un panel
 * propio con profundidad, no una lista plana más. La etiqueta en blanco
 * sobre navy es la que marca "esto es la cabecera del bloque", distinto
 * de un ítem de navegación normal. */
.nav-block {
  background: rgba(255,255,255,.045);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
  padding: var(--sp-2);
  margin: 0 var(--sp-2) var(--sp-3);
  box-shadow: 0 4px 14px rgba(0,0,0,.18), 0 1px 0 rgba(255,255,255,.05) inset;
  transition: border-color .18s, box-shadow .18s;
}
.nav-block:hover {
  border-color: rgba(201,162,39,.28);
  box-shadow: 0 6px 18px rgba(0,0,0,.24), 0 1px 0 rgba(255,255,255,.06) inset;
}
.nav-block-label {
  display: block;
  background: var(--white);
  color: var(--navy);
  font-family: var(--font-head);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: .4rem .65rem;
  border-radius: 7px;
  box-shadow: 0 2px 6px rgba(0,0,0,.18), 0 1px 0 rgba(255,255,255,.6) inset;
  margin-bottom: .45rem;
}

.sidebar-footer {
  padding: var(--sp-4);
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: var(--text-xs);
  opacity: 0.5;
  text-align: center;
}

/* ── Main content ───────────────────────────────────────────── */
.main-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-6);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
}
.topbar-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--navy);
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--text-sm);
}
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
  overflow: hidden;
}
.user-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
}

.page-content {
  flex: 1;
  padding: var(--sp-6);
  overflow-y: auto;
}

/* ── Grid de KPIs ───────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.kpi-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: var(--sp-6) var(--sp-4);
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--navy);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.kpi-card .kpi-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-600);
}
.kpi-card .kpi-value {
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--navy);
}
.kpi-card .kpi-sub {
  font-size: var(--text-xs);
  color: var(--gray-400);
}

/* ── Grid de 2 columnas ─────────────────────────────────────── */
.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-6);
}
@media (max-width: 900px) {
  .two-col-grid { grid-template-columns: 1fr; }
}

/* ── Página de login (centrada, sin sidebar) ────────────────── */
.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--gray-100);
  padding: var(--sp-4);
}

.login-box {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.login-header {
  background: var(--navy);
  color: var(--white);
  padding: var(--sp-8) var(--sp-6) var(--sp-6);
  text-align: center;
}
.login-header h1 {
  font-size: var(--text-2xl);
  font-weight: 800;
  margin-top: var(--sp-3);
}
.login-header p {
  font-size: var(--text-sm);
  opacity: 0.7;
  margin-top: var(--sp-1);
}

.login-body { padding: var(--sp-6); }

/* ── Responsive: ocultar sidebar en móvil ───────────────────── */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .sidebar.open {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 100;
    width: 240px;
  }
}

/* ── MENÚ MÓVIL ──────────────────────────────────────────────
 * El botón que faltaba. `.sidebar.open` ya estaba en el CSS de arriba, pero sin
 * nada que lo activara: en el móvil el menú quedaba oculto para siempre y solo
 * se podía usar el Dashboard.
 */
.menu-movil { display: none; }
.menu-fondo { display: none; }

@media (max-width: 768px) {
  .menu-movil {
    display: flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 38px; height: 38px; padding: 0 8px;
    background: transparent; border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm); cursor: pointer;
    margin-right: var(--sp-3); flex: 0 0 auto;
  }
  .menu-movil span {
    display: block; height: 2px; width: 100%;
    background: var(--navy); border-radius: 2px;
    transition: transform .22s ease, opacity .22s ease;
  }
  .menu-movil.abierto span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .menu-movil.abierto span:nth-child(2) { opacity: 0; }
  .menu-movil.abierto span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

  .menu-fondo[hidden] { display: none; }
  .menu-fondo {
    display: block; position: fixed; inset: 0;
    background: rgba(10, 20, 40, .55); z-index: 99;
  }

  .sidebar.open {
    display: flex;
    position: fixed; inset: 0 auto 0 0;
    z-index: 100; width: 270px; max-width: 82vw;
    overflow-y: auto;
    box-shadow: 8px 0 30px rgba(0,0,0,.35);
    animation: menu-entra .22s cubic-bezier(.2,.7,.3,1);
  }
  @keyframes menu-entra { from { transform: translateX(-100%); } to { transform: none; } }

  /* Barra superior en móvil.
   *
   * El `justify-content: space-between` del escritorio empujaba el nombre al
   * centro de la pantalla, separado de su propia foto. En una barra estrecha eso
   * no tiene sentido: el nombre pertenece al avatar, tienen que ir juntos.
   *
   * Estructura en móvil:  [☰]  Título ————————— [Nombre + rol][foto][Salir]
   */
  .topbar {
    display: flex; align-items: center; gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
  }
  .topbar-title {
    flex: 1 1 auto; min-width: 0;
    font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  /* El bloque de usuario va pegado al borde derecho, en una sola pieza. */
  .topbar-user {
    flex: 0 0 auto; gap: var(--sp-2);
    margin-left: auto;
  }
  .topbar-user > div:first-child { text-align: right; line-height: 1.25; }
  .topbar-user .fw-bold { font-size: 13px; }
  .topbar-user .text-sm { font-size: 10px; }
  .topbar-user .btn { padding: 6px 10px; font-size: 12px; }
  .user-avatar { width: 32px; height: 32px; font-size: 12px; }
}

/* ── Título de la barra: BLOQUE arriba, MÓDULO debajo ──────
 * "Marketing — Banco de imágenes" en una sola línea no dice cuál es el bloque y
 * cuál el módulo, y en móvil no cabe. Se separan.
 */
.tb-bloque {
  display: block;
  font-family: var(--font-base);
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--gray-600);
  line-height: 1.2;
}
.tb-modulo {
  display: block;
  font-family: var(--font-head);
  font-weight: 700;
  line-height: 1.25;
}
@media (max-width: 768px) {
  .tb-bloque { font-size: 9.5px; letter-spacing: .06em; }
  /* 13,5px: con 15px "Banco de imágenes" se cortaba en "Banco de imágen". */
  .tb-modulo { font-size: 13.5px; letter-spacing: -.01em; }
  /* El nombre del módulo manda: si hay que apretar, se aprieta el bloque de usuario. */
  .topbar-user .fw-bold { font-size: 12px; }
  .topbar-user .btn { padding: 5px 8px; }
}

/* En el Studio (lienzo oscuro) las rayas del botón deben verse. */
.studio .menu-movil { border-color: #2f3d4e; }
.studio .menu-movil span { background: #e8edf4; }

/* Botón flotante para las pantallas sin barra superior (el Studio). */
@media (max-width: 768px) {
  .menu-movil-flotante {
    position: fixed; top: 12px; left: 12px; z-index: 98;
    background: rgba(20, 27, 38, .9);
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 14px rgba(0,0,0,.35);
  }
  /* En el Studio la cabecera deja hueco al botón flotante. */
  .studio .studio-head { padding-left: 52px; }
}
