/* ========================================================================
   MHW Research Assistant — Premium Dark UI
   ======================================================================== */

/* --- Design Tokens --- */
:root {
  /* Core palette */
  --bg-deep: #09090b;
  --bg-surface: #111113;
  --bg-elevated: #18181b;
  --bg-hover: #1f1f23;

  /* Gold accent spectrum */
  --accent: #d4a853;
  --accent-dim: rgba(212, 168, 83, 0.12);
  --accent-glow: rgba(212, 168, 83, 0.25);
  --accent-hover: #e0b96a;

  /* Text */
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;

  /* Borders */
  --border: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(212, 168, 83, 0.25);

  /* Effects */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(212, 168, 83, 0.1);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Spacing */
  --sidebar-width: 280px;

  /* Transition */
  --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: 150ms var(--ease-spring);
  --transition-normal: 250ms var(--ease-spring);
  --transition-slow: 400ms var(--ease-spring);
}

/* --- Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* --- App Container --- */
.app-container {
  width: 100%;
  height: 100vh;
  display: flex;
  position: relative;
}

/* ========================================================================
   SIDEBAR
   ======================================================================== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-normal);
  z-index: 20;
}

.sidebar-header {
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  padding: 0 4px;
  letter-spacing: 0.5px;
}

.brand-icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.brand-accent {
  color: var(--accent);
}

#new-chat-btn {
  width: 100%;
  height: 42px;
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

#new-chat-btn svg {
  width: 16px;
  height: 16px;
}

#new-chat-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.sidebar-label {
  padding: 8px 20px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
}

/* Session list */
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.05) transparent;
}

.session-list::-webkit-scrollbar {
  width: 4px;
}
.session-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
}

.session-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  position: relative;
}

.session-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.session-item:hover .delete-btn {
  opacity: 1;
}

.session-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.session-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delete-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  line-height: 1;
}

.delete-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.sidebar-footer-text {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 30;
  width: 40px;
  height: 40px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

/* ========================================================================
   CHAT AREA
   ======================================================================== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-deep);
}

/* Header */
header {
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-surface);
  flex-shrink: 0;
}

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

.logo {
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.gold-text {
  color: var(--accent);
}

.header-badge {
  padding: 3px 10px;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.pulse {
  width: 7px;
  height: 7px;
  background: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
  animation: pulse 2.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.6; }
}

/* ========================================================================
   CHAT WINDOW
   ======================================================================== */
main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.06) transparent;
}

main::-webkit-scrollbar {
  width: 5px;
}
main::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
}

/* --- Welcome Screen --- */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px 20px;
  animation: fadeIn 0.6s var(--ease-spring);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome-icon {
  width: 64px;
  height: 64px;
  background: var(--accent-dim);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  color: var(--accent);
  border: 1px solid var(--border-accent);
}

.welcome-icon svg {
  width: 32px;
  height: 32px;
}

.welcome-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.75rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.welcome-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  max-width: 420px;
  line-height: 1.5;
  margin-bottom: 32px;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 600px;
}

.quick-prompt {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 8px;
}

.quick-prompt svg {
  color: var(--accent);
  flex-shrink: 0;
}

.quick-prompt:hover {
  background: var(--accent-dim);
  border-color: var(--border-accent);
  color: var(--accent);
  transform: translateY(-1px);
}

/* --- Message Styles --- */
.message {
  max-width: 75%;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.7;
  font-size: 0.95rem;
  position: relative;
  animation: messageIn 0.35s var(--ease-spring);
  word-break: break-word;
}

@keyframes messageIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Bot message */
.bot-message {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}

.bot-message strong, .bot-message b {
  color: var(--accent);
  font-weight: 600;
}

.bot-message h2,
.bot-message h3,
.bot-message h4 {
  color: var(--accent);
  margin: 1.25rem 0 0.75rem 0;
  font-family: 'Outfit', sans-serif;
  line-height: 1.3;
}

.bot-message ul,
.bot-message ol {
  padding-left: 24px;
  margin: 10px 0;
  color: var(--text-primary);
}

.bot-message li {
  margin-bottom: 6px;
}

.bot-message h2 { font-size: 1.3rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.bot-message h3 { font-size: 1.15rem; }
.bot-message h4 { font-size: 1rem; }

.bot-message p {
  margin-bottom: 1rem;
}

.bot-message p:last-child {
  margin-bottom: 0;
}

.bot-message code {
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
  color: var(--accent-hover);
}

.bot-message pre {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82em;
  line-height: 1.5;
}

.bot-message pre code {
  background: none;
  padding: 0;
  color: var(--text-primary);
}

.bot-message a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(212, 168, 83, 0.3);
  transition: border-color var(--transition-fast);
}

