/**
 * NVQ Expert AI Assistant - Widget Styles
 * Scoped to .nvqai-* classes to prevent theme conflicts.
 * Companion to nvq-expert.js. Load via the plugin's PHP loader.
 */

/* ==========================================================================
   Base (scoped reset)
   ========================================================================== */

.nvqai-fab,
.nvqai-widget,
.nvqai-widget * {
  box-sizing: border-box;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.nvqai-widget button,
.nvqai-fab {
  font-family: inherit;
}

/* ==========================================================================
   Floating Action Button
   Default: pill with label, bottom-right (standard chat widget position).
   Compact variant (.nvqai-fab--compact): circular icon-only, middle-right.
   Applied on tutor mode (mock test pages) so it doesn't cover test UI.
   ========================================================================== */

.nvqai-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 22px 12px 18px;
  background: #d6780f;
  border: none;
  border-radius: 999px;
  box-shadow: 0 4px 18px rgba(214, 120, 15, 0.35), 0 2px 6px rgba(25, 25, 30, 0.15);
  color: #ffffff;
  cursor: pointer;
  z-index: 999998;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s ease;
  white-space: nowrap;
}

.nvqai-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(214, 120, 15, 0.45), 0 3px 8px rgba(25, 25, 30, 0.2);
  background: #b85f08;
}

.nvqai-fab.nvqai-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.9);
}

.nvqai-fab svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nvqai-fab-label {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.2px;
  line-height: 1;
}

/* Compact mode: circular icon, bottom-left. Used on mock test pages
   so the FAB stays out of the way of sticky test UI (Next Question, Flag,
   scroll-to-top etc). Gets a tooltip on hover/long-press to explain itself. */
.nvqai-fab--compact {
  bottom: 20px;
  left: 20px;
  right: auto;
  top: auto;
  transform: none;
  width: 50px;
  height: 50px;
  padding: 0;
  border-radius: 50%;
  justify-content: center;
}

.nvqai-fab--compact:hover {
  transform: scale(1.06);
  background: #b85f08;
}

.nvqai-fab--compact.nvqai-hidden {
  transform: scale(0.85);
}

.nvqai-fab--compact .nvqai-fab-label {
  /* Visually hidden, kept for screen readers */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.nvqai-fab--compact svg {
  width: 24px;
  height: 24px;
}

/* Tooltip - hidden by default, only renders on compact FAB */
.nvqai-fab-tooltip {
  display: none;
}

.nvqai-fab--compact .nvqai-fab-tooltip {
  display: block;
  position: absolute;
  bottom: calc(100% + 12px);
  left: 0;
  white-space: nowrap;
  padding: 8px 14px;
  background: #1a1a1a;
  color: #ffffff;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.1px;
  line-height: 1.2;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.nvqai-fab--compact .nvqai-fab-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 18px;
  border: 6px solid transparent;
  border-top-color: #1a1a1a;
}

/* Desktop: show tooltip on hover */
@media (hover: hover) {
  .nvqai-fab--compact:hover .nvqai-fab-tooltip {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile long-press: JS toggles this class */
.nvqai-fab--compact.nvqai-fab--tooltip-visible .nvqai-fab-tooltip {
  opacity: 1;
  transform: translateY(0);
}

/* Advisor pill variant gets the same tooltip structure, positioned above
   and aligned to the right edge of the pill. Only visible when JS applies
   the .nvqai-fab--tooltip-visible class (scroll-triggered, once per session). */
.nvqai-fab:not(.nvqai-fab--compact) .nvqai-fab-tooltip {
  display: block;
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  white-space: nowrap;
  padding: 8px 14px;
  background: #1a1a1a;
  color: #ffffff;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.1px;
  line-height: 1.2;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.nvqai-fab:not(.nvqai-fab--compact) .nvqai-fab-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 22px;
  border: 6px solid transparent;
  border-top-color: #1a1a1a;
}

.nvqai-fab:not(.nvqai-fab--compact).nvqai-fab--tooltip-visible .nvqai-fab-tooltip {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   Widget Container
   ========================================================================== */
.nvqai-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  height: 620px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(25, 25, 30, 0.25);
  overflow: hidden;
  z-index: 999999;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  color: #1a1a1a;
  font-size: 14px;
  line-height: 1.5;
}

.nvqai-widget.nvqai-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ==========================================================================
   Header
   ========================================================================== */

.nvqai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, #d6780f 0%, #e8810c 100%);
  color: #ffffff;
  flex-shrink: 0;
}

.nvqai-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.nvqai-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  flex-shrink: 0;
}

.nvqai-title {
  font-family: 'IBM Plex Mono', 'SF Mono', Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.2px;
  line-height: 1.2;
}

.nvqai-subtitle {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 2px;
  line-height: 1.2;
}

.nvqai-close {
  background: none;
  border: none;
  color: #ffffff;
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  transition: opacity 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}

.nvqai-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

/* ==========================================================================
   Messages Area
   ========================================================================== */

.nvqai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  background: #fafaf8;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.nvqai-messages::-webkit-scrollbar {
  width: 6px;
}

