/* ============================================================
   باحث الشاملة — نظام التصميم v3 (مطابق للمكتبة)
   أسطح متدرجة: إطار ← محتوى مستدير ← بطاقات | حدود شعرية | تمييز أزرق سماوي
   ============================================================ */
:root {
  /* ──── الأسطح ──── */
  --bg:            #1e1e1e;
  --side:          #252526;
  --panel:         #252526;
  --panel-2:       #2d2d30;
  --panel-elevate: #37373d;
  --line:          #3c3c3c;
  --line-2:        #4e4e52;
  --line-subtle:   rgba(255, 255, 255, 0.08);

  /* ──── نصوص ──── */
  --text:          #d4d4d4;
  --muted:         #9a9a9a;
  --faint:         #6e6e6e;

  /* ──── تمييز ──── */
  --accent:        #007acc;
  --accent-hover:  #1b89fc;
  --accent-active: #0062a3;
  --on-accent:     #ffffff;
  --accent-glow:   rgba(0, 122, 204, 0.32);
  --accent-bg:     rgba(0, 122, 204, 0.16);
  --accent-border: rgba(0, 122, 204, 0.45);

  --cite:          #4fc1ff;
  --user-bubble:   #181818;
  --user-border:   #333333;
  --composer-bg:   #181818;
  --danger:        #f14c4c;
  --danger-bg:     rgba(241, 76, 76, 0.15);
  --danger-border: rgba(241, 76, 76, 0.4);
  --success:       #89d185;

  /* ──── أشكال وظلال وحركة ──── */
  --hl:            inset 0 1px 0 rgba(255, 255, 255, 0.045);
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md:     0 10px 28px -12px rgba(0, 0, 0, 0.6);
  --shadow-lg:     0 28px 70px -16px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --shadow-glow:   0 0 16px rgba(90, 162, 255, 0.2);
  --ease:          cubic-bezier(.3, .7, .2, 1);
  --dur:           160ms;

  --font: "IBM Plex Sans Arabic", system-ui, sans-serif;
  --serif: "Amiri", serif;
  color-scheme: dark;
}

/* ──── النمط الفاتح ──── */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:            hsl(220, 18%, 96%);
    --side:          hsl(220, 16%, 92%);
    --panel:         hsl(0, 0%, 100%);
    --panel-2:       hsl(220, 15%, 89%);
    --panel-elevate: hsl(220, 15%, 93%);
    --line:          hsl(220, 14%, 82%);
    --line-2:        hsl(220, 12%, 74%);
    --line-subtle:   hsla(220, 14%, 82%, 0.4);
    --text:          hsl(225, 20%, 18%);
    --muted:         hsl(225, 10%, 40%);
    --faint:         hsl(225, 8%, 58%);
    --accent:        hsl(214, 92%, 50%);
    --accent-hover:  hsl(214, 96%, 56%);
    --accent-active: hsl(214, 92%, 42%);
    --on-accent:     #ffffff;
    --accent-glow:   hsla(214, 92%, 50%, 0.2);
    --accent-bg:     hsl(214, 85%, 92%);
    --accent-border: hsl(214, 60%, 75%);
    --cite:          hsl(214, 85%, 44%);
    --user-bubble:   hsl(220, 20%, 92%);
    --user-border:   hsl(220, 14%, 80%);
    --composer-bg:   hsl(0, 0%, 98%);
    --danger:        hsl(4, 80%, 50%);
    --danger-bg:     hsl(4, 85%, 94%);
    --danger-border: hsl(4, 70%, 80%);
    --success:       hsl(152, 70%, 38%);
    --hl:            inset 0 1px 0 rgba(255, 255, 255, 0.8);
    --shadow-sm:     0 1px 2px rgba(20, 30, 50, 0.08);
    --shadow-md:     0 10px 28px -14px rgba(20, 30, 50, 0.22);
    --shadow-lg:     0 28px 70px -18px rgba(20, 30, 50, 0.35), 0 0 0 1px rgba(20, 30, 50, 0.06);
    --shadow-glow:   0 0 20px rgba(31, 111, 235, 0.14);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg:            hsl(220, 18%, 96%);
  --side:          hsl(220, 16%, 92%);
  --panel:         hsl(0, 0%, 100%);
  --panel-2:       hsl(220, 15%, 89%);
  --panel-elevate: hsl(220, 15%, 93%);
  --line:          hsl(220, 14%, 82%);
  --line-2:        hsl(220, 12%, 74%);
  --line-subtle:   hsla(220, 14%, 82%, 0.4);
  --text:          hsl(225, 20%, 18%);
  --muted:         hsl(225, 10%, 40%);
  --faint:         hsl(225, 8%, 58%);
  --accent:        hsl(214, 92%, 50%);
  --accent-hover:  hsl(214, 96%, 56%);
  --accent-active: hsl(214, 92%, 42%);
  --on-accent:     #ffffff;
  --accent-glow:   hsla(214, 92%, 50%, 0.2);
  --accent-bg:     hsl(214, 85%, 92%);
  --accent-border: hsl(214, 60%, 75%);
  --cite:          hsl(214, 85%, 44%);
  --user-bubble:   hsl(220, 20%, 92%);
  --user-border:   hsl(220, 14%, 80%);
  --composer-bg:   hsl(0, 0%, 98%);
  --danger:        hsl(4, 80%, 50%);
  --danger-bg:     hsl(4, 85%, 94%);
  --danger-border: hsl(4, 70%, 80%);
  --success:       hsl(152, 70%, 38%);
  --hl:            inset 0 1px 0 rgba(255, 255, 255, 0.8);
  --shadow-sm:     0 1px 2px rgba(20, 30, 50, 0.08);
  --shadow-md:     0 10px 28px -14px rgba(20, 30, 50, 0.22);
  --shadow-lg:     0 28px 70px -18px rgba(20, 30, 50, 0.35), 0 0 0 1px rgba(20, 30, 50, 0.06);
  --shadow-glow:   0 0 20px rgba(31, 111, 235, 0.14);
  color-scheme: light;
}

