/* آوا — رابط به سبک ChatGPT (تم تیره) */

:root {
  --bg: #212121;
  --sidebar: #171717;
  --surface: #2f2f2f;
  --surface-2: #3a3a3a;
  --border: rgba(255, 255, 255, 0.10);
  --text: #ececec;
  --muted: #9b9b9b;
  --accent: #10a37f;
  --danger: #ef4444;
  --live: #34d399;
  --radius: 14px;
  font-size: 15px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* صفت hidden همیشه باید برنده شود (حتی روی عناصری که display صریح دارند) */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  overflow: hidden;
  height: 100dvh; /* ارتفاع واقعی صفحه در موبایل (با احتساب نوار مرورگر) */
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; color: var(--text); }

/* ---------- سایدبار ---------- */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
  transition: margin-inline-start 0.25s ease;
}
#sidebar.hidden { margin-inline-start: -260px; }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
}
.new-chat-btn:hover { background: rgba(255, 255, 255, 0.06); }
.new-chat-btn svg { margin-inline-start: auto; opacity: 0.7; }

.logo-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #19c37d, #0e8a6a);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}

#chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  color: var(--text);
  width: 100%;
  text-align: start;
  white-space: nowrap; overflow: hidden;
}
.chat-item span { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.chat-item:hover { background: rgba(255, 255, 255, 0.06); }
.chat-item.active { background: rgba(255, 255, 255, 0.10); }
.chat-item .del { opacity: 0; font-size: 12px; color: var(--muted); }
.chat-item:hover .del { opacity: 1; }
.chat-item .del:hover { color: var(--danger); }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 8px; }
.side-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px;
  border-radius: 10px; font-size: 14px;
}
.side-item:hover { background: rgba(255, 255, 255, 0.06); }

/* ---------- بخش اصلی ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  position: relative;
}
.icon-btn {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  color: var(--text);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }
.icon-btn.active { background: var(--danger); color: #fff; }

.model-picker select {
  background: transparent;
  border: none;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  max-width: 300px;
}
.model-picker select:hover { background: rgba(255, 255, 255, 0.08); }
.model-picker select:focus { outline: none; }
.model-picker option { background: var(--surface); }

.chip-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
}
.chip-btn:hover { background: rgba(255, 255, 255, 0.06); }
.chip-btn.danger { color: var(--danger); border-color: var(--danger); }

.tone-popover {
  position: absolute;
  top: 52px;
  inset-inline-start: 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  z-index: 30;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  width: min(440px, calc(100vw - 40px));
  max-height: 70vh;
  overflow-y: auto;
}
.tone-popover .span2 { grid-column: 1 / -1; }
.tone-popover label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.tone-popover select {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 13px;
}

/* ---------- پیام‌ها ---------- */
#messages-wrap { flex: 1; overflow-y: auto; position: relative; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#messages { max-width: 768px; margin: 0 auto; padding: 12px 20px 24px; display: flex; flex-direction: column; gap: 4px; }

.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; pointer-events: none;
}
.empty-logo {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, #19c37d, #0e8a6a);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700;
}
.empty-state h1 { font-size: 26px; font-weight: 600; }
.empty-state.gone { display: none; }

.row { display: flex; gap: 14px; padding: 14px 0; }
.row .avatar {
  width: 32px; height: 32px; min-width: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}
