/* Reset */
html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: #f5f7fa;
  color: #2c3e50;
  height: auto; /* ✅ Fix necesario para que el scroll funcione siempre */
  width: 100%;
}

:root {
  --sidebar-width: 20%;
  --top-bar-height-desktop: 8%;
  --top-bar-height-mobile: 65px;
}

.pointer {
  cursor: pointer;
}

/* ====== UTILIDADES RESPONSIVE ====== */

/* Visible solo en móvil (< 768px) */
.mobile-only {
  display: none;
}

/* Visible solo en escritorio (≥ 768px) */
.desktop-only {
  display: flex;
}

@media (max-width: 767px) {
  .mobile-only {
    display: flex;
  }
  .desktop-only {
    display: none !important;
  }
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: -1000px; /* oculto en móvil por defecto */
  width: var(--sidebar-width);
  height: 100%;
  background: #2c3e50;
  color: white;
  display: flex;
  flex-direction: column;
  transition: left 0.3s ease-in-out;
  z-index: 998;
  box-shadow: 3px 0 12px rgba(0,0,0,0.25);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar.open {
  left: 0;
  display: block !important;
}

/* Menú - IMPORTANTE: añadir padding-bottom para que se pueda hacer scroll hasta el final */
.menu {
  display: flex;
  flex-direction: column;
  margin-top: 0;
  gap: 0.3rem;
  padding: 1rem 0 5rem 0; /* Aumentado padding-bottom para permitir scroll completo */
  min-height: min-content;
}

.menu > * {
  transition: transform 0.32s ease;
  will-change: transform;
}

/* Botones principales */
.submenu-toggle {
  background: none;
  border: none;
  color: #ecf0f1;
  font-size: 1.1rem;
  text-align: left;
  padding: 0.9rem 1.2rem;
  cursor: pointer;
  width: 100%;
  border-radius: 6px;
  transition: all 0.25s ease;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.submenu-toggle:hover {
  background: #34495e;
  transform: translateX(5px);
}

.submenu-toggle .arrow {
  transition: transform 0.25s;
}

.submenu-toggle .arrow.rotated {
  transform: rotate(90deg);
}

/* Submenús */
.submenu {
  width: 100%;
  display: flex;
  flex-direction: column;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-10px);
  transition: max-height 0.35s ease, opacity 0.3s ease, transform 0.3s ease;
  background: #34495e;
  border-radius: 4px;
  margin: 0.2rem 0;
  border-left: 3px solid #4a6572;
}

.submenu.open {
  max-height: 500px;
  opacity: 1;
  transform: translateY(0);
  display: block !important;
}

/* Submenús de segundo nivel (anidados) */
.submenu .submenu {
  background: #2c3e50;
  border-left: 3px solid #5d7a8c;
  margin: 0.1rem 0.5rem;
  width: calc(100% - 1rem);
}

/* Submenús de tercer nivel (más profundos) */
.submenu .submenu .submenu {
  background: #243342;
  border-left: 3px solid #7B1E1E;
  margin: 0.1rem 0.5rem;
  width: calc(100% - 1rem);
}

/* Botones de submenú anidados */
.submenu .submenu-toggle {
  background: rgba(255, 255, 255, 0.05);
  padding: 0.8rem 1.2rem 0.8rem 1.8rem;
  font-size: 0.95rem;
  border-radius: 4px;
  margin: 0.1rem 0.3rem;
  width: calc(100% - 0.6rem);
}

.submenu .submenu .submenu-toggle {
  padding: 0.75rem 1.2rem 0.75rem 2.4rem;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.92rem;
}

.submenu a {
  color: #dce3ea;
  text-decoration: none;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  font-size: 0.95rem;
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  position: relative;
}

/* Enlaces en submenús anidados */
.submenu .submenu a {
  padding: 0.7rem 1.5rem 0.7rem 1.8rem;
  font-size: 0.93rem;
  background: rgba(255, 255, 255, 0.02);
}

.submenu .submenu .submenu a {
  padding: 0.65rem 1.5rem 0.65rem 2.4rem;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.01);
}

/* Efectos hover diferenciados por nivel */
.submenu a:hover {
  background: #4a6572;
  padding-left: 2rem;
  transform: translateX(5px);
}

