/* ═══════════════════════════════════════════════════════════════
   KAKOARA ASSISTANT v3.1 — Voice Modality
   Premium glassmorphism chat + voice browse
   Zero-impact — never breaks core functionality
   ═══════════════════════════════════════════════════════════════ */

:root {
  --pa-gold: #C8943B;
  --pa-gold-dark: #A6782E;
  --pa-gold-light: #E8C56A;
  --pa-bg: #F5F0EB;
  --pa-surface: #FCFAF7;
  --pa-text: #2C1810;
  --pa-text-muted: #9C8B7A;
  --pa-bot-bubble: #EDE6DC;
  --pa-user-bubble: #D4845E;
  --pa-border: rgba(180, 140, 100, 0.12);
  --pa-shadow: rgba(60, 40, 20, 0.08);
  --pa-terracotta: #D4845E;
  --pa-radius: 14px;
  --pa-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pa-ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ═══════════════════════════════════════════════════════════════
   FLOATING ACTION BUTTON
   ═══════════════════════════════════════════════════════════════ */

.pa-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2147483647;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #D4845E 0%, #C8943B 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(212, 132, 94, 0.3),
    0 2px 8px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.35s var(--pa-ease);
  position: relative;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.pa-fab::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(212, 132, 94, 0.25);
  animation: pa-pulse-ring 2.5s cubic-bezier(0.455, 0.03, 0.515, 0.955) infinite;
  pointer-events: none;
}

@keyframes pa-pulse-ring {
  0% { transform: scale(0.92); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 0.3; }
  100% { transform: scale(1.3); opacity: 0; }
}

.pa-fab:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 8px 30px rgba(212, 132, 94, 0.4),
    0 4px 12px rgba(0,0,0,0.15);
  background: linear-gradient(135deg, #E8C56A 0%, #D4845E 100%);
}

.pa-fab:active {
  transform: scale(0.92);
}

.pa-fab svg {
  width: 22px;
  height: 22px;
  transition: transform 0.3s var(--pa-ease);
}

.pa-fab__close-icon { display: none; }
.pa-fab.is-open .pa-fab__open-icon { display: none; }
.pa-fab.is-open .pa-fab__close-icon { display: block; }
.pa-fab.is-open::before { animation: none; opacity: 0; }

/* ─── Online Status Dot ─── */

.pa-fab__dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2ecc71;
  border: 2.5px solid #fff;
  z-index: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.pa-fab__dot::after {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  background: #2ecc71;
  animation: pa-dot-pulse 2s ease-in-out infinite;
}

@keyframes pa-dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ─── Unread Badge ─── */

.pa-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #e74c3c;
  color: #fff;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  z-index: 2;
  display: none;
  box-shadow: 0 2px 6px rgba(231, 76, 60, 0.4);
  animation: pa-badge-in 0.3s var(--pa-ease-bounce);
}

.pa-badge.is-visible { display: block; }

@keyframes pa-badge-in {
  0% { transform: scale(0); }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ═══════════════════════════════════════════════════════════════
   CHAT PANEL
   ═══════════════════════════════════════════════════════════════ */

.pa-panel {
  position: fixed;
  bottom: 86px;
  right: 24px;
  z-index: 2147483646;
  width: 360px;
  max-height: 540px;
  background: var(--pa-surface);
  border-radius: var(--pa-radius);
  box-shadow:
    0 16px 48px rgba(60, 40, 20, 0.12),
    0 4px 16px rgba(60, 40, 20, 0.06);
  overflow: hidden;
  display: none;
  flex-direction: column;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transition: all 0.35s var(--pa-ease);
  pointer-events: auto;
  border: 1px solid rgba(180, 140, 100, 0.15);
}

.pa-panel.is-open {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ═══════════════════════════════════════════════════════════════
   PANEL HEADER
   ═══════════════════════════════════════════════════════════════ */

.pa-header {
  background: linear-gradient(135deg, #D4845E 0%, #C8943B 100%);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.pa-header::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 120px;
  height: 100%;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.08) 100%);
  pointer-events: none;
}

.pa-header__left {
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1;
}

.pa-header__avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(255,255,255,0.25) 0%, rgba(255,255,255,0.1) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.pa-header__info { flex: 1; min-width: 0; }

.pa-header__title {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  color: #fff;
  letter-spacing: -0.01em;
}

.pa-header__status {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.6);
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.pa-header__status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2ecc71;
  display: inline-block;
  animation: pa-dot-pulse 2s ease-in-out infinite;
}

