/* =============================================================================
   AMICOM ANALYTICS — AI Scientific Assistant
   Floating chat widget, branding-consistent, mobile-first.
   Future AI replacement: swap AmicomAssistant.engine module in assistant.js
   without touching any CSS here.
   ============================================================================= */

/* ---------- Custom properties (scoped to widget namespace) ---------- */
:root {
  --ai-primary:      #0a6eb4;
  --ai-primary-d:    #084d80;
  --ai-teal:         #00a896;
  --ai-teal-d:       #007a6e;
  --ai-accent:       #00c9b1;
  --ai-dark:         #0d1b2a;
  --ai-dark-2:       #1a2d42;
  --ai-text:         #2c3e50;
  --ai-text-m:       #8a9ab0;
  --ai-bg:           #ffffff;
  --ai-bg-l:         #f4f8fc;
  --ai-border:       #dde4ed;
  --ai-border-l:     #eef2f7;
  --ai-shadow:       0 8px 40px rgba(10,110,180,0.18);
  --ai-radius:       16px;
  --ai-radius-sm:    10px;
  --ai-radius-msg:   18px;
  --ai-font:         'Inter', 'Segoe UI', system-ui, sans-serif;
  --ai-z:            9500;
  --ai-transition:   all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =============================================================================
   FLOATING TRIGGER BUTTON
   ============================================================================= */
.ai-trigger {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: var(--ai-z);
  display: flex;
  align-items: center;
  gap: 0;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  /* Shift up when back-to-top is visible to avoid overlap */
  transition: bottom 0.3s ease, transform 0.2s ease;
}

/* Pill label that slides in on hover */
.ai-trigger-pill {
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-teal));
  color: #fff;
  font-family: var(--ai-font);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.5rem 1rem 0.5rem 1.25rem;
  border-radius: 50px 0 0 50px;
  white-space: nowrap;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-width 0.4s ease, opacity 0.3s ease, padding 0.4s ease;
  pointer-events: none;
}

.ai-trigger:hover .ai-trigger-pill,
.ai-trigger:focus-visible .ai-trigger-pill {
  max-width: 180px;
  opacity: 1;
  padding: 0.5rem 1rem 0.5rem 1.25rem;
}

/* Circle icon button */
.ai-trigger-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ai-primary) 0%, var(--ai-teal) 100%);
  box-shadow: 0 4px 20px rgba(10,110,180,0.35), 0 0 0 0 rgba(10,110,180,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--ai-transition);
  animation: ai-pulse-ring 2.5s ease-in-out 1s 3;
  position: relative;
  flex-shrink: 0;
}

.ai-trigger:hover .ai-trigger-btn,
.ai-trigger:focus-visible .ai-trigger-btn {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(10,110,180,0.45), 0 0 0 0 rgba(10,110,180,0);
}

/* Icon swap: show chat icon by default, X when open */
.ai-trigger-icon-chat,
.ai-trigger-icon-close {
  position: absolute;
  transition: opacity 0.25s ease, transform 0.25s ease;
  color: #fff;
}

.ai-trigger-icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.7);
}

.ai-widget--open .ai-trigger-icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.7);
}

.ai-widget--open .ai-trigger-icon-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Notification dot */
.ai-trigger-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: #ff4757;
  border-radius: 50%;
  border: 2px solid #fff;
  animation: ai-dot-pulse 2s ease-in-out infinite;
  transition: opacity 0.3s;
}

.ai-widget--open .ai-trigger-dot,
.ai-trigger-dot--hidden {
  opacity: 0;
  pointer-events: none;
}

@keyframes ai-pulse-ring {
  0%   { box-shadow: 0 4px 20px rgba(10,110,180,0.35), 0 0 0 0 rgba(10,110,180,0.4); }
  70%  { box-shadow: 0 4px 20px rgba(10,110,180,0.35), 0 0 0 14px rgba(10,110,180,0); }
  100% { box-shadow: 0 4px 20px rgba(10,110,180,0.35), 0 0 0 0 rgba(10,110,180,0); }
}

@keyframes ai-dot-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.2); }
}

/* =============================================================================
   CHAT WINDOW
   ============================================================================= */
.ai-window {
  position: fixed;
  bottom: 6rem;
  right: 2rem;
  z-index: var(--ai-z);
  width: 400px;
  max-height: 620px;
  min-height: 480px;
  background: var(--ai-bg);
  border-radius: var(--ai-radius);
  box-shadow: var(--ai-shadow), 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--ai-font);
  border: 1px solid var(--ai-border-l);

  /* Hidden state */
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
  transform-origin: bottom right;
}

.ai-window--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ---------- Header ---------- */
.ai-header {
  background: linear-gradient(135deg, var(--ai-dark) 0%, var(--ai-dark-2) 60%, #0a3a5c 100%);
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

/* Subtle grid texture in header */
.ai-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
}

.ai-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-teal));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  position: relative;
  z-index: 1;
}

