/* ═══════════════════════════════════════════════════════════════
   LYDIAN CHAT — Persistent AI Guide Panel
   Uses design-system.css Tier 1/2 tokens
   z-index: 9990 (below toasts=10000, above content)
   ═══════════════════════════════════════════════════════════════ */

/* ── Root Container ─────────────────────────────────────────── */
.lc-root {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 9990;
  font-family: var(--font-sans);
  pointer-events: none;
}
.lc-root * { box-sizing: border-box; }

/* ── FAB (Floating Action Button) ───────────────────────────── */
.lc-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: var(--r-full);
  border: none;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--ld-400) 0%, var(--ld-600) 100%);
  color: var(--white);
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 4px 20px rgba(212, 101, 74, 0.4);
  transition: transform var(--dur-normal) var(--ease-out),
              box-shadow var(--dur-normal) var(--ease-out);
}
.lc-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(212, 101, 74, 0.55);
}
.lc-fab:active { transform: scale(0.95); }
.lc-fab.lc-hidden { display: none; }

/* FAB pulse animation — first 10s to attract attention */
@keyframes lc-fab-heartbeat {
  0%, 100% { transform: scale(1); box-shadow: 0 4px 20px rgba(212, 101, 74, 0.4); }
  14% { transform: scale(1.12); box-shadow: 0 4px 28px rgba(212, 101, 74, 0.6), 0 0 0 6px rgba(212, 101, 74, 0.12); }
  28% { transform: scale(1); box-shadow: 0 4px 20px rgba(212, 101, 74, 0.4); }
  42% { transform: scale(1.08); box-shadow: 0 4px 24px rgba(212, 101, 74, 0.55), 0 0 0 4px rgba(212, 101, 74, 0.1); }
}
.lc-fab { animation: lc-fab-heartbeat 2.4s ease-in-out infinite; }
.lc-fab.lc-pulse { animation: lc-fab-heartbeat 1.8s ease-in-out infinite; }

/* ── Chat Panel ─────────────────────────────────────────────── */
.lc-panel {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 400px;
  height: 600px;
  max-height: calc(100vh - 32px);
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-16);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);

  /* Closed state */
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  visibility: hidden;
  transition: transform 280ms var(--ease-out),
              opacity 280ms var(--ease-out),
              visibility 280ms;
}
.lc-panel.lc-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
}

/* ── Header ─────────────────────────────────────────────────── */
.lc-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
  gap: 10px;
}
.lc-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--ld-400) 0%, var(--ld-600) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-weight: 700;
  font-size: var(--size-15);
  flex-shrink: 0;
}
.lc-title {
  font-weight: 600;
  font-size: var(--size-15);
  color: var(--text-primary);
  flex: 1;
}
.lc-status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--emerald-400);
  margin-right: 4px;
  flex-shrink: 0;
}
.lc-status-dot.offline { background: var(--gray-500); }
.lc-actions {
  display: flex;
  gap: 4px;
}
.lc-actions button {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--r-6);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.lc-actions button:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

/* ── Messages Area ──────────────────────────────────────────── */
.lc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}
.lc-messages::-webkit-scrollbar { width: 5px; }
.lc-messages::-webkit-scrollbar-track { background: transparent; }
.lc-messages::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--r-full);
}

/* ── Message Bubbles ────────────────────────────────────────── */
.lc-msg {
  display: flex;
  gap: 8px;
  max-width: 92%;
  animation: lc-msg-in 200ms var(--ease-out);
}
@keyframes lc-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.lc-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.lc-msg.assistant { align-self: flex-start; }

.lc-msg-bubble {
  padding: 10px 14px;
  border-radius: var(--r-12);
  font-size: var(--size-13);
  line-height: 1.55;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap;
}
.lc-msg.assistant .lc-msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
}
.lc-msg.user .lc-msg-bubble {
  background: rgba(212, 101, 74, 0.12);
  border: 1px solid rgba(212, 101, 74, 0.25);
}

/* Inline markdown */
.lc-msg-bubble strong { font-weight: 600; color: var(--text-bright); }
.lc-msg-bubble code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}
.lc-msg-bubble a {
  color: var(--ld-200);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.lc-msg-bubble a:hover { color: var(--ld-300); }
.lc-msg-bubble ul, .lc-msg-bubble ol {
  margin: 4px 0;
  padding-left: 18px;
}
.lc-msg-bubble li { margin: 2px 0; }

/* Small avatar circle for assistant msgs */
.lc-msg-av {
  width: 24px;
  height: 24px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--ld-400), var(--ld-600));
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

