/* Shahi Meva Customer Assistant Chat Widget */

/* Launcher */
.chat-launcher {
  position: fixed;
  bottom: 48px;
  right: 48px;
  width: 112px;
  height: 112px;
  padding: 0;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  filter: drop-shadow(0 10px 18px rgba(24, 44, 35, 0.28));
  z-index: 1000;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.chat-launcher:hover {
  transform: scale(1.05);
  filter: drop-shadow(0 14px 22px rgba(24, 44, 35, 0.34));
}

.chat-launcher:focus-visible {
  outline: 3px solid var(--gold-light);
  outline-offset: 3px;
  border-radius: 50%;
}

.chat-launcher-art {
  width: 112px;
  height: 112px;
  object-fit: contain;
  pointer-events: none;
}

.chat-launcher-logo {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 57px;
  height: 57px;
  object-fit: contain;
  transform: translate(-50%, -54%);
  pointer-events: none;
}

/* Panel */
.chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  height: 560px;
  background: #fffdf7;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-warm);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
  font-family: "Plus Jakarta Sans", "Tiro Devanagari Hindi", sans-serif;
}

.chat-panel.hidden {
  display: none;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--forest);
  color: var(--ivory);
  flex-shrink: 0;
}

.chat-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-brand img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.chat-title {
  font-family: "Rozha One", "Playfair Display", serif;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 0.2px;
}

.chat-actions {
  display: flex;
  gap: 8px;
}

.chat-action-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  color: var(--ivory);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background-color 0.2s ease;
}

.chat-action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chat-action-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fffdf7;
}

.chat-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--forest);
  color: var(--ivory);
  border-bottom-right-radius: 4px;
}

.chat-message.assistant {
  align-self: flex-start;
  background: #ffffff;
  color: var(--charcoal);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-welcome {
  align-self: center;
  text-align: center;
  color: var(--forest);
  font-family: "Rozha One", "Playfair Display", serif;
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 8px;
  line-height: 1.4;
}

.chat-welcome-supporting {
  align-self: center;
  text-align: center;
  color: var(--olive);
  font-family: "Tiro Devanagari Hindi", serif;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 12px;
}

/* Formatted message blocks */
.formatted-message p {
  margin: 0 0 10px 0;
}

.formatted-message > *:last-child {
  margin-bottom: 0;
}

.formatted-message h3 {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: bold;
  color: var(--forest);
}

.formatted-message ul,
.formatted-message ol {
  margin: 0 0 10px 0;
  padding-left: 20px;
}

.formatted-message ul {
  list-style: disc;
}

.formatted-message ol {
  list-style: decimal;
}

.formatted-message li {
  margin-bottom: 4px;
}

.formatted-message li:last-child {
  margin-bottom: 0;
}

.formatted-message table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 8px 0;
}

.formatted-message th,
.formatted-message td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.formatted-message th {
  background: var(--forest);
  color: var(--ivory);
  font-weight: bold;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.chat-typing span {
  width: 8px;
  height: 8px;
  background: var(--olive);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.chat-typing span:nth-child(1) { animation-delay: -0.32s; }
.chat-typing span:nth-child(2) { animation-delay: -0.16s; }
.chat-typing span:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Error state */
.chat-error {
  align-self: flex-start;
  background: #fdecea;
  color: #b3261e;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  margin-bottom: 8px;
  border: 1px solid #f5c6c6;
}

/* Composer — light, integrated input */
.chat-composer {
  padding: 12px 16px;
  background: #fffdf7;
  flex-shrink: 0;
}

.chat-composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 7px 8px 7px 14px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 4px 16px rgb(39 58 40 / 5%);
}

.chat-composer-inner.hidden {
  display: none;
}

.chat-input {
  flex: 1;
  min-height: 34px;
  max-height: 120px;
  padding: 8px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--charcoal);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  outline: none;
}

.chat-input:focus,
.chat-input:focus-visible {
  outline: none;
  border: 0;
  box-shadow: none;
}

.chat-input::placeholder {
  color: #899489;
}

.chat-send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--forest);
  color: var(--ivory);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.chat-send.hidden {
  display: none;
}

.chat-send:hover:not(:disabled) {
  background: var(--olive);
  transform: translateY(-1px);
}

.chat-send:disabled {
  background: #d8d2c0;
  color: #8a8570;
  cursor: not-allowed;
  transform: none;
}

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

