/**
 * SUS 360 — Design System 1.0.0
 * componentes/topbar/topbar.css
 *
 * Estilos da topbar fixa, organizada em três áreas: esquerda (gov.br e
 * logo), centro (título, versão, visão atual e breadcrumbs) e direita
 * (status e ações).
 *
 * Depende de: variáveis de design system (--header-height, --border-color,
 * --sus-blue, --radius-*, --text-*, --shadow-lg, --z-*,
 * --transition-fast) e animações pulse-glow, pulse-glow-dark,
 * grau-sparkle e pulse-live.
 */

/* ── Contêiner ────────────────────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: var(--z-header);
}

body.dark .header {
  background: rgba(13, 17, 23, 0.85);
}

/* ── Esquerda: gov.br + logo SUS 360 ──────────────────────────────────── */
.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.gov-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  padding-right: 16px;
  border-right: 1px solid var(--border-color);
}
.gov-logo img {
  height: 24px;
  width: auto;
}
body.dark .gov-logo img {
  filter: brightness(0) invert(1);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.logo:hover {
  text-decoration: none;
}

.logo-icon {
  width: auto;
  height: 40px;
  animation: pulse-glow 3s ease-in-out infinite;
}
body.dark .logo-icon {
  filter: brightness(0) invert(1);
  animation: pulse-glow-dark 3s ease-in-out infinite;
}

.logo-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.logo-text {
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.logo-sus {
  font-size: 18px;
  font-weight: 900;
  color: var(--sus-blue);
  letter-spacing: -0.5px;
}
.logo-360 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}
.logo-grau {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  animation: grau-sparkle 10s ease-in-out infinite;
}
.logo-subtitle {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ── Centro: customizável por painel ──────────────────────────────────── */
.header-center {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  justify-content: flex-start;
  margin-left: 16px;
}

.header-sep {
  width: 1px;
  height: 28px;
  background: var(--border-color);
}

.header-title-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 180px;
}

.header-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.header-version {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
}

.header-subtitle {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Visão atual (selo com bandeira) ──────────────────────────────────── */
.header-view {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-body);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  height: 36px;
  flex-shrink: 0;
}

.header-view-flag {
  width: 24px;
  height: 18px;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.header-view-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-view-close {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
  display: flex;
  align-items: center;
}
.header-view-close:hover {
  color: var(--color-danger);
}

.header-view.has-filter {
  background: rgba(0, 102, 204, 0.08);
  border-color: var(--sus-blue);
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}
body.dark .header-view.has-filter {
  background: rgba(59, 158, 255, 0.12);
  box-shadow: 0 0 0 2px rgba(59, 158, 255, 0.15);
}

/* ── Breadcrumbs ──────────────────────────────────────────────────────── */
.breadcrumb-link {
  cursor: pointer;
  color: var(--sus-blue);
  opacity: 0.8;
  transition: opacity var(--transition-fast);
}
.breadcrumb-link:hover {
  opacity: 1;
  text-decoration: underline;
}
.breadcrumb-active {
  font-weight: 700;
  color: var(--text-primary);
}
.breadcrumb-sep {
  margin: 0 4px;
  color: var(--text-secondary);
  opacity: 0.5;
  font-size: 14px;
}

/* ── Direita: ações ───────────────────────────────────────────────────── */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: rgba(40, 167, 69, 0.1);
  color: #28a745;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 11px;
}
.header-status-dot {
  width: 6px;
  height: 6px;
  background: #28a745;
  border-radius: 50%;
  animation: pulse-live 2s ease-in-out infinite;
}

.header-divider {
  width: 1px;
  height: 24px;
  background: var(--border-color);
}

/* ── Botões de ação ───────────────────────────────────────────────────── */
.header-action-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  font-size: 16px;
}
.header-action-btn:hover {
  background: var(--bg-body);
  color: var(--sus-blue);
}
.header-action-btn.active {
  background: var(--sus-blue);
  color: white;
}

/* Alternância dos ícones de tema (sol/lua) */
.header-action-btn .sun-icon {
  display: none;
}
body.dark .header-action-btn .sun-icon {
  display: block;
}
body.dark .header-action-btn .moon-icon {
  display: none;
}

/* ── Busca inline no header ───────────────────────────────────────────── */
.header-search-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--sus-blue);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all var(--transition-fast);
}
.header-search-btn:hover {
  background: #003d7a;
  transform: scale(1.05);
}
body.dark .header-search-btn {
  background: #58a6ff;
  color: #0d1117;
}
body.dark .header-search-btn:hover {
  background: #79c0ff;
}

/* ── Fundo escurecido da busca ────────────────────────────────────────── */
.search-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-search-backdrop);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.search-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}
body.dark .search-backdrop {
  background: rgba(0, 0, 0, 0.7);
}

/* ── Lista suspensa de resultados da busca ────────────────────────────── */
.search-results-dropdown {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, calc(100vw - 32px));
  z-index: var(--z-search-dropdown);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
}

/* ── Hamburger mobile ─────────────────────────────────────────────────── */
.header-hamburger {
  display: none;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

/* ── Mobile: < 768px ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .header {
    padding: 0 12px;
  }
  .header-center {
    display: none;
  }
  .header-status {
    display: none;
  }
  .header-hamburger {
    display: flex;
  }
  .header-divider {
    display: none;
  }
  .gov-logo {
    padding-right: 10px;
  }
  .gov-logo img {
    height: 20px;
  }
  .logo-icon {
    height: 32px;
  }
  .logo-sus {
    font-size: 16px;
  }
  .logo-360 {
    font-size: 14px;
  }
  .logo-grau {
    font-size: 14px;
  }
  .logo-subtitle {
    font-size: 10px;
  }
}

/* ── Skip-link posicionado em relação ao header ───────────────────────── */
.header ~ .skip-link:focus,
.skip-link:focus + .header {
  z-index: var(--z-header);
}

/* Foco visível nos botões do header */
.header-action-btn:focus-visible,
.header-hamburger:focus-visible,
.header-search-btn:focus-visible {
  outline: 2px solid var(--sus-blue);
  outline-offset: 2px;
}
