/* ============================================================
   SAGE — the Sahara AI guide
   A geometric "chip" character, not a cartoon avatar.
   States are pure CSS/JS, no image assets required.
   ============================================================ */

#sage-root {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 900;
  font-family: 'Inter', sans-serif;
}

/* ---- Bubble that pops up above the mascot ---- */
.sage-bubble {
  position: absolute;
  bottom: 74px;
  right: 0;
  max-width: 240px;
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  border: 1px solid rgba(255,255,255,0.16);
  color: var(--text);
  padding: 12px 15px;
  border-radius: 14px 14px 4px 14px;
  font-size: 13.5px;
  box-shadow: 0 18px 40px -18px rgba(0,0,0,.4);
  opacity: 0;
  transform: translateY(6px) scale(.97);
  transform-origin: bottom right;
  transition: opacity .3s var(--ease), transform .3s var(--ease);
  pointer-events: none;
}
.sage-bubble.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

/* ---- The avatar button ---- */
.sage-avatar {
  width: 60px; height: 60px;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--purple-light), var(--purple) 55%, var(--orange));
  border: none;
  cursor: pointer;
  position: relative;
  box-shadow: 0 16px 34px -12px rgba(139,63,224,.55);
  transition: transform .3s var(--ease);
}
.sage-avatar:hover { transform: translateY(-3px) scale(1.03); }

.sage-face {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.sage-eyes { display: flex; gap: 9px; }
.sage-eye { width: 7px; height: 7px; border-radius: 50%; background: #fff; }
.sage-mouth { width: 20px; height: 2.5px; border-radius: 3px; background: rgba(255,255,255,.85); }

/* Idle: gentle blink + breathing scale */
.sage-avatar.state-idle .sage-eye { animation: sageBlink 4.2s infinite; }
.sage-avatar.state-idle { animation: sageBreathe 3.6s ease-in-out infinite; }
@keyframes sageBlink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.15); } }
@keyframes sageBreathe { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

/* Thinking: eyes shift + small orbit dot */
.sage-avatar.state-thinking .sage-eyes { animation: sageThink 1.4s ease-in-out infinite; }
.sage-avatar.state-thinking .sage-mouth { width: 8px; border-radius: 50%; height: 8px; }
@keyframes sageThink { 0%,100% { transform: translateX(0); } 50% { transform: translateX(3px); } }

/* Typing: mouth pulses like a cursor */
.sage-avatar.state-typing .sage-mouth { animation: sageType .5s steps(2) infinite; }
@keyframes sageType { 50% { opacity: 0.2; width: 12px; } }

/* Listening: ring pulses outward */
.sage-avatar.state-listening::before {
  content: ""; position: absolute; inset: -6px; border-radius: 22px;
  border: 2px solid var(--orange); opacity: .6;
  animation: sageListen 1.2s ease-out infinite;
}
@keyframes sageListen { 0% { transform: scale(.9); opacity: .7; } 100% { transform: scale(1.25); opacity: 0; } }

/* Happy: eyes curve up (approximated via squish) + mouth widens */
.sage-avatar.state-happy .sage-eye { border-radius: 50% 50% 40% 40%; transform: scaleY(0.7) translateY(-1px); }
.sage-avatar.state-happy .sage-mouth { width: 24px; border-radius: 0 0 12px 12px; height: 8px; background: transparent; border-bottom: 2.5px solid #fff; }

/* Waving: whole avatar tilts */
.sage-avatar.state-waving { animation: sageWave .6s ease-in-out 2; }
@keyframes sageWave { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }

/* Sleeping: eyes close, "z" drifts */
.sage-avatar.state-sleeping .sage-eye { height: 1.5px; border-radius: 2px; }
.sage-avatar.state-sleeping .sage-mouth { opacity: .4; }
.sage-avatar.state-sleeping::after {
  content: "z"; position: absolute; top: -8px; right: 2px; color: var(--orange);
  font-family: 'Space Grotesk'; font-size: 13px; font-weight: 700;
  animation: sageZ 2.4s ease-in-out infinite;
}
@keyframes sageZ { 0% { opacity: 0; transform: translateY(0); } 40% { opacity: .9; } 100% { opacity: 0; transform: translateY(-14px) translateX(6px); } }

/* Celebrating: bounce + confetti dots */
.sage-avatar.state-celebrating { animation: sageBounce .5s ease-in-out 3; }
@keyframes sageBounce { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-10px) scale(1.08); } }

