/*
 * The hand-written half of the site header.
 *
 * It started as the fix for the top-level menu in every language, which is
 * what the long note below is about, and it has since become the one place
 * where header and footer corrections live, because it is the only stylesheet
 * of ours that both halves of the site load. The sections, in order:
 *
 *   the top-level menu     flex row, one gap, no title-casing
 *   the mobile drawer      a flex column so the bottom row stays on screen
 *   the shell              one content width for the chrome and the page
 *
 * Each section carries its own measurements. Scroll to the one you need.
 *
 * THE TOP-LEVEL MENU, MADE TO FIT IN EVERY LANGUAGE
 * -------------------------------------------------
 *
 * WHAT WAS WRONG
 * --------------
 * Reported as "menu breaks in French", and French was the visible case: the
 * bar wrapped onto two and sometimes three rows at every desktop width. It
 * was never only French. Measured across the site's nine languages at 1280,
 * 1366, 1440, 1600 and 1920:
 *
 *   English, Korean                     fit at every width
 *   French                              wrapped at every width
 *   Spanish, German, Italian, Dutch,    wrapped at 1280, 1366 and 1440,
 *   Portuguese, Turkish                 which is most laptops
 *
 * 23 of those 45 combinations wrapped, and only one of them had been noticed.
 *
 * inc/nav-data.php carries the note that "six labels sit on one row, a
 * seventh wraps the bar onto two", measured at 1280 and 1440. That
 * measurement was taken in English, which is one of the two languages that
 * was never going to show the problem.
 *
 * WHERE THE SPACE WENT
 * --------------------
 * At 1920 the menu has about 800px, and in French the six labels need 632px
 * of it. The remaining 200px was gaps, and the gap is not the 17px the
 * stylesheet appears to set. app.min.css has
 *
 *     .main-menu > ul > li { margin: 0 17px }
 *
 * which is 17px on each side, so 34px between neighbours. The list is
 * display:block holding inline-block items, so the whitespace between the
 * <li> tags adds about 6px more at the list's own 21px font-size. The
 * measured gap is 40px. Five of them, 200px, a quarter of the bar spent on
 * air that nobody chose.
 *
 * Laying the list out as a flex row replaces all of that with one number that
 * means what it says. At 18px every language fits on one row at every desktop
 * width, with the agency item shortened to its bare noun (Agences, Agencias,
 * Agenturen) in the TranslatePress dictionary. Those two changes together
 * were measured at 0 failures across all 45 combinations; the gap alone left
 * Spanish wrapping on laptops, and the shorter label alone was not enough for
 * French.
 *
 * Two different wraps, and they are treated differently. A label is never
 * broken in the middle (white-space:nowrap on the anchor, flex-shrink:0 on
 * the item), because a word split in half reads as a rendering fault. The bar
 * itself is still allowed to take a second row, because the alternative is a
 * long label running underneath the Sign in button, and this site gains
 * translations regularly. A second row is poor; covering the sign-in link is
 * worse.
 *
 * THE TRANSITION
 * --------------
 * app.min.css also puts `transition: all .4s` on .main-menu a. It animates
 * nothing: no property on the anchor changes on hover, and the chevron and
 * the mega panel carry their own transitions. What it does do is swallow any
 * change to font-size, which then cannot be overridden at all, not by a more
 * specific rule and not by an inline !important either. That cost an hour of
 * believing font-size was being applied and measuring no difference, so it is
 * scoped to colour here and the property is available again.
 *
 * BOTH HEADERS
 * ------------
 * The same header markup is served two ways. The marketing pages load
 * app.min.css with tolinku-overrides.css on top; the blog and tools pages
 * load tolinku-header.css, the scoped extract built by
 * tools/build-header-css.py. Neither of those files is loaded by the other,
 * so a fix written in tolinku-overrides.css would have left the blog header
 * still wrapping. The rules below are written for both worlds, and this file
 * is enqueued on its own hook for the same reason the language switcher's
 * assets are: tolinku_enqueue_assets() returns early on Azzle pages.
 */

.main-menu.menu-style1 > ul,
.tolinku-chrome .main-menu.menu-style1 > ul {
  display: flex;
  align-items: center;
  /*
   * Still allowed to wrap. See the note above about not wrap-proofing this:
   * a label longer than anything measured here should take a second row
   * rather than run under the Sign in button.
   */
  flex-wrap: wrap;
  gap: 18px;
}

