/* ===== توکن‌های طراحی ===== */
:root {
  --bg:            #eef1f8;
  --surface:       #ffffff;
  --surface-2:     #f6f8fc;
  --surface-3:     #eceff7;
  --border:        #dde3ee;
  --border-strong: #c7d0e0;
  --text:          #1b2330;
  --text-2:        #5a6577;
  --text-3:        #8b95a7;
  --accent:        #3b6ef6;
  --accent-soft:   #e5edff;
  --accent-text:   #1b46bd;
  --danger:        #d6455a;
  --ok:            #15905f;
  --shadow-sm:     0 1px 2px rgba(20,30,60,.06), 0 1px 3px rgba(20,30,60,.04);
  --shadow-md:     0 4px 16px rgba(20,30,60,.08);
  --shadow-lg:     0 18px 50px rgba(16,24,48,.18);
  --radius:        16px;
  --radius-sm:     10px;
  --font: "Vazirmatn", "Segoe UI", Tahoma, "Iranian Sans", sans-serif;

  --a-slate:#64748b;   --a-blue:#3b6ef6;    --a-emerald:#10a06a;
  --a-amber:#d99500;   --a-rose:#e0526b;    --a-violet:#8455e8;
  --a-cyan:#0aa5c4;    --a-teal:#0d9d92;    --a-orange:#e8763a;
  --a-indigo:#5b62e8;  --a-lime:#71a406;    --a-fuchsia:#c4479d;
}

[data-theme="dark"] {
  --bg:            #0f131c;
  --surface:       #171d29;
  --surface-2:     #1d2431;
  --surface-3:     #232b3a;
  --border:        #2a3344;
  --border-strong: #3a4558;
  --text:          #e8edf6;
  --text-2:        #a3aec2;
  --text-3:        #74809a;
  --accent:        #6b93ff;
  --accent-soft:   #1e2c4d;
  --accent-text:   #a8c2ff;
  --shadow-sm:     0 1px 2px rgba(0,0,0,.3);
  --shadow-md:     0 4px 16px rgba(0,0,0,.35);
  --shadow-lg:     0 18px 50px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }

/* خصیصهٔ hidden باید همیشه برنده باشد — قاعده‌هایی مثل .field{display:block}
   به‌طور پیش‌فرض بر استایل مرورگر غلبه می‌کنند و عنصر مخفی را نشان می‌دهند. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.75;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ===== نوار بالا ===== */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
}

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

.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 20px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.brand-text { min-width: 0; }

.notebook-title {
  border: 1px solid transparent;
  background: transparent;
  font-size: 17px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 8px;
  width: 100%;
  max-width: 320px;
}
.notebook-title:hover  { border-color: var(--border); }
.notebook-title:focus  { outline: none; border-color: var(--accent); background: var(--surface); }

.brand-sub { font-size: 12px; color: var(--text-3); padding-inline-start: 9px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.usage-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  box-shadow: var(--shadow-sm);
}
.usage-num   { font-weight: 600; }
.usage-label { color: var(--text-3); }
.usage-sep   { width: 1px; height: 14px; background: var(--border); }

.ghost-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  max-width: 180px;
  box-shadow: var(--shadow-sm);
}

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  transition: .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.subtle { border-color: transparent; background: transparent; box-shadow: none; }
.icon-btn.subtle:hover { background: var(--surface-3); }

/* ===== چیدمان اصلی ===== */
.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 400px;   /* در RTL: چت راست، استودیو چپ */
  gap: 14px;
  padding: 0 18px 16px;
  min-height: 0;
}
.workspace.collapsed { grid-template-columns: 1fr 0; }
.workspace.collapsed .studio-panel { display: none; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  box-shadow: var(--shadow-sm);
}

.panel-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; }
.panel-head-actions { display: flex; align-items: center; gap: 8px; }

.active-agent {
  display: flex; align-items: center; gap: 6px;
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 12.5px;
  font-weight: 500;
  max-width: 260px;
}
.active-agent .aa-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aa-clear {
  border: none; background: transparent; cursor: pointer;
  color: inherit; opacity: .6; font-size: 12px; padding: 0 2px;
}
.aa-clear:hover { opacity: 1; }

/* ===== چت ===== */
.chat-scroll { flex: 1 1 auto; overflow-y: auto; padding: 20px 22px; scroll-behavior: smooth; }

.empty-state { max-width: 560px; padding: 24px 4px; }
.empty-state .wave { font-size: 40px; line-height: 1; }
.empty-state h1 { font-size: 30px; margin: 14px 0 10px; font-weight: 600; }
.empty-state p  { color: var(--text-2); margin: 0 0 14px; }
.empty-model {
  display: inline-block; margin: 0 0 18px; padding: 5px 11px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--text-2);
  font-size: 12px; unicode-bidi: plaintext;
}
.empty-state[hidden] { display: none; }

.starter-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.starter-chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  font-size: 13px;
  transition: .15s;
}
.starter-chip:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }

.msg { display: flex; gap: 12px; margin-bottom: 22px; align-items: flex-start; }
.msg.user .msg-main { min-width: 0; flex: 1 1 auto; }

.msg-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--text-3); margin-bottom: 4px;
}
.msg-meta b { color: var(--text-2); font-weight: 600; }
.meta-tag {
  unicode-bidi: plaintext;
  background: var(--surface-3);
  border-radius: 6px; padding: 1px 7px;
  font-variant-numeric: tabular-nums;
}
.meta-tag.est { border: 1px dashed var(--border-strong); background: transparent; }

