/* ═══════════════════════════════════════════════════════════════
   SAA ENHANCEMENTS  v1.0.0
   Utility layer loaded on all exam pages.
   Rules here must never override existing style.css selectors —
   they are additive only.
═══════════════════════════════════════════════════════════════ */

/* ─── 1. REDUCED MOTION ──────────────────────────────────────────────────── */
/*
  Respects the OS-level "reduce motion" accessibility preference.
  Every animation/transition added by enhancement scripts must use
  one of the classes below, or check this media query itself.
*/
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration:        0.01ms !important;
    animation-iteration-count: 1      !important;
    transition-duration:       0.01ms !important;
    scroll-behavior:           auto   !important;
  }
}

/* ─── 2. SEARCH HIGHLIGHT ────────────────────────────────────────────────── */
/*
  Applied by the search feature to wrap matching text.
  Two variants: light-mode uses yellow, dark-mode uses amber.
*/
.saa-highlight {
  background-color: #fef08a; /* yellow-200 */
  color:            #1a1a1a;
  border-radius:    2px;
  padding:          0 2px;
  /* fade-out transition used after 2 s */
  transition:       background-color 0.6s ease, color 0.6s ease;
}

/* Dark theme override */
html:not(.light) .saa-highlight {
  background-color: #b45309; /* amber-700 */
  color:            #fff;
}

/* After the JS removes the class, we want a smooth fade */
.saa-highlight-fading {
  background-color: transparent !important;
  color:            inherit     !important;
}

/* ─── 3. SCREEN-READER-ONLY ─────────────────────────────────────────────── */
/*
  Visually hide an element while keeping it accessible to assistive tech.
  Use for labels on icon-only controls and live-region announcements.
*/
.saa-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;
}

/* ─── 4. FOCUS RING ─────────────────────────────────────────────────────── */
/*
  All new interactive elements added by enhancement scripts must carry
  the class saa-focusable so they get a consistent, visible focus ring.
  Uses :focus-visible so the ring only shows for keyboard navigation.
*/
.saa-focusable:focus-visible {
  outline:        2px solid var(--accent, #0070f3);
  outline-offset: 3px;
  border-radius:  3px;
}

/* Remove the default browser outline when our custom one is active */
.saa-focusable:focus:not(:focus-visible) {
  outline: none;
}

/* ─── 5. SCROLL PROGRESS BAR ─────────────────────────────────────────────── */
#saa-scroll-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  z-index: 9999;
  pointer-events: none;
  transition: width 0.1s linear, background-color 0.3s ease;
}

/* ─── 6. DOMAIN TAB TOOLTIPS ─────────────────────────────────────────────── */
.saa-tab-tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--surface2, #111);
  border: 1px solid var(--border, #333);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  min-width: 110px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.saa-tab-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.saa-tt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.2rem;
  padding: 0.18rem 0;
  color: var(--muted, #888);
  line-height: 1.4;
}

.saa-tt-row strong {
  color: var(--accent, #0070f3);
  font-weight: 600;
}

/* ─── 7. ACTIVE TASK HIGHLIGHTING ────────────────────────────────────────── */
.tlink.active-task {
  color: var(--accent) !important;
  border-left: 2px solid var(--accent) !important;
  font-weight: 700 !important;
  background: rgba(0, 112, 243, 0.08) !important;
  border-radius: 0 3px 3px 0;
}

/* tlink needs flex so the review badge can sit at the right edge */
.tlink {
  display: flex !important;
  align-items: center;
  gap: 0.4rem;
}

/* ─── 8. CARD REVIEW BUTTON ──────────────────────────────────────────────── */
.saa-card-review-footer {
  padding: 0.55rem 1.4rem 0.8rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.saa-review-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.28rem 0.75rem;
  border-radius: 5px;
  font-size: 0.81rem;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 32px;
  line-height: 1.4;
}

.saa-review-btn:hover:not(.reviewed) {
  border-color: var(--accent3);
  color: var(--accent3);
}

.saa-review-btn.reviewed {
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.4);
  color: #34d399;
  font-weight: 600;
}

/* Persistent ✓ indicator in card header — invisible until card is reviewed */
.saa-reviewed-indicator {
  font-size: 0.72rem;
  color: transparent;
  flex-shrink: 0;
  transition: color 0.25s;
  margin-left: auto;
}

.card[data-reviewed="true"] .saa-reviewed-indicator {
  color: #34d399;
}

/* ─── 9. SIDEBAR REVIEW BADGE ────────────────────────────────────────────── */
.saa-review-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  padding: 0.08rem 0.38rem;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  margin-left: auto;
}

