/* ==========================================================================
   Site header ("topbar") — WordPress pages re-skinned to match the
   Autobahn redesign's shared TopBar component (libs/packages/
   fe-ui-core-autobahn/chrome/TopBar.tsx + theme/md3.css `.topbar*` rules),
   ported to plain PHP/CSS/vanilla JS since WP pages don't load React.

   Colors/spacing/radii below are copied from the `.md3` token block
   (theme/md3.css) so this matches the React header pixel-for-pixel without
   pulling the whole design-system stylesheet (and its React dependency)
   onto every WordPress page. Scoped under #site-topbar (not `.md3`) so it
   never collides with the real `.md3` subtree other WP widgets (CarsSlider,
   search box) mount elsewhere on the same page.

   Auth state: kept the EXISTING contract from front/js/custom.js — it
   toggles `.user-login` / `.user-logined` (reading localStorage's
   auto_jwt_username/displayName/isAdmin or cfEmail) and fills in
   `.user-logined .user-name`. This stylesheet just gives those the new
   look; front/js/topbar.js only owns hamburger/account-menu open+close.
   ========================================================================== */

/* The old header was `position: fixed`, so front/sass/default/_general.scss
   gives `body` an unconditional 80px top padding to keep page content from
   sliding under it. This header is `position: sticky` (stays in the normal
   flow), so that compensation is now 80px of dead space above it on every
   page. Same specificity as the legacy `body{}` rule, but this file loads
   after style.css, so plain source order is enough to win — no !important. */
body {
  padding-top: 0;
}

#site-topbar {
  --tb-primary: #005cff;
  --tb-primary-container: #dbe4ff;
  --tb-on-primary-container: #001a45;
  --tb-on-surface: #1a1b22;
  --tb-on-surface-variant: #44464f;
  --tb-outline-variant: #c5c6d2;
  --tb-surface: #fbfbfe;
  --tb-error: #ba1a1a;
  --tb-r-full: 999px;
  --tb-elev: 0 2px 6px rgba(16, 22, 42, 0.1), 0 1px 2px rgba(16, 22, 42, 0.1);
  --tb-font: "Hanken Grotesk", system-ui, sans-serif;

  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 102;
  background: var(--tb-surface);
  border-bottom: 1px solid var(--tb-outline-variant);
  font-family: var(--tb-font);
}

#site-topbar * {
  box-sizing: border-box;
}

/* Defensive reset: the legacy theme's bare `button{...}` rule (front/css/style.css)
   sets text-transform:uppercase, font-family:Arial, line-height:18px, a gray fill
   etc. directly on the `button` element — since it targets the element itself
   (not just inherited from an ancestor), those declarations win over anything
   this stylesheet's parent selectors set unless overridden per-property here too.
   `all: unset` clears it in one shot; every component rule below re-declares what
   it needs (cursor, display, font) explicitly rather than relying on inheritance. */
#site-topbar button {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  font-family: var(--tb-font);
}

/* Same problem, `<a>` version: front/css/style.css has a bare `a{color:#333;
   font-family:Arial,Helvetica,sans-serif;font-size:14px}` reset. It only sets
   3 properties, but font-family is one of them, and — same as the button
   reset above — an explicit rule on the element itself beats this
   stylesheet's `font-family: var(--tb-font)` on an ANCESTOR (#site-topbar)
   regardless of specificity, because inheritance always loses to any
   explicit declaration. `inherit` here just means "actually use what the
   cascade would give a non-`a` element" — color/font-size are re-declared
   per component below where they matter, so only font-family needs the
   blanket fix. */
#site-topbar a {
  font-family: inherit;
}

#site-topbar .topbar-container {
  max-width: 1230px;
  margin: 0 auto;
  padding: 15px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
}

#site-topbar .icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--tb-r-full);
  border: 0;
  cursor: pointer;
  background: transparent;
  color: var(--tb-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font: inherit;
  text-decoration: none;
  transition: background 0.15s;
}

#site-topbar .icon-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

#site-topbar .icon-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* logo */
#site-topbar .topbar-logo-link {
  flex: none;
  display: inline-flex;
  align-items: center;
}

