/*
 * Global search. Loaded on every page by the layout: the header's Search/Help button (left of the user
 * name; it opens the sidebar, help.css), the live list in that sidebar (search-live.js) and the
 * /search results grid. Tokens only.
 */

/* ------------------------------------------------------------ header button */

/* Drawn like the 228px box it replaced, with the 16px gap before it inside the button, so the bar
   keeps its layout; when the bar runs short of room it gives way first (large flex-shrink). The hidden
   form.header-search beside it only carries the action for the wedge scan (app.js). */
:is(button, a).header-search {
  display: flex;
  align-self: center;
  flex: 0 100 auto;
  min-width: 138px;
  margin: 0 16px 0 auto;
  padding: 0 0 0 16px;
  font: inherit;
  color: var(--color-search-placeholder);
  background: none;
  border: 0;
  cursor: pointer;
}
.header-search + .user-menu { margin-left: 0; }
.header-search-box {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: var(--space-2);
  width: 228px;
  min-width: 0;
  height: 36px;
  padding: 0 var(--space-2) 0 10px;
  font-size: var(--text-base);
  line-height: 20px;
  background: var(--color-search-bg);
  border: 1px solid var(--color-search-border);
  border-radius: var(--radius-control);
  transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.header-search-box > .icon { flex: none; color: var(--color-topbar-text); }
.header-search-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-align: left; white-space: nowrap; text-overflow: ellipsis; }
:is(button, a).header-search:hover, .header-search[aria-expanded="true"] { color: var(--color-topbar-text); text-decoration: none; }
:is(button, a).header-search:hover > .header-search-box, .header-search[aria-expanded="true"] > .header-search-box { background: var(--color-nav-hover-bg); }
:is(button, a).header-search:focus-visible { outline: 0; }
:is(button, a).header-search:focus-visible > .header-search-box { outline: var(--focus-width) solid var(--color-topbar-text); outline-offset: 1px; }
/* The shortcut chip, at 1280px and up with a mouse (aria-keyshortcuts names it to a screen reader),
   while the button is wide enough for it beside the whole label. */
@media screen and (min-width: 1280px) and (pointer: fine) {
  button.header-search > .header-search-box { container-type: inline-size; }
  button.header-search > .header-search-box::after {
    content: "Ctrl Alt S";
    display: var(--search-kbd-display);
    flex: none;
    padding: 0 var(--space-1);
    font-size: var(--text-xs);
    font-weight: 500;
    line-height: 18px;
    white-space: nowrap;
    color: var(--color-search-placeholder);
    border: 1px solid var(--color-search-border);
    border-radius: var(--radius-chip);
  }
  @container (max-width: 179px) {
    button.header-search > .header-search-box::after { display: none; }
  }
}

/* With the full menu showing, below about 1060px only the magnifier stays; the button never shrinks
   past it. */
@media (max-width: 1059px) and (min-width: 981px) {
  :is(button, a).header-search { min-width: auto; }
  .header-search-box { flex: none; justify-content: center; width: 36px; padding: 0; }
  .header-search-label { display: none; }
}
@media (max-width: 600px) {
  :is(button, a).header-search { min-width: auto; margin-right: 10px; }
  .header-search-box { justify-content: center; width: 38px; padding: 0; }
  .header-search-label { display: none; }
}
/* Touch: a 44px box like the fields beside it. */
@media screen and (max-width: 760px), screen and (pointer: coarse) {
  .header-search-box { height: var(--touch-control-height); }
}

/* ------------------------------------------------------------ results page */

.search-page-form input[type="search"] { width: 760px; }
.search-hint { max-width: 760px; margin: 18px 0 0; font-size: var(--text-base); color: var(--color-text-muted); }
.search-hint kbd {
  display: inline-block;
  padding: 0 5px;
  font-size: var(--text-xs);
  line-height: 18px;
  color: var(--color-text);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-chip);
}

.search-summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 20px; margin: 22px 0 18px; font-size: var(--text-lg); color: var(--color-text); }
.search-summary strong { font-weight: 400; }

