/* FeedFilters — a single stylesheet for the whole app.
   CSS custom properties for colors; dark-mode override via prefers-color-scheme.
   No build step: served straight from the embedded static FS. */

:root {
  --bg: #ffffff;
  --fg: #222222;
  --fg-muted: #666666;
  --fg-faint: #999999;
  --border: #dddddd;
  --border-subtle: #eeeeee;
  --link: #0b6bcb;
  --link-hover: #094b93;
  --error: #b30000;
  --error-bg: #fbe9e9;
  --success: #0a6a2a;
  --success-bg: #e9f6ed;
  --warning-bg: #fff6d9;
  --warning-border: #d3c16a;
  --chip-bg: #eef1fa;
  --chip-border: #c4cde7;
  --chip-except-bg: #fde9e9;
  --chip-except-border: #d9b5b5;
  --card-bg: #ffffff;
  --button-bg: #f5f5f5;
  --button-fg: #222;
  --button-border: #c8c8c8;
  --button-hover-bg: #ececec;
  --button-danger-bg: #b30000;
  --button-danger-fg: #ffffff;
  --input-bg: #ffffff;
  --input-border: #b8b8b8;
  --input-focus: #0b6bcb;
  --code-bg: #f3f3f3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);

  /* Fixed control height so .btn (text + icon-only) line up cleanly
     side-by-side. Sized to roughly match what padding-driven buttons
     used to render at, so this doesn't visibly shift other pages. */
  --btn-h: 2.4rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --fg: #e6e6e6;
    --fg-muted: #9aa0a8;
    --fg-faint: #6c737b;
    --border: #2d3139;
    --border-subtle: #23262c;
    --link: #6aa9ff;
    --link-hover: #9bc6ff;
    --error: #ff7070;
    --error-bg: #3a1a1a;
    --success: #7ed58c;
    --success-bg: #152a1d;
    --warning-bg: #3a3219;
    --warning-border: #6a5d30;
    --chip-bg: #212739;
    --chip-border: #354161;
    --chip-except-bg: #2f1f1f;
    --chip-except-border: #5a3838;
    --card-bg: #1b1e24;
    --button-bg: #23262c;
    --button-fg: #e6e6e6;
    --button-border: #3a3f48;
    --button-hover-bg: #2e323a;
    --button-danger-bg: #9a2020;
    --button-danger-fg: #ffffff;
    --input-bg: #1a1d23;
    --input-border: #3a3f48;
    --input-focus: #6aa9ff;
    --code-bg: #1a1d23;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  line-height: 1.5;
}

body {
  padding: 2.5rem 1rem 4rem;
}

.page {
  max-width: 40rem;
  margin: 0 auto;
}

h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h1.breadcrumbs { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.4rem; font-size: 1.4rem; }
h1.breadcrumbs a { color: var(--link); }
h1.breadcrumbs .crumb-sep { color: var(--fg-faint); font-weight: 400; }

.breadcrumb-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0 0 1rem;
}
.breadcrumb-row h1.breadcrumbs { margin: 0; }
.breadcrumb-row .crumb-edit {
  font-size: 0.85rem;
  /* Reset button-element defaults so a <button class="crumb-edit"> renders
     identically to an <a class="crumb-edit">. The bulk-edit toggle uses
     a button (it fires JS, not a navigation), but the folder-edit link is
     a real anchor. */
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-weight: inherit;
  color: var(--link);
  cursor: pointer;
}
.breadcrumb-row .crumb-edit:hover { color: var(--link-hover); text-decoration: underline; }
h2 { font-size: 1.2rem; margin: 2rem 0 0.5rem; }
h3 { font-size: 1rem; margin: 1.5rem 0 0.5rem; }

p { margin: 0.5rem 0; }

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

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--code-bg);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  word-break: break-all;
}

hr { border: 0; border-top: 1px solid var(--border-subtle); margin: 2rem 0; }

/* ---------- Nav ---------- */

nav.topbar {
  margin-bottom: 2rem;
  font-size: 0.9rem;
  color: var(--fg-muted);
  display: flex;
  gap: 1.5rem;
  align-items: baseline;
  flex-wrap: wrap;
  width: 100%;
}

nav.topbar a { color: var(--link); }

nav.topbar .topbar-right {
  margin-left: auto;
  display: flex;
  gap: 1.5rem;
  align-items: baseline;
  flex-wrap: wrap;
}

