:root {
  --accent: #6366F1;
  --accent-hover: #4F46E5;
  --accent-light: rgba(99,102,241,0.08);
  --success: #10B981;
  --success-bg: #ECFDF5;
  --error: #EF4444;
  --error-bg: #FEF2F2;
  --warning: #F59E0B;
  --warning-bg: #FEF3C7;
  --text: #111827;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --bg: #FFFFFF;
  --bg-secondary: #F9FAFB;
  --border: #E5E7EB;
  --border-light: #F3F4F6;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-secondary);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

#app { max-width: 1200px; margin: 0 auto; min-height: 100vh; }

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.logo-link {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
}

.logo-icon { font-size: 24px; }

.logo-text {
  font-size: 18px;
  font-weight: 700;
}

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

.nav-link {
  padding: 8px 16px;
  text-decoration: none;
  color: var(--text-secondary);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}

.nav-link:hover { background: var(--bg-secondary); color: var(--text); }
.nav-link.active { background: var(--accent-light); color: var(--accent); }

.header-right { display: flex; align-items: center; gap: 12px; }

.user-email {
  font-size: 14px;
  color: var(--text);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  gap: 6px;
}

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

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

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

.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ── Upgrade Banner ── */
.upgrade-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--warning-bg);
  border-bottom: 1px solid var(--warning);
  font-size: 14px;
}

.upgrade-icon { flex-shrink: 0; }

.upgrade-text { flex: 1; }

.upgrade-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.upgrade-link:hover { text-decoration: underline; }

.upgrade-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0 4px;
}

/* ─── Views ─── */
.view { padding: 0; }

.hidden { display: none !important; }

/* ─── 左侧导航布局 ─── */
.nm-body { display: flex; min-height: calc(100vh - 57px); }
.nm-sidebar {
  width: 200px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  position: sticky; top: 57px;
  align-self: flex-start;
  max-height: calc(100vh - 57px);
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.nm-sidebar-brand {
  display: flex; align-items: center; gap: 8px;
  padding: 0 8px 16px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}
.nm-sidebar-brand .nm-sidebar-icon { font-size: 20px; }
.nm-sidebar-brand .nm-sidebar-name { font-weight: 700; font-size: 16px; color: var(--text); }
.nm-sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nm-sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  text-decoration: none; color: var(--text-secondary);
  font-size: 14px; font-weight: 500;
  transition: all 0.2s;
}
.nm-sidebar-link:hover { color: var(--text); background: var(--bg-secondary); }
.nm-sidebar-link.active { color: var(--accent); background: var(--accent-light); }
.nm-sidebar-link .nm-sidebar-icon { font-size: 16px; width: 20px; text-align: center; }
.nm-sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border-light); }
.nm-sidebar-email { font-size: 12px; color: var(--text-tertiary); word-break: break-all; }
.nm-main { flex: 1; min-width: 0; padding: 24px 32px; max-width: 900px; margin: 0 auto; }

@media (max-width: 768px) {
  .nm-body { flex-direction: column; }
  .nm-sidebar { width: 100%; position: static; max-height: none; border-right: none; border-bottom: 1px solid var(--border); flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nm-sidebar-brand { border-bottom: none; padding: 0 12px; margin: 0; }
  .nm-sidebar-nav { flex-direction: row; }
  .nm-sidebar-footer { display: none; }
  .nm-main { padding: 16px; }
}

/* ─── List View ─── */
.list-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.list-header h1 { font-size: 24px; font-weight: 700; }

.search-input {
  flex: 1;
  max-width: 300px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
}

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

.article-list { display: flex; flex-direction: column; gap: 8px; }

.article-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.article-item:hover { border-color: var(--accent); box-shadow: var(--shadow); }

.article-item.main {
  background: #FEF3C7;
  border-color: #F59E0B;
}

.article-item.main .article-title { color: #92400E; }

.article-main-badge {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: #92400E;
  background: #FEF3C7;
  border: 1px solid #F59E0B;
  padding: 2px 8px;
  border-radius: 4px;
}

.article-content { flex: 1; min-width: 0; }

.article-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.article-meta {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.article-tag {
  font-size: 11px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-secondary);
}

.article-excerpt {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.load-more-container {
  text-align: center;
  margin-top: 16px;
}

/* ─── Detail View ─── */
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.detail-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: text;
}

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

.detail-title[contenteditable] {
  background: #FAFCFF;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.detail-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tag-badge {
  font-size: 12px;
  background: var(--accent-light);
  color: var(--accent);
  padding: 4px 8px;
  border-radius: 4px;
}

.detail-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.detail-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 300px;
  line-height: 1.7;
}

.detail-content.readonly {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-content.editable {
  min-height: 400px;
  outline: none;
}

/* Markdown rendering */
.detail-content h1, .detail-content h2, .detail-content h3 {
  margin: 16px 0 8px;
  font-weight: 700;
  color: var(--text);
}

.detail-content h1 { font-size: 24px; }
.detail-content h2 { font-size: 20px; }
.detail-content h3 { font-size: 18px; }

.detail-content p { margin: 8px 0; }

.detail-content ul, .detail-content ol { margin: 8px 0; padding-left: 24px; }

.detail-content li { margin: 4px 0; }

.detail-content code {
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

.detail-content pre {
  background: #1F2937;
  color: #F3F4F6;
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 12px 0;
}

.detail-content pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.detail-content blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 12px;
  margin: 12px 0;
  color: var(--text-secondary);
}

.detail-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}

.detail-content th, .detail-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.detail-content th { background: var(--bg-secondary); font-weight: 600; }

.detail-content a {
  color: var(--accent);
  text-decoration: none;
}

.detail-content a:hover { text-decoration: underline; }

/* ─── Chat Overlay ─── */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 500px;
  background: var(--bg);
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  z-index: 200;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-title { flex: 1; font-weight: 600; }

.chat-context {
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.chat-message {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

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

.chat-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
}

.chat-message.user .chat-bubble {
  background: var(--accent);
  color: #fff;
}

.chat-message.assistant .chat-bubble {
  background: var(--bg-secondary);
  color: var(--text);
}

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.chat-input-area textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 80px;
  outline: none;
}

.chat-input-area textarea:focus { border-color: var(--accent); }

.chat-input-area .btn { margin-top: 8px; width: 100%; }

.export-section {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

/* ─── Dropdown Menu ─── */
.dropdown-menu {
  position: absolute;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 300;
  padding: 4px 0;
}

.dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dropdown-item:hover { background: var(--bg-secondary); }
.dropdown-item.selected { background: var(--accent-light); color: var(--accent); }
.dropdown-item .check { visibility: hidden; }
.dropdown-item.selected .check { visibility: visible; }

.dropdown-divider {
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.dropdown-empty {
  padding: 12px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

/* ─── Login Modal ─── */
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  width: 100%;
  max-width: 400px;
}

.modal h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
}

.modal input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
}

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

.modal .btn { width: 100%; margin-bottom: 8px; }

.modal .hint {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 12px;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 400;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

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

/* ─── Loading / Empty States ─── */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

.loading::after {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p { margin-bottom: 16px; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .app-header { padding: 12px 16px; }

  .header-nav { display: none; }

  .detail-header { flex-wrap: wrap; }
  .detail-actions { width: 100%; margin-top: 8px; }

  .chat-panel { width: 100%; }
}