.search-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 30px 40px; align-items: start; }
.search-box { min-width: 0; overflow: hidden; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-panel); }
.search-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px 10px 20px;
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
}
.search-box-head h2 { margin: 0; overflow: hidden; font-size: var(--text-md); font-weight: 600; line-height: 28px; white-space: nowrap; text-overflow: ellipsis; color: var(--color-label); }
.search-box-count { flex: none; font-size: var(--text-sm); color: var(--color-text-muted); }

.search-rows { margin: 0; padding: 0; list-style: none; }
.search-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  min-height: 60px;
  padding: 10px 14px 10px 17px;
  border-bottom: 1px solid var(--color-border);
  box-shadow: inset var(--bar-width) 0 0 var(--tone, var(--color-th-bar));
}
.search-tile {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1;
  color: var(--color-text);
  background: color-mix(in srgb, var(--tone, var(--color-th-bar)) 14%, var(--color-surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone, var(--color-th-bar)) 50%, var(--color-surface));
  border-radius: var(--radius-control);
}
.search-ring { display: flex; flex: none; align-items: center; justify-content: center; width: 40px; height: 40px; }
.search-ring { flex-direction: column; }
.search-row-text { min-width: 0; overflow-wrap: break-word; }
.search-row-text a { font-size: var(--text-md); font-weight: 600; line-height: 22px; }
.search-row-sub { display: block; margin-top: 2px; font-size: 13px; line-height: 18px; color: var(--color-text-muted); }
/* Each part stays on one line unless it alone is wider than the box. */
.search-row-sub > span { display: inline-block; max-width: 100%; }
.search-row.is-muted .search-tile { opacity: .55; }
.search-row.is-muted .search-row-text a { color: var(--color-text-muted); }

.search-box-foot { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; padding: 10px 20px; font-size: var(--text-base); background: var(--color-surface-alt); }
.search-box-types { font-size: 13px; color: var(--color-text-muted); }
.search-none { margin: 24px 0 0; color: var(--color-text-muted); }

.tone-red { --tone: var(--module-people); }
.tone-cyan { --tone: var(--module-resources); }
.tone-teal { --tone: var(--state-draft); }
.tone-purple { --tone: var(--module-dashboard); }
.tone-blue { --tone: var(--color-primary); }
.tone-green { --tone: var(--color-create); }
.tone-orange { --tone: var(--color-warning); }
.tone-grey { --tone: var(--status-inactive); }
.tone-dark { --tone: var(--item-completed); }
.tone-state-enquiry { --tone: var(--state-enquiry); }
.tone-state-draft { --tone: var(--state-draft); }
.tone-state-quotation { --tone: var(--state-quotation); }
.tone-state-order { --tone: var(--state-order); }

@media (max-width: 1180px) {
  .search-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
}
@media (max-width: 720px) {
  .search-grid { grid-template-columns: minmax(0, 1fr); }
  .search-summary { font-size: 16px; }
}

/* ------------------------------------------------------------ live list (search-live.js, in the sidebar's .help-suggest) */

.search-suggest-note { margin: 0; padding: 14px var(--space-4); font-size: var(--text-base); color: var(--color-text-muted); }
.search-suggest-note[hidden] { display: none; }
.search-suggest-list { transition: opacity var(--dur-1) var(--ease-out); }
.is-busy > .search-suggest-list { opacity: .5; }