nav.topbar form { display: inline; margin: 0; }
nav.topbar form button {
  padding: 0.1rem 0.5rem;
  font: inherit;
  font-size: 0.85rem;
}

nav.topbar button.linklike {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: inherit;
  color: var(--link);
  cursor: pointer;
}
nav.topbar button.linklike:hover {
  background: none;
  color: var(--link-hover);
  text-decoration: underline;
}

/* ---------- Admin sidebar layout ----------
   Admin pages render with a left sidebar inside a wider .page wrapper
   so tables of users / metrics charts have room to breathe. The
   default 40rem column is kept for everything else. The sidebar
   collapses above the content on narrow screens. */

body.has-sidebar .page.admin-page { max-width: 70rem; }

.admin-shell {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}
.admin-sidebar {
  flex: 0 0 12rem;
  position: sticky;
  top: 1rem;
  font-size: 0.95rem;
}
.admin-sidebar h2 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
}
.admin-sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 1px solid var(--border-subtle);
}
.admin-sidebar li { margin: 0; }
.admin-sidebar a {
  display: block;
  padding: 0.4rem 0.75rem;
  color: var(--fg);
  border-left: 2px solid transparent;
  margin-left: -1px;
}
.admin-sidebar a:hover { background: var(--button-hover-bg); text-decoration: none; }
.admin-sidebar a.active {
  color: var(--link);
  border-left-color: var(--link);
  background: color-mix(in srgb, var(--link) 8%, transparent);
}
.admin-main { flex: 1 1 auto; min-width: 0; }

@media (max-width: 50rem) {
  .admin-shell { flex-direction: column; gap: 1rem; }
  .admin-sidebar {
    position: static;
    flex: none;
    width: 100%;
  }
  .admin-sidebar ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    border-left: none;
  }
  .admin-sidebar a {
    border-left: none;
    border-bottom: 2px solid transparent;
    padding: 0.3rem 0.6rem;
    margin-left: 0;
  }
  .admin-sidebar a.active {
    border-left-color: transparent;
    border-bottom-color: var(--link);
  }
}

/* ---------- Forms ---------- */

form { margin: 1rem 0; }

label {
  display: block;
  margin: 0.75rem 0 0.25rem;
  font-size: 0.95rem;
}
label.radio { margin: 0.25rem 0; }
label.radio input { margin-right: 0.25rem; }

input[type="email"],
input[type="password"],
input[type="text"],
input[type="url"],
input[type="file"],
select,
textarea {
  display: block;
  width: 100%;
  padding: 0.5rem;
  font: inherit;
  color: var(--fg);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--input-focus) 25%, transparent);
}

/* Default rule for both <button> and .btn: visual chrome (color,
   background, border, radius). Sizing differs by use case below —
   plain <button> stays padding-driven so chip-remove and other
   inline buttons don't get stretched to control height; .btn pins
   to a fixed height so toolbar buttons line up cleanly. */
button,
.btn {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  font: inherit;
  color: var(--button-fg);
  background: var(--button-bg);
  border: 1px solid var(--button-border);
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--btn-h);
  box-sizing: border-box;
  padding: 0 0.9rem;
}
button:hover, .btn:hover { background: var(--button-hover-bg); text-decoration: none; }

button[disabled] { opacity: 0.5; cursor: not-allowed; }

button.danger {
  color: var(--button-danger-fg);
  background: var(--button-danger-bg);
  border-color: transparent;
}

form > button { margin-top: 1rem; }

form.inline { display: inline; margin: 0; }
form.inline button { padding: 0.1rem 0.5rem; margin-top: 0; }

.hint {
  color: var(--fg-muted);
  font-size: 0.9em;
  margin-top: 0.25rem;
}

/* The two except-tag hints in feeds_edit.html have parallel copy for
   the two filter modes. Show only the one matching the active radio
   via :has() so the description stays accurate when the user flips
   between modes without saving. */
.hint-include, .hint-exclude { display: none; }
form:has(input[name="filter_mode"][value="include"]:checked) .hint-include { display: block; }
form:has(input[name="filter_mode"][value="exclude"]:checked) .hint-exclude { display: block; }

/* ---------- Status messages ---------- */

.error {
  color: var(--error);
  background: var(--error-bg);
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  border: 1px solid color-mix(in srgb, var(--error) 40%, transparent);
}
.info {
  color: var(--success);
  background: var(--success-bg);
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  border: 1px solid color-mix(in srgb, var(--success) 40%, transparent);
}

