/* ══════════════════════════════════════════════════════════════════
   مساعد الأرشيف الذكي — مجموعة محمد الكندي
   كل الألوان رموز دلالية (tokens) في مكان واحد، ولكل رمز قيمتان:
   واحدة للوضع الفاتح وأخرى للداكن. لتعديل الهوية غيّر هذه القيم فقط.
   ══════════════════════════════════════════════════════════════════ */
:root {
  /* ألوان الهوية — ثابتة في الوضعين */
  --navy: #0B2545;
  --gold: #C9A227;
  --gold-soft: #e0bf50;

  /* الأسطح والنصوص — الوضع الفاتح */
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #f4f7fb;
  --text: #16202e;
  --text-muted: #5f6b7d;
  --border: #e5e9f0;
  --gold-tint: #fdf8ea;
  --gold-ink: #8a6f14;

  /* القائمة الجانبية */
  --side-bg: #0B2545;
  --side-text: rgba(255, 255, 255, .78);
  --side-text-strong: #ffffff;
  --side-hover: rgba(255, 255, 255, .09);
  --side-active: rgba(201, 162, 39, .20);
  --side-border: rgba(255, 255, 255, .14);
  --side-muted: rgba(255, 255, 255, .45);
  --side-field: rgba(255, 255, 255, .07);

  /* الفقاعات */
  --user-bubble: #0B2545;
  --user-bubble-text: #ffffff;
  --error-bg: #fef4f4;
  --error-border: #f0c9c9;
  --error-text: #8c2f2f;

  --btn-text: #ffffff;
  --track: #dde4ee;
  --shadow: 0 1px 3px rgba(11, 37, 69, .06);
  --overlay: rgba(11, 37, 69, .45);

  --radius: 14px;
  --radius-sm: 10px;
  --font-ui: "Thmanyah Sans", "Tajawal", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Thmanyah Serif Display", "Thmanyah Sans", "Tajawal", Georgia, serif;
  --sidebar-width: 280px;
}

/* الوضع الداكن — يُفعَّل باختيار المستخدم أو بإعداد النظام */
:root[data-theme="dark"] {
  --bg: #0d141d;
  --surface: #151d28;
  --surface-2: #1b2532;
  --text: #e6edf3;
  --text-muted: #94a3b6;
  --border: #27323f;
  --gold-tint: #2a2413;
  --gold-ink: #e0bf50;

  --side-bg: #080d14;
  --side-text: rgba(233, 240, 248, .74);
  --side-text-strong: #ffffff;
  --side-hover: rgba(255, 255, 255, .07);
  --side-active: rgba(201, 162, 39, .22);
  --side-border: rgba(255, 255, 255, .10);
  --side-muted: rgba(233, 240, 248, .42);
  --side-field: rgba(255, 255, 255, .06);

  --user-bubble: #1e3a63;
  --user-bubble-text: #f2f6fb;
  --error-bg: #2b1717;
  --error-border: #5c2b2b;
  --error-text: #f2b8b8;

  --track: #27323f;
  --shadow: 0 1px 3px rgba(0, 0, 0, .35);
  --overlay: rgba(0, 0, 0, .6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d141d;
    --surface: #151d28;
    --surface-2: #1b2532;
    --text: #e6edf3;
    --text-muted: #94a3b6;
    --border: #27323f;
    --gold-tint: #2a2413;
    --gold-ink: #e0bf50;

    --side-bg: #080d14;
    --side-text: rgba(233, 240, 248, .74);
    --side-text-strong: #ffffff;
    --side-hover: rgba(255, 255, 255, .07);
    --side-active: rgba(201, 162, 39, .22);
    --side-border: rgba(255, 255, 255, .10);
    --side-muted: rgba(233, 240, 248, .42);
    --side-field: rgba(255, 255, 255, .06);

    --user-bubble: #1e3a63;
    --user-bubble-text: #f2f6fb;
    --error-bg: #2b1717;
    --error-border: #5c2b2b;
    --error-text: #f2b8b8;

    --track: #27323f;
    --shadow: 0 1px 3px rgba(0, 0, 0, .35);
    --overlay: rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; overflow: hidden; }

/* ───────────────────────────────────────────── الهيكل العام */
.app { flex: 1; display: flex; min-height: 0; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ─────────────────────────────────────────── القائمة الجانبية */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 12px;
  background: var(--side-bg);
  overflow: hidden;
  transition: width .2s ease, padding .2s ease;
}
/* الطي على سطح المكتب */
body.sidebar-collapsed .sidebar {
  width: 0;
  padding-inline: 0;
  border: none;
}
body.sidebar-collapsed .sidebar > * { display: none; }

.newchat {
  font-family: var(--font-ui);
  font-size: .87rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--side-border);
  background: transparent;
  color: var(--side-text-strong);
  cursor: pointer;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
  white-space: nowrap;
}
.newchat:hover { background: var(--side-hover); border-color: var(--gold); }
.newchat__plus { font-size: 1.1rem; line-height: 1; color: var(--gold); }