.msg.user .msg-body {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: 4px 14px 14px 14px;
  padding: 10px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-body { overflow-wrap: anywhere; }
.msg-body > *:first-child { margin-top: 0; }
.msg-body > *:last-child  { margin-bottom: 0; }
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 {
  margin: 18px 0 8px; font-weight: 600; line-height: 1.5;
}
.msg-body h1 { font-size: 20px; }
.msg-body h2 { font-size: 17px; }
.msg-body h3 { font-size: 15px; }
.msg-body h4 { font-size: 14px; color: var(--text-2); }
.msg-body p  { margin: 0 0 12px; }
.msg-body ul, .msg-body ol { margin: 0 0 12px; padding-inline-start: 22px; }
.msg-body li { margin-bottom: 5px; }
.msg-body blockquote {
  margin: 0 0 12px;
  border-inline-start: 3px solid var(--border-strong);
  padding-inline-start: 12px;
  color: var(--text-2);
}
.msg-body hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.msg-body a { color: var(--accent); }
.msg-body code {
  background: var(--surface-3);
  border-radius: 5px;
  padding: 1px 5px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: .9em;
  direction: ltr; display: inline-block;
}
.msg-body pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  margin: 0 0 12px;
}
.msg-body pre code { background: none; padding: 0; display: block; }

.table-scroll { overflow-x: auto; margin: 0 0 14px; }
.msg-body table { border-collapse: collapse; width: 100%; font-size: 13px; }
.msg-body th, .msg-body td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: start;
  vertical-align: top;
}
.msg-body th { background: var(--surface-2); font-weight: 600; }
.msg-body tbody tr:nth-child(even) { background: var(--surface-2); }

/* نامِ اشخاصِ اوراش، جای [[p:کد]]. کلاسِ جدا: «who» کلاسِ نشانِ کاربر در سرصفحه است */
.orash-name {
  background: var(--surface-2);
  border-radius: 5px;
  padding: 0 5px;
  white-space: nowrap;
}
.orash-name:not(.named) { color: var(--muted, inherit); }

.cite {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: 5px;
  padding: 0 6px;
  font-size: 11.5px;
  font-weight: 600;
  margin: 0 1px;
  cursor: help;
}

.used-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.used-source {
  unicode-bidi: plaintext;
  font-size: 11.5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  color: var(--text-2);
  background: var(--surface-2);
}

.msg-error {
  unicode-bidi: plaintext;
  border: 1px solid #f0b6bf;
  background: #fdf1f3;
  color: #9b2033;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  overflow-wrap: anywhere;
}
[data-theme="dark"] .msg-error { background: #2c1a1e; border-color: #5c2a33; color: #f2b3bd; }

.msg-notice {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-2);
  font-size: 13px;
  margin-bottom: 10px;
}

.cursor-dot {
  display: inline-block; width: 7px; height: 15px;
  background: var(--accent); border-radius: 2px;
  vertical-align: -2px; animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ===== کادر نوشتن ===== */
.composer { flex: 0 0 auto; padding: 0 18px 12px; }

.composer-extra {
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: none;
  background: var(--surface-2);
  padding: 10px 14px 12px;
}
.composer-extra label { display: block; font-size: 11.5px; color: var(--text-3); margin-bottom: 5px; }
.composer-extra textarea {
  width: 100%; resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 8px 10px;
}
.composer-extra textarea:focus { outline: none; border-color: var(--accent); }

.composer-box {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px 12px 8px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.composer-box textarea {
  width: 100%;
  border: none; background: transparent; resize: none;
  padding: 4px 4px 6px;
  max-height: 210px;
  line-height: 1.8;
}
.composer-box textarea:focus { outline: none; }

.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.composer-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }

.chip-btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  transition: .15s;
}
.chip-btn:hover  { background: var(--surface-3); color: var(--text); }
.chip-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.chip-btn.off    { opacity: .5; text-decoration: line-through; }


