/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 240px;
  --bg: #f5f5f5;
  --sidebar-bg: #2c3e50;
  --sidebar-hover: #3d5166;
  --sidebar-active: #1a252f;
  --sidebar-text: #ecf0f1;
  --sidebar-muted: #95a5a6;
  --accent: #3498db;
  --accent-hover: #2980b9;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #212121;
  --text-muted: #757575;
  --unread-dot: #3498db;
  --read-text: #9e9e9e;
  --star-color: #f39c12;
  --danger: #e74c3c;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,0.12);
}

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

/* ── Layout ────────────────────────────────────────────────────────────────── */
body { display: flex; height: 100vh; }

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
  transition: transform 0.25s ease;
}

#main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Sidebar Header ────────────────────────────────────────────────────────── */
#sidebar-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 12px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.logo {
  flex: 1;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff;
}

#btn-hamburger {
  background: none;
  border: none;
  color: var(--sidebar-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s;
  display: none; /* shown on mobile */
}
#btn-hamburger:hover { color: #fff; }

#btn-refresh-all {
  background: none;
  border: none;
  color: var(--sidebar-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
#btn-refresh-all:hover { color: #fff; background: var(--sidebar-hover); }
#btn-refresh-all.spinning { animation: spin 1s linear infinite; }

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

/* ── Feed Nav ──────────────────────────────────────────────────────────────── */
#feed-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

#feed-nav ul { list-style: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.12s;
  user-select: none;
}
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.active { background: var(--sidebar-active); }

.nav-icon { font-size: 12px; opacity: 0.6; flex-shrink: 0; }
.nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.badge:empty { display: none; }

.nav-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--sidebar-muted);
}

#btn-add-feed {
  background: none;
  border: none;
  color: var(--sidebar-muted);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
  transition: color 0.15s;
}
#btn-add-feed:hover { color: #fff; }

.feed-nav-item { position: relative; }

.feed-rename-btn,
.feed-delete-btn {
  background: none;
  border: none;
  color: var(--sidebar-muted);
  cursor: pointer;
  padding: 0 3px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
  line-height: 1;
}
.feed-nav-item:hover .feed-rename-btn,
.feed-nav-item:hover .feed-delete-btn { opacity: 1; }
/* Always show on touch devices */
@media (hover: none) {
  .feed-rename-btn, .feed-delete-btn { opacity: 1; font-size: 16px; }
}
.feed-rename-btn:hover { color: #fff; }
.feed-delete-btn:hover { color: var(--danger); }

.feed-rename-input {
  flex: 1;
  min-width: 0;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 3px;
  color: #fff;
  font-size: 13px;
  padding: 2px 6px;
  outline: none;
}
.feed-rename-input::placeholder { color: rgba(255,255,255,0.35); }

.feed-error-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}

/* ── Sidebar Footer ────────────────────────────────────────────────────────── */
#sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--sidebar-muted);
  user-select: none;
}
.toggle-label input { cursor: pointer; accent-color: var(--accent); }

/* ── Story List Panel ──────────────────────────────────────────────────────── */
#story-list-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  min-height: 0;
}

#story-list-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

#btn-menu-open {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  display: none; /* shown on mobile */
  flex-shrink: 0;
}
#btn-menu-open:hover { color: var(--text); }

#panel-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

