/* ===== 泰哥赛道文案生成工具 - ChatGPT 风格样式 ===== */
:root {
  --primary: #d4a849;
  --primary-dark: #b8923a;
  --bg: #f7f7f8;
  --bg-sidebar: #f0f0eb;
  --bg-main: #ffffff;
  --bg-message-user: #f0f7ff;
  --bg-message-ai: #ffffff;
  --bg-input: #ffffff;
  --text: #1a1a1a;
  --text-soft: #6b6b6b;
  --text-muted: #9b9b9b;
  --border: #e5e5e0;
  --border-soft: #ededeb;
  --success: #4a8a3f;
  --danger: #d44a4a;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 10px;
  --radius-sm: 6px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* =================== 登录页 =================== */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fdfaf0 0%, #f5edd5 100%);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: white;
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

.auth-brand h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

.auth-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px;
  font-size: 13px;
  color: var(--text-soft);
  border-radius: 6px;
  transition: all 0.15s;
}

.auth-tab.active {
  background: white;
  color: var(--text);
  font-weight: 500;
  box-shadow: var(--shadow);
}

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

.auth-field { display: flex; flex-direction: column; gap: 4px; }

.auth-field label {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 500;
}

.auth-field input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.15s;
}

.auth-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(212, 168, 73, 0.15);
}

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

.auth-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 11px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}

.auth-btn:hover { background: var(--primary-dark); }
.auth-btn:disabled { background: #ccc; cursor: not-allowed; }

.auth-btn-secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  white-space: nowrap;
  transition: all 0.15s;
}

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

.auth-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* =================== 主应用 =================== */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  background: var(--bg);
}

/* ===== Sidebar ===== */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.new-chat-btn {
  width: 100%;
  background: white;
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.new-chat-btn:hover {
  background: #fafafa;
  border-color: var(--primary);
}

.new-chat-btn span {
  font-size: 18px;
  color: var(--primary);
  font-weight: 400;
}

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 8px 4px;
  letter-spacing: 0.5px;
}

.history-list { display: flex; flex-direction: column; gap: 2px; }

.history-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item:hover {
  background: rgba(0,0,0,0.05);
}

.history-item.active {
  background: white;
  border: 1px solid var(--border);
}

.history-item-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-soft);
  position: relative;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.user-info:hover { background: rgba(0,0,0,0.05); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.user-meta { flex: 1; min-width: 0; }
.user-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 11px;
  color: var(--text-muted);
}

.user-menu-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  padding: 0 6px;
}

.user-menu {
  position: absolute;
  bottom: 70px;
  left: 12px;
  right: 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 100;
}

.user-menu button {
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  transition: background 0.15s;
}

.user-menu button:hover { background: var(--bg); }

/* ===== Main Area ===== */
.main-area {
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  overflow: hidden;
}

.main-header {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
}

.main-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.main-status {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.online { background: var(--success); }
.status-dot.mock { background: var(--primary); }

/* ===== Chat ===== */
.chat-container {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: none;  /* 默认隐藏，由 switchView 控制 */
}

.empty-state {
  max-width: 800px;
  margin: 0 auto;
  padding: 80px 24px 40px;
  text-align: center;
}

.empty-title {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.empty-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 40px;
}

@media (max-width: 768px) {
  .suggestion-grid { grid-template-columns: 1fr; }
}

.suggestion-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
}

.suggestion-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.suggestion-icon {
  font-size: 24px;
  margin-bottom: 6px;
}

.suggestion-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

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

.data-summary {
  margin-top: 32px;
  padding: 16px;
  background: var(--bg);
  border-radius: 10px;
  font-size: 12px;
  color: var(--text-soft);
}

.data-summary-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}

.data-summary-row strong { color: var(--primary-dark); }

/* Messages */
.messages {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message {
  display: flex;
  gap: 12px;
  animation: msgIn 0.2s ease-out;
}

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

.message.user { flex-direction: row-reverse; }

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  font-weight: 600;
}

.message.user .message-avatar {
  background: #5b8def;
  color: white;
}

.message.assistant .message-avatar {
  background: var(--primary);
  color: white;
}

.message-body {
  flex: 1;
  max-width: calc(100% - 56px);
}

.message.user .message-body {
  background: var(--bg-message-user);
  border-radius: 12px;
  padding: 12px 16px;
}

.message.assistant .message-body { padding-top: 4px; }

.message-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.message.user .message-name { text-align: right; }

.message-config {
  font-size: 12px;
  color: var(--text-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.config-tag {
  background: rgba(91, 141, 239, 0.1);
  color: #2a5fcf;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
}

.message-loading {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-soft);
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.message-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 11px;
  color: var(--text-muted);
}

.variants-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.variant-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  transition: all 0.15s;
}

.variant-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(212, 168, 73, 0.1);
}

.variant-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.variant-num {
  background: var(--primary);
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

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

.variant-actions button {
  background: white;
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-soft);
  transition: all 0.15s;
}

