:root {
  --bg: #ffffff;
  --bg-alt: #f6f7f8;
  --bg-hover: #eaecef;
  --border: #e1e4e8;
  --text: #1a1a1a;
  --text-muted: #6a737d;
  --primary: #f97316;
  --primary-hover: #ea580c;
  --unread: #3b82f6;
  --star: #facc15;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --sidebar-w: 240px;
  --list-w: 380px;
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-alt: #16162a;
  --bg-hover: #262640;
  --border: #2a2a44;
  --text: #e0e0e8;
  --text-muted: #8888a0;
  --primary: #f97316;
  --primary-hover: #fb923c;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.6;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 0.85rem; }

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-left { flex: 0 0 auto; }
.topbar-center { flex: 1; max-width: 500px; margin: 0 24px; }
.topbar-right { display: flex; gap: 4px; }

.logo { font-weight: 700; font-size: 1.1rem; }

.search-input {
  width: 100%;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-alt);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--primary); }

.btn-icon {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius);
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--bg-hover); }

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--bg-alt);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}
.btn-secondary:hover { background: var(--bg-hover); }

/* ===== Layout ===== */
.layout {
  display: flex;
  height: calc(100vh - 52px);
  overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
}
.sidebar-header h3 { font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; }
.badge {
  background: var(--bg-hover);
  color: var(--text-muted);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
}

.feed-list { flex: 1; overflow-y: auto; padding: 0 6px; }

.feed-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
}
.feed-item:hover { background: var(--bg-hover); }
.feed-item.active { background: var(--primary); color: white; }
.feed-item.active .feed-count { color: rgba(255,255,255,0.8); }

.feed-icon { font-size: 1rem; flex-shrink: 0; }
.feed-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.85rem; }
.feed-count { font-size: 0.7rem; color: var(--text-muted); flex-shrink: 0; }
.feed-delete { opacity: 0; font-size: 0.85rem; cursor: pointer; transition: opacity 0.15s; flex-shrink: 0; }
.feed-item:hover .feed-delete { opacity: 0.6; }
.feed-delete:hover { opacity: 1 !important; color: #ef4444; }

.sidebar-footer { border-top: 1px solid var(--border); padding: 6px; }
.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  font-size: 0.85rem;
  transition: background 0.12s;
}
.nav-item:hover { background: var(--bg-hover); }
.nav-item.active { background: var(--bg-hover); font-weight: 600; }

/* ===== Article list ===== */
.article-list-panel {
  width: var(--list-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.article-list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px 16px 8px;
}
.article-list-header h2 { font-size: 1rem; }

.article-list { flex: 1; overflow-y: auto; }

.article-card {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}
.article-card:hover { background: var(--bg-alt); }
.article-card.active { background: var(--bg-hover); border-left: 3px solid var(--primary); padding-left: 13px; }
.article-card.unread::before {
  content: '';
  position: absolute;
  left: 6px; top: 50%;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--unread);
  transform: translateY(-50%);
}

.ac-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; line-height: 1.4; }
.ac-preview { color: var(--text-muted); font-size: 0.8rem; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ac-meta { display: flex; gap: 8px; margin-top: 6px; font-size: 0.7rem; color: var(--text-muted); }
.ac-star { color: var(--star); }

/* ===== Reader ===== */
.reader-panel {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}

.reader-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.4; }

.reader-content { max-width: 760px; margin: 0 auto; padding: 24px 40px 80px; }

.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.reader-meta { display: flex; gap: 12px; align-items: center; }
.reader-feed { font-weight: 600; color: var(--primary); font-size: 0.8rem; }
.reader-date { color: var(--text-muted); font-size: 0.8rem; }
.reader-actions { display: flex; gap: 6px; }

.btn-action {
  background: none;
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.8rem;
  text-decoration: none;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-action:hover { background: var(--bg-hover); border-color: var(--primary); }
.btn-action.starred { color: var(--star); border-color: var(--star); }

.ai-result {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  padding: 16px 20px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  font-size: 0.9rem;
}
.ai-result h4 { margin-bottom: 8px; color: var(--primary); font-size: 0.8rem; }
.ai-result .ai-content { line-height: 1.7; }
.ai-result .ai-content p { margin-bottom: 8px; }

#readerTitle { font-size: 1.6rem; font-weight: 700; line-height: 1.3; margin-bottom: 16px; }

.reader-body { font-size: 0.95rem; line-height: 1.8; }
.reader-body p { margin-bottom: 16px; }
.reader-body h2 { font-size: 1.3rem; margin: 24px 0 12px; }
.reader-body h3 { font-size: 1.1rem; margin: 20px 0 10px; }
.reader-body img { max-width: 100%; border-radius: var(--radius); margin: 12px 0; }
.reader-body a { color: var(--primary); }
.reader-body pre { background: var(--bg-alt); padding: 14px; border-radius: var(--radius); overflow-x: auto; margin: 12px 0; }
.reader-body code { font-size: 0.85em; }
.reader-body blockquote { border-left: 3px solid var(--border); padding-left: 16px; color: var(--text-muted); margin: 12px 0; }
.reader-body table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.reader-body th, .reader-body td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--bg);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 460px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal h2 { margin-bottom: 16px; font-size: 1.1rem; }
.modal-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 10px;
  outline: none;
}
.modal-input:focus { border-color: var(--primary); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  color: white;
  padding: 10px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  z-index: 2000;
  animation: toast-in 0.2s ease;
}
.toast.error { background: #dc2626; }
.toast.success { background: #16a34a; }

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

/* ===== Loading ===== */
.loading { padding: 24px; text-align: center; color: var(--text-muted); }

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

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .sidebar { display: none; }
}
@media (max-width: 768px) {
  .article-list-panel { width: 100%; }
  .reader-panel { display: none; }
  .reader-panel.mobile-open { display: block; position: fixed; inset: 52px 0 0 0; z-index: 100; }
}
