:root {
  --bg: #ece6d9;
  --paper: #fbf9f4;
  --ink: #1d2a2b;
  --muted: #69766f;
  --line: #ddd5c4;
  --brand: #0c6a5e;
  --brand-2: #0a5148;
  --brand-ink: #ffffff;
  --accent: #d9822b;
  --theirs: #ffffff;
  --danger: #b3382c;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(29, 42, 43, .08), 0 8px 24px -12px rgba(29, 42, 43, .25);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101816; --paper: #172220; --ink: #e8efec; --muted: #8fa39b; --line: #2a3a36;
    --brand: #17907f; --brand-2: #12756a; --theirs: #1f2e2b; --danger: #e0685b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Vazirmatn, Vazir, "IRANSans", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, color-mix(in srgb, var(--brand) 14%, transparent) 0, transparent 38%),
    radial-gradient(circle at 92% 92%, color-mix(in srgb, var(--accent) 16%, transparent) 0, transparent 40%),
    var(--bg);
  line-height: 1.7;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }

/* ---------- کارت ورود ---------- */
.center { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.card {
  width: min(420px, 100%); background: var(--paper); border: 1px solid var(--line);
  border-radius: 26px; padding: 34px 28px 26px; box-shadow: var(--shadow);
  animation: rise .5s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.mark {
  width: 60px; height: 60px; border-radius: 20px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--brand), var(--brand-2)); color: #fff;
  margin-bottom: 18px; box-shadow: 0 10px 22px -10px var(--brand);
}
.mark svg { width: 30px; height: 30px; }
.card h1 { margin: 0 0 6px; font-size: 24px; line-height: 1.4; }
.card p.lead { margin: 0 0 22px; color: var(--muted); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--bg); transition: border-color .15s, background .15s;
}
.field input:focus { outline: none; border-color: var(--brand); background: var(--paper); }
.btn {
  width: 100%; padding: 12px 18px; border: 0; border-radius: 14px; font-weight: 700;
  background: var(--brand); color: var(--brand-ink); transition: background .15s, transform .1s;
}
.btn:hover { background: var(--brand-2); }
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .6; cursor: default; }
.note { margin: 16px 0 0; font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.err { color: var(--danger); font-size: 13.5px; min-height: 22px; margin: 0 0 8px; }

/* ---------- چت ---------- */
.chat-app { height: 100dvh; display: flex; justify-content: center; padding: 0; }
.chat-box {
  width: min(760px, 100%); height: 100%; display: flex; flex-direction: column;
  background: var(--paper); border-inline: 1px solid var(--line); box-shadow: var(--shadow);
}
@media (min-width: 800px) { .chat-app { padding: 18px 0; } .chat-box { border-radius: 24px; border: 1px solid var(--line); overflow: hidden; } }
.bar {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: #fff;
  background: linear-gradient(120deg, var(--brand-2), var(--brand));
}
.bar .avatar { background: rgba(255, 255, 255, .2); color: #fff; }
.bar h2 { margin: 0; font-size: 16px; line-height: 1.3; }
.bar small { opacity: .85; font-size: 12.5px; }
.bar .grow { flex: 1; min-width: 0; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 800; background: color-mix(in srgb, var(--brand) 16%, var(--paper)); color: var(--brand);
}
.iconbtn {
  border: 0; background: transparent; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: inherit;
}
.iconbtn:hover { background: rgba(127, 127, 127, .16); }
.iconbtn svg { width: 21px; height: 21px; }

.thread {
  flex: 1; overflow-y: auto; padding: 18px 14px 10px; display: flex; flex-direction: column; gap: 6px;
  overscroll-behavior: contain; scroll-behavior: smooth;
}
.day { align-self: center; font-size: 12px; color: var(--muted); background: color-mix(in srgb, var(--line) 55%, transparent); padding: 1px 12px; border-radius: 99px; margin: 10px 0 4px; }
.empty-hint { margin: auto; text-align: center; color: var(--muted); max-width: 280px; }
.empty-hint b { color: var(--ink); display: block; font-size: 17px; margin-bottom: 4px; }
.bubble {
  max-width: min(78%, 480px); padding: 8px 12px 6px; border-radius: var(--radius);
  box-shadow: 0 1px 1px rgba(29, 42, 43, .08); word-wrap: break-word; overflow-wrap: anywhere;
  animation: pop .22s ease-out both;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.bubble.mine { align-self: flex-start; background: var(--brand); color: #fff; border-end-start-radius: 5px; }
.bubble.theirs { align-self: flex-end; background: var(--theirs); border: 1px solid var(--line); border-end-end-radius: 5px; }
.bubble .txt { white-space: pre-wrap; }
.bubble img { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin: 2px 0 6px; cursor: zoom-in; background: rgba(127,127,127,.15); min-width: 120px; min-height: 80px; object-fit: cover; }
.bubble time { display: block; font-size: 11px; opacity: .7; text-align: end; margin-top: 1px; }

.composer { border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--paper); }
.composer .row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 44px; padding: 10px 14px; line-height: 1.6;
  border: 1.5px solid var(--line); border-radius: 22px; background: var(--bg);
}
.composer textarea:focus { outline: none; border-color: var(--brand); background: var(--paper); }
.send {
  width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none; display: grid; place-items: center;
  background: var(--brand); color: #fff; transition: background .15s, transform .1s;
}
.send:hover { background: var(--brand-2); }
.send:disabled { opacity: .5; cursor: default; }
.send svg { width: 20px; height: 20px; transform: scaleX(-1); }
.attach { color: var(--muted); width: 44px; height: 44px; border-radius: 50%; }
.preview { display: flex; align-items: center; gap: 10px; padding: 6px 4px 10px; }
.preview img { width: 54px; height: 54px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.preview span { flex: 1; font-size: 13px; color: var(--muted); }
.banner { background: #fff3d6; color: #6b4a00; text-align: center; font-size: 13px; padding: 4px 10px; }
.toast { position: fixed; inset-inline: 0; bottom: 92px; margin: auto; width: fit-content; max-width: 90%; background: var(--ink); color: var(--paper); padding: 8px 16px; border-radius: 12px; font-size: 14px; z-index: 30; box-shadow: var(--shadow); }

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(8, 12, 11, .88); display: grid; place-items: center; padding: 20px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

/* ---------- پنل مدیریت ---------- */
.panel { height: 100dvh; display: grid; grid-template-columns: 340px 1fr; }
.side { background: var(--paper); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; gap: 4px; padding: 14px 14px 8px; }
.side-head h1 { flex: 1; margin: 0; font-size: 18px; }
.search { padding: 4px 14px 10px; }
.search input { width: 100%; padding: 9px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--bg); }
.search input:focus { outline: none; border-color: var(--brand); }
.list { list-style: none; margin: 0; padding: 0 8px 10px; overflow-y: auto; flex: 1; }
.item {
  display: flex; gap: 11px; align-items: center; width: 100%; text-align: start; padding: 10px; border: 0; background: transparent;
  border-radius: 16px; transition: background .12s;
}
.item:hover { background: color-mix(in srgb, var(--line) 45%, transparent); }
.item[aria-current="true"] { background: color-mix(in srgb, var(--brand) 14%, var(--paper)); }
.item .meta { flex: 1; min-width: 0; }
.item .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .tm { font-size: 11.5px; color: var(--muted); flex: none; }
.item .bot { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.item .pv { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; min-width: 21px; height: 21px; padding: 0 6px; border-radius: 99px; display: grid; place-items: center; flex: none; }
.list-empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: transparent; }
.main .bar { background: var(--paper); color: var(--ink); border-bottom: 1px solid var(--line); }
.main .bar .avatar { background: color-mix(in srgb, var(--brand) 16%, var(--paper)); color: var(--brand); }
.main .bar small { opacity: 1; color: var(--muted); }
.main .thread { padding-inline: clamp(12px, 4vw, 40px); }
.main .composer { background: var(--paper); }
.placeholder { margin: auto; text-align: center; color: var(--muted); }
.placeholder .mark { margin-inline: auto; opacity: .85; }
.danger:hover { color: var(--danger); }
.only-mobile { display: none; }
@media (max-width: 760px) {
  .panel { grid-template-columns: 1fr; }
  .panel .main { display: none; }
  .panel.open .side { display: none; }
  .panel.open .main { display: flex; background: var(--paper); }
  .only-mobile { display: grid; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- پنجرهٔ کد پیگیری ---------- */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(8, 12, 11, .55); display: grid; place-items: center; padding: 20px; }
.modal .card { padding: 26px 24px 22px; }
.modal h2 { margin: 0 0 6px; font-size: 20px; }
.code { direction: ltr; text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 26px; letter-spacing: 3px; font-weight: 700; padding: 14px 8px; margin: 14px 0; border-radius: 16px; background: var(--bg); border: 1.5px dashed var(--brand); user-select: all; }
.btn.ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--brand); }
.btn.ghost:hover { background: color-mix(in srgb, var(--brand) 10%, transparent); }
.stack { display: grid; gap: 8px; }
.linkbtn { background: none; border: 0; color: var(--brand); text-decoration: underline; padding: 6px 0; margin-top: 10px; }
