/*
 * QuadraEdge.LMS — Accessibility & UX Layer  (qe-a11y.css)
 * ---------------------------------------------------------------------------
 * Load AFTER qe-v3.css. This layer adds the production-grade accessibility
 * and learner-UX behaviour the base design system was missing, WITHOUT
 * touching qe-v3.css, so it can be deployed and rolled back in isolation.
 *
 * It delivers, site-wide:
 *   1. Visible keyboard focus on every interactive element (fixes outline:none).
 *   2. A skip-to-content link.
 *   3. Status indicators that carry meaning in TEXT + SHAPE, never colour alone.
 *   4. Accessible quiz option cards and result-review styling.
 *   5. Course-map / focus-mode / resume components for the learner screens.
 *   6. Reduced-motion and high-contrast user-preference support.
 *
 * Every value inherits from the qe-v3 token system. No hardcoded brand colours.
 * ========================================================================= */

:root {
  --focus-ring:        #1d4ed8;   /* cobalt-deep — 3:1+ against white & off-white */
  --focus-ring-light:  #ffffff;   /* for dark navs / heroes */
  --status-done-bg:    #dcfce7;
  --status-done-ink:   #14532d;   /* ~10:1 on the bg above */
  --status-prog-bg:    #fef9c3;
  --status-prog-ink:   #854d0e;   /* ~8:1 */
  --status-todo-bg:    #eef2f7;
  --status-todo-ink:   #334155;   /* ~9:1 */
}

/* ═══════════════════════════════════════════════════════
   1 · KEYBOARD FOCUS  (the unplug-the-mouse test)
   :focus-visible only fires for keyboard / programmatic focus, so mouse
   users never see a ring, but keyboard & screen-reader users always do.
   These selectors are 1-class+1-pseudo (0,2,0) and therefore override the
   (0,1,0) `outline:none` declarations already in qe-v3.css with no !important.
═══════════════════════════════════════════════════════ */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
.btn:focus-visible,
.form-control:focus-visible,
.nav-links a:focus-visible,
.nav-pill:focus-visible,
.nav-lang:focus-visible,
.nav-toggle:focus-visible,
.filter-pill:focus-visible,
.search-input:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--r-xs, 6px);
}

/* On dark surfaces a cobalt ring disappears — switch to a white ring. */
.qe-nav :focus-visible,
.on-dark :focus-visible,
.hero :focus-visible,
.learn-hero :focus-visible,
.dash-hero :focus-visible,
.section-dark :focus-visible,
.auth-left :focus-visible,
.qe-footer :focus-visible {
  outline-color: var(--focus-ring-light);
}

/* Inputs already carry a soft inner glow on :focus; keep it and add the
   sharp outer ring only for keyboard focus so the field stays obvious. */
.form-control:focus-visible {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .18);
}

/* ═══════════════════════════════════════════════════════
   2 · SKIP LINK
═══════════════════════════════════════════════════════ */
.qe-skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 1000;
  transform: translateY(-160%);
  background: var(--cobalt);
  color: #fff;
  font-family: var(--font-d);
  font-weight: 700;
  font-size: .9rem;
  padding: 12px 20px;
  border-radius: var(--r-sm);
  box-shadow: var(--sh-lg);
  transition: transform 160ms cubic-bezier(.25, .8, .25, 1);
  text-decoration: none;
}
.qe-skip-link:focus {
  transform: translateY(0);
  outline: 3px solid #fff;
  outline-offset: 2px;
}
[dir="rtl"] .qe-skip-link { left: auto; right: 8px; }

/* A focus target landed on by the skip link should not draw its own box. */
:target,
[tabindex="-1"]:focus { outline: none; }

/* ═══════════════════════════════════════════════════════
   3 · STATUS PILLS — colour + icon + TEXT (colour-blind safe)
   Use anywhere a "where am I" signal is needed: dashboards, course maps,
   lesson lists. The label text is mandatory; colour is reinforcement only.
═══════════════════════════════════════════════════════ */
.qe-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-d);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .01em;
  padding: 3px 10px 3px 8px;
  border-radius: var(--r-pill);
  line-height: 1.4;
  white-space: nowrap;
}
.qe-status::before {
  font-size: .8em;
  font-weight: 900;
  line-height: 1;
}
.qe-status--done   { background: var(--status-done-bg); color: var(--status-done-ink); }
.qe-status--done::before   { content: "\2713"; }              /* ✓ */
.qe-status--prog   { background: var(--status-prog-bg); color: var(--status-prog-ink); }
.qe-status--prog::before   { content: "\25D0"; }              /* ◐ half-filled */
.qe-status--todo   { background: var(--status-todo-bg); color: var(--status-todo-ink); }
.qe-status--todo::before   { content: "\25CB"; }              /* ○ */
.qe-status--locked { background: var(--status-todo-bg); color: var(--status-todo-ink); }
.qe-status--locked::before { content: "\1F512"; }            /* 🔒 */

