/* AI Chatbot Widget — v1.3 */
:root {
  --aichat-primary: #1a6496;
  --aichat-primary-dark: #155177;
  --aichat-bot-bg: #f0faf4;
  --aichat-user-bg: #e8f4fd;
  --aichat-radius: 12px;
  --aichat-shadow: 0 8px 32px rgba(0,0,0,.18);
}

#aichat-root { position: fixed; bottom: 24px; right: 24px; z-index: 99999; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

/* Toggle button */
#aichat-toggle {
  width: 56px; height: 56px; border-radius: 50%; background: var(--aichat-primary);
  border: none; cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(26,100,150,.45); transition: background .2s, transform .2s; color: #fff;
}
#aichat-toggle:hover { background: var(--aichat-primary-dark); transform: scale(1.08); }
#aichat-toggle svg { width: 24px; height: 24px; }

/* Chat window */
#aichat-window {
  position: absolute; bottom: 70px; right: 0;
  width: 360px; max-height: 580px;
  background: #fff; border-radius: var(--aichat-radius);
  box-shadow: var(--aichat-shadow);
  display: flex; flex-direction: column;
  border: 1px solid #e0e0e0; overflow: hidden;
}
#aichat-window[hidden] { display: none !important; }

/* Header */
#aichat-header {
  background: var(--aichat-primary); color: #fff;
  padding: 12px 16px; display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
#aichat-bot-name { font-weight: 600; font-size: 15px; }
#aichat-header-actions { display: flex; align-items: center; gap: 10px; }
#aichat-status { font-size: 12px; opacity: .85; }

/* X close button in header */
#aichat-close-btn {
  background: none; border: none; cursor: pointer; color: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: 2px; border-radius: 4px; opacity: .8; transition: opacity .15s, background .15s;
  line-height: 1;
}
#aichat-close-btn:hover { opacity: 1; background: rgba(255,255,255,.15); }
#aichat-close-btn svg { width: 18px; height: 18px; }

/* ── Visitor info form ── */
#aichat-visitor-form {
  padding: 18px 18px 16px;
  display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto; flex: 1;
}
#aichat-visitor-intro {
  margin: 0 0 4px; font-size: 13px; color: #555; line-height: 1.5;
}
.aichat-field { display: flex; flex-direction: column; gap: 4px; }
.aichat-field label { font-size: 12px; font-weight: 600; color: #444; }
.aichat-req { color: #c00; }
.aichat-field input {
  border: 1px solid #ccc; border-radius: 8px; padding: 8px 11px;
  font-size: 13px; outline: none; font-family: inherit; transition: border-color .2s;
}
.aichat-field input:focus { border-color: var(--aichat-primary); }
#aichat-visitor-error {
  font-size: 12px; color: #c00; background: #fff0f0; border: 1px solid #fcc;
  border-radius: 6px; padding: 6px 10px; margin: 0;
}
#aichat-visitor-submit {
  background: var(--aichat-primary); color: #fff; border: none;
  padding: 10px 0; border-radius: 8px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .2s; margin-top: 2px;
}
#aichat-visitor-submit:hover { background: var(--aichat-primary-dark); }

/* ── Chat area ── */
#aichat-chat-area {
  flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}

/* Messages */
#aichat-messages {
  flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px;
}

.aichat-msg {
  max-width: 82%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.55;
  word-break: break-word; animation: aichat-fade .2s ease;
}
.aichat-msg.user  { background: var(--aichat-user-bg); color: #1a3a50; align-self: flex-end; border-bottom-right-radius: 4px; }
.aichat-msg.bot   { background: var(--aichat-bot-bg); color: #1c3a2b; align-self: flex-start; border-bottom-left-radius: 4px; }
.aichat-msg.typing { opacity: .65; font-style: italic; }

@keyframes aichat-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Input row */
#aichat-input-row {
  display: flex; align-items: flex-end; padding: 10px 12px;
  border-top: 1px solid #ececec; gap: 8px; background: #fafafa; flex-shrink: 0;
}
#aichat-input {
  flex: 1; border: 1px solid #ccc; border-radius: 20px;
  padding: 9px 14px; font-size: 14px; resize: none; max-height: 100px; outline: none;
  font-family: inherit; line-height: 1.4; transition: border-color .2s;
}
#aichat-input:focus { border-color: var(--aichat-primary); }
#aichat-send {
  width: 38px; height: 38px; border-radius: 50%; background: var(--aichat-primary);
  border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #fff;
  flex-shrink: 0; transition: background .2s;
}
#aichat-send:hover { background: var(--aichat-primary-dark); }
#aichat-send svg { width: 16px; height: 16px; }

/* Mobile */
@media (max-width: 420px) {
  #aichat-root { bottom: 12px; right: 12px; }
  #aichat-window { width: calc(100vw - 24px); right: -12px; max-height: 90vh; }
}
