/* AI Chat Assistant - Frontend Styles */
.aic-widget {
  --aic-radius: 16px;
  --aic-shadow: 0 10px 40px rgba(0,0,0,.15);
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  direction: rtl;
  box-sizing: border-box;
  z-index: 99999;
}

.aic-widget *,
.aic-widget *::before,
.aic-widget *::after {
  box-sizing: border-box;
}

/* Popup mode */
.aic-mode-popup {
  position: fixed;
  bottom: 24px;
  left: 24px; /* RTL: bottom-left */
}

.aic-mode-popup .aic-toggle-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--aic-primary, #7c3aed), var(--aic-secondary, #2563eb));
  color: #fff;
  cursor: pointer;
  box-shadow: var(--aic-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .25s ease, box-shadow .25s ease;
}

.aic-mode-popup .aic-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 48px rgba(124, 58, 237, .4);
}

.aic-mode-popup .aic-panel {
  position: absolute;
  bottom: 72px;
  left: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: var(--aic-radius);
  box-shadow: var(--aic-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: aicSlideUp .3s ease;
}

@keyframes aicSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Full page mode */
.aic-mode-page {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  min-height: 70vh;
}

.aic-mode-page .aic-panel {
  display: flex !important;
  flex-direction: column;
  height: 75vh;
  min-height: 500px;
  background: #fff;
  border-radius: var(--aic-radius);
  box-shadow: var(--aic-shadow);
  overflow: hidden;
}

/* Header */
.aic-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--aic-primary, #7c3aed), var(--aic-secondary, #2563eb));
  color: #fff;
  flex-shrink: 0;
}

.aic-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 1rem;
}

.aic-header-actions {
  display: flex;
  gap: 6px;
}

.aic-btn-icon {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
}

.aic-btn-icon:hover {
  background: rgba(255,255,255,.3);
}

/* Messages */
.aic-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}

.aic-welcome {
  text-align: center;
  color: #64748b;
  padding: 24px 12px;
  font-size: .95rem;
}

.aic-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: .92rem;
  line-height: 1.6;
  word-wrap: break-word;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.aic-bubble.user {
  align-self: flex-start; /* RTL: user on right side visually? In RTL flex-start is right */
  background: linear-gradient(135deg, var(--aic-primary, #7c3aed), var(--aic-secondary, #2563eb));
  color: #fff;
  border-bottom-right-radius: 4px;
}

.aic-bubble.assistant,
.aic-bubble.admin {
  align-self: flex-end;
  background: #fff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.aic-bubble.admin {
  border-color: #f59e0b;
  background: #fffbeb;
}

.aic-bubble img {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 6px;
}

.aic-bubble audio {
  width: 100%;
  margin-top: 6px;
}

.aic-bubble .aic-time {
  display: block;
  font-size: .7rem;
  opacity: .7;
  margin-top: 4px;
}

/* Typing indicator */
.aic-typing {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #64748b;
  font-size: .85rem;
}

.aic-typing span {
  width: 7px;
  height: 7px;
  background: var(--aic-primary, #7c3aed);
  border-radius: 50%;
  animation: aicBounce 1.2s infinite ease-in-out;
}

.aic-typing span:nth-child(2) { animation-delay: .2s; }
.aic-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes aicBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input area */
.aic-input-area {
  border-top: 1px solid #e2e8f0;
  padding: 10px 12px;
  background: #fff;
  flex-shrink: 0;
}

.aic-toolbar {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}

.aic-toolbar .aic-btn-icon {
  background: #f1f5f9;
  color: #475569;
}

.aic-toolbar .aic-btn-icon:hover {
  background: #e2e8f0;
}

.aic-toolbar .aic-btn-icon.recording {
  background: #ef4444;
  color: #fff;
  animation: aicPulse 1s infinite;
}

@keyframes aicPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .6; }
}

.aic-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.aic-textarea {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: .92rem;
  resize: none;
  max-height: 120px;
  outline: none;
  transition: border-color .2s;
  direction: rtl;
}

.aic-textarea:focus {
  border-color: var(--aic-primary, #7c3aed);
}

.aic-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--aic-primary, #7c3aed), var(--aic-secondary, #2563eb));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, opacity .2s;
  flex-shrink: 0;
}

.aic-send-btn:hover {
  transform: scale(1.05);
}

.aic-send-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

.aic-recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  color: #ef4444;
  font-size: .85rem;
}

.aic-rec-dot {
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: 50%;
  animation: aicPulse 1s infinite;
}

.aic-stop-record {
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: .8rem;
}

/* Privacy banner */
.aic-privacy-banner {
  background: #fef3c7;
  padding: 10px 14px;
  font-size: .82rem;
  color: #92400e;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.aic-privacy-banner p {
  margin: 0;
  flex: 1;
}

.aic-privacy-accept {
  background: #f59e0b;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: .8rem;
  white-space: nowrap;
}

/* Dark mode */
.aic-widget.aic-dark .aic-panel {
  background: #0f172a;
}

.aic-widget.aic-dark .aic-messages {
  background: #1e293b;
}

.aic-widget.aic-dark .aic-welcome {
  color: #94a3b8;
}

.aic-widget.aic-dark .aic-bubble.assistant,
.aic-widget.aic-dark .aic-bubble.admin {
  background: #334155;
  color: #e2e8f0;
  border-color: #475569;
}

.aic-widget.aic-dark .aic-bubble.admin {
  background: #422006;
  border-color: #b45309;
}

.aic-widget.aic-dark .aic-input-area {
  background: #0f172a;
  border-color: #334155;
}

