/* Public navbar layout (desktop and mobile).
 * Loaded after css/style.css by includes/header.php.
 * Keep search, category selector, and hamburger sizing here instead of
 * adding further overrides inside the shared PHP template.
 * All existing button colors and states remain in css/style.css.
 */

/* Desktop: search -> Add Recipe -> Home -> Logout -> Admin.
   This fixes older header-controls rules that shrink or separate the group. */
@media screen and (min-width: 761px) {
  .site-header .header-controls {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
  }
  .site-header .header-controls > .search-box {
    order: 0;
    flex: 1 1 240px;
    width: auto;
    min-width: 0;
    margin: 0;
  }
  .site-header .header-controls > .header-navbar {
    order: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    gap: var(--nav-button-gap, 6px);
    flex: 0 0 auto;
    width: auto;
    margin: 0;
  }
  .site-header .header-navbar > .header-add-recipe-link { order: -1; }
  .site-header .header-navbar > a,
  .site-header .header-navbar > form { flex-shrink: 0; }
  .site-header .header-navbar .logout-form { margin: 0; }
  .site-header .header-mobile-menu { display: none; }
}

/* Phone widths: the hamburger contains Add Recipe first.
   Desktop buttons do not compete for the limited header width. */
@media screen and (max-width: 760px) {
  .site-header .header-controls > .header-navbar { display: none; }
  .site-header .header-controls > .search-box { min-width: 0; }
  .site-header .header-mobile-menu { display: block; }
}

/* Mobile category selector: migrated from the validated V4 header rules.
 * The specific selectors override legacy layout defaults in css/style.css.
 * The search input and category select both remain exactly 40px tall.
 */
/* Stable default if an older navbar-placement.css is still cached. */
body:not(.admin-site) .site-header .search-box > .navbar-category-select {
  flex: 0 1 180px;
  width: clamp(128px, 14vw, 190px);
  min-width: 128px;
  height: 30px;
  margin: 0;
  padding: 2px 26px 2px 9px;
  font-size: 12px;
  color: var(--text);
  background-color: #fff;
  border: 1px solid var(--recipe-field-border, #3d6501);
  border-radius: 6px;
}
/* The category selector must occupy actual page height on phones.
   Self-contained to avoid stale external CSS overriding mobile form layout. */
@media screen and (max-width: 760px) {
  body:not(.admin-site) .site-navigation-sticky > .site-header {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  body:not(.admin-site) .site-navigation-sticky > .site-header .header-layout {
    height: auto !important;
    grid-template-rows: auto auto;
  }
  body:not(.admin-site) .site-navigation-sticky > .site-header .header-controls {
    position: relative;
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 88px !important;
    max-height: none !important;
    overflow: visible !important;
    margin: 0 !important;
  }
  body:not(.admin-site) .site-navigation-sticky > .site-header .header-controls > form.search-box {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) 42px 42px;
    grid-template-rows: 40px 40px;
    grid-template-areas: "query submit ." "category category category";
    gap: 8px 7px;
    align-content: start;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 88px !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    flex: none !important;
  }
  body:not(.admin-site) .site-navigation-sticky .search-box > #recipe-search {
    grid-area: query !important;
    width: 100% !important;
    min-width: 0 !important;
    height: 40px !important;
    margin: 0 !important;
    font-size: 16px !important;
  }
  body:not(.admin-site) .site-navigation-sticky .search-box > .search-button {
    grid-area: submit !important;
    display: inline-flex !important;
    width: 42px !important;
    height: 40px !important;
    margin: 0 !important;
    padding: 0 !important;
    flex: none !important;
  }
  body:not(.admin-site) .site-navigation-sticky .search-box > .navbar-category-select {
    grid-area: category !important;
    display: block !important;
    visibility: visible !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 40px !important;
    min-height: 40px !important;
    max-height: 40px !important;
    box-sizing: border-box !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    line-height: 1.25 !important;
    margin: 0 !important;
    font-size: 16px !important;
  }
  body:not(.admin-site) .site-navigation-sticky .header-controls > .header-navbar {
    display: none !important;
  }
  body:not(.admin-site) .site-navigation-sticky .header-controls > .header-mobile-menu {
    display: block !important;
    position: absolute !important;
    top: 0;
    right: 0;
    width: 42px;
    height: 40px;
    margin: 0 !important;
    z-index: 1050;
  }
}
