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

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-hover: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #ff6719;
  --accent-dim: rgba(255, 103, 25, 0.15);
  --link: #58a6ff;
  --font: "Geist Mono", monospace;
  --font-mono: "Geist Mono", monospace;
  --radius: 8px;
  --max-width: 720px;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-card: #f6f8fa;
  --bg-hover: #eef1f5;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --accent: #e5550d;
  --accent-dim: rgba(229, 85, 13, 0.12);
  --link: #0969da;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* --- Header --- */
.header {
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}
.header h1 {
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
}
.header h1:hover { color: var(--accent); }
.header .badge {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.header .spacer { flex: 1; }

/* --- Search bar --- */
.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 360px;
}
.search-wrapper .search-icon {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.search-wrapper input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 12px 7px 32px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.search-wrapper input::placeholder { color: var(--text-muted); }
.search-wrapper input:focus {
  border-color: var(--accent);
  background: var(--bg);
}
.header-btn, .theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--font);
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  gap: 4px;
}
.theme-toggle { font-size: 16px; }
.header-btn:hover, .theme-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  text-decoration: none;
}

.header .live-dot {
  width: 8px; height: 8px;
  background: #3fb950;
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* --- Main content --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px;
}

/* --- Dashboard layout with sidebar --- */
.dashboard-layout {
  display: flex;
  gap: 0;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0;
}
.sort-sidebar {
  width: 230px;
  flex-shrink: 0;
  padding: 24px 0 24px 24px;
  position: sticky;
  top: 57px; /* header height */
  align-self: flex-start;
  height: fit-content;
}
.sort-sidebar h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.sort-sidebar .sort-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  text-align: left;
}
.sort-sidebar .sort-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.sort-sidebar .sort-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.sort-sidebar .sort-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}
.sort-sidebar .nl-list {
  margin-top: 12px;
}
.sort-sidebar .nl-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 12px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  text-align: left;
  min-width: 0;
}
.sort-sidebar .nl-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.sort-sidebar .nl-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.sort-sidebar .nl-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}
.sort-sidebar .nl-count {
  font-size: 11px;
  opacity: 0.6;
  margin-left: auto;
  flex-shrink: 0;
}
.dashboard-main {
  flex: 1;
  min-width: 0;
  padding: 24px;
}
@media (max-width: 700px) {
  .dashboard-layout {
    flex-direction: column;
  }
  .sort-sidebar {
    width: 100%;
    position: static;
    padding: 16px 16px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
  }
  .sort-sidebar h3 {
    width: 100%;
    margin-bottom: 4px;
  }
  .sort-sidebar .nl-list {
    margin-top: 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
  }
  .sort-sidebar .nl-btn {
    width: auto;
  }
  .dashboard-main {
    padding: 16px;
  }
}

/* --- Dashboard --- */
.newsletter-group { margin-bottom: 32px; }
.newsletter-group h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.article-card {
  display: block;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.article-card:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  text-decoration: none;
}
.article-card .title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}
.article-card .subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.article-card .meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* --- Article Reader --- */
.article-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.article-header .back {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: inline-block;
}
.article-header .back:hover { color: var(--accent); }
.article-header h1 {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 8px;
}
.article-header .subtitle {
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.article-header .meta {
  font-size: 13px;
  color: var(--text-muted);
}

.article-body {
  font-size: 17px;
  line-height: 1.8;
}
.article-body h1 { font-size: 28px; margin: 32px 0 16px; }
.article-body h2 { font-size: 24px; margin: 28px 0 14px; }
.article-body h3 { font-size: 20px; margin: 24px 0 12px; }
.article-body p { margin-bottom: 16px; }
.article-body img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 16px 0;
}
.article-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  margin: 16px 0;
  color: var(--text-muted);
}
.article-body pre {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  margin: 16px 0;
  font-family: var(--font-mono);
  font-size: 14px;
}
.article-body code {
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.article-body pre code { background: none; padding: 0; }
.article-body ul, .article-body ol {
  margin: 16px 0;
  padding-left: 24px;
}
.article-body li { margin-bottom: 8px; }
.article-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}
.article-body a { color: var(--link); }

/* --- Download Dropdown --- */
.download-wrapper {
  position: relative;
  display: inline-block;
}
.download-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  padding: 6px 14px;
  font-size: 13px;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}
.download-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.download-btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.download-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 160px;
  z-index: 150;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  overflow: hidden;
  animation: dropIn 0.15s ease;
}
.download-menu.open { display: block; }
@keyframes dropIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.download-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}
.download-menu button:hover {
  background: var(--bg-hover);
}
.download-menu button span.dl-icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.download-menu .dl-label { flex: 1; }
.download-menu .dl-ext {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 6px;
  background: var(--accent-dim);
  border-radius: 4px;
}

/* --- Loading / Empty --- */
.loading, .empty {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}
.loading { font-size: 14px; }
.empty { font-size: 16px; }

/* --- Print styles for PDF export --- */
@media print {
  .header, .article-header .back, .download-wrapper, .toast { display: none !important; }
  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 12pt;
  }
  .container { max-width: 100%; padding: 0; }
  .article-header { border-bottom: 1px solid #ccc; }
  .article-header h1 { font-size: 24pt; color: #000; }
  .article-header .subtitle { color: #444; }
  .article-header .meta { color: #666; }
  .article-body { font-size: 11pt; line-height: 1.6; }
  .article-body pre {
    background: #f5f5f5 !important;
    border: 1px solid #ddd;
  }
  .article-body a { color: #000; text-decoration: underline; }
  .article-body img { max-width: 100%; }
}

/* --- Toast notification --- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 14px;
  z-index: 200;
  animation: slideIn 0.3s ease;
  max-width: 360px;
}
@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