#header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#btn-mark-all-read {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
#btn-mark-all-read:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Layout toggle buttons ─────────────────────────────────────────────────── */
#layout-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.layout-btn {
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: background 0.12s, color 0.12s;
}
.layout-btn:last-child { border-right: none; }
.layout-btn:hover { background: var(--bg); color: var(--text); }
.layout-btn.active { background: var(--accent); color: #fff; }

#story-list {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* ── Story Row ─────────────────────────────────────────────────────────────── */
.story-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.story-row:hover { background: #f0f7ff; }
.story-row.read { color: var(--read-text); }
.story-row.read .story-title { font-weight: 400; color: var(--read-text); }
.story-row.selected { background: #e3f2fd; }

/* Unread dot — now a toggle button */
.story-unread-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--unread-dot);
  margin-top: 5px;
  flex-shrink: 0;
  cursor: pointer;
  border: none;
  padding: 0;
  transition: background 0.15s, transform 0.1s;
  outline: none;
}
.story-unread-dot:hover { transform: scale(1.3); }
.story-row.read .story-unread-dot { background: #d0d0d0; }
.story-unread-dot[title] { cursor: pointer; }

.story-body { flex: 1; min-width: 0; }

.story-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.story-row.read .story-meta { color: #bdbdbd; }

.story-feed-name { font-weight: 500; }

.story-summary {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.story-row.read .story-summary { color: #bdbdbd; }

.story-star-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #ccc;
  flex-shrink: 0;
  padding: 2px 4px;
  transition: color 0.15s;
  line-height: 1;
}
.story-star-btn:hover,
.story-star-btn.starred { color: var(--star-color); }

/* ── Load More ─────────────────────────────────────────────────────────────── */
#load-more-bar {
  padding: 16px 20px;
  text-align: center;
  border-top: 1px solid var(--border);
  display: none;
}
#load-more-bar.visible { display: block; }

#btn-load-more {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 7px 24px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
#btn-load-more:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Empty / Loading States ────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
}
.empty-state .empty-icon { font-size: 48px; opacity: 0.3; }
.empty-state p { font-size: 14px; }
.empty-state button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}

/* ── Reader loading / fallback states ─────────────────────────────────────── */
.reader-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 80px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

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

.reader-fallback-notice {
  background: #fff8e1;
  border-left: 3px solid #f39c12;
  color: #795548;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 0 4px 4px 0;
  margin-bottom: 24px;
}

/* ── Modals (add feed) ─────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 440px;
  max-width: 95vw;
  box-shadow: var(--shadow);
}
.modal-box h3 { font-size: 16px; margin-bottom: 16px; }
.modal-box input[type="url"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.modal-box input[type="url"]:focus { border-color: var(--accent); }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; }
.error-msg.hidden { display: none; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
  background: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 8px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}
.btn-secondary:hover { background: var(--bg); }

/* ── Reader box ────────────────────────────────────────────────────────────── */

/* Base: hidden */
#reader-box {
  background: #fafafa;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#reader-box.hidden { display: none; }

/* Modal layout: full-screen overlay */
#main.layout-modal #reader-box:not(.hidden) {
  position: fixed;
  inset: 0;
  z-index: 101;
}

/* Right split layout */
#main.layout-right {
  flex-direction: row;
}
#main.layout-right #story-list-panel {
  width: 380px;
  min-width: 260px;
  max-width: 45%;
  border-right: 1px solid var(--border);
  flex: none;
}
#main.layout-right #reader-box {
  flex: 1;
  min-width: 0;
  border-left: none;
}
#main.layout-right #reader-placeholder {
  flex: 1;
}

/* Bottom split layout */
#main.layout-bottom {
  flex-direction: column;
}
#main.layout-bottom #story-list-panel {
  height: 45%;
  min-height: 120px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
#main.layout-bottom #reader-box {
  flex: 1;
  min-height: 0;
}
#main.layout-bottom #reader-placeholder {
  flex: 1;
}

/* Reader placeholder (split modes, no story selected) */
#reader-placeholder {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-muted);
}
#main.layout-right #reader-placeholder,
#main.layout-bottom #reader-placeholder {
  display: flex;
}
#main.layout-right #reader-box:not(.hidden) ~ #reader-placeholder,
#main.layout-bottom #reader-box:not(.hidden) ~ #reader-placeholder {
  display: none;
}

.placeholder-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.placeholder-icon { font-size: 40px; opacity: 0.2; }
#reader-placeholder p { font-size: 13px; }

/* Modal backdrop */
#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 100;
  cursor: pointer;
}
#modal-backdrop.hidden { display: none; }

/* ── Reader toolbar ────────────────────────────────────────────────────────── */
#reader-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

#btn-reader-close {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  color: var(--accent);
  padding: 4px 8px;
  border-radius: var(--radius);
  white-space: nowrap;
  transition: background 0.15s;
  flex-shrink: 0;
}
#btn-reader-close:hover { background: #e3f2fd; }

#reader-meta {
  flex: 1;
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  min-width: 0;
}
#reader-feed-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#reader-date { white-space: nowrap; flex-shrink: 0; }

