/* ===================================================================
   V1 Stage 2.2 — GLOBAL INTELLIGENCE SEARCH

   A results page, not a dashboard. The reader arrived with a question,
   so the page gives the answer the most room: the query stays editable
   at the top, the type filter is one row, and everything below is a
   single scannable column of results.

   Deliberately NO card grid. Results vary enormously in length and
   type; a grid would force them into equal boxes and make a
   three-word entity match look as substantial as a Critical event.
   A list lets each result be exactly as big as it is.

   Uses the Stage 1/2.1 shared primitives -- .v2-tabs, .empty-state,
   .btn, .sig-badge -- rather than restyling them. This page is the
   first consumer of .v2-tabs, which is why the tab row here needs no
   CSS of its own beyond the count chip.
   =================================================================== */

.search-page {
  max-width: 860px;      /* Result text is READ, so it gets a measure. */
  margin: 0 auto;
}

/* --- Header ------------------------------------------------------- */

.search-header { margin-bottom: var(--sp-7); }

.search-eyebrow {
  margin: 0 0 var(--sp-4);
  font-family: var(--font-ui);
  font-size: var(--fs-label);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* The query stays EDITABLE rather than becoming a heading. Searching is
   iterative -- the second query is usually a refinement of the first --
   so the fastest path back is the field the reader already typed into,
   pre-filled and ready to amend. */
.search-form {
  display: flex;
  gap: var(--sp-4);
  align-items: stretch;
}

.search-form-input {
  flex: 1 1 auto;
  min-width: 0;          /* Flex items default to min-width:auto, which
                            makes a long value push the button off. */
  padding: var(--sp-5) var(--sp-6);
  background: var(--surface-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: var(--fs-section);
  line-height: 1.3;
}
.search-form-input::placeholder {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
}
.search-form-input:focus {
  outline: 2px solid var(--accent-primary);
  outline-offset: -1px;
  border-color: var(--accent-primary);
}
/* The browser's own clear affordance is a dark glyph on a dark ground. */
.search-form-input::-webkit-search-cancel-button { filter: invert(1) opacity(0.55); }

.search-result-count {
  margin: var(--sp-5) 0 0;
  color: var(--text-secondary);
  font-size: var(--fs-meta);
}
.search-result-count .num {
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
}

/* A count riding inside a .v2-tab, matching the existing
   .events-view-tab-count / .review-status-tab-count treatment. */
.v2-tab-count {
  padding: 0 var(--sp-3);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.v2-tab.is-active .v2-tab-count { color: var(--text-secondary); }

/* --- Results ------------------------------------------------------ */

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.search-result {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-7) 0;
  border-bottom: 1px solid var(--border-subtle);
}
.search-result:first-child { padding-top: var(--sp-2); }
.search-result:last-child { border-bottom: none; }

.search-result-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-4);
}

/* The type chip. Four channels, one per searchable record type, so a
   reader scanning a mixed result list can tell at a glance whether a hit
   is an event, a raw signal, a developing situation or an entity --
   which is the single thing that changes how much weight to give it.
   Outlined rather than filled: these mark a kind, not a severity, and
   must never compete with the significance badge beside them. */
.search-type-chip {
  display: inline-block;
  padding: 2px var(--sp-3);
  border: 1px solid currentColor;
  border-radius: var(--radius-xs);
  font-family: var(--font-ui);
  font-size: var(--fs-micro);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.6;
}
.search-type-event     { color: var(--provenance-fact); }
.search-type-signal    { color: var(--text-muted); }
.search-type-situation { color: var(--provenance-synthesis); }
.search-type-entity    { color: var(--provenance-metric); }

.search-result-date {
  color: var(--text-muted);
  font-size: var(--fs-caption);
  font-variant-numeric: tabular-nums;
}

.search-result-title {
  font-family: var(--font-display);
  font-size: var(--fs-card-title);
  font-weight: var(--fw-semibold);
  line-height: 1.35;
  color: var(--text-primary);
  text-decoration: none;
  text-wrap: balance;
}
.search-result-title:hover { color: var(--accent-primary); }
.search-result-title:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
}

.search-result-excerpt {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--fs-meta);
  line-height: 1.6;
}

/* The matched terms. Underlined as well as coloured -- a highlight
   carried by colour alone disappears for a reader who cannot separate
   the gold from the surrounding text. */
.search-result-excerpt mark {
  background: transparent;
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
  text-decoration: underline;
  text-decoration-color: var(--accent-primary);
  text-underline-offset: 3px;
}

/* --- Pagination --------------------------------------------------- */

.search-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-5);
  margin-top: var(--sp-8);
  padding-top: var(--sp-7);
  border-top: 1px solid var(--border-default);
}
.search-pagination-position {
  color: var(--text-muted);
  font-size: var(--fs-meta);
  font-variant-numeric: tabular-nums;
}

/* --- V1 completion: the four filters ------------------------------ */

/* The disclosure spans the full form row beneath the input and button,
   so opening it pushes results down rather than overlaying them. No
   JavaScript is involved: <details> is the same element nine other
   ProcIntel pages already use for progressive disclosure. */
/* The form row must WRAP so the disclosure drops onto its own line.
   Without this the form stays one flex line, and `align-items: stretch`
   stretched the search box and button to the full height of the open
   filter panel -- found by opening it in a real browser, not by a test. */
.search-form { flex-wrap: wrap; }
/* ...and once it wraps, the input must not claim the whole first line
   and push the Search button onto a line of its own. A zero basis lets
   it grow into whatever the button leaves. */
.search-form > .search-form-input { flex-basis: 0; }
.search-filters {
  flex-basis: 100%;
  margin-top: var(--sp-4);
}
.search-filters-summary {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--fs-meta);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.02em;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.search-filters-summary:hover { color: var(--text-primary); }
.search-filters-summary:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}
.search-filters-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 var(--sp-2);
  background: var(--accent-primary);
  color: var(--surface-base);
  border-radius: var(--radius-pill);
  font-size: var(--fs-micro);
  font-variant-numeric: tabular-nums;
}

/* Grid, not per-control margins: siblings are spaced by gap so nothing
   collapses or doubles when a control is conditionally absent. */
.search-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: var(--sp-4);
  margin-top: var(--sp-4);
  padding: var(--sp-5);
  background: var(--surface-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}
.search-filter { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.search-filter > label {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--fs-meta);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.search-filter > select {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-base);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--fs-body);
}
.search-filter > select:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 1px;
}
.search-filter-note {
  margin: var(--sp-4) 0 var(--sp-4);
  color: var(--text-muted);
  font-size: var(--fs-meta);
  max-width: 62ch;
}

/* --- Active filter chips ------------------------------------------ */

.search-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}
.search-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--surface-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  font-size: var(--fs-meta);
  text-decoration: none;
}
.search-chip:hover { border-color: var(--accent-primary); }
.search-chip:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}
.search-chip-x { color: var(--text-muted); font-size: 1.05em; line-height: 1; }
.search-chip-clear { color: var(--text-muted); }

/* The explanation of why a whole result type is absent. Stated in
   words, never signalled by a colour or an empty tab alone. */
.search-excluded-note {
  margin: var(--sp-4) 0 0;
  color: var(--text-muted);
  font-size: var(--fs-meta);
  max-width: 72ch;
}
.search-excluded-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin: var(--sp-2) 0 0;
  padding: 0;
  list-style: none;
}
.search-excluded-list strong {
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
}

@media (max-width: 639.98px) {
  .search-form { flex-direction: column; }
  .search-form-input { font-size: var(--fs-card-title); }
  .search-filter-grid { grid-template-columns: 1fr; }
}
