.app-navbar {
  width: calc(100% - 32px);
  max-width: 1920px;
  margin: 18px auto 12px;
  background: var(--surface-glass-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
}

.app-navbar.is-sticky {
  position: sticky;
  top: 8px;
  z-index: 120;
}

.navbar-inner {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 11px 14px;
}

.navbar-brand-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.navbar-brand {
  text-decoration: none;
  color: #60a5fa;
  font-family: 'DM Sans', sans-serif;
  font-weight: 1000;
  font-size: var(--text-md);
  letter-spacing: 0.02em;
}

.feature-search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: var(--space-2);
}

.feature-search-input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0 var(--space-3);
  min-height: 40px;
  background: var(--surface-1);
  color: var(--shell-ink);
  color-scheme: dark;
}

.feature-search-input::placeholder {
  color: #475569;
}

.feature-search-button {
  min-height: 40px;
  border: none;
  border-radius: var(--radius-md);
  padding: 0 13px;
  background: var(--brand);
  color: #fff;
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
}

.navbar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius-lg);
  padding: var(--space-1) 6px;
}

.navbar-user:hover {
  background: rgba(255, 255, 255, 0.05);
}

.navbar-user:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.navbar-avatar-image,
.navbar-avatar-fallback {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-default);
  flex: 0 0 auto;
}

.navbar-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-bold);
}

.navbar-user-meta {
  display: grid;
  min-width: 0;
}

.navbar-user-meta strong,
.navbar-user-meta span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.navbar-user-meta strong {
  font-size: var(--text-sm);
}

.navbar-user-meta span {
  font-size: var(--text-xs);
  color: var(--shell-muted);
}

.navbar-user-cluster {
  display: flex;
  align-items: center;
  gap: 4px;
}

.navbar-icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  border-radius: var(--radius-lg);
  color: inherit;
  text-decoration: none;
}

.navbar-icon-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.navbar-icon-btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.navbar-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  background: var(--brand);
  color: #fff;
  font-size: 10px;
  font-weight: var(--font-weight-bold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
  pointer-events: none;
}

.navbar-guest-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: end;
  width: auto;
  white-space: nowrap;
  min-height: 40px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  font-size: var(--text-base);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  text-decoration: none;
  padding: 0 var(--space-4);
  transition:
    background var(--duration-base) var(--ease-default),
    border-color var(--duration-base) var(--ease-default),
    transform var(--duration-base) var(--ease-default);
}

.navbar-guest-cta:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  transform: translateY(-1px);
}

.navbar-guest-cta:active {
  transform: translateY(0);
}

.navbar-guest-cta:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.shell {
  --sidebar-width-expanded: 270px;
  --sidebar-width-collapsed: 72px;
  width: calc(100% - 32px);
  max-width: 1920px;
  margin: var(--space-4) auto 18px;
  display: grid;
  grid-template-columns: var(--sidebar-width-expanded) minmax(0, 1fr);
  align-items: start;
  gap: 18px;
  transition: grid-template-columns var(--duration-fast) var(--ease-default);
}

.shell.is-sidebar-collapsed,
html[data-sidebar-collapsed] .shell:not(.is-sidebar-collapsed) {
  grid-template-columns: var(--sidebar-width-collapsed) minmax(0, 1fr);
}

.sidebar {
  background: var(--surface-glass-2);
  border: 1px solid var(--border-default);
  border-right: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 18px;
  position: sticky;
  top: 14px;
  align-self: start;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
}

.sidebar-toggle-row {
  display: flex;
  justify-content: flex-start;
  margin-bottom: var(--space-2);
}

.sidebar-toggle-btn {
  padding: 8px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--shell-muted);
  cursor: pointer;
  transition:
    background var(--duration-base),
    border-color var(--duration-base),
    color var(--duration-base);
}

.sidebar-toggle-btn:hover {
  background: var(--sidebar-active-bg);
  border-color: var(--border-strong);
  color: var(--brand);
}

.sidebar-toggle-btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.sidebar-toggle-icon {
  display: block;
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  flex: 0 0 16px;
  flex-shrink: 0;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-toggle-glyph {
  display: block;
  line-height: 0;
}

/* Desktop: single panel icon; mobile close icon stays hidden */
.sidebar-toggle-btn .sidebar-toggle-glyph--desktop-expanded {
  display: block;
}

.sidebar-toggle-btn .sidebar-toggle-glyph--close {
  display: none;
}

.sidebar-section {
  margin-top: 0;
}

.sidebar-section + .sidebar-section {
  margin-top: var(--space-4);
}

.sidebar-section-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--shell-muted);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: #cbd5e1;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 10px;
  font-size: var(--text-base);
  margin-bottom: 5px;
  transition:
    color var(--duration-base),
    background var(--duration-base),
    border-color var(--duration-base);
}

.sidebar nav .sidebar-link:last-child {
  margin-bottom: 0;
}

.sidebar-link-profile {
  width: 100%;
}

.sidebar-link-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-link-label {
  min-width: 0;
}

.sidebar-link-dot {
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  flex-shrink: 0;
  background: #fbbf24;
}

.sidebar-profile-avatar-wrap {
  display: inline-flex;
  flex: 0 0 auto;
}

.sidebar-profile-avatar {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-default);
  flex: 0 0 auto;
}

.sidebar-profile-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-bold);
}

.sidebar-link:hover {
  background: var(--sidebar-active-bg);
  border-color: var(--border-default);
  color: var(--shell-ink);
}

.sidebar-link.is-active {
  border-color: rgba(59, 158, 255, 0.4);
  background: rgba(59, 158, 255, 0.15);
  color: var(--brand);
  font-weight: var(--font-weight-semibold);
}

