:root {
  --ai-red: #a62626;
  --ai-red-soft: #fef2f2;
  --ai-bg: #e8edf3;
  --ai-card: #fff;
  --ai-text: #1a1a1a;
  --ai-muted: #6b7280;
  --ai-border: #e3e6ea;
  --ai-user-bg: linear-gradient(135deg, #a62626 0%, #8a1a1a 100%);
  --ai-bot-bg: #ffffff;
  --ai-sidebar-w: 220px;
  --ai-chat-bg:
    radial-gradient(ellipse 120% 70% at 100% 0%, rgba(166, 38, 38, .07) 0%, transparent 52%),
    radial-gradient(ellipse 90% 55% at 0% 100%, rgba(30, 64, 175, .05) 0%, transparent 48%),
    linear-gradient(180deg, #f4f7fb 0%, #e8edf3 55%, #e2e8f0 100%);
}

.ai-page {
  min-height: 100vh;
  background: linear-gradient(165deg, #fafafa 0%, var(--ai-bg) 45%, #e4e9ef 100%);
  font-family: Tahoma, 'Segoe UI', sans-serif;
}

.ai-shell {
  max-width: 1100px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--ai-bg);
}

.ai-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
  border: 1px solid var(--ai-border);
  border-radius: 16px;
  overflow: hidden;
  background: var(--ai-card);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .06);
  position: relative;
}

.ai-sidebar-backdrop {
  display: none;
}

.ai-mobile-topbar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #fff;
  border-bottom: 1px solid var(--ai-border);
  flex-shrink: 0;
}

.ai-mobile-topbar-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--ai-muted);
}

.ai-sidebar {
  width: var(--ai-sidebar-w);
  min-width: var(--ai-sidebar-w);
  background: #f8f9fb;
  border-left: 1px solid var(--ai-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.ai-sidebar-head {
  padding: 12px 10px;
  border-bottom: 1px solid var(--ai-border);
}

.ai-new-chat-btn {
  width: 100%;
  border: 1px dashed #d4a5a5;
  background: #fff;
  color: var(--ai-red);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .2s, border-color .2s;
}

.ai-new-chat-btn:hover {
  background: var(--ai-red-soft);
  border-color: var(--ai-red);
}

.ai-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ai-chat-list::-webkit-scrollbar { display: none; }

.ai-chat-empty {
  font-size: .72rem;
  color: var(--ai-muted);
  text-align: center;
  padding: 16px 8px;
  margin: 0;
}

.ai-chat-item {
  width: 100%;
  text-align: right;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s;
}

.ai-chat-item:hover { background: #fff; }

.ai-chat-item.active {
  background: #fff;
  border-color: #f0c4c4;
  box-shadow: 0 2px 8px rgba(166, 38, 38, .08);
}

.ai-chat-item-title {
  display: block;
  font-size: .76rem;
  font-weight: 700;
  color: var(--ai-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-chat-item-preview {
  display: block;
  font-size: .68rem;
  color: var(--ai-muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--ai-chat-bg);
}

.ai-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--ai-card);
  border-bottom: 1px solid var(--ai-border);
  flex-shrink: 0;
}

.ai-avatar,
.ai-row-avatar {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .1);
  flex-shrink: 0;
}

.ai-header .ai-avatar {
  width: 48px;
  height: 48px;
  min-width: 48px;
}

.ai-header-info h1,
.ai-header-info h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: var(--ai-text);
}

.ai-header-info p {
  margin: 2px 0 0;
  font-size: .75rem;
  color: var(--ai-muted);
}

.ai-badge {
  margin-right: auto;
  font-size: .65rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 999px;
  background: #ecfdf5;
  color: #047857;
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 12px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ai-messages::-webkit-scrollbar { display: none; }

.ai-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: aiRowIn .28s cubic-bezier(.22, 1, .36, 1) both;
}

@keyframes aiRowIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-row.user {
  flex-direction: row;
  align-self: flex-end;
  max-width: 82%;
}

.ai-row.bot {
  flex-direction: row;
  align-self: flex-start;
  max-width: 88%;
}

.ai-row-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.ai-row.user .ai-row-content { align-items: flex-start; }
.ai-row.bot .ai-row-content { align-items: flex-end; }

.ai-row-name {
  font-size: .68rem;
  font-weight: 700;
  color: var(--ai-muted);
  padding: 0 4px;
}

.ai-row-avatar-spacer {
  width: 38px;
  min-width: 38px;
  flex-shrink: 0;
}

.ai-msg {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: .88rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-row-suggestions {
  max-width: 100%;
  width: 100%;
}

.ai-row-suggestions .ai-row-content {
  flex: 1;
  max-width: calc(100% - 46px);
}

.ai-msg.user {
  background: var(--ai-user-bg);
  color: #fff;
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 14px rgba(166, 38, 38, .22);
  direction: rtl;
  text-align: right;
  animation: aiUserIn .26s cubic-bezier(.22, 1, .36, 1) both;
}

@keyframes aiUserIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: none; }
}