.row.assistant .avatar { background: linear-gradient(135deg, #19c37d, #0e8a6a); color: #fff; }
.row .content { line-height: 2.05; font-size: 15.5px; min-width: 0; overflow-wrap: break-word; padding-top: 3px; }

.row.user { justify-content: flex-start; }
.row.user .content {
  background: var(--surface);
  border-radius: 20px;
  padding: 10px 18px;
  max-width: 78%;
}

.row.assistant .content { flex: 1; }
.row.assistant .content p { margin: 0 0 10px; }
.row.assistant .content p:last-child { margin-bottom: 0; }
.row.assistant .content ul, .row.assistant .content ol { margin: 0 20px 10px 0; }
.row.assistant .content pre {
  background: #0d0d0d; border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; overflow-x: auto;
  direction: ltr; text-align: left; font-size: 13px; margin: 0 0 10px;
}
.row.assistant .content code { background: rgba(255,255,255,0.08); border-radius: 5px; padding: 1px 5px; font-size: 13.5px; }
.row.assistant .content pre code { background: none; padding: 0; }

.row.system { justify-content: center; }
.row.system .content { color: var(--muted); font-size: 12.5px; }

.typing { display: inline-flex; gap: 4px; padding: 8px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ---------- کامپوزر ---------- */
.composer-wrap { max-width: 768px; width: 100%; margin: 0 auto; padding: 0 20px 14px; }
.status { min-height: 20px; font-size: 12.5px; color: var(--muted); padding: 2px 8px; }
.status.error { color: var(--danger); }
.status.live { color: var(--live); }

.composer {
  background: var(--surface);
  border-radius: 26px;
  padding: 10px 14px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  box-shadow: 0 0 0 1px var(--border);
}
.composer:focus-within { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.25); }

#text-input {
  flex: 1;
  background: transparent;
  border: none;
  resize: none;
  font-size: 16px; /* ۱۶px = جلوگیری از زوم خودکار iOS هنگام فوکوس */
  line-height: 1.8;
  max-height: 180px;
  padding: 6px 4px;
}
#text-input:focus { outline: none; }
#text-input::placeholder { color: var(--muted); }

.composer-actions { display: flex; align-items: center; gap: 4px; }
.send-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #fff;
  color: #000;
  display: inline-flex; align-items: center; justify-content: center;
  transition: opacity 0.15s;
}
.send-btn:disabled { opacity: 0.25; cursor: default; }
.wave-btn.active, #record-btn.active { background: var(--danger); color: #fff; }

.composer-hint { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 8px; }

