@import url("https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap");

:root {
  color-scheme: light;
  --black: #111111;
  --ink: #242424;
  --muted: #6f6f6f;
  --line: #dedede;
  --paper: #f3f3f3;
  --surface: #ffffff;
  --soft: #f7f7f7;
  --brand-red: #ce0b26;
  --brand-red-dark: #82071a;
  --success: #459647;
  --danger-soft: #fff1f2;
  font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  direction: rtl;
  background: var(--paper);
}

body::before {
  display: none;
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
textarea:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(206, 11, 38, 0.3);
  outline-offset: 2px;
}

.chat-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(860px, calc(100% - 32px));
  height: calc(100dvh - 32px);
  min-height: 560px;
  margin: 16px auto;
  overflow: hidden;
  direction: rtl;
  text-align: right;
  background: var(--surface);
  border: 1px solid #d6d6d6;
  border-radius: 8px;
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.08);
}

.utility-bar {
  display: none;
  min-height: 36px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 26px;
  color: #fff;
  background: var(--black);
  font-size: 0.72rem;
  font-weight: 600;
}

.utility-bar span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.utility-bar i {
  width: 7px;
  height: 7px;
  background: var(--brand-red);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(206, 11, 38, 0.22);
}

.topbar {
  position: relative;
  display: flex;
  min-height: 72px;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  color: var(--ink);
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.topbar::after {
  position: absolute;
  right: 0;
  bottom: -1px;
  width: 200px;
  height: 2px;
  content: "";
  background: var(--brand-red);
}

.brand-lockup {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0;
}

.brand-mark {
  display: grid;
  flex: 0 0 58px;
  width: 58px;
  height: 52px;
  place-items: center;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-wordmark {
  display: grid;
  min-width: 72px;
  color: var(--black);
  direction: ltr;
  line-height: 0.82;
  text-align: left;
}

.brand-wordmark strong {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1.02rem;
  font-weight: 900;
  letter-spacing: -0.06em;
}

.brand-wordmark span {
  margin-top: 6px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.57rem;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.brand-copy {
  min-width: 0;
  padding-inline-start: 4px;
}

.eyebrow,
.brand-copy h1,
.presence,
.speaker,
.disclaimer {
  margin: 0;
}

.eyebrow {
  color: var(--brand-red);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-copy h1 {
  color: var(--black);
  font-size: clamp(0.98rem, 2.4vw, 1.12rem);
  font-weight: 800;
  line-height: 1.45;
}

.presence {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.71rem;
}

.presence span {
  width: 7px;
  height: 7px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(69, 150, 71, 0.13);
}

.reset-button {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 8px;
  margin-inline-start: auto;
  width: auto;
  padding: 9px 13px;
  justify-content: center;
  cursor: pointer;
  color: var(--black);
  background: #fff;
  border: 1px solid #cfcfcf;
  border-radius: 2px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  transition: 170ms ease;
}

.reset-button:hover {
  color: #fff;
  background: var(--black);
  border-color: var(--black);
}

.messages {
  min-height: 0;
  padding: 24px clamp(16px, 4vw, 34px);
  overflow-y: auto;
  scroll-behavior: smooth;
  direction: rtl;
  background: #fff;
  scrollbar-color: #b8b8b8 transparent;
  scrollbar-width: thin;
}

.messages::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-thumb {
  background: #b8b8b8;
  border: 2px solid #fff;
}

.message {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  width: fit-content;
  max-width: 78%;
  margin-right: 0;
  margin-left: 0;
  margin-bottom: 15px;
  animation: enter 220ms ease both;
}

.assistant-message {
  margin-right: auto;
  margin-left: 0;
  direction: ltr;
}

.assistant-message .bubble {
  direction: rtl;
}

.message > div:last-child {
  min-width: 0;
}

.avatar {
  display: grid;
  flex: 0 0 50px;
  width: 50px;
  height: 50px;
  place-items: center;
  padding: 3px;
  color: var(--black);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.68rem;
  font-weight: 900;
}

.avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.speaker {
  display: none;
}

.bubble {
  position: relative;
  padding: 11px 14px;
  overflow-wrap: anywhere;
  color: var(--ink);
  direction: rtl;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: none;
  font-size: 0.9rem;
  line-height: 1.9;
  text-align: right;
  unicode-bidi: plaintext;
  white-space: normal;
}

.assistant-message .bubble::before {
  display: none;
}

.bubble > :first-child {
  margin-top: 0;
}

.bubble > :last-child {
  margin-bottom: 0;
}

.bubble p,
.bubble ul,
.bubble ol,
.bubble blockquote,
.bubble pre,
.bubble .markdown-table-wrap {
  margin: 0.65em 0;
}

.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
  margin: 0.85em 0 0.4em;
  color: var(--black);
  line-height: 1.5;
}

.bubble h1 { font-size: 1.3rem; }
.bubble h2 { font-size: 1.18rem; }
.bubble h3 { font-size: 1.08rem; }
.bubble h4,
.bubble h5,
.bubble h6 { font-size: 1rem; }

.bubble ul,
.bubble ol {
  padding-inline-start: 1.45em;
}

.bubble li + li {
  margin-top: 0.25em;
}

.bubble a {
  color: var(--brand-red-dark);
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.bubble a:hover {
  color: var(--brand-red);
}

.bubble code {
  padding: 0.12em 0.38em;
  color: var(--black);
  direction: ltr;
  background: #f1f1f1;
  border: 1px solid #d8d8d8;
  border-radius: 2px;
  font: 0.86em/1.6 Consolas, "Courier New", monospace;
  unicode-bidi: isolate;
}

.bubble pre {
  max-width: 100%;
  padding: 12px;
  overflow-x: auto;
  color: #f5f5f5;
  direction: ltr;
  background: var(--black);
  border-radius: 2px;
  text-align: left;
  white-space: pre;
}

.bubble pre code {
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
}

.bubble blockquote {
  padding: 0.15em 0.9em;
  color: #555;
  border-inline-start: 4px solid var(--brand-red);
}

.bubble hr {
  margin: 0.9em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.markdown-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.bubble table {
  width: 100%;
  border-spacing: 0;
  border-collapse: collapse;
  font-size: 0.9em;
}

.bubble th,
.bubble td {
  padding: 7px 9px;
  border: 1px solid var(--line);
  text-align: start;
  vertical-align: top;
}

.bubble th {
  color: var(--black);
  background: #f1f1f1;
}

.user-message {
  flex-direction: row;
  margin-right: 0;
  margin-left: auto;
  direction: rtl;
}

.user-message .speaker {
  text-align: right;
}

.user-message .bubble {
  color: #fff;
  background: var(--black);
  border-color: var(--black);
  border-radius: 10px;
  box-shadow: none;
  white-space: pre-wrap;
}

.error-message .bubble {
  color: #731323;
  background: var(--danger-soft);
  border-color: #efbbc3;
}

.error-message .bubble::before {
  background: var(--brand-red-dark);
}

.debug-panel {
  margin-top: 8px;
  overflow: hidden;
  color: #ededed;
  direction: rtl;
  background: var(--black);
  border: 1px solid #333;
  border-radius: 2px;
}

.debug-panel summary {
  padding: 8px 11px;
  cursor: pointer;
  color: #fff;
  direction: rtl;
  font-size: 0.72rem;
  font-weight: 700;
  user-select: none;
}

.debug-entry {
  padding: 10px;
  border-top: 1px solid #3b3b3b;
}

.debug-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 10px;
  border-top: 1px solid #3b3b3b;
}

.debug-actions button {
  padding: 6px 9px;
  cursor: pointer;
  color: #fff;
  background: #252525;
  border: 1px solid #555;
  border-radius: 2px;
  font: 700 0.7rem inherit;
}

.debug-actions button:hover {
  background: #3a3a3a;
}

.debug-entry h3,
.debug-entry p {
  margin: 0;
  direction: rtl;
  font-family: Consolas, "Courier New", monospace;
  text-align: right;
}

.debug-entry h3 {
  margin-bottom: 9px;
  color: #ff6d7f;
  font-size: 0.72rem;
}

.debug-entry p {
  margin: 9px 0 4px;
  color: #aaa;
  font-size: 0.67rem;
  font-weight: 700;
  text-transform: uppercase;
}

.debug-entry pre {
  max-height: 280px;
  margin: 0;
  padding: 9px;
  overflow: auto;
  color: #f5f5f5;
  direction: ltr;
  background: #050505;
  border-radius: 1px;
  font: 0.7rem/1.55 Consolas, "Courier New", monospace;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 38px 20px 0;
  direction: rtl;
}

.suggestions button {
  min-height: 38px;
  padding: 7px 11px;
  cursor: pointer;
  color: var(--black);
  background: #fff;
  border: 1px solid #d6d6d6;
  border-radius: 8px;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.5;
  text-align: right;
  transition: 170ms ease;
}

.suggestions button::after {
  display: none;
}

.suggestions button:hover {
  color: var(--brand-red-dark);
  background: #fff7f8;
  border-color: #e6aeb6;
}

.suggestions button:hover::after {
  color: #fff;
}

.thinking {
  min-width: min(215px, calc(100vw - 105px));
}

.thinking-header {
  display: flex;
  min-height: 28px;
  align-items: center;
  gap: 10px;
  color: var(--black);
  font-size: 0.86rem;
  font-weight: 700;
}

.activity-spinner {
  display: inline-block;
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(206, 11, 38, 0.18);
  border-top-color: var(--brand-red);
  border-radius: 50%;
  animation: activity-spin 1.6s linear infinite;
  will-change: transform;
}

.thinking-failed .thinking-label {
  color: var(--brand-red-dark);
}

.composer-wrap {
  padding: 12px clamp(14px, 4vw, 28px) 13px;
  background: #fff;
  border-top: 1px solid var(--line);
}

.composer {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 5px 6px 5px 12px;
  background: #fff;
  border: 1px solid #d3d3d3;
  border-radius: 11px;
  box-shadow: none;
  transition: 170ms ease;
}

.composer:focus-within {
  border-color: var(--brand-red);
  box-shadow: 0 0 0 2px rgba(206, 11, 38, 0.08);
}

textarea {
  width: 100%;
  max-height: 140px;
  padding: 9px 6px;
  resize: none;
  color: var(--ink);
  direction: rtl;
  background: transparent;
  border: 0;
  outline: 0;
  line-height: 1.75;
  text-align: right;
  unicode-bidi: plaintext;
}

textarea::placeholder {
  color: #8b8b8b;
}

.send-button {
  place-self: center;
  display: grid;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  cursor: pointer;
  place-items: center;
  color: #fff;
  background: var(--brand-red);
  border: 1px solid var(--brand-red);
  border-radius: 8px;
  transition: 170ms ease;
}

.send-button:hover:not(:disabled) {
  background: var(--brand-red-dark);
  border-color: var(--brand-red-dark);
}

.send-button:disabled {
  cursor: wait;
  opacity: 0.5;
}

.send-button i {
  font-size: 1.05rem;
  transform: scaleX(-1);
}

.disclaimer {
  margin-top: 8px;
  color: #777;
  font-size: 0.68rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.embedded body {
  min-width: 0;
  background: #fff;
}

.embedded body::before,
.embedded .utility-bar {
  display: none;
}

.embedded .chat-shell {
  width: 100%;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.embedded .topbar {
  min-height: 68px;
  padding: 9px 13px;
}

.embedded .brand-wordmark {
  display: none;
}

.embedded .brand-copy {
  padding-inline-start: 4px;
}

.embedded .brand-copy h1 {
  font-size: 1rem;
}

.embedded .reset-button {
  padding: 8px 10px;
  font-size: 0.72rem;
}

.embedded .messages {
  min-height: 0;
  padding: 18px 13px;
}

.embedded .message {
  max-width: 93%;
}

.embedded .suggestions {
  margin-right: 0;
}

.embedded .composer-wrap {
  padding: 11px 12px max(12px, env(safe-area-inset-bottom));
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@keyframes activity-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 760px) {
  .brand-wordmark {
    display: none;
  }

}

@media (max-width: 640px) {
  body {
    background: #fff;
  }

  body::before,
  .utility-bar {
    display: none;
  }

  .chat-shell {
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .topbar {
    min-height: 68px;
    gap: 9px;
    padding: 8px 12px;
  }

  .topbar::after {
    width: 38px;
  }

  .brand-mark {
    flex-basis: 52px;
    width: 52px;
    height: 46px;
  }

  .brand-mark img {
    width: 100%;
    height: 100%;
  }

  .brand-copy {
    padding-inline-start: 3px;
  }

  .eyebrow {
    display: none;
  }

  .brand-copy h1 {
    font-size: 0.98rem;
  }

  .reset-button {
    padding: 8px 9px;
    font-size: 0.7rem;
  }

  .messages {
    min-height: 0;
    padding: 18px 12px;
    background: #fff;
  }

  .message {
    max-width: 92%;
  }

  .bubble {
    padding: 10px 12px;
    font-size: 0.88rem;
  }

  .suggestions {
    margin-right: 0;
  }

  .composer-wrap {
    padding: 11px 12px max(12px, env(safe-area-inset-bottom));
  }

  .disclaimer {
    line-height: 1.6;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