.saa-review-badge.complete {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.4);
  color: #34d399;
}

/* ─── 10. FIRST-LOAD HINTS ───────────────────────────────────────────────── */
@keyframes saa-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 112, 243, 0); }
  50%       { box-shadow: 0 0 0 4px rgba(0, 112, 243, 0.35); }
}

.saa-hint-pulse {
  animation: saa-pulse 1.1s ease-in-out 2;
}

.saa-hint-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  color: var(--accent);
  font-style: italic;
  white-space: nowrap;
  flex-shrink: 0;
  opacity: 1;
  transition: opacity 0.6s ease;
}

.saa-hint-label.fading {
  opacity: 0;
}

/* ─── 11. KNOWLEDGE / SKILLS LABELS ─────────────────────────────────────── */
.saa-lbl-knowledge {
  color: #60a5fa !important;
}
html.light .saa-lbl-knowledge {
  color: #1d4ed8 !important;
}

.saa-lbl-skills {
  color: #4ade80 !important;
}
html.light .saa-lbl-skills {
  color: #15803d !important;
}

.saa-ks-legend {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  color: var(--muted);
  margin-bottom: 0.7rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.saa-ks-legend span { white-space: nowrap; }

/* ─── 12. MCQ CLICKABLE OPTIONS ──────────────────────────────────────────── */
.saa-mcq-option {
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
  list-style: none;
}

/* Hover only when the container hasn't been answered yet */
.mcq-container:not([data-answered]) .saa-mcq-option:hover {
  background-color: var(--surface2, rgba(255,255,255,0.05));
  border-color: var(--border, #333);
}

.saa-opt-correct {
  background-color: rgba(52, 211, 153, 0.12) !important;
  border-color:     rgba(52, 211, 153, 0.5)  !important;
  color:            #34d399                  !important;
}

.saa-opt-wrong {
  background-color: rgba(239, 68, 68, 0.12) !important;
  border-color:     rgba(239, 68, 68, 0.5)  !important;
  color:            #f87171                 !important;
}

/* Bold the option the user actually selected */
.saa-opt-selected {
  font-weight: 700;
}

/* Light-mode overrides */
html.light .saa-opt-correct {
  background-color: rgba(22, 163, 74, 0.12) !important;
  border-color:     rgba(22, 163, 74, 0.5)  !important;
  color:            #16a34a                 !important;
}

html.light .saa-opt-wrong {
  background-color: rgba(220, 38, 38, 0.12) !important;
  border-color:     rgba(220, 38, 38, 0.5)  !important;
  color:            #dc2626                 !important;
}

/* ─── 13. MCQ SCORE HEADER ───────────────────────────────────────────────── */
.saa-score-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         0.4rem 0.8rem;
  background:      var(--surface2, #111);
  border:          1px solid var(--border, #333);
  border-radius:   6px;
  margin-bottom:   0.75rem;
  font-family:     'JetBrains Mono', monospace;
  font-size:       0.78rem;
}

.saa-score-value { color: var(--muted, #888); }
.saa-score-good  { color: #34d399 !important; }
.saa-score-poor  { color: #f59e0b !important; }

.saa-score-reset {
  background:  transparent;
  border:      1px solid var(--border, #333);
  color:       var(--muted, #888);
  padding:     0.15rem 0.55rem;
  border-radius: 4px;
  font-size:   0.72rem;
  font-family: 'JetBrains Mono', monospace;
  cursor:      pointer;
  transition:  border-color 0.2s, color 0.2s;
  flex-shrink: 0;
}

.saa-score-reset:hover {
  border-color: #f87171;
  color:        #f87171;
}

/* ─── 14. MCQ SIDEBAR BADGE ──────────────────────────────────────────────── */
.saa-mcq-badge {
  font-family:  'JetBrains Mono', monospace;
  font-size:    0.7rem;
  padding:      0.08rem 0.38rem;
  border-radius: 10px;
  background:   var(--surface2);
  border:       1px solid var(--border);
  color:        var(--muted);
  white-space:  nowrap;
  flex-shrink:  0;
  transition:   background 0.2s, color 0.2s, border-color 0.2s;
}

.saa-mcq-badge.in-progress {
  background:   rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.4);
  color:        #f59e0b;
}

.saa-mcq-badge.complete {
  background:   rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.4);
  color:        #34d399;
}

/* ─── 15. QUIZ MODE — MCQ OPTION REVEAL ──────────────────────────────────── */

/* In quiz mode: hide option list until user reveals it */
body.quiz-mode .mcq-options { display: none; }

/* Revealed via button click, or already answered */
body.quiz-mode .mcq-options.saa-opts-revealed,
body.quiz-mode .mcq-container[data-answered] .mcq-options { display: block; }

/* "Show Options" button: hidden normally, shown only in quiz mode */
.saa-show-options-btn {
  display:       none;
  align-items:   center;
  gap:           0.4rem;
  background:    transparent;
  border:        1px solid var(--border, #333);
  color:         var(--accent, #0070f3);
  padding:       0.28rem 0.75rem;
  border-radius: 5px;
  font-size:     0.81rem;
  font-family:   'JetBrains Mono', monospace;
  cursor:        pointer;
  transition:    background 0.2s, border-color 0.2s;
  margin:        0.5rem 0;
}

body.quiz-mode .saa-show-options-btn { display: inline-flex; }

/* Hide button once used, or if question already answered */
body.quiz-mode .saa-show-options-btn.saa-used,
body.quiz-mode .mcq-container[data-answered] .saa-show-options-btn { display: none; }

.saa-show-options-btn:hover {
  background:   rgba(0, 112, 243, 0.08);
  border-color: var(--accent, #0070f3);
}

/* ─── 16. SEARCH MODAL ───────────────────────────────────────────────────── */
.saa-search-overlay {
  display:         none;
  position:        fixed;
  inset:           0;
  z-index:         10000;
  background:      rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  align-items:     flex-start;
  justify-content: center;
  padding-top:     12vh;
}
.saa-search-overlay.open { display: flex; }
body.saa-search-open     { overflow: hidden; }

.saa-search-box {
  background:     var(--surface, #0a0a0a);
  border:         1px solid var(--border, #333);
  border-radius:  12px;
  width:          100%;
  max-width:      640px;
  box-shadow:     0 20px 60px rgba(0, 0, 0, 0.6);
  display:        flex;
  flex-direction: column;
  max-height:     70vh;
  overflow:       hidden;
}
html.light .saa-search-box { box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18); }

.saa-search-input-row {
  display:     flex;
  align-items: center;
  gap:         0.75rem;
  padding:     0.9rem 1.1rem;
  border-bottom: 1px solid var(--border, #333);
  flex-shrink: 0;
}
.saa-search-icon { width: 18px; height: 18px; color: var(--muted, #888); flex-shrink: 0; }

#saa-search-input {
  flex:        1;
  background:  transparent;
  border:      none;
  outline:     none;
  color:       var(--text, #ededed);
  font-size:   1.05rem;
  font-family: 'Sora', sans-serif;
  line-height: 1.4;
}
#saa-search-input::placeholder { color: var(--muted, #888); }

.saa-search-esc-hint {
  font-family:   'JetBrains Mono', monospace;
  font-size:     0.72rem;
  background:    var(--surface2, #111);
  border:        1px solid var(--border, #333);
  border-radius: 3px;
  padding:       0.1rem 0.4rem;
  color:         var(--muted, #888);
  flex-shrink:   0;
}

.saa-search-results {
  list-style: none;
  padding:    0;
  margin:     0;
  overflow-y: auto;
  flex:       1;
}

.saa-search-result {
  display:        flex;
  flex-direction: column;
  gap:            0.15rem;
  padding:        0.65rem 1.1rem;
  cursor:         pointer;
  border-bottom:  1px solid var(--border, #333);
  transition:     background 0.1s;
}
.saa-search-result:last-child       { border-bottom: none; }
.saa-search-result:hover,
.saa-search-result.saa-sr-selected  { background: var(--surface2, #111); }

.saa-sr-main  { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.saa-sr-title { font-size: 0.95rem; font-weight: 600; color: var(--text, #ededed); }
.saa-sr-meta  {
  font-family: 'JetBrains Mono', monospace;
  font-size:   0.71rem;
  color:       var(--muted, #888);
}
.saa-sr-excerpt {
  font-size:     0.82rem;
  color:         var(--muted, #888);
  white-space:   nowrap;
  overflow:      hidden;
  text-overflow: ellipsis;
}
mark.saa-hl {
  background:    rgba(255, 210, 0, 0.22);
  color:         inherit;
  border-radius: 2px;
  padding:       0 1px;
}
html.light mark.saa-hl { background: rgba(255, 160, 0, 0.28); }

.saa-search-empty {
  padding:    1.2rem 1.1rem;
  color:      var(--muted, #888);
  font-size:  0.9rem;
  text-align: center;
}

.saa-search-footer {
  display:     flex;
  gap:         1.2rem;
  padding:     0.5rem 1.1rem;
  border-top:  1px solid var(--border, #333);
  font-family: 'JetBrains Mono', monospace;
  font-size:   0.71rem;
  color:       var(--muted, #888);
  flex-shrink: 0;
}
.saa-search-footer kbd {
  background:    var(--surface2, #111);
  border:        1px solid var(--border, #333);
  border-radius: 3px;
  padding:       0 0.3rem;
  font-size:     0.69rem;
}

/* ─── 17. PROGRESS DASHBOARD ─────────────────────────────────────────────── */
#saa-dashboard-btn {
  background:  var(--surface2);
  border:      1px solid var(--border);
  color:       var(--muted);
  padding:     0.6rem 1rem;
  border-radius: 6px;
  cursor:      pointer;
  font-family: 'Sora', sans-serif;
  font-size:   0.85rem;
  transition:  all 0.2s;
}
#saa-dashboard-btn:hover { border-color: var(--accent2); color: var(--accent2); }

.saa-dashboard-overlay {
  display:         none;
  position:        fixed;
  inset:           0;
  z-index:         10001;
  background:      rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  align-items:     center;
  justify-content: center;
  padding:         2rem;
}
.saa-dashboard-overlay.open { display: flex; }
body.saa-db-open             { overflow: hidden; }

.saa-db-panel {
  background:     var(--surface, #0a0a0a);
  border:         1px solid var(--border, #333);
  border-radius:  12px;
  width:          100%;
  max-width:      780px;
  max-height:     82vh;
  display:        flex;
  flex-direction: column;
  box-shadow:     0 24px 64px rgba(0, 0, 0, 0.6);
  overflow:       hidden;
}

.saa-db-hdr {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         1rem 1.4rem;
  border-bottom:   1px solid var(--border);
  flex-shrink:     0;
}
.saa-db-title {
  font-family: 'Sora', sans-serif;
  font-size:   1.05rem;
  font-weight: 700;
  color:       var(--h1);
}
.saa-db-close {
  background:    transparent;
  border:        1px solid var(--border);
  color:         var(--muted);
  width:         28px; height: 28px;
  border-radius: 50%;
  cursor:        pointer;
  font-size:     0.9rem;
  display:       flex; align-items: center; justify-content: center;
  transition:    all 0.2s;
}
.saa-db-close:hover { border-color: var(--accent4); color: var(--accent4); }

.saa-db-body { overflow-y: auto; padding: 1.2rem 1.4rem; flex: 1; }

.saa-db-overview {
  display:       flex;
  gap:           1rem;
  margin-bottom: 1.4rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--border);
}
.saa-db-ov-item {
  flex:          1;
  background:    var(--surface2);
  border:        1px solid var(--border);
  border-radius: 8px;
  padding:       0.85rem 1.1rem;
  display:       flex;
  align-items:   center;
  gap:           0.8rem;
}
.saa-db-ov-num {
  font-family: 'JetBrains Mono', monospace;
  font-size:   2rem;
  font-weight: 700;
  color:       var(--accent);
  flex-shrink: 0;
  line-height: 1;
}
.saa-db-ov-num.saa-db-ov-good { color: #34d399; }
.saa-db-ov-lbl {
  font-size:   0.84rem;
  color:       var(--muted);
  line-height: 1.4;
}
.saa-db-ov-lbl small { font-family: 'JetBrains Mono', monospace; font-size: 0.71rem; }

.saa-db-pages  { display: flex; flex-direction: column; gap: 0.85rem; }
.saa-db-pg {
  background:    var(--surface2);
  border:        1px solid var(--border);
  border-left:   3px solid var(--pg-color, var(--border));
  border-radius: 8px;
  padding:       0.9rem 1.1rem;
}
.saa-db-pg-hdr  { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.65rem; }
.saa-db-pg-badge {
  font-family:   'JetBrains Mono', monospace;
  font-size:     0.71rem;
  padding:       0.1rem 0.42rem;
  border-radius: 3px;
  background:    rgba(255,255,255,0.05);
  border:        1px solid var(--pg-color, var(--border));
  color:         var(--pg-color, var(--muted));
}
.saa-db-pg-name { font-size: 0.9rem; font-weight: 600; color: var(--text); flex: 1; }
.saa-db-pg-curr {
  font-family:   'JetBrains Mono', monospace;
  font-size:     0.68rem;
  color:         var(--accent);
  border:        1px solid var(--accent);
  border-radius: 10px;
  padding:       0.04rem 0.42rem;
}
.saa-db-pg-none { font-size: 0.84rem; color: var(--muted); font-style: italic; }
.saa-db-pg-stats { display: flex; flex-direction: column; gap: 0.42rem; }
.saa-db-row { display: flex; align-items: center; gap: 0.7rem; }
.saa-db-row-lbl {
  font-family: 'JetBrains Mono', monospace;
  font-size:   0.76rem;
  color:       var(--muted);
  width:       112px;
  flex-shrink: 0;
}
.saa-db-bar {
  flex:          1;
  height:        5px;
  background:    var(--border);
  border-radius: 3px;
  overflow:      hidden;
}
.saa-db-bar-fill {
  height:        100%;
  background:    var(--accent);
  border-radius: 3px;
  transition:    width 0.5s ease;
  min-width:     0;
}
.saa-db-row-val {
  font-family: 'JetBrains Mono', monospace;
  font-size:   0.74rem;
  color:       var(--text);
  white-space: nowrap;
  width:       82px;
  text-align:  right;
  flex-shrink: 0;
}

/* ─── 18. READING TIME ───────────────────────────────────────────────────── */
.saa-reading-time {
  font-family:   'JetBrains Mono', monospace;
  font-size:     0.73rem;
  color:         var(--muted);
  background:    var(--surface2);
  border:        1px solid var(--border);
  border-radius: 10px;
  padding:       0.06rem 0.5rem;
  display:       inline-block;
  margin-top:    0.45rem;
}

/* ─── 19. SKIP LINK ──────────────────────────────────────────────────────── */
.saa-skip-link {
  position:      absolute;
  top:           -100px;
  left:          1rem;
  z-index:       99999;
  background:    var(--accent, #0070f3);
  color:         #fff;
  padding:       0.5rem 1rem;
  border-radius: 0 0 6px 6px;
  font-size:     0.9rem;
  font-weight:   600;
  text-decoration: none;
  transition:    top 0.2s;
}
.saa-skip-link:focus { top: 0; }

/* ─── 20. PRINT STYLES ───────────────────────────────────────────────────── */
@media print {
  nav,
  .content-toolbar,
  #scrollTopBtn,
  #saa-search-modal,
  #saa-dashboard,
  .saa-card-review-footer,
  .saa-score-header,
  .toc-sidebar,
  #saa-skip-link,
  .saa-hint-label,
  .saa-show-options-btn { display: none !important; }

  .domain-section         { display: block !important; }
  .card-body              { display: block !important; }
  .chev                   { display: none  !important; }
  *                       { transition: none !important; animation: none !important; }

  .domain-section              { page-break-before: always; }
  .domain-section:first-of-type { page-break-before: auto;  }
  .card                        { break-inside: avoid; border-color: #ccc !important; }
  .card-hdr                    { background: #f5f5f5 !important; }

  body { background: #fff !important; color: #111 !important; }
}

/* ─── 21. RESPONSIVE (mobile) ────────────────────────────────────────────── */
@media (max-width: 599px) {
  .saa-search-overlay   { padding-top: 6vh; padding-left: 0.5rem; padding-right: 0.5rem; }
  .saa-search-box       { max-width: 100%; }
  .saa-dashboard-overlay { padding: 0.5rem; }
  .saa-db-panel         { max-height: 90vh; }
  .saa-db-overview      { flex-direction: column; }
  .saa-db-row-lbl       { width: 80px; }
  .saa-db-row-val       { width: 64px; font-size: 0.69rem; }
  .saa-score-header     { flex-wrap: wrap; gap: 0.4rem; }
}
