/* Chat Modal Redesign - Container & Layout Styles */

/*
 * Task 1.1: Modal container styles
 * - Centered ~75vw x 75vh dialog with large rounded corners
 * - Backdrop blur overlay
 * - White content area with shadow, no border
 * - Fullscreen fallback on small viewports
 */

/* Centered dialog occupying ~75% of the viewport */
#modalChat .chat-modal-dialog {
  width: 80vw;
  max-width: 80vw;
  height: 85vh;
  margin: auto;
  display: flex;
  align-items: center;
  min-height: calc(100% - 1rem);
}

/* Modal content: white background, rounded, shadow, no border */
#modalChat .chat-modal-content {
  width: 100%;
  height: 85vh;
  max-height: 100%;
  background-color: #ffffff;
  border: none;
  border-radius: 1.25rem;
  box-shadow: 0 1.5rem 3rem rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

/* Backdrop blur so the page behind stays partially visible */
#modalChat.modal {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-backdrop.show,
#modalChat ~ .modal-backdrop.show {
  background-color: rgba(17, 24, 39, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 1;
}

/* Responsive: fullscreen layout on mobile */
@media (max-width: 768px) {
  #modalChat .chat-modal-dialog {
    width: 100%;
    max-width: 100%;
    height: 100%;
    margin: 0;
    min-height: 100%;
  }

  #modalChat .chat-modal-content {
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
}
/*
 * Task 1.3: Modal header styles
 * - Header flex layout with bottom border
 * - Left block: bot icon + title/subtitle
 * - Pill-shaped action buttons
 * Requirements: 2.1, 2.2, 2.3, 2.4
 */

/* Header row: left block on the left, action buttons on the right */
#modalChat .chat-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #eceef2;
}

/* Left block: bot icon + title/subtitle */
#modalChat .chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

/* Styled bot icon container */
#modalChat .chat-header-bot-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #7b6ef0, #6c5ce7);
  color: #ffffff;
  font-size: 1.35rem;
  line-height: 1;
}

/* Title block wrapper */
#modalChat .chat-header-title {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

/* Main title text */
#modalChat .chat-title-text {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
  color: #1f2430;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Subtitle text (subject + school level) */
#modalChat .chat-subtitle-text {
  font-size: 0.8125rem;
  line-height: 1.2;
  color: #8a909d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Right-side action buttons group */
#modalChat .chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Soft rounded action buttons */
#modalChat .chat-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid #e7e9f2;
  border-radius: 12px;
  background-color: #ffffff;
  color: #3f4557;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

#modalChat .chat-pill-btn i {
  font-size: 1.05rem;
  line-height: 1;
  color: #6c5ce7;
}

#modalChat .chat-pill-btn:hover {
  background-color: #f7f7fe;
  border-color: #d9d5fb;
  color: #1f2430;
  box-shadow: 0 2px 6px rgba(108, 92, 231, 0.12);
}

/* Disabled pill button state */
#modalChat .chat-pill-btn.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

/* Responsive: hide pill button labels on small viewports, keep icons */
@media (max-width: 768px) {
  #modalChat .chat-modal-header {
    padding: 0.75rem 1rem;
  }

  #modalChat .chat-pill-btn span {
    display: none;
  }

  #modalChat .chat-pill-btn {
    padding: 0.375rem 0.5rem;
  }
}
/*
 * Task 2.3: Message rendering styles
 * - Message rows (avatar + bubble + timestamp) with per-role alignment
 * - Avatars, timestamps, and assistant message action icons
 * Requirements: 3.1, 3.2, 3.3, 4.1, 7.2
 */

/* Message row: flex layout wrapping avatar + bubble column */
#modalChat .cw-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: 100%;
}

/* User messages align to the right, assistant messages to the left */
#modalChat .cw-msg-row-user {
  justify-content: flex-end;
}

#modalChat .cw-msg-row-assist {
  justify-content: flex-start;
}

/* Column holding the bubble, timestamp, and actions */
#modalChat .cw-bubble-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: calc(100% - 2.75rem);
}

#modalChat .cw-msg-row-user .cw-bubble-col {
  align-items: flex-end;
}

#modalChat .cw-msg-row-assist .cw-bubble-col {
  align-items: flex-start;
}

/* Message bubble: alignment now handled by the row, not self-alignment */
#modalChat .cw-bubble {
  max-width: 100%;
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  overflow: visible;
}

/* User bubble: soft lavender background; assistant bubble: white with border */
#modalChat .cw-user {
  background: #efeafe;
  color: #3a3f51;
}

#modalChat .cw-assist {
  background: #ffffff;
  color: #212529;
  border: 1px solid #e9ecef;
}

/* Avatar: 32px circle with cover-fit images */
#modalChat .cw-avatar {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 1.15rem;
}

#modalChat .cw-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#modalChat .cw-avatar-bot {
  background: #e7f1ff;
  color: #0d6efd;
}

#modalChat .cw-avatar-user {
  background: #6c757d;
  color: #ffffff;
  font-size: 1rem;
}

/* Timestamp: small muted text below the bubble */
#modalChat .cw-timestamp {
  font-size: 0.7rem;
  color: #adb5bd;
  margin-top: 2px;
  padding: 0 0.3rem;
}

/* Assistant message action icons (copy / read-aloud / thumbs-up) */
#modalChat .cw-msg-actions {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.15rem;
  padding: 0 0.3rem;
}

#modalChat .cw-msg-row-user .cw-msg-actions {
  justify-content: flex-end;
}

#modalChat .cw-msg-action {
  background: none;
  border: none;
  color: #adb5bd;
  cursor: pointer;
  padding: 0.15rem 0.3rem;
  border-radius: 0.35rem;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  transition: color 0.15s ease, background 0.15s ease;
}

