* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: #020617;
  color: #e5e7eb;
}

body {
  display: flex;
}

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

.app-header {
  height: 52px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  background: radial-gradient(circle at top left, #1e293b 0, #020617 55%);
}

.icon-button {
  border: none;
  background: transparent;
  color: #e5e7eb;
  font-size: 20px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.icon-button:hover {
  background: rgba(148, 163, 184, 0.25);
}

.primary-button {
  border: none;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.5);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.primary-button:hover {
  transform: translateY(-0.5px);
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.45);
}

.secondary-button {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}

.ghost-button {
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: #9ca3af;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}

.small-button {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: transparent;
  color: #e5e7eb;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
}

.header-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.header-title {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.header-subtitle {
  font-size: 11px;
  color: #9ca3af;
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-subtitle span#currentModelName {
  padding-left: 8px;
  border-left: 1px solid rgba(148, 163, 184, 0.45);
}

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.side-panel {
  width: 320px;
  max-width: 90vw;
  background: radial-gradient(circle at top left, #020617 0, #020617 45%, #020617 100%);
  border-right: 1px solid rgba(148, 163, 184, 0.25);
  display: flex;
  flex-direction: column;
  padding: 10px;
  transition: transform 0.18s ease-out;
}

.side-panel.hidden {
  transform: translateX(-100%);
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.side-panel-title {
  font-weight: 600;
  font-size: 14px;
}

.side-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.side-tab {
  flex: 1;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: #9ca3af;
  font-size: 12px;
  padding: 6px 6px;
  cursor: pointer;
}

.side-tab.active {
  background: rgba(30, 64, 175, 0.7);
  color: #e5e7eb;
}

.side-tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
}

.side-tab-panel.active {
  display: flex;
}

.side-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0;
  font-size: 13px;
  font-weight: 500;
}

.list-container {
  flex: 1;
  min-height: 120px;
  max-height: 50vh;
  overflow-y: auto;
  border-radius: 10px;
  border: 1px solid rgba(31, 41, 55, 0.9);
  background: radial-gradient(circle at top left, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.85));
  padding: 6px;
}

.list-item {
  padding: 6px 7px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-item:hover {
  background: rgba(31, 41, 55, 0.9);
}

.list-item.active {
  background: rgba(37, 99, 235, 0.25);
  border: 1px solid rgba(59, 130, 246, 0.7);
}

.list-item-title {
  font-weight: 500;
  color: #e5e7eb;
}

.list-item-sub {
  font-size: 11px;
  color: #9ca3af;
}

.list-item-actions {
  margin-top: 4px;
  display: flex;
  gap: 4px;
}

.list-item-actions button {
  font-size: 10px;
  padding: 2px 8px;
}

.empty-hint {
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-text {
  font-size: 12px;
  color: #6b7280;
  text-align: center;
  padding: 8px;
}

.editor-panel {
  margin-top: 10px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(31, 41, 55, 0.9);
  background: radial-gradient(circle at top left, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.92));
  overflow-y: auto;
  max-height: 55vh;
}

.editor-panel h3 {
  margin: 0 0 10px 0;
  font-size: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 13px;
}

.field span {
  font-size: 12px;
  color: #9ca3af;
}

.field input,
.field textarea,
.field select {
  border-radius: 9px;
  border: 1px solid rgba(55, 65, 81, 0.9);
  background: rgba(15, 23, 42, 0.95);
  color: #e5e7eb;
  padding: 6px 8px;
  font-size: 13px;
}

.field textarea {
  resize: vertical;
}

.field-hint {
  font-size: 11px;
  color: #6b7280;
}

.editor-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.editor-buttons .spacer {
  flex: 1;
}

.test-result {
  margin-top: 6px;
  font-size: 12px;
}

.test-result.ok {
  color: #4ade80;
}

.test-result.error {
  color: #f97373;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-toolbar {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(31, 41, 55, 0.9);
  background: radial-gradient(circle at top right, #0b1220 0, #020617 55%);
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  min-width: 160px;
}

.toolbar-field span {
  color: #9ca3af;
}

.toolbar-field select,
.toolbar-field input {
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(55, 65, 81, 0.9);
  color: #e5e7eb;
  font-size: 13px;
  padding: 5px 10px;
}

.messages-container {
  flex: 1;
  padding: 10px 12px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-chat-hint {
  margin: auto;
  text-align: center;
  color: #6b7280;
  font-size: 13px;
}

.empty-main {
  font-size: 15px;
  margin-bottom: 4px;
}

.message-bubble {
  max-width: 900px;
  border-radius: 14px;
  padding: 9px 11px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-row {
  display: flex;
  margin-bottom: 4px;
}

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

.message-row.assistant {
  justify-content: flex-start;
}

.message-bubble.user {
  background: linear-gradient(135deg, #1d4ed8, #7c3aed);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-bubble.assistant {
  background: rgba(15, 23, 42, 0.96);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(31, 41, 55, 0.95);
}

.message-meta {
  font-size: 11px;
  color: #6b7280;
  margin-top: 2px;
}

.message-bubble.assistant .message-meta {
  color: #9ca3af;
}

.message-thinking {
  font-style: italic;
  color: #9ca3af;
  font-size: 13px;
}

.input-section {
  border-top: 1px solid rgba(31, 41, 55, 0.9);
  padding: 8px 10px;
  background: radial-gradient(circle at bottom, #020617 0, #020617 60%);
}

.input-inner {
  max-width: 960px;
  margin: 0 auto;
  border-radius: 16px;
  border: 1px solid rgba(55, 65, 81, 0.9);
  background: rgba(15, 23, 42, 0.98);
  padding: 6px 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#userInput {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: #e5e7eb;
  resize: none;
  font-size: 14px;
}

.input-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.status-text {
  font-size: 12px;
  color: #6b7280;
}

@media (max-width: 768px) {
  .app-header {
    padding: 0 8px;
  }
  .chat-toolbar {
    padding: 6px 8px;
  }
  .toolbar-group {
    flex-direction: column;
  }
  .messages-container {
    padding: 8px 8px 10px;
  }
}

@media (min-width: 900px) {
  .side-panel.hidden {
    transform: translateX(0);
  }
}

/* Top navigation bar */
.top-nav {
  height: 44px;
  padding: 0 12px;
  background: radial-gradient(circle at top left, #020617 0, #020617 55%);
  border-bottom: 1px solid rgba(148, 163, 184, 0.4);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-nav-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.app-logo {
  font-weight: 600;
  letter-spacing: 0.04em;
}

.top-nav-page {
  font-size: 12px;
  color: #9ca3af;
}

.top-nav-links {
  display: flex;
  gap: 8px;
}

.top-nav-links a {
  font-size: 13px;
  color: #9ca3af;
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.top-nav-links a.active {
  color: #e5e7eb;
  border-color: rgba(129, 140, 248, 0.8);
  background: radial-gradient(circle at top left, #1e293b 0, #020617 70%);
}

/* Settings pages common layout */
.settings-page {
  padding: 8px 12px 20px;
}

.settings-header h1 {
  font-size: 18px;
  margin: 8px 0 4px;
}

.settings-header p {
  font-size: 13px;
  color: #9ca3af;
  margin: 0 0 12px;
}

.settings-body {
  border-radius: 14px;
  border: 1px solid rgba(31, 41, 55, 0.9);
  background: radial-gradient(circle at top left, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.92));
  padding: 10px;
}

.settings-body.narrow {
  max-width: 720px;
}

.settings-separator {
  border: none;
  border-top: 1px solid rgba(31, 41, 55, 0.9);
  margin: 12px 0;
}

/* Connections page layout */
.connections-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.connections-list-block {
  flex: 1 1 260px;
  min-width: 240px;
}

.connections-editor-block {
  flex: 2 1 320px;
  min-width: 260px;
}

.editor-empty-hint {
  margin-top: 10px;
}

@media (max-width: 768px) {
  .connections-layout {
    flex-direction: column;
  }
}

/* Slim header for chat page (remove double big header感) */
.app-header.slim {
  height: 48px;
}


/* Slider controls for generation parameters */
.slider-field {
  margin-bottom: 16px;
}

.slider-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  margin-bottom: 4px;
}

.slider-label-row span:first-child {
  font-weight: 500;
}

.slider-value {
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
  font-size: 13px;
}

.icon-button.tiny {
  border: none;
  background: none;
  cursor: pointer;
  padding: 2px 6px;
  font-size: 12px;
  opacity: 0.7;
}

.icon-button.tiny:hover {
  opacity: 1;
}

.field-hint {
  margin-top: 4px;
  font-size: 12px;
  opacity: 0.7;
}

.slider-field input[type="range"] {
  width: 100%;
}


/* Inline input + button container */
.field-with-button {
  display: flex;
  gap: 8px;
  align-items: center;
}

.field-with-button input[type="text"],
.field-with-button input[type="password"] {
  flex: 1;
}

/* Modal for model picker */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

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

.modal-panel {
  background: #111827;
  border-radius: 12px;
  max-width: 480px;
  width: calc(100% - 32px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
  padding: 16px 16px 12px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.close-button {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.modal-body {
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.model-picker-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.model-chip {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 12px;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.9);
}

.model-chip:hover {
  border-color: rgba(255, 255, 255, 0.4);
}

.model-chip.selected {
  border-color: #4f46e5;
  background: rgba(79, 70, 229, 0.18);
}

.empty-text.small {
  font-size: 12px;
  opacity: 0.7;
}

/* ========== 记忆条目样式 ========== */
.memory-items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 12px;
}

.memory-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(55, 65, 81, 0.6);
  border-radius: 8px;
}

.memory-item.disabled {
  opacity: 0.5;
}

.memory-item.disabled .memory-content {
  text-decoration: line-through;
}

.memory-toggle {
  background: none;
  border: none;
  color: #10b981;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}

.memory-item.disabled .memory-toggle {
  color: #6b7280;
}

.memory-content {
  flex: 1;
  font-size: 14px;
  line-height: 1.5;
  color: #e5e7eb;
  word-break: break-word;
}

.memory-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ========== Token统计样式 ========== */
.token-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #9ca3af;
  padding: 4px 8px;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 6px;
}

.token-stats .label {
  opacity: 0.7;
}

.token-stats .value {
  color: #10b981;
  font-weight: 500;
}

/* ========== 聊天搜索样式 ========== */
.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(55, 65, 81, 0.6);
  border-radius: 6px;
  margin-bottom: 8px;
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  color: #e5e7eb;
  font-size: 13px;
  outline: none;
}

.search-box input::placeholder {
  color: #6b7280;
}

/* ========== 消息编辑样式 ========== */
.message-actions {
  display: none;
  gap: 4px;
  margin-top: 4px;
}

.message-row:hover .message-actions {
  display: flex;
}

.message-actions button {
  padding: 2px 6px;
  font-size: 11px;
  background: rgba(55, 65, 81, 0.6);
  border: 1px solid rgba(75, 85, 99, 0.6);
  border-radius: 4px;
  color: #9ca3af;
  cursor: pointer;
}

.message-actions button:hover {
  background: rgba(75, 85, 99, 0.8);
  color: #e5e7eb;
}

.message-bubble.editing {
  background: rgba(79, 70, 229, 0.1);
  border: 1px solid rgba(79, 70, 229, 0.3);
}

.message-edit-area {
  width: 100%;
  min-height: 60px;
  background: transparent;
  border: none;
  color: #e5e7eb;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}

.message-edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  justify-content: flex-end;
}

/* ========== 云同步相关样式 ========== */
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(55, 65, 81, 0.6);
}

.auth-tab {
  padding: 8px 16px;
  background: transparent;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.auth-tab.active {
  color: #e5e7eb;
  border-bottom-color: #6366f1;
}

.auth-tab:hover {
  color: #e5e7eb;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-form input {
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(55, 65, 81, 0.6);
  border-radius: 6px;
  color: #e5e7eb;
  font-size: 14px;
}

.auth-form input:focus {
  outline: none;
  border-color: #6366f1;
}

.auth-form input::placeholder {
  color: #6b7280;
}

.auth-message {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-top: 8px;
  display: none;
}

.auth-message.error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.auth-message.success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
}

.sync-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.sync-user {
  font-size: 14px;
  color: #e5e7eb;
}

.sync-indicator {
  font-size: 12px;
  color: #6b7280;
}

.sync-indicator.syncing {
  color: #fbbf24;
  animation: pulse 1s infinite;
}

.sync-indicator.success {
  color: #10b981;
}

.sync-indicator.error {
  color: #ef4444;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
