/* Barra lateral: selector de contexto, acción principal, menú, contador, pie, foco y variante contraída. */

/* ============================================================
   Shell de compu (Rediseño 2): barra lateral de dos niveles y
   barra superior, al estilo de Órbita 2 (`Sidebar.tsx`,
   `Topbar.tsx` y la sección 3-4 de `rediseno.css`).
   Se carga DESPUÉS de los CSS de css/componentes/ y css/pantallas/. Todo color sale de
   tokens.css. El markup es UNO para todos los anchos: debajo de
   768 px la barra lateral no se ve y la navegación es la tab bar
   (la barra inferior nueva es de la Tarea 3).
   ============================================================ */

/* --- Barra lateral ---
   Base (celular): oculta. Desde 768 px: columna pegajosa de 264 px, o de
   72 px contraída (`.shell[data-barra="contraida"]`). */
.sidebar { display: none; }

@media (min-width: 768px) {
  .sidebar {
    position: sticky;
    top: 0;
    flex: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    width: var(--sidebar-w);
    height: 100dvh;
    padding: var(--space-4) var(--space-3) var(--space-3);
    /* Se desplaza el menú, no la barra entera: así el pie no tapa el último
       grupo (mismo arreglo que Órbita). */
    overflow: hidden;
    background: var(--bg-grupo);
    border-right: 1px solid var(--border);
    transition: width var(--dur-base) var(--ease-ios), padding var(--dur-base) var(--ease-ios);
  }
}

.sidebar__cabeza {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  padding-inline: var(--space-2);
}
.sidebar__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-xs);
  background: var(--accent-fill);
  color: var(--on-accent);
  box-shadow: var(--sh-xs);
}
.sidebar__marca {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.01em;
  color: var(--label);
  white-space: nowrap;
}

/* Selector de contexto: tarjeta con iniciales, empresa y recorte. */
.sidebar__contexto {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 52px;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--label);
  font: inherit;
  text-align: left;
}
button.sidebar__contexto { cursor: pointer; transition: border-color var(--dur-fast), background-color var(--dur-fast); }
button.sidebar__contexto:hover { border-color: var(--border-strong); background: var(--surface-3); }
.sidebar__contexto-iniciales {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  background: var(--accent-fill);
  color: var(--on-accent);
  font-family: var(--font-display);
  font-size: var(--text-caption1-size);
  font-weight: 700;
}
.sidebar__contexto-texto { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sidebar__contexto-nombre,
.sidebar__contexto-detalle {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.sidebar__contexto-nombre {
  font-size: var(--text-subhead-size);
  line-height: var(--text-subhead-lh);
  font-weight: 600;
}
.sidebar__contexto-detalle {
  font-size: var(--text-caption1-size);
  line-height: var(--text-caption1-lh);
  color: var(--label-secondary);
}
.sidebar__contexto-chevron { flex: none; color: var(--text-3); }

/* Acción principal: el botón grande de marca («Nueva orden»). */
.sidebar__crear { padding-bottom: var(--space-1); }
.sidebar__accion {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 46px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--accent-fill);
  color: var(--on-accent);
  font-family: var(--font-display);
  font-size: var(--text-callout-size);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--sh-sm);
  transition: filter var(--dur-fast), box-shadow var(--dur-fast);
}
.sidebar__accion:hover { filter: brightness(1.08); box-shadow: var(--sh-md); }

/* El menú es lo que se desplaza. */
.sidebar__nav {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow-y: auto;
  overscroll-behavior: contain;
  margin-inline: calc(var(--space-3) * -1);
  padding: var(--space-1) var(--space-3);
  scrollbar-width: thin;
}
.sidebar__grupo { display: flex; flex-direction: column; gap: 2px; }
.sidebar__titulo {
  margin: 0;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-caption1-size);
  line-height: var(--text-caption1-lh);
  font-weight: 600;
  letter-spacing: .02em;
  /* Es TEXTO: --text-3 compone 5:1 o más sobre la superficie en los dos temas. */
  color: var(--text-3);
  white-space: nowrap;
}
.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 38px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  color: var(--label-secondary);
  font-size: var(--text-body-size);
  line-height: var(--text-body-lh);
  text-decoration: none;
  white-space: nowrap;
}
/* Sin transición de fondo: el ítem activo cambia en el mismo cuadro en que
   cambia la ruta (con transición, una captura o una medición tomadas al
   navegar veían el activo viejo a medio apagar). */
