:root {
  --bg-primary: #0a1628;
  --bg-secondary: #0f1f3a;
  --bg-tertiary: #162a4a;
  --bg-input: #122240;
  --bg-hover: #1e3355;
  --bg-message-user: #1e3a5f;
  --bg-message-assistant: #122240;
  --bg-tool: #0f1f3a;
  --text-primary: #e4e4ef;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b80;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-dim: rgba(59, 130, 246, 0.15);
  --border: #1e3355;
  --error: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --scrollbar: #2a4060;
  --scrollbar-hover: #3a5070;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --font-size-base: 13px;
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  --bg-input: #f1f3f5;
  --bg-hover: #dee2e6;
  --bg-message-user: #1e3a5f;
  --bg-message-assistant: #f1f3f5;
  --bg-tool: #f8f9fa;
  --text-primary: #212529;
  --text-secondary: #495057;
  --text-muted: #868e96;
  --accent: #1d4ed8;
  --accent-hover: #2563eb;
  --accent-dim: rgba(29, 78, 216, 0.1);
  --border: #dee2e6;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --scrollbar: #ced4da;
  --scrollbar-hover: #adb5bd;
  --font-size-base: 13px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: var(--font-size-base);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

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

.logo {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
}

.title {
  font-size: 15px;
  font-weight: 700;
  background: linear-gradient(135deg, #3b82f6, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

[data-theme="light"] .title {
  -webkit-text-fill-color: #1d4ed8;
}

.header-right {
  display: flex;
  gap: 4px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

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

.model-bar {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
  overflow-x: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
}

.model-bar::-webkit-scrollbar {
  height: 3px;
}

.model-bar::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 2px;
}

.select-sm {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color 0.15s;
}

.select-sm:focus {
  border-color: var(--accent);
}

.select-sm option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  scroll-behavior: smooth;
  position: relative;
}

.ascii-logo {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 11px;
  line-height: 1.3;
  color: #3b82f6;
  opacity: 0.08;
  white-space: pre;
  text-align: center;
  pointer-events: none;
  z-index: 0;
  user-select: none;
}

.chat-container > * {
  position: relative;
  z-index: 1;
}

.message {
  margin-bottom: 12px;
  display: flex;
  gap: 8px;
  animation: fadeIn 0.2s ease;
}

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

.message.user {
  justify-content: flex-end;
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.user .message-avatar {
  background: var(--accent);
  color: white;
  order: 2;
}

.message.assistant .message-avatar {
  background: var(--bg-tertiary);
  color: var(--accent);
}

.message-body {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

.message.user .message-body {
  background: var(--bg-message-user);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-body {
  background: var(--bg-message-assistant);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-body p {
  margin-bottom: 6px;
}

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

.message-body pre {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.4;
}

.message-body code {
  background: var(--bg-tertiary);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
}

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

.message-body h1, .message-body h2, .message-body h3 {
  margin: 10px 0 6px;
  font-size: 14px;
}

.message-body a {
  color: var(--accent);
  text-decoration: none;
}

.message-body a:hover {
  text-decoration: underline;
}

.message-body li {
  margin-left: 16px;
  margin-bottom: 2px;
}

.tool-block {
  background: var(--bg-tool);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 4px 0;
  overflow: hidden;
}

.tool-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  transition: background 0.15s;
  user-select: none;
}

.tool-header:hover {
  background: var(--bg-hover);
}

.tool-header .tool-name {
  font-weight: 600;
  color: var(--accent);
  font-size: 11px;
}

.tool-content {
  padding: 8px 10px;
  font-size: 11px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  color: var(--text-secondary);
  max-height: 0;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-all;
  transition: max-height 0.2s ease, padding 0.2s ease;
  padding: 0 10px;
}

.tool-block.open .tool-content {
  max-height: 200px;
  overflow-y: auto;
  padding: 8px 10px;
}

.tool-block .tool-chevron {
  transition: transform 0.15s;
  font-size: 10px;
  color: var(--text-muted);
}

.tool-block.open .tool-chevron {
  transform: rotate(90deg);
}

.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

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

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

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

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

.input-area {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

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

.input-wrapper:focus-within {
  border-color: var(--accent);
}

#user-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
}

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

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

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

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

.hidden {
  display: none !important;
}

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.quick-bar {
  display: flex;
  gap: 4px;
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
  overflow-x: auto;
}

.quick-bar::-webkit-scrollbar {
  height: 3px;
}

.quick-bar::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 2px;
}

.quick-bar-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.quick-bar-btn:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

.chat-history-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  width: 260px;
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
}

.chat-history-sidebar.open {
  transform: translateX(0);
}

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

.sidebar-header-actions {
  display: flex;
  gap: 4px;
}

.sidebar-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 14px;
  padding: 8px 12px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.sidebar-new-chat:hover {
  background: var(--accent);
  color: white;
}

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

.sidebar-list-item {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}

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

.sidebar-list-item.active {
  background: var(--accent-dim);
  border-left: 2px solid var(--accent);
}

.sidebar-list-item-title {
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-list-item-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-list-item-delete {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.15s;
}

.sidebar-list-item:hover .sidebar-list-item-delete {
  opacity: 1;
}

.api-key-modal {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.api-key-modal.open {
  display: flex;
}

.api-key-modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 90%;
  max-width: 340px;
}

.api-key-modal-content h3 {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.api-key-modal-content .input {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  margin-bottom: 12px;
}

.api-key-modal-content .input:focus {
  border-color: var(--accent);
}

.api-key-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

#btn-pin-model.pinned {
  color: var(--accent);
}

#btn-add-api-key.no-key {
  color: var(--warning);
}

#btn-add-api-key.no-key:hover {
  background: rgba(245, 158, 11, 0.15);
}

.settings-modal {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}

.settings-modal.open {
  display: flex;
}

.settings-modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 80%;
  overflow-y: auto;
}

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

.settings-modal-header h3 {
  font-size: 15px;
  color: var(--text-primary);
}

.settings-modal-body {
  padding: 14px 16px;
}

.settings-modal-body .form-group {
  margin-bottom: 12px;
}

.settings-modal-body .form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.settings-modal-body .input {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  outline: none;
}

.settings-modal-body .input:focus {
  border-color: var(--accent);
}

.settings-modal-footer {
  padding-top: 10px;
  border-top: 1px solid var(--border);
  margin-top: 10px;
}