/*
 * The margins the gap replaces. Both sides, because the template sets
 * `margin: 0 17px` and a gap laid on top of those would be the old spacing
 * plus the new one rather than instead of it.
 */
.main-menu.menu-style1 > ul > li,
.tolinku-chrome .main-menu.menu-style1 > ul > li {
  margin-left: 0;
  margin-right: 0;
  /*
   * Flex items shrink by default, and that is worse than what it replaced.
   * The first version of this file left it at the default and Spanish at
   * 1280 stopped wrapping the bar and started wrapping inside a label
   * instead: the item grew from 85px to 109px because "Desarrolladores" had
   * been squeezed onto two lines. A menu that wraps onto a second row is
   * poor; a single word broken in half is worse, and it looks like a
   * rendering fault rather than a tight fit.
   */
  flex-shrink: 0;
}

.main-menu.menu-style1 > ul > li > a,
.tolinku-chrome .main-menu.menu-style1 > ul > li > a {
  white-space: nowrap;
}

.main-menu a,
.tolinku-chrome .main-menu a {
  transition: color 0.4s ease;
}

/* ---- laptop widths ------------------------------------------------ */

/*
 * A tighter gap between 992px and 1599px, where the bar is closest to
 * running out of room.
 *
 * Measured on the live site at 1280px, after the agency labels were
 * shortened. The header is a three column row (logo 129, menu, calls to
 * action) and the middle column gets whatever the other two leave, so the
 * room the menu has depends on how long the "Start free" translation is:
 *
 *   en  button 121px  menu column 710  needs 592  118 to spare
 *   es  button 162px  menu column 621  needs 637  16 short
 *   tr  button 182px  menu column 635  needs 653  18 short
 *   fr  button 248px  menu column 536  needs 651  115 short
 *
 * "needs" is the six label widths plus five gaps. Dropping the gap from 18
 * to 12 frees 30px, which clears Spanish and Turkish with about 12px in
 * hand.
 *
 * It did not clear French, and no gap could: removing the gap entirely
 * frees 90px against a 115px shortfall. French was wide because its "Start
 * free" read "Commencer gratuitement" at 248px, against 121px in English,
 * so the call to action took 127px the menu would otherwise have had. That
 * was a copy problem wearing a layout costume, and no amount of CSS here
 * was going to fix it. The French string is now "Commencer" (143px), which
 * frees 105px against the 85px that was missing once the gap came down.
 *
 * So if French starts wrapping again, look at that button before touching
 * anything in this file.
 *
 * 1600px and up keeps 18px: every language already fits there, and there is
 * no reason to crowd a bar that has room.
 */
@media (min-width: 992px) and (max-width: 1599px) {
  .main-menu.menu-style1 > ul,
  .tolinku-chrome .main-menu.menu-style1 > ul {
    gap: 12px;
  }
}

/* ---- letter case -------------------------------------------------- */

/*
 * The menu renders the words it was given, rather than title-casing them.
 *
 * app.min.css and tolinku-header.css both put text-transform: capitalize on
 * .main-menu a, the sub-menu links and the mobile menu. In English it does
 * nothing, because every label in inc/nav-data.php is already written in the
 * case it should appear in. In the other languages it is simply wrong:
 *
 *   fr   Pour les agences  ->  Pour Les Agences
 *   fr   A propos          ->  A Propos
 *   es   Acerca de         ->  Acerca De
 *   it   Chi siamo         ->  Chi Siamo
 *
 * French, Spanish, Italian and Portuguese capitalise a heading's first word
 * and leave the rest, so title case reads like a mistake to anyone who reads
 * those languages. The translations in the dictionary are correctly cased;
 * CSS was overriding them on the way to the screen.
 *
 * It was wrong in English too, just invisibly: the rule also covers the mega
 * panel, where it turned the descriptions into "Check An Apple Association
 * File", and it is why inc/nav-data.php carries a note about the panel
 * turning "assetlinks.json" into "Assetlinks.Json". Both are fixed by this.
 *
 * Nothing here changes an English label, because capitalize was a no-op on
 * every one of them.
 */
