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

:root {
  --bg: #1a1b26;
  --surface: #24283b;
  --surface-light: #2f3451;
  --text: #c0caf5;
  --text-dim: #565f89;
  --accent: #7aa2f7;
  --accent-dim: #3d59a1;
  --user-bg: #292e42;
  --assistant-bg: #1f2335;
  --error: #f7768e;
  --success: #9ece6a;
  --system: #bb9af7;
  --border: #3b4261;
  --font: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
}

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

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 2px;
}

.status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
}

.status.connected {
  background: var(--success);
  color: var(--bg);
}

.status.disconnected {
  background: var(--error);
  color: var(--bg);
}

.status.connecting {
  background: var(--text-dim);
  color: var(--bg);
}

/* Conversation picker */
.conv-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.conv-picker.hidden {
  display: none;
}

.conv-picker-btn {
  background: var(--accent-dim);
  color: var(--text);
  border: none;
  border-radius: 4px;
  padding: 4px 12px;
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.conv-picker-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

.conv-picker-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  margin-left: auto;
}

.conv-picker-close:hover {
  color: var(--text);
}

.conv-list {
  max-height: 200px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.conv-list.hidden {
  display: none;
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}

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

.conv-item:hover {
  background: var(--surface-light);
}

.conv-item-left {
  flex: 1;
  min-width: 0;
}

.conv-item-label {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Messages area */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  padding: 10px 14px;
  border-radius: 8px;
  max-width: 85%;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.user {
  background: var(--user-bg);
  align-self: flex-end;
  border: 1px solid var(--border);
}

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

.message.system {
  background: transparent;
  color: var(--system);
  align-self: center;
  font-size: 12px;
  padding: 4px 8px;
}

.message.error {
  background: transparent;
  color: var(--error);
  align-self: center;
  font-size: 12px;
  padding: 4px 8px;
}

.message-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  text-align: right;
}

/* Streaming cursor */
.message.assistant.streaming::after {
  content: '\2588';
  animation: blink 0.7s step-end infinite;
  color: var(--accent);
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Command palette */
.command-palette {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
}

.command-palette.hidden {
  display: none;
}

.cmd-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s;
}

.cmd-item:first-child {
  border-radius: 8px 8px 0 0;
}

.cmd-item:last-child {
  border-radius: 0 0 8px 8px;
}

.cmd-item.selected {
  background: var(--surface-light);
}

.cmd-item:hover {
  background: var(--surface-light);
}

.cmd-name {
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
  white-space: nowrap;
  min-width: 140px;
}

.cmd-desc {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Input area */
#input-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

#input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
}

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

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

#send-btn {
  background: var(--accent-dim);
  color: var(--text);
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

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

#send-btn:disabled {
  background: var(--surface-light);
  color: var(--text-dim);
  cursor: not-allowed;
}

/* Confirmation overlay */
.confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.confirm-overlay.hidden {
  display: none;
}

.confirm-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 90%;
}

.confirm-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
}

.confirm-body {
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 20px;
}

.confirm-desc {
  color: var(--text-dim);
  font-size: 13px;
}

.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.confirm-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 6px;
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.confirm-btn.allow {
  background: var(--success);
  color: var(--bg);
}

.confirm-btn.allow:hover {
  filter: brightness(1.1);
}

.confirm-btn.deny {
  background: var(--error);
  color: var(--bg);
}

.confirm-btn.deny:hover {
  filter: brightness(1.1);
}

/* Attachment UI */
.attach-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

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

.attachment-preview {
  display: none;
  gap: 8px;
  padding: 8px 16px 0;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.attachment-preview.has-items {
  display: flex;
}

.attachment-thumb {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-thumb .file-icon {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
  word-break: break-all;
  padding: 4px;
}

.attachment-thumb .remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--error);
  color: var(--bg);
  border: none;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.message-attachments img {
  max-width: 300px;
  max-height: 200px;
  border-radius: 4px;
  cursor: pointer;
}

.message-attachments img:hover {
  opacity: 0.9;
}

.message-attachments .file-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--surface-light);
  border-radius: 4px;
  color: var(--accent);
  font-size: 12px;
  text-decoration: none;
}

.message-attachments .file-link:hover {
  text-decoration: underline;
}

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

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

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