/* Karkhoone Lab — brand layer for LibreChat (v0.3, 2026-10-31)
 * Loaded after LibreChat's own CSS (injected into index.html by brand/Dockerfile).
 * Scope: font, text alignment, brand accents. Direction itself lives in
 * brand/karkhoone-bidi.js. Keep this file small:
 * every rule here must survive a LibreChat upgrade. Test with brand/rtl-test.md.
 */

/* 1. Font — Vazirmatn for Persian, system stack for Latin. Files are copied from
 *    the Ubuntu package fonts-vazirmatn at build time (see Dockerfile). */
@font-face { font-family: "Vazirmatn"; src: url("/assets/fonts/Vazirmatn-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("/assets/fonts/Vazirmatn-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("/assets/fonts/Vazirmatn-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --kh-yellow: #F8B03A;
  --kh-orange: #EB5B26;
  --kh-green:  #44AE4C;
  --kh-red:    #C1272F;
  --kh-ink:    #030305;
}

html, body, button, input, textarea, select {
  font-family: "Vazirmatn", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif !important;
}

/* 2. Mixed-direction text. Direction is NOT decided here any more: brand/karkhoone-bidi.js
 *    sets dir="rtl" or dir="ltr" on each block from the letters it actually contains.
 *    `unicode-bidi: plaintext` used to do this in CSS alone, but it reads only the first
 *    strong character, so a Persian paragraph opening with a Latin word came out LTR.
 *    These rules only make the text hug the side its dir attribute picked. */
.markdown p, .markdown li, .markdown h1, .markdown h2, .markdown h3, .markdown h4,
.markdown blockquote, .markdown td, .markdown th,
.message-content p, .message-content li {
  text-align: start;
}

/* 2b. Landing greeting (interface.customWelcome). LibreChat's SplitText animates every
 *     letter as its own inline-block span, which breaks Persian letter joining and lays
 *     the words out left-to-right. Render it as normal inline text instead; the dir
 *     attribute comes from karkhoone-bidi.js. Only the slide-in motion is lost; the
 *     fade-in stays. */
p.split-parent, p.split-parent span {
  display: inline !important;
  transform: none !important;
  white-space: normal !important;
}
/* The composer: karkhoone-bidi.js sets dir on each keystroke, so the caret sits on the
 * right for Persian and on the left for English. */
textarea, [contenteditable="true"] {
  text-align: start;
}

/* 3. Code, paths, URLs and identifiers always stay LTR. */
pre, code, kbd, samp, .hljs, .markdown pre, .markdown code {
  direction: ltr !important;
  unicode-bidi: isolate !important;
  text-align: left !important;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace !important;
}

/* Lists and tables: bullets follow the inherited direction, and each cell gets its own
 * dir from karkhoone-bidi.js, so a Persian table with English cells reads correctly. */
.markdown ul, .markdown ol { padding-inline-start: 1.5em; }

/* 4. Brand accents — deliberately minimal so LibreChat's light/dark themes keep working. */
::selection { background: color-mix(in srgb, var(--kh-yellow) 45%, transparent); }
a { text-decoration-color: var(--kh-orange); }