.send-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: none; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 17px; cursor: pointer;
  display: grid; place-items: center;
  transition: .15s;
}
.send-btn:hover:not(:disabled) { filter: brightness(1.08); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.send-btn.stopping { background: var(--danger); }

.composer-foot { text-align: center; font-size: 11.5px; color: var(--text-3); margin-top: 8px; }

/* ===== استودیو ===== */
.tabs {
  flex: 0 0 auto;
  display: flex; gap: 4px;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  border: none; background: transparent;
  padding: 7px 14px 9px;
  font-size: 13px; color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 600; }

.tab-body { flex: 1 1 auto; overflow-y: auto; padding: 14px; min-height: 0; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.agent-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.agent-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 12px 11px;
  cursor: pointer;
  background: var(--surface);
  transition: .15s;
  overflow: hidden;
}
.agent-card::before {
  content: ""; position: absolute; inset: 0;
  background: var(--card-accent); opacity: .07;
}
.agent-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.agent-card.selected { border-color: var(--card-accent); box-shadow: 0 0 0 2px var(--card-accent) inset; }
.agent-card.selected::before { opacity: .14; }

.ac-top { position: relative; display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.ac-emoji { font-size: 15px; }
.ac-name  { font-size: 13px; font-weight: 600; }
.ac-desc  {
  position: relative;
  font-size: 11.5px; color: var(--text-2); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.ac-edit {
  position: absolute; inset-inline-end: 6px; inset-block-start: 6px;
  border: none; background: var(--surface); border-radius: 7px;
  width: 24px; height: 24px; cursor: pointer;
  opacity: 0; font-size: 11px; color: var(--text-2);
  box-shadow: var(--shadow-sm);
  transition: .15s;
}
.agent-card:hover .ac-edit { opacity: 1; }
.ac-edit:hover { color: var(--text); }
.ac-badge {
  position: absolute; inset-inline-end: 8px; inset-block-end: 8px;
  font-size: 10px; color: var(--text-3);
}

.add-agent {
  width: 100%; margin-top: 10px;
  border: 1px dashed var(--border-strong);
  background: transparent;
  border-radius: 14px;
  padding: 11px;
  cursor: pointer;
  color: var(--text-2);
  font-size: 13px;
  transition: .15s;
}
.add-agent:hover { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 22px 16px;
  text-align: center;
  transition: .15s;
  background: var(--surface-2);
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon  { font-size: 24px; color: var(--text-3); }
.dz-title { font-size: 13.5px; font-weight: 600; margin-top: 4px; }
.dz-sub   { font-size: 11.5px; color: var(--text-3); margin: 4px 0 12px; }
.dz-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 18px;
  cursor: pointer;
  font-size: 13px;
}
.dz-btn:hover { border-color: var(--accent); color: var(--accent-text); }

.source-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.source-item {
  display: flex; align-items: flex-start; gap: 9px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 11px;
  background: var(--surface);
}
.source-item.disabled { opacity: .5; }
.source-item input[type=checkbox] { margin-top: 5px; accent-color: var(--accent); }
.si-kind {
  flex: 0 0 auto; margin-top: 1px;
  min-width: 38px; padding: 3px 5px; border-radius: 6px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .04em;
  text-align: center; text-transform: uppercase;
  direction: ltr; unicode-bidi: isolate;
  color: #fff; background: var(--kind-color, var(--a-slate));
}
.si-main { flex: 1 1 auto; min-width: 0; }
.si-name {
  unicode-bidi: plaintext;
  font-size: 12.5px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.si-meta { font-size: 11px; color: var(--text-3); }
.si-actions { display: flex; gap: 2px; }
.si-actions button {
  border: none; background: transparent; cursor: pointer;
  color: var(--text-3); font-size: 12px; padding: 3px 5px; border-radius: 6px;
}
.si-actions button:hover { background: var(--surface-3); color: var(--text); }

.source-empty, .list-empty {
  text-align: center; color: var(--text-3); font-size: 12.5px; padding: 18px 6px;
}

.usage-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.usage-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  background: var(--surface-2);
}
.uc-value { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.uc-label { font-size: 11.5px; color: var(--text-3); }

.mini-head { font-size: 12.5px; color: var(--text-2); margin: 18px 0 7px; font-weight: 600; }
.mini-table { display: flex; flex-direction: column; gap: 5px; }
.mini-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 12px;
}
.mini-row .mr-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row .mr-val  { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

.fine-print { font-size: 11px; color: var(--text-3); margin-top: 16px; line-height: 1.7; }

/* ===== مودال ===== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,20,35,.5);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: 18px;
  width: min(560px, 100%);
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal.wide { width: min(780px, 100%); }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px; border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.spacer { flex: 1 1 auto; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }
.field > span small { color: var(--text-3); font-weight: 400; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  background: var(--surface);
}
.field textarea { resize: vertical; line-height: 1.8; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field.narrow { width: 90px; flex: 0 0 auto; }
.field.checkbox { display: flex; align-items: center; gap: 8px; margin-top: 22px; }
.field.checkbox input { width: auto; accent-color: var(--accent); }
/* تیک هیچ‌وقت عرض کامل فیلد را نمی‌گیرد، وگرنه متن کنارش صفر می‌شود */
.field input[type=checkbox] {
  width: auto; flex: 0 0 auto; padding: 0; border: none; background: none;
  accent-color: var(--accent);
}
.field.checkbox span { margin: 0; font-size: 12.5px; }

.row-2 { display: flex; gap: 12px; align-items: flex-start; }
.row-2 > * { flex: 1 1 0; }
.row-3 { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.row-3 > * { flex: 1 1 160px; }

.section-head { font-size: 13px; margin: 20px 0 8px; font-weight: 600; }
.section-head:first-child { margin-top: 0; }
.section-head small { color: var(--text-3); font-weight: 400; }
.hint { font-size: 11.5px; color: var(--text-3); margin: 0 0 12px; line-height: 1.8; }
.hint code { background: var(--surface-3); border-radius: 4px; padding: 1px 5px; direction: ltr; display: inline-block; }

.key-row { margin-bottom: 12px; }
.key-row .key-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 5px;
}
.key-label { font-size: 12.5px; font-weight: 500; }
.key-state { font-size: 11px; }
.key-state.on  { color: var(--ok); }
.key-state.off { color: var(--text-3); }
.key-input-row { display: flex; gap: 6px; }
.key-input-row input {
  flex: 1 1 auto; direction: ltr; text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  background: var(--surface);
  font-family: Consolas, monospace; font-size: 12.5px;
}
.key-input-row input:focus { outline: none; border-color: var(--accent); }

.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  cursor: pointer;
  font-size: 13px;
  transition: .15s;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: var(--border); background: transparent; }
.btn.danger { color: var(--danger); border-color: transparent; }
.btn.danger:hover { background: rgba(214,69,90,.1); }
.btn.small { padding: 6px 14px; font-size: 12.5px; }

.source-preview {
  white-space: pre-wrap;
  font-family: var(--font);
  font-size: 12.5px;
  line-height: 1.9;
  color: var(--text-2);
  max-height: 60vh;
  overflow-y: auto;
  margin: 0;
}

/* ===== توست ===== */
.toast-stack {
  position: fixed;
  inset-block-end: 20px; inset-inline-start: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 80;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  max-width: 380px;
  animation: slide-in .2s ease-out;
}
.toast.error { border-inline-start-color: var(--danger); }
.toast.ok    { border-inline-start-color: var(--ok); }
@keyframes slide-in { from { opacity: 0; transform: translateY(6px); } }

/* ===== اسکرول‌بار ===== */
/* نوار اسکرول هیچ‌جا دیده نمی‌شود؛ اسکرول کار می‌کند، فقط میله‌اش نیست.
   سه موتور سه قاعدهٔ جدا می‌خواهند و هیچ‌کدام جای دیگری را نمی‌گیرد. */
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { width: 0; height: 0; }

/* ===== واکنش‌گرا ===== */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr 340px; }
  .agent-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .studio-panel { max-height: 42vh; }
  .agent-grid { grid-template-columns: repeat(2, 1fr); }
  .chip-label { display: none; }
  .usage-pill { display: none; }
}

/* راهنمای نقش قفل‌شده در مودال ارتقا */
.locked-hint {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12.5px;
  line-height: 1.8;
  margin-bottom: 16px;
}
.locked-hint[hidden] { display: none; }

a.icon-btn { text-decoration: none; }

/* ===== انتخابگر مدل با جست‌وجو ===== */
.model-picker { position: relative; }

.model-trigger {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  max-width: 250px;
  transition: .15s;
}
.model-trigger:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.model-trigger:disabled { opacity: .5; cursor: not-allowed; }
.model-trigger .mt-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  unicode-bidi: plaintext;
}
.model-trigger .mt-caret { color: var(--text-3); font-size: 11px; }

