:root {
  --bg: #0a0b16;
  --bg-panel: #101223;
  --bg-elevated: #171a30;
  --bg-elevated-2: #1e2140;
  --bg-glass: rgba(23, 26, 48, 0.72);
  --border: rgba(255, 255, 255, 0.09);
  --border-soft: rgba(255, 255, 255, 0.05);
  --border-strong: rgba(255, 255, 255, 0.14);
  --purple: #7c6cf0;
  --purple-dim: #4b3f8a;
  --purple-glow: rgba(124, 108, 240, 0.4);
  --gold: #ffb84d;
  --gold-2: #ffcf70;
  --gold-dim: rgba(255, 184, 77, 0.14);
  --green: #4ade80;
  --red: #ff6b6b;
  --text: #edecf7;
  --text-dim: #9fa0c4;
  --text-faint: #6a6c94;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --font-ui: 'Vazirmatn', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background-image:
    radial-gradient(ellipse 900px 550px at 12% -12%, rgba(124, 108, 240, 0.2), transparent 55%),
    radial-gradient(ellipse 800px 500px at 105% 5%, rgba(255, 184, 77, 0.07), transparent 55%),
    radial-gradient(ellipse 600px 600px at 50% 120%, rgba(124, 108, 240, 0.08), transparent 60%);
  background-attachment: fixed;
}

::selection { background: var(--gold-dim); color: var(--gold); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); background-clip: padding-box; }

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns .35s var(--ease);
}
.app.canvas-open { grid-template-columns: 280px 1fr minmax(420px, 46%); }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 16px;
  position: relative;
  z-index: 25;
  /* روی دسکتاپ ارتفاع سلول گرید را پر کند تا لیست اسکرول شود و دکمه پایین همیشه دیده شود */
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px 4px;
  flex-shrink: 0;
}
.sidebar__brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--purple), var(--purple-dim));
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 800; color: var(--gold);
  box-shadow: 0 6px 20px var(--purple-glow);
}
.sidebar__brand-text { font-size: 15px; font-weight: 700; letter-spacing: -0.2px; }
.sidebar__brand-text span { color: var(--gold); }

.btn-new {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  background: linear-gradient(135deg, var(--gold), var(--gold-2));
  color: #2a1e00;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
  box-shadow: 0 6px 20px rgba(255, 184, 77, 0.25);
}
.btn-new:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(255, 184, 77, 0.38); }
.btn-new:active { transform: translateY(0); }

.btn-clear-all {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
  background: transparent;
  border: 1px solid rgba(255, 107, 107, 0.35);
  color: var(--red);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.btn-clear-all:hover {
  background: rgba(255, 107, 107, 0.1);
  border-color: var(--red);
}
.btn-clear-all:active {
  background: rgba(255, 107, 107, 0.16);
}

.sidebar__search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  transition: border-color .2s var(--ease);
  flex-shrink: 0;
}
.sidebar__search:focus-within { border-color: var(--purple); }
.sidebar__search svg { color: var(--text-faint); flex-shrink: 0; }
.sidebar__search input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: var(--font-ui); font-size: 13px;
}
.sidebar__search input::placeholder { color: var(--text-faint); }

.sidebar__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0 -4px;
  padding: 0 4px;
}
.sidebar__list-label {
  font-size: 11px;
  color: var(--text-faint);
  padding: 6px 10px 4px;
  font-weight: 600;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .18s var(--ease), color .18s var(--ease);
  position: relative;
}
.conv-item__icon { flex-shrink: 0; opacity: .6; }
.conv-item:hover { background: var(--bg-elevated); color: var(--text); }
.conv-item:hover .conv-item__icon { opacity: 1; }
.conv-item.active {
  background: var(--bg-elevated-2);
  color: var(--text);
  border-color: var(--border);
}
.conv-item.active::before {
  content: '';
  position: absolute;
  right: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: var(--gold);
  border-radius: 3px;
}
.conv-item__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.conv-item__del {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 5px;
  flex-shrink: 0;
  transition: all .15s var(--ease);
  /* روی موبایل حداقل ناحیه لمسی مناسب */
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.conv-item:hover .conv-item__del { opacity: 1; }
.conv-item__del:hover { color: var(--red); background: rgba(255,107,107,0.12); }
/* موبایل / لمسی: hover نداریم → دکمه حذف همیشه دیده شود */
@media (max-width: 860px), (hover: none) {
  .conv-item__del {
    opacity: 0.75;
    color: var(--text-dim);
  }
  .conv-item__del:active {
    color: var(--red);
    background: rgba(255,107,107,0.15);
    opacity: 1;
  }
}

/* ---------- Model picker ---------- */
.model-picker { position: relative; display: flex; flex-direction: column; gap: 7px; }
.model-picker__label { font-size: 11px; color: var(--text-faint); padding: 0 2px; font-weight: 600; }

.model-picker__btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  transition: border-color .2s var(--ease), background .2s var(--ease);
}
.model-picker__btn:hover { border-color: var(--purple); background: var(--bg-elevated-2); }
.model-picker__btn svg { flex-shrink: 0; color: var(--text-faint); transition: transform .25s var(--ease); }
.model-picker.open .model-picker__btn svg { transform: rotate(180deg); }
.model-picker__current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 7px; }
.model-picker__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex-shrink: 0; box-shadow: 0 0 8px var(--green); }

.model-picker__btn.is-locked {
  opacity: 0.72;
  cursor: not-allowed;
}
.model-picker__btn.is-locked:hover {
  border-color: var(--border);
  background: var(--bg-elevated);
}
.model-picker__btn.is-locked .model-picker__dot {
  background: var(--text-faint);
  box-shadow: none;
}

