/* AstroPixels AI Chat Widget - Astromech Datapad Styling */
@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Share+Tech+Mono&display=swap');

:root {
  --ap-blue: #0077dd;
  --ap-blue-dark: #00509e;
  --ap-blue-glow: rgba(0, 136, 255, 0.35);
  --ap-cyan: #00e5ff;
  --ap-cyan-glow: rgba(0, 229, 255, 0.4);
  --ap-red: #ff2d55;
  --ap-amber: #ffaa00;
  --ap-bg: #090c12;
  --ap-card-bg: #111622;
  --ap-card-sub: #182030;
  --ap-text: #e2e8f0;
  --ap-text-muted: #8493a8;
  --ap-border: #1e293b;
  --ap-border-glow: rgba(0, 150, 255, 0.28);
  --ap-font-tech: 'Chakra Petch', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --ap-font-mono: 'Share Tech Mono', monospace, Consolas, monospace;
}

/* Astromech Projector / Radar Eye Toggle Button */
#ap-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #1a8cff 0%, #0055b3 60%, #002b66 100%);
  color: #fff;
  border: 3px solid rgba(0, 229, 255, 0.4);
  box-shadow: 0 4px 20px rgba(0, 119, 221, 0.5), 0 0 15px rgba(0, 229, 255, 0.35), inset 0 0 10px rgba(255, 255, 255, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease;
}

#ap-chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(0, 140, 255, 0.75), 0 0 25px rgba(0, 229, 255, 0.6);
  border-color: var(--ap-cyan);
}

#ap-chat-toggle svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
  filter: drop-shadow(0 0 4px rgba(0, 229, 255, 0.6));
}

/* Chat Window - Sci-Fi Astromech Datapad Frame */
#ap-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 400px;
  height: 590px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  background: 
    linear-gradient(180deg, rgba(17, 22, 34, 0.97) 0%, rgba(9, 12, 18, 0.98) 100%),
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0, 150, 255, 0.02) 2px, rgba(0, 150, 255, 0.02) 4px);
  border: 1px solid var(--ap-border-glow);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.8), 0 0 24px rgba(0, 119, 221, 0.25), inset 0 0 20px rgba(0, 85, 170, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
  font-family: var(--ap-font-tech);
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px) scale(0.96);
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

#ap-chat-window.ap-open {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0) scale(1);
}

/* Header with Dual-LED Droid Telemetry */
.ap-header {
  background: linear-gradient(90deg, #101520 0%, #151b2a 100%);
  border-bottom: 1px solid var(--ap-border-glow);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.ap-header-telemetry {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Dual Droid Logic & PSI Blinkers */
.ap-psi-blinker {
  display: flex;
  gap: 4px;
  padding: 4px 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(0, 229, 255, 0.2);
  border-radius: 10px;
}

.ap-psi-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.ap-psi-led.psi {
  animation: ap-psi-cycle 3s infinite ease-in-out;
}

.ap-psi-led.logic {
  animation: ap-logic-cycle 0.8s infinite steps(2, start);
}

@keyframes ap-psi-cycle {
  0%, 100% {
    background: #ff2d55;
    box-shadow: 0 0 8px #ff2d55;
  }
  50% {
    background: #0077dd;
    box-shadow: 0 0 8px #0077dd;
  }
}

@keyframes ap-logic-cycle {
  0%, 100% {
    background: #00e5ff;
    box-shadow: 0 0 8px #00e5ff;
  }
  50% {
    background: #ffaa00;
    box-shadow: 0 0 6px #ffaa00;
  }
}

.ap-header-text {
  display: flex;
  flex-direction: column;
}

.ap-header-title {
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: 0.5px;
  color: #fff;
  text-shadow: 0 0 8px rgba(0, 229, 255, 0.3);
}

.ap-header-sub {
  font-family: var(--ap-font-mono);
  font-size: 10.5px;
  letter-spacing: 1px;
  color: var(--ap-cyan);
  opacity: 0.85;
}

.ap-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ap-tool-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--ap-text-muted);
  cursor: pointer;
  font-size: 13px;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.ap-tool-btn:hover {
  background: rgba(0, 229, 255, 0.15);
  border-color: var(--ap-cyan);
  color: var(--ap-cyan);
}

.ap-close-btn {
  font-size: 18px;
  line-height: 1;
}

/* Message Log Container */
.ap-messages {
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 150, 255, 0.4) transparent;
  background: 
    radial-gradient(ellipse at 50% 10%, rgba(0, 119, 221, 0.08) 0%, transparent 70%),
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0, 229, 255, 0.015) 2px, rgba(0, 229, 255, 0.015) 4px);
}

