/*
 * bucky-chat.css — Styles for the BUCKy chat plugin
 *
 * Designed to overlay cleanly on a Reveal.js deck without interfering
 * with slide layout or navigation.
 */

/* ---------------------------------------------------------------------------
   CSS Custom Properties
   --------------------------------------------------------------------------- */
.bucky-root {
  --bucky-primary: #2563eb;
  --bucky-primary-dark: #1d4ed8;
  --bucky-accent: #f59e0b;
  --bucky-bg: #ffffff;
  --bucky-bg-alt: #f8fafc;
  --bucky-text: #1e293b;
  --bucky-text-muted: #64748b;
  --bucky-border: #e2e8f0;
  --bucky-user-bg: #2563eb;
  --bucky-user-text: #ffffff;
  --bucky-assistant-bg: #f1f5f9;
  --bucky-assistant-text: #1e293b;
  --bucky-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
  --bucky-radius: 16px;
  --bucky-panel-w: 400px;
  --bucky-panel-h: 520px;
  --bucky-fab-size: 96px;
  --bucky-z: 10000;

  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--bucky-text);
}

/* Dark theme */
.bucky-root[data-theme="dark"],
.bucky-root[data-theme="auto"] .reveal.has-dark-background ~ & {
  --bucky-bg: #1e293b;
  --bucky-bg-alt: #0f172a;
  --bucky-text: #e2e8f0;
  --bucky-text-muted: #94a3b8;
  --bucky-border: #334155;
  --bucky-assistant-bg: #334155;
  --bucky-assistant-text: #e2e8f0;
  --bucky-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ---------------------------------------------------------------------------
   Root & Positioning
   --------------------------------------------------------------------------- */
.bucky-root {
  position: fixed;
  z-index: var(--bucky-z);
  pointer-events: none;
}

.bucky-root * {
  box-sizing: border-box;
}

.bucky-root.bucky-bottom-right {
  bottom: 24px;
  right: 24px;
}

.bucky-root.bucky-bottom-left {
  bottom: 24px;
  left: 24px;
}

.bucky-root.bucky-top-right {
  top: 24px;
  right: 24px;
}

/* ---------------------------------------------------------------------------
   Floating Action Button (the character)
   --------------------------------------------------------------------------- */
.bucky-fab {
  pointer-events: auto;
  width: var(--bucky-fab-size);
  height: var(--bucky-fab-size);
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 4px 12px rgba(37, 99, 235, 0.3));
}

.bucky-fab:hover {
  transform: scale(1.1) translateY(-2px);
}

.bucky-fab:active {
  transform: scale(0.95);
}

.bucky-open .bucky-fab {
  transform: scale(0.85);
  opacity: 0.6;
}

/* Sleeping state — backend unavailable */
.bucky-sleeping .bucky-fab {
  opacity: 0.35;
  filter: grayscale(0.8);
  cursor: default;
  animation: none;
}

.bucky-sleeping .bucky-fab:hover {
  transform: none;
}

.bucky-character {
  width: 100%;
  height: 100%;
}

/* Blink animation — hold eyes shut 15-60% of the cycle */
@keyframes bucky-blink-anim {
  0%   { ry: 6; }
  10%  { ry: 0.5; }
  50%  { ry: 0.5; }
  70%  { ry: 6; }
  100% { ry: 6; }
}

.bucky-blink .bucky-eyes ellipse {
  animation: bucky-blink-anim 0.5s ease-in-out;
}
.bucky-blink .bucky-eyes circle {
  animation: bucky-blink-hide 0.5s ease-in-out;
}
@keyframes bucky-blink-hide {
  0%   { opacity: 1; }
  10%  { opacity: 0; }
  50%  { opacity: 0; }
  70%  { opacity: 1; }
  100% { opacity: 1; }
}