.shell.is-sidebar-collapsed .sidebar,
html[data-sidebar-collapsed] .shell:not(.is-sidebar-collapsed) .sidebar {
  padding: 18px var(--space-2);
}

.shell.is-sidebar-collapsed .sidebar-toggle-row,
html[data-sidebar-collapsed] .shell:not(.is-sidebar-collapsed) .sidebar-toggle-row {
  justify-content: center;
}

.shell.is-sidebar-collapsed .sidebar-link,
html[data-sidebar-collapsed] .shell:not(.is-sidebar-collapsed) .sidebar-link {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.shell.is-sidebar-collapsed .sidebar-link-label,
html[data-sidebar-collapsed] .shell:not(.is-sidebar-collapsed) .sidebar-link-label {
  display: none;
}

.shell.is-sidebar-collapsed .sidebar-link-with-icon,
html[data-sidebar-collapsed] .shell:not(.is-sidebar-collapsed) .sidebar-link-with-icon {
  position: relative;
}

.shell.is-sidebar-collapsed .sidebar-link-dot,
html[data-sidebar-collapsed] .shell:not(.is-sidebar-collapsed) .sidebar-link-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  margin-left: 0;
  width: 6px;
  height: 6px;
}

.shell.is-sidebar-collapsed .sidebar-section-title,
html[data-sidebar-collapsed] .shell:not(.is-sidebar-collapsed) .sidebar-section-title {
  visibility: hidden;
}

.content {
  display: grid;
  align-content: start;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr);
}

/* Mobile hamburger: hidden by default (desktop) */
.navbar-mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-height: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--shell-muted);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.navbar-mobile-menu-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.navbar-mobile-menu-btn:hover {
  background: var(--brand-soft);
  border-color: rgba(59, 158, 255, 0.3);
  color: var(--brand);
}

/* Sidebar mobile overlay backdrop */
.sidebar-mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1099;
  cursor: pointer;
}

.sidebar-mobile-overlay.is-visible {
  display: block;
}

/* Bottom tab bar — hidden on desktop/tablet, shown on mobile */
.bottom-nav {
  display: none;
}

@media (min-width: 641px) and (max-width: 1080px) {
  .config-layout {
    grid-template-columns: 1fr;
  }

  .navbar-inner {
    grid-template-columns: 1fr;
  }

  .navbar-guest-cta {
    width: fit-content;
    min-height: 40px;
    justify-self: start;
  }

  .feature-search-form {
    display: none;
  }

  .navbar-user {
    display: none;
  }

  /* Shell: bloque simple, el sidebar ya no ocupa columna */
  .shell {
    display: block;
  }

  .shell.is-sidebar-collapsed {
    display: block;
  }

  /* Hamburger visible en tablet */
  .navbar-mobile-menu-btn {
    display: inline-flex;
  }

  /* Sidebar: drawer off-screen por defecto */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    border-radius: 0;
    border-right: 1px solid var(--border-default);
    transform: translateX(-100%);
    z-index: 1100;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* Transición habilitada solo después del primer paint (evita flash al cargar) */
  .sidebar.sidebar-ready {
    transition:
      transform var(--duration-slow) var(--ease-default),
      box-shadow var(--duration-slow) var(--ease-default);
  }

  /* Drawer abierto */
  .sidebar.is-mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }

  /* Mostrar botón close dentro del drawer en tablet */
  .sidebar-toggle-row {
    display: flex;
    justify-content: flex-end;
  }

  /* En tablet: mostrar ✕, ocultar iconos desktop */
  .sidebar-toggle-btn .sidebar-toggle-glyph--desktop-expanded {
    display: none;
  }

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

  /* Resetear estado collapsed en tablet (siempre full width) */
  .shell.is-sidebar-collapsed .sidebar {
    width: 280px;
  }

  .shell.is-sidebar-collapsed .sidebar-link {
    justify-content: flex-start;
    padding-left: 10px;
    padding-right: 10px;
  }

  .shell.is-sidebar-collapsed .sidebar-link-label {
    display: inline;
  }

  .shell.is-sidebar-collapsed .sidebar-profile-avatar-wrap {
    display: inline-flex;
  }

  .filter-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    padding: 22px;
  }

  .connections-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  /* Navbar simplificado — solo logo */
  .navbar-inner {
    grid-template-columns: 1fr;
    padding: var(--space-2) var(--space-3);
  }

  .feature-search-form {
    display: none;
  }

  .navbar-user {
    display: none;
  }

  .navbar-mobile-menu-btn {
    display: none;
  }

  .navbar-guest-cta {
    width: 100%;
    min-height: 44px;
    justify-self: stretch;
  }

  /* Shell: bloque simple */
  .shell {
    display: block;
    /* Espacio extra para el bottom nav */
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
  }

  .shell.is-sidebar-collapsed {
    display: block;
  }

  /* Sidebar y overlay ocultos — bottom nav toma el control */
  .sidebar,
  .sidebar-mobile-overlay {
    display: none !important;
  }

  /* Bottom tab bar */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--surface-glass-2);
    border-top: 1px solid var(--border-default);
    backdrop-filter: blur(12px);
    z-index: 1100;
    justify-content: space-around;
    align-items: stretch;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex: 1;
    text-decoration: none;
    color: var(--shell-muted);
    padding: var(--space-2) 0;
    border-radius: 0;
    transition: color var(--duration-base);
    min-height: 44px;
  }

  .bottom-nav-item.is-active {
    color: var(--brand);
  }

  .bottom-nav-item svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .bottom-nav-label {
    font-size: var(--text-xs);
    font-weight: var(--font-weight-medium);
    line-height: 1;
  }
}