/* ──── القواعد العامة وشريط التمرير ──── */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--side);
  color: var(--text);
  font: 15px/1.7 var(--font);
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-bg); }
::placeholder { color: var(--faint); opacity: 1; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; transition: all var(--dur) var(--ease); }
button:active { transform: scale(0.97); }
svg { stroke-linecap: round; stroke-linejoin: round; }
svg { width: 18px; height: 18px; flex: none; }

/* شريط تمرير أنيق متناسق */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(128, 138, 156, .32); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(128, 138, 156, .6); background-clip: padding-box; }

/* ══════════════════════════════════════════════
   الشريط الجانبي (Aside)
   ══════════════════════════════════════════════ */
aside {
  width: 284px;
  background: var(--side);
  display: flex;
  flex-direction: column;
  padding: 12px 10px 0;
  flex: none;
  transition: margin var(--dur) var(--ease), width var(--dur) var(--ease);
  font-size: 14.5px;
  z-index: 10;
}
body.closed aside { margin-inline-start: -284px; }
.side-top { display: flex; align-items: center; gap: 4px; padding: 2px 2px 10px; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: var(--muted);
  flex: none;
  background: transparent;
  transition: all var(--dur) var(--ease);
}
.icon-btn:hover {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  color: var(--muted);
  margin: 0 2px 8px;
  box-shadow: var(--hl);
  transition: all var(--dur) var(--ease);
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
  color: var(--text);
}
.search svg { width: 16px; height: 16px; }
.search input::-webkit-search-cancel-button, .q::-webkit-search-cancel-button { filter: grayscale(1); opacity: .5; }
.search input {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  background: none;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
  min-width: 0;
}

