/*
 * Engineering Edge — "Ask" UI styles.
 *
 * Ported from the frozen co-design prototype (docs/ka-ui-spec.html, v2.2).
 * Two deliberate departures from the prototype file:
 *   1. All classes are namespaced `ka-*` and design tokens are scoped to
 *      `.ka-root`, so nothing collides with Semantic UI / invenio-app-rdm
 *      classes (the prototype used bare `.btn`, `.searchbox`, `.src`, …).
 *   2. Dark mode is NOT shipped (prompt §4: a KA-only dark island against a
 *      light InvenioRDM would be worse than none). The high-contrast variant
 *      (`.ka-root.hc`) IS shipped and is the accessibility toggle.
 *
 * Palette and typography are the ee theme tokens exactly as the spec froze them.
 */

.ka-root {
  --slate: #64748b;
  --slate-deep: #566071;
  --slate-hover: #485060;
  --orange: #f78f01;
  --orange-soft: #fdf0dd;
  --blue: #4cbeff;
  --blue-deep: #2596d1;
  --ink: #1e293b;
  /* --muted / --label / --pdf-ok darkened from the prototype's #697586 /
     #94a3b8 / #16a34a so secondary text clears WCAG AA (4.5:1) on white and
     on --bg-soft. --faint stays light — it is only used for borders and
     placeholders, never as body text. (§4 contract-checked tokens.) */
  --muted: #5c6675;
  --faint: #94a3b8;
  --label: #5f6b7a;
  --pdf-ok: #157f3c;
  --line: #e2e8f0;
  --line-soft: #eef2f6;
  --bg: #ffffff;
  --bg-soft: #f8fafc;
  --card: #ffffff;
  --ok: #16a34a;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Inter", -apple-system, "Segoe UI", sans-serif;
}

/* High-contrast variant — the shipped a11y toggle (persisted per browser). */
.ka-root.hc {
  --ink: #000000;
  --muted: #1e293b;
  --faint: #334155;
  --orange: #b45309;
  --orange-soft: #ffedd5;
  --blue-deep: #1d4ed8;
  --ok: #15803d;
}
.ka-root.hc .ka-src,
.ka-root.hc .ka-searchbox,
.ka-root.hc .ka-refusal,
.ka-root.hc .ka-guardrail {
  border-width: 2px;
}
.ka-root.hc .ka-cite {
  border-width: 1.5px;
  font-weight: 700;
}

.ka-root :focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}
.ka-root svg.ka-ic {
  width: 1em;
  height: 1em;
  vertical-align: -2px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── search/ask unit — lives IN the navbar on every page (v2.3) ───────── */
/* The unit is a white pill dropped into the slate navbar, filling the flex
   space between the logo and the right-hand nav items (the `.item.search-bar`
   wrapper already carries `flex:1` from menu.overrides). */
.ka-navsearch {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}
.ka-searchbox {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  background: var(--card);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: none;
  border: 1px solid transparent;
}
.ka-searchbox input {
  flex: 1;
  border: 0;
  padding: 10px 14px;
  font-size: 14.5px;
  font-family: var(--sans);
  color: var(--ink);
  min-width: 0;
  background: transparent;
}
.ka-searchbox input::placeholder {
  color: var(--faint);
}
.ka-searchbox input:focus {
  outline: none;
}
.ka-btn {
  border: 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  padding: 0 15px;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.ka-btn-search {
  /* Dark-grey text AND icon (icon inherits via currentColor), matching the
     navbar's Log in link — not the old orange/white search button. */
  background: var(--bg-soft);
  color: #334155;
  border-left: 1px solid var(--line);
}
.ka-btn-search:hover {
  background: var(--line-soft);
}
/* Responsive: below 820px the button words collapse, leaving icon-only
   (magnifier / ✦). Narrower still, InvenioRDM's burger stacks the whole unit
   into the collapsed menu (a full-width second row). */
@media (max-width: 820px) {
  .ka-btn .ka-btnword {
    display: none;
  }
  .ka-btn {
    padding: 0 12px;
  }
}
.ka-btn-ask {
  background: var(--orange);
  color: #fff;
  position: relative;
  overflow: hidden;
}
.ka-btn-ask:hover {
  background: #e07f00;
}
.ka-root.hc .ka-btn-ask:hover {
  background: #92400e;
}
.ka-spark {
  font-size: 15px;
  line-height: 1;
}
/* ripple: a light sweep INSIDE the glyphs only (icon + word), 5.2s cycle */
.ka-btn-ask .ka-asklabel {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: linear-gradient(
      105deg,
      #fff 32%,
      #ffd9a0 42%,
      #8ed8ff 50%,
      #ffc4e1 58%,
      #fff 68%
    )
    0 0 / 260% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  /* Seamless loop with NO stationary segment (round-3 fix 2026-09-14).
     Round-2 held the rest at a fixed -150% for 50%->100%; even a faint sliver
     there (or the wide band's trailing edge easing out just before the hold)
     reads as a "tiny pause at the right end before it disappears". The fix is
     to remove the hold entirely: ONE single linear segment (`from`/`to` only)
     across 250% -> -400%. The band sweeps across the glyphs once (enters ~24%,
     fully exits by ~69%) and then keeps MOVING off-glyph through the rest — it
     is never stationary anywhere, so no position can ever "hang" at the right
     edge. Both ends are off-glyph blank (250% and -400% render identical plain
     text) so the wrap is invisible; pure linear with NO animation-delay means
     iteration 1 is byte-identical to iteration N. (will-change removed —
     background-position isn't a compositor property, so it only risked a
     first-cycle layer warm-up.) Same frozen v2.3 look (colours, 5.2s, glyph
     only). Verified in-browser by scrubbing the timeline across cycles: the
     band exits at constant speed with no held/visible remnant at the edge. */
  animation: ka-asksweep 5.2s linear infinite;
}
@keyframes ka-asksweep {
  from {
    background-position: 250% 0; /* off-glyph — == the 'to' state visually */
  }
  to {
    background-position: -400% 0; /* one linear sweep + moving off-glyph rest */
  }
}
.ka-caret {
  display: inline-block;
  width: 1px;
  height: 1.05em;
  background: var(--faint);
  vertical-align: -2px;
  margin-left: 1px;
  animation: ka-blink 1s steps(1) infinite;
}
@keyframes ka-blink {
  50% {
    opacity: 0;
  }
}
/* ── ask page layout ────────────────────────────────────── */
.ka-askwrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 26px 28px 60px;
}
.ka-crumb {
  font-size: 12.5px;
  color: var(--label);
  margin-bottom: 14px;
}
.ka-crumb a {
  color: var(--label);
  cursor: pointer;
}
.ka-qtitle {
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin: 0 0 6px;
  text-wrap: balance;
  color: var(--ink);
  font-family: var(--sans);
}
.ka-phase {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13.5px;
  margin: 14px 0 4px;
  min-height: 22px;
}
.ka-dotpulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--orange);
  animation: ka-pulse 1s ease infinite;
}
@keyframes ka-pulse {
  50% {
    opacity: 0.25;
  }
}
.ka-stats {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 8px;
  min-height: 20px;
}
.ka-stats b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.ka-stats .ka-sep {
  color: var(--line);
}
.ka-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 42px;
  margin-top: 10px;
}
@media (max-width: 900px) {
  .ka-cols {
    grid-template-columns: 1fr;
  }
}

