
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: var(--font);
  color:var(--text);
  background:
    radial-gradient(980px 620px at 18% 8%, color-mix(in oklab, var(--acc) 20%, transparent), transparent 56%),
    radial-gradient(900px 520px at 82% 14%, color-mix(in oklab, var(--user) 18%, transparent), transparent 60%),
    linear-gradient(135deg, #050b18, #0a1226 55%, #0d162e);
  overflow:hidden;
}
a{color:#c7d8ff}

.app{height:100vh;display:flex;flex-direction:column}

/* ===== Top Bar ===== */
.top{
  padding:12px 14px;
  display:flex;align-items:center;justify-content:space-between;gap:16px;
  background:linear-gradient(180deg, rgba(14,22,44,.72), rgba(10,16,28,.66));
  border-bottom:1px solid var(--stroke);
  backdrop-filter: blur(12px);
}
.brand{display:flex;align-items:center;gap:16px;min-width:220px}
.badge{
  width:48px;height:48px;border-radius:16px;
  border:1px solid var(--stroke2);
  background:linear-gradient(145deg, rgba(122,162,255,.24), rgba(45,183,166,.24));
  display:grid;place-items:center;
  box-shadow:0 12px 30px rgba(0,0,0,.20);
  overflow:hidden;
}
.brand .title{font-weight:900;letter-spacing:.2px;font-size:18px}
.brand .sub{font-size:12px;color:var(--muted);margin-top:2px}

.controls{display:flex;gap:10px;align-items:center;flex-wrap:wrap;justify-content:flex-end}
.pill{
  display:inline-flex;align-items:center;gap:8px;
  padding:8px 10px;border-radius:999px;
  border:1px solid var(--stroke);
  background:rgba(14,22,44,.58);
  font-size:12px;color:var(--muted);
  text-decoration:none;
  transition:transform .15s ease,border-color .15s ease;
}
.pill:hover{transform:translateY(-1px);border-color:rgba(122,162,255,.35)}
.dot{width:8px;height:8px;border-radius:50%}
.dot.ok{background:#2ee59d}.dot.bad{background:#ff6b6b}.dot.warn{background:#ffcc66}

select{
  border-radius:14px;
  border:1px solid var(--stroke);
  background:rgba(12,18,36,.62);
  color:var(--text);
  padding:8px 10px;outline:none;
  box-shadow:0 10px 22px rgba(0,0,0,.12);
}
select:focus{box-shadow:0 0 0 4px rgba(90,135,255,.12);border-color:rgba(90,135,255,.45)}

/* ===== Main ===== */
.main{flex:1;overflow:auto;scroll-behavior:smooth}
.wrap{max-width:1040px;margin:0 auto;padding:18px}

/* ✅ FIX: اجعل الـ Layout ثابت LTR حتى لا ينقلب الفليكس مع RTL */
.chat{display:flex;flex-direction:column;gap:16px; direction:ltr;}
.rowMsg{display:flex;gap:14px;align-items:flex-start;width:100%; direction:ltr;}

/* BOT دائمًا يسار */
.rowMsg.bot{
  flex-direction: row;
  justify-content: flex-start;
}

/* USER دائمًا يمين */
.rowMsg.user{
  flex-direction: row-reverse;
  justify-content: flex-start; /* مهم جدًا */
}

.avatar{
  width:54px;height:54px;border-radius:999px;
  border:3px solid rgba(255,255,255,.85);
  box-shadow:0 14px 32px rgba(0,0,0,.18);
  display:grid;place-items:center;
  flex:0 0 auto;
  background:linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.03));
  position:sticky; top:10px;
}
.avatar.bot,.avatar.user{border-color:rgba(45,183,166,.55)}
.avatar svg{width:32px;height:32px}

/* ===== Bubbles ===== */
.bubble{
  position:relative;
  max-width:78%;
  padding:15px 16px;
  border-radius:var(--r3);
  box-shadow:var(--shadow2);
  border:1px solid rgba(255,255,255,.10);
  line-height:1.85;
  backdrop-filter:blur(6px);
  transition:transform .15s ease, box-shadow .15s ease;
  animation:pop .18s ease-out;
}
@keyframes pop{from{transform:translateY(4px);opacity:.0}to{transform:translateY(0);opacity:1}}
.bubble:hover{transform:translateY(-1px);box-shadow:0 16px 44px rgba(0,0,0,.22)}

