/* ══════════════════════════════════════════════════════════════════
   SHARED COMPONENTS
══════════════════════════════════════════════════════════════════ */

.ai-badge {
  font-size: 0.6rem;
  font-weight: 700;
  background: var(--green);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.ai-panel-header,
.ai-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-1);
  background: var(--surface-2);
  flex-shrink: 0;
}

.ai-panel-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-1);
}

.ai-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: color 0.15s, background 0.15s;
}
.ai-icon-btn:hover {
  color: var(--text-1);
  background: var(--border-1);
}

/* Messages area */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

/* Empty / welcome state */
.ai-empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-2);
  font-size: 0.9rem;
  line-height: 1.6;
}
.ai-empty p { margin: 0 0 6px; }
.ai-empty-icon {
  width: 52px;
  height: 52px;
  background: var(--surface-2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  color: var(--green);
}
.ai-empty-sub {
  font-size: 0.82rem;
  color: var(--text-3);
}

/* Message bubbles */
.ai-msg {
  max-width: 86%;
  font-size: 0.875rem;
  line-height: 1.65;
  padding: 10px 14px;
  border-radius: 14px;
  word-break: break-word;
}
.ai-msg--user {
  align-self: flex-end;
  background: var(--surface-2);
  color: var(--text-1);
  border-radius: 14px 14px 4px 14px;
}
.ai-msg--model {
  align-self: flex-start;
  background: var(--bg);
  color: var(--text-1);
  border: 1px solid var(--border-1);
  border-left: 3px solid var(--green);
  border-radius: 4px 14px 14px 14px;
}

/* Tool buttons inside AI messages */
.ai-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  margin-right: 8px;
  padding: 8px 16px;
  background: transparent;
  border: 1.5px solid var(--green);
  color: var(--green);
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}
.ai-tool-btn:hover {
  background: var(--green);
  color: #fff;
}

/* Numbered steps */
.ai-step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 6px 0;
}
.ai-step-num {
  width: 22px;
  height: 22px;
  background: var(--green);
  color: #fff;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

/* Inline links */
.ai-inline-link {
  color: var(--green);
  text-decoration: underline;
}

/* Typing indicator */
.ai-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border-1);
  border-left: 3px solid var(--green);
  border-radius: 4px 14px 14px 14px;
  align-self: flex-start;
}
.ai-typing span {
  width: 7px;
  height: 7px;
  background: var(--text-3);
  border-radius: 50%;
  animation: ai-bounce 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40%            { transform: translateY(-5px); opacity: 1; }
}

/* Quick-start chips */
.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 14px 10px;
  flex-shrink: 0;
}
.ai-chips--modal {
  padding: 0 20px 14px;
}
.ai-chip {
  font-size: 0.77rem;
  padding: 6px 12px;
  border: 1px solid var(--border-1);
  background: var(--surface-2);
  color: var(--text-2);
  border-radius: 20px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.ai-chip:hover {
  border-color: var(--green);
  color: var(--green);
}

/* Input row */
.ai-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-1);
  background: var(--surface-2);
  flex-shrink: 0;
}
.ai-input-row--modal {
  padding: 14px 20px;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.ai-input-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.ai-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-1);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text-1);
  outline: none;
  line-height: 1.5;
  overflow-y: auto;
  transition: border-color 0.15s;
  width: 100%;
  box-sizing: border-box;
}
.ai-textarea:focus { border-color: var(--green); }
.ai-textarea::placeholder { color: var(--text-3); }
.ai-textarea:disabled { opacity: 0.5; cursor: not-allowed; }

.ai-mic-btn {
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  color: var(--text-2);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
.ai-input-row--modal .ai-mic-btn {
  width: auto;
  padding: 0 14px;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 500;
}
.ai-mic-btn:hover { color: var(--green); border-color: var(--green); }
.ai-mic-btn.ai-mic--active {
  background: #fee2e2;
  color: #dc2626;
  border-color: #dc2626;
  animation: ai-mic-pulse 1s infinite;
}
@keyframes ai-mic-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

.ai-send-btn {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.ai-send-btn--lg {
  width: auto;
  padding: 0 20px;
  gap: 7px;
  font-size: 0.875rem;
  font-weight: 600;
  height: 38px;
}
.ai-send-btn:hover { opacity: 0.85; }
.ai-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.ai-disclaimer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-3);
  padding: 6px 14px 8px;
  margin: 0;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════════════════
   MODE 1 — SIDE WIDGET
══════════════════════════════════════════════════════════════════ */

#ai-side-widget {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9998;
}

#ai-side-trigger {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
  position: relative;
}
#ai-side-trigger:hover {
  transform: scale(1.07);
  box-shadow: 0 6px 28px rgba(0,0,0,0.24);
}
#ai-side-trigger.ai-trigger--open {
  background: var(--text-1);
}
@keyframes ai-side-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(0,0,0,0.18), 0 0 0 0 rgba(34,197,94,0.4); }
  50%       { box-shadow: 0 4px 20px rgba(0,0,0,0.18), 0 0 0 14px rgba(34,197,94,0); }
}
#ai-side-trigger.ai-trigger--pulse {
  animation: ai-side-pulse 2s ease-out 4;
}

#ai-side-panel {
  position: absolute;
  bottom: 64px;
  right: 0;
  width: 360px;
  max-height: 520px;
  background: var(--bg);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 40px rgba(0,0,0,0.16);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#ai-side-panel.ai-side-panel--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

@media (max-width: 480px) {
  #ai-side-widget { bottom: 16px; right: 16px; }
  #ai-side-panel {
    position: fixed;
    bottom: 0; right: 0; left: 0;
    width: 100%;
    max-height: 80vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: none;
  }
}

/* ══════════════════════════════════════════════════════════════════
   MODE 2 — CENTER MODAL
══════════════════════════════════════════════════════════════════ */

#ai-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  backdrop-filter: blur(2px);
}
#ai-modal-overlay.ai-modal--open {
  opacity: 1;
  pointer-events: all;
}

#ai-modal-box {
  background: var(--bg);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 580px;
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.97);
  transition: transform 0.22s ease;
}
#ai-modal-overlay.ai-modal--open #ai-modal-box {
  transform: translateY(0) scale(1);
}
#ai-modal-messages {
  min-height: 240px;
}

@media (max-width: 600px) {
  #ai-modal-overlay { padding: 0; align-items: flex-end; }
  #ai-modal-box {
    max-width: 100%;
    max-height: 88vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: none;
  }
}