.model-picker__panel {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  bottom: auto;
  right: 0;
  left: 0;
  max-height: min(55vh, 480px);
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 40;
  animation: panelDown .22s var(--ease);
}
@keyframes panelDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.model-picker.open .model-picker__panel { display: block; }

.model-group { margin-bottom: 4px; }
.model-group:last-child { margin-bottom: 0; }

.model-group__head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.model-group__head:hover {
  background: var(--bg-elevated-2);
  border-color: var(--border-soft);
}
.model-group.is-open .model-group__head {
  background: rgba(124, 108, 240, 0.08);
  border-color: rgba(124, 108, 240, 0.2);
}
.model-group__head-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.model-group__chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  transition: transform .22s var(--ease);
  flex-shrink: 0;
}
.model-group.is-open .model-group__chevron {
  transform: rotate(180deg);
  color: var(--purple);
}
.model-group__title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  text-align: right;
}
.model-group__badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.model-group[data-key="reasoning"] .model-group__badge { background: rgba(124,108,240,0.22); color: #b3a4ff; }
.model-group[data-key="balanced"]  .model-group__badge { background: var(--gold-dim); color: var(--gold); }
.model-group[data-key="fast"]      .model-group__badge { background: rgba(74,222,128,0.15); color: var(--green); }
.model-group[data-key="image"]     .model-group__badge { background: rgba(255,122,199,0.18); color: #ff8fc7; }

.model-group__body {
  display: none;
  padding: 2px 0 6px;
}
.model-group.is-open .model-group__body {
  display: block;
  animation: groupOpen .2s var(--ease);
}
@keyframes groupOpen {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.model-group__desc {
  font-size: 11px;
  color: var(--text-faint);
  padding: 2px 10px 8px;
  line-height: 1.6;
}

.model-option {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .14s var(--ease);
}
.model-option:hover { background: var(--bg-elevated-2); }
.model-option.selected { background: var(--gold-dim); }
.model-option.selected .model-option__name { color: var(--gold); }
.model-option__name { font-size: 13px; color: var(--text); }
.model-option__note { font-size: 11px; color: var(--text-faint); white-space: nowrap; }
.model-option.selected .model-option__note { color: rgba(255,184,77,0.7); }
.model-divider { height: 1px; background: var(--border-soft); margin: 6px 4px; }

/* ---------- Main ---------- */
.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  z-index: 15;
}
.topbar__title { font-size: 14px; font-weight: 600; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }
.topbar__model-badge {
  font-size: 11px; padding: 5px 12px 5px 10px; border-radius: 20px;
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
  transition: border-color .2s var(--ease), color .2s var(--ease);
}
.topbar__model-badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 6px var(--green); flex-shrink: 0;
}
.topbar__model-badge.busy::before { background: var(--gold); box-shadow: 0 0 6px var(--gold); animation: liveDot 1s ease-in-out infinite; }

.topbar__cost-badge {
  font-size: 11px; font-family: var(--font-mono); font-weight: 600;
  padding: 5px 12px; border-radius: 20px; margin-right: 8px;
  background: rgba(255,178,0,0.1); border: 1px solid rgba(255,178,0,0.28);
  color: var(--gold);
  direction: ltr; unicode-bidi: isolate; white-space: nowrap;
}
.topbar__cost-badge.hidden { display: none; }

.topbar__badges {
  display: flex;
  align-items: center;
  min-width: 0;
}

.sidebar-toggle {
  display: none;
  width: 38px; height: 38px;
  align-items: center; justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
}

.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; scroll-behavior: smooth; }

.empty-state {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; gap: 12px; padding: 20px;
}
.empty-state__mark {
  width: 64px; height: 64px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--purple), var(--purple-dim));
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 800; color: var(--gold);
  box-shadow: 0 12px 40px var(--purple-glow);
  margin-bottom: 6px;
  animation: floatMark 4s ease-in-out infinite;
}
@keyframes floatMark { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.empty-state h1 { font-size: 24px; margin: 0; color: var(--text); font-weight: 700; }
.empty-state p { color: var(--text-dim); margin: 0; font-size: 14.5px; }
.empty-state.hidden { display: none; }

.empty-state__chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 12px; max-width: 520px; }

/* انتخاب مدل در صفحه خالی — همان زبان بصری منوی سایدبار */
.empty-model {
  width: 100%;
  max-width: 420px;
  margin: 6px auto 8px;
  padding: 12px;
  border-radius: 18px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  text-align: right;
  direction: rtl;
  box-sizing: border-box;
}
.empty-model__label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 0.2px;
  margin-bottom: 8px;
  padding: 0 4px;
}
.empty-model__hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(124, 108, 240, 0.1);
  border: 1px solid rgba(124, 108, 240, 0.28);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.7;
  direction: rtl;
  text-align: right;
}
.empty-model__hint[hidden] {
  display: none !important;
}
.empty-model__hint-icon {
  flex-shrink: 0;
  color: var(--purple);
  margin-top: 2px;
  display: flex;
}
.empty-model__hint-text {
  flex: 1;
  min-width: 0;
}
.empty-model__hint-text strong {
  color: var(--gold);
  font-weight: 700;
}
.empty-model__current {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.empty-model__current::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  flex-shrink: 0;
}
.empty-model__groups {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: min(48vh, 380px);
  overflow-y: auto;
  padding: 2px;
  -webkit-overflow-scrolling: touch;
}
/* استفاده از همان model-group / model-option سایدبار داخل کارت */
.empty-model .model-group {
  margin-bottom: 2px;
}
.empty-model .model-group__head {
  padding: 11px 10px;
  border-radius: 11px;
}
.empty-model .model-group__title {
  font-size: 13px;
}
.empty-model .model-group__body {
  padding: 2px 0 6px;
}
.empty-model .model-group__desc {
  padding: 2px 10px 8px;
  line-height: 1.65;
}
.empty-model .model-option {
  padding: 10px 12px;
  border-radius: 10px;
  gap: 8px;
}
.empty-model .model-option__name {
  font-size: 13px;
  font-weight: 500;
}
.empty-model .model-option__note {
  font-size: 11px;
  white-space: normal;
  text-align: left;
  direction: ltr;
  max-width: 42%;
  line-height: 1.35;
}
.empty-model .model-option.selected {
  box-shadow: inset 0 0 0 1px rgba(255, 184, 77, 0.35);
}

