/* ai360agent — Public Chat Interface */
/* Modern, responsive chat UI for AI agent interactions */

/* ── Base container ── */
.ai360-chat-container {
  max-width: 480px;
  margin: 0 auto;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  height: 600px;
  max-height: 80vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  position: relative;
}

/* ── Screen-reader-only utility ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Header ── */
.ai360-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: linear-gradient(135deg, #00BFFF 0%, #4B4BFF 35%, #8A4DFF 70%, #FF2FB3 100%);
  color: #ffffff;
  border-radius: 16px 16px 0 0;
}

.ai360-chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #FF2FB3, #4B4BFF);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  text-transform: uppercase;
  user-select: none;
}

.ai360-chat-header-info { flex: 1; min-width: 0; }

.ai360-chat-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai360-chat-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai360-chat-status { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.ai360-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
}

.ai360-status-dot.online {
  background: #4caf50;
  box-shadow: 0 0 6px rgba(76, 175, 80, 0.6);
  animation: ai360-pulse 2s infinite;
}

@keyframes ai360-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.ai360-status-text { font-size: 12px; opacity: 0.8; }

/* ── Messages area ── */
.ai360-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f8f9fb;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

.ai360-chat-messages::-webkit-scrollbar { width: 6px; }
.ai360-chat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
.ai360-chat-messages::-webkit-scrollbar-track { background: transparent; }

/* Focus-visible: show clear ring for keyboard users */
.ai360-chat-messages:focus-visible {
  outline: 2px solid #4B4BFF;
  outline-offset: -2px;
}

.ai360-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  color: #9ca3af;
}

.ai360-chat-empty-icon { font-size: 48px; margin-bottom: 12px; }

.ai360-chat-empty p {
  font-size: 15px;
  line-height: 1.5;
  max-width: 240px;
  margin: 0;
}

/* ── Messages ── */
.ai360-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: ai360-msg-in 0.25s ease-out;
}

@keyframes ai360-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai360-msg-user { align-self: flex-end; }
.ai360-msg-agent { align-self: flex-start; }