.ai-msg.bot {
  background: var(--ai-bot-bg);
  border: 1px solid var(--ai-border);
  color: var(--ai-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .05);
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
  animation: aiBubbleIn .34s cubic-bezier(.22, 1, .36, 1) both;
}

@keyframes aiBubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.ai-msg.ai-cursor::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-right: 2px;
  vertical-align: text-bottom;
  background: var(--ai-red);
  border-radius: 1px;
  animation: aiCaretBlink 1s ease-in-out infinite;
}

@keyframes aiCaretBlink {
  0%, 45% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.ai-typing-indicator {
  display: inline-flex;
  align-items: center;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--ai-border);
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .04);
  direction: rtl;
}

.ai-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 14px;
}

.ai-typing-dots i {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ai-red);
  opacity: .4;
  animation: aiDotPulse 1.4s cubic-bezier(.45, 0, .55, 1) infinite;
}

.ai-typing-dots i:nth-child(1) { animation-delay: 0s; }
.ai-typing-dots i:nth-child(2) { animation-delay: .2s; }
.ai-typing-dots i:nth-child(3) { animation-delay: .4s; }

@keyframes aiDotPulse {
  0%, 100% { transform: scale(.85); opacity: .35; }
  50% { transform: scale(1.15); opacity: 1; }
}

.ai-suggestions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.ai-suggestion-card {
  display: flex;
  align-items: stretch;
  gap: 0;
  width: 100%;
  text-align: right;
  border: 1px solid var(--ai-border);
  border-radius: 14px;
  padding: 0;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  overflow: hidden;
  direction: rtl;
  transition: border-color .22s, box-shadow .22s, transform .18s;
  animation: aiCardIn .38s cubic-bezier(.22, 1, .36, 1) both;
  box-shadow: 0 2px 10px rgba(15, 23, 42, .05);
}

@keyframes aiCardIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.ai-suggestion-card:hover {
  border-color: #e8b4b4;
  box-shadow: 0 8px 24px rgba(166, 38, 38, .12);
  transform: translateY(-2px);
}

.ai-suggestion-media {
  width: 108px;
  min-width: 108px;
  height: 108px;
  background: #f1f5f9;
  flex-shrink: 0;
  overflow: hidden;
}

.ai-suggestion-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .35s ease;
}

.ai-suggestion-card:hover .ai-suggestion-media img {
  transform: scale(1.06);
}

.ai-suggestion-body {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ai-suggestion-title {
  display: block;
  font-size: .82rem;
  font-weight: 800;
  color: var(--ai-text);
  line-height: 1.45;
}

.ai-suggestion-price {
  display: block;
  font-size: .78rem;
  font-weight: 800;
  color: var(--ai-red);
}

.ai-suggestion-meta {
  display: block;
  font-size: .72rem;
  color: var(--ai-muted);
}

.ai-suggestion-addr {
  display: block;
  font-size: .68rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-suggestion-addr i {
  color: var(--ai-red);
  opacity: .75;
  margin-left: 4px;
}

.ai-suggestion-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: .68rem;
  font-weight: 700;
  color: var(--ai-red);
}

.ai-suggestion-cta i {
  font-size: .62rem;
  transition: transform .2s;
}

.ai-suggestion-card:hover .ai-suggestion-cta i {
  transform: translateX(-3px);
}

.ai-starters {
  padding: 8px 12px 10px;
  flex-shrink: 0;
  border-top: 1px solid var(--ai-border);
  background: var(--ai-card);
}

.ai-starters.hidden { display: none; }

.ai-starters-title {
  font-size: .72rem;
  font-weight: 700;
  color: var(--ai-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-starters-title i { color: var(--ai-red); }

.ai-starters-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ai-starter-chip {
  text-align: right;
  border: 1px solid #ecd5d5;
  background: #fff;
  border-radius: 14px;
  padding: 11px 12px;
  font-family: inherit;
  font-size: .76rem;
  font-weight: 600;
  color: #4a2020;
  cursor: pointer;
  line-height: 1.45;
  transition: border-color .2s, box-shadow .2s, transform .15s, background .2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .04);
  direction: rtl;
}

.ai-starter-chip:hover {
  border-color: #d49090;
  background: #fffafa;
  box-shadow: 0 4px 14px rgba(166, 38, 38, .1);
  transform: translateY(-2px);
}

.ai-quick-tools {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed #e5e7eb;
}

.ai-quick-tools-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .7rem;
  font-weight: 700;
  color: var(--ai-muted);
  margin-bottom: 8px;
}

.ai-quick-tools-label i { color: var(--ai-red); }

.ai-quick-tools-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-quick-tool {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid #dbeafe;
  background: #fff;
  color: #1e3a5f;
  font-size: .68rem;
  font-weight: 700;
  text-decoration: none;
  transition: background .2s, border-color .2s, transform .15s;
}

.ai-quick-tool i {
  color: var(--ai-red);
  font-size: .72rem;
}

.ai-quick-tool:hover {
  background: #f8fafc;
  border-color: #93c5fd;
  transform: translateY(-1px);
}

.ai-inline-link {
  color: var(--ai-red);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-inline-link:hover {
  color: #7a1515;
}

.ai-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--ai-card);
  border-top: 1px solid var(--ai-border);
  flex-shrink: 0;
}