.nav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  width: 100%;
  text-align: start;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 2px;
  transition: all var(--dur) var(--ease);
}
.nav:hover {
  background: var(--panel-2);
  color: var(--text);
}
.nav .circle {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  transition: all var(--dur) var(--ease);
}
.nav:hover .circle {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.nav .circle svg { width: 14px; height: 14px; }
.nav > svg { width: 18px; height: 18px; color: var(--muted); margin-inline: 2px; transition: color var(--dur) var(--ease); }
.nav:hover > svg { color: var(--accent); }

#convs {
  flex: 1;
  overflow-y: auto;
  margin: 10px -4px 0;
  padding: 0 4px 12px;
}
.group { margin-bottom: 4px; }
.ghead {
  display: flex;
  align-items: center;
  border-radius: 8px;
  padding-inline-end: 4px;
  transition: background var(--dur) var(--ease);
}
.ghead:hover { background: var(--panel-2); }
.ghead.drop { background: var(--panel-2); outline: 1px dashed var(--accent); }
.gname {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  color: var(--muted);
  text-align: start;
  min-width: 0;
  font-size: 13.5px;
}
.gname span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.ghead:hover .gname { color: var(--text); }
.chev { width: 14px; height: 14px; transition: transform var(--dur) var(--ease); transform: rotate(180deg); }
.group.open .chev { transform: rotate(90deg); color: var(--accent); }
.gact { width: 26px; height: 26px; opacity: 0; transition: opacity var(--dur) var(--ease); }
.ghead:hover .gact { opacity: 1; }
.gbody { display: none; padding-inline-start: 8px; }
.group.open .gbody { display: block; }

.conv {
  display: flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 11px;
  margin-bottom: 2px;
  transition: all var(--dur) var(--ease);
}
.conv:hover { background: var(--panel-2); }
.conv.active {
  background: var(--accent-bg);
}
.conv button.open {
  flex: 1;
  text-align: start;
  padding: 8px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13.5px;
  color: var(--muted);
  min-width: 0;
}
.conv.active button.open { color: var(--accent); font-weight: 600; }
.conv:hover button.open { color: var(--text); }
.conv .cact { opacity: 0; width: 24px; height: 24px; transition: opacity var(--dur) var(--ease); }
.conv .cact svg { width: 15px; height: 15px; }
.conv:hover .cact { opacity: 1; }
.more, .empty { color: var(--faint); font-size: 13px; padding: 5px 10px; }
.more:hover { color: var(--text); }

.menu {
  position: fixed;
  z-index: 25;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 6px;
  min-width: 190px;
  box-shadow: var(--shadow-lg);
  animation: dlgIn var(--dur) var(--ease);
}
.menu .lbl { color: var(--faint); font-size: 12px; padding: 4px 10px; }
.menu button {
  display: block;
  width: 100%;
  text-align: start;
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--text);
  transition: all var(--dur) var(--ease);
}
.menu button:hover { background: var(--panel-2); color: var(--accent); }
.menu button.cur { color: var(--accent); font-weight: 500; }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 13.5px;
  flex: none;
}
.who-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.who-text b { font-weight: 600; font-size: 14px; color: var(--text); }
.who-text small { color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ══════════════════════════════════════════════
   المحتوى الرئيسي (Main Chat Thread)
   ══════════════════════════════════════════════ */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: var(--bg);
  margin-block: 10px;
  margin-inline: 0 10px;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: margin var(--dur) var(--ease);
}
body.closed main { margin-inline-start: 10px; }
.topbar {
  position: absolute;
  top: 12px;
  inset-inline-start: 12px;
  display: flex;
  align-items: center;
  gap: 2px;
  z-index: 15;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 3px;
  box-shadow: var(--shadow-sm);
}
.topbar #toggle2, .topbar #newBtn2 { display: none; }
body.closed .topbar #toggle2, body.closed .topbar #newBtn2 { display: grid; }
/* أداة الخط: نفس شكل .zoomg في شريط الكتاب بالمكتبة */
.zoomg { position: relative; display: inline-flex; align-items: center; gap: 1px; padding: 2px; border-radius: 11px; }
.zoomg .zb { width: 30px; height: 28px; display: grid; place-items: center; border-radius: 8px; color: var(--muted); }
.zoomg .zb b { font-weight: 600; font-size: 17px; line-height: 1; }
.zoomg .zb:hover, .zoomg .fsVal:hover { background: var(--panel-2); color: var(--text); }
.zoomg .fsVal { height: 28px; min-width: 60px; padding: 0 8px; border-radius: 8px; color: var(--text); font-weight: 600; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.zoomg .fsVal svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.zoomg .fsMenu { position: absolute; top: calc(100% + 6px); inset-inline-start: 0; display: flex; flex-direction: column; min-width: 100%;
  padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow-sm); }