/* Thought bubbles */
.bucky-thought {
  pointer-events: none;
  position: absolute;
  bottom: calc(var(--bucky-fab-size) - 8px);
  right: calc(var(--bucky-fab-size) - 16px);
  background: white;
  color: #1e293b;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  animation: bucky-thought-in 0.3s ease-out;
  z-index: 1;
}

/* Tail — a small circle beneath the bubble */
.bucky-thought::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 12px;
  width: 10px;
  height: 10px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

@keyframes bucky-thought-in {
  from { opacity: 0; transform: translateY(6px) scale(0.8); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.bucky-thought-out {
  opacity: 0;
  transform: translateY(-4px) scale(0.9);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Hide thoughts when sleeping or panel open */
.bucky-sleeping .bucky-thought,
.bucky-open .bucky-thought {
  display: none;
}

/* Idle floating */
@keyframes bucky-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.bucky-fab:not(:hover) .bucky-character {
  animation: bucky-float 4s ease-in-out infinite;
}

/* Loading pulse on character */
@keyframes bucky-pulse {
  0%, 100% { filter: drop-shadow(0 4px 12px rgba(37, 99, 235, 0.3)); }
  50% { filter: drop-shadow(0 4px 20px rgba(37, 99, 235, 0.6)); }
}

.bucky-root.bucky-open .bucky-fab {
  animation: none;
}

/* ---------------------------------------------------------------------------
   Chat Panel
   --------------------------------------------------------------------------- */
.bucky-panel {
  pointer-events: auto;
  position: absolute;
  width: var(--bucky-panel-w);
  height: var(--bucky-panel-h);
  max-height: calc(100vh - 100px);
  max-width: calc(100vw - 48px);
  background: var(--bucky-bg);
  border-radius: var(--bucky-radius);
  box-shadow: var(--bucky-shadow);
  border: 1px solid var(--bucky-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Hidden by default */
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

.bucky-open .bucky-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Position relative to FAB */
.bucky-bottom-right .bucky-panel {
  bottom: calc(var(--bucky-fab-size) + 12px);
  right: 0;
}

.bucky-bottom-left .bucky-panel {
  bottom: calc(var(--bucky-fab-size) + 12px);
  left: 0;
}

.bucky-top-right .bucky-panel {
  top: calc(var(--bucky-fab-size) + 12px);
  right: 0;
}

/* ---------------------------------------------------------------------------
   Panel Header
   --------------------------------------------------------------------------- */
.bucky-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bucky-primary);
  color: white;
  flex-shrink: 0;
}

.bucky-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
}

.bucky-panel-icon {
  font-size: 18px;
}

.bucky-panel-badge {
  font-size: 10px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.02em;
}

.bucky-panel-actions {
  display: flex;
  gap: 4px;
}

.bucky-panel-actions button {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.bucky-panel-actions button:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ---------------------------------------------------------------------------
   Messages Area
   --------------------------------------------------------------------------- */
.bucky-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bucky-bg-alt);
}

/* Scrollbar styling */
.bucky-messages::-webkit-scrollbar {
  width: 5px;
}
.bucky-messages::-webkit-scrollbar-track {
  background: transparent;
}
.bucky-messages::-webkit-scrollbar-thumb {
  background: var(--bucky-border);
  border-radius: 3px;
}

/* Message bubbles */
.bucky-msg {
  max-width: 88%;
  animation: bucky-msg-in 0.2s ease-out;
}

@keyframes bucky-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bucky-msg-user {
  align-self: flex-end;
}

.bucky-msg-assistant {
  align-self: flex-start;
}

.bucky-msg-content {
  padding: 10px 14px;
  border-radius: 14px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.bucky-msg-user .bucky-msg-content {
  background: var(--bucky-user-bg);
  color: var(--bucky-user-text);
  border-bottom-right-radius: 4px;
}

.bucky-msg-assistant .bucky-msg-content {
  background: var(--bucky-assistant-bg);
  color: var(--bucky-assistant-text);
  border-bottom-left-radius: 4px;
}

/* Typography inside assistant messages */
.bucky-msg-assistant .bucky-msg-content p {
  margin: 0 0 8px 0;
}
.bucky-msg-assistant .bucky-msg-content p:last-child {
  margin-bottom: 0;
}
.bucky-msg-assistant .bucky-msg-content code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}
.bucky-msg-assistant .bucky-msg-content pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.85em;
}
.bucky-msg-assistant .bucky-msg-content pre code {
  background: none;
  padding: 0;
  color: inherit;
}
.bucky-msg-assistant .bucky-msg-content strong {
  font-weight: 600;
}
.bucky-msg-assistant .bucky-msg-content a {
  color: var(--bucky-primary);
  text-decoration: underline;
}

