/* self-hosted (OFL): the page makes no third-party requests */
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --panel: #f7f9fc;
  --border: #e3e8f0;
  --text: #1c2738;
  --muted: #6b7789;
  --primary: #1a5fe0;
  --primary-ink: #ffffff;
  --accent: #19b5d9;
  --user-bubble: #e4f3fc;
  --user-border: #cbe6f6;
  --bot-bubble: #ffffff;
  --chip-border: #c7d5ea;
  --shadow: 0 12px 40px rgba(28, 39, 56, 0.08);
  --orb-bg: #ffffff;
  --orb-shadow: 0 10px 30px rgba(26, 95, 224, 0.15), inset 0 -6px 16px rgba(28, 39, 56, 0.05);
  --viz-a: #1a5fe0;
  --viz-b: #22c3e6;
  --viz-glow: 0;
  --focus: #1a5fe0;
  --danger: #d93838;
  --radius: 18px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #121826;
  --card: #1a2232;
  --panel: #1f2939;
  --border: #2b3649;
  --text: #e8edf5;
  --muted: #98a4b8;
  --primary: #2f74f5;
  --accent: #2fd0f0;
  --user-bubble: #22304a;
  --user-border: #2f4064;
  --bot-bubble: #1f2939;
  --chip-border: #34425a;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --orb-bg: #f4f7fb;
  --orb-shadow: 0 0 40px rgba(47, 208, 240, 0.35);
  --viz-a: #2f8cf5;
  --viz-b: #36d6f2;
  --viz-glow: 1;
  --focus: #5cc8ff;
  --danger: #ff7272;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121826; --card: #1a2232; --panel: #1f2939; --border: #2b3649; --text: #e8edf5; --muted: #98a4b8;
    --primary: #2f74f5; --accent: #2fd0f0; --user-bubble: #22304a; --user-border: #2f4064; --bot-bubble: #1f2939;
    --chip-border: #34425a; --shadow: 0 12px 40px rgba(0,0,0,.35); --orb-bg: #f4f7fb;
    --orb-shadow: 0 0 40px rgba(47,208,240,.35); --viz-a: #2f8cf5; --viz-b: #36d6f2; --viz-glow: 1;
    --focus: #5cc8ff; --danger: #ff7272; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.75 "Vazirmatn", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- shell ---------- */
.app {
  height: 100dvh;
  display: flex; flex-direction: column;
  max-width: 1180px; margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 4px 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  flex: none; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  color: var(--primary); background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.logo svg { width: 26px; height: 26px; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.3; }
.brand p { margin: 0; font-size: 13px; color: var(--muted); }
.icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  transition: background 200ms ease, color 200ms ease;
}
.icon-btn:hover { background: var(--panel); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}
.i-muted { display: none; }
#sound[aria-pressed="false"] .i-sound { display: none; }
#sound[aria-pressed="false"] .i-muted { display: block; }
.top__actions { display: flex; gap: 4px; }
.embed .top { padding-inline-end: 112px; } /* room for the host page's «خروج» button */
@media (max-width: 379px) { .logo { display: none; } } /* small phones: the decorative logo makes way for the buttons */
@media (max-width: 499px) { /* phones in the overlay: only the title fits beside three buttons and «خروج» */
  .embed .logo, .embed .brand p { display: none; }
  .embed .brand h1 { font-size: 18px; }
}

.layout { flex: 1; min-height: 0; display: flex; gap: 16px; }

/* ---------- chat column ---------- */
.chat {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow);
  padding: 16px;
}