.model-pop {
  position: absolute;
  inset-block-end: calc(100% + 8px);
  inset-inline-start: 0;
  width: min(380px, 78vw);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 40;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.model-pop[hidden] { display: none; }

.mp-search { padding: 9px; border-bottom: 1px solid var(--border); }
.mp-search input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 12.5px;
}
.mp-search input:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.mp-list { max-height: 300px; overflow-y: auto; padding: 5px; }

.mp-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  border: none; background: transparent;
  border-radius: 9px;
  padding: 7px 10px;
  cursor: pointer;
  text-align: start;
}
.mp-item:hover { background: var(--surface-2); }
.mp-item.current { background: var(--accent-soft); }
.mp-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.mp-label {
  font-size: 12.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  unicode-bidi: plaintext;
}
.mp-item.current .mp-label { color: var(--accent-text); font-weight: 600; }
.mp-meta { font-size: 10.5px; color: var(--text-3); unicode-bidi: plaintext; }
.mp-price {
  font-size: 10.5px; color: var(--text-3);
  white-space: nowrap; direction: ltr;
  font-variant-numeric: tabular-nums;
}
.mp-empty { padding: 22px 10px; text-align: center; color: var(--text-3); font-size: 12.5px; }
.mp-foot {
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-3);
  background: var(--surface-2);
}

/* ===== استودیوی خروجی ===== */
.pane-lead {
  font-size: 12px; color: var(--text-2); line-height: 1.85;
  margin: 0 0 14px;
}

.report-templates {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px;
}
.report-card {
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 13px;
  padding: 11px 12px 10px;
  cursor: pointer;
  text-align: start;
  font: inherit;
  color: inherit;
  transition: .15s;
}
.report-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}
.rt-top { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.rt-emoji { font-size: 15px; }
.rt-name { font-size: 12.5px; font-weight: 600; }
.rt-desc {
  font-size: 11px; color: var(--text-2); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.rt-formats { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 7px; }
.rt-fmt {
  font-size: 9.5px; color: var(--text-3);
  border: 1px solid var(--border); border-radius: 999px; padding: 0 6px;
  unicode-bidi: plaintext;
}
.rt-badge {
  position: absolute; inset-inline-end: 8px; inset-block-start: 8px;
  font-size: 9px; color: var(--text-3);
}

.report-list { display: flex; flex-direction: column; gap: 7px; }
.report-item {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 9px 11px;
  background: var(--surface);
}
.ri-main { flex: 1 1 auto; min-width: 0; }
.ri-head { display: flex; align-items: center; gap: 6px; }
.ri-emoji { font-size: 13px; }
.ri-title {
  font-size: 12.5px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ri-meta { font-size: 10.5px; color: var(--text-3); unicode-bidi: plaintext; }
.ri-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.ri-btn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 4px 10px; font-size: 11.5px;
  cursor: pointer; color: var(--text-2);
}
.ri-btn:hover { background: var(--surface-3); color: var(--text); }
.ri-btn.danger { border-color: transparent; }
.ri-btn.danger:hover { background: rgba(214,69,90,.12); color: var(--danger); }

/* مودال ساخت */
.report-hero {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface-2);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 16px;
}
.rh-emoji { font-size: 24px; }
.rh-name { font-size: 14px; font-weight: 600; }
.rh-desc { font-size: 11.5px; color: var(--text-2); }

.report-note {
  font-size: 11.5px; color: var(--text-3);
  background: var(--surface-2); border-radius: 9px; padding: 8px 12px;
}
.report-note.warn {
  background: rgba(214,69,90,.09); color: var(--danger);
}

/* پیش‌نمایش خروجی */
.download-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding-bottom: 14px; margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.dl-label { font-size: 12px; color: var(--text-3); }
.dl-btn {
  border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: 999px; padding: 5px 14px; font-size: 12.5px;
  cursor: pointer; unicode-bidi: plaintext;
}
.dl-btn:hover { border-color: var(--accent); color: var(--accent-text);
                background: var(--accent-soft); }

.preview-body { max-height: 58vh; overflow-y: auto; }
.pv-sub { color: var(--text-2); font-size: 13px; margin: 0 0 14px; }
.pv-head { font-size: 14px; margin: 18px 0 7px; color: var(--accent-text); }
.pv-p { margin: 0 0 10px; font-size: 13px; line-height: 1.9; }
.pv-ul, .pv-ol { margin: 0 0 12px; padding-inline-start: 22px; font-size: 13px; }
.pv-ul li, .pv-ol li { margin-bottom: 4px; }
.pv-ol li.correct { color: var(--ok); font-weight: 600; }
.pv-note { font-size: 11.5px; color: var(--text-3); margin: 0 0 10px; }
.pv-table { overflow-x: auto; margin: 0 0 14px; }
.pv-table table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.pv-table th, .pv-table td {
  border: 1px solid var(--border); padding: 6px 9px;
  text-align: start; vertical-align: top;
}
.pv-table th { background: var(--surface-2); font-weight: 600; }
.pv-table tbody tr:nth-child(even) { background: var(--surface-2); }
.pv-loading { color: var(--text-3); font-size: 12.5px; padding: 30px; text-align: center; }
.svg-holder { overflow: auto; text-align: center; }
.svg-holder svg { max-width: 100%; height: auto; }

@media (max-width: 1100px) {
  .report-templates { grid-template-columns: 1fr; }
}

/* ===== تحلیل چندمرحله‌ای ===== */
.panel-picker {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px; max-height: 150px; overflow-y: auto;
}
.panel-item {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 8px; border-radius: 8px; cursor: pointer; font-size: 12.5px;
}
.panel-item:hover { background: var(--surface-2); }
.panel-item input { accent-color: var(--accent); }

.step-track {
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
}
.track-wait { font-size: 12.5px; color: var(--text-3); }

.track-step {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 11px; border-radius: 9px;
  background: var(--surface-2); font-size: 12.5px;
}
.ts-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto;
  background: var(--border-strong);
}
.ts-title { flex: 1 1 auto; color: var(--text-2); }
.ts-meta { font-size: 11px; color: var(--text-3); unicode-bidi: plaintext; }