.main-menu a,
.tolinku-chrome .main-menu a,
.main-menu ul.sub-menu li a,
.tolinku-chrome .main-menu ul.sub-menu li a,
.azzle-mobile-menu ul li a,
.tolinku-chrome .azzle-mobile-menu ul li a {
  text-transform: none;
}

/* ---- the mobile drawer ------------------------------------------- */

/*
 * The drawer's bottom row stays on screen.
 *
 * Azzle laid the drawer out as three blocks stacked in normal flow: the logo
 * bar, the menu at `max-height: calc(100vh - 200px); overflow-y: scroll`, and
 * then a `.azzle-mobile-menu-btn` row holding the call to action, with
 * `padding-top: 50px` above it. Nothing bounded the total, and
 * .azzle-menu-area is `height: 100%` with no overflow of its own, so when a
 * submenu expanded the menu grew to its 100vh-200px ceiling and pushed the
 * bottom row off the end of the drawer, where there was no way to scroll back
 * to it. The row is also `flex-wrap: wrap`, so the switcher beside the button
 * was the first thing to go: it wrapped to a second line and that line was
 * already past the bottom edge. Reported as "the language selector goes below
 * and cannot be seen again".
 *
 * Making the area a flex column fixes it with one number instead of two: the
 * menu takes whatever is left after the two fixed rows, and the ceiling is
 * the drawer rather than a guess at the viewport. The 200px in that calc was
 * the guess, and it was wrong by however much the translated button and the
 * switcher needed.
 *
 * Both selectors, once for each stylesheet: marketing pages get app.min.css
 * (unprefixed) and the blog and tools pages get tolinku-header.css (scoped
 * under .tolinku-chrome), and the scoped copy's extra class beats a one-class
 * rule here however late it loads. See the note at the top of this file.
 */

.azzle-menu-wrapper .azzle-menu-area,
.tolinku-chrome .azzle-menu-wrapper .azzle-menu-area {
  display: flex;
  flex-direction: column;
}

.azzle-menu-mobile-top,
.tolinku-chrome .azzle-menu-mobile-top {
  flex: 0 0 auto;
}

