/* ─────────────────────────────────────────────
   PeçaRadar — Topbar & Barra de Status da IA
   
   VARIÁVEIS NECESSÁRIAS NO :root (variables.css):
   --bg-dark, --text-light, --accent, --accent-h,
   --muted, --tag-bg, --r-md, --r-xl,
   --t: all 0.2s ease
───────────────────────────────────────────── */

#topbar {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  background:
    radial-gradient(circle at 10% 20%, rgba(0, 97, 255, 0.12) 0%, transparent 50%),
    radial-gradient(circle at 90% 20%, rgba(0, 97, 255, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 50% 100%, rgba(0, 97, 255, 0.15) 0%, transparent 60%),
    linear-gradient(135deg, #0f172a 0%, #020617 100%);
  color: var(--text-light);
  width: 100%;
  /* max-width removido: o dropdown precisa de posicionamento relativo ao topbar inteiro */
  z-index: 1000;
  position: relative;
  min-height: 80px;
  padding: 16px 24px;
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.6);
  overflow: visible !important;
}

/* Borda decorativa inferior com glow — substitui border-bottom */
#topbar::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.8;
}

/* ── Brand / Logo ── */

.topbar-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
  min-width: 200px;
  flex-shrink: 0;
  overflow: visible !important;
}

.topbar-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding-top: 0;
  min-width: 0;
}

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

.logo-link {
  text-decoration: none;
  display: block;
  transition: opacity var(--t, 0.2s ease);
}

.logo-link:hover { opacity: 0.9; }

.logo { min-width: 180px; }

.logo h1 {
  font-size: 1.6rem;
  margin: 0;
  padding: 0;
  line-height: 1;
  letter-spacing: -0.5px;
  color: #fff;
}

.logo h1 span {
  color: #0061FF;
  font-weight: 700;
  text-shadow: 0 0 8px rgba(0, 97, 255, 0.3);
}

.logo p {
  font-size: 0.7rem;
  margin: 4px 0 0 0;
  padding: 0;
  opacity: 0.8;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

/* ── Busca ── */

.search-area {
  display: flex;
  flex: 1;
  max-width: 700px;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

#search-wrap,
#cep-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--r-md, 8px);
  padding: 0 16px;
  transition: all var(--t, 0.2s ease);
}

#search-wrap { flex: 1; min-width: 0; }
#cep-wrap    { min-width: 160px; }

#search-wrap:focus-within,
#cep-wrap:focus-within {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.2);
}

.search-icon,
.loc-icon {
  color: #fff;
  font-size: 14px;
  margin-right: 8px;
  flex-shrink: 0;
}

#searchInput,
#cep-input {
  width: 100%;
  background: transparent;
  border: none;
  padding: 12px 0;
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

#searchInput::placeholder,
#cep-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

/* ── Notificações ── */

#notifWrapper {
  position: relative;
  flex-shrink: 0;
}

#btnNotifications {
  background: transparent;
  border: none;
  padding: 8px;
  cursor: pointer;
  font-size: 18px;
  color: #fff;
}

#notifBadge {
  position: absolute;
  top: 0;
  right: 0;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  border-radius: 10px;
  padding: 2px 6px;
  /* Controlado via JS: notifBadge.style.display = 'block' */
  display: none;
}

#notifDropdown {
  /* Estado padrão: oculto. Ativado via .open pelo JS */
  display: none;
  position: absolute;
  top: 50px;
  right: 0;
  width: 340px;
  background: #110f15;
  border: 1px solid #36323E;
  border-radius: 12px;
  z-index: 100;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
  max-height: 450px;
  overflow-y: auto;
  flex-direction: column;
}

#notifDropdown.open {
  display: flex;
}

.dropdown-title {
  padding: 16px;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid #36323E;
  color: #fff;
}

/* ── Botões ── */

.top-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 11px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t, 0.2s ease);
  white-space: nowrap;
  min-width: 80px; /* evita botões minúsculos em telas estreitas */
}

.top-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}

.top-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
}

.top-btn.primary:hover {
  background: var(--accent-h);
  border-color: var(--accent-h);
}

/* ── Menu de categorias ── */

.hamburger-btn {
  background: rgba(0, 97, 255, 0.1);
  border: 1px solid rgba(0, 97, 255, 0.3);
  color: var(--accent);
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 800;
  cursor: pointer;
  transition: all var(--t, 0.2s ease);
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.hamburger-btn .icon { font-size: 16px; }

.hamburger-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-1px);
  /* Sombra usa cor do accent (azul) — consistente com o tema do projeto */
  box-shadow: 0 6px 20px rgba(0, 97, 255, 0.4);
}

.cat-menu-wrapper { position: relative; overflow: visible !important; }