/* تبويبا المحادثات والملفات */
.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--side-field);
  flex-shrink: 0;
}
.tab {
  flex: 1;
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 500;
  padding: 7px 6px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--side-text);
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.tab:hover { color: var(--side-text-strong); }
.tab--active { background: var(--side-hover); color: var(--side-text-strong); }
.tab__count { opacity: .6; font-size: .72rem; }

.pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pane[hidden] { display: none; }

.sidelist {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scrollbar-width: thin;
  scrollbar-color: var(--side-border) transparent;
}
.sidelist__empty {
  color: var(--side-muted);
  font-size: .8rem;
  text-align: center;
  margin-top: 18px;
  padding: 0 8px;
  line-height: 1.9;
}

/* عنصر المحادثة */
.conv {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--side-text);
  font-size: .84rem;
  transition: background .12s, color .12s;
}
.conv:hover { background: var(--side-hover); color: var(--side-text-strong); }
.conv--active { background: var(--side-active); color: var(--side-text-strong); }
.conv--active .conv__title { font-weight: 500; }
.conv__title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  unicode-bidi: plaintext;
}
.conv__del {
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--side-muted);
  cursor: pointer;
  font-size: .95rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 5px;
  opacity: 0;
  transition: opacity .12s, color .12s, background .12s;
}
.conv:hover .conv__del, .conv--active .conv__del { opacity: 1; }
.conv__del:hover { color: #fff; background: rgba(255, 255, 255, .18); }

/* البحث في الملفات */
.search {
  position: relative;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.search input {
  width: 100%;
  font-family: var(--font-ui);
  font-size: .82rem;
  padding: 9px 32px 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--side-border);
  background: var(--side-field);
  color: var(--side-text-strong);
  outline: none;
  transition: border-color .15s;
}
.search input::placeholder { color: var(--side-muted); }
.search input:focus { border-color: var(--gold); }
.search__icon {
  position: absolute;
  inset-inline-start: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--side-muted);
  font-size: .8rem;
  pointer-events: none;
}

/* بطاقة ملف في القائمة */
.filerow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--side-text);
  font-size: .81rem;
  transition: background .12s, color .12s;
  text-decoration: none;
}
.filerow:hover { background: var(--side-hover); color: var(--side-text-strong); }
.filerow__icon { flex-shrink: 0; font-size: .95rem; width: 18px; text-align: center; }
.filerow__body { flex: 1; min-width: 0; }
.filerow__name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.6;
  /* الأسماء تخلط العربية واللاتينية: plaintext يجعل كل اسم يتبع اتجاهه
     فيقع القصّ في نهايته لا في بدايته. */
  unicode-bidi: plaintext;
}
.filerow__meta { display: block; font-size: .7rem; color: var(--side-muted); line-height: 1.5; }
.filerow__go { flex-shrink: 0; color: var(--side-muted); font-size: .8rem; opacity: 0; transition: opacity .12s; }
.filerow:hover .filerow__go { opacity: 1; }

.backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 25; }