/* Unread ping */
.sage-ping {
  position: absolute; top: -3px; right: -3px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--orange); border: 2px solid var(--bg);
  opacity: 0; transform: scale(0); transition: .3s var(--ease);
}
.sage-ping.show { opacity: 1; transform: scale(1); }

/* ---- Chat panel ---- */
.sage-panel {
  position: absolute;
  bottom: 78px; right: 0;
  width: 340px; max-width: calc(100vw - 44px);
  height: 460px; max-height: 70vh;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(26px) saturate(180%);
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 18px;
  box-shadow: 0 40px 90px -30px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,0.1);
  display: flex; flex-direction: column;
  opacity: 0; transform: translateY(14px) scale(.97);
  pointer-events: none;
  transform-origin: bottom right;
  transition: opacity .3s var(--ease), transform .3s var(--ease);
  overflow: hidden;
}
.sage-panel.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

.sage-panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(120deg, color-mix(in srgb, var(--purple) 18%, transparent), transparent);
}
.sage-mini-avatar { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(145deg, var(--purple-light), var(--orange)); flex-shrink: 0; }
.sage-panel-head strong { font-size: 14.5px; display: block; }
.sage-panel-head small { color: var(--muted); font-size: 11.5px; display: flex; align-items: center; gap: 5px; }
.sage-status-dot { width: 6px; height: 6px; border-radius: 50%; background: #59e3a4; }
.sage-close { margin-left: auto; background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; }
.sage-close svg { width: 18px; height: 18px; }

.sage-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.sage-messages::-webkit-scrollbar { width: 5px; }
.sage-messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; }

.sage-msg { max-width: 84%; font-size: 13.5px; padding: 10px 13px; border-radius: 12px; line-height: 1.5; }
.sage-msg.bot { background: var(--surface-2); align-self: flex-start; border-bottom-left-radius: 3px; }
.sage-msg.user { background: var(--orange); color: #150726; align-self: flex-end; border-bottom-right-radius: 3px; font-weight: 500; }

.sage-suggestions { display: flex; flex-direction: column; gap: 7px; padding: 0 16px 12px; }
.sage-chip {
  text-align: left; font-size: 12.5px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--muted);
  cursor: pointer; transition: .2s;
}
.sage-chip:hover { border-color: var(--orange); color: var(--text); }

.sage-typing-indicator { display: flex; gap: 4px; align-self: flex-start; padding: 12px 15px; background: var(--surface-2); border-radius: 12px; border-bottom-left-radius: 3px; }
.sage-typing-indicator span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: sageDot 1.2s infinite; }
.sage-typing-indicator span:nth-child(2) { animation-delay: .15s; }
.sage-typing-indicator span:nth-child(3) { animation-delay: .3s; }
@keyframes sageDot { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.sage-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.sage-input-row input {
  flex: 1; background: var(--surface-2); border: 1px solid var(--line); border-radius: 100px;
  padding: 10px 14px; font-size: 13.5px; color: var(--text);
}
.sage-input-row input:focus { outline: none; border-color: var(--orange); }
.sage-send { width: 38px; height: 38px; border-radius: 50%; border: none; background: var(--orange); color: #150726; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.sage-send svg { width: 16px; height: 16px; }

@media (max-width: 420px) {
  .sage-panel { width: calc(100vw - 32px); right: -6px; }
}
