/* ============================================================
   NorCam — Menú lateral de proyectos (compartido)
   Paleta institucional: navy #1a3554 · burgundy #7a2041
   ============================================================ */

:root {
  --sb-width: 258px;
  --sb-mini: 78px;
  --sb-navy: #1a3554;
  --sb-navy-deep: #12263d;
  --sb-navy-top: #1e3d61;
  --sb-burgundy: #7a2041;
  --sb-burgundy-light: #943050;
  --sb-text: #e8ecf1;
  --sb-muted: #8ba0b8;
  --sb-line: rgba(255, 255, 255, 0.09);
  --sb-topbar: 52px;
}

/* --- Comportamiento táctil de todos los controles del menú --- */
.sb-item,
.sb-sub a,
.sb-rail-btn,
.sb-handle,
.sb-burger {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* --- Espacio reservado en la página --- */
body {
  padding-left: var(--sb-width);
  transition: padding-left 0.25s ease;
}

/* Contraído: el menú se reduce a un riel con las miniaturas */
html.sb-hidden body {
  padding-left: var(--sb-mini);
}

/* --- Contenedor --- */
.sb {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sb-width);
  z-index: 200;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #1e3d61 0%, var(--sb-navy) 42%, var(--sb-navy-deep) 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 2px 0 18px rgba(0, 0, 0, 0.28);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  transition: width 0.25s ease, transform 0.25s ease;
  overflow: hidden;
}

/* --- Marca: emblema NorCam en disco claro --- */
.sb-brand {
  padding: 20px 14px 18px;
  border-bottom: 1px solid var(--sb-line);
  flex-shrink: 0;
  display: flex;
  justify-content: center;
}

/* El emblema es azul y vinotinto: necesita fondo claro para destacar */
.sb-brand-logo {
  width: 92px;
  height: 92px;
  border-radius: 18px;
  background: #eceef0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.35);
}

.sb-brand-logo img {
  display: block;
  width: 100%;
  height: auto;
}

/* --- Título de sección --- */
.sb-section {
  padding: 18px 18px 8px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sb-muted);
  flex-shrink: 0;
}

/* --- Lista de proyectos --- */
.sb-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 10px calc(12px + env(safe-area-inset-bottom));
}

.sb-nav::-webkit-scrollbar { width: 6px; }
.sb-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 3px;
}

.sb-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  margin-bottom: 5px;
  border-radius: 9px;
  text-decoration: none;
  color: var(--sb-text);
  transition: background 0.18s, color 0.18s;
}

.sb-item:hover {
  background: rgba(255, 255, 255, 0.07);
}

.sb-item.is-active {
  background: var(--sb-burgundy);
  box-shadow: 0 3px 12px rgba(122, 32, 65, 0.4);
}

.sb-item.is-active:hover {
  background: var(--sb-burgundy-light);
}

/* Miniatura fotográfica del proyecto */
.sb-item-thumb {
  width: 52px;
  height: 38px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.35);
  transition: border-color 0.18s, transform 0.18s;
}

.sb-item:hover .sb-item-thumb {
  transform: scale(1.04);
}

.sb-item.is-active .sb-item-thumb {
  border-color: rgba(255, 255, 255, 0.75);
}

.sb-item-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  opacity: 0.9;
}

.sb-item-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sb-item-text {
  min-width: 0;
  line-height: 1.3;
}

.sb-item-text strong {
  display: block;
  font-size: 0.81rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-item-text small {
  display: block;
  font-size: 0.66rem;
  color: var(--sb-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.sb-item.is-active .sb-item-text small {
  color: rgba(255, 255, 255, 0.72);
}

.sb-item-ext {
  margin-left: auto;
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  opacity: 0.45;
}

.sb-item-ext svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sb-item:hover .sb-item-ext { opacity: 0.85; }

/* --- Pie del menú: logotipo a color --- */
.sb-foot {
  flex-shrink: 0;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--sb-line);
}

/* El logotipo es oscuro: necesita tarjeta blanca sobre el fondo azul */
.sb-foot-logo {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}

/* --- Sub-navegación del proyecto activo --- */
.sb-sub {
  margin: 2px 0 10px 26px;
  padding-left: 12px;
  border-left: 1px solid var(--sb-line);
}

.sb-sub a {
  display: block;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 0.76rem;
  color: var(--sb-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.sb-sub a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--sb-text);
}

.sb-sub a.is-current {
  color: #fff;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.09);
}

/* --- Botón circular para ocultar/mostrar el menú --- */
.sb-handle {
  position: fixed;
  top: 50%;
  left: var(--sb-width);
  transform: translate(-50%, -50%);
  z-index: 205;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  background: var(--sb-burgundy);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  transition: left 0.25s ease, transform 0.25s ease, background 0.18s;
}

.sb-handle:hover {
  background: var(--sb-burgundy-light);
}

.sb-handle:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.sb-handle svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.25s ease;
}

html.sb-hidden .sb-handle {
  left: var(--sb-mini);
}

html.sb-hidden .sb-handle svg {
  transform: rotate(180deg);
}

/* ============================================================
   Estado contraído (escritorio): riel angosto solo con miniaturas
   ============================================================ */
@media (min-width: 901px) {
  html.sb-hidden .sb {
    width: var(--sb-mini);
  }

  /* El emblema es cuadrado: cabe en el riel, solo más pequeño */
  html.sb-hidden .sb-brand {
    padding: 14px 0 12px;
  }

  html.sb-hidden .sb-brand-logo {
    width: 54px;
    height: 54px;
    border-radius: 12px;
    padding: 4px;
  }

  /* El rótulo "Proyectos" sobra, pero se conserva su espacio vertical */
  html.sb-hidden .sb-section {
    padding: 16px 0 8px;
    font-size: 0;
    letter-spacing: 0;
  }

  html.sb-hidden .sb-nav {
    padding-left: 0;
    padding-right: 0;
  }

  /* Cada proyecto queda reducido a su miniatura */
  html.sb-hidden .sb-item {
    justify-content: center;
    gap: 0;
    padding: 9px 0;
    margin-bottom: 7px;
    border-radius: 11px;
  }

  html.sb-hidden .sb-item-text,
  html.sb-hidden .sb-item-ext,
  html.sb-hidden .sb-sub {
    display: none;
  }

  /* En el riel no cabe el logotipo del pie: ya está el de la cabecera */
  html.sb-hidden .sb-foot { display: none; }

  html.sb-hidden .sb-item-thumb {
    width: 54px;
    height: 40px;
  }

  /* El proyecto activo se marca con una barra a la izquierda */
  html.sb-hidden .sb-item.is-active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 26px;
    border-radius: 0 3px 3px 0;
    background: #fff;
  }
}

