/* In-app help: the "i" explanations and the guided tour.
   Design: docs/help-and-guide.md. Chrome only - nothing here sits on the navy
   plot canvas, so nothing here needs a dark variant. */

/* --- A label with its "i" ----------------------------------------------------
   The row carries the label's bottom margin so the label and the button share
   one baseline box; the label inside it drops its own. */
.control-label-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: var(--space-1);
  min-width: 0;
}
/* Doubled class: retrieve.css loads after this file (Dash serves assets in
   name order) and sets label margins at the same specificity. */
.control-label-row > .control-label.control-label,
.control-label-row > .details-kicker.details-kicker,
.control-label-row > .panel-title.panel-title { margin-bottom: 0; }
/* In the inspector the "i" follows the record's first section title. */
.details-section-head > .details-section-title.details-section-title { margin-bottom: 0; }
.results-heading .control-label-row { margin-bottom: 0; }
/* The rail is 247 px here: label, "i" and a 128 px stepper do not fit, so the
   label keeps its width and the stepper gives a little up. */
.topk-head .control-label-row { margin: 0; flex: none; }
.sidebar .topk-head .topk-input { flex: 0 1 128px; width: auto; min-width: 104px; }
.ai-panel .control-label-row { margin: 0 0 var(--space-2); }

.bm-group-label-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 9px;
}
.bm-group-label-row > .bm-group-label.bm-group-label { margin-bottom: 0; }

.mode-switch-row { display: flex; align-items: center; gap: 6px; }
.mode-switch-row > .mode-switch { flex: 1; min-width: 0; }

/* --- The "i" button ----------------------------------------------------------
   A 24 px target (WCAG 2.5.8) drawn as a 16 px ring; the negative margin keeps
   the larger target from pushing the label's line apart. */
.info-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  margin: -4px -2px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-secondary);
  font: italic 700 10px/1 Georgia, "Times New Roman", serif;
  cursor: pointer;
  border-radius: 50%;
  transition: color var(--interaction-duration) ease;
}
.info-btn::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid var(--control-border);
  border-radius: 50%;
  transition: border-color var(--interaction-duration) ease,
              background-color var(--interaction-duration) ease;
}
.info-btn:hover,
.info-btn[aria-expanded="true"] { color: var(--accent-text); }
.info-btn:hover::before,
.info-btn[aria-expanded="true"]::before {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.info-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 0; }

/* --- The popover ------------------------------------------------------------ */
.info-popover {
  position: fixed;
  z-index: 1000;
  width: min(380px, calc(100vw - 16px));
  overflow: auto;
  overscroll-behavior: contain;
  padding: 14px 16px 16px;
  background: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.08);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  animation: info-in 140ms cubic-bezier(0.2, 0, 0, 1);
}
.info-popover:has(.info-code) { width: min(460px, calc(100vw - 16px)); }
.info-popover[hidden] { display: none; }
.info-popover[data-side="above"] { animation-name: info-in-above; }
.info-popover:focus { outline: none; }
.info-popover:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

@keyframes info-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes info-in-above { from { opacity: 0; transform: translateY(4px); } }

.info-title {
  margin: 0 28px 6px 0;
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
}
.info-text { margin: 0 0 8px; color: var(--text-primary); }
.info-text:last-of-type { margin-bottom: 0; }

.info-pop-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
}
.info-pop-close::before,
.info-pop-close::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 1.5px;
  background: currentColor;
  transform: rotate(45deg);
}
.info-pop-close::after { transform: rotate(-45deg); }
.info-pop-close:hover { background: var(--control-hover-fill); color: var(--text-primary); }
.info-pop-close:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 0; }

.info-code {
  margin: 12px 0 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
}
.info-code-path {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}
.info-code pre {
  margin: 0;
  padding: 8px 10px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-primary);
  white-space: pre;
}
.info-code pre:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }

/* --- "How it works" in the header ------------------------------------------ */
.app-guide-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  min-height: 32px;
  padding: 5px 12px 5px 6px;
  border: 1px solid var(--header-line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--header-fg);
  font: 600 13px/1 var(--font-heading);
  cursor: pointer;
  transition: background-color var(--interaction-duration) ease,
              border-color var(--interaction-duration) ease;
}
.app-guide-btn:hover { background: rgba(255, 255, 255, 0.08); border-color: var(--header-fg-muted); }
.app-guide-btn:focus-visible { outline: 2px solid var(--header-fg); outline-offset: 2px; }
.app-guide-icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--header-fg);
  color: var(--header-bg);
  font-size: 12px;
  font-weight: 700;
}
/* With the header stats hidden the switcher takes the free space, so the
   button follows it rather than floating mid-header. */
@media (max-width: 1100px) {
  .app-guide-btn { margin-left: calc(var(--space-2) - var(--space-4)); }
}
/* On a phone the header holds the brand mark, the switcher and this; the
   words step aside but stay the button's accessible name. */
