/* ============================================================
   assist-panel.css — On-screen assistance panel
   ─────────────────────────────────────────────────────────────
   PURPOSE : Styles for `js/retinoscopy/ui/assist-panel.js` — the
             assistance header, the on/off switch, the four-level
             radiogroup, and the stack of hint cards beneath them.
   SCOPE   : retinoscopy.html only. Everything is namespaced under
             `.ret-assist`, uses the tokens already declared in
             retinoscopy.css (--ret-surface, --ret-surface-card,
             --ret-surface-elevated, --ret-border, --ret-streak,
             --accent, --accent-tint) and is written with logical
             properties so RTL needs no mirroring rules.
   ============================================================ */

/* ── Native `hidden` must always win ──────────────────────────────────────
   retinoscopy-ui.css already ships a global `[hidden]{display:none!important}`.
   This is the same rule scoped to this component, so the panel stays
   collapsible even if it is ever loaded on its own. Nothing below sets
   `display` on an element the JS toggles with `hidden` without this net —
   the panel's level-0 collapse depends on it. */
.ret-assist[hidden],
.ret-assist [hidden] { display: none !important; }

/* ══════════════════════════════════════════════════════════════════════
   SHELL
   ══════════════════════════════════════════════════════════════════════ */

.ret-assist {
  background: var(--ret-surface);
  border: 1px solid var(--ret-border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Off: the panel is a header and its controls, nothing more. */
.ret-assist.is-off {
  padding-block-end: 12px;
  opacity: 0.9;
}

/* Mounted INSIDE one of the workspace cards rather than as a card of its own:
   step one surface lighter at every level so it still reads as a distinct
   block instead of a flat rectangle of the same colour. */
.ret-card > .ret-assist { background: var(--ret-surface-card); }
.ret-card > .ret-assist .ret-assist-hint { background: var(--ret-surface-elevated); }
.ret-card > .ret-assist .ret-assist-hint--danger { background: rgba(239, 68, 68, 0.14); }
.ret-card > .ret-assist .ret-assist-level { background: var(--ret-surface-elevated); }
.ret-card > .ret-assist .ret-assist-level.is-active { background: var(--accent); }
.ret-card > .ret-assist .ret-assist-level[data-level='0'].is-active {
  background: var(--ret-surface);
}

/* Screen-reader-only, local so the component never depends on a utility
   class defined in another sheet. */
.ret-assist-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ══════════════════════════════════════════════════════════════════════
   HEAD — title, count, power switch
   ══════════════════════════════════════════════════════════════════════ */

.ret-assist-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ret-assist-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #94a3b8;
  margin: 0;
}

.ret-assist-count {
  font-size: 10.5px;
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
  color: #7dd3fc;
  background: var(--accent-tint);
  border: 1px solid var(--ret-border);
  border-radius: 999px;
  padding: 2px 8px;
  unicode-bidi: plaintext;
  font-variant-numeric: tabular-nums;
}

.ret-assist-power {
  margin-inline-start: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--ret-surface-elevated);
  border: 1px solid var(--ret-border);
  border-radius: 999px;
  padding: 4px 12px 4px 5px;
  padding-inline: 5px 12px;
  color: #94a3b8;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.ret-assist-power:hover { border-color: var(--accent); }

.ret-assist-power.is-on {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: #e2e8f0;
}

.ret-assist-power-track {
  position: relative;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: var(--ret-border);
  flex-shrink: 0;
  transition: background 0.18s ease;
}

.ret-assist-power.is-on .ret-assist-power-track { background: var(--accent); }

.ret-assist-power-knob {
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #cbd5e1;
  transition: transform 0.18s ease, background 0.18s ease;
}

.ret-assist-power.is-on .ret-assist-power-knob {
  background: #fff;
  transform: translateX(13px);
}

/* The knob travels toward the end edge, whichever side that is. */
.ret-assist[dir='rtl'] .ret-assist-power.is-on .ret-assist-power-knob,
html[dir='rtl'] .ret-assist-power.is-on .ret-assist-power-knob {
  transform: translateX(-13px);
}

/* ══════════════════════════════════════════════════════════════════════
   LEVELS — 0 off · 1 nudges · 2 guidance · 3 full
   ══════════════════════════════════════════════════════════════════════ */

.ret-assist-levels {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.ret-assist-level {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--ret-surface-card);
  border: 1px solid var(--ret-border);
  border-radius: 8px;
  padding: 7px 4px;
  color: #94a3b8;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.ret-assist-level:hover { border-color: var(--accent); }

.ret-assist-level-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  opacity: 0.65;
  direction: ltr;
  unicode-bidi: isolate;
}

.ret-assist-level-label {
  text-align: center;
  overflow-wrap: anywhere;
}

.ret-assist-level.is-active {
  background: var(--accent);
  border-color: var(--accent-strong, var(--accent));
  color: #fff;
}

.ret-assist-level.is-active .ret-assist-level-num { opacity: 0.85; }

/* Level 0 is a state, not a failure — it reads muted, never alarming. */
.ret-assist-level[data-level='0'].is-active {
  background: var(--ret-surface-elevated);
  border-color: #64748b;
  color: #cbd5e1;
}

.ret-assist-caption {
  font-size: 11px;
  line-height: 1.5;
  color: #64748b;
  margin: 0;
  unicode-bidi: plaintext;
}

/* ══════════════════════════════════════════════════════════════════════
   HINT REGION
   ══════════════════════════════════════════════════════════════════════ */

.ret-assist-region {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ret-assist-hints {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.ret-assist-empty {
  font-size: 12px;
  color: #64748b;
  font-style: italic;
  margin: 0;
  unicode-bidi: plaintext;
}

/* ── Hint card ── */

.ret-assist-hint {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  background: var(--ret-surface-card);
  border: 1px solid var(--ret-border);
  border-inline-start: 3px solid var(--ret-border);
  border-radius: 10px;
  padding: 9px 11px;
}

.ret-assist-hint.is-enter { animation: ret-assist-in 0.2s ease both; }

@keyframes ret-assist-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.ret-assist-hint-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ret-assist-hint-title {
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
  margin: 0;
  line-height: 1.35;
  unicode-bidi: plaintext;
}

/* `plaintext` keeps degrees, dioptres and axis numbers reading left-to-right
   inside an Arabic sentence — the same treatment the mono read-outs get in
   retinoscopy-ui.css. */
.ret-assist-hint-body {
  font-size: 12px;
  line-height: 1.55;
  color: #cbd5e1;
  margin: 0;
  unicode-bidi: plaintext;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.ret-assist-hint-src {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #64748b;
  margin-block-start: 2px;
}

/* ── Severity chip ── */

.ret-assist-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 2px 8px 2px 4px;
  padding-inline: 4px 8px;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
  margin-block-start: 1px;
}

.ret-assist-chip-glyph {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Severity palettes ── */

.ret-assist-hint--info { border-inline-start-color: #38bdf8; }
.ret-assist-hint--info .ret-assist-chip { background: rgba(56, 189, 248, 0.14); color: #7dd3fc; }
.ret-assist-hint--info .ret-assist-chip-glyph { background: #38bdf8; color: #06202b; }

.ret-assist-hint--tip { border-inline-start-color: #10b981; }
.ret-assist-hint--tip .ret-assist-chip { background: rgba(16, 185, 129, 0.14); color: #6ee7b7; }
.ret-assist-hint--tip .ret-assist-chip-glyph { background: #10b981; color: #052e21; }

.ret-assist-hint--warn { border-inline-start-color: var(--ret-streak, #ffe082); }
.ret-assist-hint--warn .ret-assist-chip { background: rgba(255, 224, 130, 0.14); color: #ffe082; }
.ret-assist-hint--warn .ret-assist-chip-glyph { background: var(--ret-streak, #ffe082); color: #2b2205; }

/* Danger is unmistakable: red rule, red field, red text — the same language
   the case red-flag block already speaks. */
.ret-assist-hint--danger {
  border-color: #ef4444;
  border-inline-start-color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}
.ret-assist-hint--danger .ret-assist-chip { background: rgba(239, 68, 68, 0.22); color: #fca5a5; }
.ret-assist-hint--danger .ret-assist-chip-glyph { background: #ef4444; color: #fff; }
.ret-assist-hint--danger .ret-assist-hint-title { color: #fee2e2; }
.ret-assist-hint--danger .ret-assist-hint-body { color: #fecaca; }
.ret-assist-hint--danger .ret-assist-hint-src { color: #f87171; }

/* ── Dismiss ── */

.ret-assist-dismiss {
  min-width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid var(--ret-border);
  background: transparent;
  color: #64748b;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 0 5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ret-assist-dismiss:hover {
  border-color: var(--accent);
  color: #cbd5e1;
}

/* Armed = the danger card's first press. The second press dismisses; blur or
   Escape stands it back down. A danger hint is never auto-hidden. */
.ret-assist-dismiss.is-armed {
  width: auto;
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
  padding: 0 8px;
}

.ret-assist-hint--danger .ret-assist-dismiss {
  border-color: rgba(239, 68, 68, 0.55);
  color: #fca5a5;
}

.ret-assist-hint.is-armed { box-shadow: 0 0 0 1px #ef4444 inset; }

/* ── Focus visibility (AA) — mirrors the rule in retinoscopy-ui.css so the
      panel is correct even outside `.ret-app`. ── */
.ret-assist :is(button, [tabindex]):focus-visible {
  outline: 2px solid var(--ret-streak, #ffe082);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ══════════════════════════════════════════════════════════════════════
   RESPONSIVE — the panel lives in the side column; below 1024px the
   workspace collapses to one column and it becomes a full-width block.
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
  .ret-assist-levels { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .ret-assist { padding: 12px 13px; gap: 9px; }
  .ret-assist-hint { padding: 8px 10px; }
}

@media (max-width: 480px) {
  .ret-assist-levels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ret-assist-head { gap: 8px; }
  .ret-assist-power { margin-inline-start: auto; }
  /* Chip above the text rather than beside it — 3 columns is too many at
     this width and the title would wrap to one word per line. */
  .ret-assist-hint {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .ret-assist-chip { grid-column: 1 / -1; }
}

/* ══════════════════════════════════════════════════════════════════════
   REDUCED MOTION
   ══════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .ret-assist-hint.is-enter { animation: none; }
  .ret-assist-power,
  .ret-assist-power-track,
  .ret-assist-power-knob,
  .ret-assist-level,
  .ret-assist-dismiss {
    transition: none;
  }
}

/* ══════════════════════════════════════════════════════════════════════
   RTL — logical properties do the layout; these are the exceptions
   ──────────────────────────────────────────────────────────────────────
   The panel sets `dir` on its own root from the injected `getLang()`, so
   both `.ret-assist[dir="rtl"]` and an inherited `html[dir="rtl"]` are
   covered.
   ══════════════════════════════════════════════════════════════════════ */

.ret-assist[dir='rtl'],
html[dir='rtl'] .ret-assist {
  font-family: 'Noto Kufi Arabic', 'Inter', system-ui, sans-serif;
}

/* Degrees, dioptres, axes and counts stay left-to-right inside Arabic copy. */
.ret-assist[dir='rtl'] .ret-assist-hint-body,
.ret-assist[dir='rtl'] .ret-assist-hint-title,
.ret-assist[dir='rtl'] .ret-assist-caption,
.ret-assist[dir='rtl'] .ret-assist-count,
html[dir='rtl'] .ret-assist-hint-body,
html[dir='rtl'] .ret-assist-hint-title,
html[dir='rtl'] .ret-assist-caption,
html[dir='rtl'] .ret-assist-count {
  unicode-bidi: plaintext;
  font-variant-numeric: tabular-nums;
}

/* The level number is a digit, never a word — pin it LTR so "0" stays the
   first level visually as well as logically. */
.ret-assist[dir='rtl'] .ret-assist-level-num,
html[dir='rtl'] .ret-assist-level-num {
  direction: ltr;
  unicode-bidi: isolate;
}
