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

:root {
  --bg: #090a0f;
  --surface: #12141d;
  --surface-2: #1a1d2b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --insta-gradient: linear-gradient(135deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
  --accent: #e6683c;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.1);
  --success: #22c55e;
  --danger: #ef4444;
}

[hidden] {
  display: none !important;
}

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

body.chat-page {
  font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  direction: rtl;
  overflow-x: hidden;
}

.chat-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 80px;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(18, 20, 29, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.chat-header-main {
  display: flex;
  align-items: center;
  gap: 16px;
}

.chat-back {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  transition: color 0.2s;
}

.chat-back:hover {
  color: #fff;
}

.header-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(230, 104, 60, 0.15);
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 2px;
}

.chat-header h1 {
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
}

.chat-header p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* 📊 Top Step Progress Bar 📊 */
.wizard-progress-container {
  max-width: 800px;
  margin: 24px auto 16px;
  padding: 0 20px;
  width: 100%;
}

.wizard-progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
}

.wizard-progress-fill {
  height: 100%;
  width: 25%;
  background: var(--insta-gradient);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.wizard-steps-indicators {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.wizard-step-dot {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  transition: color 0.3s;
}

.wizard-step-dot.active {
  color: #fff;
  font-weight: 700;
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  transition: all 0.3s ease;
}

.wizard-step-dot.active .step-num {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(230, 104, 60, 0.4);
}

/* Wizard Cards & Panels */
.wizard-card-wrapper {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

.wizard-step-panel {
  display: none;
  animation: fadeInSlide 0.35s ease forwards;
}

.wizard-step-panel.active {
  display: block;
}

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

.step-card-center {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px;
  text-align: center;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
  max-width: 580px;
  margin: 20px auto;
}

.step-card-wide {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
  margin-top: 10px;
}

.step-icon-badge {
  font-size: 2.4rem;
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-card-center h2, .step-panel-header h2 {
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 8px;
}

.step-card-center p, .step-panel-header p {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.optional-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Step 1 Input */
.insta-input-wrapper-lg {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  margin: 24px 0;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.insta-input-wrapper-lg:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(230, 104, 60, 0.2);
}

.insta-prefix-lg {
  padding: 0 16px;
  color: var(--text-muted);
  font-family: monospace;
  font-size: 1.05rem;
  background: rgba(255, 255, 255, 0.04);
  border-left: 1px solid var(--border);
  user-select: none;
}

.insta-input-wrapper-lg input {
  flex: 1;
  border: none !important;
  background: transparent !important;
  padding: 16px !important;
  font-size: 1.1rem !important;
  color: #fff !important;
  outline: none !important;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--insta-gradient);
  color: #fff;
  box-shadow: 0 4px 16px rgba(220, 39, 67, 0.35);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-outline {
  background: var(--surface-2);
  color: #fff;
  border: 1px solid var(--border);
}

.btn-outline:hover {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
}

.btn-next-step {
  width: 100%;
  padding: 16px;
  font-size: 1.05rem;
  border-radius: 14px;
}

/* Step 2 Template Selection Grid */
.template-grid-lg {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.template-card-lg {
  position: relative;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  display: flex;
  flex-direction: column;
}

.template-card-lg:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
  background: rgba(99, 102, 241, 0.08);
}

.template-card-lg.active {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.12);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.35);
}

.template-preview-wrap {
  width: 100%;
  height: 135px;
  background: #1e293b;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.template-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform 0.3s ease;
}

.template-card-lg:hover .template-preview-img {
  transform: scale(1.06);
}

.template-card-content {
  padding: 14px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.template-coin-tag {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 6px;
  width: fit-content;
}

.template-coin-tag.premium {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.template-coin-tag.free {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.template-check {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #6366f1;
  color: #fff;
  font-size: 0.85rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.6);
  transition: all 0.2s ease;
  z-index: 5;
}

.template-card-lg.active .template-check {
  opacity: 1;
  transform: scale(1);
}

.template-icon {
  font-size: 1.8rem;
  margin-bottom: 8px;
}

.template-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.template-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Fixed Bottom Footer for Step 2 */
.fixed-bottom-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(18, 20, 29, 0.9);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  justify-content: center;
  z-index: 100;
}

.btn-footer-action {
  width: 100%;
  max-width: 480px;
  padding: 14px 24px;
  font-size: 1.05rem;
  font-weight: 800;
}

/* Step 3 Textarea */
.custom-prompt-wrapper {
  margin: 20px 0;
}

.custom-prompt-wrapper textarea {
  width: 100%;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
  outline: none;
  resize: vertical;
  transition: border-color 0.2s;
}

.custom-prompt-wrapper textarea:focus {
  border-color: var(--accent);
}

.step-actions-row {
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.margin-top-lg {
  margin-top: 24px;
}

/* Step 4 Image Upload Cards */
.images-upload-container {
  margin-top: 20px;
}

.images-add-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.upload-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.uploaded-images-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-images-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 24px 0;
}

.uploaded-image-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  flex-wrap: wrap;
}

.image-preview-thumb {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  object-fit: cover;
  background: #000;
}

.image-meta-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

.image-meta-fields input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: #fff;
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.image-size-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
  direction: ltr;
  text-align: right;
}

.btn-remove-image {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-remove-image:hover {
  background: rgba(239, 68, 68, 0.3);
}

.btn-build-final {
  padding: 14px 28px;
  font-size: 1.05rem;
}

/* Status / Loading Overlay */
.insta-status-card {
  text-align: center;
  padding: 40px 20px;
  background: var(--surface);
  border-radius: 20px;
  border: 1px solid var(--border);
  margin-top: 20px;
}

.status-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(230, 104, 60, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 0.9s linear infinite;
}

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

.insta-status-card h3 {
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 8px;
}

.insta-status-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.status-steps {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-step {
  font-size: 0.78rem;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.status-step.active {
  background: rgba(230, 104, 60, 0.2);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* AI Stream Container & Progress Bar */
.ai-stream-container {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 20px;
  margin: 20px 0;
  text-align: right;
  direction: rtl;
}

.ai-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main, #f8fafc);
}

.ai-progress-percent {
  font-size: 1.1rem;
  font-weight: 900;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.1);
  padding: 2px 10px;
  border-radius: 8px;
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.ai-progress-bar-wrap {
  width: 100%;
  height: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.ai-progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f59e0b, #ec4899, #6366f1);
  border-radius: 999px;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
}

.ai-stream-stats {
  font-size: 0.82rem;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-live-preview-wrap {
  background: #090d16;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  overflow: hidden;
}

.ai-live-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  padding: 8px 14px;
  font-size: 0.78rem;
  color: #94a3b8;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ai-live-preview-code {
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  color: #34d399;
  background: transparent;
  padding: 12px;
  max-height: 120px;
  overflow-y: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  direction: ltr;
  text-align: left;
}

/* Result Card */
.insta-result-card {
  background: var(--surface);
  border-radius: 20px;
  border: 1px solid var(--border);
  padding: 24px;
  margin-top: 20px;
}

.result-header {
  text-align: center;
  margin-bottom: 24px;
}

.result-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.18);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: var(--success);
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.result-details {
  background: var(--surface-2);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-info-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.result-info-item code {
  background: rgba(0, 0, 0, 0.4);
  padding: 4px 10px;
  border-radius: 6px;
  color: #60a5fa;
  font-family: monospace;
  direction: ltr;
}

.result-info-item a {
  color: var(--accent);
  text-decoration: none;
  direction: ltr;
  word-break: break-all;
  font-weight: 600;
}

.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.iframe-preview-wrapper {
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: #000;
}

.iframe-bar {
  background: var(--surface-2);
  padding: 10px 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.iframe-preview-wrapper iframe {
  width: 100%;
  height: 520px;
  border: none;
  background: #fff;
}

/* Modal Confirmation */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
  animation: fadeIn 0.2s ease;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.modal-icon {
  font-size: 2.2rem;
  margin-bottom: 12px;
}

.modal-card h3 {
  font-size: 1.25rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 8px;
}

.modal-card p {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.modal-card strong {
  color: var(--accent);
  direction: ltr;
  display: inline-block;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 85px;
  right: 20px;
  left: 20px;
  max-width: 450px;
  margin: 0 auto;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 14px 22px;
  border-radius: 14px;
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  z-index: 999999;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  direction: rtl;
  text-align: right;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.toast.success {
  border-color: #22c55e;
  background: rgba(16, 185, 129, 0.95);
  color: #ffffff;
}

.toast.danger {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.95);
  color: #ffffff;
}
