/* ══════════════════════════════════════════════
   HEADER SEARCH AS ONE OBJECT  (js/search-seek.js)
   ──────────────────────────────────────────────
   Ported from the Bencho "Search" (Seek) component, MIT licensed,
   https://bencho.dev/licence. A search icon that becomes a search
   field: a single box whose WIDTH is the state, with the lens and the
   field inside it the whole time. Two things swapping is never mistaken
   for one thing changing, however well the crossfade is tuned.

   Bencho's tokens, mapped onto the app theme (defined on .sek only, so
   nothing leaks out):
     --ink → --text      --ink-2 → --text    --ink-3 → --text2
     --ink-4 → --text3   --ink-5 → --text3   (the app has three inks, not five)
     --pane → --bg3      the same fill as the header's secondary buttons
     --pane-edge → --border
     --bg → --bg2        the header ground, for the focus ring's gap
     --font-ui → inherit (Inter, from body)
     --ink-rgb           three bare numbers of --text, per theme
     --g-blur / --g-sat  0 / 100%: the app is flat, there is no glass

   Desktop only. On a phone #gs-wrap is the full-screen search overlay
   (css/mobile.css, body.gs-mobile-open), so the bottom block keeps the
   plain field it always had.
══════════════════════════════════════════════ */
@media (min-width: 769px) {
  .sek {
    --ink: var(--text); --ink-2: var(--text); --ink-3: var(--text2);
    --ink-4: var(--text3); --ink-5: var(--text3);
    --ink-rgb: 15, 23, 42;
    --pane: var(--bg3); --pane-edge: var(--border); --sek-bg: var(--bg2);
    --g-blur: 0px; --g-sat: 100%;
    /* The frame is the shut circle and never changes size, so opening
       pushes nothing: the skin grows out of it to the left, over the
       header's empty middle, on its own layer. Its right edge stays
       pinned to the frame, which is what keeps the neighbours still. */
    position: relative;
    flex-shrink: 0;
    width: var(--shut);
    height: var(--shut);
    /* Above the page, below every dialog (z-index 1000+): at 1450 the
       closed circle showed on top of the dialogs' dimmed background. */
    z-index: 960;
    font-family: inherit;
  }
  body.dark-mode .sek { --ink-rgb: 236, 236, 236; }

  /* ── the object ───────────────────────────────────────────
     Width is the state. Height is fixed and the corner is one number at
     every width, so the SHAPE is one rule rather than a tween with two
     ends. Bencho's Corner knob runs 0..32 and the original sits fully
     round; here it is the app's own button corner, 9, so shut it is a
     rounded square beside the other buttons and open a rounded field. */
  .sek-skin {
    position: absolute;
    right: 0;
    top: 0;
    width: var(--w, var(--shut));
    height: var(--shut);
    border-radius: 9px;
    background: var(--pane);
    -webkit-backdrop-filter: blur(var(--g-blur)) saturate(var(--g-sat)) brightness(var(--g-bright, 100%));
    backdrop-filter: blur(var(--g-blur)) saturate(var(--g-sat)) brightness(var(--g-bright, 100%));
    isolation: isolate;
    /* the press and the hover share one transform: two transforms on one
       element is one of them winning. (Bencho also leans the object
       toward the pointer here; that was taken out on request.) */
    transform: scale(var(--sk, 1));
    transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1), background 220ms ease;
    /* the field is inside from the first frame; this keeps it from
       spilling out of the circle */
    overflow: hidden;
  }
  /* The edge. Bencho draws none unless asked; here it is on, because
     every other control in this header carries the same hairline. */
  .sek-skin::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 1px solid var(--pane-edge);
    pointer-events: none;
    z-index: 2;
  }
  .sek[data-open="true"] .sek-skin { background: var(--bg2); cursor: text; }
  .sek[data-open="true"] .sek-skin::before { border-color: var(--text3); }

  /* Hover: it comes up a hair. Small enough to be felt rather than seen;
     a hover state you notice is a hover state that has said too much. */
  .sek:not([data-open="true"]) .sek-skin:hover { --sk: 1.045; --g-bright: 104%; background: var(--bg2); }

  /* Pressed: it yields before it moves. A thing that gives under a click
     reads as having been pushed; a thing that only expands reads as
     having been triggered. :active is the button held down, data-press
     the 90ms beat after the click before it opens. Both come after the
     hover rule with the same :not(), so they win on order. */
  .sek:not([data-open="true"]) .sek-skin:active,
  .sek:not([data-open="true"])[data-press="true"] .sek-skin {
    --sk: 0.93;
    transition: transform 160ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  /* ── the lens ─────────────────────────────────────────────
     Fixed at the box's left inset and never animated. At the shut width
     that inset centres it, (36 - 16) / 2 = 10, and open it is the
     field's padding: one number doing two jobs that agree by
     construction. Because the right edge is pinned, the lens rides out
     with the left edge as the box grows. */
  .sek-lens {
    position: absolute;
    left: var(--inset);
    top: 50%;
    width: var(--lens);
    height: var(--lens);
    margin-top: calc(var(--lens) / -2);
    fill: none;
    stroke: var(--ink-3);
    /* 1.5 on an 18-unit viewBox is 0.0833 of the glyph, the same weight
       as lucide's 2 on 24. A 2 here would be a third heavier. */
    stroke-width: 1.5;
    stroke-linecap: round;
    pointer-events: none;
    transition: stroke 220ms ease, stroke-width 220ms ease;
  }
  .sek-skin:hover .sek-lens { stroke: var(--ink); }
  .sek[data-open="true"] .sek-lens { stroke: var(--ink-4); }
  /* typing: the lens thickens a hair and darkens, one beat per burst,
     not one per keystroke */
  .sek[data-busy="true"] .sek-lens { stroke: var(--ink-2); stroke-width: 1.8; }

  /* ── the field ────────────────────────────────────────────
     Present from the first frame and revealed by --say, the last stretch
     of the width's own progress. It slides a few pixels in from the
     left, so it reads as coming out of the lens rather than fading up
     where it stood. !important only to beat the old #gs-input rules. */
  .sek #gs-input {
    position: absolute;
    left: calc(var(--inset) + var(--lens) + 8px);
    right: 30px;
    top: 0;
    width: auto;
    height: 100%;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0;
    background: none !important;
    box-shadow: none !important;
    font: inherit;
    font-size: 13px;
    color: var(--ink);
    outline: none;
    text-overflow: ellipsis;
    opacity: var(--say, 0);
    transform: translateX(calc((1 - var(--say, 0)) * -6px));
    /* until it is most of the way open it is not a target: a caret
       placed in a 36px circle is a caret in the wrong place */
    pointer-events: none;
  }
  .sek[data-open="true"] #gs-input { pointer-events: auto; }
  .sek #gs-input::placeholder { color: var(--ink-5); text-overflow: ellipsis; }
  .sek #gs-clear { right: 6px !important; }
  .sek:not([data-open="true"]) #gs-clear { display: none !important; }

  /* the way in, while there is one */
  .sek-hit {
    position: absolute;
    inset: 0;
    border: 0;
    border-radius: inherit;
    background: none;
    cursor: pointer;
    padding: 0;
  }
  .sek[data-open="true"] .sek-hit { display: none; }
  .sek-hit:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--sek-bg), inset 0 0 0 4px rgba(var(--ink-rgb), 0.4);
  }

  /* Results hang from the pinned right edge, exactly as wide as the open
     field (--span, set by the JS) so the two read as one column... */
  .sek #gs-panel { top: calc(100% + 8px); right: 0; width: var(--span, 280px); transform-origin: top right; }
  /* ...and only once the box has finished growing (data-settled, from
     js/search-seek.js). Shutting drops it first, so the panel is gone
     before the box starts to fold. Outranks the [data-show] rule below. */
  .sek:not([data-settled="true"]) #gs-panel {
    opacity: 0;
    transform: translateY(-6px) scale(0.985);
    pointer-events: none;
  }
}