.variant-actions button:hover {
  background: var(--bg);
  border-color: var(--primary);
  color: var(--text);
}

.variant-actions button.copied {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.variant-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.variant-post {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 4px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
  font-family: ui-monospace, monospace;
}

.variant-script {
  font-size: 13px;
  line-height: 1.75;
  white-space: pre-wrap;
  background: #fdfbf3;
  padding: 10px;
  border-radius: 6px;
  border-left: 3px solid var(--primary);
}

/* ===== Input Area ===== */
.input-area {
  border-top: 1px solid var(--border-soft);
  background: white;
  padding: 12px 24px 16px;
}

.input-options {
  max-width: 800px;
  margin: 0 auto;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.opt-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.opt-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 140px;
}

.opt-group.opt-narrow { flex: 0 0 90px; }
.opt-group.opt-grow { flex: 1; }

.opt-group label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.opt-select, .opt-group input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
  transition: border-color 0.15s;
}

.opt-select:focus, .opt-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.input-box {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  transition: border-color 0.15s;
}

.input-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(212, 168, 73, 0.1);
}

#extraInput {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  padding: 6px 8px;
  max-height: 120px;
  min-height: 24px;
  background: transparent;
}

.send-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  height: 36px;
}

.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.input-footer {
  max-width: 800px;
  margin: 6px auto 0;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-card-large { max-width: 720px; max-height: 80vh; overflow-y: auto; }

.modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

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

.modal-btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13px;
}

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

.modal-btn-secondary {
  background: white;
  border: 1px solid var(--border);
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13px;
}

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

.modal-close {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
}

/* Admin */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.admin-tab {
  background: transparent;
  border: none;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-soft);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.admin-tab.active {
  color: var(--primary-dark);
  border-bottom-color: var(--primary);
  font-weight: 500;
}

.admin-pane { display: none; }
.admin-pane.active { display: block; }

.admin-add-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th, .admin-table td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border-soft);
}

.admin-table th {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.admin-table .role-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.role-badge.admin { background: #fef0c7; color: #8b6914; }
.role-badge.employee { background: #e0e7ff; color: #2a5fcf; }
.role-badge.disabled { background: #fee; color: var(--danger); }
.role-badge.active { background: #dfd; color: var(--success); }

.admin-table .row-actions button {
  background: transparent;
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  margin-right: 4px;
}

.admin-table .row-actions button:hover {
  background: var(--bg);
  border-color: var(--primary);
}

.config-key-display {
  font-family: monospace;
  background: var(--bg);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.config-hint {
  background: #fff8e1;
  border: 1px solid #ffe082;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  color: #8b6914;
  margin-bottom: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg);
  padding: 14px;
  border-radius: 8px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--primary-dark);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.user-rank-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-rank-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 13px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 9999;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.2s ease-out;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ===== 脚本库样式 ===== */
.library-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px 24px;
  min-height: 70vh;
}
.library-sidebar {
  background: white;
  border-radius: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  height: fit-content;
}
.library-sidebar h3 {
  font-size: 14px;
  color: var(--primary-dark);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
}
.lib-field {
  margin-bottom: 10px;
}
.lib-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-soft);
  display: block;
  margin-bottom: 4px;
}
.lib-field input,
.lib-field select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
  background: white;
}
.lib-field input:focus, .lib-field select:focus {
  outline: none;
  border-color: var(--primary);
}
.lib-field select[multiple] {
  height: auto;
  min-height: 100px;
}
.lib-field .hint {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  display: block;
}
.lib-btn-primary {
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 6px;
}
.lib-btn-primary:hover { background: var(--primary-dark); }
.lib-btn-ghost {
  width: 100%;
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 6px;
}
.lib-btn-ghost:hover { background: var(--bg); }
.library-sidebar hr {
  border: none;
  border-top: 1px solid var(--border-soft);
  margin: 12px 0;
}
.library-main {
  background: white;
  border-radius: 10px;
  padding: 16px;
  border: 1px solid var(--border);
}
.lib-search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.lib-search-bar input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.lib-search-bar input:focus { outline: none; border-color: var(--primary); }
.lib-search-bar button { width: auto; padding: 8px 16px; }
.lib-stats {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
}
.lib-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lib-card {
  background: #fcfbf7;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.lib-card:hover {
  border-color: var(--primary);
  background: white;
  transform: translateY(-1px);
}
.lib-card-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 6px;
}
.lib-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}
.lib-card-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.lib-card-meta .lib-badge {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  color: var(--text-soft);
}
.lib-card-meta .lib-badge.likes {
  background: #ffe7c2;
  color: #8b6914;
  font-weight: 600;
}
.lib-card-meta .lib-star {
  color: var(--primary);
  font-size: 14px;
}
.lib-card-content {
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lib-pager {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
}
.lib-pager button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}
.lib-pager button:disabled { opacity: 0.4; cursor: not-allowed; }
.lib-pager button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ===== 对话样式 ===== */
.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px 24px;
  min-height: 70vh;
}
.chat-sidebar {
  background: white;
  border-radius: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.chat-sessions-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: 60vh;
}
.chat-session-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.chat-session-item:hover { background: var(--bg); }
.chat-session-item.active {
  background: var(--bg-soft, #f5f0e1);
  border: 1px solid var(--primary);
}
.chat-session-item-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.chat-session-item-preview {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-main {
  background: white;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 75vh;
}
.chat-session-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-session-name {
  font-weight: 600;
  font-size: 14px;
}
.chat-session-actions {
  display: flex;
  gap: 6px;
}
.chat-session-actions button {
  padding: 4px 8px;
  font-size: 11px;
  width: auto;
  margin: 0;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
}
.chat-empty .empty-icon {
  font-size: 64px;
  opacity: 0.3;
  margin-bottom: 12px;
}
.chat-empty h3 {
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--text);
}
.chat-empty ul {
  text-align: left;
  list-style: none;
  margin-top: 8px;
  font-size: 13px;
}
.chat-empty li {
  padding: 4px 0;
}
.chat-empty .highlight {
  background: #fff8d4;
  padding: 1px 4px;
  border-radius: 3px;
  font-family: monospace;
}
.chat-msg {
  display: flex;
  gap: 10px;
  max-width: 85%;
}
.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  color: white;
}
.chat-msg.user .chat-msg-avatar { background: #5b8def; }
.chat-msg.assistant .chat-msg-avatar { background: var(--primary); }
.chat-msg-body {
  background: #f5f5f5;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-msg.user .chat-msg-body {
  background: #e8f0fe;
  color: var(--text);
}
.chat-msg.assistant .chat-msg-body {
  background: #fdfbf3;
  border: 1px solid var(--border);
}
.chat-msg-loading {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
}
.chat-input-area {
  border-top: 1px solid var(--border-soft);
  padding: 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--bg);
}
#chatInput {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  background: white;
}
#chatInput:focus { outline: none; border-color: var(--primary); }
#chatSendBtn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  height: 40px;
}
#chatSendBtn:disabled { background: #ccc; cursor: not-allowed; }
#chatSendBtn:hover:not(:disabled) { background: var(--primary-dark); }