.bubble.bot{background:var(--bot);color:var(--botText)}
.bubble.user{
  background:linear-gradient(135deg, color-mix(in oklab, var(--user) 92%, white), var(--user));
  color:#06211d;
  border-color:rgba(255,255,255,.16)
}

/* ✅ ذيل ثابت: bot يسار, user يمين */
.bubble.bot:before{
  content:"";
  position:absolute; left:-10px; top:24px; bottom:auto;
  width:0;height:0;
  border-top:10px solid transparent;
  border-bottom:10px solid transparent;
  border-right:10px solid var(--bot);
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.08));
}
.bubble.user:before{
  content:"";
  position:absolute; right:-10px; top:24px; bottom:auto;
  width:0;height:0;
  border-top:10px solid transparent;
  border-bottom:10px solid transparent;
  border-left:10px solid var(--user);
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.08));
}

/* ✅ اتجاه النص فقط حسب اللغة */
body.rtl .bubble{direction:rtl;text-align:right}
body.ltr .bubble{direction:ltr;text-align:left}

/* Actions */
.actions{
  position:absolute; top:10px;
  display:flex; gap:8px;
  opacity:0; transition:all .15s ease;
}
.rowMsg.bot .actions{left:10px}
.rowMsg.user .actions{right:10px}
.bubble:hover .actions{opacity:1}

.iconBtn{
  width:32px;height:32px;border-radius:12px;
  border:1px solid rgba(0,0,0,.12);
  background:rgba(255,255,255,.62);
  color:#0c1430;
  cursor:pointer;
  display:grid;place-items:center;
  transition:transform .15s ease, background .15s ease;
}
.rowMsg.user .iconBtn{background:rgba(255,255,255,.40);border-color:rgba(255,255,255,.24)}
.iconBtn:hover{transform:translateY(-1px)}

.meta{
  margin-top:10px;font-size:11px;opacity:.76;
  display:flex;justify-content:space-between;gap:10px;
}

/* Markdown */
.md :is(h1,h2,h3){margin:12px 0 6px}
.md p{margin:8px 0}
.md ul,.md ol{margin:8px 18px}
.md code{background:rgba(0,0,0,.08);padding:2px 6px;border-radius:9px}
.md pre{
  background:rgba(0,0,0,.22)!important;
  border:1px solid rgba(0,0,0,.10);
  border-radius:16px;
  padding:12px;overflow:auto
}
.md pre code{background:transparent;padding:0}

/* Typing */
.typingDots{display:inline-flex;gap:7px;align-items:center}
.typingDots span{
  width:8px;height:8px;border-radius:999px;
  background:rgba(16,22,40,.35);
  animation:bop 1.1s infinite ease-in-out
}
.typingDots span:nth-child(2){animation-delay:.15s}
.typingDots span:nth-child(3){animation-delay:.30s}
@keyframes bop{0%,100%{transform:translateY(0);opacity:.55}50%{transform:translateY(-6px);opacity:1}}

/* Footer */
.footer{
  background:linear-gradient(180deg, rgba(12,18,36,.90), rgba(10,16,28,.92));
  border-top:1px solid var(--stroke);
  backdrop-filter: blur(12px);
  padding:14px 14px 16px;
}
.composer{
  max-width:1040px;margin:0 auto;
  display:flex;gap:10px;align-items:flex-end;
}
.box{
  flex:1;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(10,16,34,.58);
  border-radius:24px;
  padding:10px 12px;
  box-shadow:0 18px 52px rgba(0,0,0,.22);
}
textarea{
  width:100%;min-height:52px;max-height:170px;
  resize:vertical;border:0;outline:none;background:transparent;
  color:var(--text);font-family:inherit;font-size:14px;line-height:1.75;
}
.tools{display:flex;gap:10px;align-items:center}

