/**
 * Help Panel Styles — in-app help system for the IRF assessment framework.
 * WCAG 2.1 Level AA compliant: sufficient contrast, focus indicators, responsive.
 * Mobile-responsive: panel becomes full-width below 768px.
 *
 * @version 1.0.0
 */

/* ────────────────────────── Screen reader only ────────────────────────── */
.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;
}

/* ────────────────────────── Help Trigger Button ──────────────────────── */
.help-trigger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #1B3A5C;
  background: #FFFFFF;
  color: #1B3A5C;
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, box-shadow 0.2s;
  line-height: 1;
  flex-shrink: 0;
}

.help-trigger-btn:hover {
  background-color: #1B3A5C;
  color: #FFFFFF;
}

.help-trigger-btn:focus-visible {
  outline: 2px solid #2E6DA4;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(46, 109, 164, 0.25);
}

.help-trigger-fixed {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  font-size: 20px;
  z-index: 9998;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* ────────────────────────── Overlay ──────────────────────────────────── */
.help-panel-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.help-panel-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* ────────────────────────── Panel ────────────────────────────────────── */
.help-panel {
  position: fixed;
  top: 0;
  right: -440px;
  width: 420px;
  max-width: 100vw;
  height: 100vh;
  background: #FFFFFF;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  transition: right 0.25s ease;
  overflow: hidden;
}

.help-panel.open {
  right: 0;
}

/* Prevent body scroll when panel is open */
body.help-panel-open {
  overflow: hidden;
}

/* ── Header ── */
.help-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #E8E8E6;
  background: #FAFAF8;
  flex-shrink: 0;
}

.help-panel-title {
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: #1B3A5C;
  margin: 0;
}

.help-panel-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 24px;
  color: #666666;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.15s, color 0.15s;
  line-height: 1;
}

.help-panel-close:hover {
  background-color: #F0F0EE;
  color: #2C2C2C;
}

.help-panel-close:focus-visible {
  outline: 2px solid #2E6DA4;
  outline-offset: 2px;
}

/* ── Tabs ── */
.help-panel-tabs {
  display: flex;
  border-bottom: 1px solid #E8E8E6;
  background: #FAFAF8;
  flex-shrink: 0;
}

.help-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  color: #666666;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.help-tab:hover {
  color: #2C2C2C;
}

.help-tab.active {
  color: #1B3A5C;
  border-bottom-color: #1B3A5C;
  font-weight: 600;
}

.help-tab:focus-visible {
  outline: 2px solid #2E6DA4;
  outline-offset: -2px;
}

/* ── Body ── */
.help-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.help-content {
  display: none;
  padding: 16px 20px;
}

.help-content.active {
  display: block;
}

/* ────────────────────────── Sections ─────────────────────────────────── */
.help-section {
  margin-bottom: 24px;
}

.help-section-title {
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: #1B3A5C;
  margin: 0 0 12px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid #E8E8E6;
}

/* ────────────────────────── Accordion ────────────────────────────────── */
.help-accordion {
  border: 1px solid #E8E8E6;
  border-radius: 6px;
  margin-bottom: 8px;
  overflow: hidden;
}

.help-accordion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  color: #2C2C2C;
  transition: background-color 0.15s;
  list-style: none;
}

.help-accordion-header::-webkit-details-marker {
  display: none;
}

.help-accordion-header::before {
  content: '\25B6';
  font-size: 0.65rem;
  color: #999;
  transition: transform 0.15s;
  flex-shrink: 0;
}

details[open] > .help-accordion-header::before {
  transform: rotate(90deg);
}

.help-accordion-header:hover {
  background-color: #F5F5F3;
}

.help-accordion-header:focus-visible {
  outline: 2px solid #2E6DA4;
  outline-offset: -2px;
}

.help-accordion-body {
  padding: 8px 14px 14px;
  font-size: 0.85rem;
  color: #444;
  line-height: 1.6;
}

.help-accordion-body p {
  margin: 0 0 8px 0;
}

.help-accordion-body ul {
  margin: 4px 0 8px 20px;
  padding: 0;
}

.help-accordion-body li {
  margin-bottom: 4px;
}

/* ── Step number badge ── */
.help-step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #1B3A5C;
  color: #FFFFFF;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

