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

:root {
  --bg: #f8f9fa;
  --sidebar-bg: #2d3748;
  --sidebar-text: #e2e8f0;
  --sidebar-hover: #4a5568;
  --sidebar-active: #4c51bf;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-secondary: #718096;
  --accent: #4c51bf;
  --accent-light: #667eea;
  --unread-dot: #e53e3e;
  --read-bg: #ffffff;
  --unread-bg: #f0f4ff;
  --hover-bg: #edf2f7;
  --saved-color: #ecc94b;
  --panel-divider: #d0d7e2;
  --reader-link: #4c51bf;
}

[data-theme="dark"] {
  --bg: #1a202c;
  --sidebar-bg: #171923;
  --sidebar-text: #cbd5e0;
  --sidebar-hover: #2d3748;
  --sidebar-active: #4c51bf;
  --border: #2d3748;
  --text: #e2e8f0;
  --text-secondary: #a0aec0;
  --unread-bg: #1e2a4a;
  --hover-bg: #2d3748;
  --read-bg: #1a202c;
  --panel-divider: #2d3748;
  --reader-link: #7f9cf5;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

#app {
  display: grid;
  grid-template-columns: 220px 360px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
#sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 12px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}

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

.icon-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  background: transparent;
  color: var(--sidebar-text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

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

.feeds-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.feeds-list::-webkit-scrollbar { width: 4px; }
.feeds-list::-webkit-scrollbar-track { background: transparent; }
.feeds-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

.feed-item {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
  gap: 8px;
  position: relative;
  font-size: 13.5px;
}

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

.feed-item.active {
  background: var(--sidebar-active);
  color: #fff;
}

.feed-item.active .feed-count {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

.feed-icon {
  font-size: 14px;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.feed-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feed-count {
  background: rgba(255,255,255,0.15);
  color: var(--sidebar-text);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.feed-divider {
  font-size: 11px;
  color: rgba(255,255,255,0.3);
  padding: 12px 14px 4px;
  letter-spacing: 1px;
}

.feed-item .feed-delete {
  opacity: 0;
  font-size: 12px;
  color: #fc8181;
  padding: 2px 4px;
  border-radius: 3px;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.feed-item:hover .feed-delete { opacity: 1; }
.feed-item .feed-delete:hover { background: rgba(252,129,129,0.2); }

.sidebar-footer {
  padding: 8px 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.last-updated {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
}

/* ===== ARTICLE LIST ===== */
#article-list-panel {
  background: var(--bg);
  border-right: 1px solid var(--panel-divider);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.panel-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--read-bg);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-input {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  width: 130px;
  transition: border-color 0.15s, width 0.2s;
}

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

.text-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12.5px;
  padding: 4px 6px;
  border-radius: 4px;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
}

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

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

#article-list::-webkit-scrollbar { width: 4px; }
#article-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.article-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
  background: var(--read-bg);
}

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

.article-item.unread {
  background: var(--unread-bg);
}

.article-item.unread .article-title {
  font-weight: 700;
}

.article-item.selected {
  background: #e8eaff;
  border-left: 3px solid var(--accent);
}

.article-item.selected.unread {
  background: #dde3ff;
}

[data-theme="dark"] .article-item.selected { background: #2d3a6a; }
[data-theme="dark"] .article-item.selected.unread { background: #35427a; }

.article-title {
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.article-feed-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}

.article-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--unread-dot);
  flex-shrink: 0;
}

.article-item.read .article-dot { display: none; }

.article-saved {
  color: var(--saved-color);
  font-size: 11px;
}

.loading-indicator {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

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

/* ===== READER ===== */
#reader-panel {
  background: var(--read-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#reader-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reader-empty-content {
  text-align: center;
  color: var(--text-secondary);
}

.reader-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.reader-empty-content p {
  font-size: 14px;
}

#reader-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#reader-content::-webkit-scrollbar { width: 6px; }
#reader-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.reader-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--read-bg);
  gap: 12px;
}

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

.reader-feed-name {
  color: var(--accent);
  font-weight: 500;
}

.reader-date {}

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

.reader-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.4;
  padding: 20px 24px 8px;
  color: var(--text);
}

.reader-body {
  padding: 0 24px 40px;
  font-size: 15.5px;
  line-height: 1.8;
  color: var(--text);
  max-width: 760px;
}

.reader-body p { margin-bottom: 14px; }
.reader-body h1, .reader-body h2, .reader-body h3 {
  margin: 20px 0 10px;
  font-weight: 700;
}
.reader-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 8px 0;
}
.reader-body a {
  color: var(--reader-link);
  text-decoration: underline;
  text-decoration-color: var(--reader-link);
}
.reader-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  color: var(--text-secondary);
  margin: 12px 0;
}
.reader-body pre, .reader-body code {
  background: var(--hover-bg);
  border-radius: 4px;
  font-size: 13px;
}
.reader-body pre { padding: 12px; overflow-x: auto; margin: 12px 0; }
.reader-body code { padding: 2px 5px; }
.reader-body ul, .reader-body ol { padding-left: 24px; margin-bottom: 14px; }
.reader-body li { margin-bottom: 4px; }

/* ===== MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal-box {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  width: 460px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

[data-theme="dark"] .modal-box { background: #1a202c; }

.modal-box h3 {
  font-size: 17px;
  margin-bottom: 16px;
  color: var(--text);
}

.modal-box input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s;
}

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

.modal-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

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

.btn {
  padding: 8px 20px;
  border-radius: 7px;
  border: none;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-light); }
.btn.secondary { background: var(--hover-bg); color: var(--text); }
.btn.secondary:hover { background: var(--border); }

.modal-error {
  margin-top: 10px;
  font-size: 12.5px;
  color: #e53e3e;
  min-height: 18px;
}

/* ===== Scrollbar ===== */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  #app {
    grid-template-columns: 180px 280px 1fr;
  }
}

/* ===== DISCOVERY PANEL ===== */
.discovery-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  height: 100vh;
  background: var(--read-bg);
  box-shadow: -4px 0 30px rgba(0,0,0,0.15);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: right 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.discovery-panel.open {
  right: 0;
}

.discovery-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 199;
}

.discovery-header {
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.discovery-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.discovery-search-wrap {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.discovery-search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s;
}

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

#discovery-categories {
  padding: 8px 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cat-tag {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: transparent;
  transition: all 0.15s;
}

.cat-tag:hover, .cat-tag.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.discovery-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.discovery-list::-webkit-scrollbar { width: 4px; }
.discovery-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.discovery-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

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

.dis-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 700;
}

.dis-info {
  flex: 1;
  overflow: hidden;
}

.dis-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.dis-desc {
  font-size: 11.5px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dis-cat {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--hover-bg);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.dis-subscribe-btn {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  flex-shrink: 0;
  transition: all 0.15s;
}

.dis-subscribe-btn:not(.subscribed) {
  background: var(--accent);
  color: #fff;
}

.dis-subscribe-btn:not(.subscribed):hover {
  background: var(--accent-light);
}

.dis-subscribe-btn.subscribed {
  background: var(--hover-bg);
  color: var(--text-secondary);
  cursor: default;
}

.dis-subscribe-btn.loading {
  opacity: 0.6;
  pointer-events: none;
}

.dis-subscribe-btn.done {
  background: #48bb78;
  color: #fff;
}

@media (max-width: 700px) {
  #app {
    grid-template-columns: 1fr;
  }
  #sidebar { display: none; }
  .discovery-panel { width: 100%; right: -100%; }
}