.pa-header__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 1;
}

.pa-header__btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: all 0.2s;
  padding: 0;
  line-height: 1;
}

.pa-header__btn:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.pa-header__btn--sound.is-muted {
  opacity: 0.4;
}

/* ═══════════════════════════════════════════════════════════════
   CHAT BODY
   ═══════════════════════════════════════════════════════════════ */

.pa-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: #fafaf8;
  min-height: 200px;
}

.pa-body::-webkit-scrollbar {
  width: 4px;
}

.pa-body::-webkit-scrollbar-track {
  background: transparent;
}

.pa-body::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 2px;
}

.pa-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.18);
}

/* ═══════════════════════════════════════════════════════════════
   CHAT BUBBLES
   ═══════════════════════════════════════════════════════════════ */

.pa-message {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.8rem;
  line-height: 1.55;
  animation: pa-msg-in 0.35s var(--pa-ease) both;
  word-wrap: break-word;
  position: relative;
}

@keyframes pa-msg-in {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* User message */
.pa-message--user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--pa-user-bubble) 0%, var(--pa-gold) 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(212, 132, 94, 0.15);
}

/* Bot message */
.pa-message--bot {
  align-self: flex-start;
  background: var(--pa-bot-bubble);
  color: var(--pa-text);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(255,255,255,0.5);
}

.pa-message--bot strong {
  color: var(--pa-gold-dark);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════
   TYPING INDICATOR
   ═══════════════════════════════════════════════════════════════ */

.pa-typing {
  align-self: flex-start;
  display: none;
  align-items: center;
  gap: 5px;
  padding: 12px 18px;
  background: var(--pa-bot-bubble);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(255,255,255,0.6);
  margin-top: -4px;
}

.pa-typing.is-visible {
  display: flex;
  animation: pa-msg-in 0.25s var(--pa-ease) both;
}

.pa-typing__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #bbb;
  animation: pa-typing-bounce 1.4s ease-in-out infinite;
}

.pa-typing__dot:nth-child(2) { animation-delay: 0.16s; }
.pa-typing__dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes pa-typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    background: #bbb;
  }
  30% {
    transform: translateY(-8px);
    background: var(--pa-gold);
  }
}

/* ═══════════════════════════════════════════════════════════════
   SUGGESTION CHIPS
   ═══════════════════════════════════════════════════════════════ */

.pa-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 8px;
  animation: pa-msg-in 0.35s var(--pa-ease) both;
}

.pa-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1.5px solid rgba(0,0,0,0.07);
  background: #fff;
  color: #555;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.7rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s var(--pa-ease);
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.pa-chip:hover {
  border-color: var(--pa-gold);
  color: var(--pa-gold-dark);
  background: #faf8f5;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(200, 148, 59, 0.12);
}

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

.pa-chip span {
  font-size: 0.8rem;
}

/* ═══════════════════════════════════════════════════════════════
   INPUT AREA
   ═══════════════════════════════════════════════════════════════ */

.pa-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--pa-border);
  background: #fff;
  flex-shrink: 0;
}

.pa-input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1.5px solid rgba(0,0,0,0.07);
  background: #f5f5f5;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.8rem;
  color: var(--pa-text);
  outline: none;
  transition: all 0.2s var(--pa-ease);
}

.pa-input:focus {
  border-color: var(--pa-gold);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(200, 148, 59, 0.08);
}

.pa-input::placeholder {
  color: #aaa;
}