#reader-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#btn-reader-star {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #ccc;
  transition: color 0.15s;
  line-height: 1;
}
#btn-reader-star:hover,
#btn-reader-star.starred { color: var(--star-color); }

#btn-reader-unread {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
#btn-reader-unread:hover { background: var(--bg); }

#btn-reader-original {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  white-space: nowrap;
  transition: background 0.15s;
}
#btn-reader-original:hover { background: var(--accent-hover); }

/* ── Reader content ────────────────────────────────────────────────────────── */
#reader-content {
  flex: 1;
  overflow-y: auto;
  padding: 36px 24px 60px;
  max-width: 740px;
  margin: 0 auto;
  width: 100%;
}

#reader-title {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 12px;
  color: var(--text);
}

#reader-author {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

#reader-body {
  font-size: 16px;
  line-height: 1.8;
  color: #333;
}

#reader-body h1, #reader-body h2, #reader-body h3,
#reader-body h4, #reader-body h5, #reader-body h6 {
  margin: 1.4em 0 0.6em;
  line-height: 1.3;
  color: var(--text);
}
#reader-body h1 { font-size: 1.6em; }
#reader-body h2 { font-size: 1.4em; }
#reader-body h3 { font-size: 1.2em; }

#reader-body p { margin-bottom: 1.2em; }

#reader-body a { color: var(--accent); text-decoration: underline; }
#reader-body a:hover { color: var(--accent-hover); }

#reader-body img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 12px 0;
}

#reader-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  margin: 16px 0;
  color: var(--text-muted);
  background: #f0f7ff;
  border-radius: 0 4px 4px 0;
}

#reader-body pre {
  background: #f5f5f5;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px;
  overflow-x: auto;
  font-size: 14px;
  margin-bottom: 1em;
}

#reader-body code {
  background: #f0f0f0;
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.9em;
}

#reader-body pre code { background: none; padding: 0; }

#reader-body ul, #reader-body ol {
  margin: 0.8em 0 1.2em 1.5em;
}
#reader-body li { margin-bottom: 0.4em; }

#reader-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.2em;
  font-size: 14px;
}
#reader-body th, #reader-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
#reader-body th { background: #f5f5f5; font-weight: 600; }

.reader-no-content {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}
.reader-no-content a { color: var(--accent); font-size: 15px; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #323232;
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 999;
  opacity: 1;
  transition: opacity 0.4s;
}
#toast.hidden { display: none; }
#toast.fade-out { opacity: 0; }

/* ── Scrollbar styling ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.3); }

/* ── Mobile sidebar overlay ────────────────────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 49;
}
#sidebar-overlay.visible { display: block; }

/* ── Mobile responsive ─────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  /* Sidebar slides in from left as an overlay */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 50;
    width: min(var(--sidebar-w), 80vw);
  }
  #sidebar.open { transform: translateX(0); }

  #btn-hamburger { display: block; }
  #btn-menu-open { display: block; }

  /* Hide layout toggle on small screens (only modal makes sense) */
  #layout-toggle { display: none; }

  /* Force modal layout on mobile regardless of saved preference */
  #main.layout-right,
  #main.layout-bottom {
    flex-direction: column;
  }
  #main.layout-right #story-list-panel,
  #main.layout-bottom #story-list-panel {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    border: none !important;
    flex: 1 !important;
  }
  #main.layout-right #reader-placeholder,
  #main.layout-bottom #reader-placeholder { display: none; }
  #main.layout-right #reader-box:not(.hidden),
  #main.layout-bottom #reader-box:not(.hidden) {
    position: fixed;
    inset: 0;
    z-index: 101;
  }

  /* Tighter story rows */
  .story-row { padding: 10px 12px; gap: 8px; }
  .story-summary { display: none; }

  /* Reader toolbar wraps on small screens */
  #reader-toolbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  #reader-meta { order: 3; width: 100%; }
  #reader-content { padding: 20px 16px 60px; }
  #reader-title { font-size: 20px; }
  #reader-body { font-size: 15px; }

  /* Smaller header */
  #story-list-header { padding: 10px 12px; }
  #panel-title { font-size: 15px; }
  #btn-mark-all-read { display: none; }
}
