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

:root {
  --bg: #0f0f0f;
  --surface: #161616;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text-muted: #666;
  --user-bg: #1a2433;
  --user-text: #a8c4e0;
  --ce-bg: #1a1a1a;
  --ce-text: #d4d4d4;
  --accent: #3a7bd5;
  --error-bg: #2a1515;
  --error-text: #c07070;
  --font-mono: "IBM Plex Mono", "Courier New", monospace;
  --font-sans: "IBM Plex Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 760px;
  margin: 0 auto;
}

/* Header */
header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.wordmark {
  font-family: var(--font-sans);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--text);
  font-weight: 500;
}

.header-copy {
  font-family: var(--font-sans);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  font-weight: 300;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  margin-left: 2px;
  position: relative;
  top: -1px;
}

.status-dot.offline {
  background: var(--error-text);
}

.clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  cursor: pointer;
  padding: 4px 8px;
  text-transform: uppercase;
  transition: color 0.15s;
}

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

/* Chat area */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
}

#chat::-webkit-scrollbar {
  width: 4px;
}

#chat::-webkit-scrollbar-track {
  background: transparent;
}

#chat::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Empty state */
.empty-state {
  margin: auto;
  text-align: center;
  user-select: none;
}

.empty-title {
  font-family: var(--font-sans);
  font-size: 32px;
  font-weight: 300;
  color: var(--text);
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.empty-subtitle {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 8px;
}

/* Message rows */
.msg-row {
  display: flex;
  margin-bottom: 6px;
  animation: fadeIn 0.18s ease;
}

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

.msg-row.user {
  justify-content: flex-end;
}

.msg-row.ce {
  justify-content: flex-start;
}

/* Sender label */
.msg-label {
  font-family: var(--font-sans);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.msg-row.user .msg-label {
  text-align: right;
}

.msg-wrapper {
  max-width: 78%;
  display: flex;
  flex-direction: column;
}

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

/* Bubble */
.bubble {
  padding: 10px 14px;
  border-radius: 3px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.user .bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border: 1px solid #243a54;
}

.msg-row.ce .bubble {
  background: var(--ce-bg);
  color: var(--ce-text);
  border: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 300;
}

/* Markdown rendered content */
.msg-row.ce .bubble p { margin: 0 0 0.75em; }
.msg-row.ce .bubble p:last-child { margin-bottom: 0; }
.msg-row.ce .bubble h1,
.msg-row.ce .bubble h2,
.msg-row.ce .bubble h3 {
  font-weight: 500;
  margin: 1em 0 0.4em;
  color: var(--text);
  font-size: 1em;
  letter-spacing: 0.02em;
}
.msg-row.ce .bubble h1:first-child,
.msg-row.ce .bubble h2:first-child,
.msg-row.ce .bubble h3:first-child { margin-top: 0; }
.msg-row.ce .bubble ul,
.msg-row.ce .bubble ol {
  padding-left: 1.4em;
  margin: 0 0 0.75em;
}
.msg-row.ce .bubble li { margin-bottom: 0; }
.msg-row.ce .bubble li p { margin: 0; }
.msg-row.ce .bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: #1f1f1f;
  border: 1px solid #2f2f2f;
  border-radius: 2px;
  padding: 0.1em 0.35em;
  color: #a8c4e0;
}
.msg-row.ce .bubble pre {
  background: #141414;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0.5em 0;
}
.msg-row.ce .bubble pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
  color: #c8c8c8;
}
.msg-row.ce .bubble strong { font-weight: 500; color: var(--text); }
.msg-row.ce .bubble em { font-style: italic; opacity: 0.85; }
.msg-row.ce .bubble a { color: var(--accent); text-decoration: none; }
.msg-row.ce .bubble a:hover { text-decoration: underline; }
.msg-row.ce .bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75em 0;
}
.msg-row.ce .bubble blockquote {
  border-left: 2px solid var(--border);
  padding-left: 12px;
  color: var(--text-muted);
  margin: 0.5em 0;
}

.msg-row.error .bubble {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid #3a2020;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Thinking indicator */
.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--ce-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.thinking-dots {
  display: flex;
  gap: 3px;
}

.thinking-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* Input area */
footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px 20px;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 12px;
  resize: none;
  outline: none;
  min-height: 42px;
  max-height: 160px;
  transition: border-color 0.15s;
}

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

#input:focus {
  border-color: #3a3a3a;
}

#input:disabled {
  opacity: 0.5;
}

#send {
  background: var(--accent);
  border: none;
  border-radius: 3px;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0 18px;
  height: 42px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s, background 0.15s;
  flex-shrink: 0;
}

#send:hover:not(:disabled) {
  background: #4a8be5;
}

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

.footer-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Responsive */
@media (max-width: 600px) {
  #chat { padding: 16px; }
  footer { padding: 12px 16px 16px; }
  header { padding: 16px; }
  .msg-wrapper { max-width: 90%; }
}
