/* Search V2 — faceted search with a place-relationship hero at the top.
   The sidebar facet rail is gone: the hero carries keyword + an initiator→receiver
   place dyad (direction + per-side OR) + a scope/refine row. Design tokens come
   from colors_and_type.css + dataroom-shared.css (loaded first in dataroom_base.html).
   The .row/.rows/.mk/.bd/.rt result-row classes live in dataroom-shared.css. */

.search-page {
  flex: 1 1 auto; max-width: 78rem; width: 100%; margin: 0 auto;
  padding: var(--space-8) clamp(1.25rem, 4vw, 2.75rem) var(--space-12);
  display: flex; flex-direction: column; gap: var(--space-8);
}
/* the hero toggles popovers/badges via the `hidden` attribute; component rules
   set display, so force `hidden` to win across the whole page. */
.search-page [hidden] { display: none !important; }

/* ───────── HERO ───────── */
.search-hero {
  display: flex; flex-direction: column; gap: var(--space-5);
  background: var(--color-linen);
  border: 1px solid var(--color-oatmeal);
  border-radius: var(--radius-lg);
  padding: clamp(1.1rem, 2.4vw, 1.75rem);
}

/* keyword bar */
.tb-kwbar {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  background: #fff; border: 1px solid var(--color-oatmeal); border-radius: var(--radius-md);
  padding: 13px 16px; cursor: text;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.tb-kwbar:focus-within { border-color: var(--color-navy); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-navy) 12%, transparent); }
.tb-kwbar > i { font-size: 21px; color: var(--color-stone); flex: none; }
.tb-kwbar input { flex: 1; min-width: 0; border: none; outline: none; background: none; font-family: var(--font-ui); font-size: var(--text-md); color: var(--color-charcoal); }
.tb-kwbar input::placeholder { color: var(--color-stone); opacity: 0.7; }
.tb-kwbar input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.tb-kwbar kbd { flex: none; font-family: var(--font-mono); font-size: 11px; line-height: 1; color: var(--color-stone); background: var(--color-linen); border: 1px solid var(--color-oatmeal); border-bottom-width: 2px; border-radius: var(--radius-sm); padding: 4px 8px; }
.tb-kwbar:focus-within kbd { display: none; }

/* "or analyse a relationship" divider */
.tb-or { display: flex; align-items: center; gap: var(--space-3); }
.tb-or > span:first-child { font-family: var(--font-ui); font-size: 11px; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-stone); white-space: nowrap; }
.tb-or-line { flex: 1; height: 1px; background: var(--color-oatmeal); }

/* relationship band */
.tb-band { display: flex; flex-direction: column; gap: var(--space-3); }
.tb-row { display: flex; align-items: stretch; gap: var(--space-3); flex-wrap: wrap; }

.tb-field {
  position: relative; flex: 1 1 220px; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  background: #fff; border: 1px solid var(--color-oatmeal); border-radius: var(--radius-md);
  padding: 9px 12px; transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.tb-field:focus-within, .tb-field.open { border-color: var(--color-navy); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-navy) 10%, transparent); }
.dfi-ic { font-size: 18px; color: var(--color-stone); flex: none; }
.dfi-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; background: none; border: none; padding: 0; cursor: pointer; text-align: left; }
.dfi-lab { font-size: 10px; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-stone); }
.dfi-val { font-family: var(--font-ui); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-charcoal); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dfi-val.is-empty { font-weight: var(--weight-regular); color: var(--color-stone); }
.dfi-caret { font-size: 13px; color: var(--color-stone); flex: none; }

/* swap button between the two place fields */
.dswap {
  flex: none; align-self: center; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; background: #fff; color: var(--color-navy);
  border: 1px solid var(--color-oatmeal); border-radius: var(--radius-pill); cursor: pointer;
  transition: background var(--transition-base), border-color var(--transition-base), transform var(--transition-base);
}
.dswap:hover { background: var(--color-slate-pale); border-color: var(--color-navy); }
.dswap:active { transform: scale(0.92); }
.dswap i { font-size: 16px; }