/* ─────────────────────────────────────────────────── الترويسة */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header__logo { height: 46px; width: auto; object-fit: contain; }
.header__titles { flex: 1; min-width: 0; }
.header__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header__subtitle { margin: 0; font-size: .8rem; color: var(--text-muted); }

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.iconbtn:hover { border-color: var(--gold); background: var(--surface-2); }

/* ─────────────────────────────────────────── الشريط الإداري */
.adminbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: .8rem;
  color: var(--text-muted);
}
.adminbar__stats { display: flex; gap: 16px; flex-wrap: wrap; }
.adminbar__stat strong { color: var(--text); font-weight: 700; }
.adminbar__spacer { flex: 1; }

.btn {
  font-family: var(--font-ui);
  font-size: .82rem;
  font-weight: 500;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gold);
  background: var(--gold);
  color: var(--btn-text);
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:hover:not(:disabled) { background: var(--gold-soft); border-color: var(--gold-soft); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.progress { flex-basis: 100%; height: 5px; border-radius: 999px; background: var(--track); overflow: hidden; }
.progress__bar { height: 100%; width: 0; background: var(--gold); border-radius: 999px; transition: width .35s ease; }

/* ────────────────────────────────────────────── منطقة المحادثة */
.chat { flex: 1; overflow-y: auto; min-height: 0; padding: 24px 20px 8px; }
.chat__inner { max-width: 880px; margin: 0 auto; }

.welcome { max-width: 720px; margin: 6vh auto 0; text-align: center; padding: 0 4px; }
.welcome__logo { height: 92px; margin-bottom: 22px; }
.welcome__text {
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-weight: 500;
  color: var(--text);
  line-height: 2.1;
  margin: 0 auto 28px;
  max-width: 620px;
}
.samples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sample {
  font-family: var(--font-ui);
  font-size: .87rem;
  text-align: right;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  line-height: 1.7;
}
.sample:hover { border-color: var(--gold); background: var(--gold-tint); }

/* ─────────────────────────────────────────────────── الفقاعات */
.msg { margin-bottom: 22px; display: flex; }
.bubble {
  max-width: 92%;
  padding: 14px 18px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bubble--user {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-top-right-radius: 4px;
  margin-inline-start: auto;
  max-width: 80%;
}
.bubble--bot {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow);
  width: 100%;
}
.bubble--error { background: var(--error-bg); border: 1px solid var(--error-border); color: var(--error-text); width: 100%; }

.inference {
  display: block;
  background: var(--gold-tint);
  border-inline-start: 3px solid var(--gold);
  padding: 8px 12px;
  margin: 8px 0;
  border-radius: 6px;
}

.typing { display: flex; align-items: center; gap: 9px; color: var(--text-muted); font-size: .87rem; }
.typing__dots { display: inline-flex; gap: 4px; }
.typing__dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); animation: pulse 1.3s infinite ease-in-out; }
.typing__dots i:nth-child(2) { animation-delay: .18s; }
.typing__dots i:nth-child(3) { animation-delay: .36s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ─────────────────────────────────────────── بطاقات المصادر */
.sources { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.sources__toggle {
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 500;
  color: var(--text);
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sources__toggle:hover { color: var(--gold); }
.sources__arrow { transition: transform .2s; font-size: .7rem; }
.sources__list { display: grid; gap: 8px; margin-top: 10px; }
.sources__list[hidden] { display: none; }

.source {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: .82rem;
}
.source__name { font-weight: 500; color: var(--text); word-break: break-word; }
.source__where { color: var(--text-muted); font-size: .78rem; }
.source__link { margin-inline-start: auto; flex-shrink: 0; color: var(--gold-ink); text-decoration: none; font-weight: 500; white-space: nowrap; }
.source__link:hover { text-decoration: underline; }

/* ─────────────────────────────────────────── بطاقات الملفات */
.filecards { display: grid; gap: 10px; margin-top: 12px; }
.filecard { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; background: var(--surface); box-shadow: var(--shadow); }
.filecard__top { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 4px; }
.filecard__name { font-weight: 700; color: var(--text); word-break: break-word; flex: 1; }
.filecard__badge { flex-shrink: 0; font-size: .7rem; padding: 2px 9px; border-radius: 999px; background: var(--gold-tint); color: var(--gold-ink); border: 1px solid var(--border); }
.filecard__meta { font-size: .78rem; color: var(--text-muted); margin-bottom: 11px; }
.filecard__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filecard__btn { font-size: .8rem; padding: 6px 14px; border-radius: var(--radius-sm); text-decoration: none; border: 1px solid var(--border); color: var(--text); transition: background .15s, color .15s, border-color .15s; }
.filecard__btn:hover { border-color: var(--gold); background: var(--gold-tint); }
.filecard__btn--gold { border-color: var(--gold); color: var(--btn-text); background: var(--gold); }
.filecard__btn--gold:hover { background: var(--gold-soft); border-color: var(--gold-soft); color: var(--btn-text); }

/* ────────────────────────────────────────────── صندوق الإدخال */
.composer { position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--border); padding: 14px 20px 18px; }
.composer__inner {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 7px 7px 14px;
  background: var(--surface);
  transition: border-color .15s;
}
.composer__inner:focus-within { border-color: var(--gold); }
.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-ui);
  font-size: .95rem;
  line-height: 1.7;
  max-height: 160px;
  background: transparent;
  color: var(--text);
  padding: 6px 4px;
}
.composer textarea::placeholder { color: var(--text-muted); }
.composer__send {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: none;
  background: var(--navy);
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
  transition: opacity .15s;
}
:root[data-theme="dark"] .composer__send { background: var(--gold); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .composer__send { background: var(--gold); }
}
.composer__send:hover:not(:disabled) { opacity: .85; }
.composer__send:disabled { opacity: .4; cursor: not-allowed; }
.composer__hint { max-width: 880px; margin: 8px auto 0; font-size: .72rem; color: var(--text-muted); text-align: center; }