/* High-contrast border so the pill survives forced-colours / greyscale. */
@media (forced-colors: active) {
  .qe-status { border: 1px solid currentColor; }
}

/* ═══════════════════════════════════════════════════════
   4 · PROGRESS BAR — works with role="progressbar"
   Keeps the qe-v3 look but makes the fill readable and adds a colour-blind
   safe striped texture option for the "in progress" state.
═══════════════════════════════════════════════════════ */
.progress[role="progressbar"] { position: relative; }
.progress-fill-prog {
  background: var(--warn, #d97706);
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, .25) 0,
    rgba(255, 255, 255, .25) 6px,
    transparent 6px,
    transparent 12px
  );
}
.progress-fill-done { background: var(--success, #16a34a); }

/* ═══════════════════════════════════════════════════════
   5 · ACCESSIBLE QUIZ OPTION CARDS
   The whole row is the click/tap target (≥44px). Selected state is shown by
   a filled control + border + tint + a check glyph — four redundant signals,
   not colour alone. Native radio/checkbox stays in the DOM for AT + keyboard.
═══════════════════════════════════════════════════════ */
.qe-question {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 20px;
  margin: 0 0 16px;
  box-shadow: var(--sh-xs);
}
.qe-question > legend,
.qe-question .qe-q-text {
  font-family: var(--font-d);
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--ink);
  line-height: 1.45;
  margin-bottom: 14px;
  padding: 0;
}
.qe-q-num {
  display: inline-block;
  min-width: 1.6em;
  color: var(--cobalt);
  font-weight: 800;
}
.qe-options { display: grid; gap: 10px; }
.qe-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 44px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--t), background var(--t);
}
.qe-option:hover { border-color: var(--cobalt-lt); background: var(--cobalt-pale); }
.qe-option input { margin-top: 2px; width: 18px; height: 18px; accent-color: var(--cobalt); flex-shrink: 0; }
.qe-option-text { color: var(--ink-2); line-height: 1.5; }
/* Selected card: the :has() selector lights the whole card on modern browsers;
   the input's own accent-color covers everywhere else. */