/* picker popover (searchable checklist under a field) */
.dpk {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  width: max(100%, 260px); max-height: 320px; display: flex; flex-direction: column;
  background: #fff; border: 1px solid var(--color-oatmeal); border-radius: var(--radius-md);
  box-shadow: var(--shadow-overlay); overflow: hidden;
}
.dpk-search { display: flex; align-items: center; gap: 8px; padding: 9px 11px; border-bottom: 1px solid var(--color-ecru); flex: none; }
.dpk-search i { font-size: 15px; color: var(--color-stone); }
.dpk-search input { flex: 1; min-width: 0; border: none; outline: none; background: none; font-family: var(--font-ui); font-size: var(--text-sm); color: var(--color-charcoal); }
.dpk-list { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: var(--space-2); }
.dpk-grp + .dpk-grp { margin-top: var(--space-2); border-top: 1px solid var(--color-ecru); padding-top: var(--space-2); }
.dpk-gl { font-size: 10px; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-stone); padding: 2px 6px 4px; }

/* shared checklist row (picker + refine) */
.dchk { display: flex; align-items: center; gap: var(--space-2); padding: 6px 7px; border-radius: var(--radius-sm); cursor: pointer; transition: background var(--transition-base); }
.dchk:hover { background: var(--color-linen); }
.dchk input { appearance: none; -webkit-appearance: none; width: 15px; height: 15px; flex: none; border: 1px solid var(--color-oatmeal); border-radius: 3px; background: #fff; position: relative; cursor: pointer; transition: background var(--transition-base), border-color var(--transition-base); }
.dchk input:checked { background: var(--color-navy); border-color: var(--color-navy); }
.dchk input:checked::after { content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.dchk span { flex: 1 1 auto; font-size: var(--text-sm); color: var(--color-charcoal); min-width: 0; }

/* segmented control (direction · record) */
.dseg { display: inline-flex; align-items: stretch; gap: 2px; background: #fff; border: 1px solid var(--color-oatmeal); border-radius: var(--radius-pill); padding: 3px; }
.dseg button { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-ui); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-stone); background: none; border: none; border-radius: var(--radius-pill); padding: 6px 13px; cursor: pointer; white-space: nowrap; transition: background var(--transition-base), color var(--transition-base); }
.dseg button i { font-size: 15px; }
.dseg button:hover { color: var(--color-charcoal); }
.dseg button[aria-pressed="true"] { background: var(--color-navy); color: #fff; }

.tb-second { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.tb-count { font-family: var(--font-ui); font-size: var(--text-sm); color: var(--color-stone); }
.tb-count b { font-weight: var(--weight-semibold); color: var(--color-charcoal); font-variant-numeric: tabular-nums; }
.tb-rc { color: var(--color-oatmeal); }

/* ───────── SCOPE / REFINE ROW ───────── */
.tb-scope { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; padding-top: var(--space-4); border-top: 1px solid var(--color-oatmeal); }
.tb-scope-l { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.tb-scope-r { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

/* date scope — year range (primary) + exact-dates popover (refinement) */
.tb-scope-l .tb-time, .tb-scope-l .tb-refine-btn, .tb-scope .tb-record { height: 38px; box-sizing: border-box; }
.tb-time { display: inline-flex; align-items: stretch; background: #fff; border: 1px solid var(--color-oatmeal); border-radius: var(--radius-md); }
.tb-years { display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; }
.tb-years > i { font-size: 16px; color: var(--color-stone); }
.tb-yl { font-size: 9.5px; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-stone); }
.tb-ysel { appearance: none; -webkit-appearance: none; font-family: var(--font-mono); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-charcoal);
  background-color: var(--color-linen);
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none' stroke='%23837E75' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
  border: 1px solid var(--color-oatmeal); border-radius: var(--radius-sm); padding: 5px 24px 5px 9px; cursor: pointer;
  transition: border-color var(--transition-base), background-color var(--transition-base); }
.tb-ysel:hover { border-color: var(--color-stone); background-color: var(--color-ecru); }
.tb-ysel:focus { outline: none; border-color: var(--color-navy); }
.tb-yd { color: var(--color-oatmeal); font-family: var(--font-mono); }
.tb-dclear { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; border: none; background: none; color: var(--color-stone); cursor: pointer; border-radius: 50%; }
.tb-dclear:hover { color: var(--color-eurepoc-red); background: var(--color-linen); }
.tb-dclear i { font-size: 13px; }
.tb-time.exact .tb-years { opacity: 0.4; }
.tb-exact-wrap { position: relative; display: inline-flex; }
.tb-exact { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-ui); font-size: var(--text-sm); color: var(--color-stone); background: none; border: none; border-left: 1px solid var(--color-ecru); padding: 6px 13px; cursor: pointer; border-radius: 0 var(--radius-md) var(--radius-md) 0; transition: color var(--transition-base), background var(--transition-base); }
.tb-exact:hover { color: var(--color-navy); background: var(--color-linen); }
.tb-exact i { font-size: 14px; }
.tb-exact.on { color: var(--color-navy); background: var(--color-slate-pale); font-weight: var(--weight-medium); }
.tb-exact-pop { position: absolute; top: calc(100% + 8px); left: 0; z-index: 60; width: 232px; background: #fff; border: 1px solid var(--color-oatmeal); border-radius: var(--radius-md); box-shadow: var(--shadow-overlay); padding: 13px; display: flex; flex-direction: column; gap: 9px; }
.tep-h { font-size: 12px; font-weight: var(--weight-semibold); color: var(--color-charcoal); display: flex; flex-direction: column; gap: 1px; }
.tep-h span { font-size: 10.5px; font-weight: var(--weight-regular); color: var(--color-stone); font-style: italic; }
.tep-row { display: grid; grid-template-columns: 38px 1fr; align-items: center; gap: 8px; }
.tep-row span { font-size: 10px; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-stone); }
.tep-row input[type="date"] { font-family: var(--font-ui); font-size: var(--text-sm); color: var(--color-charcoal); background: var(--color-linen); border: 1px solid var(--color-oatmeal); border-radius: var(--radius-sm); padding: 6px 8px; cursor: pointer; }
.tep-row input[type="date"]:focus { outline: none; border-color: var(--color-navy); }
.tep-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 8px; border-top: 1px solid var(--color-ecru); }
.tep-clear { font-family: var(--font-ui); font-size: var(--text-sm); color: var(--color-stone); background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: var(--radius-sm); }
.tep-clear:hover { color: var(--color-eurepoc-red); }
.tep-done { font-family: var(--font-ui); font-size: var(--text-sm); font-weight: var(--weight-medium); color: #fff; background: var(--color-navy); border: none; border-radius: var(--radius-sm); padding: 6px 16px; cursor: pointer; }
.tep-done:hover { background: var(--color-navy-mid); }

/* refine popover */
.tb-refine-wrap { position: relative; display: inline-flex; }
.tb-refine-btn { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-ui); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-charcoal); background: #fff; border: 1px solid var(--color-oatmeal); border-radius: var(--radius-md); padding: 8px 13px; cursor: pointer; transition: background var(--transition-base), border-color var(--transition-base); }
.tb-refine-btn:hover, .tb-refine-btn.open { background: var(--color-slate-pale); border-color: var(--color-navy); }
.tb-refine-btn > i { font-size: 16px; color: var(--color-stone); }
.trb-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; font-family: var(--font-mono); font-size: 10px; color: #fff; background: var(--color-navy); border-radius: var(--radius-pill); }
.tb-refine-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60; width: 300px; max-height: 360px; overflow-y: auto;
  background: #fff; border: 1px solid var(--color-oatmeal); border-radius: var(--radius-md);
  box-shadow: var(--shadow-overlay); padding: var(--space-3);
}
.trp-grp + .trp-grp { margin-top: var(--space-3); border-top: 1px solid var(--color-ecru); padding-top: var(--space-3); }
.trp-h { font-size: 10px; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-stone); padding: 0 6px var(--space-1); }

