:root {
  --bg: #1a1a1a;
  --bg2: #242424;
  --bg3: #2e2e2e;
  --border: #3a3a3a;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #4a9eff;
  --accent-hover: #6ab3ff;
  --unread-dot: #4a9eff;
  --star: #f5a623;
  --danger: #e05555;
  --ok: #4caf50;
  --sidebar-w: 260px;
  --radius: 8px;
}

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

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); height: 100dvh; overflow: hidden; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Layout ─────────────────────────────────────────────────── */
#app { display: flex; height: 100dvh; overflow: hidden; }

#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
  transition: width .2s, min-width .2s;
}
#sidebar.collapsed { width: 48px; min-width: 48px; overflow: hidden; }
#sidebar.collapsed .feed-name, #sidebar.collapsed .badge,
#sidebar.collapsed .feed-category, #sidebar.collapsed .feed-section-label,
#sidebar.collapsed .sidebar-search { display: none; }

#main { flex: 1; overflow-y: auto; padding: 0 0 40px; }

/* ── Sidebar internals ───────────────────────────────────────── */
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px; border-bottom: 1px solid var(--border);
}
.logo { font-weight: 700; font-size: 1.1rem; color: var(--text); white-space: nowrap; }
.sidebar-search { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.sidebar-search input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 10px; color: var(--text); font-size: .85rem;
}
.feed-section-label { font-size: .7rem; text-transform: uppercase; color: var(--text-muted);
  padding: 12px 14px 4px; letter-spacing: .06em; }
.feed-category { font-size: .75rem; color: var(--text-muted); padding: 8px 14px 2px;
  text-transform: uppercase; letter-spacing: .05em; }

.feed-list, .feed-list-inner { list-style: none; }
.feed-list li a, .feed-list-inner li a {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px; font-size: .875rem; color: var(--text); border-radius: 0;
  transition: background .15s;
}
.feed-list li a:hover, .feed-list-inner li a:hover { background: var(--bg3); }
.feed-list li.active a, .feed-list-inner li.active a { background: var(--bg3); color: var(--accent); }

.favicon { width: 16px; height: 16px; border-radius: 3px; flex-shrink: 0; }
.feed-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  background: var(--accent); color: #fff; border-radius: 10px;
  padding: 1px 6px; font-size: .7rem; font-weight: 600; min-width: 20px; text-align: center;
}

/* ── Stream ──────────────────────────────────────────────────── */
.stream-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--bg); z-index: 10;
}
.stream-header h1 { font-size: 1.2rem; font-weight: 600; }
.stream-actions { display: flex; gap: 8px; }

.article-card {
  border-bottom: 1px solid var(--border); padding: 14px 24px;
  transition: background .1s; cursor: default;
}
.article-card:hover { background: var(--bg2); }
.article-card.read { opacity: .6; }
.article-card.unread .article-title a::before {
  content: ''; display: inline-block; width: 7px; height: 7px;
  background: var(--unread-dot); border-radius: 50%; margin-right: 8px; vertical-align: middle;
}

.article-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.feed-name-small { font-size: .75rem; color: var(--text-muted); }
.article-date { font-size: .75rem; color: var(--text-muted); margin-left: auto; }
.author { font-size: .75rem; color: var(--text-muted); }

.article-title { font-size: .95rem; font-weight: 600; line-height: 1.4; margin-bottom: 4px; }
.article-title a { color: var(--text); }
.article-title a:hover { color: var(--accent); }

.article-summary { font-size: .82rem; color: var(--text-muted); line-height: 1.5;
  margin-bottom: 8px; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; }

.article-actions { display: flex; gap: 6px; align-items: center; }
.action-btn {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 8px; font-size: .78rem; color: var(--text-muted); cursor: pointer;
  transition: all .15s; line-height: 1.4;
}
.action-btn:hover { border-color: var(--accent); color: var(--accent); }
.action-btn.active { border-color: var(--star); color: var(--star); }
.action-btn.read-btn.active { border-color: var(--ok); color: var(--ok); }

.empty-state { padding: 60px 24px; text-align: center; color: var(--text-muted); font-size: 1.1rem; }

#load-more-row { padding: 20px; text-align: center; }
.btn-load-more {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 8px 24px; border-radius: var(--radius); cursor: pointer; font-size: .9rem;
}
.btn-load-more:hover { border-color: var(--accent); }

