/* Retrieval plans (code plan engine): plan rows on the AI plan card and the
   criteria-match chips on grouped results. Rows reuse the card's try layout
   (.plan-try in geodesy_panel_redesign.css) and main's criterion highlights
   (.hi-*, .hi-clickable) and previews (.plan-popover); this file adds what is new. */

.ai-plan .plan-retrieval > ol,
.ai-plan .plan-retrieval details > ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.retrieval-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 1px 6px;
  border: 1px solid var(--gd-rim);
  border-radius: var(--gd-r);
  font-size: var(--gd-sz-sm);
  color: var(--gd-text-hi);
  white-space: normal;
}

.retrieval-chip b {
  font-family: var(--gd-font-mono);
  font-weight: 400;
  color: var(--gd-amber);
}

.retrieval-met {
  font-family: var(--gd-font-mono);
  color: var(--gd-amber);
}

/* Criteria stay inside their column however narrow the panel: chips wrap, and a long
   criterion is cut with an ellipsis (its full text is the chip's tooltip). */
.retrieval-criteria-col {
  white-space: normal;
  overflow: hidden;
}

.retrieval-criteria-col .retrieval-chip {
  max-width: 100%;
  margin: 1px 0;
}

.retrieval-chip-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.retrieval-broader {
  margin-top: 2px;
  font-size: var(--gd-sz-sm);
  color: var(--gd-text-mid);
}

.retrieval-broader-label {
  color: var(--gd-amber);
}

/* The card: one line per plan ("Plan n", its sentence, its outcome beside it), in plan order.
   Every plan runs, so a queued one is not dimmed. Criteria read as plain words, underlined
   where they open a preview. */