@media (max-width: 860px) {
  .empty-state {
    padding: 12px 14px 8px;
    justify-content: flex-start;
    padding-top: 18px;
  }
  .empty-state__mark {
    width: 48px;
    height: 48px;
    font-size: 22px;
    margin-bottom: 2px;
  }
  .empty-state h1 {
    font-size: 18px;
  }
  .empty-state p {
    font-size: 13px;
    margin-bottom: 4px;
  }
  .empty-model {
    max-width: 100%;
    margin: 4px 0 6px;
    padding: 10px;
    border-radius: 16px;
  }
  .empty-model__current {
    font-size: 13px;
    padding: 10px 11px;
    margin-bottom: 8px;
  }
  .empty-model__groups {
    max-height: min(40vh, 300px);
  }
  .empty-model .model-option {
    padding: 11px 12px;
    min-height: 44px;
  }
  .empty-model .model-option__note {
    max-width: 48%;
    font-size: 10.5px;
  }
  .empty-state__chips {
    margin-top: 8px;
    gap: 8px;
  }
  .suggest-chip {
    padding: 8px 12px;
    font-size: 12px;
  }
}

.suggest-chip {
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-dim); padding: 10px 16px; border-radius: 12px;
  font-size: 13px; cursor: pointer; transition: all .18s var(--ease); font-family: var(--font-ui);
}
.suggest-chip:hover { border-color: var(--purple); color: var(--text); transform: translateY(-2px); background: var(--bg-elevated-2); }

