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

:root {
  --sidebar-w: 260px;
  --bg-sidebar: #f5f5f7;
  --bg-main: #ffffff;
  --bg-hover: #e8e8ed;
  --bg-active: #dcdce0;
  --bg-input: #f9f9fb;
  --border: #e0e0e4;
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-muted: #a1a1a6;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-light: #e8f0fe;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --radius: 8px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro", "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
}

html, body { height: 100%; font-family: var(--font); color: var(--text-primary); background: var(--bg-main); -webkit-font-smoothing: antialiased; }

/* Layout */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  user-select: none;
}

.sidebar-header {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

.btn-new-chat {
  width: 100%;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-new-chat:hover { background: var(--accent-hover); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px;
}

.conv-item {
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-primary);
  transition: background 0.1s;
  position: relative;
}

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

.conv-item.active {
  background: var(--bg-active);
  font-weight: 500;
}

.conv-item .conv-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.conv-item .conv-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  border-radius: 4px;
}

.conv-item:hover .conv-delete { display: flex; }

.conv-item .conv-delete:hover { color: #ff3b30; background: rgba(255,59,48,0.1); }

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.btn-ghost {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  width: 100%;
  transition: background 0.1s, color 0.1s;
}

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

/* Main Area */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-main);
}

.chat-area {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

/* Welcome Screen */
.welcome-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px;
}

.welcome-content {
  text-align: center;
  max-width: 520px;
}

.welcome-content h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 10px;
  color: var(--text-primary);
}

.welcome-desc {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 32px;
}

.prompt-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 24px;
}

.suggestion-chip {
  padding: 8px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
}

.suggestion-chip:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.hint-text {
  font-size: 13px;
  color: var(--text-muted);
}

/* Message List */
.message-list {
  display: none;
  padding: 24px 0;
}

.message {
  padding: 16px 24px;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
}

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

.message.assistant {
  background: var(--bg-main);
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.message.user .message-header { color: var(--accent); }

.message-content {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-wrap: break-word;
}

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

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

.message-content strong { font-weight: 600; }

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

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

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

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-main);
}

.input-wrapper {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.prompt-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 200px;
  min-height: 24px;
}

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

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

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

.btn-send:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.input-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 6px;
  padding: 0 4px;
}

.model-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* Settings Panel */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

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

.settings-panel {
  width: 460px;
  max-height: 80vh;
  background: var(--bg-main);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.settings-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.btn-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

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

.settings-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.form-group textarea {
  resize: vertical;
  line-height: 1.5;
}

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

.btn-primary {
  padding: 8px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

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

/* Connection status */
.connection-status {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: #ff3b30;
  color: #fff;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(255,59,48,0.3);
}

.connection-status.hidden { display: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Code block styling */
.message-content pre {
  background: #f5f5f7;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 12px 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

.message-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: #f5f5f7;
  padding: 2px 6px;
  border-radius: 4px;
}

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