/* ==========================================================================
   Powell AI Assistant — Widget Styles
   ========================================================================== */

#powell-ai-root {
  --pai-accent:      #1B4B8A; /* overridden inline from PHP */
  --pai-accent-dark: color-mix(in srgb, var(--pai-accent) 80%, black);
  --pai-radius:      16px;
  --pai-shadow:      0 8px 32px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.10);
  --pai-font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --pai-z:           9999;

  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--pai-z);
  font-family: var(--pai-font);
  font-size: 15px;
  line-height: 1.5;
}

/* --------------------------------------------------------------------------
   Toggle Button
   -------------------------------------------------------------------------- */
#powell-ai-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--pai-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
  position: relative;
  margin-left: auto;
}
#powell-ai-toggle:hover {
  background: color-mix(in srgb, var(--pai-accent) 85%, black);
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0,0,0,.30);
}
#powell-ai-toggle:focus-visible {
  outline: 3px solid var(--pai-accent);
  outline-offset: 3px;
}
#powell-ai-toggle svg { width: 26px; height: 26px; transition: opacity .15s, transform .15s; }

#powell-ai-toggle .pai-icon-close { position: absolute; opacity: 0; transform: scale(0.7) rotate(-45deg); }
#powell-ai-toggle.is-open .pai-icon-chat  { opacity: 0; transform: scale(0.7) rotate(45deg); }
#powell-ai-toggle.is-open .pai-icon-close { opacity: 1; transform: scale(1) rotate(0); }

/* Unread badge */
.pai-unread-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #EF4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid #fff;
  animation: pai-pulse 2s infinite;
}
@keyframes pai-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.15); }
}

/* --------------------------------------------------------------------------
   Chat Panel
   -------------------------------------------------------------------------- */
#powell-ai-panel {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  width: min(380px, 94vw);
  background: #fff;
  border-radius: var(--pai-radius);
  box-shadow: var(--pai-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: min(560px, 80vh);
  border: 1px solid rgba(0,0,0,.08);

  /* Entry animation */
  transform-origin: bottom right;
  animation: pai-panel-in .22s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}
#powell-ai-panel[hidden] { display: none; }

@keyframes pai-panel-in {
  from { opacity: 0; transform: scale(0.88) translateY(12px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);     }
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.pai-header {
  background: var(--pai-accent);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.pai-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.pai-avatar svg { width: 40px; height: 40px; }
.pai-header-info { flex: 1; min-width: 0; }
.pai-header-info strong { display: block; font-size: 15px; font-weight: 700; }
.pai-header-info span   { font-size: 12px; opacity: .8; }

.pai-close-btn {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.pai-close-btn:hover { background: rgba(255,255,255,.25); }

/* --------------------------------------------------------------------------
   Messages
   -------------------------------------------------------------------------- */
.pai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.pai-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: pai-msg-in .18s ease both;
}
@keyframes pai-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pai-msg--assistant { align-self: flex-start; }
.pai-msg--user      { align-self: flex-end; }

.pai-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}
.pai-msg--assistant .pai-msg-bubble {
  background: #F1F5F9;
  color: #1e293b;
  border-bottom-left-radius: 4px;
}
.pai-msg--user .pai-msg-bubble {
  background: var(--pai-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.pai-msg-time {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 3px;
  padding: 0 4px;
}
.pai-msg--user .pai-msg-time { text-align: right; }

/* Links inside assistant messages */
.pai-msg--assistant .pai-msg-bubble a {
  color: var(--pai-accent);
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Typing indicator
   -------------------------------------------------------------------------- */
.pai-typing {
  padding: 10px 16px 4px;
  display: flex;
  gap: 5px;
  align-items: center;
  flex-shrink: 0;
}
.pai-typing[hidden] { display: none; }
.pai-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: pai-bounce 1.2s infinite ease-in-out;
}
.pai-typing span:nth-child(2) { animation-delay: .18s; }
.pai-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes pai-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* --------------------------------------------------------------------------
   Lead Capture Form
   -------------------------------------------------------------------------- */
.pai-lead-form {
  padding: 14px 16px;
  background: #F8FAFC;
  border-top: 1px solid #E2E8F0;
  flex-shrink: 0;
}
.pai-lead-form[hidden] { display: none; }

.pai-lead-intro {
  font-size: 13px;
  color: #475569;
  margin: 0 0 10px;
}
.pai-lead-form input {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid #CBD5E1;
  border-radius: 8px;
  font-size: 13px;
  font-family: var(--pai-font);
  color: #1e293b;
  background: #fff;
  margin-bottom: 7px;
  box-sizing: border-box;
  transition: border-color .15s;
}
.pai-lead-form input:focus {
  outline: none;
  border-color: var(--pai-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pai-accent) 15%, transparent);
}

.pai-lead-submit-btn {
  width: 100%;
  padding: 9px;
  background: var(--pai-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  margin-bottom: 6px;
}
.pai-lead-submit-btn:hover {
  background: color-mix(in srgb, var(--pai-accent) 82%, black);
}
.pai-lead-skip-btn {
  width: 100%;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 12px;
  cursor: pointer;
  padding: 4px;
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Input Area
   -------------------------------------------------------------------------- */
.pai-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid #E2E8F0;
  background: #fff;
  flex-shrink: 0;
}
#powell-ai-input {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid #CBD5E1;
  border-radius: 10px;
  font-size: 14px;
  font-family: var(--pai-font);
  resize: none;
  line-height: 1.45;
  color: #1e293b;
  background: #F8FAFC;
  transition: border-color .15s, box-shadow .15s;
  min-height: 40px;
  max-height: 100px;
  overflow-y: auto;
}
#powell-ai-input:focus {
  outline: none;
  border-color: var(--pai-accent);
  background: #fff;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pai-accent) 12%, transparent);
}
#powell-ai-input::placeholder { color: #94a3b8; }

#powell-ai-send {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--pai-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
#powell-ai-send:hover:not(:disabled) {
  background: color-mix(in srgb, var(--pai-accent) 82%, black);
}
#powell-ai-send:active:not(:disabled) { transform: scale(0.94); }
#powell-ai-send:disabled { opacity: .4; cursor: not-allowed; }

/* --------------------------------------------------------------------------
   Footer note
   -------------------------------------------------------------------------- */
.pai-footer-note {
  text-align: center;
  font-size: 11px;
  color: #94a3b8;
  padding: 5px 12px 8px;
  background: #fff;
  flex-shrink: 0;
}
.pai-footer-note a { color: #94a3b8; text-decoration: underline; }

/* --------------------------------------------------------------------------
   Mobile adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  #powell-ai-root {
    bottom: 16px;
    right: 16px;
  }
  #powell-ai-panel {
    width: calc(100vw - 32px);
    right: 0;
    max-height: 75vh;
  }
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  #powell-ai-panel, .pai-msg, .pai-unread-badge { animation: none; }
  .pai-typing span { animation: none; opacity: .6; }
}
