/* style.css — مِيراث
   مبدأ التصميم: المستخدم يتألم وينتظر. كل عنصر يجب أن يخفّف، لا أن يزيد الحمل.
   لوحة: أخضر عميق من الليل، ضوء دافئ، حواف ناعمة، حركة بطيئة كتنفّس. */

:root {
  /* ---- لوحة ---- */
  --ink:          #0a1410;
  --ink-2:        #0f1d16;
  --ink-3:        #14251c;
  --surface:      #132a20;
  --surface-2:    #1a3327;
  --line:         rgba(120, 190, 150, 0.14);
  --line-strong:  rgba(140, 210, 168, 0.28);

  --herb:         #74c69d;   /* أخضر النبات الرئيسي */
  --herb-soft:    #a7e0c2;
  --herb-deep:    #40916c;
  --leaf:         #95d5b2;

  --warm:         #e8c98a;   /* ضوء دافئ — قريب من العسل */
  --warm-soft:    #f2dfb6;
  --clay:         #c98474;   /* تحذير بلا فزع */
  --sky:          #8ecae6;

  --text:         #e8f3ec;
  --text-2:       #a9c4b6;
  --text-3:       #6f8c7f;

  --ok:           #7dd3a0;
  --warn:         #e8c98a;
  --bad:          #e08a7a;

  --radius:       18px;
  --radius-sm:    12px;
  --radius-lg:    26px;

  --shadow-soft:  0 8px 32px rgba(0, 0, 0, 0.28);
  --shadow-glow:  0 0 0 1px var(--line), 0 12px 48px rgba(116, 198, 157, 0.08);

  --font: "Nunito Sans", "Segoe UI", "Tahoma", system-ui, -apple-system, sans-serif;
  --font-display: "Aref Ruqaa", "Nunito Sans", "Segoe UI", system-ui, sans-serif;
  /* الرموز التعبيرية: دون هذا الخط يُرسم ✅ ⚠️ ❌ كمربعات فارغة (tofu)،
     وهي علامات الحكم — لا يجوز أن تختفي. */
  --font-emoji: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji",
                "Segoe UI Symbol", "Noto Emoji", sans-serif;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-slow: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- خطوط عربية + رموز ---- */
@import url("https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@300;400;600;700&family=Aref+Ruqaa:wght@400;700&family=Noto+Color+Emoji&display=swap");

* { box-sizing: border-box; }

/* [hidden] يعمل دائمًا: بعض القواعد أدناه تضبط display فتُبطل أثر السمة. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font), var(--font-emoji);
  font-size: 15.5px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

/* الخلفية والنوافذ والـ script خارج التدفق — فلا تُحسب في التوزيع */
.forest-bg, .modal, .modal[hidden], script { flex: none; }
.modal { position: fixed; }

/* ══════════════════════════════════════════
   خلفية الغابة — تنفّس هادئ
   ══════════════════════════════════════════ */

.forest-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(ellipse 120% 80% at 20% 0%, #16332610 0%, transparent 60%),
    radial-gradient(ellipse 100% 70% at 80% 100%, #1d3d2a20 0%, transparent 65%),
    linear-gradient(168deg, #0b1a13 0%, #0e1f16 50%, #0a1712 100%);
}

.glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.35;
  will-change: transform;
}

.glow-1 {
  width: 44vw; height: 44vw;
  top: -14vw; right: -10vw;
  background: radial-gradient(circle, rgba(116, 198, 157, 0.40), transparent 68%);
  animation: drift-1 28s ease-in-out infinite;
}
.glow-2 {
  width: 38vw; height: 38vw;
  bottom: -16vw; left: -12vw;
  background: radial-gradient(circle, rgba(232, 201, 138, 0.20), transparent 70%);
  animation: drift-2 34s ease-in-out infinite;
}
.glow-3 {
  width: 30vw; height: 30vw;
  top: 36%; left: 34%;
  background: radial-gradient(circle, rgba(64, 145, 108, 0.26), transparent 70%);
  animation: drift-3 40s ease-in-out infinite;
}

@keyframes drift-1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(-4vw, 6vh) scale(1.12); }
}
@keyframes drift-2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(5vw, -5vh) scale(1.08); }
}
@keyframes drift-3 {
  0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.32; }
  50%      { transform: translate(-6vw, -4vh) scale(1.18); opacity: 0.48; }
}

