/* ===== SyriaIO — الهوية البصرية ===== */
:root {
  --ink:        #0B0E14;
  --ink-2:      #0F131C;
  --surface:    #151B27;
  --surface-2:  #1C2434;
  --line:       rgba(255, 255, 255, 0.08);
  --line-soft:  rgba(255, 255, 255, 0.05);
  --text:       #F5F3EF;
  --muted:      #8A93A6;
  --gold:       #E8B04B;
  --gold-deep:  #C98F2E;
  --teal:       #4FD1C5;
  --danger:     #F0736A;
  --radius:     16px;
  --radius-sm:  11px;
  --shadow:     0 20px 60px rgba(0, 0, 0, 0.45);
  --font:       'IBM Plex Sans Arabic', system-ui, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--ink);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ===== العلامة ===== */
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand__mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: url('../img/logo-icon.png') center / contain no-repeat;
  position: relative; flex: 0 0 auto;
}
.brand__mark::after { content: none; }
.brand__name { font-weight: 700; font-size: 20px; letter-spacing: 0.2px; }
.brand__io { color: var(--gold); }
.brand--sm .brand__name { font-size: 17px; }

/* ===== أزرار عامة ===== */
.btn {
  font-family: var(--font); font-size: 15px; font-weight: 600;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  padding: 13px 18px; width: 100%; transition: transform .12s, filter .2s, background .2s;
}
.btn:active { transform: translateY(1px); }
.btn--gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: #241a05;
}
.btn--gold:hover { filter: brightness(1.06); }
.btn--gold:disabled { opacity: .6; cursor: default; filter: none; }

.link {
  background: none; border: none; color: var(--gold);
  font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer;
}
.link:hover { text-decoration: underline; }
.link--muted { color: var(--muted); font-weight: 500; }

.icon-btn {
  background: none; border: none; color: var(--muted);
  font-size: 20px; cursor: pointer; padding: 6px; border-radius: 8px; line-height: 1;
}
.icon-btn:hover { color: var(--text); background: var(--line-soft); }

/* ===== شاشة الدخول ===== */
.auth {
  min-height: 100dvh; display: grid; place-items: center;
  padding: 24px; position: relative; overflow: hidden;
}
.auth__glow {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(600px 340px at 70% -10%, rgba(232, 176, 75, 0.16), transparent 70%),
    radial-gradient(520px 320px at 15% 110%, rgba(79, 209, 197, 0.10), transparent 70%);
  animation: drift 14s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translateY(-16px) scale(1.04); } }

.auth__card {
  position: relative; z-index: 1; width: 100%; max-width: 400px;
  background: linear-gradient(180deg, rgba(28, 36, 52, 0.86), rgba(21, 27, 39, 0.86));
  backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 34px 28px;
}
.auth__title { font-size: 25px; font-weight: 700; margin-top: 22px; }
.auth__sub { color: var(--muted); font-size: 15px; margin-top: 4px; margin-bottom: 24px; }
.auth__switch { text-align: center; margin-top: 20px; color: var(--muted); font-size: 14px; }

/* ===== نماذج ===== */
.form { display: flex; flex-direction: column; gap: 15px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .composer textarea {
  font-family: var(--font); font-size: 15px; color: var(--text);
  background: var(--ink-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px; width: 100%;
  transition: border-color .2s, box-shadow .2s;
}
.field input::placeholder, .composer textarea::placeholder { color: #566072; }
.field input:focus, .composer textarea:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(232, 176, 75, 0.14);
}
.form__error {
  color: var(--danger); font-size: 13.5px; background: rgba(240, 115, 106, 0.09);
  border: 1px solid rgba(240, 115, 106, 0.25); border-radius: 10px; padding: 9px 12px;
}

/* ===== تخطيط التطبيق ===== */
.app { height: 100dvh; display: flex; overflow: hidden; }

.sidebar {
  width: 280px; flex: 0 0 280px; background: var(--ink-2);
  border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px;
}
.sidebar__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.sidebar__close { display: none; }

.btn--new {
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 16px;
}
.btn--new:hover { background: var(--surface-2); border-color: rgba(232, 176, 75, 0.4); }
.plus { color: var(--gold); font-size: 18px; font-weight: 700; }

.convos { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin: 0 -6px; padding: 0 6px; }
.convo {
  text-align: start; background: none; border: none; color: var(--muted);
  font-family: var(--font); font-size: 14.5px; cursor: pointer;
  padding: 11px 12px; border-radius: 10px; width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .15s, color .15s;
}
.convo:hover { background: var(--surface); color: var(--text); }
.convo.is-active { background: var(--surface-2); color: var(--text); box-shadow: inset 3px 0 0 var(--gold); }

.sidebar__foot { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 8px; display: flex; flex-direction: column; gap: 12px; }
.credits {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(232, 176, 75, 0.08); border: 1px solid rgba(232, 176, 75, 0.22);
  border-radius: 999px; padding: 7px 14px; width: fit-content;
}
.credits__coin { width: 15px; height: 15px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffd97a, var(--gold-deep)); box-shadow: 0 0 10px rgba(232,176,75,.4); }
.credits__num { font-weight: 700; color: var(--gold); }
.credits__label { font-size: 12.5px; color: var(--muted); }
.user { display: flex; align-items: center; justify-content: space-between; }
.user__name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar__scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 8; }

