/* =====================================================================
   MENU ROW + SEARCH: the phone ☰ Menu button and the lesson search (phones and computers). Used by every new page.
   ===================================================================== */

/* =====================================================================
   PHONE MENU ROW + SEARCH  (this page only)
   [☰ Menu] [search] on the left, level box on the right.
   Hidden on computers; only active on phones held upright,
   the same screen size as the phone styles in styleHmenu.css.
   ===================================================================== */
/* ---------- COMPUTERS: magnifying glass on the right of the page, level with the menu bar;
   the field slides out to the left.
   The script moves the search inside the menu (#mainMenu) so it lines up with the bar,
   and sets --search-x so the glass sits 26px in from the right of the page
   (lined up with the right edge of the lesson content). ---------- */
@media (min-width: 769px), (orientation: landscape) {
  #mainMenu > .phone-search {
    position: absolute;
    top: 0;
    left: var(--search-x, calc(100% + 10px));   /* right side of the page (set by the script) */
    height: 100%;
    display: flex;
    align-items: center;
    z-index: 50;                        /* the Grammar mega menu (z-index 100) opens over it */
    text-align: left;
  }
  #mainMenu .search-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #1F2433;                     /* colour of the magnifying glass */
    cursor: pointer;
    transition: background 0.15s;
  }
  #mainMenu .search-toggle:hover,
  #mainMenu .search-toggle:focus-visible { background: #EEF0F4; outline: none; }
  #mainMenu .search-toggle svg { display: block; width: 24px; height: 24px; }

  #mainMenu .search-box {
    position: absolute;
    top: 50%;
    right: calc(100% + 6px);            /* ends just before the magnifying glass, grows to the left */
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    width: 0;
    height: 40px;
    margin: 0;
    overflow: hidden;
    background: #fff;
    border: 2px solid transparent;
    border-radius: 8px;
    box-sizing: border-box;
    opacity: 0;
    transition: width 0.25s ease, opacity 0.2s ease, border-color 0.2s;
  }
  #mainMenu .phone-search.is-open .search-box {
    width: 320px;
    opacity: 1;
    border-color: #1F2433;
  }
  #mainMenu .search-box input {
    flex: 1;
    min-width: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0 12px;
    border: 0;
    outline: none;
    background: transparent;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    font: 15px Arial, Helvetica, sans-serif;
    color: #1d2b3a;
  }
  #mainMenu .search-box input::-webkit-search-cancel-button { display: none; }
  #mainMenu .search-close {
    flex: 0 0 auto;
    height: 100%;
    margin: 0;
    padding: 0 12px;
    border: 0;
    background: transparent;
    box-shadow: none;
    color: #1F2433;
    font: bold 18px Arial, sans-serif;
    cursor: pointer;
  }

  #mainMenu .search-results {
    position: absolute;
    top: calc(50% + 26px);
    right: calc(100% + 6px);            /* lined up with the right end of the field */
    width: 420px;
    max-height: 60vh;
    overflow-y: auto;
    margin: 0;
    padding: 6px 0;
    list-style: none;
    background: #fff;
    border: 2px solid #1F2433;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  }
  #mainMenu .search-results[hidden] { display: none; }
  #mainMenu .search-results li { margin: 0; padding: 0; }
  #mainMenu .search-results a {
    display: block;
    padding: 10px 14px;
    color: #1d2b3a;
    background: #fff;
    text-decoration: none;
    white-space: normal;
    font: bold 14px Arial, Helvetica, sans-serif;
    border-bottom: 1px solid #E3E5EA;
  }
  #mainMenu .search-results li:last-child a { border-bottom: 0; }
  #mainMenu .search-results a:hover,
  #mainMenu .search-results a:focus { background: #EEF0F4; }
  #mainMenu .search-results .where { display: block; margin-top: 2px; font-weight: normal; font-size: 12px; color: #6a7787; }
  #mainMenu .search-results .none { padding: 10px 14px; font: 14px Arial, sans-serif; color: #6a7787; }
  #mainMenu .search-results .none a { display: inline; padding: 0; border: 0; background: none; text-decoration: underline; color: #1F2433; }
}