.ai-plan .plan-retrieval ol {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ai-plan .plan-retrieval .plan-try {
  align-items: baseline;
  padding: 4px 0;
}

.ai-plan .plan-tries.plan-retrieval .plan-try:not(:last-child)::before {
  content: none;
}

.ai-plan .plan-retrieval .plan-try[data-state="found"] {
  background: none;
}

.ai-plan .plan-retrieval .plan-try[data-state="waiting"] > * {
  opacity: 1;
}

.retrieval-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.retrieval-plan-n {
  flex: none;
  font-size: var(--gd-sz-xs);
  color: var(--gd-text-low);
  white-space: nowrap;
}

.retrieval-line .try-text {
  flex: 1;
  min-width: 0;
}

.ai-plan .retrieval-line .try-outcome {
  flex: none;
  max-width: 40%;
  margin: 0;
  text-align: end;
}

/* The outcome is a button: once the plan has results, its count opens them. */
.ai-plan .retrieval-line button.try-outcome {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: var(--gd-sz-sm);
}

/* Until then it reads as plain text, not as a disabled control (button_styles.css). */
.ai-plan .retrieval-line button.try-outcome:disabled {
  opacity: 1;
  cursor: default;
}

.ai-plan .retrieval-line button.try-outcome:enabled {
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.ai-plan .retrieval-line button.try-outcome:enabled:hover {
  text-decoration-style: solid;
}

/* Stop / Re-run sit beside the outcome. */
.retrieval-line .try-actions {
  flex: none;
}

.ai-plan .retrieval-line .try-actions button {
  margin-top: 0;
}

/* Until inspected, criteria read as plain words; Inspect (.is-inspect) restores their
   method colours, eyes, whole lists and the fields searched, in place. */
.ai-plan:not(.is-inspect)
  .plan-retrieval
  :is(.hi-emerald, .hi-purple, .hi-amber, .hi-blue, .hi-cyan, .hi-slate) {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-weight: 400;
}

.ai-plan:not(.is-inspect) .plan-retrieval .hi-clickable {
  border-bottom: 1px solid var(--gd-stroke);
}

.ai-plan:not(.is-inspect) .plan-retrieval .hi-clickable:hover {
  border-bottom-color: var(--gd-text-mid);
}

.ai-plan:not(.is-inspect)
  .plan-retrieval
  :is(.hi-clickable, .retrieval-verdict)
  .fa-eye,
.retrieval-inspect {
  display: none;
}

/* Inspect-only detail takes its element's own display: a phrase inline, a line as a block. */
.is-inspect .retrieval-inspect {
  display: revert;
}

.is-inspect .plan-retrieval .retrieval-list > .retrieval-rest {
  display: inline;
}

.is-inspect .plan-retrieval .retrieval-list > .retrieval-show-rest,
.is-inspect .plan-retrieval .retrieval-list > .retrieval-show-less {
  display: none;
}

/* Inspected, each kind of condition (its piece, data-type) takes a fixed colour from one
   ten-colour palette; a kind not listed takes --type-9. */
.plan-retrieval {
  --type-0: #2db56d; /* place */
  --type-1: #a78bfa; /* text search */
  --type-2: #4aa8e8; /* language */
  --type-3: #e0b43c; /* time */
  --type-4: #2ec4d6; /* field value */
  --type-5: #ec6fa8; /* custom code */
  --type-6: #f2805a; /* network */
  --type-7: #9fb0c8; /* field searched */
  --type-8: #a3c94a; /* free */
  --type-9: #8c94f5; /* any other piece */
}

.ai-plan.is-inspect .plan-retrieval [data-type] {
  color: var(--chip);
  background: color-mix(in srgb, var(--chip) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip) 45%, transparent);
}

.ai-plan.is-inspect .plan-retrieval [data-type] code {
  color: inherit;
}

.ai-plan.is-inspect .plan-retrieval [data-type]:hover {
  background: color-mix(in srgb, var(--chip) 24%, transparent);
  opacity: 1;
}

.plan-retrieval [data-type] {
  --chip: var(--type-9);
}
.plan-retrieval [data-type="in_area"] {
  --chip: var(--type-0);
}
.plan-retrieval [data-type="mentions"] {
  --chip: var(--type-1);
}
.plan-retrieval [data-type="language_is"] {
  --chip: var(--type-2);
}
.plan-retrieval
  :is(
    [data-type="time_between"],
    [data-type="hours"],
    [data-type="weekday_in"],
    [data-type="month_in"]
  ) {
  --chip: var(--type-3);
}
.plan-retrieval [data-type="compare"] {
  --chip: var(--type-4);
}
.plan-retrieval [data-type="code"] {
  --chip: var(--type-5);
}
.plan-retrieval [data-type="network"] {
  --chip: var(--type-6);
}
.plan-retrieval [data-type="field"] {
  --chip: var(--type-7);
}

/* The card's Inspect switch, top right. */
.retrieval-card-head {
  display: flex;
  justify-content: flex-end;
}

.retrieval-inspect-toggle[aria-pressed="true"] {
  border-color: var(--gd-text-mid);
  color: var(--gd-text-hi);
}

/* The reviewer's verdict: a quiet line, its icon coloured by it. */
.retrieval-meta {
  margin-top: 3px;
}

.ai-plan .plan-retrieval .retrieval-verdict {
  padding: 0;
  border: 0;
  color: var(--gd-text-mid);
}

.ai-plan .plan-retrieval .retrieval-verdict:hover {
  color: var(--gd-text-hi);
}

.ai-plan .plan-retrieval .retrieval-verdict i {
  color: var(--verdict);
}

.retrieval-read-as {
  margin-bottom: 4px;
  font-size: var(--gd-sz-sm);
  white-space: pre-line;
}

.retrieval-approve,
.retrieval-inspect-toggle {
  padding: 1px 6px;
  border: 1px solid var(--gd-rim);
  border-radius: var(--gd-r);
  background: none;
  font-size: var(--gd-sz-xs);
  color: var(--gd-text-mid);
  cursor: pointer;
}

.retrieval-approve {
  margin-top: 4px;
  border-color: var(--gd-amber);
  color: var(--gd-amber);
}

/* The reviewer's verdict, coloured by it. */
.retrieval-verdict {
  --verdict: var(--gd-text-mid);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding: 1px 6px;
  border: 1px solid var(--verdict);
  border-radius: var(--gd-r);
  background: none;
  font-size: var(--gd-sz-xs);
  color: var(--verdict);
  text-transform: none;
  letter-spacing: normal;
  cursor: pointer;
}

/* A link's requirement uses main's nested connection list, indented as main's is (the tries
   list's reset would flatten it); its items do not expand here. */
.ai-plan .plan-retrieval ol.conn-crit-list {
  margin: 4px 0;
  padding: 0;
  padding-inline-start: 16px;
}

.ai-plan .plan-retrieval .conn-crit-item {
  cursor: default;
}

.retrieval-verdict .fa-eye {
  opacity: 0.5;
}

.retrieval-verdict:hover .fa-eye {
  opacity: 1;
}

:is(.retrieval-verdict, .retrieval-verdict-text)[data-verdict="achieves"] {
  --verdict: var(--gd-green);
  color: var(--gd-green);
}

:is(.retrieval-verdict, .retrieval-verdict-text)[data-verdict="partial"] {
  --verdict: var(--gd-amber);
  color: var(--gd-amber);
}

:is(.retrieval-verdict, .retrieval-verdict-text)[data-verdict="does_not"] {
  --verdict: var(--gd-red);
  color: var(--gd-red);
}

/* Code, Criteria and sources: small arrows on one line; an opened one takes the row. */
/* Code and criteria, one per line whether open or closed. */
.retrieval-more {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 3px;
}

.retrieval-detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: var(--gd-sz-xs);
  color: var(--gd-text-low);
}