.submenu .submenu a:hover {
  background: #3a5166;
  padding-left: 2.2rem;
  transform: translateX(3px);
}

.submenu .submenu .submenu a:hover {
  background: #2d4254;
  padding-left: 2.6rem;
  transform: translateX(2px);
}

/* Indicadores visuales para submenús anidados */
.submenu .submenu-toggle::before {
  content: "›";
  position: absolute;
  left: 0.8rem;
  color: #bdc3c7;
  font-size: 1rem;
  opacity: 0.7;
}

.submenu .submenu .submenu-toggle::before {
  left: 1.4rem;
  content: "»";
}

.maquinas-equipos {
  background-color: #2c3e50;
}

#link-index, #auditoria, #empresas_sucursal, .menu-admin-item {
  color: #dce3ea;
  text-decoration: none;
  padding: 0.75rem 1.2rem;
  border-radius: 6px;
  font-size: 0.95rem;
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

#link-index:hover, #auditoria:hover, #empresas_sucursal:hover, .menu-admin-item:hover {
  background: #34495e;
  padding-left: 2rem;
  transform: translateX(5px);
}

/* ====== BOTÓN HAMBURGUESA ====== */
.menu-toggle {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  transition: all 0.25s ease;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  margin-left: 0.8rem;
}

.menu-toggle:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.08);
}

.menu-toggle:active {
  transform: scale(0.95);
}

/* Contenido principal */
.content {
  margin-left: 0;
  padding: 2rem 0 0 0;
  transition: margin-left 0.3s ease-in-out;
  margin-top: 3%;
  background: #f5f7fa;
  min-height: calc(100vh - 8%); /* Cambiado de height a min-height */
  box-sizing: border-box;
}

.content.shifted {
  margin-left: var(--sidebar-width);
}

/* Íconos dinámicos con Font Awesome */
.submenu-toggle span:first-child {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.submenu-toggle[onclick*="clientesSubmenu"] span:first-child::before {
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  content: "\f0c0"; /* fa-users */
}

.submenu-toggle[onclick*="cobradoresSubmenu"] span:first-child::before {
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  content: "\f19c"; /* fa-briefcase */
}

.submenu-toggle[onclick*="prestamosSubmenu"] span:first-child::before {
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  content: "\f53a"; /* fa-hand-holding-usd */
}

/* Barra superior */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--top-bar-height-desktop);
  background: #7B1E1E;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;
  z-index: 999;
  border-bottom: 3px solid #5a1515;
  transition: transform 0.35s ease;
}

.top-bar-left {
  display: flex;
  align-items: center;
  height: 100%;
  width: var(--sidebar-width); /* Mismo ancho que el sidebar */
  min-width: 250px; /* Ancho mínimo consistente */
  flex-shrink: 0;
}

/* Título en top-bar */
.sidebar-title {
  padding-left: 2%;
  display: flex;
  align-items: center;
  height: 100%;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
  border-right: 2px solid rgba(255, 255, 255, 0.3);
  width: 18%;
}

.sidebar-title h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.5px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}

.block-header {
  width: 30%;
  color: white;
  margin: 0;
  padding-left: 1.5rem;
  font-size: 1.2rem;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  text-align: left;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.6rem 1.2rem;
  transition: all 0.3s ease;
  margin-left: auto;
  flex-shrink: 0;
}

.user-info:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.username {
  font-weight: 600;
  color: white;
  font-size: 1rem;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
}

.logout-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 6px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
}

.logout-btn:hover {
  background: #e74c3c;
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(231, 76, 60, 0.3);
}

/* ESTILOS GENERALES */
.td-amarillo {
  background: rgb(255, 255, 0);
  font-weight: 600;
}

