/* ==========================================================================
   Uniframe Studio — Topbar v2 (camada de refinamento)
   Carregado DEPOIS de /styles.css. Só vale para <body class="tbv2">.
   O layout atual (/) não é afetado.

   O que muda em relação à topbar atual:
   1. Marca: logo "U" nova no rail; wordmark simples, sem o selo "Pro Multi-User".
   2. Breadcrumb: Uniframe Studio / Projeto — o projeto ativo vira o contexto da página.
   3. Modos no centro, em português e com estado ativo legível.
   4. Lado direito enxuto: status dos motores com cor real (verde só com 100%),
      Contas e Logs como ações discretas. Grid/List saem daqui porque já existem
      na barra da galeria logo abaixo (Grade/Lista).
   ========================================================================== */

body.tbv2 {
  --tb2-height: 56px;
  --tb2-control-h: 32px;
  --tb2-radius: 9px;
  --tb2-fill: rgba(255, 255, 255, 0.04);
  --tb2-fill-hover: rgba(255, 255, 255, 0.07);
  --tb2-fill-active: rgba(255, 255, 255, 0.10);
  --tb2-hairline: rgba(255, 255, 255, 0.07);
  --tb2-hairline-strong: rgba(255, 255, 255, 0.12);
  --tb2-focus: var(--border-focus);
  --topbar-height: var(--tb2-height);
}

/* --------------------------------------------------------------------------
   Rail: logo nova, sem o ponto verde sobreposto
   -------------------------------------------------------------------------- */

body.tbv2 .brand-monogram {
  width: 44px;
  height: 44px;
}

body.tbv2 .brand-monogram-img {
  width: 30px;
  filter: drop-shadow(0 4px 14px rgba(99, 102, 241, 0.40));
}

/* --------------------------------------------------------------------------
   Estrutura: 3 zonas — contexto | modo | status
   -------------------------------------------------------------------------- */

body.tbv2 .app-topbar.tb2 {
  display: grid;
  /* max-content como mínimo: as zonas nunca se sobrepõem */
  grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
  align-items: center;
  gap: 20px;
  height: var(--tb2-height);
  padding: 0 16px 0 18px;
  background-color: var(--surface-topbar);
  border-bottom: 1px solid var(--tb2-hairline);
}

body.tbv2 .tb2-left {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  justify-self: start;
}

body.tbv2 .tb2-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  justify-self: end;
}

/* --------------------------------------------------------------------------
   Marca + breadcrumb do projeto
   -------------------------------------------------------------------------- */

body.tbv2 .tb2-brand {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: var(--tb2-control-h);
  padding: 0 6px 0 2px;
  border-radius: var(--tb2-radius);
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

body.tbv2 .tb2-brand:focus-visible {
  outline: 2px solid var(--tb2-focus);
  outline-offset: 2px;
}

body.tbv2 .tb2-wordmark {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

body.tbv2 .tb2-wordmark-sub {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text-secondary);
}

body.tbv2 .tb2-sep {
  color: var(--text-disabled);
  font-size: 18px;
  font-weight: 300;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
  user-select: none;
}

body.tbv2 .tb2-left .project-selector-wrapper {
  min-width: 0;
}

body.tbv2 .tb2-left .project-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--tb2-control-h);
  max-width: 300px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--tb2-radius);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  text-transform: none;
  transition: background-color var(--duration-fast), border-color var(--duration-fast);
}

body.tbv2 .tb2-left .project-pill-btn svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

body.tbv2 .tb2-left .project-pill-btn:hover {
  background-color: var(--tb2-fill-hover);
  border-color: var(--tb2-hairline);
}

body.tbv2 .tb2-left .project-pill-btn:focus-visible {
  outline: 2px solid var(--tb2-focus);
  outline-offset: 1px;
}

body.tbv2 .tb2-left .project-pill-btn .project-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Modos (centro)
   -------------------------------------------------------------------------- */

body.tbv2 .tb2 .mode-segmented {
  justify-self: center;
  height: 36px;
  padding: 3px;
  gap: 2px;
  background-color: var(--tb2-fill);
  border: 1px solid var(--tb2-hairline);
  border-radius: 11px;
}

body.tbv2 .tb2 .mode-pill {
  height: 28px;
  padding: 0 12px;
  gap: 7px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

body.tbv2 .tb2 .mode-pill svg {
  flex-shrink: 0;
  opacity: 0.85;
}

body.tbv2 .tb2 .mode-pill:hover {
  background-color: var(--tb2-fill-hover);
  color: var(--text-primary);
}

body.tbv2 .tb2 .mode-pill.active {
  background-color: var(--surface-card-hover);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--tb2-hairline-strong), 0 1px 3px rgba(0, 0, 0, 0.45);
}

body.tbv2 .tb2 .mode-pill.active svg {
  color: var(--accent-lime);
  opacity: 1;
}

body.tbv2 .tb2 .mode-pill:focus-visible {
  outline: 2px solid var(--tb2-focus);
  outline-offset: 1px;
}

