:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1c2230;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #2f4a8a;
  --accent-ink: #ffffff;
  --ok: #1a7f4b;
  --warn: #b45309;
  --danger: #b42318;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }

/* top bar */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar .wrap { display: flex; align-items: center; gap: 18px; height: 58px; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 16px; }
.topbar nav a { color: var(--muted); font-weight: 500; }
.topbar nav a:hover { color: var(--ink); text-decoration: none; }
.spacer { flex: 1; }
.inline { display: inline; margin: 0; }

main.wrap { padding-top: 24px; padding-bottom: 40px; }
h1 { font-size: 1.5rem; margin: 0 0 18px; }
h2 { font-size: 1.05rem; margin: 22px 0 10px; }

/* buttons */
.btn {
  display: inline-block; cursor: pointer;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; font-size: 0.9rem; font-weight: 500;
  font-family: inherit;
}
.btn:hover { border-color: #c9cfda; text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: #263c73; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 0.82rem; }
.btn.tiny { padding: 4px 9px; font-size: 0.78rem; }
.btn.danger { color: var(--danger); border-color: #f0c8c4; }
.btn.danger:hover { background: #fdf3f2; }
summary.btn { list-style: none; }
summary::-webkit-details-marker { display: none; }
.link { cursor: pointer; color: var(--accent); font-size: 0.85rem; }

/* flashes */
.flashes { margin-bottom: 18px; display: grid; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 8px; font-size: 0.9rem; border: 1px solid; }
.flash.ok { background: #eaf6ef; border-color: #bfe3ce; color: var(--ok); }
.flash.err { background: #fdeeec; border-color: #f3cdc8; color: var(--danger); }

/* filter bar */
.filterbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.counts { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 0.82rem; color: var(--muted); }
.pill b { color: var(--ink); }
.pill.on { border-color: var(--accent); color: var(--accent); }
.pill.clear, .pill.on.clear { color: var(--danger); }
.feedfilter select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-family: inherit; }

/* table */
table.issues { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.issues th, table.issues td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); }
table.issues th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: #fafbfc; }
table.issues tr:last-child td { border-bottom: none; }
table.issues tr:hover td { background: #fafbfc; }
.issue-cell a { font-weight: 600; }
.actions { text-align: right; white-space: nowrap; }
.actions .btn { margin-left: 4px; }
.check .ok, .check .warn { font-weight: 700; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.74rem; font-weight: 600; }
.badge.ready { background: #eaf6ef; color: var(--ok); }
.badge.validation_warning { background: #fdf2e6; color: var(--warn); }
.badge.queued, .badge.downloading, .badge.downloaded, .badge.converting { background: #eef2fb; color: var(--accent); }
.badge.failed { background: #fdeeec; color: var(--danger); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* empty state */
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 40px; text-align: center; }

/* cards & forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 4px; font-size: 0.85rem; font-weight: 600; }
.form input { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 0.92rem; font-family: inherit; }
.form input:focus { outline: none; border-color: var(--accent); }
.form small { font-weight: 400; color: var(--muted); }
.form .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check-inline { flex-direction: row; align-items: center; gap: 8px; display: flex; }
.addform { margin-bottom: 20px; }
.addform > summary { display: inline-block; }
.addform[open] > summary { margin-bottom: 12px; }

/* feed cards */
.feed .feed-top { display: flex; justify-content: space-between; align-items: center; }
.feed-name { font-weight: 700; font-size: 1.02rem; }
.feed-url { margin: 4px 0; word-break: break-all; }
.feed-meta { margin-bottom: 8px; }
.feed details { margin-top: 6px; }

/* issue detail */
.issue-head { margin-bottom: 18px; }
.issue-head h1 { margin-bottom: 8px; }
.meta { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.note { padding: 8px 12px; border-radius: 8px; font-size: 0.85rem; margin-top: 10px; }
.note-ok { background: #eaf6ef; color: var(--ok); }
.note-warn { background: #fdf2e6; color: var(--warn); }
.content {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 36px; max-width: 820px; font-size: 1.03rem;
}
.content h1 { font-size: 2rem; font-weight: 800; line-height: 1.18; margin: 0.1em 0 0.5em; letter-spacing: -0.01em; }
.content h2 { font-size: 1.6rem; font-weight: 700; line-height: 1.22; margin: 1.55em 0 0.4em; letter-spacing: -0.01em; }
.content h2:first-child { margin-top: 0; }
.content h3 { font-size: 1.2rem; font-weight: 700; line-height: 1.35; margin: 1.2em 0 0.3em; }
.content p { margin: 0 0 0.95em; line-height: 1.72; }
.content img { max-width: 100%; }
.content table { border-collapse: collapse; }
.content table td, .content table th { border: 1px solid var(--line); padding: 5px 9px; }
pre.plain { white-space: pre-wrap; word-wrap: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

.foot { margin-top: 30px; padding: 20px 0; border-top: 1px solid var(--line); font-size: 0.82rem; }

@media (max-width: 640px) {
  .form .grid2 { grid-template-columns: 1fr; }
  table.issues th:nth-child(2), table.issues td:nth-child(2),
  table.issues th:nth-child(5), table.issues td:nth-child(5) { display: none; }
}

/* login */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 360px; margin: 0; }
.login-brand {
  font-weight: 700; font-size: 1.25rem; text-align: center;
  margin-bottom: 18px;
}

/* structuring UI */
.form textarea {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 0.9rem; font-family: inherit; resize: vertical; width: 100%;
}
.form textarea:focus { outline: none; border-color: var(--accent); }
.form textarea.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem; line-height: 1.45;
}
.ai-badge { margin-left: 6px; font-size: 0.85rem; cursor: default; }
.ai-badge.warn { color: var(--warn); }

/* feed filter preview */
.preview-row { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.preview-result:not(:empty) {
  margin-top: 8px; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
}
.preview-head { margin-bottom: 6px; }
.preview-list { list-style: none; margin: 4px 0 0; padding: 0; font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.preview-list li { padding: 2px 0; line-height: 1.4; }
.preview-list.match li { color: var(--ok); }
.preview-list.nomatch li { color: var(--muted); }
.preview-list .muted { color: var(--muted); }
.preview-unmatched { margin-top: 8px; }
.preview-unmatched summary { cursor: pointer; }

/* failure reason under the Failed badge */
.fail-reason { color: var(--warn); margin-top: 4px; line-height: 1.35; max-width: 260px; }
