/* ══════════════════════════════════════════
   AI EDITOR — SIDEBAR & TOOLS
   ══════════════════════════════════════════ */

/* Body offset when editor is active */
body.ai-editor-active {
  margin-right: 380px !important;
  transition: margin-right 0.25s ease;
}
body.ai-editor-collapsed {
  margin-right: 48px !important;
}

/* ── Sidebar ────────────────────────────── */
#ai-editor-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100vh;
  background: #12121f;
  color: #e0e0e0;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 13px;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.6);
  transform: translateX(0);
  transition: transform 0.25s ease;
  user-select: none;
}

#ai-editor-sidebar.collapsed {
  transform: translateX(calc(100% - 48px));
}

/* ── Header ─────────────────────────────── */
.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #1a1a2e;
  border-bottom: 1px solid #2a2a44;
  flex-shrink: 0;
}

.ai-header-title {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}

.ai-header-title span {
  color: #4fc3f7;
}

.ai-toggle-btn {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.ai-toggle-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* ── Toolbar ────────────────────────────── */
.ai-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid #2a2a44;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.ai-tool-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #3a3a55;
  background: #1e1e33;
  color: #ccc;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ai-tool-btn:hover {
  background: #2a2a44;
  color: #fff;
  border-color: #4fc3f7;
}
.ai-tool-btn.active {
  background: #1a3a5c;
  color: #4fc3f7;
  border-color: #4fc3f7;
}

.ai-tool-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.ai-publish-btn {
  margin-left: auto;
  background: #1b4332;
  border-color: #2d6a4f;
  color: #95d5b2;
}
.ai-publish-btn:hover {
  background: #2d6a4f;
  color: #fff;
  border-color: #52b788;
}

.ai-new-btn {
  background: #3a1a1a;
  border-color: #6a2a2a;
  color: #e0a0a0;
}
.ai-new-btn:hover {
  background: #5a2a2a;
  color: #fff;
}

/* ── Context bar ────────────────────────── */
.ai-context-bar {
  padding: 8px 16px;
  background: #1a2a3a;
  border-bottom: 1px solid #2a2a44;
  font-size: 11px;
  color: #4fc3f7;
  display: none;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
}
.ai-context-bar.visible {
  display: flex;
}
.ai-context-bar code {
  background: rgba(79, 195, 247, 0.15);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
}
.ai-context-clear {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 14px;
  margin-left: auto;
  padding: 0 4px;
}
.ai-context-clear:hover {
  color: #fff;
}

/* ── Chat area ──────────────────────────── */
.ai-chat {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: #3a3a55 transparent;
}
.ai-chat::-webkit-scrollbar {
  width: 6px;
}
.ai-chat::-webkit-scrollbar-thumb {
  background: #3a3a55;
  border-radius: 3px;
}

/* Messages */
.ai-msg {
  padding: 10px 12px;
  border-radius: 10px;
  line-height: 1.45;
  word-break: break-word;
  max-width: 100%;
}
.ai-msg-user {
  background: #2a2a50;
  border-bottom-right-radius: 3px;
  align-self: flex-end;
}
.ai-msg-ai {
  background: #1a2e3e;
  border-bottom-left-radius: 3px;
  align-self: flex-start;
}
.ai-msg-error {
  background: #3a1a1a;
  color: #ff8a8a;
  border-bottom-left-radius: 3px;
  align-self: flex-start;
}

.ai-msg-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  opacity: 0.6;
}