.zoomg .fsMenu[hidden] { display: none; }
.zoomg .fsMenu button { padding: 7px 12px; border-radius: 8px; text-align: start; font-size: 13px; color: var(--muted); }
.zoomg .fsMenu button:hover { background: var(--panel-2); color: var(--text); }
.zoomg .fsMenu button.cur { color: var(--accent); background: var(--accent-bg); font-weight: 600; }
#scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
#thread { max-width: 800px; margin: 0 auto; padding: 40px 24px 32px; font-size: calc(15px * var(--fs, 1)); }

/* فقاعة المستخدم الأنيقة والمتباينة */
.msg-user-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin: 26px 0 16px;
}
.msg-user {
  background: var(--user-bubble);
  border: 1px solid var(--user-border);
  border-radius: 20px 6px 20px 20px;
  padding: 12px 18px;
  width: fit-content;
  max-width: 85%;
  white-space: pre-wrap;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  line-height: 1.65;
}
.msg-user-wrap .bar { opacity: 0; transition: opacity var(--dur) var(--ease); }
.msg-user-wrap:hover .bar, .msg-user-wrap .bar:focus-within { opacity: 1; }
.bar { display: flex; align-items: center; gap: 4px; color: var(--faint); font-size: 12.5px; margin-top: 5px; }
.bar .icon-btn { width: 28px; height: 28px; color: var(--faint); border-radius: 7px; }
.bar .icon-btn:hover { color: var(--text); background: var(--panel-2); }
.bar .icon-btn svg { width: 15px; height: 15px; }
.bar .on { color: var(--accent); }
.bar time { margin-inline-start: 6px; }
.pinned .msg-user { box-shadow: 0 0 0 2px var(--accent), var(--shadow-sm); }
.msg-ai.pinned { border-inline-start: 3px solid var(--accent); padding-inline-start: 14px; }

/* شريط الرسائل المثبتة */
.pins {
  position: sticky;
  top: 0;
  z-index: 8;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  display: flex;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  padding: 10px 0;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--line-subtle);
}
.pins:empty { display: none; }
.pins button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: none;
  font-size: 13px;
  color: var(--muted);
  transition: all var(--dur) var(--ease);
}
.pins button:hover {
  background: var(--panel-2);
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-1px);
}

/* رد المساعد الذكي */
.msg-ai { margin: 0 0 16px; line-height: 1.8; color: var(--text); }
.msg-ai p { margin: .6em 0 1em; }
.msg-ai h1, .msg-ai h2, .msg-ai h3 {
  font-size: 1.2em;
  font-weight: 600;
  margin: 1.4em 0 .5em;
  color: var(--text);
  font-weight: 700;
}
.msg-ai blockquote {
  margin: .8em 0;
  padding: 8px 16px;
  border-inline-start: 3px solid var(--accent);
  background: var(--accent-bg);
  border-radius: 0 12px 12px 0;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 1.15em;
}
.msg-ai ul, .msg-ai ol { padding-inline-start: 1.5em; }
.msg-ai code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: .9em;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.cite {
  display: inline-block;
  color: var(--cite);
  font-weight: 600;
  font-size: .88em;
  padding: 0 3px;
  border-radius: 4px;
  background: var(--accent-bg);
  margin: 0 2px;
}

