/* ==========================================================================
   Header search and the New button

   The drop-down under the search box, the full-screen search on a phone, and
   the New button with its menu. Everything here is the header's own: the
   drop-down is not a .combo, whose list is placed by a component, and the
   New menu borrows .menu only for its items.
   ========================================================================== */

/* ---- The search drop-down ------------------------------------------------ */

/* Only on a phone, below. */
.topbar__search-open,
.topbar__search-close { display: none; }

/* Hung from the box, at least as wide as it and wide enough for a name, a
   line of detail and a figure, but never wider than the window. */
.search-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: var(--z-menu);
  width: max(100%, min(480px, calc(100vw - 24px)));
  max-height: min(540px, calc(100vh - 96px));
  max-height: min(540px, calc(100dvh - 96px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  animation: mkh-rise 0.16s var(--ease);
}
.search-panel[hidden] { display: none; }

.search-group + .search-group {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line-soft);
}

.search-group__head {
  padding: 7px 10px 5px;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--txt-3);
}

/* One line: what it is and who or what it concerns on the left, the figure
   on the right. The left column is the one that gives, and its text is cut
   short rather than wrapped, so every line is the same height. */
.search-hit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
  min-height: 42px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  color: var(--txt);
  cursor: pointer;
}
.search-hit:hover { text-decoration: none; }

/* The highlight follows the keyboard as well as the mouse, as a picker's
   does, so there is only ever one lit line. */
.search-hit.is-active { background: var(--surface-2); }
.search-hit:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-ring); }

.search-hit__main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.search-hit__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
}

.search-hit__meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-xs);
  color: var(--txt-3);
}

/* What it is, in words before the detail, so colour is never what says it. */
.search-hit__kind {
  margin-right: 6px;
  font-weight: var(--fw-semibold);
  color: var(--txt-2);
}

.search-hit__figure {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--txt-2);
}
.search-hit__figure-label {
  font-family: var(--font-sans);
  font-size: var(--fs-2xs);
  color: var(--txt-3);
}

.search-panel__state {
  margin: 0;
  padding: 12px 10px;
  font-size: var(--fs-sm);
  color: var(--txt-3);
}
.search-panel__state[hidden] { display: none; }

/* While the drop-down or the phone's search is open the header sits above a
   document's save bar, which would otherwise be drawn over the bottom of it. */
body[data-search] .topbar { z-index: var(--z-drawer); }

/* ---- Search on a phone ---------------------------------------------------

   A button in the header; pressed, the box opens over the whole screen with
   its results under it. The header is frosted with a backdrop filter, which
   makes it the box that a fixed child is placed in, so the filter is lifted
   while the search is open or the overlay would be the header's size. */
@media (max-width: 620px) {
  .topbar__search-open { display: grid; }
  .topbar__search { display: none; }

  body[data-search="open"] .topbar {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  body[data-search="open"] .topbar__search {
    position: fixed;
    inset: 0;
    z-index: var(--z-drawer);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    max-width: none;
    padding: 10px 14px 0;
    background: var(--surface);
  }
  body[data-search="open"] { overflow: hidden; }

  /* The box and its close button on one row, the results filling the rest. */
  body[data-search="open"] .topbar__search-close {
    display: grid;
    position: absolute;
    top: 10px;
    left: 14px;
  }
  body[data-search="open"] .topbar__search .field__icon { display: none; }
  body[data-search="open"] .topbar__search .input {
    flex: none;
    height: 42px;
    margin-left: 50px;
    width: calc(100% - 50px);
    padding-left: 14px;
    padding-right: 14px;
  }
  body[data-search="open"] .search-panel {
    position: static;
    width: auto;
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
    margin: 10px -14px 0;
    padding: 6px 8px 24px;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
    animation: none;
  }
}

/* Under a finger the box is 42 like every other box. */
@media (pointer: coarse) {
  .topbar__search .input { height: 42px; }
}

/* ---- New -------------------------------------------------------------- */

.newbtn { position: relative; display: flex; align-items: center; flex: none; }

.newbtn__toggle { gap: 6px; }
.newbtn__toggle svg { width: 16px; height: 16px; }
.newbtn__toggle .newbtn__chevron { width: 14px; height: 14px; margin-right: -3px; }

/* A split button on a list page: the page's own New, and an arrow joined to
   it for everything else. */
.newbtn--split .newbtn__main {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.newbtn--split .newbtn__toggle {
  width: 30px;
  padding: 0;
  justify-content: center;
  border-left-color: rgba(255, 255, 255, 0.28);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.newbtn--split .newbtn__plus,
.newbtn--split .newbtn__text { display: none; }
.newbtn--split .newbtn__toggle .newbtn__chevron { margin: 0; }

/* The page's own New is first in the menu only where the button beside the
   arrow is folded away. */
.newmenu__here { display: none; }

.newmenu { min-width: 236px; max-height: min(560px, calc(100dvh - 96px)); overflow-y: auto; }

/* Under a finger the button and the arrow are 42 high like every other box,
   and a menu item 42 to be hit. */
@media (pointer: coarse) {
  .newbtn .btn--sm { height: 42px; }
  .newbtn--split .newbtn__toggle { width: 42px; }
  .newmenu .menu__item { min-height: 42px; }
}

/* On the narrowest screens the header holds the menu, search, New, the bell,
   the theme and the account at 42 each; New becomes a single plus that opens
   the menu, with the page's own New at the top of it. The gaps close up and
   the account's chevron goes, which is what makes it fit at 320. */
@media (max-width: 480px) {
  .topbar { gap: 6px; }
  .topbar__actions { gap: 6px; }

  .newbtn__main { display: none; }
  .newbtn__toggle,
  .newbtn--split .newbtn__toggle {
    width: 38px;
    padding: 0;
    justify-content: center;
    border-radius: var(--r-sm);
  }
  .newbtn__toggle .newbtn__plus,
  .newbtn--split .newbtn__toggle .newbtn__plus { display: block; }
  .newbtn__text,
  .newbtn__toggle .newbtn__chevron { display: none; }
  .newmenu__here { display: flex; }
  .newmenu .menu__sep.newmenu__here { display: block; }

  .usermenu__trigger > svg { display: none; }

  /* Too near the middle for a menu hung from the button: it spans the header. */
  .newbtn { position: static; }
  .newmenu {
    left: 8px;
    right: 8px;
    max-width: none;
    top: calc(100% + 6px);
  }
}

@media (max-width: 480px) and (pointer: coarse) {
  .newbtn__toggle,
  .newbtn--split .newbtn__toggle { width: 42px; }
}