.ai360-msg-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.ai360-msg-user .ai360-msg-bubble {
  background: linear-gradient(135deg, #4B4BFF, #6C63FF);
  color: #ffffff;
  border-bottom-right-radius: 6px;
}

.ai360-msg-agent .ai360-msg-bubble {
  background: #ffffff;
  color: #1a1a2e;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.ai360-msg-time { font-size: 10px; color: #9ca3af; margin-top: 4px; padding: 0 4px; }
.ai360-msg-user .ai360-msg-time { text-align: right; }
.ai360-msg-agent .ai360-msg-time { text-align: left; }

/* ── Typing indicator ── */
.ai360-msg-typing .ai360-msg-bubble {
  padding: 14px 20px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.ai360-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: ai360-typing 1.4s infinite both;
}

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

@keyframes ai360-typing {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* ── Error message ── */
.ai360-msg-error .ai360-msg-bubble {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  font-size: 13px;
}

/* ── Input area ── */
.ai360-chat-input {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 16px 12px;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
}

.ai360-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.ai360-chat-input-actions {
  display: flex;
  flex-direction: row;
  gap: 6px;
  flex-shrink: 0;
  padding-left: 2px;
}

.ai360-chat-input-actions button {
  width: 34px;
  height: 30px;
  border-radius: 8px;
  background: #f3f4f6;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  color: #6b7280;
}

.ai360-chat-input-actions button:hover {
  background: rgba(75, 75, 255, 0.1);
  color: #4B4BFF;
  transform: scale(1.05);
}

.ai360-chat-input-actions button:active {
  transform: scale(0.95);
}

.ai360-chat-input-actions button:focus-visible {
  outline: 2px solid #4B4BFF;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(75,75,255,0.2);
}

.ai360-chat-input-actions button.active {
  color: #ef4444;
  background: #fee2e2;
}

.ai360-chat-textarea {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #f9fafb;
}

.ai360-chat-textarea:focus {
  border-color: #4B4BFF;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(75, 75, 255, 0.15);
}

.ai360-chat-textarea:focus-visible {
  outline: none; /* uses box-shadow instead for better visibility */
}

.ai360-chat-send {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #FF2FB3, #FF6B6B);
  color: #ffffff;
  border: none;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, opacity 0.2s, box-shadow 0.15s;
  flex-shrink: 0;
  line-height: 1;
}

.ai360-chat-send:hover { transform: scale(1.05); opacity: 0.9; }
.ai360-chat-send:active { transform: scale(0.95); }
.ai360-chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.ai360-chat-send:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(255,47,179,0.4);
}
.ai360-chat-send svg { width: 20px; height: 20px; fill: currentColor; }

/* ── Keyboard hint ── */
.ai360-chat-keyboard-hint {
  text-align: center;
  font-size: 10px;
  color: #9ca3af;
  padding: 0;
  margin: 0;
  user-select: none;
}

/* ── Login overlay ── */
.ai360-chat-login-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(4px);
  padding: 20px;
  display: flex;
  justify-content: center;
  border-top: 1px solid #e5e7eb;
}

.ai360-chat-login-card { text-align: center; }

.ai360-chat-login-card p {
  margin: 0 0 12px;
  font-size: 14px;
  color: #6b7280;
}

.ai360-chat-login-btn {
  display: inline-block;
  padding: 10px 28px;
  background: linear-gradient(135deg, #4B4BFF, #8A4DFF);
  color: #ffffff;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: transform 0.15s;
}

.ai360-chat-login-btn:hover { transform: scale(1.03); }
.ai360-chat-login-btn:focus-visible {
  outline: 2px solid #4B4BFF;
  outline-offset: 3px;
}

/* ── Connecting banner ── */
.ai360-chat-connecting {
  text-align: center;
  padding: 12px;
  background: #fff8e1;
  color: #b45309;
  font-size: 13px;
  border-bottom: 1px solid #fde68a;
  animation: ai360-msg-in 0.25s ease-out;
}

/* ── System message (info/warnings) ── */
.ai360-msg-system .ai360-msg-bubble {
  background: #f0f9ff;
  color: #0c4a6e;
  border: 1px solid #bae6fd;
  font-size: 13px;
  text-align: center;
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .ai360-msg,
  .ai360-chat-connecting,
  .ai360-status-dot.online {
    animation: none;
  }
  .ai360-chat-input-actions button,
  .ai360-chat-send,
  .ai360-chat-login-btn {
    transition: none;
  }
}

/* ── Responsive: tablet ── */
@media (max-width: 768px) {
  .ai360-chat-container {
    max-width: 100%;
    border-radius: 12px;
    height: 500px;
  }
  .ai360-chat-header {
    border-radius: 12px 12px 0 0;
    padding: 14px 16px;
  }
  .ai360-chat-messages {
    padding: 16px;
    gap: 12px;
  }
  .ai360-msg { max-width: 90%; }
}

/* ── Responsive: mobile ── */
@media (max-width: 520px) {
  .ai360-chat-container {
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .ai360-chat-header { border-radius: 0; padding: 12px 14px; }
  .ai360-chat-avatar { width: 36px; height: 36px; font-size: 14px; border-radius: 10px; }
  .ai360-chat-title { font-size: 15px; }
  .ai360-chat-subtitle { font-size: 11px; }
  .ai360-chat-messages { padding: 12px; gap: 10px; }
  .ai360-msg { max-width: 92%; }
  .ai360-msg-bubble { font-size: 13px; padding: 10px 14px; }
  .ai360-chat-input { padding: 6px 10px 10px; }
  .ai360-chat-input-actions button {
    width: 36px;
    height: 36px;
    font-size: 14px;
  }
  .ai360-chat-send { width: 44px; height: 44px; }
  .ai360-chat-textarea { font-size: 13px; }
}

/* ── RTL support ── */
[dir="rtl"] .ai360-msg-user { align-self: flex-start; }
[dir="rtl"] .ai360-msg-agent { align-self: flex-end; }
[dir="rtl"] .ai360-msg-user .ai360-msg-time { text-align: left; }
[dir="rtl"] .ai360-msg-agent .ai360-msg-time { text-align: right; }
[dir="rtl"] .ai360-msg-user .ai360-msg-bubble {
  border-bottom-right-radius: 18px;
  border-bottom-left-radius: 6px;
}
[dir="rtl"] .ai360-msg-agent .ai360-msg-bubble {
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 6px;
}
[dir="rtl"] .ai360-chat-input-actions { padding-left: 0; padding-right: 2px; }