.nvqai-messages::-webkit-scrollbar-thumb {
  background: #d4d4d0;
  border-radius: 3px;
}

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

.nvqai-msg-row {
  display: flex;
  width: 100%;
}

.nvqai-msg-row.user {
  justify-content: flex-end;
}

.nvqai-msg-row.assistant {
  justify-content: flex-start;
}

.nvqai-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.nvqai-bubble.assistant {
  background: #ffffff;
  border: 1px solid #ececec;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
}

.nvqai-bubble.user {
  background: #d6780f;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.nvqai-system-msg {
  align-self: center;
  max-width: 92%;
  padding: 10px 14px;
  background: #fff3e0;
  border: 1px solid #f5d4a8;
  border-radius: 10px;
  font-size: 13px;
  color: #5c3c0a;
  text-align: center;
  line-height: 1.5;
}

/* Typing indicator */

.nvqai-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: #ffffff;
  border: 1px solid #ececec;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.nvqai-typing span {
  width: 6px;
  height: 6px;
  background: #b8b8b8;
  border-radius: 50%;
  animation: nvqai-typing-dot 1.2s infinite;
}

.nvqai-typing span:nth-child(2) { animation-delay: 0.15s; }
.nvqai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes nvqai-typing-dot {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30%           { opacity: 1;    transform: translateY(-3px); }
}

/* ==========================================================================
   Input Area
   ========================================================================== */

.nvqai-input-area {
  padding: 12px 14px 10px;
  background: #ffffff;
  border-top: 1px solid #ececec;
  flex-shrink: 0;
}

.nvqai-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f5f5f1;
  border: 1.5px solid #eaeae3;
  border-radius: 22px;
  padding: 4px 4px 4px 14px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.nvqai-input-row:focus-within {
  border-color: #d6780f;
  background: #ffffff;
}

.nvqai-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 16px; /* 16px minimum prevents iOS auto-zoom on focus */
  color: #1a1a1a;
  padding: 8px 0;
  font-family: inherit;
  min-width: 0;
}

.nvqai-input:disabled {
  cursor: not-allowed;
}

.nvqai-input::placeholder {
  color: #999999;
}

.nvqai-send {
  background: #d6780f;
  color: #ffffff;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(214, 120, 15, 0.3);
}

.nvqai-send svg {
  width: 18px;
  height: 18px;
}

.nvqai-send:hover:not(:disabled) {
  background: #b85f08;
  transform: scale(1.06);
  box-shadow: 0 3px 10px rgba(214, 120, 15, 0.4);
}

.nvqai-send:disabled {
  background: #cccccc;
  cursor: not-allowed;
  box-shadow: none;
}

.nvqai-footer {
  text-align: center;
  font-size: 10.5px;
  color: #888888;
  margin-top: 8px;
  line-height: 1.4;
}

.nvqai-footer a {
  color: #4144e8;
  text-decoration: underline;
}

.nvqai-footer a:hover {
  color: #d6780f;
}

/* ==========================================================================
   Form Cards (shared)
   ========================================================================== */

.nvqai-form-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 18px;
  margin: 4px 0;
  box-shadow: 0 2px 10px rgba(25, 25, 30, 0.06);
}