/* الشعار ملوّن بنصّ كحلي على أبيض، فيُوضع في الوضع الداكن على بطاقة
   بيضاء مقصودة بدل أن يبدو مربّعاً أبيض شارداً. */
:root[data-theme="dark"] .header__logo,
:root[data-theme="dark"] .welcome__logo {
  background: #ffffff;
  border-radius: 8px;
  padding: 3px 7px;
}
:root[data-theme="dark"] .welcome__logo { padding: 10px 16px; border-radius: 14px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .header__logo,
  :root:not([data-theme="light"]) .welcome__logo {
    background: #ffffff;
    border-radius: 8px;
    padding: 3px 7px;
  }
  :root:not([data-theme="light"]) .welcome__logo { padding: 10px 16px; border-radius: 14px; }
}

/* ─────────────────────────────────────────── شجرة الملفات */
.tree { padding-bottom: 6px; }
.tree__list { list-style: none; margin: 0; padding: 0; }
.tree__row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-block: 6px;
  padding-inline-end: 6px;
  border-radius: var(--radius-sm);
  color: var(--side-text);
  font-size: .81rem;
  text-decoration: none;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.tree__row:hover { background: var(--side-hover); color: var(--side-text-strong); }
.tree__row--folder { font-weight: 500; }
.tree__row--scoped { background: var(--side-active); color: var(--side-text-strong); }
.tree__row--bad .tree__name { opacity: .7; }
.tree__caret { width: 12px; flex-shrink: 0; font-size: .7rem; color: var(--side-muted); }
.tree__icon { flex-shrink: 0; width: 16px; text-align: center; font-size: .85rem; }
.tree__name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; unicode-bidi: plaintext; }
.tree__count { flex-shrink: 0; font-size: .68rem; color: var(--side-muted); }
.tree__scope {
  flex-shrink: 0;
  border: 1px solid transparent;
  background: none;
  color: var(--side-muted);
  border-radius: 6px;
  width: 22px;
  height: 22px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, color .12s, border-color .12s;
}
.tree__row:hover .tree__scope, .tree__scope--on { opacity: 1; }
.tree__scope:hover { color: var(--gold); border-color: var(--gold); }
.tree__scope--on { color: var(--gold); border-color: var(--gold); }

