/**
 * AgenticChat Widget v2.0 — SagePrint Edition
 * Premium Agentic Feel — Glassmorphism · Streaming · Context-Aware
 */

/* ── Trigger button — pulsing glow ring ── */
.aw-trigger {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--aw-brand-lt), var(--aw-brand-dk));
  border: none;
  cursor: pointer;
  overflow: visible;
  box-shadow: 0 6px 28px rgba(0,0,0,0.45);
  transition: transform 0.35s cubic-bezier(0.16,1,0.3,1), box-shadow 0.35s ease;
  font-size: 22px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.aw-trigger::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--aw-brand);
  opacity: 0.4;
  animation: aw-ring-pulse 2.4s ease-in-out infinite;
}
.aw-trigger::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--aw-brand);
  opacity: 0.15;
  animation: aw-ring-pulse 2.4s ease-in-out 0.6s infinite;
}
@keyframes aw-ring-pulse {
  0%   { transform: scale(1);    opacity: 0.4; }
  70%  { transform: scale(1.25); opacity: 0; }
  100% { transform: scale(1.25); opacity: 0; }
}
.aw-trigger:hover {
  transform: translateY(-4px) scale(1.08);
  box-shadow: 0 16px 40px rgba(0,0,0,0.5), 0 0 0 6px color-mix(in srgb, var(--aw-brand) 22%, transparent);
}
.aw-trigger img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* ── Panel — Premium glassmorphism ── */
.aw-panel {
  position: fixed;
  bottom: 104px;
  right: 28px;
  z-index: 9998;
  width: 390px;
  max-height: 620px;
  border-radius: 22px;
  background: linear-gradient(145deg,
    rgba(15,39,68,0.97) 0%,
    rgba(10,28,55,0.99) 100%);
  border: 1px solid rgba(61,170,53,0.18);
  box-shadow:
    0 32px 90px rgba(0,0,0,0.7),
    0 0 0 1px rgba(255,255,255,0.04) inset,
    0 0 80px rgba(61,170,53,0.04) inset;
  display: none;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.94);
  transition: opacity 0.35s cubic-bezier(0.16,1,0.3,1),
              transform 0.35s cubic-bezier(0.16,1,0.3,1);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  backdrop-filter: blur(20px);
}
.aw-panel.open {
  display: flex;
  opacity: 1;
  transform: none;
}

/* ── Chat view flex wrapper ── */
#aw-chat-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* ── Header — gradient with particle shimmer ── */
.aw-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  background: linear-gradient(135deg,
    rgba(61,170,53,0.15) 0%,
    rgba(61,170,53,0.06) 100%);
  border-bottom: 1px solid rgba(61,170,53,0.14);
  position: relative;
  overflow: hidden;
}
.aw-header::before {
  content: '';
  position: absolute;
  top: -20px; right: -20px;
  width: 100px; height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(61,170,53,0.08) 0%, transparent 70%);
  animation: aw-hdr-glow 4s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes aw-hdr-glow {
  from { opacity: 0.5; transform: scale(1); }
  to   { opacity: 1;   transform: scale(1.3); }
}

/* ── Avatar ── */
.aw-av {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
  border: 1.5px solid rgba(61,170,53,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(61,170,53,0.15);
  color: var(--aw-brand);
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 0 12px rgba(61,170,53,0.2);
}
.aw-av img { width:100%; height:100%; object-fit:cover; }
.aw-name { font-size:14px; font-weight:800; color:rgba(238,242,248,0.95); line-height:1.2; }
.aw-role { font-size:11px; color:rgba(148,163,184,0.8); display:flex; align-items:center; gap:5px; }
.aw-online {
  color: #22c55e;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
}
.aw-online::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  animation: aw-online-pulse 2s ease-in-out infinite;
}
@keyframes aw-online-pulse {
  0%,100% { opacity:1; box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  50%      { opacity:0.8; box-shadow: 0 0 0 4px rgba(34,197,94,0); }
}

/* ── Header utility buttons ── */
.aw-hbtn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 7px;
  color: rgba(148,163,184,0.8);
  font-size: 12px;
  cursor: pointer;
  padding: 0 9px;
  height: 28px;
  display: flex; align-items: center; gap: 4px;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
  font-family: inherit;
  position: relative;
  z-index: 10;
}
.aw-hbtn:hover { background: rgba(255,255,255,0.1); color: #e2e8f0; }
.aw-hbtn-new {
  background: rgba(61,170,53,0.12);
  border-color: rgba(61,170,53,0.28);
  color: #4ade80;
  font-weight: 700;
}
.aw-hbtn-new:hover { background: rgba(61,170,53,0.22); }
.aw-close { font-size: 14px; padding: 0 8px; }

/* ── Messages ── */
.aw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(61,170,53,0.15) transparent;
}
.aw-messages::-webkit-scrollbar { width: 4px; }
.aw-messages::-webkit-scrollbar-thumb { background: rgba(61,170,53,0.2); border-radius: 4px; }