.cat-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  width: 320px;        /* largura única — sem duplicata */
  max-height: 90vh;    /* limita em telas pequenas sem necessidade de valor absurdo */
  background: rgba(17, 15, 21, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--r-xl, 16px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
  z-index: 9999 !important;
  opacity: 0;
  visibility: hidden;
  transform: none; /* deslocamento vertical removido — evita salto visual */
  transition: opacity 0.3s ease, visibility 0.3s ease;
  overflow-y: auto;
  padding: 8px 0;
}

/* backdrop-filter em pseudo-elemento para evitar artefatos com overflow-y no Safari */
.cat-dropdown::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  z-index: -1;
  pointer-events: none;
}

.cat-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.cat-dropdown::-webkit-scrollbar       { width: 4px; }
.cat-dropdown::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 10px; }

/* ── Seções do dropdown ── */

.dropdown-section {
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 12px 16px;
}

.dropdown-section:last-child { border-bottom: none; }

.dropdown-header {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
  opacity: 0.5;
}

.dropdown-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.grid-sources {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stats-section .stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.8rem;
}

.stats-section .stat-label { color: var(--muted); }
.stats-section .stat-val   { color: #fff; font-weight: 600; }

/* ── Subcategorias aninhadas ── */

.nested-box {
  margin: 0 8px 0 24px;
  padding: 0 10px;
  background: rgba(0, 97, 255, 0.05);
  border-left: 2px solid rgba(0, 97, 255, 0.2);
  border-radius: 0;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nested-box.show {
  max-height: 3000px; /* Aumentado para suportar muitos anos */
  opacity: 1;
  padding: 10px;
  margin: 4px 8px 12px 24px;
}

/* Reduz o recuo da 4ª camada (Anos) para evitar que o texto seja "empurrado" */
.nested-box .nested-box {
  margin-left: 12px;
  padding-left: 5px;
  border-left: 1px dotted rgba(255, 255, 255, 0.1);
}

.cat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-radius: var(--r-md, 8px);
  color: var(--text-light);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t, 0.2s ease);
  text-align: left;
}

.cat-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

.cat-btn.active {
  background: var(--tag-bg);
  color: var(--accent);
  font-weight: 700;
}

.cat-btn .icon {
  font-size: 15px;
  filter: grayscale(1);
  transition: filter var(--t, 0.2s ease);
}

.cat-btn:hover .icon,
.cat-btn.active .icon {
  filter: grayscale(0);
}

.cat-btn.has-sub {
  justify-content: flex-start;
}

.cat-btn.has-sub .chevron {
  margin-left: auto;
  font-size: 0.7rem;
  opacity: 0.5;
  transition: transform 0.3s ease;
}

.cat-btn.has-sub.open .chevron {
  transform: rotate(180deg);
  opacity: 1;
}

/* Sub-botões (Marcas/Modelos) */
.cat-btn.sub-btn {
  padding: 8px 16px;
  font-size: 0.85rem;
  opacity: 0.8;
}

.cat-btn.sub-btn:hover {
  background: rgba(0, 97, 255, 0.08);
  opacity: 1;
}

.divider-mini {
  height: 1px;
  background: rgba(255, 255, 255, 0.06);
  margin: 12px 16px;
}

/* ── AI Status Bar ── */

.ai-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
  flex-shrink: 0;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

#ai-status        { font-size: 12.5px; color: var(--muted); flex: 1; }
#ai-status strong { color: var(--accent); font-weight: 500; }

#ai-ask {
  background: transparent;
  border: 1px solid rgba(255, 107, 43, 0.3);
  border-radius: var(--r-md, 8px);
  padding: 6px 14px;
  color: var(--accent);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--t, 0.2s ease);
}

/* ── Exibição de categoria no conteúdo ── */

.content-cat-display {
  margin-bottom: 25px;
  border-left: 5px solid var(--accent);
  border-radius: 0;
  padding-left: 20px;
  animation: fadeIn 0.8s ease;
}

.content-cat-display .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.content-cat-display h2 {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text);
  font-family: 'Syne', sans-serif;
  margin: 0;
  letter-spacing: -1px;
}

/* ══════════════════════════════════════════
   RESPONSIVIDADE
══════════════════════════════════════════ */

/* ── Tablet largo ── */
@media (max-width: 1200px) {
  #topbar    { gap: 20px; padding: 10px 16px; }
  .topbar-row { gap: 12px; }
}