.track-step.active { background: var(--accent-soft); }
.track-step.active .ts-dot { background: var(--accent); animation: pulse 1s infinite; }
.track-step.active .ts-title { color: var(--accent-text); font-weight: 600; }
.track-step.done .ts-dot { background: var(--ok); }
.track-step.done .ts-title { color: var(--text); }
.track-step.failed .ts-dot { background: var(--danger); }
.track-step.failed .ts-title { color: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

.track-ok {
  font-size: 12.5px; color: var(--ok); font-weight: 600;
  padding: 8px 11px; background: rgba(21,144,95,.1); border-radius: 9px;
}
.track-error {
  font-size: 12.5px; color: var(--danger);
  padding: 8px 11px; background: rgba(214,69,90,.1); border-radius: 9px;
  overflow-wrap: anywhere;
}

.mini-head small { color: var(--text-3); font-weight: 400; }

.track-step.skipped { opacity: .65; }
.track-step.skipped .ts-dot { background: var(--text-3); }
.track-warn {
  font-size: 11.5px; color: var(--text-2);
  padding: 7px 11px; background: var(--surface-3); border-radius: 9px;
  overflow-wrap: anywhere;
}

/* ===== گزینه‌های قالب و انتخاب منبع ===== */
.opt-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  margin-bottom: 14px;
}
.opt-field > span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }

.seg {
  display: flex; border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg button {
  flex: 1 1 0; border: none; background: var(--surface);
  padding: 7px 6px; font-size: 12px; cursor: pointer; color: var(--text-2);
  border-inline-start: 1px solid var(--border);
}
.seg button:first-child { border-inline-start: none; }
.seg button:hover { background: var(--surface-3); }
.seg button.on {
  background: var(--accent-soft); color: var(--accent-text); font-weight: 600;
}

.opt-number {
  display: flex; align-items: center; gap: 8px;
}
.opt-number input[type=range] { flex: 1 1 auto; accent-color: var(--accent); }
.opt-number output {
  min-width: 34px; text-align: center; font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); border-radius: 7px; padding: 3px 6px;
}

.source-picker {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px; max-height: 168px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.source-picker .sp-item {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 8px; border-radius: 7px; cursor: pointer; font-size: 12px;
}
.source-picker .sp-item:hover { background: var(--surface-2); }
.source-picker input { accent-color: var(--accent); flex: 0 0 auto; }
.source-picker .sp-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  unicode-bidi: plaintext;
}
.sp-all {
  border: none; background: transparent; color: var(--accent-text);
  font-size: 11.5px; cursor: pointer; padding: 4px 8px; align-self: flex-start;
}
.sp-all:hover { text-decoration: underline; }

@media (max-width: 700px) { .opt-grid { grid-template-columns: 1fr; } }

/* کادر خطا با امکان تلاش دوباره */
.msg-error .me-text { margin-bottom: 0; }
.msg-error .me-retry {
  display: inline-block;
  margin-top: 9px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 12px;
  cursor: pointer;
  opacity: .85;
}
.msg-error .me-retry:hover { opacity: 1; background: rgba(214,69,90,.12); }

/* ===== نوار ابزارهای بیرونی در پاسخ ===== */
.tool-strip {
  display: flex; flex-direction: column; gap: 5px;
  margin-bottom: 12px;
}
.tool-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 11px;
  font-size: 11.5px;
}
.tr-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
  background: var(--border-strong);
}
.tr-name { color: var(--text-2); font-weight: 600; flex: 0 0 auto; }
.tr-arg {
  color: var(--text-3); flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  unicode-bidi: plaintext;
}
.tr-note { color: var(--text-3); flex: 0 0 auto; unicode-bidi: plaintext; }
.tr-link { text-decoration: none; color: var(--accent); flex: 0 0 auto; }