.messages {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 26px 22px 12px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* ---------- Message ---------- */
.msg { display: flex; gap: 13px; align-items: flex-start; animation: msgIn .35s var(--ease); }

@keyframes msgIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.msg__avatar {
  width: 32px; height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
}
.msg--assistant .msg__avatar {
  background: linear-gradient(135deg, var(--purple), var(--purple-dim));
  color: var(--gold);
  box-shadow: 0 4px 14px var(--purple-glow);
}
.msg--user .msg__avatar {
  background: var(--bg-elevated-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.msg__col { display: flex; flex-direction: column; gap: 6px; max-width: calc(100% - 46px); min-width: 0; }


.msg__bubble {
  max-width: 100%;
  padding: 13px 17px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.9;
  overflow-wrap: break-word;
  min-width: 0;
}
.msg--assistant .msg__bubble {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-top-right-radius: 5px;
  box-shadow: 0 2px 14px rgba(0,0,0,0.18);
}
.msg--user .msg__bubble {
  background: linear-gradient(135deg, var(--bg-elevated-2), var(--bg-elevated));
  border: 1px solid var(--border);
  color: var(--text);
  border-top-left-radius: 5px;
  box-shadow: 0 2px 14px rgba(0,0,0,0.14);
}

.msg__bubble p { margin: 0 0 10px; }
.msg__bubble p:last-child { margin-bottom: 0; }
.msg__bubble ul, .msg__bubble ol { margin: 8px 0; padding-inline-start: 22px; }
.msg__bubble li { margin: 4px 0; }
.msg__bubble a { color: var(--gold); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color .15s; }
.msg__bubble a:hover { border-bottom-color: var(--gold); }
.msg__bubble h1, .msg__bubble h2, .msg__bubble h3 { margin: 14px 0 8px; line-height: 1.4; }
.msg__bubble blockquote {
  border-inline-start: 3px solid var(--purple);
  margin: 10px 0; padding: 4px 14px; color: var(--text-dim);
  background: rgba(124,108,240,0.06); border-radius: 6px;
}
.msg__bubble code:not(pre code) {
  background: var(--gold-dim);
  color: var(--gold);
  padding: 1px 6px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.86em;
  unicode-bidi: isolate;
  direction: ltr;
}

/* پاراگراف‌های فارسی راست‌چین. کدهای اینلاین کوچک داخل متن جریان راست‌چین می‌مانند
   (isolate می‌شوند نه block/inline-block) تا وسط جمله به چپ پرش نکنند؛ فقط بلوک‌های
   کد کامل (فنس‌دار) با قرارداد استاندارد برنامه‌نویسی چپ‌چین نمایش داده می‌شوند. */
.msg__bubble { direction: rtl; text-align: right; }

.msg__cursor {
  display: inline-block;
  width: 8px; height: 15px;
  background: var(--gold);
  margin-inline-start: 3px;
  vertical-align: middle;
  border-radius: 2px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Message actions ---------- */
.msg__actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity .18s var(--ease);
}
.msg:hover .msg__actions, .msg:focus-within .msg__actions { opacity: 1; }

@media (hover: none) {
  .msg__actions { opacity: .65; }
}

.msg__action {
  display: flex; align-items: center; gap: 5px;
  background: none;
  border: 1px solid transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 5px 9px;
  border-radius: 8px;
  transition: all .15s var(--ease);
}
.msg__action:hover { color: var(--text); background: var(--bg-elevated); border-color: var(--border); }
.msg__action.done { color: var(--green); }
.msg__action svg { flex-shrink: 0; }

.messages {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 26px 22px 12px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* چیدمان یک‌طرفه (مثل Grok): همه پیام‌ها در یک سمت */
.msg {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  width: 100%;
  animation: msgIn .35s var(--ease);
}
@keyframes msgIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.msg__avatar {
  width: 32px; height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
}
.msg--assistant .msg__avatar {
  background: linear-gradient(135deg, var(--purple), var(--purple-dim));
  color: var(--gold);
  box-shadow: 0 4px 14px var(--purple-glow);
}
.msg--user .msg__avatar {
  background: linear-gradient(135deg, rgba(255, 184, 77, 0.28), rgba(255, 184, 77, 0.12));
  color: var(--gold);
  border: 1px solid rgba(255, 184, 77, 0.35);
}

.msg__col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.msg__bubble {
  width: 100%;
  max-width: 100%;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.9;
  overflow-wrap: break-word;
  min-width: 0;
  box-sizing: border-box;
}
.msg--assistant .msg__bubble {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  color: var(--text);
  box-shadow: 0 2px 14px rgba(0,0,0,0.18);
  border-inline-start: 3px solid var(--purple);
}
.msg--user .msg__bubble {
  background: rgba(255, 184, 77, 0.07);
  border: 1px solid rgba(255, 184, 77, 0.22);
  color: var(--text);
  box-shadow: 0 2px 14px rgba(0,0,0,0.12);
  border-inline-start: 3px solid var(--gold);
}



/* ---------- Thinking indicator ---------- */
.thinking {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 3px 0;
  min-width: 180px;
}
.thinking__row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.thinking__dots { display: flex; gap: 4px; flex-shrink: 0; }
.thinking__dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold); opacity: .35;
  animation: thinking-bounce 1.1s ease-in-out infinite;
}
.thinking__dots span:nth-child(2) { animation-delay: .15s; }
.thinking__dots span:nth-child(3) { animation-delay: .3s; }
@keyframes thinking-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30% { transform: translateY(-5px); opacity: 1; }
}
.thinking__label {
  font-size: 13px; color: var(--text-dim);
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px;
  background: linear-gradient(90deg, var(--text-dim) 0%, var(--gold) 50%, var(--text-dim) 100%);
  background-size: 200% auto;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 2.2s linear infinite;
}
.thinking__label-text { }
.thinking-timer {
  -webkit-text-fill-color: var(--text-faint);
  background: none;
  font-family: var(--font-mono);
  font-size: 12px;
}
@keyframes shimmer { 0% { background-position: 200% center; } 100% { background-position: -200% center; } }

/* نوار پیشرفت آپلود تصویر */
.thinking__progress {
  display: flex;
  align-items: center;
  gap: 10px;
  direction: ltr;
  unicode-bidi: isolate;
  padding: 0 2px;
}
.thinking__progress[hidden] { display: none !important; }
.thinking__progress-track {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  min-width: 80px;
}
.thinking__progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold), var(--gold-2));
  box-shadow: 0 0 12px rgba(255, 184, 77, 0.45);
  transition: width .18s linear;
}
.thinking__progress-bar.is-done {
  background: linear-gradient(90deg, var(--green), #6ee7a8);
  box-shadow: 0 0 12px rgba(74, 222, 128, 0.35);
}
.thinking__progress-pct {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--gold);
  min-width: 2.6em;
  text-align: right;
  flex-shrink: 0;
}

/* ---------- Code block ---------- */
.code-block {
  direction: ltr;
  text-align: left;
  margin: 12px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #090b18;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}
.code-block__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}
.code-block__lang {
  display: inline-flex; align-items: center; gap: 7px;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-dim); font-weight: 600; font-size: 11.5px;
}
.code-block__dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--lang-accent, var(--gold));
  box-shadow: 0 0 8px color-mix(in srgb, var(--lang-accent, var(--gold)) 60%, transparent);
}
.code-block__actions { display: flex; gap: 6px; }
.code-block__copy {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 1px solid transparent;
  color: var(--text-faint);
  font-family: var(--font-ui); font-size: 12px;
  padding: 5px 10px; border-radius: 7px; cursor: pointer;
  transition: all .15s var(--ease);
}
.code-block__copy svg { width: 12px; height: 12px; }
.code-block__copy:hover { color: var(--text); background: var(--bg-elevated-2); border-color: var(--border); }
.code-block__copy.copied { color: var(--green); }
.code-block pre {
  margin: 0; padding: 15px 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px; line-height: 1.7;
}
.code-block pre code { background: none !important; padding: 0 !important; }

/* شماره‌ی خط (فقط برای نمای بزرگ کانواس) */
.code-block--numbered .code-block__content { display: flex; align-items: stretch; }
.code-block__gutter {
  flex-shrink: 0;
  user-select: none;
  padding: 15px 12px 15px 14px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px; line-height: 1.7;
  color: var(--text-faint);
  background: rgba(255,255,255,0.015);
  border-inline-end: 1px solid var(--border-soft);
}
.code-block__gutter span { display: block; }
.code-block--numbered pre { flex: 1; min-width: 0; }