/* Streaming indicator */
.bucky-streaming .bucky-msg-content::after {
  content: '▋';
  animation: bucky-cursor 0.8s step-end infinite;
  color: var(--bucky-primary);
  font-weight: bold;
}

@keyframes bucky-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Error state */
.bucky-error .bucky-msg-content {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* ---------------------------------------------------------------------------
   Registration Form
   --------------------------------------------------------------------------- */
.bucky-register {
  padding: 16px;
  background: var(--bucky-bg);
  border-top: 1px solid var(--bucky-border);
  flex-shrink: 0;
}

.bucky-register-prompt {
  margin: 0 0 10px 0;
  font-size: 13px;
  color: var(--bucky-text-muted);
}

.bucky-reg-name,
.bucky-reg-email {
  display: block;
  width: 100%;
  border: 1px solid var(--bucky-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bucky-bg);
  color: var(--bucky-text);
  outline: none;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}

.bucky-reg-name:focus,
.bucky-reg-email:focus {
  border-color: var(--bucky-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.bucky-reg-submit,
.bucky-reg-skip {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  margin-right: 6px;
}

.bucky-reg-submit {
  background: var(--bucky-primary);
  color: white;
}

.bucky-reg-submit:hover {
  background: var(--bucky-primary-dark);
}

.bucky-reg-skip {
  background: var(--bucky-bg-alt);
  color: var(--bucky-text-muted);
}

.bucky-reg-skip:hover {
  background: var(--bucky-border);
}

/* ---------------------------------------------------------------------------
   Input Area
   --------------------------------------------------------------------------- */
.bucky-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--bucky-border);
  background: var(--bucky-bg);
  flex-shrink: 0;
}

.bucky-input {
  flex: 1;
  border: 1px solid var(--bucky-border);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  outline: none;
  background: var(--bucky-bg);
  color: var(--bucky-text);
  transition: border-color 0.15s;
  max-height: 120px;
}

.bucky-input:focus {
  border-color: var(--bucky-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.bucky-input::placeholder {
  color: var(--bucky-text-muted);
}

.bucky-input:disabled {
  opacity: 0.5;
}

.bucky-send {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bucky-primary);
  color: white;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.bucky-send:hover:not(:disabled) {
  background: var(--bucky-primary-dark);
  transform: scale(1.05);
}

.bucky-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loading animation on send button */
@keyframes bucky-spin {
  to { transform: rotate(360deg); }
}

.bucky-send.bucky-loading {
  position: relative;
}
.bucky-send.bucky-loading svg {
  visibility: hidden;
}
.bucky-send.bucky-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: bucky-spin 0.6s linear infinite;
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .bucky-root {
    --bucky-panel-w: calc(100vw - 32px);
    --bucky-panel-h: calc(100vh - 120px);
    --bucky-fab-size: 80px;
  }

  .bucky-root.bucky-bottom-right,
  .bucky-root.bucky-bottom-left {
    bottom: 16px;
    right: 16px;
    left: auto;
  }

  .bucky-root.bucky-top-right {
    top: 16px;
    right: 16px;
  }
}

/* ---------------------------------------------------------------------------
   Print: hide everything
   --------------------------------------------------------------------------- */
@media print {
  .bucky-root { display: none !important; }
}