@media (max-width: 640px) {
  .app-guide-btn { padding: 5px; margin-left: -4px; }
  .app-guide-text {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip-path: inset(50%); white-space: nowrap;
  }
}

/* --- The guide dialog ------------------------------------------------------- */
.guide {
  /* A definite height, so the screenshot can take whatever the words leave
     rather than pushing them below the fold on a laptop. */
  width: min(1040px, calc(100vw - 32px));
  height: min(860px, calc(100dvh - 32px));
  max-height: none;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  color: var(--text-primary);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.32);
  font-family: var(--font-sans);
  overflow: hidden;
}
.guide[open] {
  display: flex;
  flex-direction: column;
  animation: guide-in 220ms cubic-bezier(0.2, 0, 0, 1);
}
.guide::backdrop {
  background: rgba(14, 14, 16, 0.56);
  animation: guide-fade 220ms ease;
}
@keyframes guide-in { from { opacity: 0; transform: translateY(8px) scale(0.99); } }
@keyframes guide-fade { from { opacity: 0; } }

.guide-head {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 14px 16px 14px 24px;
  border-bottom: 1px solid var(--border-subtle);
  flex: none;
}
.guide-title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  white-space: nowrap;
}
.guide-tabs { display: flex; gap: 2px; margin-right: auto; }
.guide-tab {
  padding: 7px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  font: 600 13px/1.2 var(--font-heading);
  cursor: pointer;
}
.guide-tab:hover { color: var(--text-primary); background: var(--control-hover-fill); }
.guide-tab[aria-selected="true"] {
  color: var(--text-primary);
  box-shadow: inset 0 -2px var(--hds-color-nasa-red);
}
.guide-tab:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 0; }
.guide-close {
  position: relative;
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
}
.guide-close::before,
.guide-close::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 50%;
  height: 2px;
  background: currentColor;
  transform: rotate(45deg);
}
.guide-close::after { transform: rotate(-45deg); }
.guide-close:hover { background: var(--control-hover-fill); color: var(--text-primary); }
.guide-close:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 0; }

/* Scrolls only when even a fully shrunk screenshot leaves the words no room
   (a very short window); otherwise the image gives way first. */
.guide-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }
.guide-chapter { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.guide-chapter:not([data-current]),
.guide-slide:not([data-current]) { display: none; }
.guide-chapter:focus { outline: none; }

.guide-slide {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  animation: guide-slide-in 200ms ease;
}
@keyframes guide-slide-in { from { opacity: 0; } }

.guide-shot {
  /* Shrinks to the image: on a laptop the height limits it and it fills the
     space above the words; on a phone the width does, and it must not leave
     an empty band above itself. */
  flex: 0 1 auto;
  min-height: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 24px 0;
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-subtle);
}
.guide-shot img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  aspect-ratio: 16 / 10;
  object-fit: contain;
  border: 1px solid var(--border-subtle);
  border-bottom: 0;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  align-self: flex-end;
  background: var(--bg-panel);
}
.guide-copy { flex: none; }
.guide-copy { padding: 18px 24px 4px; max-width: 72ch; }
.guide-step {
  margin: 0 0 4px;
  font: 600 11px/1.3 var(--font-heading);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.guide-slide-title {
  margin: 0 0 6px;
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
}
.guide-slide-body { margin: 0; font-size: 15px; line-height: 1.55; }

.guide-foot {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 14px 24px 18px;
  flex: none;
}
.guide-dots { display: flex; gap: 6px; }
.guide-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--hds-color-carbon-20);
  transition: background-color 160ms ease, transform 160ms ease;
}
.guide-dots span.is-current { background: var(--text-primary); transform: scale(1.33); }
/* The counter is for assistive technology; the dots and the slide's own
   "Step n of m" carry it visually. */
.guide-counter {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; margin: 0;
}
.guide-nav { display: flex; gap: var(--space-2); margin-left: auto; }
.guide-nav button { width: auto; min-width: 88px; margin: 0; }
/* On the first slide there is nowhere to go back to: the button keeps its
   place so Next does not move, but it is not shown. */
.guide-nav .guide-back:disabled { visibility: hidden; }

/* Short or narrow screens: the shot shrinks before the words do, and the
   heading stacks above the chapter tabs. */
@media (max-width: 720px) {
  .guide { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .guide-head { flex-wrap: wrap; gap: var(--space-2); padding: 12px 8px 8px 16px; }
  .guide-title { font-size: 16px; flex: 1; }
  .guide-tabs { order: 3; width: 100%; margin: 0; }
  .guide-tab { flex: 1; }
  .guide-shot { padding: 12px 12px 0; }
  .guide-copy { padding: 14px 16px 4px; }
  .guide-slide-title { font-size: 17px; }
  .guide-slide-body { font-size: 14px; }
  .guide-foot { padding: 12px 16px 14px; }
  .guide-nav button { min-width: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  .info-popover,
  .guide[open],
  .guide::backdrop,
  .guide-slide { animation: none; }
  .guide-dots span { transition: none; }
}
