/* ================================================================
   css/ai-agent.css — Aling Nena Chat Widget Styles
   Spec: §30 AI Customer Service Agent — Part 4

   Targets #aling-nena-widget container (position: fixed).
   Coexists with WhatsApp (bottom-left) and back-to-top (bottom-right, 96px).
================================================================ */

/* ── Keyframe animations ─────────────────────────────────────── */

@keyframes npPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(200, 150, 62, 0.5); }
  50%       { box-shadow: 0 4px 32px rgba(200, 150, 62, 0.8), 0 0 0 8px rgba(200, 150, 62, 0.15); }
}

@keyframes npSlideUp {
  from { opacity: 0; transform: scale(0.85) translateY(20px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

@keyframes npSlideUpMobile {
  from { opacity: 0; transform: translateY(40px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

@keyframes npFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Widget root ─────────────────────────────────────────────── */

#aling-nena-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9000;
  font-family: var(--font-heading, 'DM Sans', sans-serif);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* ── Trigger button ──────────────────────────────────────────── */

.an-trigger {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #C8963E, #A87230);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: #fff;
  box-shadow: 0 4px 20px rgba(200, 150, 62, 0.5);
  animation: npPulse 2s ease-in-out infinite;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.an-trigger:hover { transform: scale(1.1); }

.an-trigger:focus-visible {
  outline: 3px solid #1A1A2E;
  outline-offset: 3px;
}

.an-trigger[aria-expanded="true"] {
  animation: none;
  background: linear-gradient(135deg, #1A1A2E, #2D2D4E);
}

/* Icon swap on open */
.an-trigger-icon,
.an-trigger-agent {
  position: absolute;
  line-height: 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.an-trigger-icon  { opacity: 1; transform: scale(1); }
.an-trigger-agent { opacity: 0; transform: scale(0.6); }

.an-trigger[aria-expanded="true"] .an-trigger-icon  { opacity: 0; transform: scale(0.6); }
.an-trigger[aria-expanded="true"] .an-trigger-agent { opacity: 1; transform: scale(1); }

/* ── Chat window ─────────────────────────────────────────────── */

.an-window {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 380px;
  height: 580px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(15, 14, 13, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.85) translateY(20px);
  transform-origin: bottom right;
  transition: opacity 0.05s ease, transform 0.05s ease;
}

.an-window--open {
  animation: npSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ── Header ──────────────────────────────────────────────────── */

.an-header {
  background: #1A1A2E;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.an-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #C8963E, #A87230);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.an-identity {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.an-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: #FAF7F2;
  letter-spacing: 0.01em;
}

.an-status {
  font-size: 0.72rem;
  color: rgba(250, 247, 242, 0.55);
}

.an-header-close {
  background: none;
  border: none;
  color: rgba(250, 247, 242, 0.5);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.15s;
  flex-shrink: 0;
}

.an-header-close:hover { color: #FAF7F2; }

.an-header-close:focus-visible {
  outline: 2px solid #C8963E;
  outline-offset: 2px;
  color: #FAF7F2;
}

/* ── Messages ────────────────────────────────────────────────── */

.an-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.an-messages::-webkit-scrollbar { width: 4px; }
.an-messages::-webkit-scrollbar-track { background: transparent; }
.an-messages::-webkit-scrollbar-thumb { background: #DDD5C8; border-radius: 2px; }

/* ── Message bubbles ─────────────────────────────────────────── */

.an-msg {
  max-width: 78%;
  font-size: 13.5px;
  line-height: 1.6;
  word-wrap: break-word;
  animation: npFadeIn 0.2s ease both;
}

/* Bot bubble */
.an-msg--bot {
  background: #FAF7F2;
  color: #0F0E0D;
  border: 1px solid #EDE8DF;
  border-radius: 16px 16px 16px 4px;
  padding: 10px 14px;
  box-shadow: 0 1px 4px rgba(15, 14, 13, 0.06);
  align-self: flex-start;
}

/* User bubble */
.an-msg--user {
  background: linear-gradient(135deg, #C8963E, #A87230);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  box-shadow: 0 2px 8px rgba(200, 150, 62, 0.3);
  align-self: flex-end;
  margin-left: auto;
}

/* ── Typing indicator ────────────────────────────────────────── */

.an-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  min-width: 56px;
  background: #FAF7F2;
  border: 1px solid #EDE8DF;
  border-radius: 16px 16px 16px 4px;
  align-self: flex-start;
  box-shadow: 0 1px 4px rgba(15, 14, 13, 0.06);
}

.an-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #C8963E;
  animation: npBounce 1.2s ease-in-out infinite;
  display: block;
}

.an-dot:nth-child(2) { animation-delay: 0.2s; }
.an-dot:nth-child(3) { animation-delay: 0.4s; }

/* ── Quick reply chips ───────────────────────────────────────── */

.an-chips {
  display: flex;
  flex-wrap: wrap;
  padding: 0 12px 10px;
  gap: 4px;
  flex-shrink: 0;
}

.an-chip {
  display: inline-block;
  padding: 5px 12px;
  background: #FAF7F2;
  border: 1px solid #DDD5C8;
  border-radius: 20px;
  font-family: inherit;
  font-size: 12px;
  color: #0F0E0D;
  cursor: pointer;
  margin: 3px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  min-height: 32px;
  text-align: left;
}

.an-chip:hover {
  background: #C8963E;
  color: #fff;
  border-color: #C8963E;
}

.an-chip:focus-visible {
  outline: 2px solid #C8963E;
  outline-offset: 2px;
}

/* ── Input row ───────────────────────────────────────────────── */

.an-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #EDE8DF;
  background: #fff;
  flex-shrink: 0;
}

.an-input {
  flex: 1;
  padding: 9px 14px;
  border: 1.5px solid #DDD5C8;
  border-radius: 22px;
  font-family: inherit;
  font-size: 13.5px;
  color: #0F0E0D;
  background: #FAF7F2;
  outline: none;
  transition: border-color 0.15s;
  min-height: 40px;
}

.an-input:focus          { border-color: #C8963E; }
.an-input:focus-visible  { outline: 2px solid #C8963E; outline-offset: 1px; }
.an-input::placeholder   { color: #8A8474; }

.an-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #C8963E, #A87230);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}

.an-send:disabled           { opacity: 0.35; cursor: not-allowed; transform: none; }
.an-send:not(:disabled):hover { transform: scale(1.08); }
.an-send:focus-visible      { outline: 2px solid #0F0E0D; outline-offset: 2px; }

/* ── Footer ──────────────────────────────────────────────────── */

.an-footer {
  padding: 5px 12px 8px;
  font-size: 0.68rem;
  color: #8A8474;
  text-align: center;
  background: #fff;
  flex-shrink: 0;
}

.an-footer a             { color: #8A8474; text-decoration: underline; text-underline-offset: 2px; }
.an-footer a:hover       { color: #0F0E0D; }

/* ── Proactive bubble ────────────────────────────────────────── */

.an-bubble {
  position: absolute;
  bottom: 72px;
  right: 0;
  background: #fff;
  border: 1px solid #DDD5C8;
  border-radius: 16px 16px 4px 16px; /* speech tail: bottom-right */
  padding: 10px 36px 10px 14px;
  font-size: 13px;
  color: #0F0E0D;
  max-width: 220px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(15, 14, 13, 0.12);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* Triangle tail pointing down-right toward trigger */
.an-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 16px;
  border: 8px solid transparent;
  border-top-color: #fff;
  border-bottom: none;
}

.an-bubble--visible {
  opacity: 1;
  transform: translateY(0);
}

.an-bubble-text {
  font-size: 13px;
  color: #0F0E0D;
  line-height: 1.5;
  margin: 0;
}

.an-bubble-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  font-size: 1rem;
  color: #8A8474;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 3px;
}

.an-bubble-close:hover { color: #0F0E0D; }

/* ── Reduced motion ──────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .an-trigger       { animation: none; }
  .an-window        { transition: none; }
  .an-window--open  { animation: none; opacity: 1; transform: none; }
  .an-msg           { animation: none; }
  .an-dot           { animation: none; opacity: 1; }
  .an-bubble        { transition: none; }
}

/* ── Mobile ──────────────────────────────────────────────────── */

@media (max-width: 480px) {
  #aling-nena-widget {
    bottom: 16px;
    right: 16px;
  }

  .an-window {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100vw;
    height: 70vh;
    max-height: 600px;
    border-radius: 20px 20px 0 0;
    transform-origin: bottom center;
  }

  .an-window--open {
    animation: npSlideUpMobile 0.3s ease both;
  }

  .an-bubble {
    max-width: 200px;
  }
}
