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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #ff5a36;
  --accent-hover: #ff7a5a;
  --user-bg: #1a2233;
  --assistant-bg: #161b22;
  --code-bg: #0d1117;
  --source-bg: rgba(255, 90, 54, 0.08);
  --source-bg-hover: rgba(255, 90, 54, 0.18);
  --source-border: rgba(255, 90, 54, 0.25);
}

[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --accent: #d94720;
  --accent-hover: #b83814;
  --user-bg: #fff4f0;
  --assistant-bg: #f6f8fa;
  --code-bg: #f6f8fa;
  --source-bg: rgba(217, 71, 32, 0.08);
  --source-bg-hover: rgba(217, 71, 32, 0.16);
  --source-border: rgba(217, 71, 32, 0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}

#app {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 0 16px;
  position: relative;
}

header {
  padding: 24px 0 16px;
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.lobster-icon {
  width: 28px;
  height: 28px;
}

#theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

#theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#theme-toggle .icon-sun {
  display: none;
}

[data-theme="light"] #theme-toggle .icon-sun {
  display: block;
}

[data-theme="light"] #theme-toggle .icon-moon {
  display: none;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

#api-key-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

#api-key-section label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 8px;
}

.key-input-row {
  display: flex;
  gap: 8px;
}

#api-key {
  flex: 1;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

#api-key:focus {
  border-color: var(--accent);
}

#save-key-btn {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}

#save-key-btn:hover {
  background: var(--accent-hover);
}

.hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

#chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chat-container.centered {
  justify-content: center;
}

#chat-container.centered #messages {
  display: none;
}

#app.landing header,
#app.landing #api-key-section,
#app.landing #status-bar {
  display: none;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
}

.message {
  padding: 12px 16px;
  margin-bottom: 8px;
  border-radius: 8px;
  line-height: 1.6;
  font-size: 0.95rem;
}

.message.user {
  background: var(--user-bg);
  border-left: 3px solid var(--accent);
}

.message.assistant {
  background: var(--assistant-bg);
  border: 1px solid var(--border);
}

.message-content p {
  margin-bottom: 8px;
}

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

.message-content code {
  background: rgba(255, 90, 54, 0.1);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.85em;
}

.message-content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}

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

.cite {
  font-size: 0.7em;
  vertical-align: super;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  padding: 0 1px;
}

.cite:hover {
  text-decoration: underline;
}

.sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sources a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.75rem;
}

.sources a:hover {
  color: var(--accent);
}

.chat-img {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
}

.thinking {
  color: var(--text-muted);
  font-style: italic;
}

#attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0;
}

#attachments:empty {
  display: none;
}

.attachment-preview {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}

.attachment-preview img {
  display: block;
  max-height: 80px;
  max-width: 120px;
  object-fit: cover;
}

.attachment-preview .file-label {
  padding: 6px 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-preview .remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#input-area {
  display: flex;
  gap: 8px;
  padding: 16px 0;
  align-items: center;
}

#input-area.drag-over #user-input {
  border-color: var(--accent);
  background: var(--source-bg);
}

#attach-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#attach-btn:hover {
  color: var(--accent);
}

#user-input {
  flex: 1;
  padding: 16px 20px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1.1rem;
  font-family: inherit;
  resize: none;
  outline: none;
  height: 54px;
  overflow-y: auto;
}

#user-input:focus {
  border-color: var(--accent);
}

#send-btn {
  padding: 14px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

#status-bar {
  padding: 8px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* Scrollbar */
#messages::-webkit-scrollbar {
  width: 6px;
}

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

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

@media (max-width: 600px) {
  #app {
    padding: 0 12px;
  }
  header h1 {
    font-size: 1.25rem;
  }
}
