/* ============================================================
   SIDEBAR LATERAL — Bitácora AI
   Tema navy oscuro, sobrio y moderno. Componente compartido.
   ============================================================ */

/* Al imprimir, ocultar el sidebar y recuperar el ancho completo */
@media print {
  #appSidebar, .sb-toggle, .sb-overlay { display: none !important; }
  body.has-sidebar { padding-left: 0 !important; padding-top: 0 !important; }
  body.has-sidebar::before, body.has-sidebar::after { display: none !important; }
}

:root {
  --sb-width: 248px;
  --sb-bg-top: #0f172a;     /* navy/slate muy oscuro */
  --sb-bg-bot: #1e293b;     /* navy/slate un poco más claro */
  --sb-surface: #1e293b;    /* hover / superficies */
  --sb-surface-2: #334155;  /* hover más marcado */
  --sb-text: #cbd5e1;       /* texto inactivo */
  --sb-text-strong: #ffffff;/* texto activo */
  --sb-muted: #94a3b8;      /* texto secundario */
  --sb-accent: #3b82f6;     /* azul de acento */
  --sb-accent-soft: rgba(59,130,246,0.16);
  --sb-border: rgba(148,163,184,0.14);
  --sb-danger: #f87171;
}

/* El body de cada página usa esta clase para dejar espacio al sidebar */
body.has-sidebar {
  padding-top: 0 !important;
  padding-left: var(--sb-width);
  /* Lienzo sobrio gris-slate (no navy): suaviza el contraste con el sidebar.
     Las tarjetas/containers blancos quedan "flotando" sobre este fondo. */
  background: #eef2f7 !important;
  min-height: 100vh;
}

/* Franja navy pintada por CSS de inmediato (antes de que el JS inyecte el
   sidebar). Evita el parpadeo al navegar: la columna izquierda ya es navy
   en cuanto carga la hoja de estilos, y #appSidebar (z-index mayor) la
   rellena encima sin salto visual. */
body.has-sidebar::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sb-width);
  background: linear-gradient(180deg, var(--sb-bg-top) 0%, var(--sb-bg-bot) 100%);
  z-index: 1999;
  pointer-events: none;
}

/* ---------- Contenedor del sidebar ---------- */
#appSidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sb-width);
  background: linear-gradient(180deg, var(--sb-bg-top) 0%, var(--sb-bg-bot) 100%);
  color: var(--sb-text);
  display: flex;
  flex-direction: column;
  z-index: 2000;
  box-shadow: 2px 0 18px rgba(0,0,0,0.28);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  transition: transform 0.25s ease;
}

/* ---------- Marca ---------- */
.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px 20px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: var(--sb-text-strong);
  border-bottom: 1px solid var(--sb-border);
}
.sb-brand .sb-brand-icon { font-size: 20px; }

/* ---------- Navegación ---------- */
.sb-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sb-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--sb-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: background 0.15s ease, color 0.15s ease;
}
.sb-link .sb-icon {
  font-size: 17px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}
.sb-link:hover {
  background: var(--sb-surface);
  color: var(--sb-text-strong);
}
.sb-link.active {
  background: var(--sb-accent-soft);
  color: var(--sb-text-strong);
}
.sb-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  border-radius: 0 3px 3px 0;
  background: var(--sb-accent);
}

/* ---------- Bloque inferior: tema + usuario + logout ---------- */
.sb-bottom {
  border-top: 1px solid var(--sb-border);
  padding: 14px 16px 18px 16px;
}

/* Switch de modo oscuro */
.sb-theme {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.sb-theme-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--sb-text);
}
.sb-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
  flex-shrink: 0;
}
.sb-switch input { opacity: 0; width: 0; height: 0; }
.sb-switch-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: #475569;
  border-radius: 22px;
  transition: background 0.2s ease;
}
.sb-switch-slider::before {
  content: '';
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}
.sb-switch input:checked + .sb-switch-slider { background: var(--sb-accent); }
.sb-switch input:checked + .sb-switch-slider::before { transform: translateX(20px); }
.sb-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.sb-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--sb-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.sb-user-info { min-width: 0; }
.sb-user-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--sb-text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-rol-badge {
  display: inline-block;
  margin-top: 3px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--sb-surface-2);
  color: var(--sb-muted);
}
.sb-rol-badge.tecnico { background: rgba(255,193,7,0.18); color: #fcd34d; }
.sb-rol-badge.subcontratista { background: rgba(245,158,11,0.18); color: #fbbf24; }
.sb-rol-badge.project_manager { background: rgba(40,167,69,0.18); color: #86efac; }
.sb-rol-badge.gerente { background: rgba(23,162,184,0.18); color: #67e8f9; }
.sb-rol-badge.superusuario { background: rgba(167,139,250,0.20); color: #c4b5fd; }

.sb-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--sb-border);
  border-radius: 10px;
  background: transparent;
  color: var(--sb-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}
.sb-logout:hover {
  background: rgba(248,113,113,0.12);
  border-color: rgba(248,113,113,0.4);
  color: var(--sb-danger);
}

/* ---------- Botón hamburguesa (móvil) ---------- */
.sb-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 2100;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: none;
  background: var(--sb-bg-top);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
  align-items: center;
  justify-content: center;
}

/* ---------- Overlay (móvil) ---------- */
.sb-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1900;
}
.sb-overlay.visible { display: block; }

/* ---------- Responsive: off-canvas en móvil ---------- */
@media (max-width: 768px) {
  body.has-sidebar {
    padding-left: 0;
    /* Reserva una franja superior para la barra/botón de menú: así los
       títulos de cada página nunca quedan debajo del botón ☰. */
    padding-top: 56px !important;
  }
  body.has-sidebar::before { display: none; } /* sin franja lateral en móvil (off-canvas) */

  /* Barra superior fija (aloja el botón ☰) */
  body.has-sidebar::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 52px;
    background: linear-gradient(180deg, var(--sb-bg-top) 0%, var(--sb-bg-bot) 100%);
    box-shadow: 0 2px 10px rgba(0,0,0,0.28);
    z-index: 1500;
  }

  #appSidebar { transform: translateX(-100%); }
  #appSidebar.open { transform: translateX(0); }

  .sb-toggle { display: flex; top: 6px; left: 12px; }
}
