/*
 * RoteaHub help documentation styles
 * Edit source (license-app monorepo): help/assets/css/help.css
 * Deployed copy: help_protrev_workflow_files/help.css (sync via protrev/tools/build_help.py)
 * Consumed by wx.html2.WebView (desktop) beside help_protrev_workflow.html.
 *
 * Layout contract (do not break — required by script.js):
 *   .fixed-header     fixed toolbar; height measured into --header-h at runtime
 *   .content          sole scroll container (overflow-y: auto)
 *   #pin-btn.latched  pinned scroll state
 *   #toc-picker         jump-to-section control (trigger + scrollable list)
 *   #toc-trigger        closed-state label button
 *   #toc-list           open list; .toc-picker__item.is-current marks selection
 *   #search-box        live search input
 *   #search-results    search dropdown (.result-item, .is-heading, mark.__hit)
 *   span.__hl__        in-document search highlight spans
 *
 * Image lightbox: single-click expandable by default.
 * Opt out per image in markdown/HTML with data-help-expand="false"
 * or class="help-img-no-expand". Default screenshot width is 32rem (see .content img).
 * Override with help-img-inline / help-img-banner for small inline assets;
 * help-img-protocol-button for toolbar status glyphs; help-img-workflow for step diagrams;
 * help-img-wide for screenshots that need the wider 40rem layout;
 * help-img-center / help-img-narrow to centre a block image (20rem);
 * help-img-row to place two or more images side by side (wraps on narrow viewports);
 * help-clear-float on a heading or empty div to start below a floated image;
 * help-img-float-right on a wrapper div so width applies to floated screenshots.
 */

/* ===== Design tokens (aligned with RoteaHub website) ===== */
:root {
  --navy: #001c3c;
  --navy-mid: #013a66;
  --blue: #0285bf;
  --light-blue: #edeef4;
  --white: #ffffff;
  --background: #f8f8f8;
  --foreground: #181818;
  --card: #ffffff;
  --primary: #0285bf;
  --secondary: #edeef4;
  --muted-foreground: #616161;
  --border: rgba(0, 28, 60, 0.12);
  --amber: #f59e0b;

  --font-sans: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;

  /* Measured from .fixed-header by updateHeaderVar(); fallback only */
  --header-h: 72px;

  --ctrl-h: 36px;
  --ctrl-radius: 0.75rem;
  --ctrl-border: 1px solid rgba(255, 255, 255, 0.22);
  --ctrl-bg: rgba(255, 255, 255, 0.1);
  --ctrl-pad-x: 12px;
  --ctrl-font: 14px;

  color-scheme: light;
}

/* ===== Base ===== */
html,
body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--foreground);
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--background);
  overflow: hidden;
}

/* ===== Fixed header (Python nav / pin / TOC / search) ===== */
.fixed-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  min-height: 56px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 55%, var(--blue) 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  box-shadow: 0 4px 20px rgba(0, 28, 60, 0.22);
  z-index: 1000;
  gap: 12px;
  box-sizing: border-box;
}

.fixed-header h1 {
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  flex: 1;
  min-width: 0;
}

/* ===== Sole scroll container ===== */
.content {
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  bottom: 0;
  padding: 24px clamp(16px, 4vw, 48px) 48px;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--background);
}

/* Readable prose column inside scroller */
.content > :not(script) {
  max-width: 42rem;
}

.content > h1:first-child,
.content > h2:first-child,
.content > p:first-child {
  margin-top: 0;
}

/* ===== Typography (article-prose alignment) ===== */
.content h1 {
  margin: 0 0 1rem;
  font-size: clamp(1.5rem, 1.154rem + 1.478vi, 2.75rem);
  line-height: 1.2;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--navy);
}

.content h2 {
  margin: 2.5rem 0 0.75rem;
  padding-top: 0.5rem;
  font-size: clamp(1.25rem, 1.077rem + 0.739vi, 1.875rem);
  line-height: 1.35;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--navy);
  border-top: 1px solid var(--border);
}