.aw-msg {
  display: flex; gap: 8px; align-items: flex-start;
  animation: awMsgIn 0.28s cubic-bezier(0.34,1.56,0.64,1) both;
}
.aw-user { justify-content: flex-end; }
.aw-bot  { justify-content: flex-start; }

.aw-bubble {
  max-width: 86%;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.68;
  border-radius: 14px;
}
.aw-bubble p { margin: 0 0 6px; }
.aw-bubble p:last-child { margin: 0; }

.aw-bubble-bot {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(61,170,53,0.12);
  border-radius: 4px 14px 14px 14px;
  color: rgba(226,232,240,0.92);
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}
.aw-bubble-user {
  background: linear-gradient(135deg, rgba(61,170,53,0.22), rgba(34,197,94,0.18));
  border: 1px solid rgba(61,170,53,0.22);
  border-radius: 14px 4px 14px 14px;
  color: rgba(226,232,240,0.95);
}
.aw-bubble strong { color: #4ade80; font-weight: 700; }
.aw-bubble a { color: #86efac; }

/* Avatar next to bot messages */
.aw-msg-av {
  width: 26px; height: 26px;
  border-radius: 7px;
  margin-top: 2px;
  flex-shrink: 0;
  font-size: 11px;
  border: 1px solid rgba(61,170,53,0.2);
  box-shadow: 0 0 8px rgba(61,170,53,0.1);
}

/* ── Streaming cursor blink ── */
.aw-stream-cursor::after {
  content: '▋';
  display: inline;
  color: #3daa35;
  animation: aw-blink 0.9s step-end infinite;
  margin-left: 1px;
}
@keyframes aw-blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ── Typing indicator — multi-stage ── */
.aw-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(61,170,53,0.12);
  border-radius: 4px 14px 14px 14px;
}
.aw-typing-label {
  font-size: 10px;
  color: rgba(61,170,53,0.7);
  margin-right: 4px;
  font-weight: 600;
  letter-spacing: 0.5px;
  animation: aw-label-cycle 2.4s ease-in-out infinite;
}
.aw-typing span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #3daa35;
  opacity: 0.5;
  animation: awTypingDot 1.2s ease-in-out infinite;
}
.aw-typing span:nth-child(2) { animation-delay: 0.2s; }
.aw-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes aw-label-cycle {
  0%  { content: "Thinking"; }
  33% { opacity: 1; }
  66% { opacity: 0.6; }
  100%{ opacity: 1; }
}

/* ── Chips (quick replies) — gradient selection ── */
.aw-chips {
  padding: 0 10px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.aw-chip {
  padding: 5px 13px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 600;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  color: rgba(148,163,184,0.8);
  cursor: pointer;
  transition: all 0.22s ease;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}
.aw-chip::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(61,170,53,0.1), rgba(34,197,94,0.06));
  opacity: 0;
  transition: opacity 0.2s;
}
.aw-chip:hover {
  border-color: rgba(61,170,53,0.5);
  color: #4ade80;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(61,170,53,0.15);
}
.aw-chip:hover::before { opacity: 1; }

