/* ============================================
   Usage Guide Modal — Shared across all pages
   ============================================ */

/* The canonical "Help & Usage Guide" opener (shared/_guide_button) is the plain
   .btn.btn-sm.btn-secondary look plus a red question mark; .guide-btn is the
   hook for page-specific placement only, never a restyle. */
.guide-btn-icon { line-height: 1; }
/* Pages that put the button beside the <h1> rather than in .page-header-actions. */
h1 .guide-btn {
  margin-left: 10px;
  vertical-align: middle;
}

.guide-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
/* `display: flex` above beats the UA's [hidden] rule — restore it so guides
   can hide via the hidden attribute instead of an inline style. */
.guide-modal-overlay[hidden] { display: none; }
.guide-modal {
  background: var(--surface, #fff);
  border-radius: 12px;
  width: 100%;
  max-width: 880px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}
.guide-modal--wide { max-width: 960px; }
.guide-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border, #e8e6e1);
  flex-shrink: 0;
}
.guide-modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}
.guide-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--muted, #8a8a8a);
  padding: 0 4px;
  line-height: 1;
}
.guide-modal-close:hover { color: var(--ink, #2d2d2d); }
.guide-modal-body {
  padding: 24px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.7;
}
.guide-modal-body .guide-intro {
  font-size: 14px;
  color: var(--stone, #555);
  margin: 0 0 20px;
  line-height: 1.7;
}
.guide-modal-body h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 24px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light, #f0eeea);
}
.guide-modal-body h3:first-of-type { margin-top: 0; }
.guide-modal-body h4 {
  font-size: 13px;
  font-weight: 700;
  margin: 14px 0 4px;
  color: var(--stone, #555);
}
.guide-modal-body ul, .guide-modal-body ol {
  margin: 0 0 10px;
  padding-left: 20px;
}
.guide-modal-body li { margin-bottom: 4px; }
.guide-section {
  padding-left: 4px;
}
.guide-formula {
  padding: 8px 12px;
  background: var(--surface-alt);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.guide-table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
  margin-top: 8px;
}
.guide-table th {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}
.guide-table td {
  padding: 4px 8px;
}

@media (max-width: 768px) {
  .guide-modal { max-width: 100%; max-height: 90vh; }
  .guide-modal-overlay { padding: 12px; }
}

/* Guide footer (shared/_guide_footer): last-edited date + "settings as of"
   timestamp. Sits after the scrolling body, so it stays visible on screen and
   prints at the end of the guide. */
.guide-footer {
  flex: none;
  padding: 10px 24px;
  border-top: 1px solid var(--border-light, #f0eeea);
  font-size: 11px;
  color: var(--muted, #8a8a8a);
}
.guide-footer-sep { margin: 0 6px; }

/* ============================================
   Print button + print-only-the-guide mode
   (guide_print_controller.js tags the modal root
   .guide-print-target and its ancestors
   .guide-print-path, then calls window.print())
   ============================================ */
.guide-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.guide-print-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex: none;
}
.guide-print-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

@media print {
  body.guide-printing {
    background: #fff !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* Hide everything that is not on the path down to the guide. */
  body.guide-printing > :not(.guide-print-path):not(.guide-print-target),
  body.guide-printing .guide-print-path > :not(.guide-print-path):not(.guide-print-target) {
    display: none !important;
  }

  /* Ancestors: flatten any app-shell layout/scroll containers. */
  body.guide-printing .guide-print-path {
    display: block !important;
    position: static !important;
    overflow: visible !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
  }

  /* The modal shell: no fixed overlay, no dimmed backdrop. */
  body.guide-printing .guide-print-target {
    display: block !important;
    position: static !important;
    inset: auto !important;
    padding: 0 !important;
    background: none !important;
    animation: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  /* The dialog card: full page width, no shadow/rounding. */
  body.guide-printing .guide-print-target > * {
    position: static !important;
    width: auto !important;
    max-width: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    animation: none !important;
    transform: none !important;
  }
  /* Un-clip every scroll box so the whole guide flows across pages. */
  body.guide-printing .guide-print-target * {
    max-height: none !important;
    overflow: visible !important;
  }

  /* No controls on paper: the header actions and any in-guide buttons ("Got it", guide switchers). */
  body.guide-printing .guide-print-target .guide-header-actions,
  body.guide-printing .guide-print-target button { display: none !important; }
  body.guide-printing .guide-print-target h2,
  body.guide-printing .guide-print-target h3,
  body.guide-printing .guide-print-target h4 { break-after: avoid; }
  body.guide-printing .guide-print-target table,
  body.guide-printing .guide-print-target pre,
  body.guide-printing .guide-print-target .guide-formula { break-inside: avoid; }
}
