/* CSS Variables */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --text-primary: #eaeaea;
  --text-secondary: #a0a0a0;
  --accent-primary: #e94560;
  --accent-secondary: #0f3460;
  --success: #4ade80;
  --warning: #fbbf24;
  --border: #2a2a4a;
  --shadow: rgba(0, 0, 0, 0.3);

  /* Citation colors */
  --citation-cph: #4ade80;
  --citation-finra: #60a5fa;
  --citation-ciro: #a78bfa;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
}

/* App Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 1rem;
}

.header-title h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.header-title .subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-group label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.control-group select {
  padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
}

.control-group select:focus {
  outline: none;
  border-color: var(--accent-primary);
}

/* Toggle Switch */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
}

.toggle-label input {
  display: none;
}

.toggle-switch {
  width: 40px;
  height: 22px;
  background: var(--bg-tertiary);
  border-radius: 11px;
  position: relative;
  transition: background 0.3s;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  background: var(--text-secondary);
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.3s, background 0.3s;
}

.toggle-label input:checked + .toggle-switch {
  background: var(--accent-primary);
}

.toggle-label input:checked + .toggle-switch::after {
  transform: translateX(18px);
  background: white;
}

/* Chat Container */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Messages */
.message {
  display: flex;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

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

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-content {
  padding: 1rem 1.25rem;
  border-radius: 12px;
  font-size: 0.9375rem;
}

.message.user .message-content {
  background: var(--accent-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-content p {
  margin-bottom: 0.5rem;
}

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

.message-content ul, .message-content ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.message-content li {
  margin-bottom: 0.25rem;
}

.message-content code {
  background: var(--bg-tertiary);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  font-family: 'Fira Code', monospace;
  font-size: 0.875em;
}

.message-content pre {
  background: var(--bg-tertiary);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.message-content pre code {
  background: none;
  padding: 0;
}

/* Citation Highlighting */
.citation {
  font-weight: 600;
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  font-size: 0.875em;
}

.citation-cph {
  background: rgba(74, 222, 128, 0.2);
  color: var(--citation-cph);
}

.citation-finra {
  background: rgba(96, 165, 250, 0.2);
  color: var(--citation-finra);
}

.citation-ciro {
  background: rgba(167, 139, 250, 0.2);
  color: var(--citation-ciro);
}

/* Disclaimer */
.disclaimer {
  font-size: 0.8125rem;
  color: var(--warning);
  font-style: italic;
  margin-top: 0.5rem;
}

/* Sources Panel */
.sources-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 1rem;
  overflow: hidden;
}

.sources-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--citation-cph);
}

.sources-content {
  padding: 1rem;
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.sources-content.collapsed {
  display: none;
}

.source-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.source-item:last-child {
  border-bottom: none;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 0.75rem;
  transition: transform 0.2s;
}

.btn-icon.collapsed {
  transform: rotate(-90deg);
}

/* Input Area */
.input-area {
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem;
}

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

#user-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.9375rem;
  resize: none;
  max-height: 150px;
  padding: 0.5rem;
  font-family: inherit;
  line-height: 1.5;
}

#user-input:focus {
  outline: none;
}

#user-input::placeholder {
  color: var(--text-secondary);
}

.btn-send {
  width: 40px;
  height: 40px;
  background: var(--accent-primary);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, opacity 0.2s;
}

.btn-send:hover:not(:disabled) {
  background: #d63d56;
}

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

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  font-size: 0.75rem;
}

.mode-indicator {
  color: var(--text-secondary);
  padding: 0.25rem 0.5rem;
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.mode-indicator.regulatory {
  color: var(--citation-cph);
  background: rgba(74, 222, 128, 0.1);
}

.disclaimer-small {
  color: var(--text-secondary);
  font-style: italic;
}

/* Streaming indicator */
.streaming::after {
  content: '▊';
  animation: blink 1s infinite;
}

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

/* Markdown headers in messages */
.message-content h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 1rem 0 0.5rem;
  color: var(--accent-primary);
}

.message-content h3:first-child {
  margin-top: 0;
}

/* Responsive */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .message {
    max-width: 95%;
  }
}

/* Loading state */
.loading {
  display: flex;
  gap: 0.25rem;
  padding: 1rem;
}

.loading-dot {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: loadingPulse 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes loadingPulse {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}