/* --------------------------------------------------------------------------
   Status dos motores
   -------------------------------------------------------------------------- */

body.tbv2 .tb2 .engine-hub-btn {
  height: var(--tb2-control-h);
  gap: 8px;
  padding: 0 10px 0 11px;
  background: transparent;
  border: 1px solid var(--tb2-hairline);
  border-radius: var(--tb2-radius);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
}

body.tbv2 .tb2 .engine-hub-btn:hover,
body.tbv2 .tb2 .engine-hub-btn[aria-expanded="true"] {
  background-color: var(--tb2-fill-hover);
  border-color: var(--tb2-hairline-strong);
  color: var(--text-primary);
}

body.tbv2 .tb2 .engine-hub-btn:focus-visible {
  outline: 2px solid var(--tb2-focus);
  outline-offset: 1px;
}

body.tbv2 .tb2 .engine-hub-title {
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text-primary);
}

body.tbv2 .tb2 .engine-hub-badge {
  padding: 0;
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

/* Saúde calculada pelo topbar-v2.js a partir do "n/m Online":
   verde só quando todos estão online; âmbar quando falta algum; vermelho com zero.
   O estado "busy" (gerando) do app continua tendo prioridade. */
body.tbv2 .tb2 .engine-hub-btn[data-health="partial"] .engine-hub-pulse-dot:not(.busy) {
  background-color: var(--status-warning);
  box-shadow: 0 0 6px rgba(234, 179, 8, 0.45);
}

body.tbv2 .tb2 .engine-hub-btn[data-health="down"] .engine-hub-pulse-dot:not(.busy) {
  background-color: var(--status-danger);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.45);
}

body.tbv2 .tb2 .engine-hub-btn[data-health="partial"] .engine-hub-badge {
  color: var(--status-warning);
}

body.tbv2 .tb2 .engine-hub-btn[data-health="down"] .engine-hub-badge {
  color: var(--status-danger);
}

/* --------------------------------------------------------------------------
   Ações (Contas, Logs)
   -------------------------------------------------------------------------- */

body.tbv2 .tb2-divider {
  width: 1px;
  height: 20px;
  margin: 0 4px;
  background-color: var(--tb2-hairline-strong);
  flex-shrink: 0;
}

body.tbv2 .tb2 .tb2-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: var(--tb2-control-h);
  min-width: var(--tb2-control-h);
  padding: 0 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--tb2-radius);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--duration-fast), color var(--duration-fast), border-color var(--duration-fast);
}

body.tbv2 .tb2 .tb2-action.icon-only {
  padding: 0;
  width: var(--tb2-control-h);
}

body.tbv2 .tb2 .tb2-action:hover {
  background-color: var(--tb2-fill-hover);
  color: var(--text-primary);
}

body.tbv2 .tb2 .tb2-action:focus-visible {
  outline: 2px solid var(--tb2-focus);
  outline-offset: 1px;
}

body.tbv2 .tb2 .tb2-action.active {
  background-color: var(--tb2-fill-active);
  border-color: var(--tb2-hairline-strong);
  color: var(--text-primary);
}

body.tbv2 .tb2 .tb2-action svg {
  flex-shrink: 0;
}

/* Grid/List da topbar: mantidos no DOM (o app.js os atualiza), mas fora da tela,
   porque a barra da galeria já tem Grade/Lista. */
body.tbv2 .tb2-hidden-controls {
  display: none;
}

/* --------------------------------------------------------------------------
   Responsivo: primeiro some o secundário, depois os rótulos dos modos
   -------------------------------------------------------------------------- */

/* Contador compacto de contas (preenchido pelo topbar-v2.js), só aparece
   quando o rótulo "Contas (n)" some */
body.tbv2 .tb2 .tb2-count {
  display: none;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1440px) {
  body.tbv2 .tb2-wordmark-sub { display: none; }
  body.tbv2 .tb2-left .project-pill-btn { max-width: 220px; }
  body.tbv2 .tb2 .engine-hub-title { display: none; }
  body.tbv2 .tb2 .tb2-action .tb2-action-label { display: none; }
  body.tbv2 .tb2 .tb2-count:not(:empty) { display: inline; }
}

@media (max-width: 1240px) {
  body.tbv2 .tb2 .mode-pill span { display: none; }
  body.tbv2 .tb2 .mode-pill { padding: 0 10px; }
  body.tbv2 .app-topbar.tb2 { gap: 12px; }
}

@media (max-width: 920px) {
  body.tbv2 .tb2-brand,
  body.tbv2 .tb2-sep,
  body.tbv2 .tb2-divider { display: none; }
  body.tbv2 .tb2-left .project-pill-btn { max-width: 170px; }
  body.tbv2 .app-topbar.tb2 { gap: 8px; padding: 0 10px 0 8px; }
}

@media (prefers-reduced-motion: reduce) {
  body.tbv2 .tb2 * { transition: none !important; }
}