.vine {
  position: absolute;
  top: 0;
  height: 100%;
  width: 22%;
  color: rgba(116, 198, 157, 0.08);
  opacity: 0.7;
}
.vine-a { right: 4%; animation: sway-a 22s ease-in-out infinite; transform-origin: top center; }
.vine-b { left: 6%; animation: sway-b 26s ease-in-out infinite; transform-origin: top center; }

@keyframes sway-a {
  0%, 100% { transform: rotate(-1.4deg) scaleY(1); }
  50%      { transform: rotate(1.4deg) scaleY(1.03); }
}
@keyframes sway-b {
  0%, 100% { transform: rotate(1.2deg) scaleY(1.02); }
  50%      { transform: rotate(-1.2deg) scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
  .glow, .vine { animation: none !important; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ══════════════════════════════════════════
   الرأس
   ══════════════════════════════════════════ */

.app-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 20px;
  background: linear-gradient(180deg, rgba(12, 26, 19, 0.94), rgba(12, 26, 19, 0.62));
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(116, 198, 157, 0.34), rgba(64, 145, 108, 0.12));
  border: 1px solid var(--line-strong);
  color: var(--herb-soft);
  flex-shrink: 0;
  box-shadow: inset 0 0 18px rgba(116, 198, 157, 0.20), 0 0 20px rgba(116, 198, 157, 0.14);
}
.logo svg { width: 22px; height: 22px; }

.brand-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.32rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--herb-soft);
  line-height: 1.2;
}
.tagline {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.24s var(--ease);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover {
  color: var(--herb-soft);
  background: rgba(116, 198, 157, 0.10);
  border-color: var(--line);
  transform: translateY(-1px);
}
.icon-btn:active { transform: translateY(0) scale(0.96); }
.icon-btn:focus-visible { outline: 2px solid var(--herb); outline-offset: 2px; }

/* ══════════════════════════════════════════
   تنبيه
   ══════════════════════════════════════════ */

.notice {
  margin: 0;
  padding: 10px 20px;
  flex: none;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--warm-soft);
  background: linear-gradient(90deg, rgba(232, 201, 138, 0.10), rgba(232, 201, 138, 0.03));
  border-bottom: 1px solid rgba(232, 201, 138, 0.16);
}
.notice strong { color: var(--warm); }

/* ══════════════════════════════════════════
   الساحة
   ══════════════════════════════════════════ */

.stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.chat {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px clamp(14px, 4vw, 32px) 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(116, 198, 157, 0.22) transparent;
}
.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb {
  background: rgba(116, 198, 157, 0.20);
  border-radius: 8px;
}
.chat::-webkit-scrollbar-thumb:hover { background: rgba(116, 198, 157, 0.34); }

/* ---- الرسائل ---- */

.msg {
  display: flex;
  gap: 10px;
  max-width: min(78ch, 88%);
  animation: msg-in 0.46s var(--ease) both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.msg.user {
  align-self: flex-start;        /* RTL: يسار */
  flex-direction: row;
  margin-left: auto;
}
.msg.bot { align-self: flex-end; }

.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 32%, rgba(116, 198, 157, 0.24), rgba(26, 51, 39, 0.9));
  border: 1px solid var(--line);
  color: var(--herb);
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
}
.avatar svg { width: 17px; height: 17px; }

.bubble {
  position: relative;
  padding: 13px 17px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-family: var(--font), var(--font-emoji);
}

.msg.bot .bubble {
  border-bottom-right-radius: 6px;
  background: linear-gradient(168deg, rgba(26, 51, 39, 0.96), rgba(19, 42, 32, 0.94));
  border-color: var(--line);
}

.msg.user .bubble {
  border-bottom-left-radius: 6px;
  background: linear-gradient(168deg, rgba(64, 145, 108, 0.30), rgba(40, 104, 76, 0.20));
  border-color: rgba(116, 198, 157, 0.24);
  color: var(--text);
}

