/*
 * ai_assistant.css
 * Lokavio AI widget styles
 */

/* ----------------------------------------------------------------
   Variables
   ---------------------------------------------------------------- */
:root {
  --ai-primary: #0f766e;
  --ai-primary-light: #0f5f8f;
  --ai-primary-hover: #0d527c;
  --ai-primary-gradient: linear-gradient(135deg, #0f766e 0%, #0f5f8f 100%);
  --ai-primary-gradient-hover: linear-gradient(135deg, #0d6b63 0%, #0d527c 100%);
  --ai-bg: #ffffff;
  --ai-panel-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
  --ai-border: #e0e0e0;
  --ai-user-bg: #2d6a4f;
  --ai-user-color: #fff;
  --ai-assistant-bg: #f1f3f4;
  --ai-assistant-color: #1a1a1a;
  --ai-radius: 16px;
  --ai-font: system-ui, -apple-system, sans-serif;
  --ai-z: 9999;
}

/* ----------------------------------------------------------------
   Widget container
   ---------------------------------------------------------------- */
#lokavio-ai-widget {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  right: 24px;
  z-index: var(--ai-z);
  font-family: var(--ai-font);
  font-size: 14px;
  /* Only capture pointer events on children; never block the whole viewport */
  pointer-events: none;
}

.ai-widget-toggle,
.ai-widget-panel {
  pointer-events: auto;
}

/* ----------------------------------------------------------------
   Toggle button
   ---------------------------------------------------------------- */
.ai-widget-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--ai-primary-gradient);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 10px 18px 10px 14px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  font-size: 14px;
  font-weight: 600;
  transition: background 0.2s, transform 0.15s;
  outline-offset: 3px;
}

.ai-widget-toggle:hover {
  background: var(--ai-primary-gradient-hover);
  transform: translateY(-1px);
}

.ai-widget-toggle:active {
  transform: translateY(0) scale(0.98);
}

#lokavio-ai-widget.is-open .ai-widget-toggle {
  transform: translateY(-1px) scale(0.96);
  box-shadow: 0 6px 22px rgba(15, 95, 143, 0.32);
}

/* ----------------------------------------------------------------
   Panel
   ---------------------------------------------------------------- */
.ai-widget-panel[hidden] {
  display: none !important;
}

.ai-widget-panel {
  position: absolute;
  bottom: 64px;
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--ai-bg);
  border-radius: var(--ai-radius);
  box-shadow: var(--ai-panel-shadow);
  border: 1px solid var(--ai-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 520px;
  opacity: 0;
  transform: translate3d(0, 12px, 0) scale(0.96);
  transform-origin: bottom right;
  pointer-events: none;
  transition:
    opacity 180ms cubic-bezier(.2, .8, .2, 1),
    transform 220ms cubic-bezier(.16, 1, .3, 1);
}

.ai-widget-panel.is-open {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1);
  pointer-events: auto;
}

/* ----------------------------------------------------------------
   Panel header
   ---------------------------------------------------------------- */
.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ai-primary-gradient);
  color: #fff;
  padding: 12px 16px;
  flex-shrink: 0;
}

.ai-panel-header-info {
  display: flex;
  flex-direction: column;
}

.ai-panel-title {
  font-weight: 700;
  font-size: 15px;
}

.ai-panel-institution {
  font-size: 11px;
  opacity: 0.85;
  margin-top: 1px;
}

.ai-panel-close {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 999px;
  line-height: 1;
  opacity: 0.9;
  transition: background 0.15s, opacity 0.15s;
}

.ai-panel-close:hover {
  background: rgba(255, 255, 255, 0.16);
  opacity: 1;
}

/* ----------------------------------------------------------------
   Disclaimer
   ---------------------------------------------------------------- */
.ai-panel-disclaimer {
  background: #fff8e1;
  border-bottom: 1px solid #ffe082;
  padding: 6px 14px;
  color: #7a5c00;
  font-size: 11px;
  flex-shrink: 0;
}

/* ----------------------------------------------------------------
   Messages area
   ---------------------------------------------------------------- */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100px;
}

.ai-message {
  display: flex;
}

.ai-message--user {
  justify-content: flex-end;
}

.ai-message--assistant {
  justify-content: flex-start;
}

.ai-message-bubble {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 14px;
  line-height: 1.45;
  font-size: 14px;
  word-break: break-word;
}

.ai-message--user .ai-message-bubble {
  background: var(--ai-primary-gradient);
  color: var(--ai-user-color);
  border-bottom-right-radius: 4px;
}

.ai-message--assistant .ai-message-bubble {
  background: var(--ai-assistant-bg);
  color: var(--ai-assistant-color);
  border-bottom-left-radius: 4px;
}

/* ----------------------------------------------------------------
   Typing indicator
   ---------------------------------------------------------------- */
.ai-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}

