/* Genius Box SI — right-to-left layout (Arabic).
   Active only when <html dir="rtl"> (set by app/i18n.py for RTL languages).
   Flexbox rows and CSS grids flip automatically with dir="rtl"; Bootstrap's
   own RTL build is swapped in by the templates. These rules flip the
   hand-written LTR assumptions: sidebars, borders, auto-margins, slide-ins. */

[dir="rtl"] body { text-align: right; }
[dir="rtl"] .text-start { text-align: right !important; }
[dir="rtl"] .text-end { text-align: left !important; }

/* Keep numbers, code, URLs, keyboard and math readable left-to-right */
[dir="rtl"] code, [dir="rtl"] pre, [dir="rtl"] kbd, [dir="rtl"] .mono,
[dir="rtl"] input[type="number"], [dir="rtl"] input[type="email"], [dir="rtl"] input[type="url"],
[dir="rtl"] input[type="password"], [dir="rtl"] canvas, [dir="rtl"] svg { direction: ltr; }

/* ---------- App shell (base.html) ---------- */
[dir="rtl"] .app-right { margin-left: 0; margin-right: auto; }
[dir="rtl"] .sidebar { border-right: 0; border-left: 1px solid var(--line); }
[dir="rtl"] .sidebar-toggle { margin-left: 0; margin-right: -8px; }
[dir="rtl"] .ylink.gb-locked .gb-lock-ic,
[dir="rtl"] .nav-chev,
[dir="rtl"] .ql-fam-count { margin-left: 0; margin-right: auto; }
[dir="rtl"] .nav-group-head { text-align: right; }
[dir="rtl"] .nav-group-body .ylink { padding: 8px 16px 8px 12px; }
[dir="rtl"] .nav-chev { transform: scaleX(-1); }
[dir="rtl"] .nav-group.open .nav-chev { transform: rotate(90deg); }
[dir="rtl"] .fa-chevron-right, [dir="rtl"] .fa-arrow-right, [dir="rtl"] .fa-angle-right,
[dir="rtl"] .fa-chevron-left, [dir="rtl"] .fa-arrow-left, [dir="rtl"] .fa-angle-left,
[dir="rtl"] .fa-arrow-up-right-from-square, [dir="rtl"] .fa-right-from-bracket,
[dir="rtl"] .fa-paper-plane, [dir="rtl"] .bi-arrow-right, [dir="rtl"] .bi-arrow-left { transform: scaleX(-1); }
[dir="rtl"] .nav-group.open .nav-chev.fa-chevron-right { transform: rotate(90deg); }

@media (max-width: 820px) {
  /* slide-in sidebar comes from the right */
  [dir="rtl"] .sidebar { left: auto; right: 0; transform: translateX(105%); box-shadow: -4px 0 20px rgba(0,0,0,.5); }
  [dir="rtl"] .sidebar.open { transform: translateX(0); }
  html[dir="rtl"][data-theme="light"] .sidebar { box-shadow: -4px 0 20px rgba(26,21,2,0.15); }
}

/* Bootstrap-free utility spacing used in hand-written markup */
[dir="rtl"] .me-1 { margin-left: .25rem !important; margin-right: 0 !important; }
[dir="rtl"] .me-2 { margin-left: .5rem !important; margin-right: 0 !important; }
[dir="rtl"] .ms-auto { margin-right: auto !important; margin-left: 0 !important; }
[dir="rtl"] .float-end { float: left !important; }
[dir="rtl"] .float-start { float: right !important; }

/* Forms / lists */
[dir="rtl"] ul, [dir="rtl"] ol { padding-left: 0; padding-right: 2rem; }
[dir="rtl"] .form-check { padding-left: 0; padding-right: 1.5em; }
[dir="rtl"] .form-check .form-check-input { float: right; margin-left: 0; margin-right: -1.5em; }
[dir="rtl"] .form-select { background-position: left .75rem center; padding-right: .75rem; padding-left: 2.25rem; }
[dir="rtl"] th, [dir="rtl"] td { text-align: right; }
[dir="rtl"] blockquote { border-left: 0; border-right: 3px solid var(--line); padding-left: 0; padding-right: 1rem; }

/* ---------- SI Instructor console (merlin_chat.html) ---------- */
[dir="rtl"] #rv-rail { border-right: 0; border-left: 1px solid rgba(255,217,15,.22); }
html[dir="rtl"][data-theme="light"] #rv-rail { border-left-color: rgba(184,150,11,.33); }
[dir="rtl"] #rv-rail .nav-chev,
[dir="rtl"] #rv-rail .ql-fam-count,
[dir="rtl"] #rv-rail .ylink.gb-locked .gb-lock-ic { margin-left: 0; margin-right: auto; }
[dir="rtl"] #rv-rail .nav-group-body .ylink { padding: 8px 16px 8px 12px; }
[dir="rtl"] #side { border-left: 0; border-right: 1px solid var(--line); }
[dir="rtl"] #export-fab-wrap { right: auto; left: 14px; align-items: flex-start; }
[dir="rtl"] #log-close { margin-left: 0; margin-right: auto; }
[dir="rtl"] #log-toggle .ping { right: auto; left: 7px; }

/* Header: in RTL the "more" (sliders) button sits at the LEFT end of the bar, so
   the controls panel and the inline drop-down menus open from the left edge and
   can never run off-screen. Applies to the ≤1340px panel and to the
   body.hdr-collapse overflow guard used on wide screens. */
[dir="rtl"] #model-menu, [dir="rtl"] #entropy-menu { right: auto; left: 0; }
[dir="rtl"] #voice-gen-panel { right: auto !important; left: 60px; }
@media (max-width: 1340px) {
  [dir="rtl"] #hdr-ctrls { right: auto; left: 10px; }
  [dir="rtl"] #model-menu, [dir="rtl"] #entropy-menu { left: 0; right: 0; }
  [dir="rtl"] #voice-gen-panel { left: 0 !important; right: 0 !important; }
}
[dir="rtl"] body.hdr-collapse #hdr-ctrls { right: auto; left: 10px; }
[dir="rtl"] body.hdr-collapse #model-menu, [dir="rtl"] body.hdr-collapse #entropy-menu { left: 0; right: 0; }
[dir="rtl"] body.hdr-collapse #voice-gen-panel { left: 0 !important; right: 0 !important; }

@media (max-width: 1100px) {
  /* command log drawer slides in from the left */
  [dir="rtl"] #side { right: auto; left: 0; border-right: 1px solid var(--cyan); transform: translateX(-104%); box-shadow: 24px 0 60px rgba(0,0,0,.6); }
  [dir="rtl"] #side.open { transform: translateX(0); }
  [dir="rtl"] #side h2 { padding: 10px 18px 10px 12px; }
}
@media (max-width: 820px) {
  /* module rail slides in from the right */
  [dir="rtl"] #rv-rail { left: auto; right: 0; border-left: 1px solid var(--cyan); transform: translateX(104%); box-shadow: -24px 0 60px rgba(0,0,0,.6); }
  [dir="rtl"] #rv-rail.open { transform: translateX(0); }
}

/* Language picker + chat bubbles */
[dir="rtl"] .gb-lang-form { direction: rtl; }
[dir="rtl"] #txt, [dir="rtl"] textarea, [dir="rtl"] input[type="text"], [dir="rtl"] input[type="search"] { text-align: right; }
