/* Webchat specific styles */

/* Override base theme colors for webchat */
:root {
  /* Inherit all base variables from common.css */
  /* Only add webchat-specific variables */
  --chat-bubble-user: var(--primary-color);
  --chat-bubble-bot: #f0f0f0;
}

/* Logo styles - specific to webchat */
.dor-logo {
  display: block;
  margin: 20px auto 40px;
  width: 150px;
  height: auto;
  transition: transform 0.2s ease;
}

.dor-logo:hover {
  transform: scale(1.05);
}

/* Welcome container styles */
.container {
  max-width: 600px;
  width: calc(100% - 40px);
  padding: 20px;
  background: var(--light-bg);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  border-radius: 10px;
  margin: 40px auto 0 auto;
  text-align: center;
}

/* Chat Widget */
#chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 100%;
  height: 82vh;
  max-width: 450px;
  max-height: 82vh;
  background: var(--light-bg);
  border-radius: 10px;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
  z-index: 1000;
}

.chat-header {
  background: var(--primary-color);
  color: white;
  padding: 15px 20px;
  font-size: clamp(14px, 4vw, 16px);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.close-button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 24px;
  padding: 8px;
  margin: -8px;
  line-height: 1;
}

.grievance-filed-banner {
  background: #e8f5e9;
  border-bottom: 1px solid #a5d6a7;
  color: #1b5e20;
  font-size: 13px;
  padding: 8px 12px;
  text-align: center;
}

.grievance-filed-banner.hidden {
  display: none;
}

/* CB-01 / CB-08: voice + file upload status (above composer toolbar) */
.composer-top {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
}

.voice-status-banner {
  background: #e3f2fd;
  border-bottom: 1px solid #90caf9;
  color: #0d47a1;
  font-size: 13px;
  line-height: 1.35;
  padding: 8px 12px;
  text-align: center;
  width: 100%;
}

.voice-status-banner.is-error {
  background: #ffebee;
  border-bottom-color: #ef9a9a;
  color: #b71c1c;
}

.voice-status-banner.hidden {
  display: none;
}

.grievance-filed-banner strong {
  font-weight: 600;
}

.composer-close-icon-btn.is-hidden,
.persistent-control-button.is-hidden {
  display: none;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.message-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 15px;
  margin: 0;
  font-size: clamp(13px, 3.5vw, 14px);
  line-height: 1.4;
  word-wrap: break-word;
}

.timestamp {
  font-size: clamp(11px, 3vw, 12px);
  color: var(--text-muted);
  margin: 2px 4px;
}

.message_received {
  background: var(--chat-bubble-bot);
  color: var(--text-color);
  border-bottom-left-radius: 5px;
  align-self: flex-start;
}

.message_sent {
  background: var(--chat-bubble-user);
  color: white;
  border-bottom-right-radius: 5px;
  align-self: flex-end;
}

/* Quick Replies */
.quick-replies {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 4px 0;
}

.quick-reply-button {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: clamp(14px, 3.5vw, 16px);
  transition: background-color 0.2s, transform 0.1s;
  margin: 4px;
  white-space: nowrap;
}

.quick-reply-button:hover {
  background: var(--secondary-color);
}

.quick-reply-button:active {
  transform: scale(0.95);
}

/* Chat Form */
#form,
#form.composer {
  padding: 10px 15px;
  background: var(--light-bg);
  border-top: 1px solid #eee;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  position: relative;
}

.composer-input {
  width: 100%;
  flex: 0 0 auto;
}

.composer-toolbar {
  --composer-btn-gap: 8px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
}

.composer-toolbar-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--composer-btn-gap);
}

.composer-toolbar-left {
  justify-content: flex-start;
}

.composer-toolbar-right {
  justify-content: flex-end;
}

.composer-round-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  flex: 0 0 auto;
  box-sizing: border-box;
}

.composer-close-icon-btn.is-hidden {
  display: none;
}

.composer-close-icon-btn {
  background: #f0f2f5;
  border: none;
  color: #54656f;
  cursor: pointer;
}

.composer-close-icon-btn:hover {
  background: #e4e6eb;
  color: #333;
}

#message-input {
  flex: 1;
  padding: 12px 15px;
  border: 1px solid #ddd;
  border-radius: 20px;
  outline: none;
  font-size: clamp(13px, 3.5vw, 14px);
  min-height: 44px;
  max-height: calc(6 * 1.4em + 24px); /* 6 lines + padding */
  resize: none;
  overflow-y: auto;
  line-height: 1.4;
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
}

