/* Layout topbar — escopado em body.layout-topbar (não altera sidebar) */

body.layout-topbar {
  --navbar-top-height: 72px;
  --navbar-top-z: 110;
}

/* Oculta navbar horizontal no modo sidebar */
body.layout-sidebar .navbar-top {
  display: none !important;
}

/* Oculta sidebar no modo topbar */
body.layout-topbar .sidebar,
body.layout-topbar #sidebar-overlay {
  display: none !important;
}

/* Shell: coluna única com nav no topo */
body.layout-topbar.app-logged-in #app-content.app-wrapper {
  display: flex !important;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  grid-template-columns: unset;
}

body.layout-topbar .app-main-column {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  height: auto;
  max-height: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.layout-topbar .main-content {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  margin-left: 0;
  overflow: auto;
}

body.layout-topbar .main-content > .container {
  width: 100%;
  max-width: none;
  margin-left: 0;
  margin-right: 0;
}

/* ===== Navbar horizontal principal ===== */
body.layout-topbar .navbar-top {
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
  width: 100%;
  min-height: var(--navbar-top-height);
  background: linear-gradient(90deg, #2b0b45 0%, #35105a 42%, #2d0a52 100%);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.28);
  position: sticky;
  top: 0;
  z-index: var(--navbar-top-z);
}

body.layout-topbar #assinatura-aviso:not([style*="display: none"]) ~ .navbar-top,
body.layout-topbar #assinatura-aviso[style*="display: flex"] ~ .navbar-top,
body.layout-topbar #assinatura-aviso[style*="display:flex"] ~ .navbar-top {
  top: 0;
}

body.layout-topbar .navbar-top__inner {
  display: flex;
  align-items: stretch;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  gap: 0;
}

body.layout-topbar .navbar-top__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px 0 16px;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
  color: #ffffff;
}

body.layout-topbar .navbar-top__brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: none;
  border: 0;
}

body.layout-topbar .navbar-top__brand-icon i {
  font-size: 20px;
  opacity: 1;
  color: #ffffff;
}

body.layout-topbar .navbar-top__scroll {
  display: flex;
  align-items: stretch;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

body.layout-topbar .navbar-top__scroll::-webkit-scrollbar {
  height: 4px;
}

body.layout-topbar .navbar-top__scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
}

body.layout-topbar .navbar-top-nav {
  display: flex;
  align-items: stretch;
  flex: 1 1 auto;
  min-width: max-content;
}

body.layout-topbar .navbar-top-section {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 12px;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  gap: 4px;
}

body.layout-topbar .navbar-top-section__label {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
  line-height: 1;
  padding: 0 2px;
  text-align: center;
  white-space: nowrap;
}

body.layout-topbar .navbar-top-section__links {
  display: flex;
  align-items: center;
  gap: 1px;
  flex-wrap: nowrap;
}

body.layout-topbar .navbar-top-nav .nav-link {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  width: auto;
  max-width: none;
  padding: 4px 8px;
  border-radius: 7px;
  color: #ffffff;
  text-decoration: none;
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
  text-align: center;
  transition: background 0.15s ease, color 0.15s ease;
  border: none;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}

body.layout-topbar .navbar-top-nav .nav-link i {
  font-size: 18px;
  opacity: 1;
  line-height: 1;
}

body.layout-topbar .navbar-top-nav .nav-link span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  letter-spacing: 0.01em;
}

body.layout-topbar .navbar-top-nav .nav-link:hover span,
body.layout-topbar .navbar-top-nav .nav-link.active span {
  overflow: visible;
  text-overflow: clip;
}

body.layout-topbar .navbar-top-nav .nav-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

body.layout-topbar .navbar-top-nav .nav-link.active {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

body.layout-topbar .navbar-top-ai-badge {
  display: inline-block;
  font-size: 7px;
  font-weight: 800;
  padding: 0 4px;
  border-radius: 999px;
  background: #7c3aed;
  color: #fff;
  vertical-align: middle;
  margin-left: 2px;
  line-height: 1.4;
}

body.layout-topbar .navbar-top__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 0 12px;
  flex-shrink: 0;
  border-left: none;
  margin-left: auto;
}

body.layout-topbar .navbar-top__user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(220px, 22vw);
  padding: 6px 14px 6px 10px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  flex-shrink: 0;
}

body.layout-topbar .navbar-top__user-pill[hidden] {
  display: none !important;
}

body.layout-topbar .navbar-top__user-pill-icon {
  flex-shrink: 0;
  font-size: 15px;
  color: #7c3aed;
  line-height: 1;
}

body.layout-topbar .navbar-top__user-pill-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.2;
}

/* Notificações ficam dentro do menu da engrenagem */
body.layout-topbar .navbar-top__notif {
  display: none !important;
}

body.layout-topbar .gear-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

body.layout-topbar .gear-menu-btn:hover,
body.layout-topbar .gear-menu-btn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
}

/* ===== Gear dropdown ===== */
body.layout-topbar .gear-dropdown-wrap {
  position: relative;
}

body.layout-topbar .gear-dropdown__notif {
  position: relative;
}

body.layout-topbar .gear-dropdown__item--notif {
  position: relative;
  justify-content: flex-start;
}

body.layout-topbar .gear-dropdown__item--notif .fa-bell {
  color: #d4af37;
}

body.layout-topbar .gear-notif-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger, #dc2626);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
  pointer-events: none;
  flex-shrink: 0;
}