.sidebar__item svg { flex: none; color: var(--text-3); }
.sidebar__item:hover { background: var(--surface-2); color: var(--label); }
.sidebar__item:hover svg { color: var(--label-secondary); }
/* Activo: pastilla de marca tenue, texto e ícono de marca, semibold. */
.sidebar__item[aria-current="page"] {
  background: var(--brand-50);
  color: var(--brand-700);
  font-weight: 600;
}
.sidebar__item[aria-current="page"] svg { color: var(--brand-700); }
.sidebar__label { overflow: hidden; text-overflow: ellipsis; }

/* Contador (emergencias abiertas): color + número, nunca sólo color. */
.sidebar__contador {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  margin-left: auto;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--estado-detenido-bg);
  color: var(--estado-detenido-text);
  font-size: var(--text-caption1-size);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.sidebar__contador[hidden] { display: none; }

/* Pie: contraer y la tarjeta de la persona. */
.sidebar__pie {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border);
}
.sidebar__contraer,
.sidebar__persona {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.sidebar__contraer {
  min-height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  color: var(--label-secondary);
  font-size: var(--text-footnote-size);
  font-weight: 500;
}
.sidebar__contraer [data-icono-barra] { display: inline-flex; flex: none; }
.sidebar__contraer:hover { background: var(--surface-2); color: var(--label); }
.sidebar__persona {
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--label);
}
.sidebar__persona:hover { background: var(--surface-2); }
.sidebar__avatar { width: 34px; height: 34px; font-size: var(--text-caption1-size); }
.sidebar__persona-texto { display: flex; flex-direction: column; min-width: 0; }
.sidebar__persona-nombre,
.sidebar__persona-rol { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sidebar__persona-nombre { font-size: var(--text-subhead-size); line-height: var(--text-subhead-lh); font-weight: 600; }
.sidebar__persona-rol { font-size: var(--text-caption1-size); line-height: var(--text-caption1-lh); color: var(--label-secondary); }

/* Foco de teclado de los controles de la barra (los ítems ya lo traen de
   css/componentes/shell-base.css, adentro, para que el borde no lo recorte). */
.sidebar__contexto:focus-visible,
.sidebar__accion:focus-visible,
.sidebar__contraer:focus-visible,
.sidebar__persona:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* --- Contraída: columna de 72 px, sólo íconos ---
   Las etiquetas se ocultan (el nombre accesible lo sostiene el aria-label y
   el tooltip el title); los títulos de grupo pasan a ser una raya. */
@media (min-width: 768px) {
  .shell[data-barra="contraida"] .sidebar {
    width: var(--sidebar-rail-w);
    padding-inline: var(--space-2);
  }
}
.shell[data-barra="contraida"] .sidebar__marca,
.shell[data-barra="contraida"] .sidebar__label,
.shell[data-barra="contraida"] .sidebar__contexto-texto,
.shell[data-barra="contraida"] .sidebar__contexto-chevron,
.shell[data-barra="contraida"] .sidebar__persona-texto { display: none; }
.shell[data-barra="contraida"] .sidebar__cabeza { justify-content: center; padding-inline: 0; }
.shell[data-barra="contraida"] .sidebar__contexto {
  justify-content: center;
  min-height: 48px;
  padding: var(--space-2) 0;
}
.shell[data-barra="contraida"] .sidebar__accion { padding: 0; }
.shell[data-barra="contraida"] .sidebar__nav {
  margin-inline: calc(var(--space-2) * -1);
  padding-inline: var(--space-2);
  gap: var(--space-2);
}
.shell[data-barra="contraida"] .sidebar__titulo {
  height: 1px;
  margin: var(--space-1) var(--space-2);
  padding: 0;
  overflow: hidden;
  background: var(--border);
  color: transparent;
}
.shell[data-barra="contraida"] .sidebar__grupo:first-child .sidebar__titulo { display: none; }
.shell[data-barra="contraida"] .sidebar__item,
.shell[data-barra="contraida"] .sidebar__contraer {
  position: relative;
  justify-content: center;
  padding: 0;
  border-radius: var(--radius-md);
}
.shell[data-barra="contraida"] .sidebar__item { min-height: 44px; }
/* El contador contraído queda como número chico sobre el ícono. */
.shell[data-barra="contraida"] .sidebar__contador {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  font-size: var(--text-caption2-size);
}
.shell[data-barra="contraida"] .sidebar__persona { justify-content: center; padding: var(--space-2) 0; }

