/* ============================================
   Libnode Chat Widget — Terminal Console Style
   ============================================ */

/* --- Terminal container --- */
.chat-widget {
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  height: 100%;
  min-height: 420px;
  max-height: 520px;
  box-shadow: var(--shadow-md), 0 0 0 1px var(--accent-glow);
  font-family: var(--font-mono);
}

/* --- Terminal title bar --- */
.chat-titlebar {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  user-select: none;
}
.chat-titlebar-dots {
  display: flex;
  gap: 6px;
}
.chat-titlebar-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.chat-titlebar-dots span:nth-child(1) {
  background: var(--window-dot-red);
}
.chat-titlebar-dots span:nth-child(2) {
  background: var(--window-dot-yellow);
}
.chat-titlebar-dots span:nth-child(3) {
  background: var(--window-dot-green);
}
.chat-titlebar-label {
  flex: 1;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}
.chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--transition-fast);
}
.chat-status-dot.online {
  background: #28c840;
  box-shadow: 0 0 4px rgba(40, 200, 64, 0.5);
}

/* --- Messages area --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  scroll-behavior: smooth;
}

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

/* --- Terminal lines --- */
.chat-line {
  font-size: 0.8125rem;
  line-height: 1.65;
  color: var(--text-primary);
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: chat-fade-in 0.15s ease;
}
.chat-line.user {
  color: var(--accent);
}
.chat-line.user::before {
  content: '> ';
  color: var(--accent);
}
.chat-line.bot {
  color: var(--text-primary);
}
.chat-line.system {
  color: var(--text-muted);
  font-style: italic;
}
.chat-line.system::before {
  content: '$ ';
  color: var(--text-muted);
}

@keyframes chat-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* --- Streaming cursor --- */
.chat-cursor {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--accent);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: chat-cursor-blink 0.8s step-end infinite;
}
@keyframes chat-cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* --- Suggestion chips — terminal command style --- */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem 0.5rem;
  padding: 0 1rem 0.625rem;
}
.chat-chip {
  background: transparent;
  border: none;
  color: var(--accent-hover);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.125rem 0;
  transition: color var(--transition-fast), text-decoration-color var(--transition-fast);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 2px;
}
.chat-chip:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}
.chat-chip:active {
  opacity: 0.7;
}
.chat-chip:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

/* --- Input area --- */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.625rem 1rem 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.chat-prompt {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  padding: 0.25rem 0;
  outline: none;
}
.chat-input::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

/* --- Offline state --- */
.chat-offline {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem 1.5rem;
  text-align: center;
}
.chat-offline.visible {
  display: flex;
}
.chat-offline p {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0;
}
.chat-offline a {
  color: var(--accent);
  text-decoration: none;
}
.chat-offline a:hover {
  text-decoration: underline;
}

/* --- Error state --- */
.chat-line.error {
  color: #f87171;
}

/* --- Hidden state when offline --- */
.chat-widget.offline .chat-messages,
.chat-widget.offline .chat-chips,
.chat-widget.offline .chat-input-area {
  display: none;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .chat-widget {
    min-height: 360px;
    max-height: 440px;
  }
  .chat-line {
    font-size: 0.75rem;
  }
  .chat-chips {
    padding: 0 0.75rem 0.5rem;
  }
  .chat-input-area {
    padding: 0.5rem 0.75rem;
  }
}
