/* ═══════════════════════════════════════════════════════════════
   SepuraHome AI Chatbot — Widget Styles
   Floating chat bubble, message bubbles, typing indicator,
   quick-reply buttons, escalation form, mobile-responsive.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --chat-primary:    #2E7D32;   /* SepuraHome green */
  --chat-primary-dk: #1B5E20;
  --chat-primary-lt: #E8F5E9;
  --chat-accent:     #FF9800;
  --chat-bg:         #FFFFFF;
  --chat-surface:    #F5F5F5;
  --chat-text:       #212121;
  --chat-text-sec:   #757575;
  --chat-border:     #E0E0E0;
  --chat-danger:     #D32F2F;
  --chat-radius:     12px;
  --chat-shadow:     0 4px 24px rgba(0,0,0,0.18);
  --chat-width:      380px;
  --chat-height:     560px;
}

/* ── Floating Bubble ────────────────────────────────────────── */
#sepura-chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--chat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--chat-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  transition: transform 0.2s, background 0.2s;
}
#sepura-chat-bubble:hover {
  transform: scale(1.08);
  background: var(--chat-primary-dk);
}
#sepura-chat-bubble svg {
  width: 28px;
  height: 28px;
  fill: #fff;
}
#sepura-chat-bubble .badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--chat-danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}

/* ── Chat Window ────────────────────────────────────────────── */
#sepura-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: var(--chat-width);
  height: var(--chat-height);
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: none;
  flex-direction: column;
  z-index: 99998;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  border: 1px solid var(--chat-border);
}
#sepura-chat-window.open {
  display: flex;
  animation: chatSlideIn 0.3s ease;
}

@keyframes chatSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ─────────────────────────────────────────────────── */
.chat-header {
  background: var(--chat-primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.chat-header-info {
  flex: 1;
}
.chat-header-info h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.chat-header-info p {
  margin: 0;
  font-size: 12px;
  opacity: 0.85;
}
.chat-header-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  opacity: 0.8;
}
.chat-header-close:hover {
  opacity: 1;
}

/* ── Device Banner ──────────────────────────────────────────── */
.chat-device-banner {
  background: var(--chat-primary-lt);
  padding: 8px 16px;
  font-size: 12px;
  color: var(--chat-primary-dk);
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--chat-border);
}
.chat-device-banner .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chat-primary);
  flex-shrink: 0;
}
.chat-device-banner .status-dot.warn { background: var(--chat-accent); }
.chat-device-banner .status-dot.critical { background: var(--chat-danger); }

/* ── Messages Area ──────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* ── Message Bubbles ────────────────────────────────────────── */
.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
}
.msg.bot {
  background: var(--chat-surface);
  color: var(--chat-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg.user {
  background: var(--chat-primary);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg .msg-time {
  font-size: 11px;
  opacity: 0.6;
  margin-top: 4px;
  display: block;
}

/* ── Typing Indicator ───────────────────────────────────────── */
.typing-indicator {
  display: none;
  align-self: flex-start;
  padding: 10px 16px;
  background: var(--chat-surface);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}
.typing-indicator.show { display: flex; gap: 4px; }
.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chat-text-sec);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Quick Replies ──────────────────────────────────────────── */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 10px;
}
.quick-reply-btn {
  background: var(--chat-bg);
  border: 1.5px solid var(--chat-primary);
  color: var(--chat-primary);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.quick-reply-btn:hover {
  background: var(--chat-primary);
  color: #fff;
}

/* ── Input Area ─────────────────────────────────────────────── */
.chat-input-area {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid var(--chat-border);
  gap: 8px;
  background: var(--chat-bg);
}
.chat-input-area input {
  flex: 1;
  border: 1.5px solid var(--chat-border);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
.chat-input-area input:focus {
  border-color: var(--chat-primary);
}
.chat-input-area button {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--chat-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.chat-input-area button:hover {
  background: var(--chat-primary-dk);
}
.chat-input-area button:disabled {
  background: #ccc;
  cursor: not-allowed;
}
.chat-input-area button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ── Escalation Form ────────────────────────────────────────── */
.escalation-form {
  display: none;
  padding: 16px;
  background: #FFF3E0;
  border-top: 2px solid var(--chat-accent);
}
.escalation-form.show { display: block; }
.escalation-form h4 {
  margin: 0 0 12px;
  font-size: 14px;
  color: #E65100;
}
.escalation-form input,
.escalation-form textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
}
.escalation-form textarea { resize: vertical; min-height: 60px; }
.escalation-form .form-actions {
  display: flex;
  gap: 8px;
}
.escalation-form .btn-submit {
  background: var(--chat-accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.escalation-form .btn-submit:hover { background: #F57C00; }
.escalation-form .btn-cancel {
  background: none;
  border: 1px solid #ccc;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--chat-text-sec);
}

/* ── Device ID Prompt ───────────────────────────────────────── */
.device-prompt {
  padding: 12px 16px;
  background: var(--chat-primary-lt);
  border-bottom: 1px solid var(--chat-border);
  display: none;
}
.device-prompt.show { display: block; }
.device-prompt p {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--chat-text);
}
.device-prompt-row {
  display: flex;
  gap: 6px;
}
.device-prompt-row input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  font-size: 13px;
}
.device-prompt-row button {
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: var(--chat-primary);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
.device-prompt .skip-link {
  display: block;
  text-align: center;
  margin-top: 6px;
  font-size: 12px;
  color: var(--chat-text-sec);
  cursor: pointer;
}
.device-prompt .skip-link:hover { text-decoration: underline; }

/* ── Mobile Responsive ──────────────────────────────────────── */
@media (max-width: 480px) {
  #sepura-chat-window {
    width: 100vw;
    height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }
  #sepura-chat-bubble {
    bottom: 16px;
    right: 16px;
  }
}

/* ── Ticket Confirmation ────────────────────────────────────── */
.ticket-confirmation {
  background: #E8F5E9;
  border: 1px solid var(--chat-primary);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 8px 0;
  align-self: flex-start;
  max-width: 85%;
}
.ticket-confirmation strong {
  color: var(--chat-primary-dk);
  display: block;
  margin-bottom: 4px;
}
.ticket-confirmation p {
  margin: 0;
  font-size: 13px;
  color: var(--chat-text);
}