.content h2:first-of-type,
.content h1 + h2 {
  border-top: 0;
  padding-top: 0;
}

.content h3 {
  margin: 1.75rem 0 0.625rem;
  font-size: clamp(1.125rem, 1.021rem + 0.444vi, 1.5rem);
  line-height: 1.35;
  font-weight: 500;
  color: var(--navy);
}

.content h4 {
  margin: 1.25rem 0 0.5rem;
  font-size: 1rem;
  line-height: 1.4;
  font-weight: 600;
  color: var(--navy);
}

.content h5 {
  margin: 1rem 0 0.375rem;
  font-size: 0.9375rem;
  line-height: 1.4;
  font-weight: 600;
  color: var(--navy-mid);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.content p {
  margin: 0 0 1.125rem;
  color: rgba(0, 28, 60, 0.82);
}

.content ul,
.content ol {
  margin: 0 0 1.125rem;
  padding-left: 1.5rem;
  color: rgba(0, 28, 60, 0.82);
}

.content ul {
  list-style-type: disc;
}

.content ol {
  list-style-type: decimal;
}

.content li + li {
  margin-top: 0.375rem;
}

.content li > p {
  margin-bottom: 0.5rem;
}

.content a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.content a:hover {
  text-decoration: none;
}

.content strong {
  font-weight: 600;
  color: var(--navy);
}

.content hr {
  margin: 2rem 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.content blockquote {
  margin: 1.5rem 0;
  padding: 0.75rem 0 0.75rem 1rem;
  border-left: 3px solid var(--primary);
  background: var(--secondary);
  border-radius: 0 0.5rem 0.5rem 0;
  color: rgba(0, 28, 60, 0.72);
}

.content code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.875em;
  background: var(--secondary);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
}

.content pre {
  margin: 1.25rem 0;
  overflow-x: auto;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 1rem 1.125rem;
}

.content pre code {
  background: transparent;
  padding: 0;
}

.content img {
  display: block;
  width: 32rem;
  max-width: 100%;
  height: auto;
  max-height: none;
  margin: 1rem 0;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: zoom-in;
}

/* Step header diagrams (workflow*.png); same default width as full screenshots */
.content img.help-img-workflow {
  display: block;
  width: 32rem;
  max-width: 100%;
  height: auto;
  max-height: none;
  margin: 1rem 0;
}

/* Wider screenshots (e.g. Modify review panel) */
.content img.help-img-wide {
  display: block;
  width: 40rem;
  max-width: 100%;
  height: auto;
  max-height: none;
  margin: 1rem 0;
}

/* Centred block images */
.content img.help-img-center {
  margin-left: auto;
  margin-right: auto;
}

.content img.help-img-narrow {
  width: 20rem;
}

/* Side-by-side image row (same 20rem width per image; stacks when narrow) */
.content .help-img-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  align-items: flex-start;
  margin: 1rem 0;
}

.content .help-img-row img {
  width: 20rem;
  max-width: 100%;
  height: auto;
  margin: 0;
  flex: 0 1 20rem;
}

/* Start below floated images (use on a div or heading after float + short text) */
.content .help-clear-float {
  clear: both;
}

/* Floated right screenshot — set width on the div; image fills the box */
.content .help-img-float-right {
  float: right;
  margin-left: 20px;
  margin-bottom: 0.5rem;
  max-width: 100%;
}

.content .help-img-float-right img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  max-width: 100%;
}

/* Opt out of lightbox: data-help-expand="false" or class help-img-no-expand */
.content img[data-help-expand="false"],
.content img.help-img-no-expand {
  cursor: default;
}

/* Rotea protocol button glyphs (~100×25 source art) */
.content img.help-img-protocol-button {
  display: inline-block;
  vertical-align: middle;
  height: 1.5rem;
  width: auto;
  max-width: 7.5rem;
  margin: 0 0.35rem;
  border: 0;
  border-radius: 0.2rem;
  background: transparent;
}