.btn{
  border:0;cursor:pointer;height:52px;min-width:52px;
  border-radius:20px;display:grid;place-items:center;
  box-shadow:0 18px 40px rgba(0,0,0,.18);
  transition:transform .15s ease, filter .15s ease;
}
.btn:hover{transform:translateY(-1px)}
.btn.send{background:linear-gradient(135deg,var(--acc),#2ee59d);color:#06121d;font-weight:900}
.btn.send:disabled{opacity:.6;cursor:not-allowed;filter:grayscale(.2)}
.btn.ghost{background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.12);color:var(--text)}

/* Suggestions */
.suggestions{max-width:1040px;margin:10px auto 0;display:flex;gap:10px;flex-wrap:wrap}
.chip{
  border:1px solid rgba(255,255,255,.10);
  background:rgba(10,16,34,.42);
  color:var(--muted);
  border-radius:999px;padding:8px 12px;font-size:12px;cursor:pointer;
  transition:transform .15s ease,border-color .15s ease,color .15s ease;
}
.chip:hover{border-color:rgba(45,183,166,.35);color:var(--text);transform:translateY(-1px)}

/* Toast */
.toast{
  position:fixed;left:50%;bottom:18px;transform:translateX(-50%);
  background:rgba(12,18,36,.95);
  border:1px solid var(--stroke);
  padding:12px 14px;border-radius:18px;
  box-shadow:var(--shadow);
  display:none;min-width:280px;z-index:30
}
.toast.show{display:block}
.toast b{display:block;margin-bottom:4px}

/* Floating */
.fab{
  position:fixed;right:18px;bottom:92px;
  width:48px;height:48px;border-radius:18px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(12,18,36,.90);color:var(--text);
  display:none;place-items:center;
  box-shadow:var(--shadow);cursor:pointer;z-index:20
}
.fab.show{display:grid}

.menuBtn{
  width:42px;height:42px;
  display:none;align-items:center;justify-content:center;
  border-radius:14px;
  border:1px solid var(--stroke);
  background:rgba(255,255,255,.08);
  color:var(--text);
  cursor:pointer;
}
.drawerOverlay{
  position:fixed;inset:0;backdrop-filter:blur(6px);
  background:rgba(0,0,0,.45);display:none;z-index:80;
}
.drawer{
  position:fixed;top:0;bottom:0;
  width:280px;
  left:0;
  background:rgba(10,16,28,.95);
  border-inline-start:1px solid var(--stroke);
  box-shadow:var(--shadow);
  padding:18px;
  transform:translateX(-110%);
  transition:transform .2s ease;
  z-index:81;
}
body.rtl .drawer{left:auto;right:0;transform:translateX(110%);}
.drawer.show{transform:translateX(0);}
.drawerHeader{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:14px;}
.drawerLinks{display:grid;gap:10px;margin-bottom:14px;}
.drawerLinks a{
  display:flex;align-items:center;gap:10px;
  padding:10px 12px;
  border:1px solid var(--stroke);
  border-radius:12px;
  text-decoration:none;color:var(--text);
  background:rgba(255,255,255,.03);
}
.drawerLinks a .icon{
  width:32px;height:32px;display:grid;place-items:center;
  border-radius:10px;
  background:rgba(255,255,255,.08);
  border:1px solid var(--stroke);
}
.drawerSection{display:grid;gap:10px;}
.drawer select{
  width:100%;
  border-radius:12px;
  border:1px solid var(--stroke);
  background:rgba(255,255,255,.06);
  color:var(--text);
  padding:10px;
}

@media (max-width:640px){
  .bubble{max-width:88%}
  .avatar{width:50px;height:50px}
  .wrap{padding:14px}
  .controls .pill, .controls select{display:none}
  .menuBtn{display:inline-flex;}
}

/* Scrollbars */
.main::-webkit-scrollbar{width:10px}
.main::-webkit-scrollbar-thumb{background:rgba(255,255,255,.12);border-radius:999px;border:2px solid rgba(0,0,0,0)}
.main::-webkit-scrollbar-track{background:transparent}



/* Private chat history list */
.chatList{margin-top:10px;display:grid;gap:8px;max-height:45vh;overflow:auto;padding-right:2px}
.chatItem{display:block;padding:10px 12px;border:1px solid var(--border);border-radius:14px;background:rgba(255,255,255,.03);color:var(--text);text-decoration:none}
.chatItem:hover{border-color:rgba(255,255,255,.22)}
.chatItem.active{border-color:var(--acc);box-shadow:0 0 0 1px rgba(122,162,255,.35) inset}
.btn.ghost{background:transparent;border:1px solid var(--border)}
.btn.ghost:hover{border-color:rgba(255,255,255,.25)}