.aic-widget.aic-dark .aic-textarea {
  background: #1e293b;
  border-color: #475569;
  color: #e2e8f0;
}

.aic-widget.aic-dark .aic-toolbar .aic-btn-icon {
  background: #334155;
  color: #cbd5e1;
}

.aic-widget.aic-dark .aic-typing {
  color: #94a3b8;
}

/* Responsive */
@media (max-width: 480px) {
  .aic-mode-popup {
    bottom: 16px;
    left: 16px;
  }
  .aic-mode-popup .aic-panel {
    width: calc(100vw - 32px);
    height: calc(100vh - 100px);
    bottom: 68px;
  }
}

/* Fullwidth shortcode mode */
.aic-widget.aic-fullwidth,
.aic-widget.aic-fullwidth .aic-panel {
  max-width: 100% !important;
  width: 100% !important;
  margin: 0;
  border-radius: 0;
}
.aic-mode-page.aic-fullwidth {
  max-width: 100%;
}
.aic-help-box {
  background: #f0f6fc;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid #c3d4e6;
}


/* Profile gate */
.aic-profile-form {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #f8fafc;
  overflow-y: auto;
}
.aic-profile-inner {
  width: 100%;
  max-width: 320px;
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,.06);
}
.aic-profile-inner h3 {
  margin: 0 0 6px;
  font-size: 1.1rem;
  color: #1e293b;
}
.aic-profile-desc {
  margin: 0 0 14px;
  font-size: .85rem;
  color: #64748b;
}
.aic-profile-inner label {
  display: block;
  font-size: .8rem;
  color: #475569;
  margin-bottom: 10px;
}
.aic-profile-inner input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-family: inherit;
  font-size: .92rem;
  direction: rtl;
}
.aic-profile-inner input:focus {
  outline: none;
  border-color: var(--aic-primary, #7c3aed);
}
.aic-profile-submit {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--aic-primary, #7c3aed), var(--aic-secondary, #2563eb));
  color: #fff;
  font-family: inherit;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
}
.aic-profile-submit:hover {
  opacity: .95;
}
.aic-widget.aic-dark .aic-profile-form {
  background: #1e293b;
}
.aic-widget.aic-dark .aic-profile-inner {
  background: #0f172a;
}
.aic-widget.aic-dark .aic-profile-inner h3 {
  color: #e2e8f0;
}
.aic-widget.aic-dark .aic-profile-inner input {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

/* Popup position */
.aic-mode-popup.aic-pos-right {
  left: auto;
  right: 24px;
}
.aic-mode-popup.aic-pos-right .aic-panel {
  left: auto;
  right: 0;
}

/* Topics panel */
.aic-topics-panel {
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  max-height: 180px;
  overflow-y: auto;
  flex-shrink: 0;
}
.aic-topics-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  font-size: .85rem;
}
.aic-topics-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px;
}
.aic-topic-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .85rem;
  margin-bottom: 4px;
  background: #fff;
  border: 1px solid #e2e8f0;
}
.aic-topic-item.active {
  border-color: var(--aic-primary, #7c3aed);
  background: #f5f3ff;
}
.aic-topic-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aic-topic-del {
  border: none;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.aic-topic-del:hover {
  color: #ef4444;
}

/* Bubble actions */
.aic-bubble-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.aic-copy-btn {
  border: none;
  background: rgba(0,0,0,.06);
  color: inherit;
  font-size: .72rem;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
.aic-bubble.assistant .aic-copy-btn,
.aic-bubble.admin .aic-copy-btn {
  background: #f1f5f9;
  color: #475569;
}
.aic-copy-btn:hover {
  opacity: .85;
}
.aic-provider-tag {
  font-size: .68rem;
  opacity: .6;
}

/* Copyright footer */
.aic-copyright {
  text-align: center;
  font-size: .7rem;
  color: #94a3b8;
  padding: 4px 0 0;
}

/* Dark topics */
.aic-widget.aic-dark .aic-topics-panel {
  background: #0f172a;
  border-color: #334155;
}
.aic-widget.aic-dark .aic-topic-item {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}
.aic-widget.aic-dark .aic-topic-item.active {
  border-color: var(--aic-primary, #7c3aed);
  background: #312e81;
}
.aic-widget.aic-dark .aic-bubble.assistant .aic-copy-btn {
  background: #475569;
  color: #e2e8f0;
}

@media (max-width: 480px) {
  .aic-mode-popup.aic-pos-right {
    right: 16px;
    left: auto;
  }
}

.aic-prof-code-hint {
  font-size: .75rem;
  color: #64748b;
  margin: -4px 0 10px;
}
.aic-recovery-box {
  margin-top: 12px;
  padding: 14px;
  border-radius: 12px;
  background: #ecfdf5;
  border: 1px solid #6ee7b7;
  text-align: center;
}
.aic-recovery-box code {
  font-size: 1.4rem;
  letter-spacing: .2em;
  color: #065f46;
  font-weight: 700;
}
.aic-recovery-warn {
  font-size: .8rem;
  color: #b45309;
}
.aic-download-code,
.aic-share-code,
.aic-recovery-continue {
  display: block;
  width: 100%;
  margin: 6px 0;
  padding: 10px;
  border-radius: 10px;
  border: none;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
}
.aic-download-code {
  background: #059669;
  color: #fff;
}
.aic-share-code {
  background: #2563eb;
  color: #fff;
}
.aic-recovery-continue {
  background: #1e293b;
  color: #fff;
}
.aic-custom-file-link {
  display: inline-block;
  margin: 8px 0;
  font-size: .85rem;
}
.aic-widget.aic-dark .aic-recovery-box {
  background: #064e3b;
  border-color: #059669;
}