/* Small inline icons and toolbar glyphs */
.content img.help-img-inline {
  display: inline-block;
  vertical-align: middle;
  width: auto;
  max-width: 100%;
  max-height: 6rem;
  margin: 0 0.25rem;
  border-radius: 0.25rem;
}

/* Low-height workflow strip diagrams */
.content img.help-img-banner {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 2.5rem;
  object-fit: contain;
  object-position: left center;
  margin: 0.75rem 0;
  border: 0;
  background: transparent;
}

.content p img.help-img-inline,
.content li img.help-img-inline {
  margin: 0 0.35rem;
}

.content figure,
.content .help-img-float {
  margin: 1.25rem 0;
  max-width: min(100%, 52rem);
}

.content .help-img-float img {
  margin: 0;
}

/* ----- Image lightbox (single-click expand) ----- */
.help-lightbox {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 48px);
  background: rgba(0, 28, 60, 0.88);
  box-sizing: border-box;
}

.help-lightbox[hidden] {
  display: none;
}

.help-lightbox__dialog {
  position: relative;
  max-width: min(96vw, 1200px);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.help-lightbox__image {
  display: block;
  max-width: 100%;
  max-height: calc(92vh - 3rem);
  width: auto;
  height: auto;
  margin: 0 auto;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: var(--card);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.35);
}

.help-lightbox__caption {
  margin: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.875rem;
  line-height: 1.45;
}

.help-lightbox__close {
  position: absolute;
  top: -0.25rem;
  right: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.12);
  color: var(--white);
  font-size: 0.875rem;
  line-height: 1;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
}

.help-lightbox__close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.content table {
  width: 100%;
  max-width: 100%;
  margin: 1.25rem 0;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.content th,
.content td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

.content th {
  background: var(--secondary);
  color: var(--navy);
  font-weight: 600;
}

/* In-document search highlights (script.js __hl__) */
.content .__hl__ {
  background: #ffe9a8;
  padding: 0 2px;
  border-radius: 2px;
}

/* Legacy utility classes from authored markdown */
.normal-text {
  font-size: 1rem;
  text-align: left;
}

.indent,
.indented-text {
  margin-left: 2rem;
}

.text-with-image {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.text-with-image img {
  max-height: 100%;
  max-width: 100%;
  vertical-align: middle;
}

/* ===== Header navigation buttons ===== */
.header-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-buttons button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--ctrl-radius);
  background: rgba(255, 255, 255, 0.12);
  color: var(--white);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
}

.header-buttons button:hover {
  background: rgba(255, 255, 255, 0.22);
}

.header-buttons button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Pin button — #pin-btn + .latched used by togglePin() */
#pin-btn {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--ctrl-radius);
  background-color: rgba(255, 255, 255, 0.12);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 17v5'/%3E%3Cpath d='M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a3 3 0 0 0-6 0v3.76z'/%3E%3C/svg%3E");
  background-size: 18px 18px;
  background-repeat: no-repeat;
  background-position: center;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

#pin-btn.latched {
  background-color: var(--amber);
  border-color: rgba(0, 0, 0, 0.15);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23001c3c' stroke='%23001c3c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 17v5'/%3E%3Cpath d='M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a3 3 0 0 0-6 0v3.76z'/%3E%3C/svg%3E");
}

.header-buttons,
.search-container {
  flex-shrink: 0;
}

/* ===== Custom TOC picker (replaces native select for wx WebView) ===== */
.toc-picker {
  position: relative;
  flex-shrink: 0;
  width: clamp(140px, 22vw, 280px);
}