#site-topbar .topbar-logo {
  height: 32px;
  width: auto;
  display: block;
}

/* desktop inline nav — the WP-editable menu (get_cached_menu), restyled as
   a row of pill links instead of the legacy two-row bootstrap dropdown bar. */
#site-topbar .topbar-nav {
  margin-left: 8px;
}

#site-topbar .topbar-nav > ul,
#site-topbar .topbar-menu-nav > ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

#site-topbar .topbar-nav > ul {
  display: flex;
  align-items: center;
  gap: 2px;
}

#site-topbar .topbar-nav .dropdown-custom {
  position: relative;
}

#site-topbar .topbar-nav .dropdown-title,
#site-topbar .topbar-nav .list-header {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--tb-r-full);
  color: var(--tb-on-surface-variant);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.1px;
  text-decoration: none;
  white-space: nowrap;
}

#site-topbar .topbar-nav .dropdown-title:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--tb-on-surface);
}

#site-topbar .topbar-nav .dropdown-block {
  list-style: none;
  margin: 0;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 200px;
  background: var(--tb-surface);
  border-radius: 12px;
  box-shadow: var(--tb-elev);
  padding: 8px;
  display: none;
  z-index: 5;
}

#site-topbar .topbar-nav .dropdown-custom:hover > .dropdown-block,
#site-topbar .topbar-nav .dropdown-custom:focus-within > .dropdown-block {
  display: block;
}

#site-topbar .topbar-nav .dropdown-block .simple-link {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--tb-on-surface);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

#site-topbar .topbar-nav .dropdown-block .simple-link:hover {
  background: rgba(0, 0, 0, 0.06);
}

#site-topbar .topbar-spacer {
  flex: 1;
}

#site-topbar .topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* "Konto" tonal pill trigger */
#site-topbar .topbar-account-wrap {
  position: relative;
  display: inline-flex;
}

#site-topbar .topbar-account-btn {
  height: 34px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--tb-r-full);
  background: var(--tb-primary-container);
  color: var(--tb-on-primary-container);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: box-shadow 0.15s;
}

#site-topbar .topbar-account-btn:hover {
  box-shadow: 0 1px 3px rgba(16, 22, 42, 0.15);
}

#site-topbar .topbar-account-btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

/* account dropdown card (desktop popover / mobile full-width sheet, see the
   ≤600px override at the bottom) */
#site-topbar .amenu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  background: var(--tb-surface);
  border-radius: 16px;
  box-shadow: var(--tb-elev);
  padding: 8px;
  z-index: 60;
}

#site-topbar .amenu.is-open {
  display: block;
}

#site-topbar .amenu-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: transparent;
}

#site-topbar .amenu-backdrop.is-open {
  display: block;
}

/* guest vs signed-in blocks — DEFAULT state (before front/js/custom.js runs)
   matches the legacy contract: guest visible, signed-in hidden. custom.js
   (unchanged) always sets an INLINE `display` on both — 'flex'/'none' for
   `.user-login`, 'none'/'flex' for `.user-logined` — which beats whatever
   `display` this stylesheet declares regardless of specificity, so only
   `flex-direction` here actually takes effect once JS runs; `display` below
   only matters for the instant before custom.js's DOMContentLoaded handler
   fires. Both need `column` (the old `.user-login` was a horizontal row by
   design — one link + one icon — but this one holds several full-width
   amenu-rows that must stack). */
#site-topbar .user-login {
  display: block;
  flex-direction: column;
}

#site-topbar .user-logined {
  display: none;
  flex-direction: column;
}

#site-topbar .amenu-user {
  padding: 6px 14px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--tb-on-surface-variant);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#site-topbar .amenu-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  color: var(--tb-on-surface);
  border-radius: 0;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
}

#site-topbar .amenu-row:hover {
  background: rgba(0, 0, 0, 0.05);
}

#site-topbar .amenu-row svg {
  width: 17px;
  height: 17px;
  flex: none;
  color: var(--tb-on-surface-variant);
}

#site-topbar .amenu-row--primary {
  background: var(--tb-primary);
  color: #fff;
  border-radius: var(--tb-r-full);
  font-weight: 700;
  justify-content: center;
  margin-bottom: 6px;
}

