/**
 * AI Chat Assistant Styles
 * Design tokens from zs-customcss.css
 * Colors: Navy #0a2540, Teal #00d4aa, Light BG #f7f9fc, Border #e1e5eb
 */

/* ── Trigger Button ── */
.ai-chat-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: none;
  border: 3px solid #00d4aa;
  cursor: pointer;
  z-index: 999999;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease, visibility 0.3s ease;
  opacity: 0;
  visibility: hidden;
}

.ai-chat-trigger.visible {
  opacity: 1;
  visibility: visible;
}

.ai-chat-trigger.scroll-hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.ai-chat-trigger:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

.ai-chat-trigger:active {
  transform: scale(0.95);
}

.ai-chat-trigger img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* ── Chat Panel ── */
.ai-chat-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: min(520px, calc(100vh - 120px));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(10, 37, 64, 0.18);
  z-index: 999999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.95);
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

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

/* ── Header ── */
.ai-chat-header {
  background: #0a2540;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

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

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

.ai-chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.ai-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.ai-chat-header-text {
  min-width: 0;
}

.ai-chat-header-text h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3 !important;
  font-family: 'Poppins', system-ui, sans-serif !important;
  color: #ffffff !important;
  white-space: nowrap;
}

.ai-chat-header-text span {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7) !important;
  line-height: 1.3 !important;
}

.ai-chat-close {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.ai-chat-close svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* ── Messages Area ── */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f7f9fc;
  scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #d0d5dd;
  border-radius: 3px;
}

/* ── Message Bubbles ── */
.ai-chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5 !important;
  font-family: 'Poppins', system-ui, sans-serif;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.ai-chat-msg a {
  color: #0066cc;
  text-decoration: underline;
}

.ai-chat-msg-assistant {
  background: #fff;
  color: #1a1a2e;
  align-self: flex-start;
  border: 1px solid #e1e5eb;
  border-bottom-left-radius: 4px;
}

.ai-chat-msg-user {
  background: #0a2540;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.ai-chat-msg-user a {
  color: #80d4ff;
}

/* Markdown formatting in assistant messages */
.ai-chat-msg-assistant strong {
  font-weight: 600;
}

.ai-chat-msg-assistant ul,
.ai-chat-msg-assistant ol {
  margin: 6px 0;
  padding-left: 20px;
}

.ai-chat-msg-assistant li {
  margin-bottom: 4px;
}

.ai-chat-msg-assistant code {
  background: #f0f2f5;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}

.ai-chat-msg-assistant pre {
  margin: 8px 0;
  padding: 10px 12px;
  background: #f0f2f5;
  border-radius: 8px;
  overflow-x: auto;
}

.ai-chat-msg-assistant pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
}

/* ── Typing Indicator ── */
.ai-chat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #e1e5eb;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  max-width: 60px;
}

.ai-chat-typing-dot {
  width: 7px;
  height: 7px;
  background: #b0b8c4;
  border-radius: 50%;
  animation: ai-chat-bounce 1.4s ease-in-out infinite;
}

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

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

@keyframes ai-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* ── Input Area ── */
.ai-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e1e5eb;
  background: #fff;
  flex-shrink: 0;
}

.ai-chat-input {
  flex: 1;
  border: 1.5px solid #e1e5eb;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: 'Poppins', system-ui, sans-serif;
  resize: none;
  max-height: 80px;
  min-height: 40px;
  line-height: 1.4 !important;
  color: #1a1a2e;
  background: #f7f9fc;
  transition: border-color 0.2s ease;
  outline: none;
}

.ai-chat-input::placeholder {
  color: #8c95a4;
}

.ai-chat-input:focus {
  border-color: #00d4aa;
  background: #fff;
}

.ai-chat-send {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 10px;
  background: #0a2540;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.ai-chat-send:hover {
  background: #1a365d;
}

.ai-chat-send:active {
  transform: scale(0.93);
}

.ai-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-chat-send svg {
  width: 18px;
  height: 18px;
  fill: white;
}