/* ---------- Chips ---------- */

.chip {
  display: inline-block;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 3px;
  padding: 0.05rem 0.45rem;
  margin: 0.05rem 0.1rem;
  font-size: 0.9em;
}
.chip.except {
  background: var(--chip-except-bg);
  border-color: var(--chip-except-border);
}
.chip-remove {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  padding: 0 0.15rem;
  font: inherit;
}

/* ---------- Feed list cards ---------- */

.feed-list { list-style: none; padding: 0; margin: 0; }
.feed-card {
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.75rem;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  flex-wrap: wrap;
}
.feed-card .feed-main { flex: 1 1 18rem; min-width: 0; }
.feed-card .feed-title {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  word-break: break-word;
}
.feed-card .feed-icon {
  width: 24px;
  height: 24px;
  border-radius: 3px;
  flex: none;
}
.feed-card .feed-desc { color: var(--fg-muted); margin-top: 0.25rem; }

/* Folder cards reuse .feed-card layout but pick up a subtly cooler
   background and a softer border to read as "containers" rather than
   "leaves" in the list. The tint scales with the theme so the
   difference is similar in light and dark. */
.feed-card.folder-card {
  background: color-mix(in srgb, var(--fg-muted) 6%, var(--card-bg));
  border-color: color-mix(in srgb, var(--fg-muted) 25%, var(--border));
}
.feed-card.folder-card .feed-title a { color: var(--fg); font-weight: 600; }
.feed-card.folder-card .feed-title a:hover { color: var(--link); }
.feed-card.folder-card .folder-icon { font-size: 1.1rem; }
.feed-card .feed-actions {
  display: flex;
  gap: 0.25rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
/* Global filter summary card: shaped like a feed-card so it sits
   naturally above the list, but differentiated with a tinted
   background and a left accent stripe so it doesn't read as just
   another feed. Editing happens on /global-filter/edit; the card
   itself is read-only. */
.feed-card.global-filter-card {
  background: color-mix(in srgb, var(--link) 6%, var(--card-bg));
  border-left: 3px solid var(--link);
}

/* Per-row checkboxes are part of "selection mode", toggled on by the
   toolbar's checkbox-button via body.edit-mode. Hidden by default so
   no-JS users (and the normal browse view) get the clean layout.
   Bumped from the browser default (~13px) so the hit target is
   comfortable on touch and in dense-list mouse use. */
.bulk-check { display: none; }
body.edit-mode .feed-card .bulk-check {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.3rem;
  flex: none;
  align-self: flex-start;
  cursor: pointer;
}

/* Toolbar swaps content based on selection mode: default toolbar
   (Add Feed / Add Folder / OPML) hides; the edit toolbar (Move /
   Delete) shows. The checkbox-toggle button stays put on the left
   in both states and gains a blue background when active so the
   mode is unmistakable. */
body.edit-mode .js-toolbar-default { display: none; }
body:not(.edit-mode) .js-toolbar-edit { display: none; }

/* Square button hosting the checkbox icon — width matches the .btn
   fixed height so the toggle is a clean square that lines up with
   the rest of the toolbar. The SVG has no intrinsic size, so an
   explicit width/height on .icon is required — otherwise the browser
   falls back to the default replaced-element box (300×150). */
.btn-edit-toggle {
  width: var(--btn-h);
  padding: 0;
}
.btn-edit-toggle .icon {
  width: 18px;
  height: 18px;
  display: block;
}
body.edit-mode .btn-edit-toggle {
  background: var(--link);
  border-color: var(--link);
  color: #fff;
}

/* Hide the global filter card while in selection mode — focus
   should be on the move/delete affordances, not unrelated chrome. */
body.edit-mode .global-filter-card { display: none; }

/* Icon-only action buttons used in feed/folder rows. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: var(--fg-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease;
}
.icon-btn:hover {
  color: var(--fg);
  background: var(--button-hover-bg);
  border-color: var(--button-border);
  text-decoration: none;
}
.icon-btn:focus-visible {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--input-focus) 25%, transparent);
}
.icon-btn.danger {
  color: var(--fg-muted);
  background: transparent;
  border-color: transparent;
}
.icon-btn.danger:hover {
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 35%, transparent);
  background: color-mix(in srgb, var(--error) 10%, transparent);
}
.icon-btn .icon {
  width: 16px;
  height: 16px;
  display: block;
  flex: none;
}
.icon-btn.copy-url .icon-done { display: none; }
.icon-btn.copy-url.copied {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  background: color-mix(in srgb, var(--success) 12%, transparent);
}
.icon-btn.copy-url.copied .icon-default { display: none; }
.icon-btn.copy-url.copied .icon-done { display: block; }
/* The error / paused banners live as direct children of .feed-card
 * (a flex+wrap container). flex-basis: 100% drops them onto a new
 * line so the message takes the full card width — no fighting with
 * .feed-actions for horizontal space. */
.feed-error,
.feed-paused {
  flex-basis: 100%;
  margin-top: 0.4rem;
  font-size: 0.9em;
}
.feed-error {
  color: var(--error);
}
.feed-paused {
  color: var(--muted);
}
.feed-paused em {
  color: var(--text);
  font-style: normal;
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  margin-left: 0.5rem;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}
.link-btn:hover { text-decoration: none; }

/* ---------- OPML review tree ---------- */

ul.opml-tree {
  list-style: none;
  padding-left: 1.25rem;
  margin: 0.25rem 0;
}
ul.opml-tree > li.opml-folder { margin: 0.5rem 0; }
ul.opml-tree > li.opml-feed { margin: 0.15rem 0; }
.opml-folder-row { display: flex; align-items: center; gap: 0.4rem; }
.opml-feed-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.opml-feed-main { flex: 1; min-width: 0; }

/* ---------- Tables ---------- */

table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5rem 0;
}
th, td {
  padding: 0.35rem 0.5rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border-subtle);
}
thead tr { border-bottom: 1px solid var(--border); }

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 3px;
  font-size: 0.85em;
  border: 1px solid transparent;
}
.badge.new {
  color: var(--success);
  background: var(--success-bg);
  border-color: color-mix(in srgb, var(--success) 40%, transparent);
}
.badge.duplicate {
  background: var(--warning-bg);
  border-color: var(--warning-border);
}
.badge.admin {
  background: color-mix(in srgb, var(--link) 14%, transparent);
  border-color: color-mix(in srgb, var(--link) 45%, transparent);
  color: var(--link);
}
.badge.verified {
  color: var(--success);
  background: var(--success-bg);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
}
.badge.unverified {
  background: var(--warning-bg);
  border-color: var(--warning-border);
}
.badge.passkey, .badge.self {
  background: var(--chip-bg);
  border-color: var(--chip-border);
  color: var(--fg-muted);
}
.badge.paused {
  background: var(--warning-bg);
  border-color: var(--warning-border);
}
.badge.error {
  color: var(--error);
  background: var(--error-bg);
  border-color: color-mix(in srgb, var(--error) 35%, transparent);
}