/* Microphone button — shown when the input is empty */
.chat-mic {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #edf1e8;
  color: #49624e;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.chat-mic:hover {
  background: #dfe8db;
  transform: translateY(-1px);
}

.chat-mic:focus-visible {
  outline: 3px solid var(--gold-light);
  outline-offset: 2px;
}

.chat-mic.hidden {
  display: none;
}

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

/* Stop-response button — replaces the microphone while an answer streams */
.chat-stop {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #edf1e8;
  color: #49624e;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.chat-stop:hover {
  background: #dfe8db;
  transform: translateY(-1px);
}

.chat-stop:focus-visible {
  outline: 3px solid var(--gold-light);
  outline-offset: 2px;
}

.chat-stop.hidden {
  display: none;
}

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

/* Temporary right-side bubble shown while a voice recording is transcribed */
.chat-voice-loading {
  justify-content: center;
  min-width: 64px;
}

.chat-voice-loading-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;
}

.chat-voice-loading-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: chat-voice-loading-bounce 1.2s ease-in-out infinite;
}

.chat-voice-loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-voice-loading-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-voice-loading-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Label appended to an assistant response the customer stopped */
.answer-stopped {
  display: block;
  margin-top: 6px;
  color: #8a8570;
  font-size: 12px;
  font-style: italic;
}

/* Voice recording bar — replaces the composer controls while recording */
.chat-voice-composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 16px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 4px 16px rgb(39 58 40 / 5%);
}

.chat-voice-composer.hidden {
  display: none;
}

.chat-recording-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #bd5043;
  box-shadow: 0 0 0 4px #f8e9e6;
  animation: chat-recording-pulse 1.4s ease-in-out infinite;
}

.chat-voice-composer.paused .chat-recording-dot {
  background: #a6a99b;
  box-shadow: 0 0 0 4px #f0f1eb;
  animation: none;
}

@keyframes chat-recording-pulse {
  0%, 100% { box-shadow: 0 0 0 4px #f8e9e6; }
  50% { box-shadow: 0 0 0 7px #f8e9e6; }
}

.chat-voice-status {
  flex: 1;
  min-width: 0;
  color: #5d6a5e;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.chat-voice-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #f6f1e5;
  color: var(--forest);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.chat-voice-button:hover {
  background: #eee5d3;
}

.chat-voice-button:focus-visible {
  outline: 3px solid var(--gold-light);
  outline-offset: 2px;
}

.chat-voice-button svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.chat-voice-primary {
  background: var(--forest);
  border-color: var(--forest);
  color: var(--ivory);
}

.chat-voice-primary:hover {
  background: var(--olive);
  border-color: var(--olive);
}

/* Voice error line */
.chat-voice-error {
  margin: 8px 2px 0;
  color: #b3261e;
  font-size: 12px;
  line-height: 1.4;
}

.chat-voice-error.hidden {
  display: none;
}

.chat-status {
  padding: 0 16px;
  flex-shrink: 0;
}


/* Responsive */
@media (max-width: 480px) {
  .chat-panel {
    width: calc(100vw - 32px);
    height: 60vh;
    bottom: 24px;
    right: 16px;
    border-radius: 16px;
    transition: height 0.25s ease;
  }

  .chat-panel.chat-panel-expanded {
    height: calc(100vh - 48px);
  }

  .chat-header {
    cursor: pointer;
  }

  .chat-header .chat-actions {
    cursor: default;
  }

  .chat-launcher {
    bottom: 16px;
    right: 16px;
    width: 72px;
    height: 72px;
  }

  .chat-launcher-art {
    width: 72px;
    height: 72px;
  }

  .chat-launcher-logo {
    width: 36px;
    height: 36px;
  }
}

/* Pending / streaming state */
.chat-pending {
  opacity: 0.7;
}

.chat-table-scroll {
  overflow-x: auto;
  max-width: 100%;
  margin: 8px 0;
}

.chat-table-scroll table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

.chat-table-scroll th,
.chat-table-scroll td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.chat-table-scroll th {
  background: var(--forest);
  color: var(--ivory);
  font-weight: bold;
}

/* Copy button for completed assistant responses */
.chat-copy-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  margin: -6px 0 0 2px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #718071;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  align-self: flex-start;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.chat-copy-button:hover {
  background: #e9eee3;
  color: var(--forest);
}

.chat-copy-button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.chat-copy-button svg {
  width: 15px;
  height: 15px;
}

.chat-copy-button.copied {
  color: var(--forest);
}