/* active refine chips */
#refine-chips { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.tb-fchip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 11px; border: 1px solid var(--color-navy); border-radius: var(--radius-pill); background: var(--color-slate-pale); color: var(--color-navy); font-family: var(--font-ui); font-size: 12px; font-weight: var(--weight-medium); }
.tb-fchip button { display: inline-flex; align-items: center; background: none; border: none; color: inherit; cursor: pointer; padding: 0; opacity: 0.7; }
.tb-fchip button:hover { opacity: 1; }
.tb-fchip button i { font-size: 12px; }

.tb-sort { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--color-oatmeal); border-radius: var(--radius-md); padding: 7px 11px; }
.tb-sort > i { font-size: 15px; color: var(--color-stone); }
.tb-sort select { font-family: var(--font-ui); font-size: var(--text-sm); color: var(--color-charcoal); background: none; border: none; outline: none; cursor: pointer; }

.search-hero .apply { align-self: flex-start; font-family: var(--font-ui); font-size: var(--text-sm); font-weight: var(--weight-medium); color: #fff; background: var(--color-navy); border: none; border-radius: var(--radius-md); padding: 9px 18px; cursor: pointer; }

/* ───────── RESULTS ───────── */
.results { min-width: 0; position: relative; }
.results.loading { opacity: 0.55; transition: opacity var(--transition-base); pointer-events: none; }
.scope-line { font-family: var(--font-display); font-weight: var(--weight-light); font-size: clamp(1.05rem, 2vw, 1.3rem); line-height: 1.35; letter-spacing: var(--tracking-tight); color: var(--color-stone); text-wrap: pretty; min-width: 0; }
.scope-line b { font-weight: var(--weight-medium); color: var(--color-charcoal); font-style: normal; }
.scope-row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); }