/* Mejora en las transiciones para mejor feedback */
.submenu-toggle {
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.submenu-toggle:hover {
  background: #34495e;
  transform: translateX(5px);
  box-shadow: 2px 0 8px rgba(0,0,0,0.2);
}

/* Efecto de profundidad con sombras */
.submenu .submenu {
  box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
}

.submenu .submenu .submenu {
  box-shadow: inset 0 0 15px rgba(0,0,0,0.15);
}

/* Mejora en los íconos para mayor claridad */
.submenu .submenu-toggle .arrow,
.submenu .submenu .submenu-toggle .arrow {
  font-size: 0.8rem;
  opacity: 0.8;
}

/* ====== ESTILOS PARA PÁGINA DE LOGIN ====== */
body.login-page #sidebar {
  display: none !important;
}

body.login-page .sidebar-title {
  display: none !important;
}

body.login-page .top-bar {
  justify-content: center;
}

body.login-page .top-bar .block-header {
  text-align: center;
  width: 100%;
  padding-left: 0;
  margin: 0;
}

body.login-page .user-info {
  display: none !important;
}

body.login-page .content {
  margin-left: 0 !important;
  width: 100% !important;
  padding-top: 3%;
}

/* Ajuste para que el top-bar ocupe el 100% en login */
body.login-page .top-bar-left {
  display: none;
}

@media (min-width: 768px) and (max-width: 991px) {
  .sidebar-title h1 {
    font-size: 1.2rem;
  }
}

/* RESPONSIVE */
@media (min-width: 768px) {
  .content {
    margin-left: 20%;
    min-height: calc(100vh - var(--top-bar-height-desktop));
  }

  .content.shifted {
    margin-left: 20%;
  }
}

@media (max-width: 767px) {
  .top-bar {
    left: 0;
    height: var(--top-bar-height-mobile);
    padding: 0 0.5rem;
    justify-content: space-between;
  }

  /* Sidebar en móvil - CORREGIDO */
  .sidebar {
    top: 0;
    padding-top: var(--top-bar-height-mobile); /* Empuja el menú debajo de la top-bar */
    height: 100%;
    width: 280px;
    box-sizing: border-box;
  }

  /* Asegurar que el menú tenga suficiente espacio al final */
  .menu {
    padding-bottom: calc(var(--top-bar-height-mobile) + 2rem); /* Espacio extra al final */
    min-height: calc(100% - var(--top-bar-height-mobile));
  }

  .content {
    margin-top: var(--top-bar-height-mobile);
    padding: 1.5rem;
    margin-left: 0 !important;
    min-height: calc(100vh - var(--top-bar-height-mobile));
  }

  .content.shifted {
    margin-left: 0;
  }

  .user-info {
    gap: 1rem;
    padding: 0.5rem 0.8rem;
    margin-left: auto;
  }

  .username {
    font-size: 0.9rem;
  }

  /* Ajustes para submenús anidados en móvil */
  .submenu .submenu,
  .submenu .submenu .submenu {
    width: calc(100% - 0.5rem);
    margin: 0.1rem 0.25rem;
  }

  .submenu .submenu-toggle {
    padding: 0.7rem 1rem 0.7rem 1.5rem;
  }

  .submenu .submenu .submenu-toggle {
    padding: 0.65rem 1rem 0.65rem 2rem;
  }
}

@media (min-width: 768px) {
  .sidebar {
    left: 0;
    top: 0;
    height: 100%;
  }

  .menu-toggle {
    display: none;
  }

  .content {
    margin-left: 20%;
  }
}

/* Móvil */
@media (max-width: 767px) {
  .sidebar {
    box-shadow: 4px 0 15px rgba(0,0,0,0.4);
  }
}

/* Efectos suaves */
.top-bar, .sidebar-title, .user-info, .logout-btn,
.submenu-toggle, .submenu a, #link-index {
  transition: all 0.3s ease;
}

/* Activos */
.submenu-toggle:active,
.submenu a:active,
#link-index:active {
  transform: translateX(3px) scale(0.98);
}

.submenu .submenu-toggle:active,
.submenu .submenu a:active {
  transform: translateX(2px) scale(0.99);
}

/* Motion reduce */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .content,
  .submenu-toggle,
  .submenu,
  .submenu a,
  #link-index,
  .logout-btn,
  .user-info {
    transition: none;
  }

  .submenu-toggle:hover,
  .submenu a:hover,
  #link-index:hover {
    transform: none;
  }
}

/* Scrollbar */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: #2c3e50;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #4a6572;
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: #5d7a8c;
}