#message-input:disabled {
  background: #f5f5f5;
  color: #888;
  cursor: not-allowed;
}

/* Attach + voice: grey when inactive; light grey bg + blue icon when active */
.attachment-button,
.voice-note-button {
  background: #e9ecef;
  border: none;
  color: #adb5bd;
  cursor: not-allowed;
}

.attachment-button.is-active:not(:disabled),
.voice-note-button.is-active:not(:disabled) {
  background: #f0f2f5;
  color: var(--primary-color);
  cursor: pointer;
}

.attachment-button.is-active:not(:disabled):hover,
.voice-note-button.is-active:not(:disabled):hover {
  background: #e4e6eb;
}

.send-button {
  background: var(--primary-color);
  color: white;
  border: none;
}

.send-button:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.8;
}

.send-button svg {
  width: 22px;
  height: 22px;
  /* Nudge icon like WhatsApp: plane sits slightly up-left in the circle */
  transform: translate(-1px, -1px);
}

.send-button-wrap {
  position: relative;
  display: flex;
  align-items: flex-end;
}

.send-invalid-tooltip {
  position: absolute;
  bottom: 52px;
  right: 0;
  background: #c0392b;
  color: #fff;
  font-size: 12px;
  line-height: 1.3;
  padding: 7px 10px;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 20;
}

.send-invalid-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 14px;
  border-width: 6px;
  border-style: solid;
  border-color: #c0392b transparent transparent transparent;
}

.send-invalid-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.attachment-button svg {
  width: 20px;
  height: 20px;
}

/* File Upload */
.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  padding: 0 15px;
}

.file-item {
  background: #eee;
  padding: 8px 12px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  font-size: 12px;
}

.file-item-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 10px;
}

.file-item-remove {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 14px;
  padding: 0 5px;
}

/* Launcher zone (button + arc arrow hint) */
.chat-launcher-zone {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
}

.chat-launcher-hint {
  /* Clear launcher (72px) + border + pulse ring (~1.4×) + gap */
  position: fixed;
  right: 118px;
  bottom: 72px;
  width: min(50vw, 400px);
  height: min(38vh, 280px);
  color: var(--primary-color);
  pointer-events: none;
  overflow: visible;
  z-index: 998;
}

.chat-launcher-hint-sketch {
  fill: none;
  stroke: currentColor;
  stroke-width: 5.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.2;
}

.chat-launcher-hint-path {
  fill: none;
  stroke: currentColor;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 310;
  stroke-dashoffset: 310;
  animation: launcher-hint-draw 3.2s ease-in-out infinite;
}

@keyframes launcher-hint-draw {
  0% {
    stroke-dashoffset: 310;
    opacity: 0.4;
  }
  42% {
    stroke-dashoffset: 0;
    opacity: 1;
  }
  68% {
    stroke-dashoffset: 0;
    opacity: 1;
  }
  100% {
    stroke-dashoffset: 310;
    opacity: 0.4;
  }
}

#chat-launcher {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary-color);
  border: 3px solid rgba(255, 255, 255, 0.95);
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(4, 105, 173, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  animation: launcher-attention 2.4s ease-in-out infinite;
}

#chat-launcher::before {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(4, 105, 173, 0.4);
  animation: launcher-ring-pulse 2.4s ease-out infinite;
  pointer-events: none;
}

@keyframes launcher-attention {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 4px 18px rgba(4, 105, 173, 0.4);
  }
  50% {
    transform: scale(1.07);
    box-shadow: 0 8px 28px rgba(4, 105, 173, 0.55);
  }
}

@keyframes launcher-ring-pulse {
  0% {
    transform: scale(0.92);
    opacity: 0.85;
  }
  75% {
    transform: scale(1.4);
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

#chat-launcher:hover {
  transform: scale(1.12);
  background: var(--secondary-color);
  animation: none;
}

#chat-launcher:hover::before {
  animation: none;
  opacity: 0;
}

#chat-launcher svg {
  width: 34px;
  height: 34px;
  fill: white;
}

@media (prefers-reduced-motion: reduce) {
  #chat-launcher,
  #chat-launcher::before,
  .chat-launcher-hint-path {
    animation: none !important;
  }

  .chat-launcher-hint-path {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}

/* Mobile Styles */
@media (max-width: 480px) {
  #chat-widget {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    margin: 0;
  }

  .container {
    margin: 10px;
    padding: 15px;
  }

  #form {
    padding: 10px;
  }

  .chat-launcher-zone {
    bottom: 15px;
    right: 15px;
  }

  .chat-launcher-hint {
    right: 96px;
    width: min(58vw, 220px);
    height: min(32vh, 200px);
    bottom: 66px;
  }

  #chat-launcher {
    width: 64px;
    height: 64px;
  }

  #chat-launcher svg {
    width: 30px;
    height: 30px;
  }

  .quick-reply-button {
    padding: 12px 20px;
    min-height: 44px;
  }
}