/* 脚本详情弹窗 */
.script-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-soft);
}
.script-meta .lib-badge {
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
}
.script-content {
  background: #fdfbf3;
  padding: 16px;
  border-radius: 8px;
  border-left: 3px solid var(--primary);
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 12px;
}
.script-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.script-actions button {
  flex: 1;
  min-width: 120px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.modal-header h3 { margin: 0; }

@media (max-width: 1024px) {
  .library-layout, .chat-layout { grid-template-columns: 1fr; }
  .library-sidebar, .chat-sidebar { max-height: 300px; overflow-y: auto; }
}

/* ===== 侧边栏导航 ===== */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  width: 100%;
}
.nav-btn:hover {
  background: rgba(0,0,0,0.05);
}
.nav-btn.active {
  background: white;
  border: 1px solid var(--primary);
  font-weight: 500;
  color: var(--primary-dark);
}
.nav-btn span { font-size: 14px; }

/* ===== 主页/导航页 ===== */
.home-view {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 80px;
  overflow-y: auto;
  flex: 1;
}
.home-hero {
  text-align: center;
  padding: 32px 0 24px;
}
.home-hero h1 {
  font-size: 32px;
  color: var(--primary-dark);
  margin-bottom: 8px;
}
.home-hero p {
  color: var(--text-soft);
  font-size: 15px;
}
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 16px 0 24px;
}
.home-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
.home-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(212, 168, 73, 0.15);
}
.home-icon {
  font-size: 32px;
  margin-bottom: 8px;
}
.home-card h3 {
  font-size: 15px;
  margin-bottom: 4px;
  color: var(--text);
}
.home-card p {
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.5;
}

/* ===== 主页头部（工具风） ===== */
.home-header {
  text-align: center;
  padding: 24px 0 20px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 24px;
}
.home-header h1 {
  font-size: 22px;
  color: var(--text);
  margin-bottom: 4px;
  font-weight: 600;
}
.home-header p {
  font-size: 13px;
  color: var(--text-soft);
}
.home-hero-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.home-cta {
  display: inline-block;
  padding: 10px 24px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.home-cta:hover { background: var(--primary-dark); }
.home-cta-secondary {
  display: inline-block;
  padding: 10px 20px;
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  text-decoration: none;
  transition: all 0.15s;
}
.home-cta-secondary:hover { background: var(--bg); }
.home-card-hint {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 10px;
  background: var(--bg);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 10px;
}
.home-card-hint.public {
  background: #dfd;
  color: var(--success);
}
.home-card {
  position: relative;
  /* 之前已有 */
}
