/**
 * ====================================================================
 * BASE, TIPOGRAFÍA, LAYOUT RESPONSIVE Y NAVEGACIÓN
 * ====================================================================
 */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  overflow-x: hidden;
}

/* Enlaces y botones base */
a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent-hover);
}

img, svg {
  display: block;
  max-width: 100%;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ====================================================================
 * LAYOUT PRINCIPAL (SHELL)
 * ==================================================================== */
.app-container {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

/* Barra lateral de navegación */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: transform var(--transition-normal);
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
}

.sidebar-header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.35);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
}

.sidebar-close-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
}

.sidebar-nav {
  flex: 1;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-text-muted);
  padding: 0.75rem 0.75rem 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  color: var(--sidebar-text);
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.93rem;
  transition: all var(--transition-fast);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  opacity: 0.8;
  flex-shrink: 0;
}

.nav-item:hover {
  background-color: var(--sidebar-hover);
  color: #ffffff;
}

.nav-item.active {
  background-color: var(--sidebar-active);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

.nav-item.active svg {
  opacity: 1;
}

.nav-badge {
  margin-left: auto;
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  background-color: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  font-weight: 600;
}

.sidebar-footer {
  padding: 1.25rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-snippet {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar-sm {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: #1e3a5f;
  color: #ffffff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.user-avatar-sm img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-info-text {
  flex: 1;
  min-width: 0;
}

.user-name-line {
  font-size: 0.88rem;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role-line {
  font-size: 0.75rem;
  color: var(--sidebar-text-muted);
  text-transform: capitalize;
}

/* ====================================================================
 * ÁREA DE CONTENIDO PRINCIPAL Y TOPBAR
 * ==================================================================== */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(8px);
  background-color: rgba(var(--bg-surface), 0.9);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.mobile-toggle-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
}

.topbar-page-title h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.topbar-page-title p {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.theme-toggle-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.theme-toggle-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.content-body {
  flex: 1;
  padding: 2rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* Backdrop para móvil */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

/* ====================================================================
 * BREAKPOINTS RESPONSIVE (MOBILE FIRST)
 * ==================================================================== */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close-btn {
    display: block;
  }

  .main-wrapper {
    margin-left: 0;
  }

  .mobile-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-backdrop.active {
    display: block;
    opacity: 1;
  }

  .topbar {
    padding: 0 1.25rem;
  }

  .content-body {
    padding: 1.25rem;
  }
}

@media (max-width: 640px) {
  .topbar-page-title p {
    display: none;
  }

  .topbar-page-title h1 {
    font-size: 1.15rem;
  }
}