body.layout-topbar .gear-dropdown__notif-panel {
  position: static;
  width: 100%;
  max-height: min(280px, 45vh);
  margin-top: 4px;
  box-shadow: none;
  border: 1px solid var(--border);
  border-radius: 8px;
}

body.layout-topbar .gear-dropdown__notif-panel[hidden] {
  display: none !important;
}

body.layout-topbar .gear-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 1300;
  width: min(300px, calc(100vw - 24px));
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

body.layout-topbar .gear-dropdown[hidden] {
  display: none !important;
}

body.layout-topbar .gear-dropdown__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease;
}

body.layout-topbar .gear-dropdown__item:hover {
  background: var(--bg-secondary);
}

body.layout-topbar .gear-dropdown__item i {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

body.layout-topbar .gear-dropdown__item--danger {
  color: var(--danger);
}

body.layout-topbar .gear-dropdown__item--danger:hover {
  background: rgba(220, 38, 38, 0.08);
}

body.layout-topbar .gear-dropdown__layout {
  padding: 8px 10px 6px;
}

body.layout-topbar .gear-dropdown__layout-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
  margin-bottom: 4px;
}

body.layout-topbar .gear-dropdown__layout-hint {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--text-light);
  line-height: 1.35;
}

body.layout-topbar .gear-dropdown__divider {
  height: 1px;
  margin: 4px 0;
  background: var(--border);
}

body.layout-topbar .gear-dropdown__meta {
  padding: 8px 12px 4px;
  font-size: 12px;
  color: var(--text-light);
  line-height: 1.45;
}

body.layout-topbar .gear-dropdown__meta strong {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
  margin-bottom: 2px;
}

body.layout-topbar .gear-dropdown__meta .js-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}

body.layout-topbar .gear-dropdown__date {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Oculta utilitários da topbar secundária no modo topbar (movidos para gear) */
body.layout-topbar .topbar-right .topbar-utilities,
body.layout-topbar .topbar-right .topbar-date,
body.layout-topbar .topbar-right .topbar-user-cluster,
body.layout-topbar .topbar-right .btn-logout {
  display: none !important;
}

/* Seletor de layout na topbar secundária (modo sidebar) */
.topbar-layout-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

body.layout-topbar .topbar-layout-wrap {
  display: none !important;
}

.topbar-layout-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 1200;
  width: min(240px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}

.topbar-layout-panel[hidden] {
  display: none !important;
}

.topbar-layout-panel__label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
  margin-bottom: 4px;
}

.topbar-layout-panel__hint {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--text-light);
  line-height: 1.35;
}

.layout-preference-grid--topbar-inline {
  gap: 8px;
  margin-top: 0;
}

.layout-preference-grid--topbar-inline .layout-preference-btn {
  padding: 10px 8px;
  font-size: 12px;
  gap: 6px;
}

.layout-preference-grid--topbar-inline .layout-preference-btn i {
  font-size: 18px;
}

body.layout-topbar .topbar {
  flex-shrink: 0;
  position: relative;
  z-index: calc(var(--navbar-top-z) - 1);
}

/* Oculta gear no modo sidebar */
body.layout-sidebar .gear-dropdown-wrap,
body.layout-sidebar .navbar-top__actions {
  display: none !important;
}

/* Mobile: bottom-nav oculto no modo topbar (nav já está no topo) */
@media (max-width: 768px) {
  body.layout-topbar .bottom-nav {
    display: none !important;
  }

  body.layout-topbar .main-content {
    padding-bottom: var(--space-4);
  }

  body.layout-topbar .navbar-top-section {
    padding: 6px 8px;
  }

  body.layout-topbar .navbar-top-nav .nav-link {
    padding: 4px 6px;
  }

  body.layout-topbar .navbar-top-nav .nav-link i {
    font-size: 16px;
  }

  body.layout-topbar .navbar-top-nav .nav-link span {
    font-size: 9px;
  }

  body.layout-topbar .navbar-top__user-pill {
    max-width: min(160px, 36vw);
    padding: 5px 10px 5px 8px;
  }

  body.layout-topbar .navbar-top__user-pill-name {
    font-size: 12px;
  }
}

/* Desktop zoom do sidebar não se aplica no topbar */
@media (min-width: 1025px) {
  body.layout-topbar.app-logged-in .app-main-column {
    zoom: 1;
    height: auto;
    max-height: none;
  }
}

/* Impressão: esconde navbar horizontal */
@media print {
  body.sr-printing .navbar-top {
    display: none !important;
  }
}

.layout-preference-grid--gear {
  gap: 8px;
}

.layout-preference-grid--gear .layout-preference-btn {
  padding: 10px 8px;
  font-size: 12px;
  gap: 6px;
}

.layout-preference-grid--gear .layout-preference-btn i {
  font-size: 18px;
}

/* Preferência de layout (engrenagem) */
.layout-preference-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.layout-preference-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 12px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  font-size: 13px;
  font-weight: 600;
}

.layout-preference-btn i {
  font-size: 24px;
  color: var(--accent);
}

.layout-preference-btn:hover {
  border-color: rgba(124, 58, 237, 0.4);
  background: var(--bg-secondary);
}

.layout-preference-btn.is-active {
  border-color: var(--accent);
  background: rgba(124, 58, 237, 0.08);
  box-shadow: 0 0 0 1px rgba(124, 58, 237, 0.2);
}

@media (max-width: 480px) {
  .layout-preference-grid {
    grid-template-columns: 1fr;
  }
}