.azzle-mobile-menu,
.tolinku-chrome .azzle-mobile-menu {
  flex: 1 1 auto;
  /*
   * A flex item's min-height is auto, which means "never smaller than my
   * content". Without this the list refuses to shrink and pushes the bottom
   * row out again, which is the whole bug wearing a different hat.
   */
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  /* Reaching the end of the list scrolls the list, not the page behind it. */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.azzle-mobile-menu-btn,
.tolinku-chrome .azzle-mobile-menu-btn {
  flex: 0 0 auto;
  /*
   * One row, always. Wrapping is what put the switcher on a second line, and
   * the two controls are sized below to fit side by side at 310px, which is
   * the drawer's width, narrowing to the full viewport under 400px.
   */
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 12px 15px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

/*
 * The call to action takes the room the switcher leaves. `width: fit-content`
 * in app.min.css sizes it to its label, which in English left a gap on the
 * right and in French (Commencer) left almost none, so the pair sat
 * differently in every language. Four classes deep to clear the scoped copy.
 */
.azzle-menu-area .azzle-mobile-menu-btn a.azzle-default-btn.sm-size,
.tolinku-chrome .azzle-menu-area .azzle-mobile-menu-btn a.azzle-default-btn.sm-size {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  justify-content: center;
}

/*
 * The chevron stops covering the label.
 *
 * It is `position: absolute; right: 0; width: 60%` inside the anchor, which
 * was deliberate while it was the only thing that toggled the submenu. The
 * whole row toggles now (assets/js/menu/menu.js and
 * assets/js/tolinku-chrome.js), so the width is only reach it does not need,
 * and at 60% of a 310px drawer it overlapped the tail of any label longer
 * than about "Resources" once translated.
 */
.azzle-mobile-menu ul .azzle-item-has-children > a .azzle-mean-expand,
.tolinku-chrome .azzle-mobile-menu ul .azzle-item-has-children > a .azzle-mean-expand {
  width: 48px;
}

/*
 * Same rule, same reason, one more place: the drawer's call to action.
 *
 * app.min.css puts text-transform: capitalize on .azzle-default-btn.sm-size,
 * which is only ever the mobile "Start free". In English it turns the label
 * into "Start Free", which is wrong but survivable; in the languages that
 * capitalise a heading's first word and leave the rest it is the same mistake
 * the menu was making, on the most prominent control in the drawer:
 *
 *   de   Kostenlos starten  ->  Kostenlos Starten
 *   es   Empieza gratis     ->  Empieza Gratis
 *   nl   Gratis starten     ->  Gratis Starten
 *
 * The desktop header button is a different class and was never affected,
 * which is why this was visible on a phone and nowhere else.
 */
.azzle-mobile-menu-btn a.azzle-default-btn.sm-size,
.tolinku-chrome .azzle-mobile-menu-btn a.azzle-default-btn.sm-size {
  text-transform: none;
}

/* ---- the shell ---------------------------------------------------- */

/*
 * One content width for the whole site, used by the chrome and by the page
 * under it.
 *
 * There used to be two. Marketing pages put their content in a .container
 * whose widths come from src/marketing.css, and tolinku-overrides.css pins
 * `.azzle-header-section .container` to the same numbers, so on those pages
 * the logo has always sat exactly above the first word of the page.
 * Everywhere else the content was Tailwind utilities at their own widths
 * (max-w-7xl on the blog, 68rem on the tools and support pages) while the
 * header kept Bootstrap's ladder, and the two disagreed at every viewport:
 *
 *   viewport   header ink     blog content ink    the logo sat
 *   600        42px           16px                26px inside the text
 *   760        122px          16px                106px inside the text
 *   991        147px          16px                131px inside the text
 *   1920       197px          345px               148px outside the text
 *
 * Stepped against fluid, so it was never right and the error swung either
 * way. The footer had it too, because that template uses .container as well.
 *
 * Giving the header each page's own width fixed the alignment and moved the
 * logo 148px between the home page and the blog, which is worse: a logo that
 * jumps as you browse is noticed immediately, and a header that is 26px out
 * is not. Two widths could never give both. So the numbers below are the
 * marketing ladder, and the blog, tools and support templates were moved onto
 * it.
 *
 * The ladder is stated once as a custom property so the chrome and the content
 * cannot drift apart again: there is no second copy to forget. It is the
 * ladder in src/marketing.css, which is Tailwind's default container, and the
 * gutter is Bootstrap's 0.75rem, which is what .container already resolved to
 * on both halves.
 *
 * functions.php puts tolinku-shell-page on the body of every page that is not
 * a marketing view, and explains why. A marketing page gets neither that class
 * nor .tolinku-shell, so nothing here touches it.
 */

:root { --tolinku-shell: 100%; }
/*
 * 540px between 576 and 639 is not part of Tailwind's ladder. It is Bootstrap's
 * `sm` step, which still reaches the marketing container because
 * tolinku-overrides.css only starts pinning the header at 640px, and it is
 * copied here deliberately. Measured across seven page types at eight widths,
 * this 64px band was the one place the logo still moved between the home page
 * and the blog, by 23px. Matching it is mimicry, but the alternative is
 * removing it from the marketing side, which would then leave the marketing
 * header out of line with the marketing content in the same band.
 */
@media (min-width: 576px)  { :root { --tolinku-shell: 540px; } }
@media (min-width: 640px)  { :root { --tolinku-shell: 640px; } }
@media (min-width: 768px)  { :root { --tolinku-shell: 768px; } }
@media (min-width: 1024px) { :root { --tolinku-shell: 1024px; } }
@media (min-width: 1280px) { :root { --tolinku-shell: 1280px; } }
@media (min-width: 1536px) { :root { --tolinku-shell: 1536px; } }

/*
 * One rule for all of it. The body class carries the specificity the chrome
 * needs: the generated .tolinku-chrome .container ladder in tolinku-header.css
 * is two classes, so a rule here needs the extra element and class to win at
 * every breakpoint without !important.
 *
 * width:100% is not redundant beside max-width. .tolinku-support-body is a
 * direct child of a `flex flex-col` body, and a flex item with auto inline
 * margins shrink-wraps to its content, so on a short support answer the column
 * came out 891px inside a 1088px box and nothing lined up with it.
 */
.tolinku-shell,
.tolinku-tool-body,
.tolinku-support-body,
body.tolinku-shell-page .tolinku-chrome .container,
body.tolinku-shell-page .tolinku-foot .container {
  width: 100%;
  max-width: var(--tolinku-shell);
  margin-inline: auto;
  padding-inline: 0.75rem;
}