/* بطاقات استدعاء الأدوات */
.tools { margin: 8px 0 14px; }
.tools:empty { display: none; }
.tsum summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 14px 6px 10px;
  border-radius: 12px;
  user-select: none;
  background: var(--panel);
  border: 1px solid var(--line);
  transition: all var(--dur) var(--ease);
}
.tsum summary::-webkit-details-marker { display: none; }
.tsum summary:hover {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--line-2);
}
.tsum summary .chev { width: 13px; height: 13px; transform: rotate(180deg); transition: transform var(--dur) var(--ease); }
.tsum[open] summary .chev { transform: rotate(90deg); }
.tsum summary > svg:first-child { width: 14px; height: 14px; color: var(--accent); }
.tsum ol {
  margin: 8px 0 4px;
  padding: 6px 12px;
  border-inline-start: 2px solid var(--accent);
  background: var(--panel);
  border-radius: 0 12px 12px 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tsum li { color: var(--muted); font-size: 13px; }
.tool span { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.tool { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.tool svg { width: 14px; height: 14px; color: var(--accent); }
.tool.run svg { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.err {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  margin: 8px 0;
  white-space: pre-line;
}
.typing::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
.typing:empty::before { content: "يفكر… "; color: var(--muted); font-size: 14px; }
@keyframes blink { 50% { opacity: 0; } }

/* ══════════════════════════════════════════════
   صندوق الكتابة والواجهة الترحيبية
   ══════════════════════════════════════════════ */
#home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px 12vh;
}
.greet {
  display: flex;
  align-items: center;
  gap: 14px;
  font: 400 clamp(30px, 4.8vw, 42px)/1.3 var(--serif);
  margin-bottom: 30px;
  text-align: center;
  color: var(--text);
}
.greet svg {
  width: 42px;
  height: 42px;
  color: var(--accent);
  filter: drop-shadow(0 0 14px var(--accent-glow));
}
.composer-wrap { width: 100%; max-width: 720px; }
#bottom { padding: 0 20px 20px; display: none; }
#bottom .composer-wrap { margin: 0 auto; max-width: 780px; }
body.chatting #home { display: none; }
body.chatting #bottom { display: block; }

/* صندوق الكتابة الأساسي */
.composer {
  background: var(--composer-bg);
  border: 1px solid var(--line-2);
  border-radius: 24px;
  padding: 16px 20px 12px;
  box-shadow: var(--shadow-md), var(--hl);
  transition: all var(--dur) var(--ease);
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow-md);
}
.composer textarea {
  width: 100%;
  resize: none;
  background: none;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
  font-size: calc(15.5px * var(--fs, 1));
  max-height: 220px;
  min-height: 1.8em;
  line-height: 1.6;
  scrollbar-width: thin;
}
.composer textarea::placeholder {
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.hint { color: var(--faint); font-size: 12.5px; }
.row-end { display: flex; align-items: center; gap: 8px; }

/* عداد الرموز (Tokens) */
.ctx { display: block; width: 24px; height: 24px; cursor: default; position: relative; }
.ctx svg { width: 24px; height: 24px; transform: rotate(-90deg); }
.ctx circle { fill: none; stroke-width: 3.5; }
.ctx .bg { stroke: var(--line); }
.ctx .fg { stroke: #5b8def; stroke-linecap: round; transition: stroke-dashoffset .4s; }
.ctx.warn .fg { stroke: var(--accent); }
.ctx.full .fg { stroke: var(--danger); }

/* محدد النماذج */
.model {
  appearance: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  padding: 7px 12px 7px 28px;
  border-radius: 11px;
  cursor: pointer;
  outline: 0;
  max-width: 190px;
  direction: ltr;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%239ca3ab' stroke-width='2' d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 14px;
  background-position: left 8px center;
  transition: all var(--dur) var(--ease);
}
.model:hover {
  background-color: var(--panel-elevate);
  color: var(--text);
  border-color: var(--line-2);
}
.model option { background: var(--panel); color: var(--text); }
/* زر البحث المعمّق */
.deep {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  font: inherit; font-size: 13.5px; padding: 7px 12px; border-radius: 11px; cursor: pointer;
  transition: all var(--dur) var(--ease); white-space: nowrap;
}
.deep:hover { background-color: var(--panel-elevate); color: var(--text); border-color: var(--line-2); }
.deep[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.deep[hidden] { display: none; }
@media (max-width: 600px) { .hint { display: none; } }

/* زر الإرسال المتألق */
.send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 8px 18px -8px var(--accent);
  font-weight: 600;
  transition: all var(--dur) var(--ease);
}
.send svg { width: 18px; height: 18px; stroke: currentColor; }
.send:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}
.send:active { transform: scale(0.95); }
.send:disabled {
  opacity: .35;
  filter: grayscale(0.8);
  box-shadow: none;
  cursor: default;
  transform: none;
}

/* أسئلة مقترحة (Chips) */
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 20px; }
.chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 20px;
  color: var(--muted);
  font-size: 13.5px;
  box-shadow: var(--shadow-sm), var(--hl);
  transition: all var(--dur) var(--ease);
}
.chip:hover {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--accent-border);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.note { text-align: center; color: var(--faint); font-size: 12.5px; margin-top: 10px; }

/* ══════════════════════════════════════════════
   النوافذ المنبثقة والأزرار العامة
   ══════════════════════════════════════════════ */
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 22px;
  padding: 26px;
  width: min(450px, calc(100vw - 32px));
  box-shadow: var(--shadow-lg);
  animation: dlgIn .22s var(--ease);
}
@keyframes dlgIn {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
dialog::backdrop {
  background: rgba(4, 7, 12, .58);
  backdrop-filter: blur(6px);
}
dialog h2 { margin: 0 0 6px; font-size: 20px; font-weight: 700; }
dialog p { margin: 0 0 16px; color: var(--muted); font-size: 13.5px; }
dialog a { color: var(--cite); text-decoration: none; }
dialog a:hover { text-decoration: underline; }
dialog input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  color: var(--text);
  font: 14px monospace;
  direction: ltr;
  outline: 0;
  transition: all var(--dur) var(--ease);
}
dialog input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.status { font-size: 13px; margin: 10px 0 0; color: var(--muted); }
.actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 20px; }