.ap-messages::-webkit-scrollbar {
  width: 6px;
}

.ap-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 150, 255, 0.4);
  border-radius: 4px;
}

.ap-messages::-webkit-scrollbar-track {
  background: transparent;
}

/* Datapad Transmission Blocks */
.ap-msg {
  max-width: 90%;
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
}

/* Transmission Metadata Badge */
.ap-msg-badge {
  font-family: var(--ap-font-mono);
  font-size: 10px;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
  opacity: 0.85;
}

.ap-msg-badge .ap-badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  background: currentColor;
}

/* User Bubble */
.ap-msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #0066cc 0%, #004c99 100%);
  color: #fff;
  border: 1px solid rgba(100, 180, 255, 0.4);
  border-right: 3px solid #00e5ff;
  border-top-right-radius: 2px;
  box-shadow: 0 4px 12px rgba(0, 80, 170, 0.35);
}

.ap-msg-user .ap-msg-badge {
  color: #cce6ff;
}

/* Assistant Bubble */
.ap-msg-assistant {
  align-self: flex-start;
  background: rgba(18, 24, 36, 0.95);
  color: var(--ap-text);
  border: 1px solid rgba(0, 150, 255, 0.2);
  border-left: 3px solid var(--ap-cyan);
  border-top-left-radius: 2px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.ap-msg-assistant .ap-msg-badge {
  color: var(--ap-cyan);
}

.ap-msg a {
  color: var(--ap-cyan);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ap-msg pre {
  background: #06090e;
  border: 1px solid rgba(0, 229, 255, 0.25);
  border-left: 3px solid var(--ap-amber);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  font-family: var(--ap-font-mono);
  font-size: 12px;
  margin: 8px 0;
  color: #93c5fd;
}

.ap-msg code {
  font-family: var(--ap-font-mono);
  background: rgba(0, 229, 255, 0.1);
  color: #7dd3fc;
  padding: 2px 5px;
  border-radius: 4px;
}

.ap-msg pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

/* Datapad Starter Chips */
.ap-starters {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 10px;
}

.ap-starter-btn {
  background: rgba(0, 119, 221, 0.1);
  color: #7dd3fc;
  border: 1px solid rgba(0, 150, 255, 0.35);
  padding: 8px 12px;
  border-radius: 6px;
  font-family: var(--ap-font-tech);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.3px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.ap-starter-btn::before {
  content: "▹";
  color: var(--ap-cyan);
  font-size: 14px;
}

.ap-starter-btn:hover {
  background: rgba(0, 150, 255, 0.25);
  border-color: var(--ap-cyan);
  color: #fff;
  transform: translateX(3px);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.3);
}

/* Input Area */
.ap-input-area {
  padding: 12px 14px;
  background: #0e131d;
  border-top: 1px solid var(--ap-border-glow);
  display: flex;
  gap: 8px;
  align-items: center;
}

.ap-input-area input {
  flex: 1;
  background: #06090e;
  border: 1px solid rgba(0, 150, 255, 0.3);
  color: var(--ap-text);
  padding: 9px 12px;
  border-radius: 6px;
  font-family: var(--ap-font-tech);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ap-input-area input:focus {
  border-color: var(--ap-cyan);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.25);
}

.ap-send-btn {
  background: linear-gradient(135deg, var(--ap-blue), var(--ap-blue-dark));
  color: #fff;
  border: 1px solid rgba(0, 229, 255, 0.4);
  border-radius: 6px;
  padding: 0 16px;
  height: 38px;
  cursor: pointer;
  font-family: var(--ap-font-tech);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ap-send-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #0088ff, #0066cc);
  border-color: var(--ap-cyan);
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.4);
}

.ap-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Animated Droid Telemetry Wave (Typing state) */
.ap-typing {
  font-family: var(--ap-font-mono);
  color: var(--ap-cyan);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ap-typing-wave {
  display: flex;
  align-items: center;
  gap: 3px;
}

.ap-typing-wave span {
  width: 3px;
  height: 12px;
  background: var(--ap-cyan);
  border-radius: 2px;
  animation: ap-wave-bar 0.9s infinite ease-in-out;
}

.ap-typing-wave span:nth-child(2) { animation-delay: 0.15s; }
.ap-typing-wave span:nth-child(3) { animation-delay: 0.3s; }
.ap-typing-wave span:nth-child(4) { animation-delay: 0.45s; }

@keyframes ap-wave-bar {
  0%, 100% { height: 4px; opacity: 0.3; }
  50% { height: 16px; opacity: 1; box-shadow: 0 0 8px var(--ap-cyan); }
}