/* ── Article Reader ──────────────────────────────────────────── */
.article-reader { max-width: 760px; margin: 0 auto; padding: 24px; }
.reader-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.back-btn { color: var(--text-muted); font-size: .9rem; }
.back-btn:hover { color: var(--accent); }
.reader-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.reader-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
  font-size: .82rem; color: var(--text-muted); }
.reader-title { font-size: 1.6rem; font-weight: 700; line-height: 1.3;
  margin-bottom: 20px; color: var(--text); }
.reader-content { font-size: .95rem; line-height: 1.8; color: #ccc; }
.reader-content p { margin-bottom: 1em; }
.reader-content h1,.reader-content h2,.reader-content h3 { color: var(--text); margin: 1.4em 0 .6em; }
.reader-content a { color: var(--accent); }
.reader-content img { max-width: 100%; border-radius: var(--radius); margin: 1em 0; }
.reader-content pre { background: var(--bg3); padding: 12px; border-radius: var(--radius);
  overflow-x: auto; margin: 1em 0; }
.reader-content code { background: var(--bg3); padding: 2px 5px; border-radius: 4px; font-size: .88em; }
.reader-footer { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--border); }

/* ── Forms / Cards ───────────────────────────────────────────── */
.page-header { padding: 20px 24px 12px; border-bottom: 1px solid var(--border); }
.page-header h1 { font-size: 1.2rem; font-weight: 600; }
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  margin: 16px; padding: 20px; }
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 14px; }
.hint { font-size: .82rem; color: var(--text-muted); margin-bottom: 14px; }

label { display: block; font-size: .85rem; margin-bottom: 12px; }
label input, label textarea, label select {
  display: block; width: 100%; margin-top: 4px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px; color: var(--text); font-size: .9rem;
}
label textarea { font-family: inherit; resize: vertical; }

.form-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.input-lg { flex: 1; min-width: 200px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; color: var(--text); font-size: .9rem; }

.btn-primary { background: var(--accent); color: #fff; border: none;
  padding: 8px 16px; border-radius: var(--radius); cursor: pointer; font-size: .9rem; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  padding: 8px 16px; border-radius: var(--radius); cursor: pointer; font-size: .9rem;
  text-align: center; display: inline-block; }
.btn-secondary:hover { border-color: var(--accent); }
.btn-sm { background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: .8rem; }
.btn-sm:hover { border-color: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--danger); }

.status-msg { font-size: .85rem; margin-top: 8px; min-height: 1.2em; }
.status-msg.ok { color: var(--ok); }
.status-msg.err { color: var(--danger); }

.provider-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.feeds-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.feeds-table th, .feeds-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.feeds-table th { color: var(--text-muted); font-weight: 600; }

/* ── AI Chat Panel ───────────────────────────────────────────── */
.chat-panel {
  position: fixed; right: 0; top: 0; bottom: 0; width: 380px; max-width: 100%;
  background: var(--bg2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 200;
  transition: transform .25s; box-shadow: -4px 0 24px rgba(0,0,0,.4);
}
.chat-panel.hidden { transform: translateX(100%); }
.chat-overlay { position: fixed; inset: 0; z-index: 199; }
.chat-overlay.hidden { display: none; }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-msg { max-width: 92%; border-radius: var(--radius); padding: 10px 12px; font-size: .88rem; line-height: 1.6; }
.chat-msg.user { background: var(--accent); color: #fff; align-self: flex-end; }
.chat-msg.assistant { background: var(--bg3); align-self: flex-start; white-space: pre-wrap; }
.chat-msg.assistant code { background: var(--bg2); padding: 2px 4px; border-radius: 3px; }

.chat-input-row { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
#chat-input {
  flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; color: var(--text); font-family: inherit; font-size: .88rem; resize: none;
}
#chat-input:focus { border-color: var(--accent); outline: none; }
#chat-send { background: var(--accent); color: #fff; border: none;
  padding: 0 14px; border-radius: var(--radius); cursor: pointer; font-size: .9rem; }

.icon-btn { background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 1.1rem; padding: 4px; border-radius: 4px; }
.icon-btn:hover { color: var(--text); }

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #sidebar { position: fixed; left: -260px; top: 0; bottom: 0; z-index: 100;
    transition: left .25s; box-shadow: 4px 0 20px rgba(0,0,0,.5); }
  #sidebar.open { left: 0; }
  #main { width: 100%; }
  .article-reader { padding: 16px; }
  .reader-title { font-size: 1.3rem; }
  .chat-panel { width: 100%; }
  .stream-header { padding: 12px 16px 10px; }
  .article-card { padding: 12px 16px; }
}