.search-suggest-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px var(--space-4) 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
  letter-spacing: var(--tracking-th);
  text-transform: uppercase;
  color: var(--color-label);
  background: var(--color-surface-alt);
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}
.search-suggest-group:first-child > .search-suggest-head { border-top: 0; }
.search-suggest-count { font-weight: 400; }
.search-suggest-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px var(--space-4);
  color: var(--color-text);
  text-decoration: none;
  cursor: pointer;
}
a.search-suggest-option:hover { color: var(--color-text); text-decoration: none; }
.search-suggest-pic { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 36px; height: 36px; overflow: hidden; }
.search-suggest-photo { background: var(--color-surface); }
.search-suggest-photo > img { width: 100%; height: 100%; object-fit: contain; }
.search-suggest-tile { font-size: var(--text-md); font-weight: 600; line-height: 1; color: var(--color-text); background: color-mix(in srgb, var(--tone, var(--color-th-bar)) 14%, var(--color-surface)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone, var(--color-th-bar)) 50%, var(--color-surface)); border-radius: var(--radius-control); }
.search-suggest-photo { border-radius: var(--radius-control); }
.search-suggest-text { display: flex; flex-direction: column; min-width: 0; }
.search-suggest-title, .search-suggest-sub { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.search-suggest-title { font-size: var(--text-base); font-weight: 500; line-height: 20px; }
.search-suggest-sub { font-size: 13px; line-height: 18px; color: var(--color-text-muted); }
.search-suggest-option.is-muted .search-suggest-title { color: var(--color-text-muted); }
.search-suggest-option.is-muted .search-suggest-pic { opacity: .55; }
.search-suggest-more { padding: 2px var(--space-4) 10px calc(var(--space-4) + 36px + var(--space-3)); font-size: var(--text-sm); color: var(--color-link); }
.search-suggest-all { justify-content: center; padding: 12px var(--space-4); font-size: var(--text-base); font-weight: 600; color: var(--color-link); border-top: 1px solid var(--color-border); }
a.search-suggest-more:hover, a.search-suggest-all:hover { color: var(--color-link); }
.search-suggest-option.is-active { color: var(--color-text); background: var(--color-accent-tint); outline: 1px solid var(--color-primary-strong); outline-offset: -1px; }
.search-suggest-option.is-active .search-suggest-title { color: inherit; }
.search-suggest-option.is-active .search-suggest-sub { color: var(--color-label); }

/* With the help assistant: pages, guide sections and the Ask row carry an icon tile in the record
   rows' rhythm. The Ask row is the primary-toned one; its question may take two lines. */
.search-suggest-glyph { color: var(--color-text-muted); }
.search-suggest-ask { --tone: var(--color-primary); border-top: 1px solid var(--color-border); }
.search-suggest-ask.is-first { border-top: 0; }
.search-suggest-ask .search-suggest-glyph { color: var(--color-primary-strong); }
.search-suggest-ask .search-suggest-title {
  display: -webkit-box;
  font-weight: 600;
  white-space: normal;
  overflow-wrap: anywhere;
  color: var(--color-link);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

/* ------------------------------------------------------------ compact and touch (docs/ARCHITECTURE.md 5.4) */

@media screen and (max-width: 760px), screen and (pointer: coarse) {
  /* The magnifier is 44px, and the button never shrinks past it (or past its whole label, 138px); the
     user name gives way instead (app.css). The sidebar it opens is the feedback: a tap highlight would
     linger over the phone sheet. */
  :is(button, a).header-search { -webkit-tap-highlight-color: transparent; }
  .header-search-box { min-width: var(--touch-target); }
  .search-kbd-hint { display: none; }
  .search-suggest-option { min-height: var(--touch-target); }
  .search-suggest-more, .search-suggest-all { display: flex; align-items: center; min-height: var(--touch-target); }
}

/* On a phone the theme toggle's 44px hit area, 6px wider each side than its 32px icon, stays 10px clear
   of the magnifier; the live list keeps the sheet's side gutter. */
@media screen and (max-width: 760px) {
  :is(button, a).header-search { margin-right: 16px; padding-left: 12px; }
  .search-suggest-note, .search-suggest-head, .search-suggest-option, .search-suggest-all { padding-right: var(--gutter); padding-left: var(--gutter); }
  .search-suggest-more { padding-right: var(--gutter); padding-left: calc(var(--gutter) + 36px + var(--space-3)); }
}

/* The results page's 760px box fits the width. */
@media screen and (max-width: 980px) {
  .search-page-form { flex: 1 1 100%; min-width: 0; }
  .search-page-form input[type="search"] { flex: 1 1 0; width: auto; min-width: 0; }
}

/* A People row's phone link keeps the sub line's size (.search-row-text a is the title's). */
.search-row-sub a.phone-link { font-size: inherit; line-height: inherit; }

/* A result's whole row opens it; the phone link in its sub line stays a separate target above that. */
@media screen and (max-width: 980px), screen and (pointer: coarse) {
  .search-row { position: relative; }
  .search-row-text > a::after { content: ""; position: absolute; inset: 0; }
  .search-row:active { background: var(--color-active-bg); }
  .search-row-sub a { position: relative; z-index: 1; }
  .search-row-sub a.phone-link { padding: 13px 0; margin: -13px 0; }
  .search-box-foot a { display: inline-block; padding: 12px 0; margin: -12px 0; }
}