/* بلوک کد کوتاهی که هنوز در حال تولید (استریم) است */
.code-block.is-live { border-color: rgba(124,108,240,0.45); }
.code-block.is-live .code-block__header::after {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--purple); margin-inline-start: 6px;
  display: inline-block; animation: liveDot 1s ease-in-out infinite;
}
@keyframes liveDot { 0%,100% { opacity: .3; } 50% { opacity: 1; } }

/* ---------- Canvas card (پاسخ‌های طولانی کد) ---------- */
.canvas-card {
  direction: ltr;
  margin: 14px 0;
  max-width: 420px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  transition:
    transform .18s var(--ease),
    box-shadow .18s var(--ease),
    border-color .18s var(--ease),
    background-color .18s var(--ease);
}
.canvas-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  background: var(--bg-elevated-2);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
}
.canvas-card__body {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 14px;
}
.canvas-card__icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: color-mix(in srgb, var(--lang-accent, var(--purple)) 16%, var(--bg-elevated-2));
  border: 1px solid color-mix(in srgb, var(--lang-accent, var(--purple)) 30%, transparent);
  display: flex; align-items: center; justify-content: center;
  color: var(--lang-accent, #c4b8ff);
}
.canvas-card__icon svg { width: 18px; height: 18px; }
.canvas-card__meta { flex: 1; min-width: 0; direction: rtl; text-align: right; }
.canvas-card__title {
  font-size: 13.5px; font-weight: 600; color: var(--text);
  margin-bottom: 4px; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.canvas-card__sub {
  font-size: 11px; color: var(--text-faint);
  display: flex; align-items: center; gap: 9px; direction: ltr; justify-content: flex-end; flex-wrap: wrap;
  font-family: var(--font-mono);
}
.canvas-card__lang { color: var(--lang-accent, var(--text-dim)); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.canvas-card__open {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-elevated-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 12px;
  font-family: var(--font-ui); font-size: 12px; font-weight: 600;
  cursor: pointer; flex-shrink: 0;
  transition: all .15s var(--ease);
}
.canvas-card:hover .canvas-card__open {
  color: var(--text); border-color: var(--lang-accent, var(--border-strong));
}
.canvas-card__open svg { flex-shrink: 0; opacity: 0.9; width: 13px; height: 13px; }
.canvas-card__progress {
  height: 2px; background: var(--border-soft); position: relative; overflow: hidden;
}
.canvas-card__progress::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--lang-accent, var(--purple)), transparent);
  animation: canvasProg 1.5s linear infinite;
}
.canvas-card.done .canvas-card__progress { display: none; }
@keyframes canvasProg { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* لحظه‌ی ارتقاء بلوک کد به کارت کانواس (فقط یک‌بار پخش می‌شود) */
.canvas-card--enter {
  animation: canvasCardIn .55s cubic-bezier(.16,1,.3,1) both;
}
@keyframes canvasCardIn {
  0% { opacity: 0; transform: translateY(14px) scale(.94); box-shadow: 0 0 0 rgba(124,108,240,0); }
  55% { opacity: 1; transform: translateY(-3px) scale(1.015); box-shadow: 0 10px 30px rgba(124,108,240,0.25); }
  100% { opacity: 1; transform: translateY(0) scale(1); box-shadow: 0 2px 10px rgba(0,0,0,0.15); }
}

/* ---------- Canvas panel (پنل کناری) ---------- */
.canvas-panel {
  background: #0d0f1c;
  border-inline-start: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transform: translateX(100%);
  box-shadow: -18px 0 40px rgba(0, 0, 0, 0.25);
  transition: transform .38s cubic-bezier(.22, 1, .36, 1);
}
.app.canvas-open .canvas-panel { transform: translateX(0); }

.canvas-panel__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-panel);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}
.canvas-panel__title {
  display: flex; align-items: center; gap: 9px;
  font-size: 13.5px; font-weight: 600; color: var(--text-dim);
  min-width: 0;
  flex: 1;
  overflow: hidden;
}
.canvas-panel__title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.canvas-panel__title svg { color: var(--text-faint); width: 16px; height: 16px; flex-shrink: 0; }
.canvas-panel__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.canvas-panel__btn {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 500;
  padding: 7px 12px; border-radius: 8px; transition: all .15s var(--ease);
  white-space: nowrap;
}
.canvas-panel__btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.canvas-panel__btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-elevated); }
.canvas-panel__btn.done { color: var(--green); border-color: var(--green); }
.canvas-panel__close {
  width: 32px; height: 32px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer; border-radius: 8px;
  transition: all .15s var(--ease);
  flex-shrink: 0;
}
.canvas-panel__close:hover { color: var(--red); border-color: var(--red); background: rgba(255,90,90,0.08); }

.canvas-panel__body { flex: 1; overflow-y: auto; padding: 16px; direction: ltr; text-align: left; }
.canvas-panel__body .code-block { margin: 0; border-radius: 12px; }
.canvas-panel__streaming {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 13px; margin-bottom: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: 9px; font-size: 12.5px; color: var(--text-dim); direction: rtl;
}