.bubble p {
  margin: 0 0 0.55em;
  line-height: 1.74;
}
.bubble p:last-child { margin-bottom: 0; }
.bubble p.muted { color: var(--text-3); font-size: 0.92em; }

/* خطوات مرقمة داخل الرد */
.bubble ol, .bubble ul {
  margin: 0.4em 0 0.7em;
  padding-inline-start: 1.35em;
}
.bubble li { margin-bottom: 0.32em; line-height: 1.7; }
.bubble li:last-child { margin-bottom: 0; }

/* ★ علامات الحكم: رموز نصية (✔ ✘ !) لا إيموجي، لأن الإيموجي يُرسم مربعًا
   فارغًا على أجهزة كثيرة — والعلامة هي الحكم نفسه لا زينة. */
.verdict-ok   { color: var(--ok);   font-weight: 700; }
.verdict-warn { color: var(--warn); font-weight: 700; }
.verdict-bad  { color: var(--bad);  font-weight: 700; }

.emoji-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  margin-inline-end: 5px;
  border-radius: 50%;
  font-size: 0.82em;
  font-weight: 800;
  line-height: 1;
  vertical-align: -0.1em;
  border: 1.2px solid currentColor;
}
.verdict-ok.emoji-mark   { background: rgba(125, 211, 160, 0.16); }
.verdict-warn.emoji-mark { background: rgba(232, 201, 138, 0.16); }
.verdict-bad.emoji-mark  { background: rgba(224, 138, 122, 0.16); }

/* صورة داخل الرد */
.thumb {
  display: block;
  max-width: 260px;
  max-height: 260px;
  border-radius: var(--radius-sm);
  margin-top: 10px;
  border: 1px solid var(--line);
  object-fit: cover;
}

/* ---- صورة المادة المقترحة ---- */

.herb-figure {
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(10, 20, 16, 0.5);
  border: 1px solid var(--line);
}
.herb-figure img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}
.herb-figure figcaption {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-3);
  line-height: 1.5;
}
.herb-figure figcaption a { color: var(--herb); }

/* ---- رسالة خطأ ---- */
.msg.error .bubble {
  background: rgba(192, 90, 74, 0.12);
  border-color: rgba(224, 138, 122, 0.32);
  color: #f0bdb2;
}

/* ══════════════════════════════════════════
   لوحة الأثر — ما يفعله الوكيل
   ══════════════════════════════════════════ */

/* Centred overlay. The panel used to pin to one edge, which left the
   layout unbalanced on wide screens and made it easy to miss. */
.trace {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(430px, calc(100% - 32px));
  max-height: min(80%, 580px);
  padding: 28px 26px 22px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(12, 26, 19, 0.975), rgba(9, 18, 14, 0.96));
  border: 1px solid var(--line-strong);
  box-shadow: 0 34px 90px rgba(0, 0, 0, 0.66), 0 0 0 1px rgba(116, 198, 157, 0.07);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  overflow-y: auto;
  animation: trace-pop 0.45s var(--ease) both;
  z-index: 30;
}

@keyframes trace-pop {
  from { opacity: 0; transform: scale(0.94) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* centre the header inside the panel */
.trace-head {
  justify-content: center;
  gap: 10px;
}
.trace-list { padding-inline: 4px; gap: 6px; }
.trace-item { padding: 12px 6px; }
.trace-foot { text-align: center; }
@keyframes trace-in {
  from { opacity: 0; transform: translateX(28px); }
  to   { opacity: 1; transform: translateX(0); }
}

.trace-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.trace-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--herb-soft);
  letter-spacing: 0.02em;
}

.trace-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--herb);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.8); }
  50%      { opacity: 1; transform: scale(1.25); }
}

.trace-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.trace-item {
  position: relative;
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 11px;
  padding: 10px 4px;
  border-radius: 10px;
  transition: background 0.3s var(--ease);
}

/* خط الحياة — جذع نبات */
.trace-item::before {
  content: "";
  position: absolute;
  inset-inline-start: 18px;
  top: 34px;
  bottom: -2px;
  width: 1.5px;
  background: linear-gradient(180deg, var(--line-strong), transparent);
}
.trace-item:last-child::before { display: none; }