/* ── Input row — glow on focus ── */
.aw-input-row {
  padding: 10px;
  border-top: 1px solid rgba(61,170,53,0.1);
  display: flex;
  gap: 7px;
  align-items: center;
  background: rgba(0,0,0,0.15);
}
.aw-input {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 100px;
  padding: 9px 16px;
  color: rgba(226,232,240,0.92);
  font-size: 13px;
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
  font-family: inherit;
}
.aw-input:focus {
  border-color: rgba(61,170,53,0.5);
  box-shadow: 0 0 0 3px rgba(61,170,53,0.1), 0 0 16px rgba(61,170,53,0.08);
}
.aw-input::placeholder { color: rgba(100,116,139,0.7); }

.aw-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5ec457, #2d7a27);
  border: none;
  cursor: pointer;
  color: #fff;
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform 0.22s, box-shadow 0.22s;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(61,170,53,0.3);
}
.aw-send:hover {
  transform: scale(1.14);
  box-shadow: 0 6px 20px rgba(61,170,53,0.45);
}

/* ── Context bar — proactive awareness strip ── */
.aw-context-bar {
  padding: 6px 12px;
  font-size: 10.5px;
  color: rgba(74,222,128,0.7);
  background: rgba(61,170,53,0.05);
  border-bottom: 1px solid rgba(61,170,53,0.1);
  display: flex;
  align-items: center;
  gap: 6px;
  animation: awMsgIn 0.3s ease;
}
.aw-context-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
  animation: aw-online-pulse 2s ease-in-out infinite;
}

/* ── Footer note ── */
.aw-footer {
  text-align: center;
  font-size: 10px;
  color: rgba(100,116,139,0.6);
  padding: 3px 12px 8px;
}

/* ── Lead capture form ── */
.aw-lead-form { display: flex; flex-direction: column; gap: 7px; }
.aw-lead-form input {
  width: 100%; box-sizing: border-box;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(61,170,53,0.2);
  border-radius: 8px; padding: 7px 11px;
  color: rgba(226,232,240,0.92); font-size: 12.5px;
  outline: none; font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.aw-lead-form input:focus {
  border-color: rgba(61,170,53,0.5);
  box-shadow: 0 0 0 2px rgba(61,170,53,0.1);
}
.aw-lead-form input::placeholder { color: rgba(100,116,139,0.7); }
.aw-lead-form button {
  background: linear-gradient(135deg, #5ec457, #2d7a27);
  border: none; border-radius: 8px; color: #fff;
  padding: 9px 14px; font-size: 12.5px; font-weight: 700;
  cursor: pointer; font-family: inherit;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 14px rgba(61,170,53,0.25);
}
.aw-lead-form button:hover { transform: scale(1.03); box-shadow: 0 6px 20px rgba(61,170,53,0.4); }

/* ── History view ── */
.aw-hist-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; border-radius: 9px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.aw-hist-item:hover { border-color: rgba(61,170,53,0.25); background: rgba(61,170,53,0.04); }
.aw-hist-active { border-color: rgba(61,170,53,0.4) !important; background: rgba(61,170,53,0.06) !important; }
.aw-hist-title { font-size: 12.5px; font-weight: 600; color: rgba(226,232,240,0.9); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aw-hist-meta { font-size: 10.5px; color: rgba(100,116,139,0.7); margin-top: 2px; }
.aw-hist-del { background: none; border: none; cursor: pointer; color: transparent; padding: 4px 6px; border-radius: 5px; transition: background 0.2s, color 0.2s; font-size: 14px; flex-shrink: 0; }
.aw-hist-item:hover .aw-hist-del { color: rgba(100,116,139,0.6); }
.aw-hist-del:hover { background: rgba(224,85,85,0.12); color: #e05555 !important; }

/* ── Proactive tooltip — premium style ── */
#aw-proactive-tip {
  border-radius: 14px 14px 4px 14px !important;
  font-weight: 500;
  animation: awMsgIn 0.35s cubic-bezier(0.34,1.56,0.64,1) both !important;
}

/* ── Animations ── */
@keyframes awMsgIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
@keyframes awTypingDot {
  0%,80%,100% { opacity: 0.3; transform: scale(0.8);  }
  40%          { opacity: 1;   transform: scale(1.2); }
}

/* ── Mobile ── */
@media (max-width: 480px) {
  .aw-panel {
    width: 100%; bottom: 0; right: 0;
    max-height: 88vh;
    border-radius: 22px 22px 0 0;
  }
  .aw-trigger { bottom: 20px; right: 20px; }
}