/* ---------- Composer ---------- */
.composer { padding: 10px 20px 20px; background: linear-gradient(180deg, transparent, var(--bg) 35%); }
.composer__box {
  max-width: 820px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px 10px 10px;
  box-shadow: 0 12px 44px rgba(0,0,0,0.4);
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.composer__box:focus-within { border-color: var(--purple); box-shadow: 0 12px 44px rgba(124,108,240,0.18); }

.btn-attach {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 13px;
  border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .15s var(--ease);
}
.btn-attach:hover { color: var(--gold); border-color: var(--gold); background: var(--gold-dim); }
.btn-attach.has-files { color: var(--gold); border-color: var(--gold); }
/* مدل‌های تصویری فقط‌تولید: دکمه پیوست غیرفعال و واضح */
.btn-attach.is-disabled {
  opacity: 0.38;
  cursor: not-allowed;
  color: var(--text-faint);
  border-color: var(--border-soft);
  background: var(--bg-elevated);
}
.btn-attach.is-disabled:hover {
  color: var(--text-faint);
  border-color: var(--border-soft);
  background: var(--bg-elevated);
  transform: none;
}
.btn-attach.is-disabled.has-files {
  color: var(--text-faint);
  border-color: var(--border-soft);
}

.file-chips { max-width: 820px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.file-chips:empty { display: none; }
.file-chip {
  display: flex; align-items: flex-start; gap: 7px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 11px; padding: 7px 9px 7px 6px;
  font-size: 12.5px; color: var(--text); max-width: 260px;
  animation: chipIn .25s var(--ease);
}
@keyframes chipIn { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }
.file-chip__icon {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 7px;
  background: var(--gold-dim); color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 10px; font-weight: 700; text-transform: uppercase;
  margin-top: 1px;
}
.file-chip__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: left; display: block; }
.file-chip__size { color: var(--text-faint); font-size: 11px; flex-shrink: 0; }
.file-chip__meta {
  display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1;
}
.file-chip__tokens {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  color: var(--text-dim); direction: ltr; unicode-bidi: isolate;
}
.file-chip__cost {
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--gold); direction: ltr; unicode-bidi: isolate;
  min-height: 13px;
}
.file-chip__remove {
  flex-shrink: 0; background: none; border: none; color: var(--text-faint);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
.file-chip__remove:hover { color: var(--red); background: rgba(255,107,107,0.12); }

.msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.msg-attachments .file-chip { cursor: default; }

.file-chip--image { align-items: center; padding: 6px; max-width: 220px; }
.file-chip__thumb {
  flex-shrink: 0; width: 32px; height: 32px; border-radius: 7px;
  object-fit: cover; background: var(--bg-elevated); margin-top: 0;
}
.file-chip__thumb--placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gold-dim);
  color: var(--gold);
  border: 1px solid rgba(255, 184, 77, 0.25);
}
.file-chip--image .file-chip__name { flex: 1; min-width: 0; }
.file-chip--image .file-chip__size { margin-inline-start: 2px; }

#promptInput {
  flex: 1; background: none; border: none; outline: none; resize: none;
  color: var(--text); font-family: var(--font-ui);
  font-size: 14.5px; line-height: 1.7; max-height: 200px; padding: 8px 4px;
  /* جهت را صریحاً راست‌چین قفل می‌کنیم تا وقتی خط با کلمه یا کد انگلیسی/لاتین
     شروع می‌شود، مرورگر آن خط را خودکار چپ‌چین نکند و ناگهان به چپ نپرد */
  direction: rtl;
  text-align: right;
}
#promptInput::placeholder { color: var(--text-faint); }

.btn-send {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 13px;
  border: none; background: var(--gold); color: #2a1e00;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform .15s var(--ease), opacity .15s var(--ease);
}
.btn-send:hover { transform: scale(1.06); }
.btn-send:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.btn-send.stop { background: var(--red); color: #fff; }

.composer__hint { text-align: center; color: var(--text-faint); font-size: 11.5px; margin-top: 9px; }

/* ---------- Generated images ---------- */
.msg-images {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  /* حباب پیام RTL است؛ ایزوله کردن جهت جلوی عرض صفر کارت روی موبایل را می‌گیرد */
  direction: ltr;
  unicode-bidi: isolate;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.msg-image-card {
  direction: ltr;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  /* بدون width مشخص، img با width:100% داخل flex گاهی روی موبایل ۰ عرض می‌شود */
  width: 100%;
  max-width: min(420px, 100%);
  min-width: 0;
  box-sizing: border-box;
  transition: border-color .15s var(--ease), transform .15s var(--ease);
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}
.msg-image-card:hover { border-color: var(--border-strong); }
.msg-image-card img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  min-height: 80px;
  object-fit: contain;
  object-position: center;
  vertical-align: middle;
  background: var(--bg);
  cursor: zoom-in;
  -webkit-user-select: none;
  user-select: none;
}
.msg-image-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border-soft);
}
.msg-image-card__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  transition: all .15s var(--ease);
  appearance: none;
  -webkit-appearance: none;
  line-height: 1.3;
}
.msg-image-card__btn:hover,
.msg-image-card__btn:active {
  color: var(--text);
  border-color: #ff8fc7;
  background: rgba(255,122,199,0.1);
}
.msg-image-card__btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* اسکلتون لودینگ تا تصویر کامل آماده شود */
.msg-image-card.is-loading {
  min-height: 200px;
}
.msg-image-card__skeleton {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 200px;
  padding: 28px 16px;
  background:
    linear-gradient(110deg, var(--bg-elevated) 30%, var(--bg-elevated-2) 45%, var(--bg-elevated) 60%);
  background-size: 200% 100%;
  animation: imgSkeletonShine 1.4s ease-in-out infinite;
}
@keyframes imgSkeletonShine {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.msg-image-card__spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 184, 77, 0.2);
  border-top-color: var(--gold);
  animation: imgSpin .75s linear infinite;
}
@keyframes imgSpin {
  to { transform: rotate(360deg); }
}
.msg-image-card__skeleton-text {
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
  direction: rtl;
  font-family: var(--font-ui);
}
.msg-image-card__skeleton-text.is-error {
  color: var(--red);
}
.msg-image-card.is-error .msg-image-card__skeleton {
  animation: none;
  background: var(--bg-elevated);
  min-height: 120px;
}
.msg-image-card__img.is-fade-in {
  animation: imgFadeIn .35s var(--ease);
}
@keyframes imgFadeIn {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}