/* ملفات تعذّرت قراءتها */
.failures { flex-shrink: 0; border-top: 1px solid var(--side-border); padding-top: 6px; max-height: 40%; overflow-y: auto; }
.failures__toggle {
  width: 100%;
  text-align: start;
  font-family: var(--font-ui);
  font-size: .78rem;
  background: none;
  border: none;
  color: #e9b949;
  padding: 6px 4px;
  cursor: pointer;
}
.failures__list { display: flex; flex-direction: column; gap: 2px; }
.failure {
  display: flex;
  flex-direction: column;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--side-text);
  font-size: .76rem;
}
.failure:hover { background: var(--side-hover); }
.failure__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; unicode-bidi: plaintext; }
.failure__reason { color: var(--side-muted); font-size: .7rem; line-height: 1.6; }

/* ─────────────────────────────────────────── شريط النطاق */
.scope {
  max-width: 880px;
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
}
.scope[hidden] { display: none; }
.scope__label { color: var(--text-muted); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 280px;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  background: var(--gold-tint);
  border: 1px solid var(--gold);
  color: var(--text);
}
.chip__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; unicode-bidi: plaintext; }
.chip__x {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .95rem;
  line-height: 1;
  padding: 0 6px;
  border-radius: 999px;
}
.chip__x:hover { color: var(--text); background: var(--surface-2); }
.scope__clear {
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: .74rem;
  text-decoration: underline;
  cursor: pointer;
}

/* ─────────────────────────────────────────── الاستشهادات والمصادر */
.cite {
  display: inline-block;
  min-width: 16px;
  padding: 0 4px;
  margin-inline-start: 2px;
  border-radius: 999px;
  background: var(--gold-tint);
  color: var(--gold-ink);
  font-size: .68rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  vertical-align: super;
}
.sources__title { font-size: .78rem; font-weight: 500; color: var(--text-muted); margin-bottom: 8px; }
.source__n {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--gold-tint);
  color: var(--gold-ink);
  font-size: .72rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.source__body { flex: 1; min-width: 0; }
.source__name { unicode-bidi: plaintext; }
.filecard__about { font-size: .8rem; color: var(--text); margin-bottom: 4px; }
.filecard__warn { font-size: .78rem; color: var(--error-text); background: var(--error-bg); border-radius: 8px; padding: 6px 10px; margin-bottom: 10px; }
button.filecard__btn { font-family: var(--font-ui); background: none; cursor: pointer; }

/* ─────────────────────────────────────────────────── الجوال */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    /* في RTL تكون البداية المنطقية هي الحافة اليمنى — وهي مكان القائمة */
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    z-index: 30;
    width: 82vw;
    max-width: 300px;
    transform: translateX(100%);
    transition: transform .22s ease;
    box-shadow: -2px 0 16px rgba(0, 0, 0, .25);
  }
  .sidebar--open { transform: translateX(0); }
  /* الطي يخصّ سطح المكتب فقط */
  body.sidebar-collapsed .sidebar { width: 82vw; padding-inline: 12px; }
  body.sidebar-collapsed .sidebar > * { display: revert; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .header { padding: 10px 14px; gap: 8px; }
  .header__logo { height: 34px; }
  .header__title { font-size: .92rem; white-space: normal; }
  .header__subtitle { display: none; }
  .adminbar { padding: 8px 14px; font-size: .74rem; gap: 8px; }
  .chat { padding: 18px 14px 4px; }
  .samples { grid-template-columns: 1fr; }
  .welcome { margin-top: 3vh; }
  .welcome__logo { height: 66px; }
  .welcome__text { font-size: 1.05rem; }
  .bubble { max-width: 100%; }
  .bubble--user { max-width: 92%; }
  .composer { padding: 10px 14px 14px; }
  .source { flex-wrap: wrap; }
  .source__link { margin-inline-start: 0; }
}