.tool-row.running .tr-dot { background: var(--accent); animation: pulse 1s infinite; }
.tool-row.ok .tr-dot { background: var(--ok); }
.tool-row.bad { border-color: #f0b6bf; background: rgba(214,69,90,.07); }
.tool-row.bad .tr-dot { background: var(--danger); }
.tool-row.bad .tr-note { color: var(--danger); }

/* ===== صفحهٔ خانه ===== */
.home {
  flex: 1 1 auto;
  min-height: 0;                       /* تا فرزندان بتوانند کوچک شوند */
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 4px 26px 18px;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;                    /* تاریخچه که بلند شد، کل صفحه می‌رود */
  overflow-x: hidden;
  padding-bottom: 40px;
}

.home-block.roles   { flex: 0 0 auto; min-width: 0; }
.home-block.history { flex: 0 0 auto; }

.home-head { margin-bottom: 12px; }
.home-head.compact {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.home-head h2 { font-size: 19px; margin: 0 0 4px; font-weight: 600; }
.home-head p { font-size: 12.5px; color: var(--text-2); margin: 0; }
.home-head .search.grow { max-width: 300px; min-width: 180px; }

.home-title { font-size: 17px; font-weight: 600; padding: 2px 9px; }
button.brand-mark { border: none; cursor: pointer; font-size: 20px; }
button.brand-mark:hover { background: var(--surface-3); }

/* --- ریل افقی نقش‌ها --- */
.rail-nav { display: flex; gap: 6px; }
.rail-btn {
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-2);
  font-size: 17px; line-height: 1;
  display: grid; place-items: center;
  transition: .15s;
}
.rail-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.rail-btn:disabled { opacity: .3; cursor: default; }

.role-rail {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 228px;
  grid-template-rows: repeat(2, 1fr);   /* دو ردیف روی مانیتور بلند */
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  /* جا برای بالاآمدنِ کارت زیر نشانگر. overflow-y مخفی است، پس بدون این
     فاصله لبهٔ بالاییِ کارت بریده می‌شود و قاب ناقص دیده می‌شود. */
  padding-block: 5px 8px;
}
.role-rail > * { scroll-snap-align: start; }

/* لبهٔ بریده محو می‌شود تا کارتِ نیمه، نصفه‌بریده به نظر نرسد.
   دو سمت مستقل‌اند و هرکدام فقط وقتی روشن می‌شوند که همان طرف
   واقعاً محتوای پنهان داشته باشد — کلاسش را syncRailButtons می‌گذارد. */
@property --fade-l { syntax: '<length>'; inherits: false; initial-value: 0px; }
@property --fade-r { syntax: '<length>'; inherits: false; initial-value: 0px; }

.role-rail {
  --fade-l: 0px;
  --fade-r: 0px;
  transition: --fade-l .2s ease, --fade-r .2s ease;
  -webkit-mask-image: linear-gradient(to right,
    transparent 0, #000 var(--fade-l),
    #000 calc(100% - var(--fade-r)), transparent 100%);
  mask-image: linear-gradient(to right,
    transparent 0, #000 var(--fade-l),
    #000 calc(100% - var(--fade-r)), transparent 100%);
}
.role-rail.fade-left  { --fade-l: 56px; }
.role-rail.fade-right { --fade-r: 56px; }

@media (max-height: 620px) {
  .role-rail { grid-auto-columns: 200px; }
}

.role-card {
  position: relative;
  text-align: start;
  font: inherit;
  color: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 16px;
  padding: 13px 14px 12px;
  cursor: pointer;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.role-card::before {
  content: ""; position: absolute; inset: 0;
  background: var(--card-accent, var(--a-slate));
  opacity: .07;
}
.role-card > * { position: relative; }
.role-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--card-accent, var(--accent));
}
.role-card.blank::before { opacity: 0; }
.role-card.blank { border-style: dashed; }

.rc-emoji { font-size: 19px; line-height: 1; margin-bottom: 7px; }
.rc-name { font-size: 13.5px; font-weight: 600; margin-bottom: 3px; }
.rc-desc {
  font-size: 11.5px; color: var(--text-2); line-height: 1.65;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.rc-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 7px; }
.rc-chip {
  font-size: 10px; border-radius: 999px; padding: 1px 8px;
  background: var(--surface-3); color: var(--text-3);
}
.rc-chip.mine { background: rgba(21,144,95,.14); color: var(--ok); }

/* --- تاریخچه --- */
.chat-scroller { padding-inline-end: 2px; }

.day-head {
  display: flex; align-items: center; gap: 8px;
  margin: 14px 0 9px;
}
.day-head:first-child { margin-top: 0; }
.dh-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.dh-count {
  font-size: 10.5px; color: var(--text-3);
  background: var(--surface-3); border-radius: 999px; padding: 0 8px;
}
.dh-rule { flex: 1 1 auto; height: 1px; background: var(--border); }

.chat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 11px;
}

/* همان زبان بصری کارت نقش: قاب، شعاع، و لکهٔ رنگیِ کم‌رمق پشت متن */
.chat-card {
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 16px;
  padding: 13px 14px 12px;
  cursor: pointer;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.chat-card::before {
  content: ""; position: absolute; inset: 0;
  background: var(--card-accent, var(--a-slate));
  opacity: .07;
}
.chat-card > * { position: relative; }
.chat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--card-accent, var(--accent));
}