.ai-header-info {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.ai-header-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.ai-header-status {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 2px;
}

.ai-status-dot {
  width: 6px;
  height: 6px;
  background: var(--ai-accent);
  border-radius: 50%;
  animation: ai-dot-pulse 2s ease-in-out infinite;
}

.ai-header-status span {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.55);
  font-weight: 500;
}

/* Step progress bar in header */
.ai-progress-wrap {
  margin-top: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  position: relative;
  z-index: 1;
}

.ai-progress-bar-track {
  flex: 1;
  height: 3px;
  background: rgba(255,255,255,0.12);
  border-radius: 2px;
  overflow: hidden;
}

.ai-progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ai-teal), var(--ai-accent));
  border-radius: 2px;
  transition: width 0.5s ease;
  width: 0%;
}

.ai-progress-label {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.4);
  white-space: nowrap;
  font-weight: 600;
}

/* Header close/minimize buttons */
.ai-header-actions {
  display: flex;
  gap: 0.35rem;
  position: relative;
  z-index: 1;
}

.ai-header-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.6);
  transition: var(--ai-transition);
}

.ai-header-btn:hover {
  background: rgba(255,255,255,0.16);
  color: #fff;
}

/* ---------- Messages area ---------- */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.ai-messages::-webkit-scrollbar { width: 4px; }
.ai-messages::-webkit-scrollbar-track { background: transparent; }
.ai-messages::-webkit-scrollbar-thumb {
  background: var(--ai-border);
  border-radius: 2px;
}

/* Base message bubble */
.ai-msg {
  display: flex;
  gap: 0.6rem;
  max-width: 88%;
  animation: ai-msg-in 0.3s ease;
}

@keyframes ai-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Bot message — left-aligned */
.ai-msg--bot {
  align-self: flex-start;
}

.ai-msg--bot .ai-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-teal));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  margin-top: 2px;
}

.ai-msg--bot .ai-msg-bubble {
  background: var(--ai-bg-l);
  border: 1px solid var(--ai-border-l);
  color: var(--ai-text);
  border-radius: 4px var(--ai-radius-msg) var(--ai-radius-msg) var(--ai-radius-msg);
  padding: 0.7rem 1rem;
  font-size: 0.875rem;
  line-height: 1.55;
}

/* User message — right-aligned */
.ai-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-msg--user .ai-msg-bubble {
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-teal-d));
  color: #fff;
  border-radius: var(--ai-radius-msg) 4px var(--ai-radius-msg) var(--ai-radius-msg);
  padding: 0.7rem 1rem;
  font-size: 0.875rem;
  line-height: 1.55;
}

/* Typing indicator */
.ai-msg--typing .ai-msg-bubble {
  padding: 0.85rem 1.1rem;
}

.ai-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.ai-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--ai-text-m);
  border-radius: 50%;
  animation: ai-typing 1.2s ease-in-out infinite;
}

.ai-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* Service recommendation card inside a bot message */
.ai-rec-card {
  background: #fff;
  border: 1px solid var(--ai-border);
  border-left: 3px solid var(--ai-teal);
  border-radius: var(--ai-radius-sm);
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
  font-size: 0.82rem;
}

.ai-rec-card-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ai-teal);
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.ai-rec-card-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ai-dark);
  margin-bottom: 0.2rem;
}

.ai-rec-card-desc {
  color: var(--ai-text-m);
  line-height: 1.45;
}

/* Summary table inside bot message */
.ai-summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.ai-summary-table tr td {
  padding: 0.35rem 0.5rem;
  vertical-align: top;
  line-height: 1.4;
}

.ai-summary-table tr td:first-child {
  color: var(--ai-text-m);
  font-weight: 600;
  white-space: nowrap;
  padding-right: 0.75rem;
  width: 40%;
}

.ai-summary-table tr td:last-child {
  color: var(--ai-text);
  font-weight: 500;
}

.ai-summary-table tr:nth-child(even) td {
  background: rgba(10,110,180,0.03);
}

/* ---------- Quick-reply chips ---------- */
.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.75rem;
  animation: ai-msg-in 0.35s ease;
}

.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.85rem;
  border-radius: 50px;
  border: 1.5px solid var(--ai-border);
  background: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ai-text);
  cursor: pointer;
  transition: var(--ai-transition);
  font-family: var(--ai-font);
}

.ai-chip:hover {
  border-color: var(--ai-primary);
  background: rgba(10,110,180,0.06);
  color: var(--ai-primary);
  transform: translateY(-1px);
}

.ai-chip:active { transform: translateY(0); }

/* ---------- Input area ---------- */
.ai-input-area {
  flex-shrink: 0;
  border-top: 1px solid var(--ai-border-l);
  padding: 0.75rem 1rem;
  background: var(--ai-bg);
}

/* Consent row (shows before final submit) */
.ai-consent-row {
  display: none;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  background: rgba(10,110,180,0.04);
  border-top: 1px solid var(--ai-border-l);
  font-size: 0.75rem;
  color: var(--ai-text-m);
  line-height: 1.5;
}

