@font-face { font-family: Vazirmatn; src: url(/assets/Vazirmatn-wght.woff2) format('woff2'); font-weight: 100 900; font-display: swap; }
:root {
  --bg: #0b1530; --bg2: #101d3f; --card: #14234a; --card2: #1a2c5a; --line: #26396b;
  --ink: #eef2fb; --muted: #9aa8c8; --accent: #2f6bff; --accent2: #22c3d6; --ok: #2ec27e; --warn: #ffb547; --danger: #ff5d6c;
  --user: #1d3a7a; --bot: #18284f;
  --radius: 18px; --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Vazirmatn, Tahoma, sans-serif; background: radial-gradient(1200px 600px at 80% -10%, #1b3a8a55, transparent 60%), var(--bg);
  color: var(--ink); line-height: 1.75; -webkit-font-smoothing: antialiased; display: flex; flex-direction: column; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { fill: currentColor; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: #0b1530cc; backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.plate { background: #fff; border-radius: 12px; padding: 5px 8px; display: flex; flex-shrink: 0; }
.plate img { height: 26px; display: block; }
.titles h1 { font-size: 16px; margin: 0; font-weight: 800; line-height: 1.4; }
.titles span { font-size: 12px; color: var(--muted); }
.scen-pick { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); min-width: 0; }
.scen-pick select { max-width: 260px; }

select, input, textarea { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; width: 100%; outline: none; transition: border-color .2s; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; line-height: 1.8; }

/* tabs */
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; }
.tab { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--muted); padding: 10px 14px; border-radius: 12px 12px 0 0; cursor: pointer; font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; }
.tab svg { width: 18px; height: 18px; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent2); }
main { flex: 1; display: flex; min-height: 0; }
.panel { display: none; flex: 1; padding: 16px; min-height: 0; }
.panel.active { display: flex; }