/* ── Layer badge ── */
.help-layer-badge {
  display: inline-block;
  padding: 2px 8px;
  background: #E8EFF6;
  color: #1B3A5C;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.help-layer-short {
  color: #666;
  font-style: italic;
}

.help-meta {
  font-size: 0.82rem;
  color: #555;
}

.help-tips-inline,
.help-mistakes-inline {
  margin-top: 8px;
  font-size: 0.82rem;
}

.help-tips-inline ul,
.help-mistakes-inline ul {
  margin-top: 4px;
}

.help-mistakes-inline {
  color: #B34700;
}

/* ── Tips box ── */
.help-tips-box {
  background: #F0F7F3;
  border: 1px solid #C8E0D2;
  border-radius: 6px;
  padding: 12px 14px;
  margin-top: 12px;
}

.help-tips-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #3A7D5E;
  margin: 0 0 6px 0;
}

.help-tips-list {
  margin: 0 0 0 18px;
  padding: 0;
  font-size: 0.82rem;
  color: #444;
}

.help-tips-list li {
  margin-bottom: 4px;
}

/* ────────────────────────── Institution Table ────────────────────────── */
.help-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.help-table th {
  background: #F5F5F3;
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  color: #1B3A5C;
  border-bottom: 2px solid #E8E8E6;
  white-space: nowrap;
}

.help-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #E8E8E6;
  vertical-align: top;
}

.help-table tr:hover {
  background: #FAFAF8;
}

.help-table-small {
  font-size: 0.75rem;
  color: #666;
  max-width: 180px;
}

.help-table-center {
  text-align: center;
  font-weight: 600;
}

/* ────────────────────────── Glossary Tab ─────────────────────────────── */
.help-search-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.help-search-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #D0D0CE;
  border-radius: 6px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  color: #2C2C2C;
  background: #FFFFFF;
  transition: border-color 0.15s;
}

.help-search-input:focus {
  outline: none;
  border-color: #2E6DA4;
  box-shadow: 0 0 0 3px rgba(46, 109, 164, 0.15);
}

.help-search-input::placeholder {
  color: #999;
}

.help-search-count {
  font-size: 0.8rem;
  color: #999;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Category filters ── */
.help-category-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}

.help-cat-filter {
  padding: 4px 10px;
  border: 1px solid #D0D0CE;
  border-radius: 20px;
  background: #FFFFFF;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  color: #666;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.help-cat-filter:hover {
  border-color: #2E6DA4;
  color: #2E6DA4;
}

.help-cat-filter.active {
  background: #1B3A5C;
  border-color: #1B3A5C;
  color: #FFFFFF;
}

.help-cat-filter:focus-visible {
  outline: 2px solid #2E6DA4;
  outline-offset: 2px;
}

/* ── Glossary items ── */
.help-glossary-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-glossary-item {
  padding: 10px 12px;
  border: 1px solid #E8E8E6;
  border-radius: 6px;
  transition: border-color 0.15s, background-color 0.3s;
}

.help-glossary-item:hover {
  border-color: #C8D8E8;
}

.help-term-name {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: #1B3A5C;
  margin: 0 0 4px 0;
}

.help-term-definition {
  font-size: 0.82rem;
  color: #444;
  line-height: 1.5;
  margin: 0 0 4px 0;
}

.help-term-usage {
  font-size: 0.78rem;
  color: #777;
  margin: 0 0 4px 0;
}

.help-related-terms {
  font-size: 0.75rem;
  color: #888;
  margin-top: 4px;
}

.help-related-link {
  color: #2E6DA4;
  text-decoration: none;
  cursor: pointer;
}

.help-related-link:hover {
  text-decoration: underline;
}

.help-related-link:focus-visible {
  outline: 2px solid #2E6DA4;
  outline-offset: 1px;
  border-radius: 2px;
}

/* ── Stub terms ── */
.help-term-stub {
  opacity: 0.65;
}

.help-stub-text {
  font-style: italic;
  color: #999;
}

/* ── Highlight animation ── */
.help-term-highlight {
  background-color: #FFF8E1;
  border-color: #FFD54F;
}

/* ────────────────────────── FAQ Tab ──────────────────────────────────── */
.help-faq-category {
  margin-bottom: 20px;
}