.trace-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(19, 42, 32, 0.8);
  color: var(--text-3);
  font-size: 0.7rem;
  transition: all 0.5s var(--ease);
  position: relative;
  z-index: 1;
}
.trace-icon svg { width: 15px; height: 15px; }

.trace-body { min-width: 0; padding-top: 3px; }
.trace-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-3);
  line-height: 1.45;
  transition: color 0.4s var(--ease);
}
.trace-note {
  display: block;
  margin-top: 2px;
  font-size: 0.73rem;
  color: var(--text-3);
  line-height: 1.45;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: all 0.5s var(--ease);
}

/* الحالة: يعمل */
.trace-item[data-phase="start"] .trace-icon {
  color: var(--herb);
  border-color: var(--line-strong);
  animation: leaf-breathe 2.4s ease-in-out infinite;
}
.trace-item[data-phase="start"] .trace-label { color: var(--herb-soft); }

@keyframes leaf-breathe {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(116, 198, 157, 0.32);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 7px rgba(116, 198, 157, 0);
    transform: scale(1.06);
  }
}

/* الحالة: تمّ */
.trace-item[data-phase="end"] .trace-icon {
  color: var(--herb);
  border-color: rgba(116, 198, 157, 0.34);
  background: rgba(116, 198, 157, 0.12);
}
.trace-item[data-phase="end"] .trace-label { color: var(--text-2); }
.trace-item[data-phase="end"] .trace-note {
  max-height: 60px;
  opacity: 1;
}

/* الحالة: اعتراض المدقق */
.trace-item.warn[data-phase="end"] .trace-icon {
  color: var(--warn);
  border-color: rgba(232, 201, 138, 0.34);
  background: rgba(232, 201, 138, 0.10);
}
.trace-item.warn .trace-note { color: var(--warn); }

.trace-foot {
  margin: 18px 4px 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 0.72rem;
  color: var(--text-3);
  line-height: 1.55;
}

/* ══════════════════════════════════════════
   مبدّل المظهر
   ══════════════════════════════════════════ */

.theme-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}

.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  transition: border-color 0.24s var(--ease), transform 0.18s var(--ease);
}
.theme-swatch:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.theme-swatch[aria-checked="true"] {
  border-color: var(--herb);
  box-shadow: 0 0 0 2px rgba(116, 198, 157, 0.22);
}

