/* ============================================================
   requests.css · Halcyon candidate-branch demo · the request surface.
   Page-specific layout only. All color, radius, and motion tokens come
   from the Datum theme vars in halcyon.css, so this inherits light + dark
   automatically and holds WCAG AA on both grounds. Trust-grammar classes
   (.km-agent-work / .km-agent-suggestion / .km-human-gate / .km-verified /
   .km-trace*) live in halcyon.css + enrich.css and are reused here, never
   redefined. No remote font, no image asset, no @import.

   Layout: a two-column stage. Left is the control surface (the form). Right
   is the result surface: a live-step trace of how the save is processed, the
   saved-request result card, and the list of requests saved on this device.
   Collapses to a single column under 900px so there is no horizontal overflow
   at 768px or 375px.
   ============================================================ */

/* screen-reader-only utility (page-local; halcyon.css does not define it) */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- the two-column stage ---- */
.req-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.85fr);
  align-items: start;
  gap: 22px;
}
@media (max-width: 900px) {
  .req-layout { grid-template-columns: minmax(0, 1fr); }
}

/* ============================================================
   LEFT — the form (control surface)
   ============================================================ */
.req-form {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.req-form-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* fieldset / legend reset so the radio grid reads cleanly */
.req-fieldset {
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;
}
.req-fieldset legend,
.req-field > label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  padding: 0;
}
.req-field { display: flex; flex-direction: column; min-width: 0; }

/* ---- the type radio grid ---- */
.req-radio-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (max-width: 480px) {
  .req-radio-grid { grid-template-columns: minmax(0, 1fr); }
}
.req-radio { display: block; cursor: pointer; min-width: 0; }
/* hide the native input but keep it focusable + reachable */
.req-radio input {
  position: absolute;
  opacity: 0;
  width: 1px; height: 1px;
  pointer-events: none;
}
.req-radio-face {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.req-radio-glyph {
  flex: none;
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 12px; font-weight: 700;
  color: var(--text-dim);
  background: var(--surface-3);
  border: 1px solid var(--border);
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.req-radio-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.req-radio-name { font-size: 14px; font-weight: 600; color: var(--text); }
.req-radio-hint { font-size: 12px; color: var(--text-dim); line-height: 1.45; }

/* checked state: accent border + filled glyph (cyan, the agent-work color) */
.req-radio input:checked + .req-radio-face {
  border-color: var(--border-accent);
  background: var(--accent-pale);
}
.req-radio input:checked + .req-radio-face .req-radio-glyph {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--border-accent);
}
/* keyboard focus ring on the face when the hidden input is focused */
.req-radio input:focus-visible + .req-radio-face {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- text inputs ---- */
.req-input,
.req-textarea,
.req-select {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.req-textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
.req-input::placeholder,
.req-textarea::placeholder { color: var(--text-dimmer); }
.req-input:focus,
.req-textarea:focus,
.req-select:focus {
  outline: none;
  border-color: var(--border-accent);
  box-shadow: 0 0 0 3px var(--accent-pale);
}
.req-field-meta {
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-dimmer);
  text-align: right;
  letter-spacing: 0.2px;
}

/* ---- acknowledgment gate ---- */
.req-ack {
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  background: var(--gold-pale);
  padding: 14px;
}
.req-ack-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  min-width: 0;
}
.req-checkbox {
  flex: none;
  width: 17px; height: 17px;
  margin-top: 1px;
  accent-color: var(--gold);
  cursor: pointer;
}
.req-ack-text {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}

/* ---- inline error ---- */
.req-error {
  font-size: 13px;
  line-height: 1.5;
  color: var(--warn-color, #E5786C);
  background: var(--warn-wash, rgba(229,120,108,0.12));
  border: 1px solid rgba(229,120,108,0.4);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* ---- actions ---- */
.req-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ============================================================
   RIGHT — the result surface (trace + saved result + list)
   ============================================================ */
.req-side {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 96px;
}
@media (max-width: 900px) {
  .req-side { position: static; }
}

.req-trace-panel,
.req-result,
.req-saved {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.req-trace-head h3,
.req-saved-head h3,
.req-result-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.req-trace-head { margin-bottom: 12px; }
.req-trace-sub {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}
.req-trace-status {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dimmer);
  letter-spacing: 0.2px;
  min-height: 14px;
}

/* the trace gets a soft accent edge so it reads as the agent-work region */
.req-trace-panel { border-left: 3px solid var(--accent); }

/* ---- the saved-request result card ---- */
.req-result { border-left: 3px solid var(--gold); }
.req-result-head { margin-bottom: 8px; }
.req-result-note {
  margin: 6px 0 14px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}
.req-result-fields {
  margin: 0 0 12px;
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  gap: 6px 14px;
}
.req-result-fields dt {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dimmer);
  white-space: nowrap;
}
.req-result-fields dd {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  min-width: 0;
  overflow-wrap: anywhere;
}
.req-result-route { margin-bottom: 14px; }

/* ---- "Here is what would happen" preview block ---- */
.req-preview-block {
  margin: 4px 0 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  min-width: 0;
}
.req-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.req-preview-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.req-preview-replay {
  font-size: 12px;
  padding: 5px 12px;
}
.req-preview-sub {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}
/* the ExampleFlow renders its own .km-example-flow inside here; this host just
   reserves the space and lets the shared flow styles take over. */
.req-preview-flow { min-width: 0; }

.req-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---- the saved-on-this-device list ---- */
.req-saved-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.req-saved-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dimmer);
  letter-spacing: 0.2px;
}
.req-saved-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.req-saved-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  min-width: 0;
}
.req-saved-item-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.req-saved-item-type {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-pale);
  border: 1px solid var(--border-accent);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.req-saved-item-summary {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.req-saved-item-meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-dimmer);
  letter-spacing: 0.2px;
}

/* ---- footer + toast ---- */
.req-foot {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}
.req-foot p {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.55;
  max-width: 62ch;
  min-width: 0;
}

.req-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 13px;
  box-shadow: var(--shadow-teal, 0 8px 24px rgba(0,0,0,0.35));
  opacity: 0;
  pointer-events: none;
  z-index: 60;
  max-width: calc(100vw - 32px);
}
.req-toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   MOTION — every transition behind no-preference; instant under reduce.
   ============================================================ */
@media (prefers-reduced-motion: no-preference) {
  .req-result { animation: req-result-in 0.4s ease both; }
  @keyframes req-result-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .req-saved-item.is-new { animation: req-item-in 0.35s ease both; }
  @keyframes req-item-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .req-toast { transition: opacity 0.2s ease, transform 0.2s ease; }
}
@media (prefers-reduced-motion: reduce) {
  .req-result,
  .req-saved-item.is-new { opacity: 1 !important; transform: none !important; animation: none !important; }
  .req-toast { transition: none; }
}