.nvqai-form-enrolment {
  border: 1.5px solid #d6780f;
  background: linear-gradient(180deg, #fff9f2 0%, #ffffff 45%);
}

.nvqai-form-nurture {
  border: 1.5px solid #4144e8;
  background: linear-gradient(180deg, #f3f3ff 0%, #ffffff 45%);
}

.nvqai-form-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.nvqai-form-title {
  font-family: 'IBM Plex Mono', 'SF Mono', Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
  letter-spacing: 0.2px;
}

.nvqai-form-desc {
  font-size: 13px;
  color: #555555;
  line-height: 1.5;
  margin-bottom: 14px;
}

.nvqai-form-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.nvqai-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #444444;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.nvqai-label .req {
  color: #d6780f;
  font-weight: 700;
}

.nvqai-field {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #e0e0d8;
  border-radius: 8px;
  font-size: 16px; /* 16px minimum prevents iOS auto-zoom on focus */
  font-family: inherit;
  font-weight: normal;
  text-transform: none;
  letter-spacing: 0;
  color: #1a1a1a;
  background: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.nvqai-field:focus {
  outline: none;
  border-color: #d6780f;
  box-shadow: 0 0 0 3px rgba(214, 120, 15, 0.12);
}

select.nvqai-field {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%23555' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='1 1.5 6 6.5 11 1.5'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.nvqai-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.nvqai-form-error {
  display: none;
  font-size: 12px;
  color: #c0392b;
  background: #fdecea;
  border: 1px solid #f5c6c0;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 10px;
  line-height: 1.4;
}

.nvqai-submit-dark,
.nvqai-submit-brand {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.nvqai-submit-dark {
  background: #1a1a1a;
  color: #ffffff;
}

.nvqai-submit-dark:hover:not(:disabled) {
  background: #333333;
}

.nvqai-submit-brand {
  background: #4144e8;
  color: #ffffff;
}

.nvqai-submit-brand:hover:not(:disabled) {
  background: #2f32c4;
}

.nvqai-submit-dark:disabled,
.nvqai-submit-brand:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.nvqai-submit-dark:active:not(:disabled),
.nvqai-submit-brand:active:not(:disabled) {
  transform: translateY(1px);
}

.nvqai-smallprint {
  font-size: 11px;
  color: #888888;
  margin-top: 10px;
  line-height: 1.4;
  text-align: center;
}

.nvqai-smallprint a {
  color: #4144e8;
  text-decoration: underline;
}

/* ==========================================================================
   Nurture-specific
   ========================================================================== */

.nvqai-guide-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #ffffff;
  border: 1.5px solid #e0e0d8;
  border-radius: 10px;
  padding: 12px 14px;
  text-decoration: none;
  color: #1a1a1a;
  margin-bottom: 14px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.nvqai-guide-link:hover {
  border-color: #d6780f;
  background: #fff9f2;
}

.nvqai-guide-title {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 2px;
}

.nvqai-guide-sub {
  font-size: 11.5px;
  color: #777777;
}

.nvqai-divider-label {
  font-size: 10.5px;
  font-weight: 600;
  color: #888888;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  text-align: center;
  margin: 6px 0 10px;
  position: relative;
}

.nvqai-divider-label::before,
.nvqai-divider-label::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 32%;
  height: 1px;
  background: #e4e4de;
}

.nvqai-divider-label::before { left: 0; }
.nvqai-divider-label::after  { right: 0; }

.nvqai-reminder-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.nvqai-reminder-options button {
  padding: 8px 6px;
  background: #ffffff;
  border: 1.5px solid #e0e0d8;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #555555;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.nvqai-reminder-options button:hover {
  border-color: #4144e8;
  color: #4144e8;
}

.nvqai-reminder-options button.selected {
  background: #4144e8;
  border-color: #4144e8;
  color: #ffffff;
}

/* ==========================================================================
   Success cards
   ========================================================================== */

.nvqai-success {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 10px;
  margin: 4px 0;
  line-height: 1.5;
}

.nvqai-success.enrolment {
  background: #fff9f2;
  border: 1.5px solid #f5c27a;
}

.nvqai-success.nurture {
  background: #f3f3ff;
  border: 1.5px solid #c4c6f5;
}

.nvqai-success svg {
  flex-shrink: 0;
  margin-top: 1px;
}

.nvqai-success-title {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 2px;
}

.nvqai-success-sub {
  font-size: 13px;
  color: #555555;
}

/* ==========================================================================
   Mobile
   ========================================================================== */

@media (max-width: 480px) {
  .nvqai-fab {
    bottom: 16px;
    right: 14px;
    padding: 10px 18px 10px 14px;
    gap: 8px;
  }

  .nvqai-fab-label {
    font-size: 13px;
  }

  .nvqai-fab svg {
    width: 18px;
    height: 18px;
  }

  .nvqai-fab--compact {
    width: 48px;
    height: 48px;
    left: 14px;
    bottom: 16px;
    padding: 0;
  }

  .nvqai-fab--compact svg {
    width: 22px;
    height: 22px;
  }

  .nvqai-widget {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .nvqai-bubble {
    max-width: 90%;
  }

  .nvqai-row-2 {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .nvqai-fab,
  .nvqai-widget,
  .nvqai-send,
  .nvqai-typing span,
  .nvqai-submit-dark,
  .nvqai-submit-brand {
    transition: none;
    animation: none;
  }
}