/* ---------- Admin users page ---------- */

.admin-users-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.75rem;
  margin: 1rem 0;
}
.admin-users-controls input[type="search"] {
  flex: 1 1 18rem;
  min-width: 12rem;
}
.admin-users-controls label {
  margin: 0;
  font-size: 0.85rem;
  color: var(--fg-muted);
}
.admin-users-controls select { min-width: 9rem; }
.admin-users-controls button { margin: 0; }

.admin-users-table .badge { margin-right: 0.25rem; }

.pager {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  margin: 1.5rem 0;
}

/* User detail page */
.user-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  margin: 1rem 0;
}
.user-meta {
  display: grid;
  grid-template-columns: 8rem 1fr;
  gap: 0.4rem 1rem;
  margin: 0;
}
.user-meta dt {
  color: var(--fg-muted);
  font-size: 0.85rem;
}
.user-meta dd { margin: 0; }
.user-meta dd .badge { margin-right: 0.25rem; }

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
}
.user-actions .inline-form { margin: 0; }
.user-actions .inline-form button { margin: 0; }

.admin-user-feeds td.break-all { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

@media (max-width: 32rem) {
  .user-meta { grid-template-columns: 1fr; gap: 0.1rem; }
  .user-meta dt { margin-top: 0.5rem; }
}

/* ---------- Utility ---------- */

.row-gap { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.muted { color: var(--fg-muted); font-size: 0.9em; }
.break-all { word-break: break-all; }

/* ---------- Small screens ---------- */

@media (max-width: 28rem) {
  body { padding: 1.5rem 0.75rem 3rem; }
  h1 { font-size: 1.35rem; }
  .feed-card { flex-direction: column; }
  .feed-card .feed-actions { width: 100%; justify-content: flex-start; }
}