/* --- Rail circular de vistas (borde derecho, centrado) --- */
.sb-rail {
  position: fixed;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
  z-index: 180;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

.sb-rail-btn {
  position: relative;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--sb-navy);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(26, 53, 84, 0.12);
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(8px);
  transition: background 0.18s, color 0.18s, transform 0.18s, box-shadow 0.18s;
}

.sb-rail-btn:hover {
  background: #fff;
  transform: scale(1.07);
}

.sb-rail-btn.is-current {
  background: var(--sb-burgundy);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.85);
  box-shadow: 0 3px 16px rgba(122, 32, 65, 0.5);
}

.sb-rail-btn.is-current:hover {
  background: var(--sb-burgundy-light);
}

.sb-rail-icon {
  width: 24px;
  height: 24px;
  display: flex;
}

.sb-rail-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Etiqueta emergente a la izquierda del botón */
.sb-rail-label {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  padding: 7px 12px;
  border-radius: 8px;
  background: rgba(13, 26, 42, 0.94);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
  transition: opacity 0.18s, transform 0.18s;
}

.sb-rail-btn:hover .sb-rail-label,
.sb-rail-btn:focus-visible .sb-rail-label {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* --- Barra superior móvil --- */
.sb-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--sb-topbar);
  z-index: 190;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: #ffffff;
  border-bottom: 1px solid #e2e6ea;
  box-shadow: 0 1px 6px rgba(13, 26, 42, 0.06);
  color: var(--sb-navy);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* Logotipo a la derecha */
.sb-topbar-logo {
  margin-left: auto;
  height: 30px;
  width: auto;
  flex-shrink: 0;
}

/* En escritorio la barra superior no hace falta: el riel contraído
   mantiene visibles el logotipo y las miniaturas de los proyectos. */

.sb-burger {
  background: rgba(26, 53, 84, 0.08);
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--sb-navy);
  flex-shrink: 0;
}

.sb-burger:hover { background: rgba(26, 53, 84, 0.14); }

.sb-burger svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.sb-topbar-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--sb-navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6, 14, 24, 0.6);
  z-index: 195;
  opacity: 0;
  transition: opacity 0.25s;
}

/* --- Responsive --- */
@media (max-width: 900px) {
  body {
    padding-left: 0 !important;
    padding-top: calc(var(--sb-topbar) + env(safe-area-inset-top));
  }

  .sb-topbar {
    height: calc(var(--sb-topbar) + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-left: calc(14px + env(safe-area-inset-left));
    padding-right: calc(14px + env(safe-area-inset-right));
  }

  .sb {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
  }

  /* En móvil la barra superior está siempre visible, con el menú hamburguesa */
  .sb-topbar { display: flex; }
  .sb-burger { display: flex; }

  /* En móvil se usa el botón hamburguesa, no el tirador circular */
  .sb-handle { display: none; }

  .sb-rail {
    right: calc(12px + env(safe-area-inset-right));
    gap: 10px;
  }

  .sb-rail-btn { width: 46px; height: 46px; }
  .sb-rail-icon { width: 22px; height: 22px; }

  /* En táctil no hay hover: la etiqueta emergente sobra */
  .sb-rail-label { display: none; }

  .sb {
    width: var(--sb-width) !important;
    transform: translateX(-100%);
  }

  html.sb-open .sb { transform: translateX(0); }

  html.sb-open .sb-scrim {
    display: block;
    opacity: 1;
  }

}

@media (prefers-reduced-motion: reduce) {
  .sb, body, .sb-scrim, .sb-handle, .sb-handle svg { transition: none; }
}