/* Thinking indicator */
.ai-thinking {
  display: flex;
  gap: 6px;
  padding: 12px;
  align-self: flex-start;
}
.ai-thinking span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4fc3f7;
  animation: ai-pulse 1.2s ease-in-out infinite;
}
.ai-thinking span:nth-child(2) { animation-delay: 0.2s; }
.ai-thinking span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-pulse {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

/* ── Input area ─────────────────────────── */
.ai-input-area {
  padding: 12px 16px;
  border-top: 1px solid #2a2a44;
  background: #1a1a2e;
  flex-shrink: 0;
  display: flex;
  gap: 8px;
}

.ai-input {
  flex: 1;
  background: #0e0e1a;
  border: 1px solid #3a3a55;
  border-radius: 8px;
  color: #e0e0e0;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s;
}
.ai-input:focus {
  border-color: #4fc3f7;
}
.ai-input::placeholder {
  color: #555;
}

.ai-send-btn {
  background: #4fc3f7;
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
  flex-shrink: 0;
}
.ai-send-btn:hover {
  background: #81d4fa;
}
.ai-send-btn:disabled {
  background: #2a3a4a;
  color: #555;
  cursor: not-allowed;
}

/* ── Element picker highlight ───────────── */
.ai-picker-hover {
  outline: 2px solid #4fc3f7 !important;
  outline-offset: 2px !important;
}

.ai-picker-selected {
  outline: 3px solid #ff065f !important;
  outline-offset: 2px !important;
  background: rgba(255, 6, 95, 0.06) !important;
}

/* ── Zone selection rectangle ───────────── */
#ai-zone-rect {
  position: fixed;
  border: 2px dashed #c1e945;
  background: rgba(193, 233, 69, 0.08);
  pointer-events: none;
  z-index: 999998;
}

/* ── Overlay for picker/zone mode ───────── */
#ai-overlay {
  position: fixed;
  inset: 0;
  z-index: 999997;
  cursor: crosshair;
}

/* ── Welcome message ────────────────────── */
.ai-welcome {
  text-align: center;
  padding: 24px 16px;
  color: #666;
  font-size: 12px;
  line-height: 1.6;
}
.ai-welcome strong {
  color: #4fc3f7;
  font-size: 14px;
}

/* ── Inline editor ─────────────────────── */
.ai-editable {
  position: relative;
  cursor: pointer;
  transition: outline 0.15s, background 0.15s;
  border-radius: 4px;
}
.ai-editable:hover {
  outline: 2px dashed #4fc3f7 !important;
  outline-offset: 3px !important;
  background: rgba(79, 195, 247, 0.06) !important;
}

.ai-editing {
  outline: 2px solid #4fc3f7 !important;
  outline-offset: 3px !important;
  background: rgba(79, 195, 247, 0.08) !important;
  min-height: 1.2em;
}

.ai-edit-btn.active {
  background: #1a3a5c;
  color: #4fc3f7;
  border-color: #4fc3f7;
}

/* Save bar — floating at bottom */
.ai-save-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(calc(-50% - 190px));
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1a1a2e;
  border: 1px solid #3a3a55;
  border-radius: 12px;
  padding: 10px 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  z-index: 999996;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 13px;
  animation: ai-save-bar-in 0.2s ease;
}
@keyframes ai-save-bar-in {
  from { opacity: 0; transform: translateX(calc(-50% - 190px)) translateY(12px); }
  to { opacity: 1; transform: translateX(calc(-50% - 190px)) translateY(0); }
}

.ai-save-btn {
  background: #2d6a4f;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}
.ai-save-btn:hover {
  background: #40916c;
}

.ai-cancel-btn {
  background: #3a1a1a;
  color: #e0a0a0;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  transition: background 0.15s;
}
.ai-cancel-btn:hover {
  background: #5a2a2a;
  color: #fff;
}

.ai-save-hint {
  color: #666;
  font-size: 11px;
  margin-left: 4px;
}

/* Toast notification */
.ai-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(calc(-50% - 190px)) translateY(12px);
  background: #2d6a4f;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 999996;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.ai-toast.visible {
  opacity: 1;
  transform: translateX(calc(-50% - 190px)) translateY(0);
}
.ai-toast-error {
  background: #6a2a2a;
  color: #ff8a8a;
}

/* ── Responsive: on narrow screens ──────── */
@media (max-width: 768px) {
  #ai-editor-sidebar {
    width: 100vw;
  }
  body.ai-editor-active {
    margin-right: 0 !important;
  }
  #ai-editor-sidebar.collapsed {
    transform: translateX(calc(100% - 48px));
  }
}