.bot-message a:hover {
  border-bottom-color: var(--accent);
}

.bot-message blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 14px;
  margin: 10px 0;
  background: var(--accent-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.bot-message hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

/* User message */
.user-message {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(212, 168, 83, 0.15), rgba(212, 168, 83, 0.08));
  border: 1px solid var(--border-accent);
  border-bottom-right-radius: 4px;
  color: var(--text-primary);
}

/* Error message */
.bot-message.error {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.08);
}

/* --- Bot avatar --- */
.message-group {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: messageIn 0.35s var(--ease-spring);
}

.message-group .message {
  animation: none;
}

.bot-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 0.7rem;
  margin-top: 2px;
  flex-shrink: 0;
}

/* --- Sources --- */
.sources {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.sources-label {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
  display: block;
}

.source-item {
  color: var(--text-secondary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  font-size: 0.82rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.source-item::before {
  content: '→';
  color: var(--accent);
  font-size: 0.75rem;
}

.source-item:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
}

/* ========================================================================
   PROGRESS INDICATOR
   ======================================================================== */
.progress-container {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: messageIn 0.35s var(--ease-spring);
}

.progress-indicator {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
  padding: 16px 20px;
  min-width: 260px;
  max-width: 400px;
}

/* Stages timeline */
.progress-stages {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.progress-stage {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  position: relative;
  animation: stageIn 0.3s var(--ease-spring);
}

@keyframes stageIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Timeline connector line */
.progress-stage:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 28px;
  width: 1px;
  height: calc(100% - 14px);
  background: var(--border);
}

.progress-stage.completed::after {
  background: var(--accent);
  opacity: 0.4;
}

/* Stage icon */
.stage-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
  position: relative;
  z-index: 1;
}

.progress-stage.active .stage-icon {
  animation: iconPulse 1.5s ease-in-out infinite;
}

@keyframes iconPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.progress-stage.completed .stage-icon {
  color: var(--text-muted);
  animation: none;
}

/* Stage text */
.stage-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.progress-stage.active .stage-text {
  color: var(--accent);
  font-weight: 500;
}

.progress-stage.completed .stage-text {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: rgba(255,255,255,0.15);
}

/* Animated dots at the bottom */
.progress-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  padding-top: 10px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

.progress-dots .dot {
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

.progress-dots .dot:nth-child(2) { animation-delay: 0.15s; }
.progress-dots .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Disabled state for input while processing */
#user-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

#send-btn:disabled:hover {
  transform: none;
  box-shadow: none;
}

/* ========================================================================
   STREAMING TEXT CURSOR & ANIMATION
   ======================================================================== */

/* Live streaming message bubble */
.message.bot-message.streaming {
  border-color: var(--border-accent);
  box-shadow: 0 0 16px rgba(212, 168, 83, 0.06);
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

/* Blinking cursor at end of streamed text */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 0.8s step-end infinite;
  border-radius: 1px;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Subtle glow on the streaming message group */
.message-group.streaming-active {
  position: relative;
}

.message-group.streaming-active::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(212, 168, 83, 0.04), transparent);
  pointer-events: none;
  z-index: -1;
  animation: glowPulse 2s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Smooth fade-in for streaming group appearance */
.message-group.streaming-active .bot-message {
  animation: streamIn 0.3s var(--ease-spring);
}

@keyframes streamIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================================================
   INPUT AREA
   ======================================================================== */
footer {
  padding: 16px 28px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-wrapper {
  display: flex;
  gap: 10px;
  background: var(--bg-elevated);
  padding: 6px 6px 6px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  transition: all var(--transition-fast);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}

input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 8px 0;
}

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

#send-btn {
  background: var(--accent);
  border: none;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #09090b;
  transition: all var(--transition-fast);
}

#send-btn svg {
  width: 18px;
  height: 18px;
}

#send-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
  box-shadow: 0 0 16px rgba(212, 168, 83, 0.3);
}

#send-btn:active {
  transform: scale(0.95);
}

.input-hint {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ========================================================================
   RESPONSIVE
   ======================================================================== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  header {
    padding-left: 64px;
  }

  main {
    padding: 20px 16px;
  }

  footer {
    padding: 12px 16px 16px;
  }

  .message {
    max-width: 90%;
  }

  .welcome-title {
    font-size: 1.35rem;
  }

  .quick-prompts {
    flex-direction: column;
  }

  .quick-prompt {
    width: 100%;
    text-align: left;
  }

  .header-badge {
    display: none;
  }
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 15;
}

.sidebar-overlay.active {
  display: block;
}