/* أزرار الإجراءات */
.btn {
  padding: 9px 20px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  box-shadow: var(--hl);
  transition: all var(--dur) var(--ease);
}
.btn:hover {
  background: var(--panel-elevate);
  border-color: var(--line-2);
  box-shadow: var(--shadow-sm);
}
.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 8px 20px -10px var(--accent);
}
.btn.primary:hover {
  background: var(--accent-hover);
  border-color: transparent;
}
.btn:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }

/* ══════════════════════════════════════════════
   شاشات الحساب والتوثيق (Auth)
   ══════════════════════════════════════════════ */
#auth {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: none;
  overflow-y: auto;
}
body.locked #auth { display: flex; }
body.booting #auth { display: none; }  /* لا تظهر بطاقة الدخول فارغةً لحظة التحقق من الجلسة، بل عند الحاجة إليها فقط */
body.locked aside, body.locked main { visibility: hidden; }
.auth-card {
  margin: auto;
  width: min(420px, calc(100vw - 32px));
  padding: 36px 28px;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 26px;
  box-shadow: var(--shadow-lg);
}
.brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 28px; text-align: center; }
.brand svg {
  width: 48px;
  height: 48px;
  color: var(--accent);
  filter: drop-shadow(0 0 16px var(--accent-glow));
}
.brand h1 { font: 400 32px/1.3 var(--serif); margin: 0; color: var(--text); }
.brand p { margin: 0; color: var(--muted); font-size: 14px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--muted); }
.field input, .settings input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 15px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  outline: 0;
  width: 100%;
  transition: all var(--dur) var(--ease);
}
.field input:focus, .settings input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.field input[dir=ltr] { text-align: left; }
.code-input {
  letter-spacing: .5em;
  text-align: center !important;
  font-size: 24px !important;
  direction: ltr;
  font-weight: 600;
}
.auth-card .btn.primary { padding: 12px; font-size: 15px; width: 100%; }
.msg { font-size: 13.5px; min-height: 1.2em; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--success); }
.links { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-top: 6px; flex-wrap: wrap; }
.link { color: var(--cite); padding: 0; }
.link:hover { text-decoration: underline; }
.muted { color: var(--muted); font-size: 13.5px; margin: 0; }

/* ══════════════════════════════════════════════
   شريط ونطاق البحث (Scope)
   ══════════════════════════════════════════════ */
.scopebar { flex: none; display: flex; justify-content: center; padding: 12px 56px 0; }
.scope-in { width: 100%; max-width: 780px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.scope-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  color: var(--muted);
  font-size: 13px;
  background: var(--panel);
  box-shadow: var(--hl);
  transition: all var(--dur) var(--ease);
}
.scope-btn:hover {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--line-2);
}
.scope-btn svg { width: 15px; height: 15px; }
.scope-btn.on {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}
.chip-s {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px 4px 12px;
  font-size: 12.5px;
  max-width: 240px;
}
.chip-s span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.chip-s small { color: var(--faint); }
.chip-s button {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: var(--faint);
  line-height: 1;
  flex: none;
  display: grid;
  place-items: center;
}
.chip-s button:hover { background: var(--line); color: var(--text); }
.clear-s { color: var(--faint); font-size: 12.5px; padding: 4px 8px; border-radius: 6px; }
.clear-s:hover { color: var(--text); background: var(--panel-2); }