.sw {
  width: 100%;
  height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.10);
}
.sw-forest { background: linear-gradient(168deg, #0b1a13, #0e1f16 50%, #0a1712); }
.sw-dusk   { background: linear-gradient(168deg, #17122a, #1e1836 50%, #120f22); }
.sw-ocean  { background: linear-gradient(168deg, #0a1826, #0d2135 50%, #081521); }
.sw-sand   { background: linear-gradient(168deg, #2a2419, #332c1f 50%, #241f15); }
.sw-plum   { background: linear-gradient(168deg, #24101a, #2d1420 50%, #1d0c14); }

.sw-name {
  font-size: 0.72rem;
  color: var(--text-3);
  font-family: var(--font);
}
.theme-swatch[aria-checked="true"] .sw-name { color: var(--herb-soft); }

/* ---- المظاهر: تُغيّر الخلفية ودرجات الأسطح فقط ---- */

/* بنفسجي هادئ */
body[data-theme="dusk"] { --ink: #120f22; --ink-2: #1e1836; --ink-3: #261e44; }
body[data-theme="dusk"] .forest-bg {
  background:
    radial-gradient(ellipse 120% 80% at 20% 0%, #2a24500d 0%, transparent 60%),
    radial-gradient(ellipse 100% 70% at 80% 100%, #3b2f6018 0%, transparent 65%),
    linear-gradient(168deg, #17122a 0%, #1e1836 50%, #120f22 100%);
}

/* أزرق بحري */
body[data-theme="ocean"] { --ink: #081521; --ink-2: #0d2135; --ink-3: #123049; }
body[data-theme="ocean"] .forest-bg {
  background:
    radial-gradient(ellipse 120% 80% at 20% 0%, #163a550d 0%, transparent 60%),
    radial-gradient(ellipse 100% 70% at 80% 100%, #1d4a6a18 0%, transparent 65%),
    linear-gradient(168deg, #0a1826 0%, #0d2135 50%, #081521 100%);
}

/* رملي فاتح */
body[data-theme="sand"] { --ink: #241f15; --ink-2: #332c1f; --ink-3: #43392a; }
body[data-theme="sand"] .forest-bg {
  background:
    radial-gradient(ellipse 120% 80% at 20% 0%, #3a301a0d 0%, transparent 60%),
    radial-gradient(ellipse 100% 70% at 80% 100%, #4a3d2218 0%, transparent 65%),
    linear-gradient(168deg, #2a2419 0%, #332c1f 50%, #241f15 100%);
}

/* عنابي */
body[data-theme="plum"] { --ink: #1d0c14; --ink-2: #2d1420; --ink-3: #3c1a2a; }
body[data-theme="plum"] .forest-bg {
  background:
    radial-gradient(ellipse 120% 80% at 20% 0%, #3d102210 0%, transparent 60%),
    radial-gradient(ellipse 100% 70% at 80% 100%, #50182c18 0%, transparent 65%),
    linear-gradient(168deg, #24101a 0%, #2d1420 50%, #1d0c14 100%);
}


/* ── Language selector ── */
.lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 6px;
}
.lang-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.22s var(--ease);
}
.lang-btn:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.lang-btn[aria-checked="true"] {
  border-color: var(--herb);
  background: rgba(116, 198, 157, 0.10);
  box-shadow: 0 0 0 2px rgba(116, 198, 157, 0.18);
}
.lang-code {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(116, 198, 157, 0.14);
  color: var(--herb-soft);
  font-size: 0.72rem;
  font-weight: 700;
}
.lang-name { font-size: 0.84rem; }
.lang-btn[aria-checked="true"] .lang-name { color: var(--herb-soft); }

/* English mode: force LTR text flow inside an RTL document */
body[data-lang="en"] { direction: ltr; }
body[data-lang="en"] .chat,
body[data-lang="en"] .composer,
body[data-lang="en"] .app-header,
body[data-lang="en"] .modal-card,
body[data-lang="en"] .trace { direction: ltr; }
body[data-lang="en"] .msg.user { margin-left: auto; margin-right: 0; }
body[data-lang="en"] .msg.bot { margin-right: auto; margin-left: 0; }
body[data-lang="en"] .checklist-list li { padding-inline: 14px 46px; }
body[data-lang="en"] .checklist-list li::before { inset-inline-start: auto; inset-inline-end: 14px; }

/* ══════════════════════════════════════════
   الشريط السفلي
   ══════════════════════════════════════════ */

.composer {
  flex: none;
  padding: 10px clamp(14px, 4vw, 32px) max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(10, 20, 16, 0.62), rgba(9, 18, 14, 0.98));
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  z-index: 8;
}

.preview {
  position: relative;
  display: inline-block;
  margin-bottom: 10px;
  animation: msg-in 0.4s var(--ease) both;
}
.preview img {
  max-height: 92px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  display: block;
}
.remove-img {
  position: absolute;
  top: -7px;
  inset-inline-start: -7px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(224, 138, 122, 0.4);
  background: var(--ink-3);
  color: var(--bad);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.2s var(--ease);
}
.remove-img svg { width: 11px; height: 11px; }
.remove-img:hover { background: rgba(224, 138, 122, 0.18); transform: scale(1.08); }

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 7px;
  border-radius: var(--radius-lg);
  background: rgba(19, 42, 32, 0.72);
  border: 1px solid var(--line);
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.input-row:focus-within {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px rgba(116, 198, 157, 0.07);
}

textarea#input {
  flex: 1;
  min-height: 40px;
  max-height: 140px;
  padding: 9px 4px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.6;
  resize: none;
  outline: none;
  scrollbar-width: thin;
}
textarea#input::placeholder { color: var(--text-3); }

.file-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.24s var(--ease);
  flex-shrink: 0;
}
.file-btn svg { width: 19px; height: 19px; }
.file-btn:hover {
  color: var(--herb-soft);
  background: rgba(116, 198, 157, 0.10);
}
.file-btn:active { transform: scale(0.94); }

.send-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(116, 198, 157, 0.34);
  background: linear-gradient(150deg, rgba(116, 198, 157, 0.90), rgba(64, 145, 108, 0.82));
  color: #07130d;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.24s var(--ease);
  box-shadow: 0 4px 18px rgba(64, 145, 108, 0.28);
}
.send-btn svg { width: 17px; height: 17px; }
.send-btn:hover:not(:disabled) {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 6px 24px rgba(116, 198, 157, 0.46);
}
.send-btn:active:not(:disabled) { transform: scale(0.96); }
.send-btn:disabled {
  opacity: 0.34;
  cursor: not-allowed;
  box-shadow: none;
}

.footnote {
  margin: 8px 6px 0;
  font-size: 0.71rem;
  color: var(--text-3);
  text-align: center;
  line-height: 1.5;
}

/* ══════════════════════════════════════════
   النوافذ
   ══════════════════════════════════════════ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 12, 9, 0.72);
  backdrop-filter: blur(10px);
  animation: fade-in 0.28s var(--ease) both;
}
.modal[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  width: min(460px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  padding: 24px;
  border-radius: var(--radius-lg);
  background: linear-gradient(168deg, var(--ink-2), var(--ink));
  border: 1px solid var(--line);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.6);
  animation: card-in 0.42s var(--ease-slow) both;
}
.modal-card.wide {
  width: min(680px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(22px) scale(0.975); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.12rem;
  color: var(--herb-soft);
  font-weight: 700;
}
.modal-close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.modal-close svg { width: 15px; height: 15px; }
.modal-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }

.step-label {
  margin: 18px 0 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--herb);
  letter-spacing: 0.02em;
}
.step-label:first-of-type { margin-top: 4px; }

.modal select,
.modal input[type="password"] {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(19, 42, 32, 0.86);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.24s var(--ease);
}
.modal select:focus,
.modal input[type="password"]:focus { border-color: var(--line-strong); }
.modal select option { background: var(--ink-2); color: var(--text); }

.hint {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--text-3);
  line-height: 1.62;
}
.hint code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(116, 198, 157, 0.10);
  color: var(--herb-soft);
  font-size: 0.92em;
  direction: ltr;
  display: inline-block;
}

.key-status {
  margin: 10px 0 0;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.5;
}
.key-status.good {
  background: rgba(125, 211, 160, 0.10);
  border: 1px solid rgba(125, 211, 160, 0.24);
  color: var(--ok);
}
.key-status.bad {
  background: rgba(224, 138, 122, 0.10);
  border: 1px solid rgba(224, 138, 122, 0.24);
  color: var(--bad);
}

.diag-row { margin-top: 18px; }
.diag-btn {
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(19, 42, 32, 0.8);
  color: var(--text-2);
  font-family: var(--font);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.22s var(--ease);
}
.diag-btn:hover { border-color: var(--line-strong); color: var(--herb-soft); }

.diag-out {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 10px;
  background: rgba(6, 14, 10, 0.8);
  border: 1px solid var(--line);
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.73rem;
  line-height: 1.65;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  direction: ltr;
  text-align: left;
  max-height: 220px;
  overflow-y: auto;
}

/* ══════════════════════════════════════════
   سجل المحادثات
   ══════════════════════════════════════════ */

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 0.86rem;
  line-height: 1.7;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  background: rgba(19, 42, 32, 0.62);
  border: 1px solid var(--line);
  transition: all 0.24s var(--ease);
}
.history-item:hover {
  border-color: var(--line-strong);
  background: rgba(26, 51, 39, 0.8);
}

.history-open {
  display: block;
  width: 100%;
  text-align: start;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  cursor: pointer;
  padding: 0;
  min-width: 0;
}
.history-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--herb-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.history-meta {
  display: block;
  font-size: 0.74rem;
  color: var(--text-3);
}

.history-del {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: all 0.22s var(--ease);
  flex-shrink: 0;
}
.history-del svg { width: 15px; height: 15px; }
.history-del:hover {
  color: var(--bad);
  background: rgba(224, 138, 122, 0.10);
  border-color: rgba(224, 138, 122, 0.24);
}

/* ---- تأكيد الحذف ---- */
.confirm-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.confirm-btn {
  padding: 7px 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.confirm-btn.danger {
  border-color: rgba(224, 138, 122, 0.4);
  color: var(--bad);
}
.confirm-btn.danger:hover { background: rgba(224, 138, 122, 0.14); }
.confirm-btn:hover { background: rgba(255, 255, 255, 0.05); }

/* ══════════════════════════════════════════
   العرض التوضيحي للعمل — SVG متحرك
   ══════════════════════════════════════════ */

.workflow-canvas {
  margin-top: 8px;
  border-radius: var(--radius);
  background: radial-gradient(circle at 50% 0%, rgba(116, 198, 157, 0.06), transparent 65%);
  border: 1px solid var(--line);
  padding: 12px;
  overflow: hidden;
}
.workflow-svg { display: block; width: 100%; height: auto; }

.wf-node circle {
  transition: fill 0.5s var(--ease), stroke 0.5s var(--ease);
}
.wf-node text {
  font-family: var(--font);
  font-size: 9.5px;
  fill: var(--text-2);
  text-anchor: middle;
  pointer-events: none;
}
.wf-node.active circle {
  fill: rgba(116, 198, 157, 0.28);
  stroke: var(--herb);
}
.wf-node.active text { fill: var(--herb-soft); }

.wf-link {
  stroke: rgba(116, 198, 157, 0.22);
  stroke-width: 1.4;
  fill: none;
  stroke-dasharray: 4 5;
  animation: dash-flow 2.4s linear infinite;
}
@keyframes dash-flow { to { stroke-dashoffset: -18; } }

.wf-particle {
  fill: var(--herb);
  filter: drop-shadow(0 0 5px rgba(116, 198, 157, 0.9));
}

.workflow-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
  font-size: 0.76rem;
  color: var(--text-3);
}
.workflow-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--herb);
  box-shadow: 0 0 8px rgba(116, 198, 157, 0.7);
}

/* ══════════════════════════════════════════
   قائمة التحقق
   ══════════════════════════════════════════ */

.checklist-list {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: gate;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.checklist-list li {
  counter-increment: gate;
  position: relative;
  padding-block: 12px;
  padding-inline: 46px 14px;
  border-radius: var(--radius-sm);
  background: rgba(19, 42, 32, 0.54);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  line-height: 1.6;
}
.checklist-list li::before {
  content: counter(gate);
  position: absolute;
  inset-inline-start: 14px;
  top: 12px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(116, 198, 157, 0.14);
  color: var(--herb);
  font-size: 0.72rem;
  font-weight: 700;
}
.checklist-list strong {
  display: block;
  color: var(--herb-soft);
  font-weight: 600;
  margin-bottom: 2px;
}
.checklist-list span { color: var(--text-3); font-size: 0.79rem; }

/* ══════════════════════════════════════════
   الشاشات الصغيرة
   ══════════════════════════════════════════ */

@media (max-width: 760px) {
  .trace {
    position: absolute;
    inset: 0;
    margin: auto;
    width: calc(100% - 28px);
    max-height: 76%;
    border-radius: var(--radius-lg);
    animation: trace-pop 0.4s var(--ease) both;
  }
  .msg { max-width: 94%; }
  .app-header { padding: 11px 14px; }
  .brand-text h1 { font-size: 1.16rem; }
  .tagline { display: none; }
  .icon-btn { width: 34px; height: 34px; }
  .header-actions { gap: 2px; }
}

@media (max-width: 420px) {
  body { font-size: 15px; }
  .chat { padding: 16px 12px 20px; gap: 11px; }
  .bubble { padding: 11px 14px; border-radius: 16px; }
  .avatar { display: none; }
}

/* ══════════════════════════════════════════
   مؤشر الكتابة
   ══════════════════════════════════════════ */

.typing .bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 15px 18px;
}
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--herb);
  opacity: 0.4;
  animation: typing-bounce 1.5s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-4px); }
}
