/* ═══════════════════════════════════════════════════════════════════════════
   e-Pouroshava — AI Chat Widget
   Floating chat widget for citizen portal
   ═══════════════════════════════════════════════════════════════════════════ */

#ai-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: var(--font, 'Hind Siliguri', system-ui, sans-serif);
}

#ai-chat-widget * {
  box-sizing: border-box;
}

/* ── Toggle Button ────────────────────────────────────────────────────────── */

.ai-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary, #1a56db);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(26, 86, 219, 0.4);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
  position: relative;
}

.ai-chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 28px rgba(26, 86, 219, 0.5);
}

.ai-chat-toggle:focus-visible {
  outline: 3px solid var(--primary, #1a56db);
  outline-offset: 3px;
}

.ai-chat-toggle.open {
  transform: rotate(90deg) scale(1.1);
  background: var(--primary-hover, #1648c0);
}

.ai-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  background: var(--danger, #ef4444);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 2px solid #fff;
  animation: ai-pulse 2s infinite;
}

@keyframes ai-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ── Chat Window ──────────────────────────────────────────────────────────── */

.ai-chat-window {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 500px;
  max-height: 70vh;
  background: var(--bg-card, #fff);
  border-radius: var(--radius-lg, 12px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--border, #e5e7eb);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ── Header ───────────────────────────────────────────────────────────────── */

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--primary, #1a56db);
  color: #fff;
  border-radius: var(--radius-lg, 12px) var(--radius-lg, 12px) 0 0;
}

.ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.ai-chat-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.ai-chat-subtitle {
  font-size: 11.5px;
  opacity: 0.85;
}

.ai-chat-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm, 6px);
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.ai-chat-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ── Messages ─────────────────────────────────────────────────────────────── */

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-chat-message {
  display: flex;
  max-width: 85%;
  animation: ai-message-in 0.3s ease;
}

@keyframes ai-message-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-chat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-chat-message.bot {
  align-self: flex-start;
}

.ai-chat-bubble {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px;
  border-radius: 18px;
  max-width: 100%;
}

.ai-chat-message.user .ai-chat-bubble {
  background: var(--primary, #1a56db);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-chat-message.bot .ai-chat-bubble {
  background: var(--gray-100, #f3f4f6);
  color: var(--text-primary, #1f2937);
  border-bottom-left-radius: 4px;
}

.ai-chat-text {
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.ai-chat-time {
  font-size: 10px;
  opacity: 0.7;
  align-self: flex-end;
}

/* ── Quick Actions (chips under an assistant answer) ──────────────────────── */

.ai-chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.ai-chat-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.4;
  text-decoration: none;
  color: var(--primary, #1a56db);
  background: rgba(26, 86, 219, 0.08);
  border: 1px solid rgba(26, 86, 219, 0.35);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s;
}

.ai-chat-action:hover {
  background: rgba(26, 86, 219, 0.16);
  border-color: rgba(26, 86, 219, 0.55);
}

.ai-chat-action:focus-visible {
  outline: 2px solid var(--primary, #1a56db);
  outline-offset: 2px;
}

.ai-chat-action-arrow {
  font-size: 12px;
}

[dir="rtl"] .ai-chat-action-arrow {
  transform: scaleX(-1);
}

/* ── Typing Indicator ─────────────────────────────────────────────────────── */

.ai-chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  color: var(--text-muted, #9ca3af);
  font-size: 12px;
}

.ai-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary, #1a56db);
  animation: ai-typing 1.4s infinite ease-in-out;
}

.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* ── Input Area ───────────────────────────────────────────────────────────── */

.ai-chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border, #e5e7eb);
  background: var(--bg-card, #fff);
}

#ai-chat-form {
  display: flex;
  gap: 8px;
}

#ai-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border, #e5e7eb);
  border-radius: var(--radius-pill, 24px);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text-primary, #1f2937);
  background: var(--gray-50, #f9fafb);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

#ai-chat-input:focus {
  border-color: var(--primary, #1a56db);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
  background: #fff;
}

#ai-chat-input::placeholder {
  color: var(--text-muted, #9ca3af);
}

#ai-chat-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#ai-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary, #1a56db);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

#ai-chat-send:hover:not(:disabled) {
  background: var(--primary-hover, #1648c0);
  transform: scale(1.05);
}

#ai-chat-send:focus-visible {
  outline: 3px solid var(--primary, #1a56db);
  outline-offset: 2px;
}

#ai-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── Mobile Responsive ────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .ai-chat-window {
    width: calc(100vw - 16px);
    height: calc(100vh - 80px);
    max-height: calc(100vh - 80px);
    bottom: 72px;
    right: 8px;
    border-radius: var(--radius-lg, 12px);
  }

  #ai-chat-widget {
    bottom: 16px;
    right: 16px;
  }
}

/* ── RTL Support (Bengali) ────────────────────────────────────────────────── */

[dir="rtl"] #ai-chat-widget {
  right: auto;
  left: 24px;
}

[dir="rtl"] .ai-chat-window {
  right: auto;
  left: 0;
}

[dir="rtl"] .ai-chat-message.user {
  align-self: flex-start;
  flex-direction: row;
}

[dir="rtl"] .ai-chat-message.bot {
  align-self: flex-end;
  flex-direction: row-reverse;
}

[dir="rtl"] .ai-chat-message.user .ai-chat-bubble {
  border-bottom-right-radius: 18px;
  border-bottom-left-radius: 4px;
}

[dir="rtl"] .ai-chat-message.bot .ai-chat-bubble {
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 4px;
}

@media (max-width: 480px) {
  [dir="rtl"] .ai-chat-window {
    left: 8px;
    right: auto;
  }

  [dir="rtl"] #ai-chat-widget {
    left: 16px;
    right: auto;
  }
}

/* ── Reduced Motion ───────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .ai-chat-toggle,
  .ai-chat-window,
  .ai-chat-message,
  .ai-typing-dot,
  #ai-chat-send {
    animation: none !important;
    transition: none !important;
  }
}