/* ── history ────────────────────────────────────────────── */
.ka-hx {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
  background: var(--bg-soft);
  max-width: 66ch;
}
.ka-hx summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  list-style: none;
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.ka-hx summary::-webkit-details-marker {
  display: none;
}
.ka-hx summary::before {
  content: "Q";
  font-size: 11px;
  font-weight: 700;
  color: var(--orange);
  background: var(--orange-soft);
  border-radius: 4px;
  padding: 0 5px;
  flex: none;
}
.ka-hx[open] summary {
  border-bottom: 1px solid var(--line);
}
.ka-hx .ka-hxbody {
  padding: 12px 16px;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.65;
  color: var(--muted);
}
.ka-hxnote {
  font-size: 11.5px;
  color: var(--label);
  margin: 0 0 10px;
}

/* ── answer + citations ─────────────────────────────────── */
.ka-answer {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.72;
  max-width: 66ch;
  color: var(--ink);
}
.ka-answer p {
  margin: 0 0 1.05em;
}
.ka-cite {
  display: inline-block;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  color: var(--orange);
  background: var(--orange-soft);
  border: 1px solid #f5d9ae;
  border-radius: 4px;
  padding: 0 5px;
  margin: 0 2px;
  vertical-align: 2px;
  cursor: pointer;
  transition: background 0.12s;
}
.ka-cite:hover,
.ka-cite.hot {
  background: var(--orange);
  color: #fff;
}
/* chained chips sit flush against their sibling */
.ka-cite.chained {
  margin-left: 0;
}
.ka-nb {
  white-space: nowrap;
}

.ka-refusal {
  border: 1px solid var(--line);
  border-left: 3px solid var(--slate);
  background: var(--bg-soft);
  border-radius: 0 8px 8px 0;
  padding: 16px 20px;
  font-family: var(--sans);
  font-size: 14.5px;
  color: var(--ink);
  max-width: 60ch;
}
.ka-guardrail {
  border: 1px solid var(--line);
  border-left: 3px solid var(--orange);
  background: var(--bg-soft);
  border-radius: 0 8px 8px 0;
  padding: 16px 20px;
  font-family: var(--sans);
  font-size: 14.5px;
  color: var(--ink);
  max-width: 60ch;
}
.ka-guardrail .ka-gr-btns {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.ka-gr-btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13.5px;
  cursor: pointer;
  font-weight: 500;
  color: var(--ink);
  font-family: var(--sans);
}
.ka-gr-btn.primary {
  background: var(--orange);
  border-color: var(--orange);
  /* Dark ink on brand orange (≈5.9:1) rather than white (≈2.4:1), so the
     solid primary CTA meets AA while keeping the brand colour. §4. */
  color: var(--ink);
  font-weight: 600;
}
.ka-gr-btn:hover {
  border-color: var(--faint);
}
.ka-gr-btn.primary:hover {
  background: #e07f00;
}

