/* =============================================================================
   IzeChat — Modern mobile search overlay (isolated, additive)
   -----------------------------------------------------------------------------
   Problem it fixes: on phones the header search opened as a see-through panel
   with no visible input (you couldn't tell what you were typing) and the feed
   bled through behind the results (see bug report). This turns the header search
   into a self-contained, full-screen search — Facebook / Twitter grade — with a
   solid surface, a prominent pill input that clearly shows your query, and clean
   Trending / Recent / Results sections.

   Scope: ONLY `.tag_header .search-container.show` at <=768px. Desktop and the
   AJAX search logic (Wo_GetRecentSearchs / Wo_SearchResult) are untouched — this
   is pure presentation over the existing markup. `.show` is toggled by the search
   handler in container.phtml (#38). Safe areas use the native --ize-safe-* vars
   with an env() fallback, so the overlay clears the status + navigation bars.
   ========================================================================== */

@media (max-width: 768px) {

  /* The auto-hide top bar sets will-change:transform on the nav, which makes it a
     containing block for position:fixed descendants — that would pin this overlay
     to the ~56px nav instead of the viewport. Neutralise it while search is open so
     the overlay reliably fills the screen (needs :has(), fine on modern WebView). */
  nav.navbar.navbar-default:has(.search-container.show) { will-change: auto !important; transform: none !important; }

  /* ---- Overlay shell -------------------------------------------------------
     The whole search-container becomes a fixed, solid, full-screen surface laid
     out as a column: [search header] on top, [scrolling results] filling the
     rest. z-index sits above both system-styled bars and the header. */
  .tag_header .search-container.show {
    position: fixed !important;
    top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    width: 100% !important; max-width: none !important;
    margin: 0 !important; padding: 0 !important;
    z-index: 3000 !important;
    background: var(--body-bg, #fff) !important;
    display: flex !important;
    flex-direction: column !important;
    animation: izeSearchIn .18s cubic-bezier(.2,.7,.3,1) both;
  }
  @keyframes izeSearchIn { from { opacity: 0; } to { opacity: 1; } }

  /* Keep the floating AI button (and its panel) from hovering over the search. */
  html:has(.tag_header .search-container.show) #ize-ai-fab,
  html:has(.tag_header .search-container.show) #ize-ai-panel { display: none !important; }

  /* ---- Search header (the <form> is repurposed as the top bar) ------------- */
  .tag_header .search-container.show > form {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    flex: 0 0 auto !important;
    width: 100% !important; min-width: 0 !important;
    height: auto !important;
    margin: 0 !important;
    /* room on the left for the absolutely-placed back arrow; top pads the notch */
    padding: calc(var(--ize-safe-top, env(safe-area-inset-top, 0px)) + 8px) 12px 8px 52px !important;
    background: var(--header-background, #fff) !important;
    border: 0 !important;
    border-bottom: 1px solid rgba(0, 0, 0, .07) !important;
    border-radius: 0 !important;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .05) !important;
    float: none !important;
    overflow: visible !important;
    transition: none !important;
  }

  /* The theme's inline magnifier <svg> is replaced by a background icon on the
     pill (below), so hide it here to avoid a duplicate. */
  .tag_header .search-container.show > form > svg { display: none !important; }

  /* The pill input — the star of the show: big, legible, shows the query. */
  .tag_header .search-container.show .search-input {
    flex: 1 1 auto !important;
    width: 100% !important;
    height: 44px !important;
    line-height: 44px !important;
    border-radius: 22px !important;
    border: 1px solid transparent !important;
    background: rgba(0, 0, 0, .055)
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%238a8a8a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E")
      no-repeat 15px center !important;
    background-size: 20px 20px !important;
    padding: 0 16px 0 46px !important;
    /* >=16px keeps mobile browsers from zooming on focus, and reads cleanly */
    font-size: 16px !important;
    color: var(--header-color, #111) !important;
    -webkit-appearance: none; appearance: none;
    transition: background-color .15s ease, border-color .15s ease !important;
  }
  .tag_header .search-container.show .search-input:focus {
    outline: none !important;
    background-color: rgba(0, 0, 0, .03) !important;
    border-color: rgba(var(--main-rgb, 10, 114, 175), .5) !important;
  }
  .tag_header .search-container.show .search-input::placeholder {
    color: rgba(0, 0, 0, .42) !important; opacity: 1 !important;
  }
  /* Hide the ugly native "X" on WebKit; the back arrow clears + closes. */
  .tag_header .search-container.show .search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

  /* Back arrow, pinned to the header's left, vertically centred on the pill. */
  .tag_header .search-container.show .tag_toggle_search {
    display: flex !important;
    align-items: center; justify-content: center;
    position: absolute !important;
    left: 6px !important;
    top: calc(var(--ize-safe-top, env(safe-area-inset-top, 0px)) + 8px) !important;
    width: 42px !important; height: 44px !important;
    margin: 0 !important; padding: 0 !important;
    background: transparent !important;
    border: 0 !important; border-radius: 50% !important;
    color: var(--header-color, #333) !important;
    z-index: 3 !important;
    -webkit-tap-highlight-color: transparent;
  }
  .tag_header .search-container.show .tag_toggle_search:active { background: rgba(0, 0, 0, .06) !important; }
  .tag_header .search-container.show .tag_toggle_search svg { width: 24px !important; height: 24px !important; }

  /* ---- Results body -------------------------------------------------------- */
  .tag_header .search-container.show .dropdown-menu {
    position: relative !important;
    top: auto !important; left: auto !important; right: auto !important; bottom: auto !important;
    width: 100% !important; min-width: 0 !important;
    height: auto !important; max-height: none !important;
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
    margin: 0 !important;
    padding: 10px 14px calc(var(--ize-safe-bottom, env(safe-area-inset-bottom, 0px)) + 20px) !important;
    background: var(--body-bg, #fff) !important;
    border: 0 !important; border-radius: 0 !important; box-shadow: none !important;
  }

  /* Trending hashtags → a labelled chip cloud (kills the theme's pill wrapper
     and per-link underline pseudo-elements). */
  .tag_header .search-container.show .wow_htag { background: transparent !important; padding: 6px 2px 2px !important; margin: 2px 0 10px !important; border-radius: 0 !important; }
  .tag_header .search-container.show .wow_htag:before { display: none !important; }
  .tag_header .search-container.show .wow_htag:not(:empty)::after {
    content: "Trending";
    display: block; order: -1; width: 100%;
    font-size: 12px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
    color: rgba(0, 0, 0, .45); margin: 0 4px 10px;
  }
  .tag_header .search-container.show .wow_htag:not(:empty) { display: flex !important; flex-wrap: wrap; align-items: center; }
  .tag_header .search-container.show .wow_htag a {
    display: inline-flex; align-items: center;
    background: rgba(var(--main-rgb, 10, 114, 175), .10);
    color: var(--main);
    border-radius: 20px;
    padding: 8px 15px !important;
    margin: 0 8px 8px 0 !important;
    font-size: 14px; font-weight: 600;
    transition: background-color .15s ease, transform .12s ease;
  }
  .tag_header .search-container.show .wow_htag a:before { display: none !important; }
  .tag_header .search-container.show .wow_htag a:active { transform: scale(.95); background: rgba(var(--main-rgb, 10, 114, 175), .18); }

  /* "Recent" header row (label + Clear). */
  .tag_header .search-container.show .search-dropdown-result { max-height: none !important; overflow: visible !important; }
  .tag_header .search-container.show .tag_srch_recent { margin: 2px 0 0 !important; }
  .tag_header .search-container.show .recent {
    display: flex !important; align-items: center; justify-content: space-between;
    padding: 4px 4px 6px !important; margin: 0 !important;
  }
  .tag_header .search-container.show .recent-searches {
    font-size: 12px !important; font-weight: 700 !important; letter-spacing: .6px;
    text-transform: uppercase; color: rgba(0, 0, 0, .45) !important;
  }
  .tag_header .search-container.show .recent .btn {
    color: var(--main) !important; font-weight: 600 !important; min-width: 0 !important;
    padding: 4px 8px !important; background: transparent !important; box-shadow: none !important;
  }

  /* Result rows (people / pages / groups) — clean, tappable, avatar-led. */
  .tag_header .search-container.show .search-dropdown-result a.valign {
    display: flex !important; align-items: center;
    padding: 10px 8px !important; margin: 1px 0 !important;
    border-radius: 12px !important;
  }
  .tag_header .search-container.show .search-dropdown-result a.valign:active { background: rgba(0, 0, 0, .05) !important; }
  .tag_header .search-container.show .search-user-avatar { width: 46px !important; min-width: 46px !important; height: 46px !important; margin-right: 13px !important; }
  .tag_header .search-container.show .search-user-name { font-size: 15.5px !important; font-weight: 600 !important; }
  .tag_header .search-container.show .search-user-lastseen { font-size: 12.5px !important; opacity: .6 !important; }

  /* Advanced-search entry + empty state. */
  .tag_header .search-container.show .search-advanced-container a { border-radius: 12px !important; padding: 11px 8px !important; }
  .tag_header .search-container.show .empty_state { padding: 54px 20px !important; }

  /* Skeleton rows inherit the same rhythm while results load. */
  .tag_header .search-container.show .skel_search { padding: 10px 8px !important; margin: 1px 0 !important; }

  @media (prefers-reduced-motion: reduce) {
    .tag_header .search-container.show { animation: none; }
  }
}

/* ---- Dark mode ------------------------------------------------------------
   WoWonder signals dark by injecting <link id="night-mode-css">; key off it (and
   the app's own html.ize-dark) so the overlay is correct on first paint. */
@media (max-width: 768px) {
  html:has(#night-mode-css) .tag_header .search-container.show,
  html.ize-dark .tag_header .search-container.show { background: var(--body-bg, #18191a) !important; }

  html:has(#night-mode-css) .tag_header .search-container.show > form,
  html.ize-dark .tag_header .search-container.show > form {
    background: var(--header-background, #242526) !important;
    border-bottom-color: rgba(255, 255, 255, .08) !important;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .3) !important;
  }
  html:has(#night-mode-css) .tag_header .search-container.show .dropdown-menu,
  html.ize-dark .tag_header .search-container.show .dropdown-menu { background: var(--body-bg, #18191a) !important; }

  html:has(#night-mode-css) .tag_header .search-container.show .search-input,
  html.ize-dark .tag_header .search-container.show .search-input {
    background-color: rgba(255, 255, 255, .09) !important;
    color: #e4e6eb !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23aaaaaa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") !important;
  }
  html:has(#night-mode-css) .tag_header .search-container.show .search-input:focus,
  html.ize-dark .tag_header .search-container.show .search-input:focus { background-color: rgba(255, 255, 255, .05) !important; }
  html:has(#night-mode-css) .tag_header .search-container.show .search-input::placeholder,
  html.ize-dark .tag_header .search-container.show .search-input::placeholder { color: rgba(255, 255, 255, .42) !important; }

  html:has(#night-mode-css) .tag_header .search-container.show .tag_toggle_search,
  html.ize-dark .tag_header .search-container.show .tag_toggle_search { color: #e4e6eb !important; }
  html:has(#night-mode-css) .tag_header .search-container.show .tag_toggle_search:active { background: rgba(255, 255, 255, .08) !important; }

  html:has(#night-mode-css) .tag_header .search-container.show .wow_htag:not(:empty)::after,
  html:has(#night-mode-css) .tag_header .search-container.show .recent-searches,
  html.ize-dark .tag_header .search-container.show .wow_htag:not(:empty)::after,
  html.ize-dark .tag_header .search-container.show .recent-searches { color: rgba(255, 255, 255, .5) !important; }

  html:has(#night-mode-css) .tag_header .search-container.show .search-dropdown-result a.valign:active,
  html.ize-dark .tag_header .search-container.show .search-dropdown-result a.valign:active { background: rgba(255, 255, 255, .06) !important; }
}