@media (max-width: 768px) and (orientation: portrait) {

  /* ---------- Menu row: [☰ Menu] [search] left, level box right, menu opens underneath ---------- */
  .page > .menuRow {
    justify-content: flex-start !important;
    position: relative !important;      /* the search field slides out inside this row */
  }
  .page > .menuRow .lesson-level {
    order: 3 !important;
    margin: 0 0 0 auto !important;      /* pushes the level box to the far right */
  }
  .page > .menuRow #mainMenu { order: 4 !important; }

  /* ---------- SEARCH: magnifying glass next to the menu button, field slides out to the right ---------- */
  .phone-search { order: 2; display: block !important; }
  .search-toggle {
    display: inline-flex !important;
    align-items: center;
    padding: 9px 6px !important;        /* finger-sized tap area */
    color: var(--fe-dark);              /* colour of the magnifying glass */
    cursor: pointer;
  }
  .search-toggle svg { display: block; width: 28px; height: 28px; }

  /* the field: zero width when closed; opens from the magnifying glass across to the
     right edge of the row (covers the level box, leaves the ☰ Menu button visible) */
  .search-box {
    position: absolute;
    top: 0;
    left: var(--search-left, 0px);      /* set by the script to where the glass sits */
    z-index: 300;
    display: flex;
    align-items: center;
    width: 0;
    height: 46px;
    margin: 0;
    overflow: hidden;
    background: #fff;
    border: 2px solid transparent;
    border-radius: 10px;
    box-sizing: border-box;
    opacity: 0;
    transition: width 0.25s ease, opacity 0.2s ease, border-color 0.2s;
  }
  .phone-search.is-open .search-box {
    width: calc(100% - var(--search-left, 0px) - var(--gutter));   /* stops at the content's right edge */
    opacity: 1;
    border-color: var(--fe-dark);
  }
  .search-box input {
    height: 100%;
    padding: 0 12px !important;
    font: 16px Arial, Helvetica, sans-serif;   /* 16px stops iPhones zooming in */
    color: #1d2b3a;
  }
  .search-box input::-webkit-search-cancel-button { display: none; }

  /* clear any general input / button styles from the rest of the site */
  .phone-search input,
  .phone-search button {
    -webkit-appearance: none;
    appearance: none;
    border: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    border-radius: 0 !important;
    outline: none;
    margin: 0 !important;
    width: auto;
  }
  .search-box input { flex: 1 !important; min-width: 0 !important; width: 100% !important; }

  .search-close {
    flex: 0 0 auto;
    padding: 0 14px !important;
    height: 100%;
    color: var(--fe-dark);
    font: bold 20px Arial, sans-serif;
    cursor: pointer;
  }

  /* the list of matching lessons under the row */
  .search-results {
    position: absolute;
    top: 52px; left: var(--gutter); right: var(--gutter);   /* same edges as the content */
    z-index: 300;
    max-height: 60vh;
    overflow-y: auto;
    margin: 0;
    padding: 6px 0;
    list-style: none;
    background: #fff;
    border: 2px solid var(--fe-dark);
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    text-align: left;
  }
  .search-results[hidden] { display: none; }
  .search-results li { margin: 0; padding: 0; background: none; line-height: 1.3; }
  .search-results a {
    display: block;
    padding: 10px 14px;
    color: #1d2b3a;
    text-decoration: none;
    font: bold 15px Arial, Helvetica, sans-serif;
    border-bottom: 1px solid var(--fe-light);
  }
  .search-results li:last-child a { border-bottom: 0; }
  .search-results a:active,
  .search-results a:focus { background: var(--fe-pale); }
  .search-results .where {                       /* grey "Grammar › Pronouns" line */
    display: block;
    margin-top: 2px;
    font-weight: normal;
    font-size: 12.5px;
    color: #6a7787;
  }
  .search-results .none { padding: 10px 14px; font: 15px Arial, sans-serif; color: #6a7787; }
  .search-results .none a { display: inline; padding: 0; border: 0; color: var(--fe-main); text-decoration: underline; font-weight: bold; }
}