/* Stop generating button variant */
.ai-chat-send.ai-chat-send-stop {
  background: #d32f2f;
}

.ai-chat-send.ai-chat-send-stop:hover {
  background: #b71c1c;
}

/* ── Mic Button ── */
.ai-chat-mic {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 50%;
  background: none;
  border: 1.5px solid #e1e5eb;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #6b7c93;
  transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
  flex-shrink: 0;
  position: relative;
}

.ai-chat-mic:hover {
  color: #00d4aa;
  border-color: #00d4aa;
  background: rgba(0, 212, 170, 0.08);
}

.ai-chat-mic:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-chat-mic svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.ai-chat-mic.active {
  color: #fff;
  background: #00d4aa;
  border-color: #00d4aa;
}

.ai-chat-mic.active:hover {
  background: #00b894;
  border-color: #00b894;
}

/* Pulse animation when recording */
.ai-chat-mic.active::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid #00d4aa;
  animation: voice-pulse 1.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes voice-pulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 0; transform: scale(1.5); }
}

/* ── Voice Indicator Bar ── */
.ai-chat-voice-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(0, 212, 170, 0.08);
  font-size: 13px;
  font-family: 'Poppins', system-ui, sans-serif;
  color: #00d4aa;
  border-bottom: 1px solid rgba(0, 212, 170, 0.15);
  flex-shrink: 0;
}

