/* Brand palette, sampled from the logo (see static/img/): deep navy
   wordmark, amber/orange RSS icon, sky-blue orbit ring. Dark is the
   default; light applies either by OS preference (prefers-color-scheme)
   or by explicit choice (html[data-theme], set by static/js/theme.js) —
   an explicit choice always wins over the OS preference. */

:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;

  --bg: #0c0f16;
  --bg-sidebar: #11151e;
  --bg-row-hover: #1a202e;
  --bg-row-selected: #1d3252;
  --accent: #5b93d9;
  --accent-dark: #3f72b8;
  --star: #f5b400;
  --text: #e8e8ea;
  --text-muted: #a3a3a8;
  --text-dim: #74747a;
  --border: #242a38;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #ffffff;
    --bg-sidebar: #eef1f6;
    --bg-row-hover: #e2e8f0;
    --bg-row-selected: #d6e3fb;
    --accent: #2f5fa8;
    --accent-dark: #24497f;
    --star: #9c6307;
    --text: #0f2038;
    --text-muted: #4a5568;
    --text-dim: #5c6677;
    --border: #c7cedb;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-sidebar: #eef1f6;
  --bg-row-hover: #e2e8f0;
  --bg-row-selected: #d6e3fb;
  --accent: #2f5fa8;
  --accent-dark: #24497f;
  --star: #9c6307;
  --text: #0f2038;
  --text-muted: #4a5568;
  --text-dim: #5c6677;
  --border: #c7cedb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a {
  color: var(--accent);
}

h1, h2, h3 {
  color: var(--text);
  margin: 0 0 0.5rem;
}

input, textarea, select, button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 1rem;
  padding: 0.5rem;
  font-family: inherit;
}

button {
  cursor: pointer;
}

.messages {
  list-style: none;
  padding: 1rem 1.25rem 0;
  margin: 0;
}

.message {
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  margin-bottom: 0.5rem;
}

