/* AndCards Chatbot — Frontend Widget */

:root {
  --ac-accent:      #e63946;
  --ac-bg:          #1a1a2e;
  --ac-bg-surface:  #16213e;
  --ac-bg-message:  #0f3460;
  --ac-text:        #e0e0e0;
  --ac-text-muted:  #9a9ab0;
  --ac-bubble-size: 56px;
  --ac-radius:      14px;
  --ac-shadow:      0 8px 32px rgba(0, 0, 0, 0.5);
}

/* ── Launcher bubble ── */
#andcards-chatbot-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  width: var(--ac-bubble-size);
  height: var(--ac-bubble-size);
  border-radius: 50%;
  background: var(--ac-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--ac-shadow);
  transition: transform 0.2s ease, background 0.2s ease;
}

#andcards-chatbot-launcher:hover {
  transform: scale(1.08);
  background: #ff4d5a;
}

#andcards-chatbot-launcher svg {
  width: 26px;
  height: 26px;
  fill: #fff;
  pointer-events: none;
}

#andcards-chatbot-launcher .ac-close-icon {
  display: none;
}

#andcards-chatbot-launcher.is-open .ac-chat-icon {
  display: none;
}

#andcards-chatbot-launcher.is-open .ac-close-icon {
  display: block;
}

/* ── Chat window ── */
#andcards-chatbot-window {
  position: fixed;
  bottom: calc(var(--ac-bubble-size) + 36px);
  right: 24px;
  z-index: 99998;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: var(--ac-bg);
  border-radius: var(--ac-radius);
  box-shadow: var(--ac-shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#andcards-chatbot-window.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ── */
.ac-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--ac-bg-surface);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.ac-header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ac-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.ac-header-info {
  flex: 1;
}

.ac-header-name {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.ac-header-status {
  font-size: 11px;
  color: #4caf50;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

.ac-messages::-webkit-scrollbar {
  width: 4px;
}

.ac-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
}

.ac-message {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  word-break: break-word;
  white-space: pre-wrap;
}

.ac-message.ac-user {
  align-self: flex-end;
  background: var(--ac-accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.ac-message.ac-assistant {
  align-self: flex-start;
  background: var(--ac-bg-message);
  color: var(--ac-text);
  border-bottom-left-radius: 3px;
}

/* ── Typing indicator ── */
.ac-typing {
  align-self: flex-start;
  background: var(--ac-bg-message);
  border-radius: 12px;
  border-bottom-left-radius: 3px;
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.ac-typing span {
  width: 7px;
  height: 7px;
  background: var(--ac-text-muted);
  border-radius: 50%;
  animation: ac-bounce 1.2s infinite ease-in-out;
}

.ac-typing span:nth-child(2) { animation-delay: 0.15s; }
.ac-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ac-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Input area ── */
.ac-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 12px 14px;
  background: var(--ac-bg-surface);
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.ac-input {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--ac-text);
  font-size: 13.5px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  resize: none;
  outline: none;
  line-height: 1.4;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.15s;
}

.ac-input::placeholder {
  color: var(--ac-text-muted);
}

.ac-input:focus {
  border-color: var(--ac-accent);
}

.ac-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ac-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}

.ac-send-btn:hover:not(:disabled) {
  background: #ff4d5a;
  transform: scale(1.06);
}

.ac-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ac-send-btn svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}

/* ── PIN gate ── */
.ac-pin-gate {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  gap: 10px;
}

.ac-pin-gate-logo {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 4px;
}

.ac-pin-gate-title {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  line-height: 1.4;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.ac-pin-gate-sub {
  font-size: 12.5px;
  color: var(--ac-text-muted);
  margin: 0 0 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.ac-pin-row {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 220px;
}

.ac-pin-input {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--ac-text);
  font-size: 15px;
  letter-spacing: 0.15em;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  outline: none;
  text-align: center;
  transition: border-color 0.15s;
}

.ac-pin-input:focus {
  border-color: var(--ac-accent);
}

.ac-pin-submit {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--ac-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}

.ac-pin-submit:hover:not(:disabled) {
  background: #ff4d5a;
  transform: scale(1.06);
}

.ac-pin-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ac-pin-submit svg {
  width: 15px;
  height: 15px;
  fill: #fff;
}

.ac-pin-error {
  font-size: 12px;
  color: #ff6b6b;
  min-height: 16px;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ── Error message ── */
.ac-error {
  font-size: 12px;
  color: #ff6b6b;
  padding: 0 16px 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  #andcards-chatbot-window {
    right: 8px;
    bottom: calc(var(--ac-bubble-size) + 20px);
    width: calc(100vw - 16px);
    height: 70vh;
  }

  #andcards-chatbot-launcher {
    bottom: 16px;
    right: 16px;
  }
}
