/* global React, Icon */
const { useState: useTopBarState, useEffect: useTopBarEffect, useRef: useTopBarRef } = React;

const NAV_ITEMS = [
  { label: "Hjem", href: "#" },
  {
    label: "Ydelser", href: "#services",
    children: [
      { label: "Tagreparation", href: "#" },
      { label: "Tagrenovering", href: "#" },
      { label: "Nyt tag", href: "#" },
      { label: "Taginspektion", href: "#" },
      { label: "Forsikringssager", href: "#" },
      { label: "Stormskader", href: "#" },
    ],
  },
  { label: "Referencer", href: "#work" },
  {
    label: "Om os", href: "#about",
    children: [
      { label: "Karriere", href: "#" },
      { label: "Blog", href: "#" },
    ],
  },
  {
    label: "Serviceområder", href: "#areas",
    children: [
      { label: "Sønderborg", href: "#" },
      { label: "Aabenraa", href: "#" },
      { label: "Haderslev", href: "#" },
      { label: "Kolding", href: "#" },
      { label: "Vejle", href: "#" },
      { label: "Odense", href: "#" },
    ],
  },
  { label: "Kontakt", href: "#contact" },
];

function NavDropdown({ item, open, onToggle }) {
  const ref = useTopBarRef(null);

  useTopBarEffect(() => {
    if (!open) return;
    const handler = (e) => {
      if (ref.current && !ref.current.contains(e.target)) onToggle(null);
    };
    document.addEventListener("mousedown", handler);
    return () => document.removeEventListener("mousedown", handler);
  }, [open]);

  return (
    <div className="tbdrop" ref={ref}>
      <button
        className={"tbdrop__trigger" + (open ? " tbdrop__trigger--open" : "")}
        onClick={() => onToggle(open ? null : item.label)}
        aria-expanded={open}
        aria-haspopup="true"
      >
        {item.label}
        <svg className="tbdrop__caret" width="10" height="6" viewBox="0 0 10 6" fill="none">
          <path d="M1 1l4 4 4-4" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
        </svg>
      </button>
      {open && (
        <div className="tbdrop__panel" role="menu">
          {item.children.map((child) => (
            <a key={child.label} href={child.href} className="tbdrop__item" role="menuitem">
              {child.label}
            </a>
          ))}
        </div>
      )}
    </div>
  );
}

function StarRating({ count = 5, fill = "#F2B636" }) {
  return (
    <span className="tb-stars">
      {Array.from({ length: count }).map((_, i) => (
        <svg key={i} width="12" height="12" viewBox="0 0 24 24" fill={fill}>
          <path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"/>
        </svg>
      ))}
    </span>
  );
}