.pa-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--pa-user-bubble) 0%, var(--pa-gold) 100%);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s var(--pa-ease);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(212, 132, 94, 0.2);
}

.pa-send-btn:hover {
  background: linear-gradient(135deg, var(--pa-gold-light) 0%, var(--pa-user-bubble) 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(212, 132, 94, 0.3);
}

.pa-send-btn:active {
  transform: scale(0.94);
}

.pa-send-btn svg {
  width: 16px;
  height: 16px;
}

/* ═══════════════════════════════════════════════════════════════
   FOOTER LINKS
   ═══════════════════════════════════════════════════════════════ */

.pa-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 8px 14px 10px;
  background: #fafaf8;
  flex-shrink: 0;
  border-top: 1px solid var(--pa-border);
}

.pa-footer a {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.65rem;
  color: #aaa;
  text-decoration: none;
  transition: color 0.2s;
  position: relative;
}

.pa-footer a:not(:last-child)::after {
  content: '';
  position: absolute;
  right: -9px;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 10px;
  background: rgba(0,0,0,0.08);
}

.pa-footer a:hover {
  color: var(--pa-gold);
}

/* ═══════════════════════════════════════════════════════════════
   PROACTIVE MESSAGE BANNER
   ═══════════════════════════════════════════════════════════════ */

.pa-proactive {
  position: fixed;
  bottom: 82px;
  right: 24px;
  z-index: 2147483645;
  background: #fff;
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  max-width: 260px;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.75rem;
  color: var(--pa-text);
  line-height: 1.5;
  cursor: pointer;
  animation: pa-proactive-in 0.5s var(--pa-ease-bounce) both;
  border: 1px solid rgba(200, 148, 59, 0.15);
  display: none;
}

.pa-proactive.is-visible { display: block; }

@keyframes pa-proactive-in {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.9);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.pa-proactive__close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.05);
  color: #999;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  line-height: 1;
  transition: all 0.2s;
  padding: 0;
}

.pa-proactive__close:hover {
  background: rgba(0,0,0,0.1);
  color: #333;
}

.pa-proactive__text {
  padding-right: 20px;
}

.pa-proactive__text strong {
  color: var(--pa-gold-dark);
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .pa-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 76px;
    max-height: 70vh;
    border-radius: 14px;
  }

  .pa-fab {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 50px;
    height: 50px;
  }

  .pa-fab svg { width: 22px; height: 22px; }

  .pa-message {
    max-width: 90%;
    font-size: 0.82rem;
  }

  .pa-proactive {
    right: 12px;
    left: 12px;
    max-width: none;
    bottom: 80px;
  }

  .pa-input {
    height: 44px;
    font-size: 0.85rem;
  }

  .pa-send-btn {
    width: 44px;
    height: 44px;
  }

  .pa-mic-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .pa-mic-btn svg { width: 16px; height: 16px; }
  .pa-header__btn { width: 44px; height: 44px; }
  .pa-proactive__close { width: 44px; height: 44px; top: 4px; right: 4px; font-size: 1rem; }
}

@media (max-width: 480px) {
  .pa-panel {
    right: 6px;
    left: 6px;
    width: auto;
    bottom: 60px;
    max-height: 60vh;
    border-radius: 10px;
  }

  .pa-fab {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    right: 8px;
    width: 40px;
    height: 40px;
  }

  .pa-fab svg { width: 16px; height: 16px; }
  .pa-fab__dot { width: 10px; height: 10px; bottom: 0; right: 0; }
  .pa-fab::before { display: none; }

  .pa-message {
    max-width: 92%;
    font-size: 0.72rem;
    padding: 8px 12px;
  }

  .pa-proactive {
    right: 8px;
    left: 8px;
    max-width: none;
    bottom: 66px;
  }

  .pa-header {
    padding: 10px 12px;
  }
  .pa-header__avatar { width: 28px; height: 28px; font-size: 0.7rem; }
  .pa-header__title { font-size: 0.78rem; }
  .pa-header__status { font-size: 0.6rem; }

  .pa-body {
    padding: 8px 8px 4px;
  }

  .pa-input {
    height: 40px;
    font-size: 0.82rem;
    padding: 0 10px;
  }

  .pa-send-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .pa-send-btn svg {
    width: 14px;
    height: 14px;
  }

  .pa-mic-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
  }

  .pa-mic-btn svg { width: 12px; height: 12px; }
  .pa-header__btn { width: 36px; height: 36px; }
  .pa-proactive__close { width: 36px; height: 36px; top: 4px; right: 4px; font-size: 0.9rem; }
  .pa-chip { padding: 4px 10px; font-size: 0.6rem; }
  .pa-chip span { font-size: 0.7rem; }
  .pa-footer { gap: 10px; padding: 6px 10px 8px; }
  .pa-footer a { font-size: 0.58rem; }
}