/* ── the results panel's way in and out ──────────────────────
   js/global-search.js keeps style.display as the on/off switch and sets
   data-show a frame after the panel is displayed, so this fade has a
   start; it hides the panel only after the fade out has run (180ms). In
   quick, out quicker: leaving should never hold anybody up. */
#gs-panel {
  opacity: 0;
  transform: translateY(-6px) scale(0.985);
  transition: opacity 110ms ease-in, transform 130ms ease-in;
  will-change: opacity, transform;
}
#gs-panel[data-show="true"] {
  opacity: 1;
  transform: none;
  transition: opacity 180ms ease-out, transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
}
#gs-panel:not([data-show="true"]) { pointer-events: none; }
@media (prefers-reduced-motion: reduce) {
  #gs-panel, #gs-panel[data-show="true"] { transition: none; transform: none; }
}

/* Phone: the overlay's plain field, as it looked before the port. */
@media (max-width: 768px), (orientation: landscape) and (pointer: coarse) and (max-height: 500px) {
  .sek-skin { position: relative; }
  .sek-lens { position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; margin-top: -8px;
    fill: none; stroke: var(--text3); stroke-width: 1.5; stroke-linecap: round; pointer-events: none; }
  .sek #gs-input { width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg2); color: var(--text); font-size: 12.5px; outline: none; }
  .sek-hit { display: none; }
  .sek #gs-panel { top: calc(100% + 6px); left: 0; right: 0; }
}