function TopBar({ onOpenQuote }) {
  const [scrolled, setScrolled] = useTopBarState(false);
  const [mobileOpen, setMobileOpen] = useTopBarState(false);
  const [openDrop, setOpenDrop] = useTopBarState(null);
  const [mobileExpanded, setMobileExpanded] = useTopBarState(null);

  useTopBarEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 60);
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  useTopBarEffect(() => {
    if (mobileOpen) document.body.style.overflow = "hidden";
    else document.body.style.overflow = "";
    return () => { document.body.style.overflow = ""; };
  }, [mobileOpen]);

  return (
    <header className={"topbar" + (scrolled ? " topbar--scrolled" : "")} data-screen-label="Top bar">

      {/* ── TOP INFO BAR — white left (logo only) / cyan-blue right (all info) ── */}
      <div className="topbar__top">

        {/* LEFT: white strip — decorative only, logo lives in the nav bar below */}
        <div className="topbar__top-left" aria-hidden="true"/>

        {/* RIGHT: cyan blue — review badges + divider + email + socials */}
        <div className="topbar__top-right">
          <div className="tb-badges-group">
            <a href="#" className="tb-badge" aria-label="Google anmeldelser">
              <span className="tb-badge__logo tb-badge__logo--google">
                <svg width="16" height="16" viewBox="0 0 24 24"><path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/><path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/><path fill="#FBBC05" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l3.66-2.84z"/><path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"/></svg>
              </span>
              <span className="tb-badge__body">
                <StarRating count={5} />
                <span className="tb-badge__label">237 anmeldelser</span>
              </span>
            </a>

            <a href="#" className="tb-badge" aria-label="Facebook anmeldelser">
              <span className="tb-badge__logo tb-badge__logo--fb">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="#fff"><path d="M24 12.073C24 5.405 18.627 0 12 0S0 5.405 0 12.073c0 6.028 4.388 11.024 10.125 11.927v-8.437H7.078v-3.49h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.49h-2.796v8.437C19.612 23.097 24 18.101 24 12.073z"/></svg>
              </span>
              <span className="tb-badge__body">
                <StarRating count={5} />
                <span className="tb-badge__label">18 anmeldelser</span>
              </span>
            </a>

            <a href="#" className="tb-badge" aria-label="Trustpilot anmeldelser">
              <span className="tb-badge__logo tb-badge__logo--tp">
                <svg width="16" height="16" viewBox="0 0 24 24"><rect width="24" height="24" rx="3" fill="#00B67A"/><path fill="#fff" d="M12 2l2.55 7.84H22l-6.27 4.56 2.39 7.37L12 17.23l-6.12 4.54 2.39-7.37L2 9.84h7.45z"/></svg>
              </span>
              <span className="tb-badge__body">
                <StarRating count={5} fill="#00B67A" />
                <span className="tb-badge__label">247 anmeldelser</span>
              </span>
            </a>
          </div>

          <span className="tb-divider" aria-hidden="true"/>

          <a href="mailto:info@frederiksen-jepsen.dk" className="tb-email">
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/></svg>
            info@frederiksen-jepsen.dk
          </a>
          <span className="tb-follow">
            <span className="tb-follow-label">Følg os:</span>
            <a href="https://www.facebook.com/pages/Frederiksen-Nielsen-AS/752817998144068" target="_blank" rel="noreferrer" className="tb-social" aria-label="Facebook">
              <svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><path d="M24 12.073C24 5.405 18.627 0 12 0S0 5.405 0 12.073c0 6.028 4.388 11.024 10.125 11.927v-8.437H7.078v-3.49h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.49h-2.796v8.437C19.612 23.097 24 18.101 24 12.073z"/></svg>
            </a>
            <a href="#" className="tb-social" aria-label="Instagram">
              <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><rect x="2" y="2" width="20" height="20" rx="5"/><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"/><line x1="17.5" y1="6.5" x2="17.51" y2="6.5"/></svg>
            </a>
            <a href="#" className="tb-social" aria-label="YouTube">
              <svg width="14" height="13" viewBox="0 0 24 24" fill="currentColor"><path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z"/></svg>
            </a>
          </span>
        </div>
      </div>

      {/* ── MAIN NAV ROW ── */}
      <div className="topbar__main">
        <div className="container topbar__main-inner">

          {/* Logo — hidden at rest, slides in when scrolled */}
          <a href="#" className="topbar__brand--nav" aria-label="Frederiksen &amp; Jepsen forside">
            <img src="./assets/logo-fj-real.png" alt="Frederiksen &amp; Jepsen A/S"/>
          </a>

          {/* Desktop nav */}
          <nav className="topbar__nav" aria-label="Primær navigation">
            {NAV_ITEMS.map((item) =>
              item.children ? (
                <NavDropdown
                  key={item.label}
                  item={item}
                  open={openDrop === item.label}
                  onToggle={setOpenDrop}
                />
              ) : (
                <a key={item.label} href={item.href} className="topbar__nav-link">
                  {item.label}
                </a>
              )
            )}
          </nav>

          {/* Phone + CTA */}
          <div className="topbar__actions">
            <a href="tel:+4574486994" className="topbar__phone">
              <span className="topbar__phone-ic">
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.86 19.86 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6A19.86 19.86 0 0 1 2.12 4.18 2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/></svg>
              </span>
              74 48 69 94
            </a>
            <button className="topbar__cta" onClick={onOpenQuote}>
              Gratis tilbud
            </button>
          </div>

          {/* Mobile hamburger */}
          <button className="topbar__burger" onClick={() => setMobileOpen(true)} aria-label="Åben menu">
            <span/><span/><span/>
          </button>
        </div>
      </div>

      {/* ── MOBILE OVERLAY ── */}
      {mobileOpen && (
        <div className="topbar__mobile" role="dialog" aria-modal="true" aria-label="Navigation">
          <div className="topbar__mobile-head">
            <img src="./assets/logo-fj-real.png" alt="Frederiksen &amp; Jepsen A/S" style={{ height: 32 }}/>
            <button onClick={() => setMobileOpen(false)} aria-label="Luk menu" className="topbar__mobile-close">
              <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
            </button>
          </div>

          <nav className="topbar__mobile-nav">
            {NAV_ITEMS.map((item) =>
              item.children ? (
                <div key={item.label} className="tbm-group">
                  <button
                    className={"tbm-group__toggle" + (mobileExpanded === item.label ? " tbm-group__toggle--open" : "")}
                    onClick={() => setMobileExpanded(mobileExpanded === item.label ? null : item.label)}
                  >
                    {item.label}
                    <svg width="12" height="8" viewBox="0 0 12 8" fill="none" className="tbm-caret">
                      <path d="M1 1l5 5 5-5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
                    </svg>
                  </button>
                  {mobileExpanded === item.label && (
                    <div className="tbm-group__sub">
                      {item.children.map((c) => (
                        <a key={c.label} href={c.href} onClick={() => setMobileOpen(false)} className="tbm-group__child">
                          {c.label}
                        </a>
                      ))}
                    </div>
                  )}
                </div>
              ) : (
                <a key={item.label} href={item.href} className="tbm-link" onClick={() => setMobileOpen(false)}>
                  {item.label}
                </a>
              )
            )}
          </nav>

          <a href="tel:+4574486994" className="topbar__mobile-phone">74 48 69 94</a>
          <button className="topbar__cta topbar__cta--full" onClick={() => { setMobileOpen(false); onOpenQuote(); }}>
            Gratis tilbud
          </button>
        </div>
      )}

      <style>{`
        /* ── TOPBAR SHELL ── */
        .topbar {
          position: sticky; top: 0; z-index: 50;
          background: #fff;
        }

        /* ── TOP INFO BAR — diagonal split ── */
        .topbar__top {
          display: flex;
          height: 60px;
          overflow: hidden;
          transition: height 260ms var(--ease-snappy), opacity 220ms;
          background: #00385B;
        }
        .topbar--scrolled .topbar__top {
          height: 0; opacity: 0; pointer-events: none;
        }

        /* White decorative strip — logo is NOT here; it lives in the nav bar below
           and is translated upward to straddle the boundary */
        .topbar__top-left {
          background: #fff;
          /* Width roughly matches where the logo will appear */
          width: max(120px, calc((100vw - 1240px) / 2 + 370px));
          flex-shrink: 0;
          position: relative; z-index: 1;
          clip-path: polygon(0 0, calc(100% - 40px) 0, 100% 100%, 0 100%);
        }

        /* Dark navy right panel — badges + contact */
        .topbar__top-right {
          flex: 1;
          display: flex; align-items: center; justify-content: flex-start;
          gap: clamp(6px, calc(2.2vw - 18px), 14px);
          padding-left: 25px;
          padding-right: 25px;
        }

        /* Review badges (on blue) */
        .tb-badge {
          display: inline-flex; align-items: center; gap: 8px;
          text-decoration: none;
          transition: opacity 80ms var(--ease-snappy);
        }
        .tb-badge:hover { opacity: 0.8; }
        .tb-badge__logo {
          width: clamp(24px, 2.08vw, 30px); height: clamp(24px, 2.08vw, 30px); border-radius: var(--radius-pill);
          background: #fff; border: 1.5px solid rgba(255,255,255,0.3);
          display: flex; align-items: center; justify-content: center;
          flex-shrink: 0;
        }
        .tb-badge__logo--fb { background: #1877F2; border-color: #1877F2; }
        .tb-badge__logo--tp { background: #00B67A; border-color: #00B67A; }
        .tb-badge__body {
          display: flex; flex-direction: column; gap: 1px;
        }
        .tb-stars { display: flex; gap: 1px; }
        .tb-badge__label {
          font-family: var(--font-body); font-size: clamp(10px, 0.9vw, 13px); font-weight: 700;
          color: rgba(255,255,255,0.88); letter-spacing: 0.02em; white-space: nowrap;
        }
        .tb-stars svg { width: clamp(11px, 0.9vw, 13px); height: clamp(11px, 0.9vw, 13px); }
        /* BYG GARANTI cert badge */
        .tb-badge--cert {
          gap: 1px; padding: 3px 10px; border-radius: var(--radius-sm);
          border: 1.5px solid rgba(255,255,255,0.45);
          flex-direction: column; align-items: center;
        }
        .tb-badge__cert-text {
          font-family: var(--font-display); font-weight: 700;
          font-size: clamp(11px, 0.97vw, 14px); color: #fff; letter-spacing: 0.1em; line-height: 1;
        }
        .tb-badge__cert-sub {
          font-family: var(--font-body); font-size: clamp(8px, 0.7vw, 10px); font-weight: 700;
          color: rgba(255,255,255,0.7); letter-spacing: 0.1em; text-transform: uppercase;
        }

        /* Vertical divider between badge group and contact group */
        .tb-divider {
          display: block; width: 1px; height: 26px;
          background: rgba(255,255,255,0.3); flex-shrink: 0;
          margin: 0 4px;
        }

        /* Email + socials (on blue) */
        .tb-email {
          display: flex; align-items: center; gap: 8px;
          font-family: var(--font-body); font-size: clamp(11px, 0.97vw, 14px); font-weight: 700;
          color: #fff; text-decoration: none; white-space: nowrap;
          transition: opacity 80ms var(--ease-snappy);
          margin-left: auto;
        }
        .tb-email:hover { opacity: 0.8; }
        .tb-email svg { flex-shrink: 0; color: #fff; width: clamp(13px, 1.11vw, 16px); height: clamp(13px, 1.11vw, 16px); }
        .tb-follow {
          display: flex; align-items: center; gap: 8px;
          font-family: var(--font-body); font-size: clamp(10px, 0.9vw, 13px); font-weight: 700;
          color: rgba(255,255,255,0.9); letter-spacing: 0.06em; text-transform: uppercase;
          white-space: nowrap;
        }
        .tb-social {
          width: clamp(24px, 1.94vw, 28px); height: clamp(24px, 1.94vw, 28px); border-radius: var(--radius-pill);
          background: rgba(255,255,255,0.2);
          display: inline-flex; align-items: center; justify-content: center;
          color: #fff; text-decoration: none;
          border: 1px solid rgba(255,255,255,0.35);
          transition: background 80ms var(--ease-snappy), transform 80ms var(--ease-snappy);
        }
        .tb-social:hover { background: rgba(255,255,255,0.4); transform: translateY(-1px); }
        .tb-social:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

        /* ── MAIN NAV ROW ── */
        .topbar__main {
          background: #fff;
          /* Must sit above the info bar so the translated logo renders on top */
          position: relative; z-index: 5;
        }
        .topbar__main-inner {
          max-width: none;
          display: flex; align-items: center; gap: clamp(10px, calc(5vw - 44px), 28px);
          height: 72px;
          padding-left: 25px;
          padding-right: 25px;
        }

        /* Logo in nav — always in the flex flow.
           At rest: translateY(-36px) = -navHeight/2, placing its center exactly
           on the info-bar / nav-bar boundary. On scroll: returns to Y=0
           while the info bar collapses — one continuous smooth motion, no jump. */
        .topbar__brand--nav {
          flex-shrink: 0;
          transform: translateY(-36px);
          transition: transform 260ms var(--ease-snappy);
          text-decoration: none;
          margin-left: 0;
        }
        .topbar__brand--nav img {
          height: clamp(26px, calc(5vw - 28px), 44px); width: auto; display: block;
          transition: height 260ms var(--ease-snappy);
        }
        .topbar__brand--nav:hover { opacity: 0.85; }
        .topbar__brand--nav:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
        /* Scrolled: logo settles naturally into the nav bar */
        .topbar--scrolled .topbar__brand--nav { transform: translateY(0); }
        .topbar--scrolled .topbar__brand--nav img { height: clamp(20px, calc(2.78vw - 10px), 30px); }

        /* Desktop nav */
        .topbar__nav {
          display: flex; align-items: center; gap: clamp(0px, calc(0.56vw - 6px), 2px);
          margin-left: auto;
        }
        .topbar__nav-link {
          padding: clamp(5px, calc(1.11vw - 7px), 9px) clamp(7px, calc(1.94vw - 14px), 14px); border-radius: var(--radius-sm);
          font-family: var(--font-display); font-weight: 700;
          font-size: clamp(12px, 1.11vw, 16px); letter-spacing: 0.04em; text-transform: uppercase;
          color: var(--ink); text-decoration: none;
          transition: color 80ms var(--ease-snappy), background 80ms var(--ease-snappy);
          white-space: nowrap;
        }
        .topbar__nav-link:hover { color: var(--accent); background: rgba(229,172,49,0.06); }
        .topbar__nav-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
        .topbar__nav-link:active { color: var(--accent-lo); }

        /* Dropdown trigger */
        .tbdrop { position: relative; }
        .tbdrop__trigger {
          display: flex; align-items: center; gap: 4px;
          padding: clamp(5px, calc(1.11vw - 7px), 9px) clamp(7px, calc(1.94vw - 14px), 14px); border-radius: var(--radius-sm); border: 0;
          font-family: var(--font-display); font-weight: 700;
          font-size: clamp(12px, 1.11vw, 16px); letter-spacing: 0.04em; text-transform: uppercase;
          color: var(--ink); background: transparent; cursor: pointer;
          transition: color 80ms var(--ease-snappy), background 80ms var(--ease-snappy);
          white-space: nowrap;
        }
        .tbdrop__trigger:hover, .tbdrop__trigger--open { color: var(--accent); background: rgba(229,172,49,0.06); }
        .tbdrop__trigger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
        .tbdrop__trigger:active { color: var(--accent-lo); }
        .tbdrop__caret {
          color: currentColor; flex-shrink: 0; opacity: 0.7;
          transition: transform 160ms var(--ease-snappy);
        }
        .tbdrop__trigger--open .tbdrop__caret { transform: rotate(180deg); }

        /* Dropdown panel */
        .tbdrop__panel {
          position: absolute; top: calc(100% + 8px); left: 50%;
          transform: translateX(-50%);
          min-width: 200px;
          background: #fff; border-radius: var(--radius-md);
          box-shadow: 0 4px 6px rgba(0,0,0,0.05), 0 12px 40px rgba(0,0,0,0.14);
          border: 1px solid rgba(0,0,0,0.07);
          padding: 6px;
          animation: tbDropIn 160ms var(--ease-snappy) both;
          z-index: 10;
        }
        @keyframes tbDropIn {
          from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
          to   { opacity: 1; transform: translateX(-50%) translateY(0); }
        }
        .tbdrop__item {
          display: block; padding: 9px 14px; border-radius: var(--radius-sm);
          font-family: var(--font-body); font-weight: 500; font-size: 14px;
          color: var(--ink-dim); text-decoration: none;
          transition: background 60ms var(--ease-snappy), color 60ms var(--ease-snappy);
          white-space: nowrap;
        }
        .tbdrop__item:hover { background: rgba(229,172,49,0.07); color: var(--accent); }
        .tbdrop__item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius-sm); }
        .tbdrop__item:active { background: rgba(229,172,49,0.12); }

        /* Phone */
        .topbar__actions {
          display: flex; align-items: center; gap: clamp(6px, calc(1.67vw - 12px), 12px); flex-shrink: 0;
        }
        .topbar__phone {
          display: flex; align-items: center; gap: 7px;
          font-family: var(--font-display); font-weight: 700; font-size: clamp(13px, calc(1.11vw + 1px), 17px);
          letter-spacing: 0.02em; color: var(--ink); text-decoration: none;
          transition: color 80ms var(--ease-snappy);
          white-space: nowrap;
        }
        .topbar__phone:hover { color: var(--accent); }
        .topbar__phone:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
        .topbar__phone-ic {
          width: clamp(24px, 2.22vw, 32px); height: clamp(24px, 2.22vw, 32px); border-radius: var(--radius-pill);
          background: var(--accent); color: #fff;
          display: inline-flex; align-items: center; justify-content: center;
          flex-shrink: 0;
          box-shadow: 0 2px 0 var(--accent-lo), 0 4px 12px rgba(229,172,49,0.3);
        }
        .topbar__phone:hover .topbar__phone-ic {
          background: var(--accent-hi);
        }

        /* CTA button */
        .topbar__cta {
          padding: clamp(8px, calc(0.83vw - 1px), 11px) clamp(12px, calc(2.22vw - 12px), 20px); border-radius: var(--radius-sm); border: 0;
          font-family: var(--font-display); font-weight: 700;
          font-size: clamp(11px, calc(0.56vw + 5px), 13px); letter-spacing: var(--tracking-button); text-transform: uppercase;
          color: #fff; background: var(--accent); cursor: pointer;
          box-shadow: 0 4px 0 var(--accent-lo), 0 8px 24px rgba(229,172,49,0.28);
          transition: background 80ms var(--ease-snappy), transform 80ms var(--ease-snappy), box-shadow 80ms var(--ease-snappy);
          white-space: nowrap;
        }
        .topbar__cta:hover {
          background: var(--accent-hi); transform: translateY(-1px);
          box-shadow: 0 6px 0 var(--accent-lo), 0 12px 30px rgba(229,172,49,0.35);
        }
        .topbar__cta:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
        .topbar__cta:active {
          background: var(--accent-lo); transform: translateY(1px);
          box-shadow: 0 0 0 var(--accent-lo), 0 4px 10px rgba(229,172,49,0.2);
        }
        .topbar__cta--full { width: 100%; }

        /* Hamburger */
        .topbar__burger {
          display: none; flex-direction: column; gap: 5px;
          width: 36px; height: 36px; align-items: center; justify-content: center;
          background: transparent; border: 0; cursor: pointer; padding: 6px;
          border-radius: var(--radius-sm);
          transition: background 80ms var(--ease-snappy);
        }
        .topbar__burger:hover { background: rgba(11,17,24,0.07); }
        .topbar__burger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
        .topbar__burger span {
          display: block; width: 22px; height: 2px;
          background: var(--ink); border-radius: 2px;
          transition: opacity 80ms var(--ease-snappy);
        }

        /* ── MOBILE OVERLAY ── */
        .topbar__mobile {
          position: fixed; inset: 0; z-index: 200;
          background: #0B1118;
          display: flex; flex-direction: column; gap: 0;
          padding: 0;
          animation: mobileSlideIn 220ms var(--ease-snappy) both;
        }
        @keyframes mobileSlideIn {
          from { opacity: 0; transform: translateX(100%); }
          to   { opacity: 1; transform: translateX(0); }
        }
        .topbar__mobile-head {
          display: flex; align-items: center; justify-content: space-between;
          padding: 20px 24px;
          border-bottom: 1px solid var(--surface-divider);
        }
        .topbar__mobile-close {
          background: transparent; border: 0; padding: 6px; cursor: pointer;
          color: var(--paper); border-radius: var(--radius-sm);
          transition: background 80ms var(--ease-snappy), color 80ms var(--ease-snappy);
        }
        .topbar__mobile-close:hover { background: rgba(255,255,255,0.08); }
        .topbar__mobile-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
        .topbar__mobile-close:active { color: var(--accent); }
        .topbar__mobile-nav {
          flex: 1; overflow-y: auto; padding: 12px 24px;
        }
        .tbm-link {
          display: block; padding: 14px 0; border-bottom: 1px solid var(--surface-divider);
          font-family: var(--font-display); font-weight: 600;
          font-size: 22px; text-transform: uppercase; letter-spacing: 0.04em;
          color: var(--paper); text-decoration: none;
          transition: color 80ms var(--ease-snappy);
        }
        .tbm-link:hover { color: var(--accent); }
        .tbm-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
        .tbm-group__toggle {
          display: flex; align-items: center; justify-content: space-between;
          width: 100%; padding: 14px 0; border-bottom: 1px solid var(--surface-divider); border-left: 0; border-right: 0; border-top: 0;
          background: transparent; cursor: pointer;
          font-family: var(--font-display); font-weight: 600;
          font-size: 22px; text-transform: uppercase; letter-spacing: 0.04em;
          color: var(--paper);
          transition: color 80ms var(--ease-snappy);
        }
        .tbm-group__toggle:hover, .tbm-group__toggle--open { color: var(--accent); }
        .tbm-group__toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
        .tbm-caret {
          transition: transform 160ms var(--ease-snappy); flex-shrink: 0;
        }
        .tbm-group__toggle--open .tbm-caret { transform: rotate(180deg); }
        .tbm-group__sub {
          padding: 4px 0 8px 16px;
          animation: tbDropIn 140ms var(--ease-snappy) both;
        }
        .tbm-group__child {
          display: block; padding: 10px 0;
          font-family: var(--font-body); font-weight: 500; font-size: 15px;
          color: var(--paper-dim); text-decoration: none;
          border-bottom: 1px solid rgba(255,255,255,0.04);
          transition: color 80ms var(--ease-snappy);
        }
        .tbm-group__child:hover { color: var(--accent); }
        .tbm-group__child:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
        .topbar__mobile-phone {
          display: block; padding: 20px 24px;
          font-family: var(--font-display); font-weight: 700; font-size: 34px;
          color: var(--accent); text-decoration: none; letter-spacing: 0.02em;
          transition: color 80ms var(--ease-snappy);
        }
        .topbar__mobile-phone:hover { color: var(--accent-hi); }
        .topbar__cta--full { margin: 0 24px 24px; }

        /* Badges group */
        .tb-badges-group { display: flex; align-items: center; gap: clamp(6px, calc(2.2vw - 18px), 14px); }

        /* ── INFO BAR PROGRESSIVE HIDING ── */
        /* Stage 1: drop "FØLG OS:" label early — most laptops are ≤1440px */
        @media (max-width: 1450px) { .tb-follow-label { display: none; } }
        /* Stage 2: drop social icons below M2 MacBook Air width (1280px CSS viewport) */
        @media (max-width: 1280px) { .tb-follow { display: none; } }
        /* Stage 3: drop review badges + divider, email stays right via margin-left: auto */
        @media (max-width: 1150px) { .tb-badges-group { display: none; } .tb-divider { display: none; } }

        /* ── RESPONSIVE ── */
        @media (max-width: 1080px) {
          /* Hide info bar entirely on tablet/mobile */
          .topbar__top { display: none; }
          .topbar__nav { display: none; }
          .topbar__actions { display: none; }
          .topbar__burger { display: inline-flex; margin-left: auto; }
          /* Logo sits flat in nav bar — no info bar to straddle */
          .topbar__brand--nav,
          .topbar--scrolled .topbar__brand--nav {
            transform: translateY(0);
            margin-left: 0;
          }
          .topbar__brand--nav img,
          .topbar--scrolled .topbar__brand--nav img {
            height: 32px;
          }
        }
      `}</style>
    </header>
  );
}

Object.assign(window, { TopBar });
