/* ===== فونت وزیرمتن (self-hosted) ===== */
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/vazirmatn-arabic.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200D;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/vazirmatn-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212;
}

/* ===== توکن‌های طراحی ===== */
:root {
  /* پالت آبی (Trust Blue) */
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-deep: #1e40af;
  --accent: #38bdf8;
  --sky: #60a5fa;

  --bg: #f5f8fe;
  --surface: #ffffff;
  --surface-2: #fbfdff;
  --foreground: #1e293b;     /* متن اصلی، کنتراست بالا */
  --muted: #64748b;          /* متن کم‌رنگ */
  --border: #e6edf8;
  --border-strong: #d6e2f3;

  --user-grad: linear-gradient(135deg, #2f7bf0, #1d4ed8);
  --logo-grad: linear-gradient(145deg, #38bdf8, #2563eb 55%, #1e40af);

  --ring: rgba(37, 99, 235, 0.22);
  --shadow-sm: 0 1px 3px rgba(30, 58, 138, 0.06);
  --shadow-md: 0 8px 26px rgba(30, 64, 138, 0.10);
  --shadow-lg: 0 18px 50px rgba(29, 78, 216, 0.16);

  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;

  --font: "Vazirmatn", "Segoe UI", Tahoma, system-ui, sans-serif;
  --maxw: 780px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font);
  color: var(--foreground);
  background-color: var(--bg);
  background-image:
    radial-gradient(60rem 32rem at 88% -8%, rgba(56, 189, 248, 0.14), transparent 60%),
    radial-gradient(52rem 30rem at 6% 108%, rgba(37, 99, 235, 0.12), transparent 58%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  max-width: var(--maxw);
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== هدر ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 13px 18px;
  background: rgba(248, 251, 255, 0.72);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
  position: relative;
  width: 42px; height: 42px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 13px;
  background: var(--logo-grad);
  color: #fff;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.38), inset 0 1px 0 rgba(255,255,255,0.4);
}
.brand-logo::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
}
.logo-glyph { width: 23px; height: 23px; fill: #fff; }
.brand-title { font-weight: 700; font-size: 15.5px; letter-spacing: -0.2px; }
.brand-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted); margin-top: 3px; font-weight: 500;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #1fc873; box-shadow: 0 0 0 3px rgba(31, 200, 115, 0.16);
}
.shop-link {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--primary); text-decoration: none; font-size: 13px; font-weight: 600;
  padding: 8px 13px; border-radius: 11px; transition: background .16s, color .16s;
  white-space: nowrap;
}
.shop-link:hover { background: rgba(37, 99, 235, 0.08); }

/* ===== ناحیه‌ی پیام‌ها ===== */
.messages {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 24px 18px 10px;
  display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 9px; }