.help-faq-category-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: #1B3A5C;
  margin: 0 0 8px 0;
  padding-bottom: 6px;
  border-bottom: 1px solid #E8E8E6;
}

.help-faq-item {
  border: 1px solid #E8E8E6;
  border-radius: 6px;
  margin-bottom: 6px;
  overflow: hidden;
}

.help-faq-question {
  padding: 10px 14px;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: #2C2C2C;
  list-style: none;
  transition: background-color 0.15s;
}

.help-faq-question::-webkit-details-marker {
  display: none;
}

.help-faq-question::before {
  content: '\25B6';
  font-size: 0.6rem;
  color: #999;
  margin-right: 8px;
  transition: transform 0.15s;
  display: inline-block;
}

details[open] > .help-faq-question::before {
  transform: rotate(90deg);
}

.help-faq-question:hover {
  background-color: #F5F5F3;
}

.help-faq-question:focus-visible {
  outline: 2px solid #2E6DA4;
  outline-offset: -2px;
}

.help-faq-answer {
  padding: 8px 14px 14px;
  font-size: 0.82rem;
  color: #444;
  line-height: 1.6;
}

.help-faq-answer p {
  margin: 0 0 6px 0;
}

.help-faq-related {
  margin-top: 8px;
  font-size: 0.75rem;
  color: #888;
}

.help-glossary-link {
  color: #2E6DA4;
  text-decoration: none;
  cursor: pointer;
}

.help-glossary-link:hover {
  text-decoration: underline;
}

.help-glossary-link:focus-visible {
  outline: 2px solid #2E6DA4;
  outline-offset: 1px;
}

/* ────────────────────────── Tooltip ──────────────────────────────────── */
.help-tooltip-trigger {
  border-bottom: 1px dotted #2E6DA4;
  cursor: help;
}

.help-tooltip {
  position: absolute;
  z-index: 10001;
  max-width: 320px;
  padding: 10px 14px;
  background: #1B3A5C;
  color: #FFFFFF;
  border-radius: 6px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
  pointer-events: none;
}

.help-tooltip.visible {
  opacity: 1;
  visibility: visible;
}

.help-tooltip::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #1B3A5C;
}

.help-tooltip.help-tooltip-below::after {
  bottom: auto;
  top: -6px;
  border-top: none;
  border-bottom: 6px solid #1B3A5C;
}

.help-tooltip-term {
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 0.82rem;
}

.help-tooltip-def {
  opacity: 0.9;
}

/* ────────────────────────── Error state ──────────────────────────────── */
.help-error {
  color: #B34700;
  text-align: center;
  padding: 24px;
  font-style: italic;
}

/* ────────────────────────── Responsive ───────────────────────────────── */
@media (max-width: 768px) {
  .help-panel {
    width: 100vw;
    right: -100vw;
  }

  .help-trigger-fixed {
    bottom: 16px;
    right: 16px;
  }

  .help-table {
    font-size: 0.72rem;
  }

  .help-table-small {
    max-width: 120px;
  }

  .help-category-filters {
    gap: 3px;
  }

  .help-cat-filter {
    font-size: 0.7rem;
    padding: 3px 8px;
  }
}

@media (max-width: 480px) {
  .help-panel-header {
    padding: 12px 16px;
  }

  .help-content {
    padding: 12px 16px;
  }

  .help-accordion-header {
    padding: 8px 12px;
    font-size: 0.85rem;
  }

  .help-search-wrapper {
    flex-wrap: wrap;
  }

  .help-search-count {
    width: 100%;
    text-align: right;
  }
}

/* ────────────────────────── Print ────────────────────────────────────── */
@media print {
  .help-panel,
  .help-panel-overlay,
  .help-trigger-btn,
  .help-tooltip {
    display: none !important;
  }
}

/* ────────────────────────── Reduced motion ───────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .help-panel,
  .help-panel-overlay,
  .help-tooltip,
  .help-accordion-header::before,
  .help-faq-question::before {
    transition: none;
  }
}

/* ────────────────────────── High contrast ────────────────────────────── */
@media (forced-colors: active) {
  .help-trigger-btn {
    border: 2px solid ButtonText;
  }

  .help-tab.active {
    border-bottom-color: Highlight;
  }

  .help-glossary-item {
    border-color: ButtonText;
  }

  .help-tooltip {
    border: 1px solid ButtonText;
  }
}
