/*
 * Global search. Loaded on every page by the layout: the header search box (left of the user name,
 * "Search or scan": one 228px box on the bar with the magnifier joined at its right end) and the
 * /search results grid. Tokens only.
 */

/* ------------------------------------------------------------ header box */

/* When the bar runs short of room the box gives way first (large flex-shrink), down to 80px. */
.header-search { position: relative; display: flex; align-self: center; flex: 0 100 auto; min-width: 138px; margin: 0 16px 0 auto; padding-left: 16px; }
.header-search + .user-menu { margin-left: 0; }
.header-search input {
  flex: 1 1 auto;
  width: 192px;
  min-width: 0;
  height: 36px;
  padding: 0 var(--space-3);
  font: inherit;
  font-size: var(--text-base);
  color: var(--color-topbar-text);
  background: var(--color-search-bg);
  border: 1px solid var(--color-search-border);
  border-right: 0;
  border-radius: var(--radius-control) 0 0 var(--radius-control);
  -webkit-appearance: none;
  appearance: none;
  transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.header-search input::placeholder { color: var(--color-search-placeholder); opacity: 1; }
.header-search input:focus { color: var(--color-text-input); background: var(--color-input-bg); border-color: var(--color-focus); outline: var(--focus-width) solid var(--color-topbar-text); outline-offset: 1px; }
.header-search input:focus::placeholder { color: var(--color-text-muted); }
.header-search button {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--color-topbar-text);
  background: var(--color-search-bg);
  border: 1px solid var(--color-search-border);
  border-left: 0;
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  cursor: pointer;
  transition: background-color var(--dur-1) var(--ease-out);
}
.header-search button:hover { background: var(--color-nav-hover-bg); }
.header-search button:focus-visible { outline: var(--focus-width) solid var(--color-topbar-text); outline-offset: -4px; }
/* The shortcut chip: at 1280px and up, hidden while the box is in use or holds a value, and under touch. */
.search-kbd {
  display: none;
  position: absolute;
  top: 50%;
  right: 44px;
  padding: 0 var(--space-1);
  font-family: inherit;
  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);
  transform: translateY(-50%);
  pointer-events: none;
}
@media screen and (min-width: 1280px) and (pointer: fine) {
  .header-search:not(:focus-within) > input:placeholder-shown ~ .search-kbd { display: var(--search-kbd-display); }
  .header-search:not(:focus-within) > input:placeholder-shown { padding-right: var(--search-kbd-room); text-overflow: ellipsis; }
}

/* With the full menu showing, below about 1060px only the magnifier stays (it opens /search). */
@media (max-width: 1059px) and (min-width: 981px) {
  .header-search { min-width: 0; }
  .header-search input { display: none; }
  .header-search button { border-left: 1px solid var(--color-search-border); border-radius: var(--radius-control); }
}
@media (max-width: 600px) {
  .header-search { min-width: 0; margin-right: 10px; }
  .header-search input { display: none; }
  .header-search button { width: 38px; border-left: 1px solid var(--color-search-border); border-radius: var(--radius-control); }
}
/* Touch: 16px text (app.css) in a 44px box, the magnifier matching it. */
@media screen and (max-width: 760px), screen and (pointer: coarse) {
  .header-search input, .header-search button { 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; }
}

/* ------------------------------------------------------------ search modal (search-live.js, desktop only) */

/* dialog.modal (app.css) gives the blue title bar, the close button and the backdrop. */
html.search-modal-open { overflow: hidden; }
dialog.modal.search-modal { width: 900px; height: 80vh; }
dialog.search-modal[open] { display: flex; flex-direction: column; }
.search-modal > .modal-header, .search-modal-form { flex: none; }
.search-modal-form { padding: 16px 30px; border-bottom: 1px solid var(--color-border); }
.search-modal .search-modal-input { display: block; width: 100%; height: 44px; padding: 8px 14px; font-size: 18px; line-height: 26px; }
.search-modal-body { flex: 1 1 auto; min-height: 0; padding: 0; overflow-y: auto; overscroll-behavior: contain; }
.search-modal-note { margin: 0; padding: 18px 30px; font-size: var(--text-base); color: var(--color-text-muted); }
.search-modal-note[hidden] { display: none; }
.search-suggest-list { transition: opacity var(--dur-1) var(--ease-out); }
.search-modal.is-busy .search-suggest-list { opacity: .5; }

.search-suggest-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 30px 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: 14px;
  padding: 8px 30px;
  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 30px 10px 80px; font-size: var(--text-sm); color: var(--color-link); }
.search-suggest-all { justify-content: center; padding: 12px 30px; 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-modal .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); }

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

@media screen and (max-width: 760px), screen and (pointer: coarse) {
  /* The box never shrinks past its 44px magnifier; the user name gives way instead (app.css). */
  .header-search { min-width: calc(16px + var(--touch-target)); }
  .header-search button { 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. */
@media screen and (max-width: 760px) {
  .header-search { min-width: calc(12px + var(--touch-target)); margin-right: 16px; padding-left: 12px; }
}

/* The search modal fills the screen and ends above the on-screen keyboard (--vvh). 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; }
  dialog.modal.search-modal {
    width: 100%;
    max-width: 100%;
    height: var(--vvh, 100dvh);
    max-height: var(--vvh, 100dvh);
    margin: 0;
    padding-bottom: 0;
  }
  dialog.modal.search-modal .search-modal-body { padding: 0; }
  .search-modal-form { padding: 10px 16px; }
  .search-modal-note { padding: 14px 16px; }
  .search-suggest-head { padding-right: 16px; padding-left: 16px; }
  .search-suggest-option { padding-right: 16px; padding-left: 16px; }
  .search-suggest-more { padding-right: 16px; padding-left: 66px; }
  .search-suggest-all { padding-right: 16px; padding-left: 16px; }
}

/* 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; }
}
