/* Header, nav, langue, thème */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: minmax(0, auto) 1fr auto;
  align-items: center;
  gap: 0.75rem;
  /* Slightly inset from viewport edge; a bit more left padding so logo/title aren’t flush */
  padding-left: max(0.65rem, calc((100vw - var(--content-max)) / 2 + 0.65rem));
  padding-right: max(0.5rem, calc((100vw - var(--content-max)) / 2 + 0.5rem));
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
  background: var(--bg);
  border-bottom: 1px solid var(--header-border);
}

body {
  padding-top: 3rem;
}

.site-header .header-left {
  grid-column: 1;
  justify-self: start;
  min-width: 0;
  max-width: 100%;
}

.site-header .header-nav {
  grid-column: 2;
  justify-self: center;
}

.site-header .menu-toggle {
  grid-column: 2;
  justify-self: end;
}

.site-header .header-right-actions {
  grid-column: 3;
  justify-self: end;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

a.header-left:hover .header-title,
a.header-left:hover .header-tagline {
  opacity: 0.85;
}

.logo-icon {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.header-titles {
  margin: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  flex: 1 1 auto;
}

/* Each line stays single-line on all viewports (narrow phones, large desktops) */
.header-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.header-tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 1.75rem;
}

.header-nav a {
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.35rem 0;
}

.header-nav a:hover {
  color: var(--accent);
}

.header-nav .nav-link-open-to {
  word-spacing: -0.12em;
}

.nav-misc-wrap {
  position: relative;
  display: inline-block;
}

.nav-misc-trigger {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  padding: 0.35rem 0;
  font-family: inherit;
}

.nav-misc-trigger:hover {
  color: var(--accent);
}

.nav-misc-arrow {
  font-size: 0.65rem;
  opacity: 0.8;
  transition: transform 0.2s;
}

.nav-misc-wrap.open .nav-misc-arrow {
  transform: rotate(180deg);
}

.nav-misc-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  min-width: 10rem;
  display: none;
  z-index: 200;
  padding: 0.25rem 0;
}

[data-theme="dark"] .nav-misc-dropdown {
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.nav-misc-wrap.open .nav-misc-dropdown {
  display: block;
}

.nav-misc-dropdown a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}

.nav-misc-dropdown a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.header-right-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Language dropdown: only shown on home; reserve space when hidden so nav links don't shift */
.lang-switcher-wrap {
  visibility: hidden;
  width: 3.5rem;
  min-width: 3.5rem;
  pointer-events: none;
}

body.is-home .lang-switcher-wrap {
  visibility: visible;
  pointer-events: auto;
}

.lang-switcher-wrap--menu {
  width: 100%;
  min-width: 0;
}

body:not(.is-home) .lang-switcher-wrap--menu {
  display: none;
}

.mobile-nav-utilities {
  border-top: 1px solid var(--border);
  margin-top: 0.35rem;
  padding: 0.5rem 0.75rem 0.35rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}

.mobile-nav-utilities .lang-switcher {
  width: 100%;
}

.mobile-nav-utilities .lang-switcher-trigger {
  width: 100%;
  justify-content: space-between;
}

.mobile-nav-utilities .theme-toggle {
  align-self: flex-start;
  padding: 0.45rem 0.5rem;
}

.lang-switcher {
  position: relative;
  display: inline-block;
}

.lang-switcher-trigger {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text);
  min-width: 2.5rem;
}

.lang-switcher-trigger:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.lang-switcher-arrow {
  font-size: 0.7rem;
  opacity: 0.8;
  transition: transform 0.2s;
}

.lang-switcher.open .lang-switcher-arrow {
  transform: rotate(180deg);
}

.lang-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  min-width: 8rem;
  display: none;
  z-index: 200;
}

[data-theme="dark"] .lang-dropdown {
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.lang-switcher.open .lang-dropdown {
  display: block;
}

.lang-dropdown button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text);
  text-align: left;
}

.lang-dropdown button:hover,
.lang-dropdown button.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.35rem;
  color: var(--accent);
  font-size: 1.2rem;
  line-height: 1;
}

.theme-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}
.theme-icon svg {
  display: block;
}
.theme-icon-sun { display: none; }
.theme-icon-moon { display: inline-flex; }
[data-theme="dark"] .theme-icon-sun { display: inline-flex; }
[data-theme="dark"] .theme-icon-moon { display: none; }

/* ----- Mobile: dropdown nav next to flags (replaces hamburger + full-width nav) ----- */
.mobile-nav-wrap {
  display: none;
}

.mobile-nav-trigger {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  font-family: inherit;
}

.mobile-nav-trigger:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.mobile-nav-wrap.open .mobile-nav-trigger {
  border-color: var(--accent);
  color: var(--accent);
}

.mobile-nav-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  min-width: 11rem;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  display: none;
  z-index: 200;
  padding: 0.25rem 0;
}

[data-theme="dark"] .mobile-nav-dropdown {
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.mobile-nav-wrap.open .mobile-nav-dropdown {
  display: block;
}

.mobile-nav-dropdown > a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}

.mobile-nav-dropdown > a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Nested Misc. cascade */
.mobile-nav-misc-wrap {
  position: relative;
}

.mobile-nav-misc-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  text-align: left;
  font-family: inherit;
}

.mobile-nav-misc-trigger:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.mobile-nav-misc-arrow {
  font-size: 0.65rem;
  opacity: 0.8;
  transition: transform 0.2s;
}

.mobile-nav-misc-wrap.open .mobile-nav-misc-arrow {
  transform: rotate(90deg);
}

.mobile-nav-misc-dropdown {
  display: none;
  padding-left: 0.5rem;
  border-left: 2px solid var(--border);
  margin-left: 0.75rem;
  margin-bottom: 0.25rem;
}

.mobile-nav-misc-wrap.open .mobile-nav-misc-dropdown {
  display: block;
}

.mobile-nav-misc-dropdown a {
  display: block;
  padding: 0.4rem 0.75rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}

.mobile-nav-misc-dropdown a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

@media (max-width: 768px) {
  body {
    padding-top: var(--site-header-offset-mobile, 4.5rem);
  }

  .site-header {
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
    padding-left: max(0.45rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.2rem, env(safe-area-inset-right, 0px));
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto;
    align-items: center;
    column-gap: 0.2rem;
    row-gap: 0;
  }

  .site-header .header-left {
    grid-column: 1;
    grid-row: 1;
    justify-self: stretch;
    min-width: 0;
    max-width: 100%;
    gap: 0.3rem;
  }

  .site-header .header-right-actions {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: center;
    width: auto;
    flex-shrink: 0;
    justify-content: flex-end;
  }

  .logo-icon {
    width: 28px;
    height: 28px;
  }

  .header-title {
    font-size: 0.95rem;
  }

  .header-tagline {
    font-size: 0.62rem;
    letter-spacing: -0.025em;
  }

  .menu-toggle {
    display: none;
  }

  .header-nav {
    display: none;
  }

  .mobile-nav-wrap {
    display: block;
    position: relative;
  }

  .mobile-nav-trigger {
    box-sizing: border-box;
    min-width: 2.5rem;
    min-height: 2.5rem;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    justify-content: center;
    border-radius: 8px;
    font-size: 1.05rem;
    line-height: 1;
  }

  .header-right-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .header-bar-only {
    display: none !important;
  }
}

/* Desktop / tablet: cap title block; reserve a bit less for nav/actions (tighter header padding) */
@media (min-width: 769px) {
  .site-header .header-left {
    max-width: min(36rem, calc(100vw - 18.5rem));
  }
}

.menu-toggle {
  display: none;
}