.qe-option:has(input:checked) {
  border-color: var(--cobalt);
  background: var(--cobalt-pale);
  box-shadow: inset 0 0 0 1px var(--cobalt);
}
.qe-option:has(input:focus-visible) {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Live "answered N of M" helper bar */
.qe-quiz-progress {
  position: sticky;
  top: calc(var(--nav-h) + 8px);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px 16px;
  margin-bottom: 18px;
  box-shadow: var(--sh-sm);
}
.qe-quiz-progress .progress { flex: 1; height: 8px; }
.qe-quiz-count { font-family: var(--font-d); font-weight: 700; font-size: .85rem; color: var(--ink-2); white-space: nowrap; }

/* ═══════════════════════════════════════════════════════
   6 · ASSESSMENT REVIEW — explicit [Correct] / [Incorrect]
   Verdict is a TEXT label first; the colour and the left bar are extra.
   Incorrect uses a dashed bar so it differs from Correct in greyscale too.
═══════════════════════════════════════════════════════ */
.qe-review-item {
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px 18px 18px 22px;
  margin-bottom: 14px;
  background: var(--surface);
  border-left: 6px solid var(--muted-lt);
}
.qe-review-item.is-correct   { border-left: 6px solid var(--success); border-left-style: solid; }
.qe-review-item.is-incorrect { border-left: 6px dashed var(--danger); }
.qe-verdict {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-d);
  font-weight: 800;
  font-size: .76rem;
  letter-spacing: .03em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  margin-bottom: 10px;
}
.qe-verdict--correct   { background: var(--status-done-bg); color: var(--status-done-ink); }
.qe-verdict--correct::before   { content: "\2713 "; }
.qe-verdict--incorrect { background: var(--danger-pale); color: #991b1b; }
.qe-verdict--incorrect::before { content: "\2717 "; }
.qe-review-q { font-family: var(--font-d); font-weight: 700; color: var(--ink); margin: 4px 0 12px; line-height: 1.45; }
.qe-answer-row { display: flex; gap: 8px; font-size: .9rem; margin: 4px 0; color: var(--ink-2); }
.qe-answer-row .lbl { color: var(--muted); min-width: 122px; font-weight: 600; }
.qe-answer-row .val { font-weight: 600; }
.qe-answer-row .val.correct { color: var(--status-done-ink); }
.qe-answer-row .val.wrong   { color: #991b1b; text-decoration: line-through; text-decoration-color: rgba(153,27,27,.5); }
.qe-explain {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--off-white);
  border-radius: var(--r-sm);
  font-size: .9rem;
  color: var(--ink-3);
  line-height: 1.6;
}
.qe-explain b { color: var(--ink); }

.qe-score-hero {
  text-align: center;
  padding: 30px 24px;
  border-radius: var(--r-lg);
  margin-bottom: 22px;
  border: 1px solid var(--line);
}
.qe-score-hero.passed     { background: var(--status-done-bg); border-color: #86efac; }
.qe-score-hero.not-passed { background: var(--danger-pale); border-color: #fecaca; }
.qe-score-num { font-family: var(--font-d); font-size: 3rem; font-weight: 800; line-height: 1; color: var(--ink); }
.qe-score-verdict { font-family: var(--font-d); font-weight: 800; font-size: 1.05rem; margin-top: 8px; }
.qe-score-hero.passed .qe-score-verdict     { color: var(--status-done-ink); }
.qe-score-hero.not-passed .qe-score-verdict { color: #991b1b; }

/* ═══════════════════════════════════════════════════════
   7 · COURSE MAP (learn.php) — vertical progress tree
═══════════════════════════════════════════════════════ */
.qe-coursemap { display: flex; flex-direction: column; gap: 2px; }
.qe-coursemap a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-weight: 600;
  font-size: .9rem;
  line-height: 1.35;
  transition: background var(--t);
}
.qe-coursemap a:hover { background: var(--off-white); }
.qe-coursemap a[aria-current="true"] {
  background: var(--cobalt-pale);
  color: var(--cobalt-deep);
  box-shadow: inset 3px 0 0 var(--cobalt);
}
.qe-map-dot {
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 900;
  border: 1.5px solid var(--line);
  color: var(--muted);
  background: var(--surface);
}
.qe-map-dot.done { background: var(--success); border-color: var(--success); color: #fff; }
.qe-map-dot.done::before { content: "\2713"; }
.qe-map-dot.todo::before { content: ""; }
.qe-map-num { font-size: .72rem; }

/* Focus mode: collapse the map for distraction-free reading */
.learn-layout.focus-mode { grid-template-columns: 1fr; }
.learn-layout.focus-mode .lesson-list { display: none; }
.qe-focus-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-pill);
  padding: 8px 16px;
  font-family: var(--font-d);
  font-weight: 700;
  font-size: .82rem;
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color var(--t), color var(--t);
}
.qe-focus-toggle:hover { border-color: var(--cobalt); color: var(--cobalt); }

/* ═══════════════════════════════════════════════════════
   8 · RESUME CARD (dashboard) — single-click continue
═══════════════════════════════════════════════════════ */
.qe-resume {
  display: flex;
  align-items: center;
  gap: 20px;
  background: linear-gradient(120deg, var(--slate-900), var(--slate-800));
  color: #fff;
  border-radius: var(--r-lg);
  padding: 22px 26px;
  margin-bottom: 26px;
  box-shadow: var(--sh);
  flex-wrap: wrap;
}
.qe-resume-body { flex: 1 1 280px; min-width: 0; }
.qe-resume-eyebrow {
  font-family: var(--font-d);
  font-size: .68rem; font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--teal);
}
.qe-resume h2 { color: #fff; font-size: 1.35rem; margin: 4px 0 6px; }
.qe-resume p { color: rgba(255, 255, 255, .72); font-size: .9rem; margin: 0; }
.qe-resume .progress { margin-top: 12px; max-width: 360px; background: rgba(255, 255, 255, .16); }

/* ═══════════════════════════════════════════════════════
   9 · CARD MICRO-INTERACTIONS  (alive, but subtle)
═══════════════════════════════════════════════════════ */
.course-card { transition: transform var(--t), box-shadow var(--t); }
.course-card:hover { transform: translateY(-3px); box-shadow: var(--sh); }
.course-card:focus-within { box-shadow: var(--sh), 0 0 0 3px rgba(37, 99, 235, .18); }

/* Make completed mark-as-done buttons read as a finished state, with a tick. */
.btn-muted.is-done::before { content: "\2713 "; font-weight: 900; }

/* ═══════════════════════════════════════════════════════
   10 · USER PREFERENCES — motion & contrast
═══════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .course-card:hover { transform: none; }
}

@media (prefers-contrast: more) {
  :root { --line: #94a3b8; --muted: #475569; }
  .btn-outline { border-width: 2px; }
  .qe-status, .badge { border: 1px solid currentColor; }
  .form-control { border-width: 2px; }
  a:not(.btn) { text-decoration: underline; }
}

/* Honour the OS "increase contrast" on Windows high-contrast mode too. */
@media (forced-colors: active) {
  .btn { border: 1px solid currentColor; }
  .progress-fill { forced-color-adjust: none; }
}