.retrieval-detail-list li + li {
  margin-top: 2px;
}

.retrieval-detail-list .detail-method {
  color: var(--gd-text-mid);
}

/* A long list shows its first items; "+N more" shows the rest and "Show less" folds it. */
.retrieval-list:not(.open) > .retrieval-rest,
.retrieval-list:not(.open) > .retrieval-show-less,
.retrieval-list.open > .retrieval-show-rest {
  display: none;
}

.retrieval-show-rest,
.retrieval-show-less {
  cursor: pointer;
  color: var(--gd-text-mid);
  text-decoration: underline dotted;
}

.retrieval-section > summary {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  font-size: var(--gd-sz-xs);
  color: var(--gd-text-low);
  cursor: pointer;
}

.retrieval-section > summary::-webkit-details-marker {
  display: none;
}

.retrieval-section > summary::before {
  content: "\25B8";
  font-size: 9px;
  transition: transform 0.15s;
}

.retrieval-section[open] > summary::before {
  transform: rotate(90deg);
}

.retrieval-section > :not(summary) {
  margin-top: 3px;
}

.retrieval-section pre {
  margin: 0;
  padding: 6px 8px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--gd-rim);
  border-radius: var(--gd-r);
  background: var(--gd-void);
  font-family: var(--gd-font-mono);
  font-size: var(--gd-sz-xs);
  color: var(--gd-text-mid);
  white-space: pre;
}

.retrieval-where {
  color: var(--gd-text-low);
}

/* A criterion opened: label and value, one pair per line. */
.retrieval-kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 3px 10px;
  margin: 0;
  font-size: var(--gd-sz-xs);
}

.retrieval-kv dt {
  color: var(--gd-text-low);
}

.retrieval-kv dd {
  margin: 0;
  color: var(--gd-text-hi);
  overflow-wrap: anywhere;
}

.retrieval-kv + .popover-action {
  margin-top: 6px;
}

/* A try's own controls: Stop while it runs (the other tries run on), Re-run once it has. */
.ai-plan .try-actions button {
  display: none;
  margin-top: 4px;
  padding: 1px 6px;
  border: 1px solid var(--gd-rim);
  border-radius: var(--gd-r);
  background: none;
  font-size: var(--gd-sz-xs);
  color: var(--gd-text-mid);
  cursor: pointer;
}

.ai-plan .plan-try[data-state="running"] .try-stop {
  display: inline-block;
  border-color: var(--gd-amber);
  color: var(--gd-amber);
}

.ai-plan
  .plan-try:is(
    [data-state="found"],
    [data-state="empty"],
    [data-state="incomplete"],
    [data-state="stopped"],
    [data-state="failed"]
  )
  .try-rerun {
  display: inline-block;
}