/* ── Tablet ── */
@media (max-width: 950px) {
  #topbar {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    gap: 14px;
    min-height: auto;
    padding: 14px 20px 18px 20px;
  }

  .topbar-brand, .topbar-content, .topbar-row {
    display: contents;
  }

  .logo-link {
    grid-column: 1; grid-row: 1;
    align-self: center;
  }

  .topbar-actions {
    grid-column: 4; grid-row: 1;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    width: auto;
  }

  .search-area {
    grid-column: 1 / -1; grid-row: 2;
    display: flex;
    flex-direction: row;
    gap: 8px;
    width: 100%;
    max-width: none;
  }

  .cat-menu-wrapper {
    grid-column: 1 / -1; grid-row: 3;
    width: 100%;
  }

  .cat-menu-wrapper .hamburger-btn {
    width: 100%;
    justify-content: center;
  }

  .topbar-actions .top-btn {
    flex: none;
    width: max-content;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 12px;
  }

  /* CEP + busca lado a lado em tablet */
  #cep-wrap    { flex: 0 0 210px; min-width: unset; }
  #search-wrap { flex: 1; min-width: 0; }

  /* 
    Notificações flutuando elegantemente ao lado do logo no layout da grade
  */
  #notifWrapper {
    grid-column: 2; grid-row: 1;
    position: static;
    align-self: center;
    margin-left: 5px;
  }
  
  #btnNotifications {
    padding: 6px;
    font-size: 20px;
  }

  .topbar-spacer { display: none; }
}

/* ── Mobile & Landscape Phones ── */
@media (max-width: 767px) {
  #topbar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 16px 20px 16px;
    min-height: auto;
  }

  /* Mantém propriedades flex-box do celular via display: contents, liberando o order livre */
  .topbar-brand, .topbar-content, .topbar-row {
    display: contents;
  }

  .logo-link {
    order: 1;
    align-self: center;
    margin-bottom: 8px; /* Adiciona gap que se perde no display contents */
  }

  .topbar-actions {
    order: 2;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }

  .search-area {
    order: 3;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }

  /* CEP e busca empilhados em mobile */
  #cep-wrap    { width: 100%; flex: none; min-width: unset; }
  #search-wrap { width: 100%; flex: none; }

  .topbar-actions .top-btn {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .cat-menu-wrapper {
    order: 4;
    width: 100%;
    margin-top: 8px;
  }

  .hamburger-btn {
    width: 100%;
    justify-content: center;
  }

  /* Sininho: absoluto apenas em mobile para não empurrar o layout */
  #notifWrapper {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 1001;
  }

  #btnNotifications {
    padding: 4px;
    font-size: 20px;
  }

  #notifDropdown {
    width: calc(100vw - 40px);
    left: auto;
    right: 0;
    top: 44px;
  }

  .cat-dropdown {
    width: calc(100vw - 32px);
    max-height: 92vh;
  }
}

/* ── Mobile pequeno ── */
@media (max-width: 400px) {
  .logo h1 { font-size: 1.3rem; }
  .top-btn  { padding: 10px 12px; font-size: 13px; }
}

/* ── Landscape em celular ── */
@media (max-height: 520px) and (max-width: 950px) {
  #topbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    padding: 6px 15px 10px 15px;
    min-height: auto;
  }

  /* Logo compacto */
  .topbar-brand {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    order: 1;
  }

  .logo h1 { font-size: 1.1rem; }
  .logo p  { display: none; }

  /* Busca ocupa o centro */
  .topbar-content {
    flex: 1;
    order: 2;
    min-width: 0;
  }

  .topbar-row {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  .search-area {
    flex-direction: row;
    gap: 6px;
    flex: 1;
    min-width: 0;
  }

  #cep-wrap    { flex: 0 0 160px; height: 32px; }
  #search-wrap { flex: 1; height: 32px; min-width: 0; }
  #searchInput, #cep-input { padding: 0; font-size: 12px; height: 100%; }

  /* Hamburger compacto */
  .cat-menu-wrapper { order: 3; }
  .hamburger-btn {
    width: auto;
    padding: 0 12px;
    font-size: 10px;
    height: 32px;
  }

  /* Sininho estático no landscape */
  #notifWrapper {
    position: static;
    order: 4;
    flex-shrink: 0;
  }
  #btnNotifications { padding: 4px; font-size: 18px; height: 32px; }

  /* Ações em nova linha */
  .topbar-actions {
    order: 5;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    margin-top: 2px;
  }

  .topbar-actions .top-btn {
    flex: none;
    width: max-content;
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 11px;
    height: 32px;
    justify-content: center;
  }

  .topbar-spacer { display: none; }

  /* Dropdown em landscape: layout horizontal com colunas */
  .cat-dropdown {
    top: 50px;
    left: 20px;
    right: 20px;
    width: calc(100vw - 40px);
    max-height: calc(100vh - 60px);
    display: none; /* continua controlado pelo .show */
    flex-direction: row;
    flex-wrap: wrap;
    gap: 20px;
    padding: 20px;
    background: rgba(15, 12, 41, 0.98);
    border-radius: 12px;
    overflow-y: auto;
  }

  .cat-dropdown.show {
    display: flex;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .dropdown-section {
    flex: 1;
    min-width: 180px;
    margin-bottom: 0;
  }

  .dropdown-header { font-size: 11px; margin-bottom: 10px; }
  .cat-btn         { padding: 8px 12px; font-size: 12px; }
  .stat-row        { font-size: 11px; padding: 4px 0; }

  #notifDropdown {
    top: 50px;
    right: 20px;
    width: 320px;
    max-height: 70vh;
  }
}