#site-topbar .amenu-row--primary:hover {
  background: #0a47ae;
}

#site-topbar .amenu-divider {
  height: 1px;
  background: var(--tb-outline-variant);
  margin: 6px 0;
}

/* dealer-only row — shown by custom.js when auto_jwt_isAdmin is set */
#site-topbar .image-settings-link {
  display: none;
}

/* mobile hamburger nav dropdown */
#site-topbar .topbar-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--tb-surface);
  border-bottom: 1px solid var(--tb-outline-variant);
  box-shadow: var(--tb-elev);
  padding: 8px 16px 16px;
  z-index: 55;
}

#site-topbar .topbar-menu.is-open {
  display: block;
}

#site-topbar .topbar-menu-nav .dropdown-custom {
  border-bottom: 1px solid var(--tb-outline-variant);
}

#site-topbar .topbar-menu-nav .dropdown-title,
#site-topbar .topbar-menu-nav .list-header {
  display: block;
  padding: 14px 8px;
  color: var(--tb-on-surface);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.1px;
  text-decoration: none;
}

#site-topbar .topbar-menu-nav .dropdown-block {
  list-style: none;
  margin: 0 0 8px;
  padding: 0 0 0 12px;
}

#site-topbar .topbar-menu-nav .dropdown-block .simple-link {
  display: block;
  padding: 8px 4px;
  color: var(--tb-on-surface-variant);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

#site-topbar .topbar-menu-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

#site-topbar .topbar-menu-actions a {
  flex: 1;
  height: 40px;
  padding: 0 24px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border: 0;
  box-shadow: inset 0 0 0 1px var(--tb-outline-variant);
  color: var(--tb-primary);
}

#site-topbar .topbar-menu-actions a svg {
  width: 17px;
  height: 17px;
}

/* the guest/signed-in CTA reuses .user-login/.user-logined for custom.js's
   auth toggle (see the comment above those rules) — override flex-direction
   back to row here: this is a single button (icon + label side by side),
   not the amenu's list of stacked rows those classes normally imply. */
#site-topbar .topbar-menu-actions .user-login,
#site-topbar .topbar-menu-actions .user-logined {
  flex-direction: row;
}

/* custom.js's guest branch only ever sets `.user-login` to inline
   `display:flex` — it never touches `.user-logined` there, relying on
   `.user-logined`'s OWN default `display:none` to keep it hidden. That
   default loses here to `.topbar-menu-actions a`'s `display:inline-flex`
   (more specific: id+class+type beats id+class), so "Mein Konto" showed
   for guests too. Re-asserting `none` with one more class wins it back;
   the authed branches still override this via inline style same as ever. */
#site-topbar .topbar-menu-actions .user-logined {
  display: none;
}

#site-topbar .topbar-menu-actions a.topbar-menu-cta--filled {
  background: var(--tb-primary);
  color: #fff;
  box-shadow: none;
}

/* utility classes — same 600px breakpoint the React TopBar uses */
#site-topbar .show-mobile {
  display: none;
}

@media (max-width: 600px) {
  #site-topbar .hide-mobile {
    display: none !important;
  }
  #site-topbar .show-mobile {
    display: inline-flex;
  }
  #site-topbar .topbar-container {
    padding: 0 12px;
  }
  #site-topbar .topbar-logo {
    width: 122px;
    height: auto;
    margin-left: -19px;
  }
  #site-topbar .icon-btn svg {
    width: 24px;
    height: 24px;
  }
  #site-topbar .topbar-actions {
    gap: 4px;
  }
  #site-topbar .topbar-account-btn {
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
    background: transparent;
    color: var(--tb-on-surface-variant);
  }
  #site-topbar .topbar-account-btn svg {
    width: 24px;
    height: 24px;
  }
  #site-topbar .topbar-account-btn:hover {
    background: rgba(0, 0, 0, 0.06);
  }
  /* the small desktop popover becomes a full-width sheet under the header */
  #site-topbar .amenu {
    position: fixed;
    top: 64px;
    left: 12px;
    right: 12px;
    width: auto;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    border-radius: 16px;
  }
}