.toc-picker__trigger {
  appearance: none;
  width: 100%;
  height: var(--ctrl-h);
  border: var(--ctrl-border);
  border-radius: var(--ctrl-radius);
  background: var(--ctrl-bg);
  color: var(--white);
  font-family: var(--font-sans);
  font-size: var(--ctrl-font);
  padding: 0 32px 0 var(--ctrl-pad-x);
  outline: none;
  box-sizing: border-box;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(255, 255, 255, 0.9) 50%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.9) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) 50%,
    calc(100% - 10px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.toc-picker__trigger:focus {
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(2, 133, 191, 0.35);
}

.toc-picker__list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 2100;
  max-height: min(60vh, 420px);
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--card);
  box-shadow:
    0 12px 28px rgba(0, 28, 60, 0.16),
    0 2px 6px rgba(0, 28, 60, 0.08);
  -webkit-overflow-scrolling: touch;
}

.toc-picker__item {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: rgba(0, 28, 60, 0.82);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  box-sizing: border-box;
}

.toc-picker__item:hover {
  background: var(--light-blue);
}

.toc-picker__item.is-current {
  background: var(--light-blue);
  color: var(--navy);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--blue);
}

.toc-picker__item--level-1 {
  font-weight: 600;
}

.toc-picker__item--level-2 {
  padding-left: 1.25rem;
}

.toc-picker__item--level-3 {
  padding-left: 2rem;
  font-size: 0.8125rem;
}

.toc-picker__item--level-4 {
  padding-left: 2.75rem;
  font-size: 0.8125rem;
}

.fixed-header input[type="text"] {
  height: var(--ctrl-h);
  border: var(--ctrl-border);
  border-radius: var(--ctrl-radius);
  background: rgba(255, 255, 255, 0.95);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: var(--ctrl-font);
  padding: 0 12px;
  outline: none;
  box-sizing: border-box;
}

.fixed-header input[type="text"]:focus {
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(2, 133, 191, 0.35);
}

.search-container {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

#search-box {
  appearance: none;
  font-size: var(--ctrl-font);
  line-height: 1.2;
  height: var(--ctrl-h);
  padding: 0 12px;
  border: var(--ctrl-border);
  border-radius: var(--ctrl-radius);
  background: rgba(255, 255, 255, 0.95);
  color: var(--foreground);
  width: clamp(160px, 24vw, 320px);
  box-sizing: border-box;
}

#search-box::placeholder {
  color: var(--muted-foreground);
}

/* Search results panel — toggled via style.display in script.js */
#search-results {
  position: absolute;
  right: 0;
  left: auto;
  top: calc(100% + 8px);
  width: max(100%, 420px);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--card);
  box-shadow:
    0 12px 28px rgba(0, 28, 60, 0.16),
    0 2px 6px rgba(0, 28, 60, 0.08);
  z-index: 2000;
  max-height: 60vh;
  overflow-y: auto;
}

#search-results h1,
#search-results h2,
#search-results h3,
#search-results h4,
#search-results h5,
#search-results p {
  margin: 6px 0 4px;
}

#search-results > * {
  padding: 8px 12px;
  border-radius: 0;
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1.45;
  color: rgba(0, 28, 60, 0.82);
}

#search-results .is-heading {
  color: var(--navy);
  border-left: 3px solid var(--blue);
  padding-left: 10px;
  font-weight: 600;
}

#search-results > *:nth-child(odd) {
  background-color: var(--background);
}

#search-results > *:nth-child(even) {
  background-color: var(--card);
}

#search-results > *:hover {
  background-color: var(--light-blue);
}

#search-results mark.__hit {
  background: #ffe9a8;
  padding: 0 2px;
  border-radius: 2px;
}

@media (max-width: 720px) {
  .fixed-header {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-h);
    padding: 8px 10px;
    gap: 8px;
  }

  .fixed-header h1 {
    order: -1;
    flex: 1 1 100%;
  }

  #search-results {
    right: 6px;
    left: 6px;
    width: auto;
    max-width: none;
  }
}

@media (max-width: 600px) {
  #search-results {
    right: 6px;
    left: 6px;
    width: auto;
    max-width: none;
  }
}
