:root {
  --bg-color: #121212;
  --chat-bg: #121212;
  --panel-bg: #18181b;
  --border-color: #27272a;
  --text-primary: #e4e4e7;
  --text-secondary: #a1a1aa;
  --accent-color: #3b82f6;
  /* Blue 500 */
  --accent-hover: #2563eb;
  /* Blue 600 */
  --user-bubble-bg: #27272a;
  --user-bubble-text: #fafafa;
  --assistant-bubble-bg: transparent;
  --assistant-bubble-text: #e4e4e7;
  --code-bg: #18181b;
  --chunk-bg: #18181b;
  --chunk-border: #27272a;
  --font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius-lg: 1rem;
  --radius-md: 0.75rem;
  --radius-sm: 0.5rem;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-family);
  height: 100vh;
  overflow: hidden;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
  position: relative;
}

/* Header */
.app-header {
  padding: 16px 24px;
  /* border-bottom: 1px solid var(--border-color); */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(18, 18, 18, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
}

.logo h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.hint {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
  opacity: 0.8;
}

.corpus-stats {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.75;
}

/* Chat Area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 100px 24px 120px;
  /* Top padding for header, bottom for input */
  display: flex;
  flex-direction: column;
  gap: 32px;
  scroll-behavior: smooth;
}

/* Scrollbar styling */
.chat-area::-webkit-scrollbar {
  width: 6px;
}

.chat-area::-webkit-scrollbar-track {
  background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 20px;
}

.welcome-message {
  text-align: center;
  margin-top: 15vh;
  color: var(--text-secondary);
  animation: fadeIn 0.5s ease-out;
}

.welcome-message h2 {
  font-weight: 500;
  font-size: 24px;
  letter-spacing: -0.02em;
  background: linear-gradient(to bottom right, #fff, #a1a1aa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Messages */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  animation: slideIn 0.3s ease-out;
}

.msg.user-msg {
  align-items: flex-end;
}

.msg.assistant-msg {
  align-items: flex-start;
}

.bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  position: relative;
  word-wrap: break-word;
}

.user-msg .bubble {
  background: var(--user-bubble-bg);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}

.assistant-msg .bubble {
  background: var(--assistant-bubble-bg);
  color: var(--assistant-bubble-text);
  padding: 0;
  /* Remove padding for assistant to align with left edge */
  max-width: 100%;
  width: 100%;
}

.assistant-text {
  line-height: 1.7;
}

.assistant-text p {
  margin: 0 0 1em 0;
}

.assistant-text p:last-child {
  margin-bottom: 0;
}

/* Code blocks */
pre {
  background: var(--code-bg);
  padding: 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  border: 1px solid var(--border-color);
  margin: 16px 0;
}

code {
  font-family: "Menlo", "Monaco", "Courier New", monospace;
  font-size: 13px;
}

p code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
}

/* Composer */
.composer-area {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px;
  background: linear-gradient(to top, var(--bg-color) 80%, transparent);
  display: flex;
  justify-content: center;
}

.composer-wrapper {
  width: 100%;
  max-width: 800px;
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 28px;
  padding: 8px 8px 8px 20px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer-wrapper:focus-within {
  border-color: var(--text-secondary);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.05);
}

textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  resize: none;
  padding: 12px 0;
  max-height: 200px;
  outline: none;
}

textarea::placeholder {
  color: var(--text-secondary);
}

button#send {
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}

button#send:hover {
  background: var(--accent-hover);
}

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

button#send:disabled {
  background: var(--border-color);
  color: var(--text-secondary);
  cursor: not-allowed;
}

/* Chunks / Sources */
details.chunks {
  margin-top: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

details.chunks>summary {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.02);
  list-style: none;
}

details.chunks>summary:hover {
  background: rgba(255, 255, 255, 0.04);
}

details.chunks>summary::-webkit-details-marker {
  display: none;
}

details.chunks>summary::before {
  content: "›";
  display: inline-block;
  transition: transform 0.2s;
  font-size: 14px;
  line-height: 1;
}

details.chunks[open]>summary::before {
  transform: rotate(90deg);
}

.chunk-list {
  padding: 0;
  border-top: 1px solid var(--border-color);
}

.chunk-item {
  border-bottom: 1px solid var(--border-color);
}

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

.chunk-item summary {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chunk-item summary:hover {
  background: rgba(255, 255, 255, 0.02);
}

.chunk-item .score {
  font-size: 11px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
}

.chunk-content {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.2);
  line-height: 1.5;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Loading indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 8px;
  align-items: center;
}

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

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

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

@keyframes bounce {

  0%,
  80%,
  100% {
    transform: scale(0);
  }

  40% {
    transform: scale(1);
  }
}

/* Meta / Status */
.assistant-meta {
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-line {
  font-style: italic;
  opacity: 0.8;
  animation: fadeIn 0.3s ease-out;
}

.meta-details {
  margin-bottom: 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.meta-details summary {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.02);
  list-style: none;
  opacity: 1;
}

.meta-details summary:hover {
  background: rgba(255, 255, 255, 0.04);
}

.meta-details summary::before {
  content: "›";
  display: inline-block;
  transition: transform 0.2s;
  font-size: 14px;
  line-height: 1;
}

.meta-details[open] summary::before {
  transform: rotate(90deg);
}

.meta-details ul {
  margin: 0;
  padding: 12px;
  list-style: none;
  border-top: 1px solid var(--border-color);
}

.meta-details li {
  padding: 2px 0;
  color: var(--text-secondary);
  font-size: 12px;
}

/* Thinking Process */
.thinking-section {
  margin-bottom: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.thinking-header {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.02);
}

.thinking-header:hover {
  background: rgba(255, 255, 255, 0.04);
}

.thinking-content {
  padding: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: monospace;
  white-space: pre-wrap;
  border-top: 1px solid var(--border-color);
  max-height: 200px;
  overflow-y: auto;
}

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

/* Settings Button */
.settings-btn {
  position: absolute;
  right: 24px;
  top: 24px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background-color 0.2s;
}

.settings-btn:hover {
  color: var(--text-primary);
  background-color: var(--user-bubble-bg);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  background-color: var(--panel-bg);
  margin: 10% auto;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow-md);
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.close-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 14px;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent-color);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

.primary-btn {
  background-color: var(--accent-color);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.primary-btn:hover {
  background-color: var(--accent-hover);
}