/* High contrast mode */
body.high-contrast #chat-widget {
  background: var(--light-bg);
  border: 2px solid var(--border-color);
}

body.high-contrast .chat-header {
  background: var(--primary-color);
  border-bottom: 2px solid var(--border-color);
}

body.high-contrast .message_received {
  background: var(--light-bg);
  border: 2px solid var(--border-color);
}

body.high-contrast .message_sent {
  background: var(--primary-color);
  border: 2px solid var(--border-color);
}

body.high-contrast #chat-launcher {
  background: var(--primary-color);
  border: 2px solid var(--border-color);
}

body.high-contrast .chat-launcher-hint {
  color: var(--text-color);
}

/* CB-01 voice note — recording overrides active/hover secondary styles */
.voice-note-button.is-recording,
.voice-note-button.is-active.is-recording:not(:disabled),
.voice-note-button.is-active.is-recording:not(:disabled):hover {
  background: #e53935;
  color: #fff;
  cursor: pointer;
  animation: voice-record-blink 1.1s ease-in-out infinite;
}

.voice-note-button.is-recording .voice-note-icon {
  color: #fff;
}

.voice-note-button .voice-note-icon {
  display: block;
}

.voice-status-banner.is-recording {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

@keyframes voice-record-blink {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.55);
  }
  50% {
    opacity: 0.82;
    box-shadow: 0 0 0 7px rgba(229, 57, 53, 0.18);
  }
}

@media (prefers-reduced-motion: reduce) {
  .voice-note-button.is-recording,
  .voice-note-button.is-active.is-recording:not(:disabled),
  .voice-note-button.is-active.is-recording:not(:disabled):hover {
    animation: none;
    opacity: 1;
  }
}

/* CB-06 map picker */
.map-picker-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.map-picker-modal.hidden {
  display: none;
}

.map-picker-panel {
  background: var(--light-bg);
  border-radius: 12px;
  max-width: 520px;
  width: 100%;
  padding: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.map-picker-map {
  height: 280px;
  width: 100%;
  border-radius: 8px;
  margin: 12px 0;
}

.map-picker-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.map-picker-confirm {
  width: auto;
  height: auto;
  border-radius: 8px;
  padding: 10px 16px;
}

body.high-contrast .quick-reply-button {
  background: var(--primary-color);
  border: 2px solid var(--border-color);
}

body.high-contrast .send-button {
  background: var(--primary-color);
  border: 2px solid var(--border-color);
}

body.high-contrast .file-item {
  background: var(--light-bg);
  border: 2px solid var(--border-color);
}

body.high-contrast .timestamp,
body.high-contrast .session-divider {
  color: var(--text-color);
}

/* Ensure the logo link is only as wide as the image and centered */
a:has(> .dor-logo) {
  display: inline-block;
  width: auto;
  margin: 0 auto;
}

.task-status {
  background-color: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 14px;
  color: #495057;
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: fadeIn 0.3s ease-in-out;
}

.task-status::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  background-color: #6c757d;
  animation: pulse 1.5s infinite;
}

.task-status.success {
  background-color: #d4edda;
  border-color: #c3e6cb;
  color: #155724;
}

.task-status.success::before {
  background-color: #28a745;
  animation: none;
}

.task-status.error {
  background-color: #f8d7da;
  border-color: #f5c6cb;
  color: #721c24;
}

.task-status.error::before {
  background-color: #dc3545;
  animation: none;
}

.task-status.progress {
  background-color: #d1ecf1;
  border-color: #bee5eb;
  color: #0c5460;
}

.task-status.progress::before {
  background-color: #17a2b8;
  animation: pulse 1.5s infinite;
}

.task-status.info {
  background-color: #e2e3e5;
  border-color: #d6d8db;
  color: #383d41;
}

.task-status.info::before {
  background-color: #6c757d;
  animation: none;
}

@keyframes pulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(108, 117, 125, 0.7);
  }

  70% {
    transform: scale(1);
    box-shadow: 0 0 0 6px rgba(108, 117, 125, 0);
  }

  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(108, 117, 125, 0);
  }
}

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