/* talk */
#tab-talk { gap: 16px; }
.stage { flex: 0 0 380px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: linear-gradient(180deg, var(--card), var(--bg2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 16px; }
.orb-wrap { width: 230px; height: 230px; display: grid; place-items: center; }
.orb { position: relative; width: 190px; height: 190px; border-radius: 50%; border: 0; background: none; cursor: pointer; padding: 0; display: grid; place-items: center; -webkit-tap-highlight-color: transparent; }
.orb .core { position: relative; width: 150px; height: 150px; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle at 35% 30%, #4f86ff, #1a3fb8 55%, #0c1f66); box-shadow: 0 0 40px #2f6bff66, inset 0 0 30px #0006; transition: transform .25s, background .4s, box-shadow .4s; z-index: 2; overflow: hidden; }
.orb canvas { position: absolute; left: 50%; top: 50%; width: 116%; height: 116%; transform: translate(-50%,-50%); pointer-events: none; z-index: 3; }
.orb .mic { width: 54px; height: 54px; color: #fff; opacity: .95; position: relative; }
.orb .ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; }
.orb.listening .ring { animation: pulse 2.4s ease-out infinite; border-color: var(--accent2); }
.orb.listening .r2 { animation-delay: .8s; } .orb.listening .r3 { animation-delay: 1.6s; }
.orb.hearing .core { transform: scale(1.08); background: radial-gradient(circle at 35% 30%, #5ef0ff, #14a3b8 55%, #0b5566); box-shadow: 0 0 60px #22c3d699; }
.orb.thinking .core { background: conic-gradient(from 0deg, #2f6bff, #22c3d6, #7b5cff, #2f6bff); animation: spin 1.4s linear infinite; }
.orb.thinking .mic { animation: spin 1.4s linear infinite reverse; }
.orb.speaking .core { background: radial-gradient(circle at 35% 30%, #8fb0ff, #3a5cff 55%, #1d2a8a); box-shadow: 0 0 70px #5b7cff99; }
.orb.idle .core { filter: saturate(.6) brightness(.85); }
@keyframes pulse { 0% { transform: scale(.8); opacity: .8; } 100% { transform: scale(1.25); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
.status { font-size: 18px; font-weight: 700; text-align: center; min-height: 32px; }
.hint { font-size: 13px; color: var(--muted); text-align: center; max-width: 320px; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.metrics { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; font-size: 11.5px; color: var(--muted); min-height: 22px; }
.metrics span { background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 1px 10px; }
.metrics b { color: var(--accent2); font-weight: 700; direction: ltr; unicode-bidi: isolate; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 12px; padding: 10px 18px; cursor: pointer; font-weight: 700; font-size: 14px; transition: filter .15s, background .2s, opacity .2s; white-space: nowrap; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #1f4fd6); color: #fff; }
.btn.primary.stop { background: linear-gradient(135deg, #ff5d6c, #d23a4a); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { background: transparent; border-color: #ff5d6c55; color: var(--danger); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.icon { padding: 10px; }
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: default; }

.convo { flex: 1; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); min-height: 0; overflow: hidden; }
.convo-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.convo-head h2 { margin: 0; font-size: 15px; }
.badge { font-size: 12px; color: var(--accent2); background: #22c3d61a; border: 1px solid #22c3d64d; border-radius: 99px; padding: 2px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.empty { color: var(--muted); text-align: center; margin: auto; font-size: 14px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 16px; font-size: 15px; position: relative; animation: rise .25s ease-out; white-space: pre-wrap; }
.msg .who { display: block; font-size: 11.5px; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.msg.user { align-self: flex-start; background: var(--user); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-end; background: var(--bot); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.interrupted::after { content: 'قطع شد'; position: absolute; bottom: -9px; left: 12px; font-size: 10.5px; background: var(--warn); color: #241600; border-radius: 99px; padding: 0 8px; font-weight: 700; }
.msg .unspoken { opacity: .35; text-decoration: line-through; }
.msg.pending { opacity: .6; font-style: italic; }
.msg.error { background: #ff5d6c22; border: 1px solid #ff5d6c66; align-self: center; font-size: 13px; }
@keyframes rise { from { transform: translateY(6px); opacity: 0; } }
.typebar { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); padding-bottom: calc(10px + var(--safe-b)); }

/* kb */
.kb-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 16px; width: 100%; align-items: start; overflow-y: auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card.narrow { max-width: 640px; margin: 0 auto; width: 100%; overflow-y: auto; align-self: flex-start; }
.card h2 { font-size: 16px; margin: 0 0 8px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.row-btns { display: flex; gap: 6px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: #c9d3ea; }
.form label small { color: var(--muted); font-weight: 400; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label.end { justify-content: flex-end; }
.form-foot { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.saved { color: var(--ok); font-size: 13px; }
.muted { color: var(--muted); font-size: 13.5px; margin: 0 0 12px; }
.small { font-size: 12.5px; }
.drop { display: flex; flex-direction: column; align-items: center; gap: 4px; border: 2px dashed var(--line); border-radius: 16px; padding: 22px; cursor: pointer; text-align: center; transition: border-color .2s, background .2s; }
.drop:hover, .drop.over { border-color: var(--accent2); background: #22c3d60d; }
.drop input { display: none; }
.drop svg { width: 34px; height: 34px; color: var(--accent2); }
.drop small { color: var(--muted); }
.docs { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.docs li { display: flex; align-items: center; gap: 10px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 14px; }
.docs li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docs li .sz { color: var(--muted); font-size: 12px; white-space: nowrap; }
.docs li button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 8px; }
.docs li button:hover { color: var(--danger); }
.docs li .view:hover { color: var(--accent2); }
.note summary { cursor: pointer; color: var(--accent2); font-size: 14px; margin-bottom: 10px; }
.warn { background: #ffb5471a; border: 1px solid #ffb54766; color: #ffd79a; border-radius: 12px; padding: 10px 14px; font-size: 13.5px; margin-top: 14px; }
code { direction: ltr; unicode-bidi: isolate; background: #0004; padding: 1px 6px; border-radius: 6px; }
output { color: var(--accent2); font-weight: 700; margin-inline-start: 6px; }
input[type=range] { padding: 0; accent-color: var(--accent2); border: 0; background: none; }

/* modal */
.modal { position: fixed; inset: 0; background: #050a18cc; display: grid; place-items: center; z-index: 20; padding: 16px; backdrop-filter: blur(4px); }
.modal[hidden] { display: none; }
.sheet { background: var(--card); border: 1px solid var(--line); border-radius: 20px; width: min(720px, 100%); max-height: 86dvh; display: flex; flex-direction: column; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 16px; }
.sheet-body { padding: 16px 18px; overflow-y: auto; white-space: pre-wrap; font-size: 14.5px; }
.sheet-body h3 { color: var(--accent2); font-size: 15px; margin: 14px 0 4px; }

/* mobile */
@media (max-width: 860px) {
  .top { padding: 10px 12px; }
  .plate img { height: 20px; }
  .titles span { display: none; }
  .titles h1 { font-size: 14px; }
  .scen-pick > span { display: none; }
  .scen-pick select { max-width: 46vw; padding: 7px 10px; font-size: 13px; }
  .tabs { position: fixed; bottom: 0; inset-inline: 0; background: #0b1530f2; border-top: 1px solid var(--line); padding: 4px 8px calc(4px + var(--safe-b)); z-index: 6; justify-content: space-around; backdrop-filter: blur(10px); }
  .tab { flex-direction: column; gap: 0; font-size: 11.5px; padding: 6px 10px; border-radius: 12px; border-bottom: 0; }
  .tab svg { width: 22px; height: 22px; }
  .tab.active { color: var(--accent2); background: #22c3d614; }
  main { padding-bottom: calc(64px + var(--safe-b)); }
  .panel { padding: 10px; }
  #tab-talk { flex-direction: column; gap: 10px; }
  .stage { flex: 0 0 auto; padding: 14px 12px; gap: 8px; }
  .orb-wrap { width: 170px; height: 170px; }
  .orb { width: 150px; height: 150px; }
  .orb .core { width: 118px; height: 118px; }
  .orb .mic { width: 42px; height: 42px; }
  .status { font-size: 16px; }
  .hint { display: none; }
  .btn { padding: 9px 14px; font-size: 13.5px; }
  .convo { min-height: 46dvh; }
  .typebar { padding-bottom: 10px; }
  .kb-grid { grid-template-columns: 1fr; }
  .form .two { grid-template-columns: 1fr; }
  .msg { max-width: 92%; font-size: 14.5px; }
}