#modalChat .cw-msg-action:hover {
  color: #6c5ce7;
  background: #f2f0fd;
}

/* Active (toggled) state for feedback actions such as read-aloud.
 * Matches the `cw-msg-action-active` class toggled by chat-widget.js. */
#modalChat .cw-msg-action-active {
  color: #6c5ce7;
}

/* Transient success state shown after a successful copy-to-clipboard. */
#modalChat .cw-msg-action-done {
  color: #198754;
}
/*
 * Task 3.2: Quick action chip styles
 * - Horizontal, scrollable row of pill-shaped chips (icon + label)
 * - Hover / active states
 * - Disabled state while a message is in-flight
 * Requirements: 5.4
 */

/* Chips container: horizontal row that scrolls when it overflows */
#modalChat .cw-quick-chips {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* Slim scrollbar for the chips row */
#modalChat .cw-quick-chips::-webkit-scrollbar {
  height: 4px;
}

#modalChat .cw-quick-chips::-webkit-scrollbar-thumb {
  background: #d9dce3;
  border-radius: 999px;
}

/* Soft rounded chip: light border, purple icon + text label */
#modalChat .cw-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
  padding: 0.6rem 1rem;
  border: 1px solid #e7e9f2;
  border-radius: 14px;
  background-color: #ffffff;
  color: #3f4557;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

#modalChat .cw-chip i {
  font-size: 1.15rem;
  line-height: 1;
  color: #6c5ce7;
}

/* Hover state */
#modalChat .cw-chip:hover {
  background-color: #f7f7fe;
  border-color: #d9d5fb;
  color: #1f2430;
  box-shadow: 0 2px 6px rgba(108, 92, 231, 0.12);
}

/* Active / pressed state */
#modalChat .cw-chip:active {
  background-color: #efedfd;
  border-color: #cfc8fa;
}

/* Disabled state while a message is in-flight.
 * Supports the native :disabled attribute, an `is-disabled` class on the chip,
 * and an `is-loading` class on the container. */
#modalChat .cw-chip:disabled,
#modalChat .cw-chip.is-disabled,
#modalChat .cw-quick-chips.is-loading .cw-chip {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
  background-color: #f4f5f8;
  border-color: #e2e5eb;
  color: #a2a8b4;
}
/*
 * Task 4.3: Input area styles
 * - Flex input row: attachment icon + textarea + circular send button
 * - Helper text centered below the input
 * - Textarea with no resize, rounded corners, and a focus ring
 * Requirements: 6.1, 6.2, 6.3, 6.4, 7.1
 */

/* Input row: paperclip on the left, textarea in the middle, send on the right */
#modalChat .cw-input-area {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem 0.25rem;
  border-top: 1px solid #eceef2;
  background-color: #ffffff;
}

/* Attachment (paperclip) button: bordered rounded-square icon button */
#modalChat .cw-attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid #e7e9f2;
  border-radius: 14px;
  background: #ffffff;
  color: #8a909d;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

#modalChat .cw-attach-btn i {
  line-height: 1;
}

#modalChat .cw-attach-btn:hover {
  background-color: #f7f7fe;
  border-color: #d9d5fb;
  color: #6c5ce7;
}

/* Active state: an image is currently attached */
#modalChat .cw-attach-btn.cw-attach-active {
  color: #6c5ce7;
  background-color: #f0eefe;
  border-color: #d9d5fb;
}

/* Textarea: no manual resize, rounded corners, focus ring */
#modalChat .cw-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  max-height: 8rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid #d9dce3;
  border-radius: 1.25rem;
  background-color: #ffffff;
  color: #1f2430;
  font-size: 0.9375rem;
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#modalChat .cw-input::placeholder {
  color: #a2a8b4;
}

#modalChat .cw-input:focus {
  border-color: #6c5ce7;
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.18);
}

/* Rounded-square send button with purple gradient and white arrow icon */
#modalChat .cw-send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  padding: 0;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #7b6ef0, #6c5ce7);
  color: #ffffff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(108, 92, 231, 0.35);
  transition: filter 0.15s ease, transform 0.05s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

#modalChat .cw-send-btn i {
  line-height: 1;
}

#modalChat .cw-send-btn:hover {
  filter: brightness(1.08);
}

#modalChat .cw-send-btn:active {
  transform: scale(0.95);
}

#modalChat .cw-send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

/* Helper text: small, muted, centered below the input row */
#modalChat .cw-input-helper {
  padding: 0.25rem 1rem 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: #a2a8b4;
  line-height: 1.3;
}
/*
 * Task 6.4: Modal open/close transitions
 * - Smooth scale + fade on the dialog when the modal shows/hides
 * - Follows Bootstrap's `.modal.fade`/`.modal.show` convention
 * - Disables the transform animation under prefers-reduced-motion
 * Requirements: 7.5
 */

/* Closed/opening state: dialog is slightly scaled down and transparent */
#modalChat.modal.fade .chat-modal-dialog {
  opacity: 0;
  transform: scale(0.92);
  transition: transform 0.25s ease-out, opacity 0.25s ease-out;
}

/* Open state: dialog scales up to full size and fades in */
#modalChat.modal.show .chat-modal-dialog {
  opacity: 1;
  transform: scale(1);
}

/* Respect users who prefer reduced motion: keep the fade, drop the scale */
@media (prefers-reduced-motion: reduce) {
  #modalChat.modal.fade .chat-modal-dialog {
    transform: none;
    transition: opacity 0.15s linear;
  }

  #modalChat.modal.show .chat-modal-dialog {
    transform: none;
  }
}
