/* ==========================================================================
   ChatRAG Academy — Dark Theme Design System
   ========================================================================== */

:root {
  /* Backgrounds */
  --bg-primary: #0f0f13;
  --bg-secondary: #1a1a24;
  --bg-tertiary: #252533;
  --bg-accent: #2d2d44;

  /* Text */
  --text-primary: #e8e8ed;
  --text-secondary: #9999aa;
  --text-muted: #666677;

  /* Accents */
  --accent-primary: #6c5ce7;
  --accent-hover: #7f70f0;
  --accent-success: #00b894;
  --accent-error: #e74c3c;
  --accent-warning: #fdcb6e;

  /* Borders & Shadows */
  --border-color: #2a2a3a;
  --shadow-color: rgba(0, 0, 0, 0.4);

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 20px;

  /* Sizes */
  --header-height: 56px;
  --sidebar-width: 260px;
  --input-bar-height: 72px;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ==========================================================================
   Header
   ========================================================================== */

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.header-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-right {
  display: flex;
  align-items: center;
}

.health-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-xl);
  background: var(--bg-tertiary);
  font-size: 12px;
  color: var(--text-secondary);
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.health-dot.connected {
  background: var(--accent-success);
  box-shadow: 0 0 6px var(--accent-success);
}

.health-dot.error {
  background: var(--accent-error);
  box-shadow: 0 0 6px var(--accent-error);
}

/* ==========================================================================
   App Layout
   ========================================================================== */

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: calc(100vh - var(--header-height));
  margin-top: var(--header-height);
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  overflow-y: auto;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.category-select {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 13px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239999aa' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.category-select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.25);
}

.doc-count {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.suggested-chips {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.chip {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chip:hover {
  background: var(--bg-accent);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

/* Sidebar Backdrop (mobile) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 49;
  background: rgba(0, 0, 0, 0.6);
}

.sidebar-backdrop.visible {
  display: block;
}

/* ==========================================================================
   Chat Container
   ========================================================================== */

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==========================================================================
   Message Bubbles
   ========================================================================== */

.message {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* User message */
.message.user {
  align-self: flex-end;
}

.message.user .message-bubble {
  background: var(--accent-primary);
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) var(--space-xs) var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
}

/* Bot message */
.message.bot {
  align-self: flex-start;
}

.message.bot .message-bubble {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--space-xs);
  padding: var(--space-lg);
}

.message-bubble p {
  margin-bottom: var(--space-sm);
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble strong {
  color: #fff;
  font-weight: 600;
}

.message.bot .message-bubble strong {
  color: var(--text-primary);
}

.message-bubble ul, .message-bubble ol {
  margin: var(--space-sm) 0;
  padding-left: var(--space-xl);
}

.message-bubble li {
  margin-bottom: var(--space-xs);
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: var(--space-xs);
  padding: 0 var(--space-xs);
}

.message.user .message-time {
  text-align: right;
}

/* Error message */
.message.error .message-bubble {
  background: rgba(231, 76, 60, 0.12);
  border: 1px solid rgba(231, 76, 60, 0.3);
  color: #f0a0a0;
  border-radius: var(--radius-lg);
}

/* ==========================================================================
   Sources
   ========================================================================== */

.sources-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  margin-top: var(--space-md);
  padding: var(--space-xs) var(--space-sm);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sources-toggle:hover {
  background: var(--bg-accent);
  color: var(--text-primary);
}

.sources-toggle .toggle-icon {
  display: inline-block;
  transition: transform 0.2s;
  font-size: 10px;
}

.sources-toggle.expanded .toggle-icon {
  transform: rotate(90deg);
}

.sources-list {
  display: none;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.sources-list.visible {
  display: flex;
}

.source-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  transition: border-color 0.15s;
}

.source-card:hover {
  border-color: var(--accent-primary);
}

.source-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-primary);
  margin-bottom: var(--space-xs);
  display: block;
}

.source-title:hover {
  color: var(--accent-hover);
}

.source-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  font-size: 11px;
  color: var(--text-muted);
}

.source-category-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-xl);
  background: var(--bg-accent);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 500;
}

.source-text {
  margin-top: var(--space-sm);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--space-xs);
  align-self: flex-start;
  animation: fadeIn 0.25s ease-out;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ==========================================================================
   Chat Input Bar
   ========================================================================== */

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  padding: var(--space-lg);
  border-top: 1px solid var(--border-color);
  background: var(--bg-primary);
}

.chat-input {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  padding: var(--space-md) var(--space-lg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
  transition: border-color 0.15s;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.2);
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--accent-primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:active {
  transform: scale(0.93);
}

.send-btn:disabled {
  background: var(--bg-accent);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ==========================================================================
   Responsive — Mobile (< 768px)
   ========================================================================== */

@media (max-width: 767px) {
  .sidebar-toggle {
    display: flex;
  }

  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    z-index: 50;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .message {
    max-width: 90%;
  }

  .chat-messages {
    padding: var(--space-lg);
  }
}

/* ==========================================================================
   Streaming Cursor Animation
   ========================================================================== */

.streaming-cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background-color: var(--accent-primary);
  margin-left: 2px;
  animation: blink 0.8s infinite;
  vertical-align: text-bottom;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.message-timing {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: var(--space-xs);
  font-style: italic;
  opacity: 0.8;
}