/* ---------- مکالمهٔ زندهٔ تمام‌صفحه ---------- */
.live-overlay {
  position: fixed; inset: 0;
  background: #0d0d0d;
  z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 28px;
}
.orb-wrap { width: 190px; height: 190px; display: flex; align-items: center; justify-content: center; }
.orb {
  width: 150px; height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #9be8ff, #4a9eff 45%, #1c56d6 90%);
  box-shadow: 0 0 70px rgba(74, 158, 255, 0.45);
  animation: breathe 2.6s ease-in-out infinite;
  transition: transform 0.2s ease, box-shadow 0.3s ease;
}
.orb.listening { animation: breathe 1.5s ease-in-out infinite; box-shadow: 0 0 90px rgba(52, 211, 153, 0.5); background: radial-gradient(circle at 35% 30%, #b8ffd9, #34d399 45%, #0e8a6a 90%); }
.orb.speaking { animation: pulse 0.55s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }

.live-status { font-size: 16px; color: #cfcfcf; }
.live-transcript {
  max-width: 620px; min-height: 52px;
  text-align: center; color: #8f8f8f;
  font-size: 14px; line-height: 2; padding: 0 24px;
}
.live-end {
  width: 62px; height: 62px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.live-end:hover { filter: brightness(1.15); }

/* ---------- پنل تنظیمات ---------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 40; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: min(680px, 100vw);
  background: var(--bg);
  border-right: 1px solid var(--border);
  z-index: 50;
  overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  visibility: hidden;
}
.drawer.open { transform: translateX(0); visibility: visible; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2 { font-size: 18px; }

/* تب‌های پنل تنظیمات — مدرن و چسبان */
.drawer-tabs {
  position: sticky; top: -20px;
  z-index: 5;
  display: flex; gap: 6px;
  overflow-x: auto;
  padding: 10px 2px;
  margin: -6px 0 2px;
  background: var(--bg);
  scrollbar-width: none;
}
.drawer-tabs::-webkit-scrollbar { display: none; }
.dtab {
  flex-shrink: 0;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: transparent;
  transition: all 0.15s;
  white-space: nowrap;
}
.dtab:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.dtab.active {
  background: #fff; color: #000;
  border-color: #fff; font-weight: 600;
}
[data-pane].pane-hidden { display: none; }

/* ردیف انتخاب صدا + پیش‌شنود */
.voice-row { display: flex; gap: 8px; align-items: stretch; }
.voice-row select { flex: 1; min-width: 0; }
.voice-preview {
  width: 44px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 15px;
  flex-shrink: 0;
  transition: all 0.15s;
}
.voice-preview:hover { background: var(--surface-2); }
.voice-preview.loading { animation: preview-pulse 1s infinite; }
@keyframes preview-pulse { 50% { opacity: 0.4; } }

.card { background: var(--sidebar); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }
.card hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.hint { font-size: 12px; color: var(--muted); margin-bottom: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.form-grid label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; font-size: 14px;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { outline: none; border-color: rgba(255,255,255,0.35); }
.form-grid textarea { resize: vertical; line-height: 1.9; }
.actions { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.primary-btn {
  background: #fff; color: #000;
  border-radius: 999px; padding: 9px 20px; font-size: 13.5px; font-weight: 600;
}
.primary-btn:hover { filter: brightness(0.9); }

.badge { font-size: 11px; color: var(--live); }
.badge.unset { color: var(--danger); }
.test-result {
  grid-column: 1 / -1; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  font-size: 12px; direction: ltr; text-align: left; white-space: pre-wrap;
}

.kb-list { display: flex; flex-direction: column; gap: 8px; }
.kb-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; font-size: 13px;
}
.kb-item .meta { color: var(--muted); font-size: 11px; }
.kb-item button { color: var(--danger); font-size: 14px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; text-align: center; }
.stat-tile .value { font-size: 22px; font-weight: 700; color: var(--live); }
.stat-tile .label { font-size: 11px; color: var(--muted); margin-top: 4px; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.stats-table th, .stats-table td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: right; }
.stats-table th { color: var(--muted); font-weight: 400; }

/* ---------- موبایل: تجربهٔ بومی و حرفه‌ای ---------- */
.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 59;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

@media (max-width: 720px) {
  /* سایدبار = کشوی روی صفحه؛ پیش‌فرض بسته، با دکمهٔ ☰ باز می‌شود */
  #sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0;
    z-index: 60;
    width: min(304px, 85vw); min-width: 0;
    margin: 0 !important;
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.6);
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  #sidebar.open { transform: none; }
  .chat-item { padding: 12px; font-size: 14px; }
  .chat-item .del { opacity: 1; padding: 6px; } /* بدون hover در لمس */

  /* نوار بالا: فشرده و امن نسبت به ناچ */
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 10px 8px; gap: 4px; }
  .model-picker select { font-size: 15px; max-width: 44vw; }
  .tone-btn-label { display: none; }        /* فقط آیکون 🎚️ */
  .chip-btn { padding: 8px 12px; }

  /* منوی لحن = Bottom Sheet تمام‌عرض */
  .tone-popover {
    position: fixed;
    inset-inline: 0; top: auto; bottom: 0;
    width: 100%; max-height: 72vh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    box-shadow: 0 -12px 50px rgba(0, 0, 0, 0.6);
    animation: sheet-up 0.25s ease;
  }

  /* پیام‌ها */
  #messages { padding: 8px 14px 16px; }
  .row { padding: 10px 0; gap: 10px; }
  .row .content { font-size: 15px; line-height: 2; }
  .row.user .content { max-width: 88%; padding: 9px 15px; }
  .row .avatar { width: 28px; height: 28px; min-width: 28px; font-size: 12px; }
  .empty-state h1 { font-size: 20px; padding: 0 24px; text-align: center; }
  .empty-logo { width: 48px; height: 48px; font-size: 22px; }

  /* کامپوزر: چسبیده به پایین با رعایت ناحیهٔ امن */
  .composer-wrap { padding: 0 10px calc(10px + env(safe-area-inset-bottom)); }
  .composer { padding: 8px 10px; border-radius: 24px; }
  .composer-hint { display: none; }         /* فضای بیشتر برای گفتگو */
  .icon-btn { width: 42px; height: 42px; }  /* هدف لمسی ≥ 42px */
  .send-btn { width: 40px; height: 40px; }

  /* مکالمهٔ زنده */
  .live-overlay { gap: 22px; padding: calc(20px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom)); }
  .orb-wrap { width: 160px; height: 160px; }
  .orb { width: 128px; height: 128px; }
  .live-transcript { font-size: 13.5px; padding: 0 10px; }
  .live-end { width: 66px; height: 66px; }

  /* پنل تنظیمات: تمام‌صفحه */
  .drawer {
    width: 100vw; border: none;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(20px + env(safe-area-inset-bottom));
  }
  .card { padding: 16px 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid input, .form-grid select, .form-grid textarea { font-size: 16px; } /* بدون زوم iOS */
}

@keyframes sheet-up {
  from { transform: translateY(30%); opacity: 0.5; }
  to { transform: none; opacity: 1; }
}

/* دسکتاپ: برچسب دکمهٔ لحن نمایش داده شود */
@media (min-width: 721px) {
  .sidebar-backdrop { display: none !important; }
}