/* ---------- Lightbox بزرگ‌نمایی تصویر ---------- */
.img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 7, 16, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .22s var(--ease), visibility .22s var(--ease);
  padding: 48px 16px 16px;
}
.img-lightbox.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.img-lightbox__close {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .15s var(--ease);
}
.img-lightbox__close:hover {
  background: rgba(255, 107, 107, 0.18);
  border-color: var(--red);
  color: var(--red);
  transform: scale(1.05);
}
.img-lightbox__stage {
  max-width: min(96vw, 1100px);
  max-height: calc(100vh - 64px);
  max-height: calc(100dvh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.img-lightbox__img {
  max-width: 100%;
  max-height: calc(100vh - 64px);
  max-height: calc(100dvh - 64px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  background: var(--bg-panel);
  user-select: none;
  -webkit-user-drag: none;
}
@media (max-width: 860px) {
  .img-lightbox { padding: 56px 10px 12px; }
  .img-lightbox__close { top: 10px; left: 10px; width: 40px; height: 40px; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated-2); border: 1px solid var(--border-strong);
  color: var(--text); padding: 11px 18px; border-radius: 12px;
  font-size: 13px; box-shadow: var(--shadow-lg); z-index: 100;
  opacity: 0; pointer-events: none; transition: all .3s var(--ease);
  display: flex; align-items: center; gap: 8px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { color: var(--green); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .app.canvas-open { grid-template-columns: 280px 1fr; }
  .app.canvas-open .canvas-panel {
    position: fixed; inset: 0 0 0 auto; width: min(560px, 100%); z-index: 45;
    box-shadow: var(--shadow-lg);
  }
}
/* ===== موبایل: هدر و چتباکس فیکس ===== */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  
  .sidebar {
    position: fixed; inset: 0 0 0 auto; width: 280px; z-index: 110;
    transform: translateX(100%); transition: transform .3s var(--ease);
    box-shadow: -10px 0 40px rgba(0,0,0,0.5);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .sidebar__overlay { z-index: 105; }
  
  /* ===== هدر فیکس بالا (دو ردیفه تا در موبایل به هم نریزد) ===== */
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    min-height: 56px;
    height: auto;
    padding: 9px 12px 8px;
    background: rgba(10, 11, 22, 0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    row-gap: 6px;
    column-gap: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  }

  .sidebar-toggle { order: 1; flex-shrink: 0; }

  .topbar__title {
    order: 2;
    flex: 1 1 auto;
    min-width: 0;
    font-size: 13px;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ردیف دوم: مدل + هزینه، کنار هم و قابل اسکرول افقی در صورت ازدحام */
  .topbar__badges {
    order: 3;
    flex: 1 0 100%;
    justify-content: flex-end;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topbar__badges::-webkit-scrollbar { display: none; }

  .topbar__model-badge {
    font-size: 10px;
    padding: 4px 9px;
    margin-right: 0;
    flex-shrink: 0;
    white-space: nowrap;
  }
  .topbar__cost-badge {
    margin-right: 0;
    flex-shrink: 0;
    max-width: 60vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ===== اصلاح ارتفاع برای فیکس بودن ===== */
  .main {
    height: 100vh;
    height: 100dvh;
    padding-top: 80px;
    padding-bottom: 95px;
    overflow: hidden;
    position: relative;
  }

  /* ===== چتها اسکرول شوند ===== */
  .chat {
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 10px;
  }

  .messages { padding: 16px 12px; gap: 20px; }
  .msg { gap: 8px; }
  .msg__bubble { padding: 10px 12px; font-size: 13.5px; line-height: 1.8; }
  .msg__avatar { width: 28px; height: 28px; border-radius: 8px; font-size: 11px; }
  .msg__actions { opacity: 0.6; }

  /* تصاویر تولیدشده روی موبایل: تمام‌عرض حباب، بدون جمع‌شدن */
  .msg-images {
    width: 100%;
    max-width: 100%;
  }
  .msg-image-card {
    width: 100%;
    max-width: 100%;
  }
  .msg-image-card img {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 100px;
  }
  .msg-image-card__btn {
    min-height: 36px;
    padding: 8px 12px;
    font-size: 13px;
  }

  /* ===== چتباکس فیکس پایین ===== */
  .composer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(10, 11, 22, 0) 0%, rgba(10, 11, 22, 0.95) 20%, var(--bg) 40%);
    border-top: 1px solid var(--border);
  }

  .composer__box {
    max-width: 100%;
    border-radius: 16px;
    padding: 8px 10px 8px 8px;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.4);
  }

  .composer__hint { display: none; }

  /* ===== فایل چیپها بالای چتباکس ===== */
  .file-chips {
    position: fixed;
    bottom: 90px;
    left: 12px;
    right: 12px;
    z-index: 99;
    background: var(--bg);
    padding: 6px;
    border-radius: 10px;
    display: none;
  }
  .file-chips:not(:empty) { display: flex; gap: 8px; flex-wrap: wrap; }

  /* دکمهها بزرگتر */
  #promptInput { font-size: 15px; padding: 8px 4px; min-height: 24px; }
  .btn-send { width: 44px; height: 44px; border-radius: 14px; margin-left: 4px; }
  .btn-attach { width: 40px; height: 40px; }

  /* کد بلاکها */
  .code-block { margin: 8px 0; border-radius: 10px; }
  .code-block pre { padding: 10px; font-size: 12px; }

  /* ===== کانواس تمام‌صفحه روی موبایل (بالای topbar و composer) ===== */
  .canvas-panel {
    width: 100% !important;
    position: fixed !important;
    inset: 0 !important;
    right: 0 !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 120 !important; /* بالاتر از topbar (100) و composer (100) */
    border: none;
    box-shadow: none;
  }
  .canvas-panel__head {
    padding: 12px 12px calc(12px + env(safe-area-inset-top, 0px));
    padding-top: max(12px, env(safe-area-inset-top, 0px));
    gap: 8px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
  }
  .canvas-panel__title {
    font-size: 13px;
  }
  .canvas-panel__actions {
    gap: 8px;
  }
  /* دکمه‌های لمسی بزرگ‌تر تا حتماً دیده و قابل کلیک باشند */
  .canvas-panel__btn {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 13px;
    background: var(--bg-elevated);
    border-color: var(--border-strong);
    color: var(--text);
  }
  .canvas-panel__close {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: var(--bg-elevated);
    border-color: var(--border-strong);
    color: var(--text);
  }
  .canvas-panel__body {
    padding: 12px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  /* منوی مدل */
  .model-picker__panel {
    position: fixed;
    top: 84px;
    bottom: 100px;
    left: 10px;
    right: 10px;
    max-height: none;
    border-radius: 16px;
  }
}

/* برای موبایلهای خیلی کوچک */
@media (max-width: 380px) {
  .topbar__title { font-size: 12px; }
  .msg__bubble { font-size: 13px; }
  .topbar__badges { display: none; }
  .topbar { min-height: 48px; padding: 10px 12px; }
  .main { padding-top: 48px; }
  .model-picker__panel { top: 52px; }
  .btn-attach { width: 36px; height: 36px; }
  .btn-send { width: 40px; height: 40px; }
  .canvas-panel__btn {
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* امنیت برای iOS Safari */
@supports (-webkit-touch-callout: none) {
  .main { height: -webkit-fill-available; height: 100dvh; }
  .topbar { -webkit-backdrop-filter: blur(12px); }
  .composer { padding-bottom: 18px; }
  .chat { padding-bottom: 20px; }
}

.sidebar__overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40;
}
.sidebar__overlay.show { display: block; }
/* ---------- Cost badge ---------- */
.msg-cost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  padding: 3px 2px 0;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
  opacity: 0.9;
}
.msg--assistant .msg-cost { align-self: flex-start; }
.msg-cost.is-exact { color: var(--text-dim); opacity: 1; }
.msg-cost__sep { opacity: 0.45; }
.msg-cost__price { color: var(--gold); font-weight: 600; }
.msg-cost__pending { opacity: 0.6; }

/* ---------- نشان فریز‌شده‌ی مدت زمان فکر کردن ---------- */
.msg-thinking-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-faint);
  padding: 3px 2px 0;
  opacity: 0.85;
}
.msg--assistant .msg-thinking-badge { align-self: flex-start; }
.msg-thinking-badge svg { flex-shrink: 0; opacity: 0.8; }


/* ===== ساختار جدید سایدبار ===== */
.sidebar__top {
  flex-shrink: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
}

.sidebar__account-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.sidebar__total-cost {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,178,0,0.08);
  border: 1px solid rgba(255,178,0,0.22);
  color: var(--gold);
  font-size: 11.5px;
}
.sidebar__total-cost.hidden { display: none; }
.sidebar__total-cost svg { flex-shrink: 0; opacity: 0.9; }
.sidebar__total-cost-label { color: var(--text-faint); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__total-cost-value {
  font-family: var(--font-mono);
  font-weight: 700;
  direction: ltr;
  unicode-bidi: isolate;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

/* ---------- موجودی باقی‌مانده حساب ---------- */
.sidebar__balance {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(74, 222, 128, 0.07);
  border: 1px solid rgba(74, 222, 128, 0.22);
  color: var(--green);
  font-size: 11.5px;
}
.sidebar__balance.is-error {
  background: rgba(255, 107, 107, 0.08);
  border-color: rgba(255, 107, 107, 0.25);
  color: var(--red);
}
.sidebar__balance-row {
  display: flex;
  align-items: center;
  gap: 7px;
}
.sidebar__balance-row > svg { flex-shrink: 0; opacity: 0.9; }
.sidebar__balance-label {
  flex: 1;
  color: var(--text-faint);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar__balance-refresh {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  transition: all .15s var(--ease);
}
.sidebar__balance-refresh:hover {
  color: var(--green);
  border-color: rgba(74, 222, 128, 0.45);
  background: rgba(74, 222, 128, 0.1);
}
.sidebar__balance-refresh.is-loading {
  pointer-events: none;
  opacity: 0.6;
}
.sidebar__balance-refresh.is-loading svg {
  animation: spinRefresh .8s linear infinite;
}
@keyframes spinRefresh {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.sidebar__balance-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  direction: ltr;
  unicode-bidi: isolate;
  color: var(--green);
  padding-right: 20px;
}
.sidebar__balance.is-error .sidebar__balance-value { color: var(--red); }
.sidebar__balance-meta {
  font-size: 10.5px;
  color: var(--text-faint);
  padding-right: 20px;
  line-height: 1.4;
}
.sidebar__balance-meta:empty { display: none; }

.sidebar__bottom {
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

/* بهبود منوی مدل */
.model-picker__panel {
  max-height: min(55vh, 480px);
}

.model-group__head {
  padding: 11px 12px;
  font-size: 13px;
}

.model-option {
  padding: 10px 12px;
}

.model-option__name {
  font-weight: 500;
}