.voice { flex: none; display: flex; flex-direction: column; align-items: center; transition: height 300ms ease; }
.viz { position: relative; width: min(300px, 70vw); aspect-ratio: 1; transition: width 300ms ease; }
.viz canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.orb {
  position: absolute; inset: 29%; border-radius: 50%; border: 0;
  display: grid; place-items: center; color: var(--primary);
  background: radial-gradient(circle at 50% 35%, var(--orb-bg), #e9eef6 85%);
  box-shadow: var(--orb-shadow);
  transition: transform 200ms ease;
}
.orb:hover { transform: scale(1.03); }
.orb:active { transform: scale(0.97); }
.orb svg { width: 38%; height: 38%; stroke-width: 2.2; }
.status { margin: 2px 0 6px; font-size: 15px; font-weight: 500; color: var(--muted); min-height: 1.75em; text-align: center; }
body[data-state="listening"] .status,
body[data-state="thinking"] .status,
body[data-state="answering"] .status { color: var(--primary); }
body[data-state="error"] .status { color: var(--danger); }

.thread {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 14px; padding: 6px 4px 12px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

.msg { display: flex; align-items: flex-start; gap: 10px; max-width: 86%; }
.msg--user { align-self: flex-start; }      /* RTL: start = right */
.msg--bot { align-self: flex-end; flex-direction: row-reverse; }
.bubble {
  padding: 12px 16px 8px; border-radius: 18px; font-size: 15.5px; line-height: 1.85;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg--user .bubble { background: var(--user-bubble); border: 1px solid var(--user-border); border-start-start-radius: 6px; }
.msg--bot .bubble { background: var(--bot-bubble); border: 1px solid var(--border); border-start-end-radius: 6px; box-shadow: 0 4px 14px rgba(28, 39, 56, 0.05); }
.bubble a { color: var(--primary); text-underline-offset: 3px; }
.sources { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; white-space: normal; }
.source-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--chip-border); background: var(--panel);
  color: var(--primary) !important; text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background 200ms ease, border-color 200ms ease;
}
.source-btn:hover { background: var(--user-bubble); border-color: var(--primary); }
.source-btn svg { width: 16px; height: 16px; flex: none; }
.meta { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 2px; font-size: 11.5px; color: var(--muted); }
.msg--bot .meta { justify-content: flex-start; }
.meta svg { width: 16px; height: 16px; color: var(--accent); }
.bot-icon {
  flex: none; width: 36px; height: 36px; margin-top: 8px; border-radius: 50%; display: grid; place-items: center;
  color: var(--accent); border: 1px solid var(--border); background: var(--card);
}
.bot-icon svg { width: 20px; height: 20px; }
.typing .text::after {
  content: ""; display: inline-block; width: 2px; height: 1.05em; margin-inline-start: 2px; vertical-align: -0.18em;
  background: var(--primary); animation: caret 0.9s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
.dots { display: inline-flex; gap: 4px; padding: 6px 2px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: dot 1.1s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.chips { flex: none; display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 44px; padding: 0 16px; font-size: 14px;
  background: var(--card); border: 1px solid var(--chip-border); border-radius: 14px;
  transition: border-color 200ms ease, background 200ms ease;
}
.chip:hover { border-color: var(--primary); background: var(--user-bubble); }

.composer {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 6px; border-radius: 999px; background: var(--card); border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(28, 39, 56, 0.07);
}
.composer input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 8px; border: 0; background: transparent;
  font: inherit; font-size: 15px; color: var(--text);
}
.composer input::placeholder { color: var(--muted); }
.composer input:focus { outline: none; }
.composer:focus-within { border-color: var(--primary); }
.send {
  flex: none; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  transition: background 200ms ease;
}
.send:hover { background: var(--user-bubble); }
.send:disabled { opacity: .5; cursor: not-allowed; }
.send svg { width: 20px; height: 20px; transform: scaleX(-1); }
.mic {
  flex: none; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; border: 0;
  background: var(--primary); color: var(--primary-ink);
  box-shadow: 0 8px 20px rgba(26, 95, 224, 0.35);
  transition: transform 150ms ease, box-shadow 200ms ease;
}
.mic:hover { transform: scale(1.04); }
.mic svg { width: 24px; height: 24px; stroke-width: 2; }
.mic[aria-pressed="true"] { animation: ring 1.4s ease-out infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(26, 95, 224, .45); } 100% { box-shadow: 0 0 0 14px rgba(26, 95, 224, 0); } }

/* rating under each answer */
.rate { display: inline-flex; gap: 2px; margin-inline-start: auto; }
.rate button {
  width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%;
  background: transparent; border: 0; color: var(--muted); transition: background 200ms ease, color 200ms ease;
}
.rate button:hover { background: var(--panel); color: var(--text); }
.rate button[aria-pressed="true"] { color: var(--primary); background: var(--user-bubble); }
.rate svg { width: 16px; height: 16px; color: inherit; }
.msg--bot .meta { gap: 8px; }

/* «ویرایش» on questions that came from the microphone; negative margins keep the row short, the hit area 32px */
.edit {
  min-height: 32px; margin-block: -6px; margin-inline-end: auto; padding: 0 6px;
  background: transparent; border: 0; border-radius: 8px; font-size: 12px; font-weight: 500; text-underline-offset: 3px;
  color: color-mix(in srgb, var(--muted) 75%, var(--text)); /* without color-mix it inherits the muted meta color */
}
.edit:hover { color: var(--text); text-decoration: underline; }
.edit:focus-visible { outline-offset: -2px; } /* stays inside the bubble */

/* feedback sheet */
.sheet {
  width: min(480px, calc(100% - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 22px;
  background: var(--card); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
}
.sheet::backdrop { background: rgba(12, 18, 30, 0.45); backdrop-filter: blur(2px); }
.sheet form { padding: 18px 20px 20px; display: flex; flex-direction: column; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet h2 { margin: 0; font-size: 18px; }
.kinds { border: 0; padding: 0; margin: 4px 0 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.kinds legend { font-size: 14px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.kinds label { position: relative; }
.kinds input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.kinds span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 14px;
  border: 1px solid var(--chip-border); font-size: 14px; transition: all 200ms ease;
}
.kinds input:checked + span { border-color: var(--primary); background: var(--user-bubble); color: var(--primary); font-weight: 500; }
.kinds input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.field { font-size: 14px; color: var(--muted); margin: 10px 0 6px; }
.opt { font-size: 12px; }
.sheet textarea, .sheet input[type="text"] {
  width: 100%; font: inherit; font-size: 15px; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 14px; padding: 10px 14px; resize: vertical;
}
.sheet input[type="text"] { min-height: 48px; }
.sheet textarea:focus, .sheet input[type="text"]:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.hint { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.fb-msg { font-size: 14px; margin: 8px 0 0; min-height: 1.5em; }
.fb-msg.ok { color: #12945a; } .fb-msg.err { color: var(--danger); }
.primary {
  margin-top: 8px; min-height: 50px; border: 0; border-radius: 14px; background: var(--primary); color: var(--primary-ink);
  font-weight: 700; font-size: 15px; transition: filter 200ms ease;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .6; cursor: progress; }

/* microphone explainer (before the browser's own prompt) */
.sheet--mic { width: min(420px, calc(100% - 32px)); }
.mic-sheet { padding: 28px 24px 22px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.mic-sheet__icon {
  width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 14px;
  color: var(--primary-ink); background: var(--primary);
  box-shadow: 0 0 0 10px var(--user-bubble), 0 10px 30px rgba(26, 95, 224, 0.35);
}
.mic-sheet__icon svg { width: 34px; height: 34px; stroke-width: 2; }
.mic-sheet h2 { margin: 6px 0 8px; font-size: 19px; }
.mic-sheet p { margin: 0; font-size: 15px; line-height: 1.9; color: var(--text); }
.mic-sheet__steps { margin: 12px 0 0; padding-inline-start: 22px; text-align: start; font-size: 14.5px; line-height: 1.9; align-self: stretch; }
.mic-sheet__note { margin-top: 12px !important; font-size: 12.5px !important; color: var(--muted) !important; }
.mic-sheet__actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; align-self: stretch; }
.mic-sheet__actions .primary { margin-top: 0; }
.ghost {
  min-height: 48px; border: 1px solid var(--border); border-radius: 14px; background: transparent;
  color: var(--text); font-size: 15px; transition: background 200ms ease;
}
.ghost:hover { background: var(--panel); }

/* ---------- recent questions (desktop) ---------- */
.recent {
  display: none; flex: none; width: 300px; flex-direction: column;
  background: var(--card); border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow);
  padding: 18px 14px;
}
.recent h2 { display: flex; align-items: center; gap: 8px; margin: 0 6px 10px; font-size: 16px; font-weight: 700; }
.recent h2 svg { width: 20px; height: 20px; color: var(--muted); }
.recent__list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.recent__list li + li { border-top: 1px solid var(--border); }
.recent__item {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 8px; text-align: start;
  background: transparent; border: 0; border-radius: 12px; transition: background 200ms ease;
}
.recent__item:hover { background: var(--panel); }
.recent__item .q { flex: 1; min-width: 0; font-size: 14px; line-height: 1.7; }
.recent__item .when { display: block; font-size: 11.5px; color: var(--muted); }
.recent__item svg { flex: none; width: 18px; height: 18px; color: var(--muted); }
.recent__all {
  margin-top: 10px; min-height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  background: transparent; border: 1px solid var(--border); border-radius: 999px; font-size: 14px;
}
.recent__all svg { width: 18px; height: 18px; }
.recent__all:hover { background: var(--panel); }

/* ---------- desktop: thread on top, voice under it, recent questions on the side ---------- */
@media (min-width: 1000px) {
  .app { padding: 24px; }
  .recent { display: flex; }
  .chat { padding: 20px 28px 24px; }
  .thread { order: 1; }
  .voice { order: 2; }
  #live { order: 3; }
  .chips { display: none; }
  .composer { order: 4; max-width: 560px; width: 100%; align-self: center; }
  .viz { width: 260px; }
}

/* ---------- mobile: once the conversation starts, shrink the visualizer to give the thread room ---------- */
@media (max-width: 999px) {
  .chat { padding: 12px; border-radius: 20px; }
  body.has-chat .viz { width: 132px; }
  body.has-chat .status { font-size: 13px; margin-bottom: 2px; }
  .msg { max-width: 92%; }
}
@media (max-width: 999px) and (max-height: 700px) {
  .viz { width: min(220px, 60vw); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0ms !important; }
}