/* ===== منطقة المحادثة ===== */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--ink); }
.chat__bar {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--line); background: rgba(11, 14, 20, 0.7); backdrop-filter: blur(8px);
}
.chat__bar #menuBtn { display: none; }
.chat__title { font-weight: 600; font-size: 16px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__badge { font-size: 12px; color: var(--gold); border: 1px solid rgba(232,176,75,.3); border-radius: 999px; padding: 3px 10px; }

.messages { flex: 1; overflow-y: auto; padding: 24px 18px; display: flex; flex-direction: column; gap: 18px; }

.empty { margin: auto; text-align: center; color: var(--muted); max-width: 320px; }
.empty__mark {
  width: 76px; height: 76px; border-radius: 18px; display: inline-block; margin-bottom: 16px;
  background: url('../img/logo-icon.png') center / contain no-repeat; position: relative;
}
.empty__mark::after { content: none; }
.empty h2 { color: var(--text); font-size: 21px; margin-bottom: 6px; }

.msg { display: flex; gap: 12px; max-width: 760px; width: 100%; margin: 0 auto; animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.msg__avatar { width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.msg--user .msg__avatar { background: var(--surface-2); color: var(--text); }
.msg--ai .msg__avatar { background: linear-gradient(140deg, var(--gold), var(--gold-deep)); color: #241a05; }
.msg__body { padding-top: 3px; min-width: 0; flex: 1; }
.msg__role { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.msg__text { font-size: 15.5px; overflow-wrap: anywhere; word-wrap: break-word; }
.msg--user .msg__text { white-space: pre-wrap; }
.msg--ai .msg__text { color: #ECE9E3; }

.typing { display: inline-flex; gap: 5px; padding-top: 6px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); opacity: .5; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ===== صندوق الكتابة ===== */
.composer {
  display: flex; align-items: flex-end; gap: 10px; padding: 14px 18px 18px;
  border-top: 1px solid var(--line); background: var(--ink);
}
.composer textarea { resize: none; max-height: 160px; line-height: 1.5; }
.send {
  flex: 0 0 auto; width: 46px; height: 46px; border: none; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep)); color: #241a05;
  display: grid; place-items: center; transition: filter .2s, transform .12s;
}
.send:hover { filter: brightness(1.07); }
.send:active { transform: translateY(1px); }
.send:disabled { opacity: .5; cursor: default; }
/* اقلب أيقونة الإرسال باتجاه RTL */
.send svg { transform: scaleX(-1); }

/* ===== الجوال ===== */
@media (max-width: 760px) {
  .sidebar {
    position: fixed; inset-inline-start: 0; top: 0; bottom: 0; z-index: 9;
    transform: translateX(100%); transition: transform .25s ease; box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar__close { display: block; }
  .chat__bar #menuBtn { display: block; }
}

/* ===== تنسيق ردود المساعد (Markdown) ===== */
.msg--ai .msg__text > *:first-child { margin-top: 0; }
.msg--ai .msg__text > *:last-child { margin-bottom: 0; }
.msg--ai .msg__text p { margin: 0 0 10px; }
.msg--ai .msg__text h1,
.msg--ai .msg__text h2,
.msg--ai .msg__text h3,
.msg--ai .msg__text h4 { margin: 16px 0 8px; line-height: 1.3; font-weight: 700; }
.msg--ai .msg__text h1 { font-size: 20px; }
.msg--ai .msg__text h2 { font-size: 18px; }
.msg--ai .msg__text h3 { font-size: 16px; }
.msg--ai .msg__text ul,
.msg--ai .msg__text ol { padding-inline-start: 22px; margin: 0 0 10px; }
.msg--ai .msg__text li { margin-bottom: 5px; }
.msg--ai .msg__text a { color: var(--gold); text-decoration: underline; }
.msg--ai .msg__text strong { font-weight: 700; color: #fff; }
.msg--ai .msg__text blockquote {
  border-inline-start: 3px solid var(--gold); margin: 0 0 10px;
  padding: 2px 12px; color: var(--muted);
}
.msg--ai .msg__text hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* كود سطري */
.msg--ai .msg__text code {
  background: var(--surface-2); padding: 2px 6px; border-radius: 6px;
  font-family: 'Fira Code', 'Courier New', monospace; font-size: 13px;
  direction: ltr; unicode-bidi: embed;
}

/* جداول */
.msg--ai .msg__text table {
  border-collapse: collapse; display: block; overflow-x: auto;
  max-width: 100%; margin: 0 0 10px; font-size: 14px;
}
.msg--ai .msg__text th,
.msg--ai .msg__text td { border: 1px solid var(--line); padding: 6px 10px; text-align: start; }
.msg--ai .msg__text th { background: var(--surface); }

/* ===== صندوق الكود القابل للنسخ ===== */
.code-wrap { position: relative; margin: 12px 0; }
.code-wrap pre {
  background: #0A0D13; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; padding-top: 40px; overflow-x: auto;
  direction: ltr; text-align: left;
}
.code-wrap pre code {
  background: none; padding: 0; border-radius: 0;
  font-family: 'Fira Code', 'Courier New', monospace; font-size: 13px;
  color: #D7DAE0; white-space: pre; line-height: 1.6;
}
.code-copy {
  position: absolute; top: 8px; inset-inline-start: 8px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: var(--font); z-index: 2;
}
.code-copy:hover { border-color: var(--gold); color: var(--gold); }

/* ===== فقاعات الدردشة (تصميم محسّن) ===== */
.msg { display: flex; max-width: 860px; width: 100%; margin: 0 auto 10px; gap: 0; }
.msg--user { justify-content: flex-start; }
.msg--ai { justify-content: flex-end; }
.msg__avatar, .msg__role { display: none; }
.msg__body { min-width: 0; }

.bubble { max-width: 88%; padding: 11px 15px; border-radius: 16px; line-height: 1.75; }
.msg--user .bubble { background: linear-gradient(135deg, var(--gold), var(--gold-deep)); color: #241a05; border-end-end-radius: 5px; }
.msg--user .bubble .msg__text { color: #241a05; font-weight: 500; }
.msg--ai .bubble { background: var(--surface); border: 1px solid var(--line); color: var(--text); border-end-start-radius: 5px; }
.msg__text { font-size: 15.5px; overflow-wrap: anywhere; }

/* اقتراح توليد صورة */
.bubble--suggest { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.suggest__head { font-weight: 700; font-size: 15px; }
.suggest__prompt { font-size: 13.5px; color: var(--muted); direction: ltr; text-align: start; }
.suggest__btn { font-family: var(--font); font-size: 14px; font-weight: 600; background: linear-gradient(135deg, var(--gold), var(--gold-deep)); color: #241a05; border: none; border-radius: 10px; padding: 9px 16px; cursor: pointer; }
.suggest__btn:disabled { opacity: .6; cursor: default; }

/* صورة داخل الدردشة */
.bubble--img { padding: 6px; }
.chat-img { display: block; max-width: 100%; width: 320px; border-radius: 12px; }
.chat-img__dl { display: inline-block; margin-top: 6px; font-size: 13px; color: var(--gold); text-decoration: none; padding: 4px 8px; }

/* ===== القائمة الجانبية: تمرير + قوائم + استوديو ===== */
.sidebar { display: flex; flex-direction: column; height: 100dvh; }
.convos { flex: 1 1 auto; min-height: 60px; overflow-y: auto; padding: 4px 8px; }

.convo-row { position: relative; display: flex; align-items: center; gap: 2px; }
.convo-row .convo { flex: 1 1 auto; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo__more { flex: 0 0 auto; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 18px; padding: 4px 8px; border-radius: 8px; line-height: 1; }
.convo__more:hover { color: var(--gold); background: var(--ink-2); }

.convo-menu { position: absolute; top: 100%; inset-inline-start: 8px; z-index: 30; min-width: 170px; background: var(--ink-2); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 2px; }
.convo-menu__item { text-align: start; background: none; border: none; color: var(--text); font-family: var(--font); font-size: 13.5px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.convo-menu__item:hover { background: var(--surface-2); }
.convo-menu__item--danger { color: var(--danger); }

.studio { flex: 0 0 auto; border-top: 1px solid var(--line); padding: 10px 12px; max-height: 210px; overflow-y: auto; }
.studio__head { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.studio__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.studio__grid img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; }
.studio__empty { font-size: 12.5px; color: var(--muted); }

/* ===== إصلاح + تنظيف القائمة الجانبية ===== */
/* الأهم: القائمة تختفي فعلاً لما تكون hidden */
.convo-menu[hidden] { display: none !important; }

/* قائمة المحادثات: بسيطة ونظيفة */
.convos { padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.convo-row { border-radius: 10px; }
.convo-row:hover { background: var(--ink-2); }
.convo-row .convo {
  background: none !important; border: none !important;
  padding: 10px 10px !important; font-size: 14px; border-radius: 10px;
  color: var(--text); font-weight: 400;
}
.convo-row .convo.is-active { color: var(--gold); font-weight: 600; }
.convo__more { opacity: .55; font-size: 20px; }
.convo-row:hover .convo__more { opacity: 1; }

/* القائمة المنسدلة: بطاقة أنيقة */
.convo-menu {
  inset-inline-start: auto; inset-inline-end: 6px; top: calc(100% - 2px);
  min-width: 180px; padding: 6px;
  box-shadow: 0 12px 34px rgba(0,0,0,.55);
}
.convo-menu__item { padding: 11px 12px; font-size: 14px; }

/* الاستوديو: عنوان أوضح */
.studio__head { font-weight: 600; color: var(--text); }

/* ===== زر ➕ وأوضاع الوكلاء ===== */
.composer { position: relative; }
.composer .plus { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--ink-2); color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.composer .plus:hover { color: var(--gold); border-color: var(--gold); }
.agent-menu { position: absolute; bottom: 100%; inset-inline-start: 6px; margin-bottom: 8px; z-index: 30; background: var(--ink-2); border: 1px solid var(--line); border-radius: 14px; padding: 6px; display: flex; flex-direction: column; gap: 2px; box-shadow: 0 12px 34px rgba(0,0,0,.5); min-width: 200px; }
.agent-menu[hidden] { display: none !important; }
.agent-menu__item { display: flex; align-items: center; gap: 10px; background: none; border: none; color: var(--text); font-family: var(--font); font-size: 14px; padding: 11px 12px; border-radius: 10px; cursor: pointer; text-align: start; }
.agent-menu__item span { font-size: 17px; }
.agent-menu__item:hover { background: var(--surface-2); }
.agent-bar { max-width: 860px; margin: 0 auto 8px; display: flex; align-items: center; justify-content: space-between; gap: 10px; background: rgba(232,176,75,.1); border: 1px solid rgba(232,176,75,.3); border-radius: 12px; padding: 8px 14px; font-size: 13.5px; color: var(--gold); font-weight: 600; }
.agent-bar[hidden] { display: none !important; }
.agent-bar button { background: none; border: none; color: var(--gold); cursor: pointer; font-size: 15px; }

/* حالة توليد الصورة الفورية */
.img-loading { color: var(--muted); font-size: 14px; padding: 6px 2px; }

/* ===== شبكة الأوضاع (2×2) بالقائمة الجانبية ===== */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 4px 12px 12px; }
.mode { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px; background: var(--ink-2); border: 1px solid var(--line); border-radius: 14px; color: var(--text); font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s; }
.mode span { font-size: 22px; line-height: 1; }
.mode:hover { border-color: var(--gold); }
.mode.is-active { border-color: var(--gold); background: rgba(232,176,75,.12); color: var(--gold); }