.cc-head { display: flex; align-items: flex-start; gap: 10px; }
.cc-emoji {
  width: 30px; height: 30px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 10px; font-size: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.cc-titles { flex: 1 1 auto; min-width: 0; }
.cc-title {
  font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cc-sub { font-size: 10.5px; color: var(--text-3); unicode-bidi: plaintext; }

.cc-menu {
  flex: 0 0 auto;
  border: none; background: transparent; cursor: pointer;
  color: var(--text-3); font-size: 16px; line-height: 1;
  padding: 2px 6px; border-radius: 7px;
}
.cc-menu:hover { background: var(--surface-3); color: var(--text); }

.cc-preview {
  font-size: 11.5px; color: var(--text-2); line-height: 1.65;
  margin-top: 9px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.cc-preview.dim { color: var(--text-3); font-style: italic; }

.cc-stats { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.cc-stat {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; color: var(--text-3);
  background: var(--surface-3);
  border-radius: 999px; padding: 1px 8px;
  unicode-bidi: plaintext;
}
.cc-stat.dim { color: var(--text-3); }
.cs-ico { font-size: 10px; }

.grid-empty {
  text-align: center; color: var(--text-3); font-size: 13px;
  padding: 40px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
}

/* --- منوی کارت --- */
.card-menu {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 5px;
  min-width: 150px;
  z-index: 60;
}
.cm-item {
  display: block; width: 100%;
  border: none; background: transparent;
  text-align: start; font: inherit;
  padding: 8px 12px; border-radius: 8px;
  cursor: pointer; font-size: 12.5px; color: var(--text);
}
.cm-item:hover { background: var(--surface-2); }
.cm-item.danger { color: var(--danger); }
.cm-item.danger:hover { background: rgba(214,69,90,.1); }

@media (max-width: 700px) {
  .home { padding: 4px 14px 14px; }
  .chat-grid { grid-template-columns: 1fr; }
}

/* دکمهٔ برگشت به تاریخچه — چپ‌ترین چیز نوار بالا */
.back-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font: inherit; font-size: 12.5px; font-weight: 500;
  color: var(--text-2); cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 13px 6px 11px;
  transition: .15s;
}
.back-btn:hover {
  background: var(--accent-soft); border-color: var(--accent);
  color: var(--accent-text);
}
.bb-arrow { font-size: 14px; line-height: 1; transition: transform .15s; }
.back-btn:hover .bb-arrow { transform: translateX(-3px); }

/* سندی که استخراجش مشکوک است */
.source-item.flagged { border-color: var(--a-amber); }
.si-warn {
  margin-top: 5px; padding: 5px 7px; border-radius: 7px;
  background: color-mix(in srgb, var(--a-amber) 12%, transparent);
  color: var(--text-2); font-size: 11px; line-height: 1.7;
  white-space: normal;
}

/* ===== دروازهٔ ورود ===== */
.login-gate {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: var(--bg);
  padding: 20px;
}
.login-gate[hidden] { display: none !important; }
.login-card {
  width: min(420px, 100%); text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 40px 32px; box-shadow: var(--shadow-md);
}
.login-mark { font-size: 44px; line-height: 1; }
.login-card h1 { font-size: 22px; font-weight: 600; margin: 14px 0 8px; }
.login-card p { color: var(--text-2); font-size: 13px; margin: 0 0 24px; line-height: 1.9; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 11px 18px; border-radius: 12px; text-decoration: none;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 13.5px; font-weight: 500;
  transition: .15s;
}
.google-btn:hover { background: var(--surface-2); box-shadow: var(--shadow-sm); }
.g-logo {
  width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: #fff; color: #4285f4; border: 1px solid var(--border);
}
.login-note {
  margin: 18px 0 0 !important; font-size: 12px; padding: 10px 12px;
  border-radius: 10px; background: var(--surface-2); line-height: 1.9;
}
.login-note.warn { background: color-mix(in srgb, var(--a-amber) 14%, transparent); }
.login-note.bad { background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* ===== کیستی کاربر در نوار بالا ===== */
.who { display: flex; align-items: center; gap: 8px; }
.who[hidden] { display: none !important; }
.who-face {
  width: 26px; height: 26px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--border); background: var(--surface-3);
}
.who-text { display: flex; flex-direction: column; line-height: 1.3; }
.who-name { font-size: 12px; font-weight: 500; }
.who-space { font-size: 10.5px; color: var(--text-3); }

/* ===== مهمان ===== */
.btn.tiny { padding: 4px 10px; font-size: 11.5px; border-radius: 8px; }
.login-close {
  display: block; margin: 14px auto 0; border: 0; background: none;
  color: var(--text-3); font: inherit; font-size: 12px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.login-close:hover { color: var(--text); }
.login-close[hidden] { display: none !important; }
.who-space.low { color: var(--a-amber); font-weight: 600; }

/* ===== جانِ صفحه ===== */
/* مشکل «بی‌روحی» سه چیز بود: پس‌زمینهٔ تخت، رنگِ کارت‌ها که ۷٪ بود و عملاً
   دیده نمی‌شد، و عنوان‌هایی هم‌وزنِ متن. هر سه اینجا درست می‌شوند. */

body {
  background-color: var(--bg);
  background-image:
    radial-gradient(58rem 30rem at 88% -6%,
      color-mix(in srgb, var(--a-violet) 14%, transparent), transparent 68%),
    radial-gradient(50rem 28rem at 4% 2%,
      color-mix(in srgb, var(--accent) 13%, transparent), transparent 65%);
  background-attachment: fixed;
}

/* --- کیستی کاربر نباید از لبهٔ صفحه بیرون بزند --- */
.topbar-actions { min-width: 0; flex-wrap: wrap; justify-content: flex-end; }
.who { min-width: 0; }
.who-text { min-width: 0; }
.who-name, .who-space {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 148px;
}

/* --- عنوان بخش: یک میلهٔ رنگی که چشم را لنگر می‌اندازد --- */
.home-head h2 {
  font-size: 22px;
  letter-spacing: -.015em;
  position: relative;
  padding-inline-start: 15px;
  margin-bottom: 6px;
}
.home-head h2::before {
  content: "";
  position: absolute; inset-inline-start: 0; top: .3em; bottom: .3em;
  width: 4px; border-radius: 999px;
  background: linear-gradient(var(--accent), var(--a-violet));
}
.home-head p { font-size: 13px; padding-inline-start: 15px; }
.home-head .search.grow { max-width: 320px; }

/* --- کارت نقش --- */
.role-card {
  padding: 15px 16px 14px;
  border-radius: 18px;
  transition: transform .18s cubic-bezier(.2,.7,.3,1), box-shadow .18s,
              border-color .18s;
}
.role-card::before {
  opacity: 1;
  background: linear-gradient(158deg,
    color-mix(in srgb, var(--card-accent, var(--a-slate)) 20%, transparent) 0%,
    color-mix(in srgb, var(--card-accent, var(--a-slate)) 4%, transparent) 46%,
    transparent 72%);
}
.rc-emoji {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 11px;
  font-size: 18px;
  margin-bottom: 10px;
  background: color-mix(in srgb, var(--card-accent, var(--a-slate)) 15%, var(--surface));
  box-shadow: inset 0 0 0 1px
    color-mix(in srgb, var(--card-accent, var(--a-slate)) 26%, transparent);
}
.rc-name { font-size: 14px; margin-bottom: 4px; }
.rc-desc { font-size: 12px; }
.role-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--card-accent, var(--accent)) 55%, transparent);
  box-shadow: 0 10px 26px
    color-mix(in srgb, var(--card-accent, var(--accent)) 20%, transparent);
}
.role-card.blank:hover { box-shadow: var(--shadow-md); }

/* --- کارت گفت‌وگو: لبهٔ رنگی به‌جای لکهٔ محو --- */
.chat-card { border-radius: 18px; padding: 14px 15px 13px; }
.chat-card::before {
  opacity: 1;
  background: linear-gradient(158deg,
    color-mix(in srgb, var(--card-accent, var(--a-slate)) 13%, transparent) 0%,
    transparent 58%);
}
.chat-card::after {
  content: "";
  position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 3px;
  background: var(--card-accent, var(--a-slate));
  opacity: .6;
}
.chat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 26px
    color-mix(in srgb, var(--card-accent, var(--accent)) 18%, transparent);
}
.cc-emoji {
  background: color-mix(in srgb, var(--card-accent, var(--a-slate)) 13%, var(--surface));
  border-color: color-mix(in srgb, var(--card-accent, var(--a-slate)) 24%, transparent);
}
.cc-title { font-size: 13.5px; }