.ka-feedback {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
  color: var(--muted);
}
.ka-thumb {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
}
.ka-thumb svg.ka-ic {
  width: 16px;
  height: 16px;
}
.ka-thumb:hover {
  border-color: var(--faint);
  color: var(--ink);
}
.ka-thumb.sel-up {
  background: #e9f9ef;
  border-color: var(--ok);
  color: var(--ok);
}
.ka-thumb.sel-up svg.ka-ic {
  fill: #bbf7d0;
}
.ka-thumb.sel-dn {
  background: #fdeaea;
  border-color: #dc2626;
  color: #dc2626;
}
.ka-thumb.sel-dn svg.ka-ic {
  fill: #fecaca;
}
.ka-followup {
  display: flex;
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  max-width: 560px;
  background: var(--card);
}
.ka-followup input {
  flex: 1;
  border: 0;
  padding: 11px 14px;
  font-size: 14px;
  font-family: var(--sans);
  background: transparent;
  color: var(--ink);
}
.ka-followup input:focus {
  outline: none;
}
.ka-followup button {
  border: 0;
  background: var(--orange-soft);
  color: var(--orange);
  font-weight: 600;
  padding: 0 16px;
  cursor: pointer;
  font-family: var(--sans);
}
.ka-retrywrap {
  margin-top: 14px;
  max-width: 60ch;
}

/* ── sources rail ───────────────────────────────────────── */
.ka-railhead {
  font-size: 11.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--label);
  margin: 0 0 10px;
  font-weight: 600;
  line-height: 1.2;
}
.ka-railhead.consulted {
  margin-top: 22px;
}
.ka-src {
  display: flex;
  gap: 11px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.2s;
  text-align: left;
  width: 100%;
  font-family: var(--sans);
  color: var(--ink);
}
.ka-src:hover {
  border-color: var(--faint);
}
.ka-src.hot {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px var(--orange-soft);
}
.ka-src.active {
  background: var(--orange-soft);
  border-color: var(--orange);
}
/* "Consulted" cards read as secondary via the soft background and the grey
   number badge — NOT via opacity, which would drag their text below AA. */
.ka-src.dim {
  background: var(--bg-soft);
}
.ka-srcnum {
  font-size: 11px;
  font-weight: 600;
  color: var(--orange);
  background: var(--orange-soft);
  border-radius: 4px;
  height: 19px;
  min-width: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.ka-src.active .ka-srcnum {
  background: var(--orange);
  color: #fff;
}
.ka-src.dim .ka-srcnum {
  background: var(--line-soft);
  color: var(--faint);
}
.ka-srcbody {
  min-width: 0;
}
.ka-srctitle {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ka-srcmeta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
}
.ka-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 6px;
  font-weight: 500;
}
.ka-badge i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  background: var(--faint);
}
.ka-badge.b-article i {
  background: var(--blue);
}
.ka-badge.b-thesis i {
  background: var(--orange);
}
.ka-badge.b-preprint i {
  background: var(--faint);
}
.ka-pdf {
  color: var(--pdf-ok);
  font-weight: 600;
  letter-spacing: 0.03em;
}

/* ── knowledge map ──────────────────────────────────────── */
.ka-mapsec {
  margin-top: 46px;
  border-top: 1px solid var(--line);
  padding-top: 26px;
}
.ka-maphead {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.ka-maphead h3 {
  font-size: 16px;
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
}
.ka-maphead small {
  color: var(--muted);
  font-size: 13px;
}
.ka-maphead a {
  margin-left: auto;
  font-size: 13px;
  cursor: pointer;
}
.ka-cy {
  height: 430px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 14px;
  background: var(--bg-soft);
}
.ka-maplegend {
  display: flex;
  gap: 18px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.ka-maplegend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
}

/* ── high-contrast toggle control ───────────────────────── */
.ka-a11y {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}
.ka-a11y button {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: var(--sans);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ka-a11y button[aria-pressed="true"] {
  border-color: var(--orange);
  color: var(--orange);
  background: var(--orange-soft);
}

.ka-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  font-size: 13.5px;
  padding: 10px 18px;
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  max-width: 80vw;
  text-align: center;
  z-index: 60;
}
.ka-toast.on {
  opacity: 0.95;
}

.ka-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}
/* Hidden #header-search-bar compatibility element in the navbar (see header.html)
   — kept in the DOM for the search-results apps, never shown. */
.ka-navsearch-compat {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .ka-btn-ask .ka-asklabel {
    animation: none;
    background: none;
    /* Reduced-motion drops the multi-colour shimmer for a solid label; use
       dark ink so the solid fallback meets AA on the brand orange (the
       animated shimmer itself is a frozen-brand element). */
    color: var(--ink);
    -webkit-background-clip: initial;
    background-clip: initial;
  }
  .ka-dotpulse,
  .ka-caret {
    animation: none;
  }
}
