/**
 * RoccOS Gio Character + Chat Popover
 * Solid surfaces, visible borders, retro speech bubbles
 */

/* ── Gio Character ── */
.gio {
  position: absolute;
  bottom: calc(var(--dock-height) + var(--dock-padding) * 2 + var(--sp-4));
  right: var(--sp-6);
  z-index: var(--z-gio);
  cursor: grab;
  transition: transform var(--duration-fast) var(--ease-out);
}

.gio:active {
  cursor: grabbing;
}

.gio:hover {
  transform: scale(1.05);
}

.gio-sprite {
  width: 64px;
  height: 64px;
  animation: gentleBob 4s ease-in-out infinite;
}

.gio-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* Gio moods */
.gio[data-mood="sleeping"] .gio-sprite {
  animation: breathe 3s ease-in-out infinite;
  opacity: 0.7;
}

.gio[data-mood="thinking"] .gio-sprite {
  animation: none;
}

.gio[data-mood="excited"] .gio-sprite {
  animation: wiggle 0.5s ease-in-out infinite;
}

/* ── Speech Bubble — solid, bordered ── */
.gio-speech {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  max-width: 280px;
  padding: var(--sp-3) var(--sp-4);
  background: var(--os-surface);
  border: 2px solid var(--os-border);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  color: var(--os-text);
  line-height: var(--leading-normal);
  animation: speechBubbleIn 0.3s var(--ease-spring) both;
}

.gio-speech.dismissing {
  animation: speechBubbleOut 0.2s var(--ease-in-out) forwards;
}

/* Tail — solid CSS triangle */
.gio-speech::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 16px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--os-surface);
  filter: drop-shadow(0 2px 0 var(--os-border));
}

/* ── Thinking Dots ── */
.gio-thinking {
  display: flex;
  gap: 4px;
  padding: var(--sp-2) var(--sp-3);
}

.gio-thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--os-text-muted);
  animation: typingDot 1.4s ease-in-out infinite;
}

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

/* ── Chat Popover — positioned relative to Gio (its parent) ── */
.gio-chat {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  z-index: 1;
  width: 420px;
  max-height: 400px;
  display: flex;
  flex-direction: column;
  background: var(--os-surface);
  border: 2px solid var(--os-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: retroBounce 0.25s var(--ease-spring) both;
  transform-origin: bottom right;
}

.gio-chat[hidden] {
  display: none;
}

/* Override grab cursor inside chat */
.gio-chat,
.gio-chat * {
  cursor: default;
}
.gio-chat .gio-chat-close,
.gio-chat .gio-chat-send,
.gio-chat .gio-chat-input {
  cursor: pointer;
}
.gio-chat .gio-chat-input {
  cursor: text;
}

.gio-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 2px solid var(--os-border);
  flex-shrink: 0;
  background: var(--os-surface-raised);
}

.gio-chat-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.gio-chat-close {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--os-border-subtle);
  background: var(--os-surface);
  color: var(--os-text-muted);
  font-size: 18px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--duration-fast), color var(--duration-fast);
}

.gio-chat-close:hover {
  background: var(--os-accent);
  color: var(--os-accent-text);
  border-color: var(--os-accent);
}

.gio-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.gio-chat-msg {
  max-width: 85%;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  border: 2px solid var(--os-border-subtle);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  animation: slideUp 0.2s var(--ease-out) both;
}

.gio-chat-msg.gio {
  background: var(--os-surface-raised);
  color: var(--os-text);
  align-self: flex-start;
  border-bottom-left-radius: var(--radius-sm);
}

.gio-chat-msg.user {
  background: var(--os-accent);
  color: var(--os-accent-text);
  align-self: flex-end;
  border-bottom-right-radius: var(--radius-sm);
  border-color: var(--os-accent-hover);
}

.gio-chat-input-form {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-top: 2px solid var(--os-border);
  flex-shrink: 0;
}

.gio-chat-input {
  flex: 1;
  border: 2px solid var(--os-border-subtle);
  background: var(--os-bg);
  color: var(--os-text);
  font-family: var(--font-system);
  font-size: var(--text-sm);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--duration-fast);
}

.gio-chat-input:focus {
  border-color: var(--os-accent);
}

.gio-chat-input::placeholder {
  color: var(--os-text-muted);
}

.gio-chat-send {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--os-accent);
  background: var(--os-accent);
  color: var(--os-accent-text);
  border-radius: var(--radius-md);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--duration-fast);
  box-shadow: var(--shadow-sm);
}

.gio-chat-send:hover {
  background: var(--os-accent-hover);
  border-color: var(--os-accent-hover);
}