/* --- سرِ روز --- */
.dh-label { font-size: 13px; color: var(--text); }
.dh-rule {
  background: linear-gradient(to left, var(--border), transparent);
}

/* --- جای خالی، کمتر شبیه خطا --- */
.grid-empty {
  padding: 52px 20px;
  border-radius: 18px;
  border-color: var(--border);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}

/* --- ورود نرمِ صفحه: یک بار، نه با هر تایپ --- */
@keyframes homeRise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.home:not([hidden]) { animation: homeRise .34s cubic-bezier(.2,.7,.3,1) both; }

@media (prefers-reduced-motion: reduce) {
  .home:not([hidden]) { animation: none; }
  .role-card, .chat-card { transition: none; }
}

/* ===== کادر جست‌وجو ===== */
/* همان زبانِ نوار مصرف و کشوی مدل: قاب گرد، سطح روشن، سایهٔ نازک. */
.search {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding-block: 8px;
  padding-inline: 36px 14px;
  font-size: 12.5px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, background .15s;

  /* ذره‌بین به‌صورت تصویر پس‌زمینه، چون input فرزند نمی‌پذیرد و
     نمی‌خواستیم فقط برای یک آیکون دورش span بپیچیم. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b95a7' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 15px;
  background-position: right 12px center;
}
.search::placeholder { color: var(--text-3); }
.search:hover { border-color: var(--border-strong); }
.search:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

/* در چیدمان چپ‌به‌راست ذره‌بین باید آن طرف بنشیند */
:dir(ltr) .search {
  padding-inline: 14px 36px;
  background-position: left 12px center;
}

/* ===== ضبط صدا ===== */
/* حالت ضبط باید از دورتر هم دیده شود: کاربر در حال حرف‌زدن به صفحه نگاه
   نمی‌کند و باید با گوشهٔ چشم بفهمد هنوز روشن است. */
#micBtn.recording {
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  border-color: var(--danger);
  color: var(--danger);
}
#micBtn.recording #micIcon { animation: micPulse 1.1s ease-in-out infinite; }
#micBtn.busy { opacity: .65; pointer-events: none; }

@keyframes micPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .45; transform: scale(.88); }
}

@media (prefers-reduced-motion: reduce) {
  #micBtn.recording #micIcon { animation: none; }
}

/* کارتِ «دادهٔ اوراش» در منابع: سند آپلودی نیست، پس جعبهٔ تیک و حذف ندارد */
.source-item.orash-source { border-inline-start: 3px solid var(--a-emerald); }
.si-note { font-size: 10.5px; color: var(--text-3); margin-top: 2px; }

/* ورود با نام کاربری و رمز */
.password-login { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; text-align: start; }
.password-login[hidden] { display: none; }
.password-login input {
  font: inherit; font-size: 13px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
.login-or { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 11.5px; }
.login-or::before, .login-or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.login-or[hidden] { display: none; }
.login-card .login-error { color: var(--danger); font-size: 12px; margin: 0; line-height: 1.7; }
.login-card .login-error[hidden] { display: none; }