.message-success { background: #d1fae5; color: #065f46; }
.message-error { background: #fee2e2; color: #991b1b; }
.message-warning { background: #fef3c7; color: #92400e; }
.message-info { background: #dbeafe; color: #1e40af; }

form p {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.inline-form {
  display: inline;
}

.new-articles-banner[hidden],
.unread-count[hidden],
.starred-count[hidden] {
  display: none;
}

.new-articles-banner {
  display: block;
  width: 100%;
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 0.375rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-align: center;
}

.empty-state {
  opacity: 0.6;
  padding: 2rem 0;
  text-align: center;
}

.feed-favicon {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex: 0 0 auto;
}

/* App shell: sidebar + main content, used on every authenticated page */

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: 230px;
  flex: 0 0 230px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

.sidebar-brand a {
  display: block;
  color: var(--text);
  text-decoration: none;
}

.sidebar-brand img {
  height: 96px;
  width: auto;
  margin: 0 auto;
}

/* Theme-swapped logo images — used in the sidebar brand and on the
   auth pages (login/setup/create user). Neither .sidebar-brand img nor
   .auth-brand img sets `display`, so these stay the only rule touching
   it and can't lose a specificity fight with the sizing rules. */
.brand-wordmark-dark {
  display: block;
}

.brand-wordmark-light {
  display: none;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .brand-wordmark-dark {
    display: none;
  }
  :root:not([data-theme]) .brand-wordmark-light {
    display: block;
  }
}

:root[data-theme="light"] .brand-wordmark-dark {
  display: none;
}

:root[data-theme="light"] .brand-wordmark-light {
  display: block;
}

.auth-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.auth-brand img {
  height: 110px;
  width: auto;
}

.theme-switcher {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem;
}

.theme-switcher button {
  flex: 1;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 0.375rem;
  font-size: 0.75rem;
  padding: 0.3rem 0;
}

.theme-switcher button:hover {
  background: var(--bg-row-hover);
  color: var(--text);
}

.theme-switcher button.active {
  background: var(--bg-row-selected);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.sidebar-manage-btn {
  display: block;
  margin: 0.75rem 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--accent);
  color: #fff;
  text-align: center;
  border-radius: 0.375rem;
  text-decoration: none;
  font-size: 0.85rem;
}

.sidebar-manage-btn:hover {
  background: var(--accent-dark);
}

.sidebar-top-nav {
  list-style: none;
  margin: 0;
  padding: 0 0.5rem;
}

.sidebar-top-nav li a,
.sidebar-top-nav li button {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.9rem;
  text-align: left;
  background: none;
}

.sidebar-top-nav li a:hover,
.sidebar-top-nav li button:hover {
  background: var(--bg-row-hover);
  color: var(--text);
}

.sidebar-top-nav li a.active {
  background: var(--bg-row-selected);
  color: var(--text);
  font-weight: 600;
}

.sidebar-footer-nav {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.sidebar-section {
  padding: 0 0.5rem;
}

/* `summary`'s native disclosure triangle is a ::marker, positioned for
   list-item/inline content — once the tag-name + unread-count row below
   needed to be a flex box (block-level), the marker got pushed onto its
   own line above instead of sitting beside it. Replacing it with a
   plain ::before triangle lets `summary` itself be a flex row with that
   triangle as a normal flex item, so it stays inline no matter what the
   rest of the row contains. */
.sidebar-section summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  list-style: none;
}

.sidebar-section summary::-webkit-details-marker {
  display: none;
}

.sidebar-section summary::before {
  content: "▶";
  flex: 0 0 auto;
  font-size: 0.6rem;
  transition: transform 0.1s ease;
}

.sidebar-section[open] > summary::before {
  transform: rotate(90deg);
}

.sidebar-tag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  flex: 1 1 auto;
  min-width: 0;
}

.sidebar-tag-link {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  margin: -0.15rem -0.4rem;
  border-radius: 0.375rem;
  color: inherit;
  text-decoration: none;
}

.sidebar-tag-link.active {
  background: var(--bg-row-selected);
  color: var(--text);
  font-weight: 600;
}

.sidebar-item-list {
  list-style: none;
  margin: 0;
  padding: 0 0.5rem 0.5rem;
}

.sidebar-item-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.sidebar-feed-link {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.5rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 0.375rem;
  font-size: 0.85rem;
  min-width: 0;
}

.sidebar-feed-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-feed-link:hover {
  background: var(--bg-row-hover);
  color: var(--text);
}

.sidebar-feed-link.active {
  background: var(--bg-row-selected);
  color: var(--text);
  font-weight: 600;
}

.unread-count {
  font-size: 0.75rem;
  color: var(--text-dim);
  padding-right: 0.5rem;
  flex: 0 0 auto;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}

.topbar-search input[type="search"] {
  width: 100%;
  max-width: 420px;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
}

.app-content {
  padding: 1rem 1.25rem 2rem;
  flex: 1;
  min-width: 0;
}

.auth-content {
  max-width: 28rem;
  margin: 3rem auto;
  padding: 0 1rem;
}

/* Stream toolbar and article list */

.stream-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.stream-scope-title {
  font-size: 1.15rem;
  flex: 0 0 auto;
  margin: 0;
}

.filter-tabs {
  display: flex;
  gap: 0.25rem;
  margin: 0;
}

.filter-tabs a {
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.filter-tabs a:hover {
  background: var(--bg-row-hover);
}

.filter-tabs a.active {
  background: var(--bg-row-selected);
  color: var(--text);
  font-weight: 600;
}

.stream-toolbar .inline-form {
  margin-left: auto;
}

.stream-toolbar button[type="submit"] {
  background: none;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
}

.article-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.date-header {
  padding: 0.5rem 0.25rem;
  margin-top: 0.75rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.article-row {
  border-bottom: 1px solid var(--border);
}

.article-row-main {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.25rem;
}

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

.article-row.is-expanded .article-row-main {
  background: var(--bg-row-selected);
  box-shadow: inset 3px 0 0 var(--accent);
}

.article-feed-name {
  font-size: 0.8rem;
  color: var(--text-dim);
  flex: 0 0 auto;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.article-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.article-row.is-read .article-title {
  font-weight: 400;
  color: var(--text-muted);
}

.article-time {
  font-size: 0.8rem;
  color: var(--text-dim);
  flex: 0 0 auto;
  white-space: nowrap;
}

.article-actions {
  display: flex;
  gap: 0.15rem;
  flex: 0 0 auto;
}

.icon-btn {
  background: none;
  border: none;
  padding: 0.25rem;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  text-decoration: none;
  font-size: 0.85rem;
}

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

.icon-btn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.icon-btn-read.is-unread {
  color: var(--accent);
}

.icon-btn-read.is-unread svg {
  fill: var(--accent);
}

.icon-btn-star.active {
  color: var(--star);
}

.icon-btn-star.active svg {
  fill: var(--star);
}

.icon-btn-saved.active {
  color: var(--accent);
}

.icon-btn-saved.active svg {
  fill: var(--accent);
}

.article-inline-body {
  padding: 0.75rem 1rem 1.5rem 2.1rem;
  border-bottom: 1px solid var(--border);
}

.article-content-header {
  margin-bottom: 0.75rem;
}

.article-content-title {
  font-size: 1.3rem;
  margin: 0 0 0.3rem;
  font-weight: 600;
}

.article-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.article-meta .feed-favicon {
  vertical-align: -2px;
  margin-right: 0.3rem;
}

.article-content {
  line-height: 1.6;
  margin-top: 1rem;
  overflow-wrap: break-word;
  word-break: break-word;
}

.article-content a {
  overflow-wrap: anywhere;
}

.article-content img {
  max-width: 100%;
}

.pagination {
  display: flex;
  justify-content: space-between;
  margin: 1rem 0;
}

/* Tags */

.tag-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.tag-pill {
  --tag-color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--tag-color);
  color: var(--tag-color);
  text-decoration: none;
  font-size: 0.85rem;
}

.tag-pill.active {
  background: var(--tag-color);
  color: var(--bg);
}

.tag-remove {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

.article-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 1rem 0;
}

.add-tag-form {
  display: inline-flex;
  gap: 0.3rem;
}

.add-tag-form input {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  width: 8rem;
}

.tag-manage-list {
  list-style: none;
  padding: 0;
}

.tag-manage-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

/* Rules */

.rule-list {
  list-style: none;
  padding: 0;
}

.rule-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.rule-row.is-disabled {
  opacity: 0.5;
}

.rule-summary {
  font-size: 0.85rem;
  opacity: 0.75;
}

.rule-actions {
  display: flex;
  gap: 0.35rem;
}

/* Search */

.search-form {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}

.search-form input {
  flex: 1;
}

/* Subscriptions */

.subscription-list {
  list-style: none;
  padding: 0;
}

.subscription-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

/* Dashboard */

.dashboard-stats {
  list-style: none;
  padding: 0;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.feed-error-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.feed-error-table th,
.feed-error-table td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

@media (max-width: 760px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .article-feed-name {
    display: none;
  }

  .stream-toolbar .inline-form {
    margin-left: 0;
  }
}