.ai-consent-row.visible { display: flex; }

.ai-consent-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  margin-top: 1px;
  accent-color: var(--ai-primary);
  cursor: pointer;
}

.ai-consent-row label { cursor: pointer; }
.ai-consent-row a { color: var(--ai-primary); }

/* Honeypot — always hidden */
.ai-honeypot { display: none !important; visibility: hidden !important; }

/* Text input row */
.ai-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.ai-input {
  flex: 1;
  border: 1.5px solid var(--ai-border);
  border-radius: 50px;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-family: var(--ai-font);
  color: var(--ai-text);
  background: var(--ai-bg-l);
  outline: none;
  transition: var(--ai-transition);
  resize: none;
  overflow: hidden;
  line-height: 1.4;
  max-height: 100px;
}

.ai-input:focus {
  border-color: var(--ai-primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(10,110,180,0.1);
}

.ai-input::placeholder { color: var(--ai-text-m); }

.ai-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Send button */
.ai-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-teal));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  transition: var(--ai-transition);
  box-shadow: 0 2px 8px rgba(10,110,180,0.25);
}

.ai-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(10,110,180,0.4);
}

.ai-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Submit enquiry button (replaces send btn at final step) */
.ai-submit-btn {
  width: 100%;
  padding: 0.75rem;
  border-radius: 50px;
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-teal-d));
  border: none;
  cursor: pointer;
  color: #fff;
  font-family: var(--ai-font);
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--ai-transition);
  box-shadow: 0 3px 14px rgba(10,110,180,0.3);
  margin-top: 0.5rem;
}

.ai-submit-btn:hover {
  background: linear-gradient(135deg, var(--ai-primary-d), var(--ai-teal-d));
  box-shadow: 0 5px 20px rgba(10,110,180,0.4);
  transform: translateY(-1px);
}

.ai-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Loading spinner inside button */
.ai-spin {
  animation: ai-spin-anim 0.8s linear infinite;
  display: none;
}

.ai-submitting .ai-spin { display: block; }
.ai-submitting .ai-submit-icon { display: none; }

@keyframes ai-spin-anim {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Input hint */
.ai-input-hint {
  font-size: 0.68rem;
  color: var(--ai-text-m);
  text-align: center;
  margin-top: 0.4rem;
}

/* Error message under input */
.ai-input-error {
  font-size: 0.72rem;
  color: #e74c3c;
  margin-top: 0.3rem;
  min-height: 1em;
  padding-left: 0.25rem;
}

/* ---------- Success / error screen ---------- */
.ai-result-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  text-align: center;
  animation: ai-msg-in 0.4s ease;
}

.ai-result-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
}

.ai-result-icon--success {
  background: linear-gradient(135deg, rgba(46,204,113,0.15), rgba(0,168,150,0.12));
  color: #27ae60;
}

.ai-result-icon--error {
  background: rgba(231,76,60,0.1);
  color: #e74c3c;
}

.ai-result-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ai-dark);
  margin-bottom: 0.6rem;
}

.ai-result-text {
  font-size: 0.85rem;
  color: var(--ai-text-m);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.ai-result-ref {
  font-size: 0.75rem;
  background: var(--ai-bg-l);
  border: 1px solid var(--ai-border-l);
  border-radius: var(--ai-radius-sm);
  padding: 0.5rem 1rem;
  color: var(--ai-text-m);
  margin-bottom: 1.25rem;
}

.ai-result-ref strong { color: var(--ai-primary); }

/* ---------- "Restart" link ---------- */
.ai-restart-link {
  background: none;
  border: none;
  color: var(--ai-primary);
  font-family: var(--ai-font);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.ai-restart-link:hover { color: var(--ai-primary-d); }

/* ---------- Powered-by footer ---------- */
.ai-footer {
  padding: 0.5rem 1rem;
  text-align: center;
  border-top: 1px solid var(--ai-border-l);
  background: var(--ai-bg-l);
  flex-shrink: 0;
}

.ai-footer span {
  font-size: 0.67rem;
  color: var(--ai-text-m);
}

.ai-footer strong { color: var(--ai-primary); font-weight: 700; }

/* =============================================================================
   RESPONSIVE
   ============================================================================= */
@media (max-width: 480px) {
  .ai-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 88vh;
    min-height: 60vh;
    border-radius: var(--ai-radius) var(--ai-radius) 0 0;
    transform-origin: bottom center;
  }

  .ai-trigger {
    bottom: 1.25rem;
    right: 1.25rem;
  }

  .ai-trigger-pill {
    display: none;
  }

  .ai-trigger-btn {
    width: 52px;
    height: 52px;
  }
}

/* When back-to-top button is visible, nudge trigger up */
.ai-trigger.shift-up {
  bottom: 5.5rem;
}

@media (max-width: 480px) {
  .ai-trigger.shift-up {
    bottom: 5rem;
  }
}