/* ═══════════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .pa-fab,
  .pa-fab::before,
  .pa-panel,
  .pa-message,
  .pa-typing,
  .pa-chip,
  .pa-badge,
  .pa-proactive,
  .pa-mic-btn,
  .pa-mic-ring {
    animation: none !important;
    transition: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   VOICE INPUT — MICROPHONE BUTTON
   ═══════════════════════════════════════════════════════════════ */

.pa-mic-btn {
  position: relative;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #999;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
}

.pa-mic-btn:hover {
  color: var(--pa-terracotta);
  background: rgba(212, 132, 94, 0.08);
}

.pa-mic-btn:active {
  transform: scale(0.92);
}

.pa-mic-btn svg {
  width: 16px;
  height: 16px;
  position: relative;
  z-index: 2;
  transition: all 0.3s ease;
}

/* ─── Ripple rings ─── */

.pa-mic-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--pa-terracotta);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  transition: none;
}

.pa-mic--listening .pa-mic-ring {
  animation: pa-voice-ripple 1.8s ease-out infinite;
}

.pa-mic--listening .pa-mic-ring--delay {
  animation: pa-voice-ripple 1.8s ease-out infinite 0.6s;
}

@keyframes pa-voice-ripple {
  0% {
    transform: scale(0.85);
    opacity: 0.6;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

/* ─── States ─── */

.pa-mic--listening {
  color: #fff !important;
  background: var(--pa-terracotta) !important;
  box-shadow: 0 0 0 4px rgba(212, 132, 94, 0.2), 0 0 20px rgba(212, 132, 94, 0.15);
}

.pa-mic--listening svg {
  animation: pa-mic-pulse 1.2s ease-in-out infinite;
}

@keyframes pa-mic-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.pa-mic--processing {
  color: var(--pa-gold) !important;
  background: rgba(200, 148, 59, 0.12) !important;
  pointer-events: none;
}

.pa-mic--processing svg {
  animation: pa-mic-spin 0.8s linear infinite;
}

@keyframes pa-mic-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.pa-mic--error {
  color: #ef4444 !important;
  background: rgba(239, 68, 68, 0.1) !important;
  animation: pa-mic-shake 0.4s ease;
}

@keyframes pa-mic-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-4px); }
}

/* ═══════════════════════════════════════════════════════════════
   VOICE TOGGLE IN HEADER
   ═══════════════════════════════════════════════════════════════ */

.pa-header__btn--voice {
  font-size: 0.85rem;
  line-height: 1;
}

.pa-header__btn--voice.is-speaking {
  color: var(--pa-gold-light) !important;
  animation: pa-voice-toggle-speak 1s ease-in-out infinite;
}

@keyframes pa-voice-toggle-speak {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.pa-header__btn--voice.is-muted {
  opacity: 0.4;
}

/* ─── Visual waveform in header when speaking ─── */

.pa-header__btn--voice.is-speaking::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 2px;
  border-radius: 1px;
  background: var(--pa-gold-light);
  animation: pa-waveform 0.6s ease-in-out infinite;
}

@keyframes pa-waveform {
  0%, 100% { height: 2px; }
  50% { height: 5px; }
}