.ai-input-bar textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  font-family: inherit;
  font-size: .9rem;
  line-height: 1.5;
  background: transparent;
  direction: rtl;
  text-align: right;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ai-input-bar textarea::-webkit-scrollbar { display: none; }

.ai-send-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(145deg, #c42e2e, #8a1a1a);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 4px 12px rgba(166, 38, 38, .25);
}

.ai-send-btn:hover:not(:disabled) { transform: scale(1.04); }
.ai-send-btn:disabled { opacity: .5; cursor: not-allowed; }

.ai-login-wall {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 24px;
  background: var(--ai-bg);
}

.ai-login-wall[hidden] { display: none !important; }

.ai-login-wall i {
  font-size: 2.5rem;
  color: var(--ai-red);
  margin-bottom: 16px;
  opacity: .85;
}

.ai-login-wall h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  color: var(--ai-text);
}

.ai-login-wall p {
  margin: 0 0 20px;
  font-size: .85rem;
  color: var(--ai-muted);
  max-width: 280px;
  line-height: 1.7;
}

.ai-shell[data-ai-assistant] {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.ai-login-btn,
button.ai-login-btn {
  border: none;
  background: linear-gradient(145deg, #c42e2e, #8a1a1a);
  color: #fff;
  font-family: inherit;
  font-size: .88rem;
  font-weight: 700;
  padding: 12px 28px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(166, 38, 38, .28);
}

.ai-text-icon {
  font-size: .62rem !important;
  font-weight: 900 !important;
  letter-spacing: -.02em;
  color: #fff !important;
  background: linear-gradient(145deg, #7c3aed 0%, #a62626 55%, #7a1515 100%) !important;
}

.ai-assistant-body .ai-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-width: none;
  padding: 0;
  background: transparent;
}

.ai-assistant-body .ai-layout {
  border: none;
  border-radius: 0;
  box-shadow: none;
  height: 100%;
}

.ai-assistant-body .ai-header { display: none; }

.ai-embed .ai-shell {
  min-height: 560px;
  max-width: none;
  padding: 0;
}

.ai-embed .ai-layout { min-height: 520px; }

@media (max-width: 768px) {
  .ai-layout {
    border-radius: 0;
    border: none;
  }

  .ai-main:has(> .ai-header) .ai-header {
    display: none;
  }

  .ai-sidebar {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(268px, 82vw);
    z-index: 30;
    transform: translateX(105%);
    transition: transform .28s cubic-bezier(.22, 1, .36, 1);
    box-shadow: -6px 0 28px rgba(0, 0, 0, .18);
    border-left: 1px solid var(--ai-border);
  }

  .ai-layout.sidebar-open .ai-sidebar {
    transform: translateX(0);
  }

  .ai-sidebar-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 25;
    background: rgba(10, 10, 14, .45);
    backdrop-filter: blur(2px);
  }

  .ai-layout.sidebar-open .ai-sidebar-backdrop {
    display: block;
  }

  .ai-main {
    width: 100%;
    min-width: 0;
  }

  .ai-mobile-topbar {
    display: flex;
  }

  .ai-embed .ai-header {
    display: none;
  }

  .ai-sidebar-toggle {
    display: inline-flex !important;
  }

  .ai-messages {
    padding: 10px 8px;
  }

  .ai-starters {
    padding: 6px 8px 8px;
  }

  .ai-input-bar {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  }

  .ai-starters-list {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .ai-starter-chip {
    font-size: .72rem;
    padding: 9px 8px;
  }
}

.ai-sidebar-toggle {
  display: none;
  border: none;
  background: #f3f4f6;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  color: #444;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

@media (max-width: 520px) {
  .ai-starters-list { grid-template-columns: 1fr; }
  .ai-row.user, .ai-row.bot { max-width: 96%; }
  .ai-msg { font-size: .84rem; padding: 9px 12px; }
  .ai-row-avatar, .ai-row-avatar-spacer {
    width: 32px;
    min-width: 32px;
    height: 32px;
  }

  .ai-suggestion-media {
    width: 88px;
    min-width: 88px;
    height: 88px;
  }

  .ai-suggestion-body {
    padding: 8px 10px;
  }

  .ai-head-brand h2,
  .ai-header-info h1,
  .ai-header-info h2 {
    font-size: .85rem;
  }
}

@media (min-width: 769px) {
  .ai-sidebar {
    position: static;
    transform: none !important;
    width: 200px;
    min-width: 200px;
    box-shadow: none;
  }

  .ai-sidebar-backdrop {
    display: none !important;
  }

  .ai-mobile-topbar {
    display: none !important;
  }

  .ai-assistant-body .ai-layout,
  .ai-embed .ai-layout {
    display: flex;
    flex-direction: row;
    min-height: 0;
    height: 100%;
  }

  .ai-main {
    flex: 1 1 auto;
    min-height: 0;
    width: auto;
  }

  .ai-messages {
    flex: 1 1 auto;
    min-height: 240px;
  }

  .ai-starters-list {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 900px) {
  .ai-assistant-body .ai-messages {
    min-height: 320px;
  }
}