.ai-chat-voice-dot {
  width: 8px;
  height: 8px;
  background: #00d4aa;
  border-radius: 50%;
  animation: voice-pulse-dot 1.2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes voice-pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.ai-chat-panel.voice-active .ai-chat-voice-indicator {
  display: flex;
}

.ai-chat-panel.voice-active .ai-chat-input {
  opacity: 0.5;
  pointer-events: none;
}

.ai-chat-panel.voice-active .ai-chat-send {
  opacity: 0.3;
  pointer-events: none;
}

/* ── System Messages (voice status) ── */
.ai-chat-msg-system {
  background: transparent;
  color: #6b7c93;
  font-size: 12px;
  text-align: center;
  padding: 4px 12px;
  align-self: center;
  max-width: 100%;
  font-style: italic;
}

/* ── Character counter ── */
.ai-chat-char-count {
  font-size: 12px;
  color: #8c95a4;
  text-align: right;
  padding: 0 16px 4px;
  background: #fff;
  flex-shrink: 0;
  opacity: 0;
  height: 0;
  overflow: hidden;
  transition: opacity 0.2s ease, height 0.2s ease;
}

.ai-chat-char-count.visible {
  opacity: 1;
  height: 18px;
}

.ai-chat-char-count.warning {
  color: #d32f2f;
  font-weight: 600;
}

/* ── Error message ── */
.ai-chat-error {
  background: #fff5f5;
  color: #d32f2f;
  border: 1px solid #fecaca;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  align-self: center;
}

.ai-chat-error-retryable {
  cursor: pointer;
  transition: background 0.2s ease;
}

.ai-chat-error-retryable:hover {
  background: #fee2e2;
}

.ai-chat-retry {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: #0066cc;
  text-decoration: underline;
}

/* ── Powered by footer ── */
.ai-chat-footer {
  text-align: center;
  padding: 6px 16px 10px;
  font-size: 12px;
  color: #8c95a4;
  background: #fff;
  flex-shrink: 0;
}

/* ── Mobile: full-screen panel ── */
@media (max-width: 767px) {
  .ai-chat-trigger {
    bottom: 16px;
    right: 16px;
  }

  /* Shift trigger above sticky CTA when it's visible */
  .ai-chat-trigger.cta-offset {
    bottom: 72px;
  }

  .ai-chat-panel {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    transform: translateY(100%);
  }

  .ai-chat-panel.open {
    transform: translateY(0);
  }

  .ai-chat-msg {
    max-width: 90%;
  }

  /* Prevent iOS Safari auto-zoom on input focus (requires >= 16px) */
  .ai-chat-input {
    font-size: 16px;
  }

  /* Larger close/new buttons for mobile touch targets (44px min) */
  .ai-chat-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  /* Larger mic button for mobile touch targets (44px min) */
  .ai-chat-mic {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  /* Safe-area padding for notch/home-indicator devices */
  .ai-chat-footer {
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  /* Larger tap targets for footer links */
  .ai-chat-footer a {
    display: inline-block;
    padding: 8px 4px;
    min-height: 44px;
    line-height: 28px;
  }
}

/* ── Tablet adjustments ── */
@media (min-width: 768px) and (max-width: 991px) {
  .ai-chat-panel {
    width: 360px;
    height: min(480px, calc(100vh - 120px));
  }
}

/* ── Dark Mode ── */
@media (prefers-color-scheme: dark) {
  .ai-chat-panel {
    background: #1a1f2e;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  }

  .ai-chat-messages {
    background: #111520;
  }

  .ai-chat-messages::-webkit-scrollbar-thumb {
    background: #3a4050;
  }

  .ai-chat-msg-assistant {
    background: #1a1f2e;
    border-color: #2a3040;
    color: #e0e4eb;
  }

  .ai-chat-msg-assistant a {
    color: #5dade2;
  }

  .ai-chat-msg-assistant code {
    background: #252a38;
  }

  .ai-chat-msg-assistant pre {
    background: #252a38;
  }

  .ai-chat-msg-user a {
    color: #80d4ff;
  }



  .ai-chat-input-area {
    background: #1a1f2e;
    border-color: #2a3040;
  }

  .ai-chat-input {
    background: #111520;
    border-color: #2a3040;
    color: #e0e4eb;
  }

  .ai-chat-input::placeholder {
    color: #5a6370;
  }

  .ai-chat-input:focus {
    background: #1a1f2e;
    border-color: #00d4aa;
  }

  .ai-chat-char-count {
    background: #1a1f2e;
    color: #5a6370;
  }

  .ai-chat-error {
    background: #2a1515;
    border-color: #4a2020;
  }

  .ai-chat-footer {
    background: #1a1f2e;
    color: #5a6370;
  }

  .ai-chat-footer a {
    color: #5dade2 !important;
  }

  .ai-chat-typing {
    background: #1a1f2e;
    border-color: #2a3040;
  }

  .ai-chat-typing-dot {
    background: #5a6370;
  }

  .ai-chat-mic {
    border-color: #2a3040;
    color: #8c95a4;
  }

  .ai-chat-mic:hover {
    border-color: #00d4aa;
    color: #00d4aa;
    background: rgba(0, 212, 170, 0.1);
  }

  .ai-chat-voice-indicator {
    background: rgba(0, 212, 170, 0.06);
    border-color: rgba(0, 212, 170, 0.12);
  }

  .ai-chat-msg-system {
    color: #5a6370;
  }
}

/* ── Accessibility ── */
@media (prefers-reduced-motion: reduce) {
  .ai-chat-trigger,
  .ai-chat-panel,
  .ai-chat-close,
  .ai-chat-send,
  .ai-chat-mic,
  .ai-chat-input,
  .ai-chat-char-count {
    transition: none !important;
  }

  .ai-chat-typing-dot {
    animation: none;
  }

  .ai-chat-panel.open {
    transform: none;
  }

  .ai-chat-mic.active::after {
    animation: none;
  }

  .ai-chat-voice-dot {
    animation: none;
  }
}

@media (prefers-contrast: high) {
  .ai-chat-panel {
    border: 2px solid #0a2540;
  }

  .ai-chat-msg-assistant {
    border: 2px solid #0a2540;
  }

  .ai-chat-msg-user {
    border: 2px solid #fff;
  }

  .ai-chat-trigger {
    border: 2px solid #fff;
  }
}

/* ── Focus outlines ── */
.ai-chat-trigger:focus-visible,
.ai-chat-close:focus-visible,
.ai-chat-send:focus-visible,
.ai-chat-mic:focus-visible {
  outline: 3px solid #0066cc;
  outline-offset: 2px;
}

.ai-chat-input:focus-visible {
  outline: none;
  border-color: #0066cc;
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.2);
}
