/* Topbar global — premium */

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-page);
  overflow-x: hidden;
}

.app-topbar {
  min-height: 64px;
  height: auto;
  background: var(--surface, #fff);
  border-bottom: 1px solid var(--line, #e2e8f1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
  box-shadow: none;
}

.app-topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  flex: 1;
}

.app-topbar-titles {
  min-width: 0;
  padding-right: 12px;
}

.app-topbar-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: var(--color-text);
  line-height: 1.25;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-topbar-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--color-muted);
  line-height: 1.45;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-topbar-subtitle:empty {
  display: none;
}

.app-topbar-right {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-shrink: 0;
  margin-left: auto;
  padding-left: 12px;
}

.app-topbar-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  flex-shrink: 0;
}

.app-topbar-menu-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.app-topbar-menu-btn:hover {
  background: var(--color-surface-soft);
  border-color: var(--color-border-strong);
}

/* Bloco empresa */
.app-topbar-company {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-width: 240px;
  max-width: 360px;
}

.app-topbar-company-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1;
}

.app-topbar-company-field {
  display: flex;
  align-items: center;
  min-height: 52px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 0 14px;
  box-shadow: var(--shadow-soft);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.app-topbar-company-field:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-ring);
}

.app-topbar-company-select {
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--color-text);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 0;
  min-height: 38px;
  box-shadow: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 2px center;
  padding-right: 20px;
}

.app-topbar-company-select:focus {
  outline: none;
  box-shadow: none;
}

.app-topbar-company-static {
  display: block;
  width: 100%;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 12px 0;
  line-height: 1.3;
}

/* Bloco usuário */
.app-user-menu {
  position: relative;
}

.app-user-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 8px 12px 8px 8px;
  min-height: 56px;
  cursor: pointer;
  color: var(--color-text);
  max-width: 300px;
  box-shadow: var(--shadow-soft);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.app-user-button:hover,
.app-user-button[aria-expanded="true"] {
  border-color: var(--color-border-strong);
  background: #FCFDFE;
  box-shadow: var(--shadow-card);
}

.app-user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  text-align: left;
  flex: 1;
}

.app-user-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
  line-height: 1.25;
}

.app-user-role {
  font-size: 12px;
  color: var(--color-muted);
  white-space: nowrap;
  line-height: 1.35;
}

.app-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(145deg, #1F3A5F, var(--color-primary));
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.app-user-chevron {
  width: 16px;
  height: 16px;
  stroke: var(--color-faint);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.app-user-button[aria-expanded="true"] .app-user-chevron {
  transform: rotate(180deg);
}

.app-user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  box-shadow: var(--shadow-popover);
  min-width: 240px;
  overflow: hidden;
  z-index: 60;
  padding: 8px;
}

.app-user-dropdown-header {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-soft);
  border-radius: 10px 10px 0 0;
}

.app-user-dropdown-header strong {
  font-size: 14px;
  font-weight: 800;
  color: var(--color-text);
}

.app-user-dropdown-header span {
  font-size: 12px;
  color: var(--color-muted);
  word-break: break-word;
}

.app-user-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--color-text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.app-user-dropdown-item:hover {
  background: var(--color-surface-soft);
}

.app-user-dropdown-item--danger {
  color: var(--color-danger);
  margin-top: 4px;
  border-top: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.app-user-dropdown-item--danger:hover {
  background: #FEF2F2;
}

.app-content {
  flex: 1;
  min-width: 0;
  padding: 24px 28px;
  overflow-x: hidden;
}

.app-content > .panel.active-panel > .panel-heading:first-child > h2,
#appContent > .panel.active-panel > .panel-heading:first-child > h2 {
  display: none;
}

.app-content > .panel.active-panel > .panel-heading:first-child > p,
#appContent > .panel.active-panel > .panel-heading:first-child > p {
  margin-top: 0;
}

.app-content > .panel.active-panel > .panel-heading:first-child:has(> h2:only-child),
#appContent > .panel.active-panel > .panel-heading:first-child:has(> h2:only-child) {
  display: none;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.36);
  z-index: 30;
}

.app-shell.sidebar-mobile-open .sidebar-backdrop {
  display: block;
}

@media (max-width: 1024px) {
  .app-topbar {
    padding: 14px 20px;
    gap: 16px;
  }

  .app-topbar-company {
    min-width: 200px;
    max-width: 280px;
  }
}

@media (max-width: 900px) {
  .app-topbar {
    flex-wrap: wrap;
    row-gap: 10px;
    padding: 12px 16px;
    gap: 12px;
    min-height: 64px;
  }

  .app-topbar-menu-btn {
    display: inline-flex;
  }

  .app-topbar-title {
    font-size: 17px;
    max-width: 42vw;
  }

  .app-topbar-right {
    order: 3;
    width: 100%;
    margin-left: 0;
    padding-left: 0;
  }

  .app-topbar-company {
    min-width: 0;
    max-width: none;
    flex: 1;
  }

  .app-user-meta,
  .app-user-chevron {
    display: none;
  }

  .app-user-button {
    padding: 6px;
    border-radius: 50%;
    min-height: auto;
    max-width: none;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 40;
    box-shadow: var(--shadow-card);
  }

  .app-shell.sidebar-mobile-open .sidebar {
    transform: translateX(0);
  }

  .app-content {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .app-topbar-title {
    font-size: 15px;
    max-width: 36vw;
  }

  .app-topbar-subtitle {
    display: none;
  }
}