/* harmonised result-set actions: Analyse + Track sit at the same height,
   quiet outlined buttons (the user's "look like a REFERENCE text-link" note). */
.scope-acts { display: inline-flex; align-items: center; gap: var(--space-2); flex: none; }
.db-launch, .save-search {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; box-sizing: border-box;
  font-family: var(--font-ui); font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1;
  color: var(--color-navy); background: #fff; border: 1px solid var(--color-oatmeal); border-radius: var(--radius-md);
  padding: 0 13px; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background var(--transition-base), border-color var(--transition-base);
}
.db-launch:hover, .save-search:hover { background: var(--color-linen); border-color: var(--color-stone); }
.db-launch i, .save-search i { font-size: 16px; }
.save-search.in { background: var(--color-slate-pale); border-color: var(--color-slate); }

.res-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); padding-bottom: var(--space-4); margin-bottom: var(--space-2); border-bottom: 1px solid var(--hair-2); }
.res-head .count { font-family: var(--font-display); font-weight: var(--weight-light); font-size: clamp(1.4rem, 2.2vw, 1.8rem); color: var(--color-charcoal); line-height: 1.1; }
.res-head .count b { font-weight: var(--weight-regular); }
.res-head .count .q { color: var(--color-navy); font-style: italic; }
.res-head .count .count-split { display: block; font-family: var(--font-ui); font-size: var(--text-sm); font-weight: var(--weight-regular); color: var(--color-stone); margin-top: 3px; }

.gsep { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-5) 0 var(--space-1); }
.gsep:first-child { padding-top: var(--space-2); }
.gsep .gl { font-size: 10.5px; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-stone); display: inline-flex; align-items: center; gap: 7px; }
.gsep .gl i { font-size: 14px; color: var(--color-oatmeal); }
.gsep .gn { font-family: var(--font-mono); font-size: 10.5px; color: var(--color-oatmeal); }

.more-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-1); font-size: var(--text-sm); color: var(--color-stone); }
.more-row b { color: var(--color-charcoal); font-weight: var(--weight-medium); }
.grp-empty { padding: var(--space-3) var(--space-1); font-size: var(--text-sm); color: var(--color-stone); }

.empty { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding: var(--space-12) var(--space-4); text-align: center; color: var(--color-stone); }
.empty i { font-size: 30px; color: var(--color-oatmeal); }
.empty .t { font-size: var(--text-md); color: var(--color-charcoal); }
.empty .s { font-size: var(--text-sm); max-width: 30rem; }
.empty .s a { color: var(--color-navy); }

/* ───────── RESPONSIVE ───────── */
@media (max-width: 760px) {
  .search-page { padding: var(--space-5) clamp(0.9rem, 4vw, 1.5rem) var(--space-10); gap: var(--space-6); }
  .tb-row { flex-direction: column; align-items: stretch; }
  .dswap { transform: rotate(90deg); align-self: center; }
  .dswap:active { transform: rotate(90deg) scale(0.92); }
  .tb-second, .tb-scope { align-items: flex-start; }
  .tb-scope-l, .tb-scope-r { width: 100%; }
  .dseg { flex-wrap: wrap; }
  .dpk, .tb-refine-pop { width: min(92vw, 320px); }
  .scope-row { flex-direction: column; }
}

/* Threat-actor mode — swap the hero count line (incidents·responses ↔ actors). */
#hero-count [data-c="act"] { display: none; }
#hero-count[data-record="act"] [data-c="inc"],
#hero-count[data-record="act"] [data-c="sep"],
#hero-count[data-record="act"] [data-c="rsp"] { display: none; }
#hero-count[data-record="act"] [data-c="act"] { display: inline; }