.ai-typing span {
  width: 7px;
  height: 7px;
  background: #888;
  border-radius: 50%;
  display: inline-block;
  animation: ai-bounce 1.2s infinite ease-in-out;
}

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

@keyframes ai-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ----------------------------------------------------------------
   Sources
   ---------------------------------------------------------------- */
.ai-sources {
  padding: 4px 14px 4px;
  font-size: 11px;
  color: #666;
  border-top: 1px solid var(--ai-border);
  flex-shrink: 0;
}

/* ----------------------------------------------------------------
   Input form
   ---------------------------------------------------------------- */
.ai-input-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--ai-border);
  flex-shrink: 0;
}

.ai-input {
  flex: 1;
  border: 1px solid var(--ai-border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--ai-font);
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  min-height: 38px;
  max-height: 100px;
}

.ai-input:focus {
  border-color: var(--ai-primary-light);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.ai-send-btn {
  background: var(--ai-primary-gradient);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
  line-height: 1;
}

.ai-send-btn:hover {
  background: var(--ai-primary-gradient-hover);
}

.ai-send-btn:disabled {
  background: #aaa;
  cursor: not-allowed;
}

/* ----------------------------------------------------------------
   Footer
   ---------------------------------------------------------------- */
.ai-panel-footer {
  text-align: center;
  padding: 4px 12px 8px;
  color: #aaa;
  font-size: 10px;
  flex-shrink: 0;
}

/* ----------------------------------------------------------------
   Mobile / PWA – safe-area aware positioning
   The widget must sit ABOVE the bottom navigation bar on phones.
   env(safe-area-inset-bottom) handles iPhone notch / Android navbar.
   88px covers a typical bottom-nav height (56–64px) + small gap.
   ---------------------------------------------------------------- */
@media (max-width: 640px) {
  #lokavio-ai-widget {
    /* Sit above the bottom nav – adjust if your bottom-nav height differs */
    bottom: calc(env(safe-area-inset-bottom, 0px) + 88px);
    right: 12px;
    /* Only the widget itself captures pointer events, not surrounding space */
    pointer-events: none;
  }

  .ai-widget-toggle,
  .ai-widget-panel {
    pointer-events: auto;
  }

  .ai-widget-panel {
    width: min(calc(100vw - 24px), 420px);
    right: 0;
    /* Anchor bottom of panel just above the toggle button */
    bottom: calc(100% + 8px);
    /* Limit height so top of screen is not covered on short phones */
    max-height: min(70vh, calc(100dvh - env(safe-area-inset-bottom, 0px) - 160px));
  }
}

/* Collapsed / expanded states for mobile slide-in */
#lokavio-ai-widget.ai-collapsed .ai-widget-toggle {
  /* Pill handle on the right side when collapsed */
  border-radius: 24px 0 0 24px;
  padding: 10px 14px 10px 16px;
}

/* Ensure no invisible full-overlay blocks menu taps */
#lokavio-ai-widget[data-ai-assistant-widget] {
  pointer-events: none;
}
#lokavio-ai-widget .ai-widget-toggle,
#lokavio-ai-widget .ai-widget-panel {
  pointer-events: auto;
}


/* ----------------------------------------------------------------
   Consent panel (AI provider data-transfer notice)
   ---------------------------------------------------------------- */
.ai-consent-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  margin: 4px 14px;
  background: #f8fafc;
  border: 1px solid var(--ai-border);
  border-radius: 10px;
  flex-shrink: 0;
}

.ai-consent-text {
  font-size: 13px;
  line-height: 1.45;
  color: #334155;
  margin: 0;
}

.ai-consent-link {
  font-size: 12px;
  color: var(--ai-primary, #2563eb);
  text-decoration: underline;
  align-self: flex-start;
}

/* ----------------------------------------------------------------
   Action buttons (Phase 9 contact flow)
   ---------------------------------------------------------------- */
.ai-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 14px 4px;
  flex-shrink: 0;
}

.ai-action-preview {
  background: #f8fafc;
  border: 1px solid var(--ai-border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: #444;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 4px;
}

.ai-action-btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-align: center;
  text-decoration: none;
  transition: background 0.15s;
}

.ai-action-btn--confirm_contact {
  background: var(--ai-primary-gradient);
  color: #fff;
}

.ai-action-btn--confirm_contact:hover {
  background: var(--ai-primary-gradient-hover);
}

.ai-action-btn--cancel_contact {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.ai-action-btn--cancel_contact:hover {
  background: #e2e8f0;
}

.ai-action-btn--login,
.ai-action-btn--register {
  background: var(--ai-primary-gradient);
  color: #fff;
}

.ai-action-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
  .ai-widget-panel,
  .ai-widget-toggle,
  .ai-send-btn,
  .ai-panel-close {
    transition: none !important;
    animation: none !important;
  }
}
