/*
 * Top bar globale advisor — partagée memento + simulators.
 *
 * Markup canonique attendu :
 *   <header class="topbar" role="banner">
 *     <div class="topbar-inner">
 *       <a class="topbar-brand" href="/">
 *         <img class="topbar-logo-img" src="…/capital-explorer.png" />
 *         <span class="topbar-title">Memento</span>
 *       </a>
 *       <button class="topbar-toggle" type="button" aria-controls="topbar-nav"
 *               aria-expanded="false" aria-label="Ouvrir le menu">
 *         <span></span><span></span><span></span>
 *       </button>
 *       <nav id="topbar-nav" class="topbar-nav" aria-label="Navigation principale">
 *         <a href="…" class="topbar-link">Fiscal</a>
 *         …
 *         <a href="…" class="topbar-link topbar-link--external">Simulateurs</a>
 *       </nav>
 *     </div>
 *   </header>
 *
 * Dépend de tokens.css (--ce-navy, --ce-orange, --topbar-height, …) que
 * le consommateur doit charger AVANT topbar.css.
 *
 * Style aligné sur l'existant memento.capitalexplorer.fr (refacto v1 :
 * pixel-near, simple extraction depuis memento/src/styles/style.scss).
 * Les écarts visuels memento ↔ simulators seront résolus en alignant
 * progressivement simulators sur ce fichier (tâche P6 Olmo / Tristan).
 */

.topbar {
  /* Sticky plutôt que fixed : reste en flow donc pas besoin de
     padding-top sur body (qui crée des écarts avec la layout flex
     des pages simulateur). Pour les pages scrollables, sticky se
     comporte exactement comme fixed une fois en haut. */
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--ce-navy);
  color: #fff;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
  /* Reset des règles éventuelles d'un styles.css legacy qui mettrait
     display:flex / padding / gap directement sur .topbar (ex.
     simulators/docs/styles.css). On porte la mise en page UNIQUEMENT
     sur .topbar-inner pour garantir un rendu identique partout. */
  display: block;
  padding: 0;
  gap: 0;
  flex-shrink: 0;
}

.topbar-inner {
  max-width: 1200px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}

/* Fil d'ariane après le brand. Séparateur "›", entrées cliquables ou actives. */
.topbar-crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.65);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-crumb-sep {
  color: rgba(255, 255, 255, 0.35);
  font-size: 14px;
  flex-shrink: 0;
}
.topbar-crumb {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: var(--radius);
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-crumb:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}
.topbar-crumb--active {
  color: #fff;
  font-weight: 600;
  pointer-events: none;
}

/* ── Dropdown nav globale (variant sombre du subtopbar-dropdown) ──
   Markup attendu (à remplacer la nav linéaire) :
     <div class="topbar-dropdown">
       <button class="topbar-dropdown-trigger" aria-expanded="false">Menu</button>
       <div class="topbar-dropdown-menu" role="menu">
         <a href="/memento/">Memento</a>
         …
       </div>
     </div>
   Le toggle est géré par /shared-design/subtopbar.js (sélecteurs élargis). */
.topbar-dropdown {
  position: relative;
}
.topbar-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  color: rgba(255, 255, 255, 0.85);
  font: var(--font-weight-medium) var(--font-size-base) var(--font-sans);
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}
.topbar-dropdown-trigger::after {
  content: '▾';
  font-size: 10px;
  color: rgba(255, 255, 255, 0.55);
}
.topbar-dropdown-trigger:hover,
.topbar-dropdown[aria-expanded='true'] .topbar-dropdown-trigger,
.topbar-dropdown.is-open .topbar-dropdown-trigger {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.28);
  color: #fff;
}
.topbar-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid #e8eaed;
  border-radius: var(--radius-lg);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  padding: 4px;
  display: none;
  z-index: 110;
}
.topbar-dropdown[aria-expanded='true'] .topbar-dropdown-menu,
.topbar-dropdown.is-open .topbar-dropdown-menu {
  display: block;
}
.topbar-dropdown-menu a,
.topbar-dropdown-menu button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  text-align: left;
  background: none;
  border: 0;
  color: var(--ce-navy);
  font: var(--font-weight-medium) var(--font-size-base) var(--font-sans);
  text-decoration: none;
  border-radius: var(--radius);
  cursor: pointer;
}
.topbar-dropdown-menu a:hover,
.topbar-dropdown-menu button:hover {
  background: rgba(0, 0, 0, 0.04);
}
.topbar-dropdown-menu a[aria-current='page'] {
  background: var(--ce-orange-lt, rgba(245, 84, 32, 0.1));
  color: var(--ce-orange);
}
.topbar-dropdown-menu hr {
  margin: 4px 0;
  border: 0;
  border-top: 1px solid #e8eaed;
}

.topbar-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--ce-orange);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
}

.topbar-logo-img {
  display: block;
  height: 28px;
  width: auto;
}

.topbar-title {
  font-size: 16px;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius);
  transition:
    background 0.15s,
    color 0.15s;
}

.topbar-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.topbar-link[aria-current='page'] {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.topbar-link--external {
  background: var(--ce-orange);
  color: #fff;
  margin-left: 8px;
}

.topbar-link--external:hover {
  background: var(--ce-orange-h);
  color: #fff;
}

.topbar-link--logout {
  margin-left: 4px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.topbar-link--logout:hover {
  color: #fff;
  background: transparent;
  text-decoration: underline;
}

.topbar-toggle {
  display: none;
  background: transparent;
  border: 0;
  padding: 8px;
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
}

.topbar-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition:
    transform 0.2s,
    opacity 0.2s;
}

.topbar-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.topbar-toggle.is-open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.topbar-toggle.is-open span:nth-child(2) {
  opacity: 0;
}
.topbar-toggle.is-open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

@media (max-width: 768px) {
  .topbar-inner {
    padding: 0 16px;
    gap: 8px;
  }
  .topbar-title {
    display: none;
  }
  .topbar-toggle {
    display: inline-flex;
  }
  .topbar-nav {
    display: none;
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--ce-navy-dark);
    padding: 8px 12px 16px;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }
  .topbar-nav.is-open {
    display: flex;
  }
  .topbar-link {
    padding: 12px 14px;
    font-size: 15px;
    border-radius: var(--radius);
  }
}