/* ── Tool Cards ─────────────────────────────────────────────── */
.lc-tool-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 4px 0;
  border-radius: var(--r-6);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  font-size: var(--size-11);
  color: var(--text-secondary);
  animation: lc-msg-in 200ms var(--ease-out);
}
.lc-tool-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.lc-tool-card.running .lc-tool-icon { animation: lc-spin 1s linear infinite; }
@keyframes lc-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.lc-tool-name { font-weight: 600; color: var(--text-primary); }
.lc-tool-card.success { border-color: rgba(34, 197, 94, 0.2); }
.lc-tool-card.error { border-color: rgba(233, 116, 81, 0.2); }
.lc-tool-status {
  margin-left: auto;
  font-weight: 500;
}
.lc-tool-card.running .lc-tool-status { color: var(--yellow-400); }
.lc-tool-card.success .lc-tool-status { color: var(--emerald-400); }
.lc-tool-card.error .lc-tool-status { color: var(--red-400); }

/* ── Typing Indicator ───────────────────────────────────────── */
.lc-typing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  font-size: var(--size-11);
  color: var(--text-muted);
}
.lc-typing-dots {
  display: flex;
  gap: 3px;
}
.lc-typing-dot {
  width: 5px;
  height: 5px;
  border-radius: var(--r-full);
  background: var(--text-muted);
  animation: lc-bounce 1.2s ease-in-out infinite;
}
.lc-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.lc-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes lc-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

/* ── Suggestion Chips ───────────────────────────────────────── */
.lc-chips {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  flex-shrink: 0;
  border-top: 1px solid var(--glass-border);
  scrollbar-width: none;
}
.lc-chips::-webkit-scrollbar { display: none; }

.lc-chip {
  padding: 5px 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--size-11);
  font-family: var(--font-sans);
  white-space: nowrap;
  cursor: pointer;
  transition: border-color var(--dur-fast), color var(--dur-fast), background var(--dur-fast);
}
.lc-chip:hover {
  border-color: rgba(212, 101, 74, 0.4);
  color: var(--ld-200);
  background: rgba(212, 101, 74, 0.06);
}

/* ── Input Area ─────────────────────────────────────────────── */
.lc-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--glass-border);
  background: var(--bg-tertiary);
  flex-shrink: 0;
}
.lc-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-12);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--size-13);
  padding: 10px 14px;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  outline: none;
  transition: border-color var(--dur-fast);
}
.lc-input::placeholder { color: var(--text-tertiary); }
.lc-input:focus { border-color: rgba(212, 101, 74, 0.4); }

.lc-send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  border: none;
  background: linear-gradient(135deg, var(--ld-400), var(--ld-600));
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: opacity var(--dur-fast), transform var(--dur-fast);
}
.lc-send-btn:hover { opacity: 0.85; }
.lc-send-btn:active { transform: scale(0.92); }
.lc-send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Welcome Overlay (typewriter intro) ─────────────────────── */
.lc-welcome {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lc-welcome-text {
  font-size: var(--size-13);
  line-height: 1.6;
  color: var(--text-primary);
  min-height: 20px;
}
.lc-welcome-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--ld-400);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: lc-blink 0.8s step-end infinite;
}
@keyframes lc-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.lc-welcome-card {
  padding: 12px 16px;
  border-radius: var(--r-12);
  border: 1px solid rgba(212, 101, 74, 0.2);
  background: rgba(212, 101, 74, 0.04);
  cursor: pointer;
  transition: border-color var(--dur-fast), background var(--dur-fast), transform var(--dur-fast);
  opacity: 0;
  transform: translateY(8px);
}
.lc-welcome-card.lc-visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 300ms var(--ease-out), transform 300ms var(--ease-out),
              border-color var(--dur-fast), background var(--dur-fast);
}
.lc-welcome-card:hover {
  border-color: rgba(212, 101, 74, 0.45);
  background: rgba(212, 101, 74, 0.08);
}
.lc-welcome-card-title {
  font-weight: 600;
  font-size: var(--size-13);
  color: var(--ld-200);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.lc-welcome-card-desc {
  font-size: var(--size-11);
  color: var(--text-secondary);
  line-height: 1.4;
}

.lc-welcome-skip {
  align-self: flex-end;
  padding: 4px 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--size-11);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: color var(--dur-fast), border-color var(--dur-fast);
}
.lc-welcome-skip:hover {
  color: var(--text-secondary);
  border-color: var(--text-muted);
}

/* ── Keyboard shortcut hint ─────────────────────────────────── */
.lc-kbd-hint {
  position: fixed;
  bottom: 78px;
  right: 24px;
  font-size: 10px;
  color: var(--text-tertiary);
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.5s;
}
.lc-kbd-hint.lc-show { opacity: 1; }

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .lc-panel {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
    border: none;
  }
  .lc-fab {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
  .lc-kbd-hint { display: none; }
}

/* ── Reduced motion ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .lc-panel { transition-duration: 0ms; }
  .lc-msg { animation: none; }
  .lc-fab.lc-pulse { animation: none; }
  .lc-typing-dot { animation: none; }
  .lc-welcome-cursor { animation: none; }
  .lc-tool-card.running .lc-tool-icon { animation: none; }
}
