@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #eef1f0;
  --card: #ffffff;
  --line: #dbe2df;
  --ink: #17262b;
  --muted: #7b8a88;
  --accent: #0f6b5c;
  --accent-d: #0a5448;
  --accent-soft: #e1f0ec;
  --danger: #b83227;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ───────── صفحه‌ی ورود ───────── */
.page-auth { display: block; }
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--card);
  border: 1px solid var(--line); border-radius: 18px; padding: 28px 26px 24px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.logo { width: 34px; height: 34px; flex-shrink: 0; }
.logo rect { fill: var(--accent); }
.logo path { fill: #fff; }
.brand-name { font-weight: 700; font-size: 16px; }
.auth h1, .auth h2 { font-size: 20px; margin: 0 0 6px; font-weight: 700; }
.hint { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; }
.auth label { display: block; font-size: 13px; margin-bottom: 6px; color: #3d4e50; }
.auth input {
  width: 100%; height: 48px; padding: 0 14px; font: inherit; font-size: 16px;
  border: 1px solid #c5cfcc; border-radius: 10px; background: #fff; color: var(--ink);
}
.auth input[dir="ltr"] { text-align: left; }
.auth input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.code-input { letter-spacing: .5em; text-align: center !important; font-size: 22px !important; font-weight: 600; }
.primary {
  display: block; width: 100%; margin-top: 14px; height: 48px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}
.primary:hover { background: var(--accent-d); }
.primary:disabled { opacity: .55; cursor: default; }
.as-link { text-align: center; line-height: 48px; text-decoration: none; }
.links { display: flex; justify-content: space-between; margin-top: 14px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-size: 13px; }
.link:disabled { color: var(--muted); cursor: default; }
.err { min-height: 22px; margin-top: 12px; color: var(--danger); font-size: 13px; text-align: center; }

/* ───────── صفحه‌ی چت ───────── */
.page-chat { display: flex; overflow: hidden; }

#side {
  width: 280px; background: var(--card); border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; flex-shrink: 0;
}
#newchat {
  margin: 12px; padding: 10px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
}
#newchat:hover { background: var(--accent-d); }
#chats { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
a.chat { display: block; padding: 9px 10px; border-radius: 10px; text-decoration: none; color: inherit; margin-bottom: 2px; }
a.chat:hover { background: #f0f4f2; }
a.chat.active { background: var(--accent-soft); }
.ct { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cm { font-size: 11px; color: var(--muted); margin-top: 2px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 0; }
.userbox {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px;
}
.uname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

#scrim { display: none; }
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
#menu { display: none; border: 0; background: none; font-size: 22px; cursor: pointer; padding: 0 4px; color: var(--ink); }
#title { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#msgs { flex: 1; overflow-y: auto; padding: 20px 16px; }
.inner { max-width: 820px; margin: 0 auto; }

.row { display: flex; margin-bottom: 4px; }
.row.user { justify-content: flex-start; }
.row.bot  { justify-content: flex-end; margin-bottom: 18px; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 14px; line-height: 1.85; font-size: 14.5px; word-break: break-word; }
.user .bubble { background: var(--accent); color: #fff; white-space: pre-wrap; border-start-start-radius: 4px; }
.bot .bubble { background: var(--card); border: 1px solid var(--line); border-end-end-radius: 4px; min-width: 120px; }
.meta { font-size: 11px; color: var(--muted); margin: 6px 2px 0; display: flex; gap: 10px; align-items: center; }
.muted { color: var(--muted); font-size: 13px; }
.errtxt { color: var(--danger); font-size: 13px; }
.welcome { text-align: center; color: var(--muted); margin-top: 18vh; padding: 0 16px; }
.welcome h2 { color: var(--ink); margin-bottom: 6px; }

.dots span { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: #9aa8a5; animation: blink 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots span { animation: none; opacity: .6; } }

.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }

details.think { margin-bottom: 10px; border: 1px dashed #c9d2cf; border-radius: 8px; background: #f8faf9; }
details.think summary { cursor: pointer; padding: 6px 10px; font-size: 12px; color: var(--muted); }
details.think .tt { padding: 4px 12px 10px; font-size: 12.5px; color: #5d6c6a; white-space: pre-wrap; line-height: 1.7; max-height: 360px; overflow-y: auto; }
.live { font-size: 12.5px; color: var(--muted); white-space: pre-wrap; line-height: 1.7; border-inline-start: 3px solid var(--line); padding: 2px 10px; margin-bottom: 10px; max-height: 170px; overflow-y: auto; }

.retry { align-self: center; margin-inline-start: 8px; border: 1px solid var(--danger); color: var(--danger); background: #fff; border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.retry:disabled { opacity: .5; }

.files { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.files a { display: block; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: #f8faf9; color: var(--accent); text-decoration: none; font-size: 13px; direction: ltr; text-align: left; }
.files a:hover { background: var(--accent-soft); }
.ufiles { margin-top: 6px; font-size: 12px; direction: ltr; text-align: left; }
.ufiles a { display: block; color: #fff; }

.imgs { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.imgs a { display: block; max-width: 100%; }
.imgs img { max-height: 220px; max-width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; background: #eef1f0; }
.imgs .cap { font-size: 11px; color: var(--muted); direction: ltr; text-align: left; margin-top: 2px; }
details.src { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; background: #f8faf9; }
details.src summary { cursor: pointer; padding: 6px 10px; font-size: 12px; color: var(--muted); }
details.src .sl { padding: 4px 12px 10px; display: flex; flex-direction: column; gap: 4px; direction: ltr; text-align: left; }
details.src a { font-size: 12.5px; color: var(--accent); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.src a small { color: var(--muted); margin-left: 6px; }

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h3, .md h4, .md h5, .md h6 { margin: 14px 0 6px; }
.md ul, .md ol { margin: 0 0 10px; padding-inline-start: 24px; }
.md code { background: #eef1f0; padding: 1px 5px; border-radius: 4px; font-family: Consolas, monospace; font-size: 13px; direction: ltr; unicode-bidi: embed; }
.md pre { background: #14201f; color: #e8eeec; padding: 10px 12px; border-radius: 8px; overflow-x: auto; direction: ltr; text-align: left; margin: 0 0 10px; }
.md pre code { background: none; padding: 0; color: inherit; }
.md a { color: var(--accent); }

#composer { background: var(--card); border-top: 1px solid var(--line); padding: 12px 16px; }
#composer .inner { display: flex; gap: 10px; align-items: flex-end; }
#modelrow { max-width: 820px; margin: 0 auto 8px; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
#model { font-family: inherit; font-size: 13px; padding: 5px 10px; border: 1px solid #c5cfcc; border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer; }
#model:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.meta .mdl { background: var(--accent-soft); color: var(--accent-d); border-radius: 6px; padding: 0 6px; }
#chips { max-width: 820px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 6px; }
#chips span { background: var(--accent-soft); border: 1px solid #bfdcd4; border-radius: 8px; padding: 3px 8px; font-size: 12px; direction: ltr; }
#chips button { border: 0; background: none; color: var(--danger); cursor: pointer; margin-inline-start: 4px; }
#attach { border: 1px solid #c5cfcc; background: #fff; border-radius: 10px; width: 46px; height: 46px; font-size: 18px; cursor: pointer; }
textarea { flex: 1; min-height: 46px; max-height: 220px; padding: 11px 12px; font-size: 15px; font-family: inherit; border: 1px solid #c5cfcc; border-radius: 10px; resize: none; color: var(--ink); }
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#btn { padding: 0 24px; height: 46px; font-size: 15px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 600; }
#btn:hover { background: var(--accent-d); }
#btn:disabled { opacity: .5; cursor: default; }
#err { color: var(--danger); font-size: 12px; text-align: center; margin-top: 6px; min-height: 0; }

@media (max-width: 800px) {
  #side { position: fixed; top: 0; bottom: 0; right: 0; z-index: 20; transform: translateX(100%); transition: transform .2s; box-shadow: 0 0 24px rgba(0,0,0,.18); }
  #side.open { transform: none; }
  #scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 15; }
  #menu { display: block; }
}
@media (prefers-reduced-motion: reduce) { #side { transition: none; } }
