/* ==========================================================================
   دستیار هوش مصنوعی — استایل مستقل صفحه
   ========================================================================== */

:root {
  --bg: #F7F4EE;
  --panel: #FFFFFF;
  --panel-soft: #FBF9F5;
  --border: #E7E1D6;
  --text: #2B2A27;
  --text-soft: #6E6A62;
  --text-faint: #9A958A;
  --accent: #DA7756;
  --accent-dark: #C15F3C;
  --accent-soft: #F3E2D9;
  --user-bubble: #EFE7DC;
  --error: #B3432D;
  --error-bg: #FBEAE5;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(43, 42, 39, 0.06);
  --shadow-md: 0 6px 24px rgba(43, 42, 39, 0.08);
  --font-body: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
}

/* ───────────── هدر ───────────── */

#app-header {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

#app-header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

#brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  position: relative;
  flex: 0 0 auto;
}
#brand-mark::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.9;
}

#brand-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

#new-chat-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
#new-chat-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ───────────── بدنهٔ چت ───────────── */

#chat-main {
  flex: 1 1 auto;
  overflow: hidden;
  position: relative;
}

#chat-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 28px 20px 12px;
}

#empty-state {
  max-width: 640px;
  margin: 6vh auto 0;
  text-align: center;
  padding: 0 12px;
}

#empty-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  border-radius: 16px;
  background: var(--accent);
  position: relative;
}
#empty-mark::before {
  content: "";
  position: absolute;
  inset: 13px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.9;
}

#empty-state h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

#empty-state p {
  color: var(--text-soft);
  font-size: 14.5px;
  margin: 0 0 26px;
}

#suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.suggestion-chip {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .1s ease;
}
.suggestion-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.suggestion-chip:active {
  transform: scale(0.98);
}

#messages {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding-bottom: 8px;
}

.msg-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.msg-row.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.msg-row.bot .msg-avatar {
  background: var(--accent);
  color: #fff;
}

.msg-row.user .msg-avatar {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  color: var(--text-soft);
}

.msg-bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.85;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg-row.user .msg-bubble {
  background: var(--user-bubble);
  border-top-right-radius: 4px;
}

.msg-row.bot .msg-bubble {
  background: transparent;
  padding-inline-start: 0;
  padding-top: 5px;
  max-width: 100%;
}

.msg-bubble img.msg-image {
  max-width: 220px;
  border-radius: var(--radius-sm);
  display: block;
  margin-top: 8px;
  border: 1px solid var(--border);
}

.msg-bubble.error {
  background: var(--error-bg);
  color: var(--error);
  border-radius: var(--radius-sm);
}

.msg-row.bot .msg-bubble.pending {
  color: var(--text-faint);
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: sa-blink 1.1s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes sa-blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* ───────────── نوار ارسال پیام ───────────── */

#composer-wrap {
  flex: 0 0 auto;
  padding: 10px 20px 16px;
  background: linear-gradient(to bottom, rgba(247,244,238,0), var(--bg) 30%);
}

#composer {
  max-width: 720px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

#attachment-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 0;
}

#attachment-thumb {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

#attachment-remove {
  border: none;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-soft);
  line-height: 1;
}

#composer-form {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 8px 8px 10px;
}

#attach-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, color .15s ease;
}
#attach-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

#text-input {
  flex: 1 1 auto;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  padding: 9px 4px;
  max-height: 160px;
}
#text-input::placeholder {
  color: var(--text-faint);
}

#send-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, transform .1s ease, opacity .15s ease;
}
#send-btn:hover:not(:disabled) {
  background: var(--accent-dark);
}
#send-btn:active:not(:disabled) {
  transform: scale(0.94);
}
#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#composer-note {
  max-width: 720px;
  margin: 10px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* ───────────── واکنش‌گرا ───────────── */

@media (max-width: 640px) {
  #app-header-inner { padding: 12px 14px; }
  #brand-name { font-size: 15px; }
  #new-chat-btn span { display: none; }
  #new-chat-btn { padding: 8px; width: 34px; height: 34px; }
  #chat-scroll { padding: 20px 12px 12px; }
  .msg-bubble { max-width: 88%; font-size: 14.5px; }
  #composer-wrap { padding: 8px 10px 12px; }
  #empty-state h1 { font-size: 20px; }
}

/* حالت کاهش حرکت */
@media (prefers-reduced-motion: reduce) {
  .typing-dots span { animation: none; }
}

/* فوکوس قابل مشاهده برای دسترسی‌پذیری */
button:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