dialog.scope-dlg { width: min(600px, calc(100vw - 32px)); height: min(660px, calc(100vh - 40px)); padding: 24px; }
dialog.scope-dlg[open] { display: flex; flex-direction: column; gap: 12px; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.tabs button {
  padding: 8px 16px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-weight: 500;
  transition: all var(--dur) var(--ease);
}
.tabs button:hover { color: var(--text); }
.tabs button.cur { color: var(--accent); border-color: var(--accent); }
.tabs b { color: var(--accent); font-weight: 600; font-size: 12px; margin-inline-start: 4px; }
.scope-dlg input.q {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 14px;
  color: var(--text);
  font: inherit;
  outline: 0;
  transition: all var(--dur) var(--ease);
}
.scope-dlg input.q:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.picks { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.pick {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: start;
  padding: 9px 10px;
  border-radius: 11px;
  transition: all var(--dur) var(--ease);
}
.pick:hover { background: var(--panel-2); }
.pick .box {
  width: 19px;
  height: 19px;
  border: 1.5px solid var(--line-2);
  border-radius: 6px;
  flex: none;
  display: grid;
  place-items: center;
  transition: all var(--dur) var(--ease);
}
.pick.sel .box { background: var(--accent); border-color: var(--accent); }
.pick.sel .box::after { content: "✓"; color: var(--on-accent); font-size: 12px; font-weight: 700; }
.pick .t { flex: 1; min-width: 0; }
.pick .t div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); font-weight: 500; }
.pick .t small { color: var(--faint); font-size: 12px; }
.hint-s { color: var(--faint); font-size: 13px; padding: 14px 8px; text-align: center; }