.messages::-webkit-scrollbar-thumb { background: #d3e0f2; border-radius: 9px; border: 2px solid transparent; background-clip: content-box; }
.messages::-webkit-scrollbar-thumb:hover { background: #b9cdec; background-clip: content-box; }

.row { display: flex; gap: 10px; max-width: 84%; animation: rise .26s cubic-bezier(.2,.7,.3,1) both; }
.row.user { align-self: flex-start; }            /* در RTL سمت راست */
.row.bot  { align-self: flex-end; flex-direction: row-reverse; }  /* در RTL سمت چپ */

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

.avatar {
  flex: 0 0 32px; width: 32px; height: 32px; margin-top: 2px;
  border-radius: 11px; display: grid; place-items: center;
  background: var(--logo-grad); color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.30);
}
.avatar svg { width: 18px; height: 18px; fill: #fff; }

.bubble {
  padding: 12px 16px; border-radius: var(--r-md);
  line-height: 2; font-size: 14.5px; word-break: break-word;
  font-variant-numeric: tabular-nums;
}
.row.bot .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top-left-radius: 6px;
  box-shadow: var(--shadow-sm);
  color: var(--foreground);
}
.row.user .bubble {
  background: var(--user-grad); color: #fff;
  border-top-right-radius: 6px;
  box-shadow: 0 6px 18px rgba(29, 78, 216, 0.26);
}
.bubble p { margin: 0 0 9px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble a {
  color: var(--primary); font-weight: 600; text-decoration: none;
  border-bottom: 1.5px solid rgba(37, 99, 235, 0.28);
  transition: border-color .15s;
}
.bubble a:hover { border-bottom-color: var(--primary); }
.row.user .bubble a { color: #fff; border-bottom-color: rgba(255,255,255,0.55); }
.bubble ul { margin: 7px 0; padding-inline-start: 20px; }
.bubble li { margin: 4px 0; }
.bubble li::marker { color: var(--sky); }
.bubble code {
  background: rgba(37, 99, 235, 0.08); color: var(--primary-deep);
  padding: 1px 6px; border-radius: 6px; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.bubble strong { font-weight: 700; }
.bubble .md-h { margin: 12px 0 4px; font-size: 15px; color: var(--primary-deep); }
.bubble .md-h:first-child { margin-top: 0; }

/* مکان‌نمای استریم */
.caret {
  display: inline-block; width: 2px; height: 1.05em; vertical-align: -2px;
  margin-inline-start: 2px; border-radius: 2px;
  background: var(--primary); animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ===== صفحه‌ی خوش‌آمد ===== */
.welcome { text-align: center; margin: auto; padding: 22px 6px; max-width: 540px; animation: rise .4s ease both; }
.welcome-mark {
  width: 64px; height: 64px; margin: 0 auto 18px;
  display: grid; place-items: center; border-radius: 20px;
  background: var(--logo-grad); color: #fff;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.4);
}
.welcome-mark svg { width: 34px; height: 34px; fill: #fff; }
.welcome h1 { font-size: 23px; font-weight: 800; margin: 0 0 8px; letter-spacing: -0.4px; }
.welcome p { color: var(--muted); line-height: 2.1; font-size: 14.5px; margin: 0 0 22px; }
.welcome p b { color: var(--primary-deep); font-weight: 700; }

.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font); font-size: 13.5px; font-weight: 500;
  background: var(--surface); color: var(--foreground);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 15px; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .16s cubic-bezier(.2,.7,.3,1), border-color .16s, box-shadow .16s, color .16s;
}
.chip-ico { width: 17px; height: 17px; color: var(--primary); flex: 0 0 auto; }
.chip:hover { transform: translateY(-2px); border-color: var(--sky); color: var(--primary-deep); box-shadow: var(--shadow-md); }
.chip:active { transform: translateY(0); }

/* ===== تایپینگ ===== */
.typing { display: inline-flex; gap: 5px; padding: 5px 2px; }
.typing span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--sky); animation: bounce 1.3s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .16s; background: var(--primary); }
.typing span:nth-child(3) { animation-delay: .32s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-6px); opacity: 1; } }

/* ===== کامپوزر ===== */
.composer {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(248, 251, 255, 0.82);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-top: 1px solid var(--border);
}
.composer-inner {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  padding: 7px 8px 7px 15px;
  box-shadow: var(--shadow-md);
  transition: border-color .16s, box-shadow .16s;
}
.composer-inner:focus-within { border-color: var(--sky); box-shadow: 0 0 0 4px var(--ring), var(--shadow-md); }
#input {
  flex: 1; border: none; outline: none; resize: none;
  font-family: var(--font); font-size: 14.5px; line-height: 1.9;
  background: transparent; color: var(--foreground); max-height: 150px; padding: 4px 0;
}
#input::placeholder { color: #9fb2cb; }
.send-btn {
  flex: 0 0 auto; width: 42px; height: 42px; border: none; cursor: pointer;
  border-radius: 13px; color: #fff; background: var(--user-grad);
  display: grid; place-items: center;
  box-shadow: 0 5px 14px rgba(37, 99, 235, 0.34);
  transition: transform .14s cubic-bezier(.2,.7,.3,1), box-shadow .16s, opacity .16s;
}
.send-ico { width: 20px; height: 20px; color: #fff; }
.send-btn:hover { transform: translateY(-1px) scale(1.04); box-shadow: 0 8px 20px rgba(37, 99, 235, 0.42); }
.send-btn:active { transform: scale(.96); }
.send-btn:disabled { opacity: .4; cursor: default; transform: none; box-shadow: none; }
.composer-note { text-align: center; font-size: 11px; color: var(--muted); margin-top: 9px; }

/* ===== فوکوس برای دسترس‌پذیری ===== */
:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

/* ===== موبایل ===== */
@media (max-width: 600px) {
  .row { max-width: 90%; }
  .welcome h1 { font-size: 21px; }
  .topbar { padding: 11px 14px; }
  .messages { padding: 18px 14px 8px; }
}

/* ===== احترام به کاهش حرکت ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .caret { animation: none; opacity: 1; }
}