.modes {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
}
.modes button {
  flex: 1;
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--dur) var(--ease);
}
.modes button:hover { color: var(--text); }
.modes button.cur {
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.scope-foot { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.scope-foot .sum { flex: 1; color: var(--muted); font-size: 13px; }

/* ══════════════════════════════════════════════
   نافذة الإعدادات الشاملة (Preferences)
   ══════════════════════════════════════════════ */
dialog.prefs {
  width: min(780px, calc(100vw - 32px));
  height: min(580px, calc(100vh - 40px));
  padding: 0;
  overflow: hidden;
  border-radius: 24px;
}
dialog.prefs[open] { display: grid; grid-template-columns: 210px 1fr; }
.prefs nav {
  background: var(--bg);
  border-inline-end: 1px solid var(--line);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.prefs nav h2 { font-size: 18px; margin: 0 10px 16px; font-weight: 600; color: var(--text); }
.prefs nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-align: start;
  font-weight: 500;
  transition: all var(--dur) var(--ease);
}
.prefs nav button svg { width: 18px; height: 18px; }
.prefs nav button:hover { background: var(--panel-2); color: var(--text); }
.prefs nav button.cur {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}
.prefs nav .spacer { flex: 1; }
.prefs .pane { overflow-y: auto; padding: 26px 30px; position: relative; outline: 0; }
.prefs button:focus { outline: 0; }
.prefs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.prefs .pane > section { display: none; }
.prefs .pane > section.cur { display: block; animation: fade .2s ease; }
.prefs .x { position: absolute; top: 16px; inset-inline-end: 16px; }
.prefs h3 { margin: 0 0 6px; font-size: 19px; font-weight: 600; color: var(--text); }
.prefs .lead { color: var(--muted); font-size: 14px; margin: 0 0 20px; line-height: 1.6; }
.prefs .item { display: flex; align-items: center; gap: 16px; padding: 16px 0; border-top: 1px solid var(--line); }
.prefs .item:first-of-type { border-top: 0; }
.prefs .item.col { flex-direction: column; align-items: stretch; gap: 10px; }
.prefs .label { flex: 1; min-width: 0; }
.prefs .label b { display: block; font-weight: 600; font-size: 14.5px; color: var(--text); }
.prefs .label small { color: var(--faint); font-size: 12.5px; line-height: 1.6; display: block; margin-top: 2px; }
.prefs input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: 0;
  direction: rtl;
  transition: all var(--dur) var(--ease);
}
.prefs input.key { font: 13.5px monospace; direction: ltr; text-align: left; }
.prefs input.key:not(:placeholder-shown) { -webkit-text-security: disc; text-security: disc; }
.prefs input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.prefs .row2 { display: flex; gap: 10px; }
.prefs .row2 input { flex: 1; min-width: 0; }
.prefs .btn { white-space: nowrap; }

.profile { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.profile .avatar { width: 56px; height: 56px; font-size: 24px; border-width: 2px; }
.profile b { display: block; font-size: 17px; font-weight: 600; color: var(--text); }
.profile small { color: var(--faint); direction: ltr; display: block; text-align: start; margin-top: 2px; }

.danger-zone {
  margin-top: 24px;
  border: 1px solid var(--danger-border);
  background: var(--danger-bg);
  border-radius: 14px;
  padding: 6px 16px;
}
.danger-zone .label b { color: var(--danger); }
.preview {
  border: 1px solid var(--line);
  background: var(--user-bubble);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: calc(15px * var(--fs, 1));
  line-height: 1.8;
  color: var(--text);
}

@media (max-width: 640px) {
  dialog.prefs[open] { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .prefs nav { flex-direction: row; overflow-x: auto; padding: 10px; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .prefs nav h2, .prefs nav .spacer { display: none; }
  .prefs nav button { flex: none; }
  .prefs .pane { padding: 20px 18px; }
  .prefs .item { flex-wrap: wrap; }
}

.settings { width: min(500px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow-y: auto; }
.settings section { border-top: 1px solid var(--line); padding: 18px 0; display: flex; flex-direction: column; gap: 12px; }
.settings section:first-of-type { border-top: 0; padding-top: 4px; }
.settings h3 { margin: 0; font-size: 16px; font-weight: 600; }
.settings .row2 { display: flex; gap: 10px; }
.settings .row2 input { flex: 1; min-width: 0; }
.settings .key { font: 14px monospace; direction: ltr; }

/* أزرار المقاسات وتغيير المظهر */
.sizes { display: flex; gap: 8px; }
.sizes button {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  padding: 9px 0;
  line-height: 1;
  font-weight: 500;
  transition: all var(--dur) var(--ease);
}
.sizes button:hover { background: var(--panel-2); color: var(--text); border-color: var(--line-2); }
.sizes button.cur {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
  box-shadow: 0 0 0 1px var(--accent-border);
}

/* شريحة الرصيد */
.bal-chip {
  margin-inline-start: auto;
  display: none;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  direction: ltr;
  transition: all var(--dur) var(--ease);
}
.bal-chip.show { display: inline-flex; }
.bal-chip:hover { background: var(--panel-2); color: var(--text); border-color: var(--line-2); }
.bal-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 6px hsla(152, 70%, 47%, 0.4); }
.bal-chip.low { color: var(--danger); border-color: var(--danger-border); }
.bal-chip.low .dot { background: var(--danger); box-shadow: 0 0 6px hsla(4, 88%, 62%, 0.4); }

.balance {
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13.5px;
}
.balance.show { display: flex; }
.balance .amt { font-size: 22px; font-weight: 700; direction: ltr; color: var(--text); }
.balance .meta { flex: 1; color: var(--muted); line-height: 1.5; }
.balance .meta b { color: var(--text); font-weight: 600; }
.balance .low { color: var(--danger); }
.btn.danger { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }
.btn.danger:hover { filter: brightness(1.15); box-shadow: var(--shadow-sm); }
.head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }

/* ──── التجاوب للشاشات الصغيرة ──── */
@media (max-width: 760px) {
  main, body.closed main { margin: 0; border-radius: 0; border-width: 0; box-shadow: none; }
  dialog, dialog.settings {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 24px 24px 0 0;
    border-bottom-width: 0;
    animation-name: sheetIn;
  }
  dialog.prefs { height: min(92dvh, 640px); }
  dialog.scope-dlg { height: 88dvh; }
  aside {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 30;
    box-shadow: 0 0 50px rgba(0, 0, 0, .6);
  }
  body.closed aside { display: none; }
  body:not(.closed) main::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(4px);
    z-index: 20;
  }
}

@keyframes sheetIn { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
