:root {
  --bg: #f6f7f9;
  --fg: #1c1e21;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #1f6feb;
  --accent-hover: #1a5fd0;
  --accent-fg: #ffffff;
  --error: #b42318;
  --card: #ffffff;

  /* Form-control system (see the "Form controls" block below): one height, one radius and one focus ring
     for every input, select, textarea and button, so nothing has to be sized per page. */
  --control-h: 2.25rem;
  --control-h-sm: 1.75rem;
  --radius: 8px;
  --radius-sm: 6px;
  --focus: 0 0 0 3px rgba(31, 111, 235, 0.18);
  --control-bg: #ffffff;
  --control-border: #d0d5dd;
  --control-border-hover: #98a2b3;
  --placeholder: #98a2b3;
  --danger: var(--error);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 600; color: var(--fg); }
.topbar .topnav { margin: 0 0 0 2rem; }
.topbar .logout { margin: 0; }
.topbar .lang { margin: 0 0 0 auto; font-size: 0.85rem; }
.topbar .lang a { margin-right: 0.5rem; }
.topbar .lang a:last-child { margin-right: 1.25rem; }
.topbar nav a { color: var(--muted); margin-right: 1.25rem; }
.topbar nav a:last-child { margin-right: 0; }
.topbar nav a:hover { color: var(--fg); }
.topbar nav a.active { color: var(--fg); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.25rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--error); }
.crumbs { margin-bottom: 0.5rem; color: var(--muted); }

.tabs {
  display: flex;
  gap: 1.5rem;
  margin: 0.5rem 0 1.25rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.tabs a {
  display: inline-block;
  padding: 0.1rem 0.1rem 0.6rem;
  margin-bottom: -1px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--fg); text-decoration: none; }
.tabs a.active { color: var(--fg); font-weight: 600; border-bottom-color: var(--accent); }

.hint {
  display: block;
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ===========================================================================
   Form controls
   ---------------------------------------------------------------------------
   One look for every interactive element, defined once and applied by element
   selectors. A template needs a class only for a variant: .btn-secondary,
   .btn-danger, .btn-sm (small buttons), .input-sm (small inputs), button.link
   (a button that reads as a link).
   =========================================================================== */

/* --- Text-like inputs, selects and textareas ------------------------------ */
/* One :not() with a selector list, not a chain of them: the chain would outrank .input-sm and every
   per-area override below, since :not() takes the specificity of its argument. */
input:not([type="checkbox"], [type="radio"], [type="file"], [type="hidden"], [type="submit"], [type="button"]),
select,
textarea {
  font: inherit;
  font-size: 0.9rem;
  color: var(--fg);
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  height: var(--control-h);
  max-width: 100%;
  padding: 0 0.7rem;
  line-height: 1.3;
  box-shadow: none;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}

input:not([type="checkbox"], [type="radio"], [type="file"], [type="hidden"], [type="submit"], [type="button"]):hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) { border-color: var(--control-border-hover); }

input:not([type="checkbox"], [type="radio"], [type="file"], [type="hidden"], [type="submit"], [type="button"]):focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--focus);
}

input:disabled, select:disabled, textarea:disabled {
  background: var(--bg);
  color: var(--muted);
  cursor: not-allowed;
}

/* Only after the field has been interacted with, so a required field is not red before it is filled. */
input:user-invalid, select:user-invalid, textarea:user-invalid { border-color: var(--danger); }

::placeholder { color: var(--placeholder); opacity: 1; }

textarea {
  height: auto;
  min-height: 5.5rem;
  padding: 0.55rem 0.7rem;
  resize: vertical;
}

/* Select: the browser's own arrow is replaced by an inline chevron, so the control keeps the input height. */
select {
  appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%2398a2b3' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
}

/* Date pickers keep their native icon; they only need room for it. */
input[type="date"], input[type="datetime-local"], input[type="time"] { min-width: 12rem; }

/* File: the input itself is not a box, its button is. */
input[type="file"] {
  font-size: 0.85rem;
  color: var(--fg);
  max-width: 100%;
}
input[type="file"]::file-selector-button {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  height: var(--control-h-sm);
  padding: 0 0.7rem;
  margin-right: 0.6rem;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  background: var(--control-bg);
  color: var(--fg);
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover { border-color: var(--control-border-hover); }
input[type="file"]:disabled::file-selector-button { background: var(--line); color: var(--muted); cursor: not-allowed; }

input[type="checkbox"], input[type="radio"] {
  appearance: auto;
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
  vertical-align: -0.15rem;
  margin: 0 0.4rem 0 0;
}

/* --- Buttons -------------------------------------------------------------- */
/* .btn and .btn-sm are here too: both are worn by links that have to read as buttons
   (the Article link on the post page, the Open links in the posts table). */
button, .btn, .btn-sm, input[type="submit"] {
  height: var(--control-h);
  padding: 0 1rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
button:hover:not(:disabled), .btn:hover, .btn-sm:hover, input[type="submit"]:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-fg);
  text-decoration: none;
}
button:focus-visible, .btn:focus-visible, .btn-sm:focus-visible, input[type="submit"]:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}
button:disabled, .btn:disabled, .btn-sm:disabled, input[type="submit"]:disabled {
  background: var(--line);
  border-color: var(--line);
  color: var(--muted);
  cursor: not-allowed;
}

/* Quiet button: the default for anything that is not the primary action of its row. */
.btn-secondary {
  background: var(--control-bg);
  border-color: var(--control-border);
  color: var(--fg);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--control-bg);
  border-color: var(--control-border-hover);
  color: var(--fg);
}
.btn-secondary:disabled { background: var(--line); border-color: var(--line); color: var(--muted); }

/* Destructive button: Reject, Remove, Delete, Clear, Log out. */
.btn-danger {
  background: var(--control-bg);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: #fdecea;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:disabled { background: var(--line); border-color: var(--line); color: var(--muted); }

/* Small size: buttons that sit inside table rows and picture cards. */
.btn-sm {
  height: var(--control-h-sm);
  padding: 0 0.65rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}
.btn-sm:hover { text-decoration: none; }

/* A button that reads as a link (the Test buttons on Settings -> AI, Log out in the top bar). */
button.link {
  height: auto;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: inherit;
  font-size: inherit;
  display: inline;
}
button.link:hover:not(:disabled) { background: none; color: var(--accent); text-decoration: underline; }
button.link:disabled { background: none; color: var(--muted); }
button.link:focus-visible { outline: none; border-radius: var(--radius-sm); box-shadow: var(--focus); }

/* Small size of the input system, the counterpart of .btn-sm. Element-qualified so it outranks the
   base control rule above. */
input.input-sm, select.input-sm, textarea.input-sm, .input-sm {
  height: var(--control-h-sm);
  font-size: 0.8rem;
  padding: 0 0.5rem;
  min-width: 9rem;
}
input.input-sm.input-wide, .input-sm.input-wide { min-width: 16rem; }

/* --- Labels and block forms ----------------------------------------------- */
/* Every label in a form is a caption above its control; the control below it fills the form column. */
form label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.25rem;
}
form label:has(> input[type="checkbox"]), form label:has(> input[type="radio"]) {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
form label > input[type="checkbox"], form label > input[type="radio"] { margin-right: 0; }

label > input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="submit"], [type="button"]),
label > select,
label > textarea {
  display: block;
  width: 100%;
  max-width: 34rem;
  margin-top: 0.3rem;
}
/* Fields whose content has a natural length keep it instead of stretching to the form column. */
form label > input[type="number"],
form label > input[type="date"],
form label > input[type="datetime-local"],
form label > input[type="time"] { width: auto; }
input[type="number"] { min-width: 6rem; }

/* One field per row: whatever follows a finished field starts the next one. */
form label + label,
form .hint + label,
form label + button,
form label + .btn,
form label + input[type="submit"],
form .hint + button,
form .hint + .btn,
form .hint + input[type="submit"] { margin-top: 0.9rem; }
form > section + button, form > table + button { margin-top: 1rem; }
section > form + form, main > form + form { margin-top: 1rem; }

/* --- Rows of controls ----------------------------------------------------- */
.inline-form { display: inline-flex; align-items: center; gap: 0.5rem; margin: 0; flex-wrap: wrap; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.actions form { display: inline-flex; align-items: center; gap: 0.5rem; margin: 0; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.5rem 0 1rem; }
.row-actions { flex-direction: column; align-items: flex-start; gap: 0.4rem; }
.row-actions-line { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

/* Controls that live in a table cell or on a picture card: small size, laid out in one line. */
td > form, .frame-body form {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0.4rem 0.4rem 0;
}
.frame-body form { margin: 0.35rem 0.35rem 0 0; }
td > form input:not([type="checkbox"], [type="hidden"]),
td > form select,
.frame-body input:not([type="checkbox"], [type="hidden"]) {
  height: var(--control-h-sm);
  font-size: 0.8rem;
  padding: 0 0.5rem;
  min-width: 8rem;
}
.frame-body input:not([type="checkbox"], [type="hidden"]) { flex: 1 1 8rem; min-width: 0; }
td > form button, .frame-body form button { height: var(--control-h-sm); padding: 0 0.65rem; font-size: 0.8rem; }

/* --- details / summary ---------------------------------------------------- */
details {
  margin: 0.75rem 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
details summary {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.15rem 0;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
  list-style: none;
}
details summary::-webkit-details-marker { display: none; }
details summary::before {
  content: "";
  flex: none;
  width: 0.4rem;
  height: 0.4rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
}
details[open] > summary::before { transform: rotate(45deg); }
details summary:hover { color: var(--fg); }
details summary:focus-visible { outline: none; border-radius: var(--radius-sm); box-shadow: var(--focus); }
details[open] > summary { margin-bottom: 0.5rem; color: var(--fg); }
details form { margin-top: 0.35rem; }
details textarea[name="html"] {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.85rem;
  max-width: none;
}

/* "About this page" note under the site tab strip: collapsed by default, one sentence or three when open */
.page-help { margin: 0.5rem 0 1rem; font-size: 0.9rem; }
.page-help .help-icon {
  display: inline-flex;
  width: 1.1rem;
  height: 1.1rem;
  align-items: center;
  justify-content: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 600;
}
.page-help p { margin: 0.5rem 0 0; max-width: 60rem; color: var(--muted); }

/* Inline "Edit" inside a table row */
.row-edit summary { font-size: 0.8rem; }

.truncate {
  display: inline-block;
  max-width: 32rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* Background-operation indicator (docs/pipeline.md section 3): a CSS-only spinner next to the
   "<Kind>..." label, shown in the action fragments while an operation is RUNNING. */
.actions-running {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
/* A spinner used as an htmx request indicator (the Upload button in fragments/article-images.html). htmx's own
   rule only fades .htmx-indicator out, which would leave our fixed-size spinner holding a gap while idle. */
.spinner.htmx-indicator { display: none; }
.htmx-request .spinner.htmx-indicator,
.spinner.htmx-indicator.htmx-request { display: inline-block; }

.flash {
  max-width: 1100px;
  margin: 1rem auto 0;
  padding: 0.6rem 1rem;
  border: 1px solid #b7e0c0;
  background: #eaf7ee;
  border-radius: var(--radius-sm);
}
.flash-error {
  border-color: #f0b4ae;
  background: #fdecea;
  color: var(--error);
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.card h2 { margin-top: 0; }
.card .actions { margin-top: 0.75rem; padding-top: 0.5rem; border-top: 1px solid var(--line); }

.stats { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0.5rem 0; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; }

.tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--line);
  font-size: 0.8rem;
  margin-right: 0.25rem;
}
.filters .tag { cursor: pointer; margin-right: 0; }
.filters .tag.active { background: var(--accent); color: var(--accent-fg); }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); }
th, td { text-align: left; padding: 0.5rem 0.65rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #fafbfc; font-weight: 600; }

.toolbar { margin-bottom: 1rem; }
.toolbar > form { display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem; margin-bottom: 0.5rem; }

.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-box {
  width: min(360px, 90vw);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
}

/* Settings -> AI (role bindings) and Settings -> QA (rule values): dense tables of controls. */
.roles-table td { vertical-align: middle; }
.roles-table label { display: inline; font-size: inherit; color: inherit; margin: 0; }
.roles-table input:not([type="checkbox"]), .roles-table select {
  height: var(--control-h-sm);
  font-size: 0.8rem;
  padding: 0 0.5rem;
  width: 100%;
  min-width: 10rem;
}
.roles-table select { padding-right: 1.9rem; background-position: right 0.45rem center; }
.roles-table input[type="number"] { min-width: 6rem; width: auto; }

/* Site -> Profile: every field is free text, and the lists (unique facts, compliance rules) are one sentence
   per line, so the inputs need real width instead of the browser's default 20 columns. */
.profile-form label > input, .profile-form label > textarea { max-width: 56rem; }
.profile-form .hint { max-width: 56rem; }
.profile-form button { margin-top: 1rem; }

.test-result { margin-top: 0.35rem; font-size: 0.85rem; }
.test-result.test-ok { color: #1a7f37; }
.test-result.test-fail { color: var(--error); }

.submit-forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.5rem; margin-top: 0.75rem; }
.submit-forms form, .submit-forms .note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.submit-forms form h3:first-child, .submit-forms .note h3:first-child { margin-top: 0; }

/* The credential of one search source, entered inside that source's own card. */
.credential { margin-top: 1rem; }
.credential form + form { margin-top: 1rem; }

/* Post detail page */
.post-video {
  display: block;
  width: 100%;
  max-width: 720px;
  margin: 0.75rem 0;
  background: #000;
  border-radius: var(--radius);
}

.actions-bar { margin: 0.75rem 0 1.5rem; }
.actions-bar h2 { margin: 0 0 0.5rem; }

.score-bar {
  display: inline-block;
  vertical-align: middle;
  width: 160px;
  height: 10px;
  margin-right: 0.5rem;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.score-bar > span { display: block; height: 100%; background: var(--accent); }

.frames-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin: 0.75rem 0 1.5rem; }
.frame-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.frame-card img { display: block; width: 100%; height: 150px; object-fit: cover; background: var(--line); }
.frame-card .frame-body { padding: 0.5rem 0.75rem; font-size: 0.85rem; }
.frame-card .frame-body > div { margin-bottom: 0.15rem; }

.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.75rem; margin-left: 0.35rem; }
.badge-hero { background: var(--accent); color: var(--accent-fg); }
.badge-inline { background: var(--line); color: var(--fg); }
.badge-media { background: var(--line); color: var(--muted); }
.badge-photo { background: #eaf7ee; color: #1a7f37; }

/* Post detail: media section (video players and photo gallery for multi-item posts) */
.media-videos, .media-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin: 0.75rem 0 1.5rem; }
.media-video-card, .media-photo-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.media-video-card .post-video { max-width: 100%; margin: 0; border-radius: 0; }
.media-photo-card img { display: block; width: 100%; height: 180px; object-fit: cover; background: var(--line); }
.media-caption { padding: 0.5rem 0.75rem; font-size: 0.85rem; }
.media-caption p { margin: 0; }

/* Post detail: per-video analysis breakdown */
.analysis-part { padding: 0.5rem 0; border-top: 1px solid var(--line); }
.analysis-part:first-child { padding-top: 0; border-top: none; }
.analysis-part h4 { margin: 0 0 0.25rem; font-size: 0.95rem; }
.analysis-part p { margin: 0.25rem 0; }

/* Article detail: rendered draft preview */
.preview {
  display: block;
  max-width: 100%;
  margin: 0.75rem 0 1.25rem;
  padding: 1rem 1.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.preview h1, .preview h2, .preview h3 { margin-top: 1.25rem; }
.preview h1:first-child, .preview h2:first-child, .preview h3:first-child { margin-top: 0; }
.preview p { margin: 0.6rem 0; }
.preview ul, .preview ol { margin: 0.6rem 0; padding-left: 1.4rem; }
.preview figure { margin: 1rem 0; }
.preview figure img, .preview img { display: block; max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.preview figcaption { margin-top: 0.35rem; color: var(--muted); font-size: 0.85rem; }
.preview table { width: 100%; margin: 0.75rem 0; border-collapse: collapse; border: 1px solid var(--line); }
.preview table th, .preview table td { border: 1px solid var(--line); padding: 0.4rem 0.6rem; }

.preview .preview-hero { margin: 0 0 1rem; }
.preview .preview-hero img { width: 100%; max-width: 100%; height: auto; border-radius: var(--radius); margin: 0; }
main > section figure img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: 0.75rem 0;
}

.faq { margin: 0.5rem 0 0; }
.faq dt { font-weight: 600; margin-top: 0.75rem; }
.faq dt:first-child { margin-top: 0; }
.faq dd { margin: 0.2rem 0 0; color: var(--muted); }

/* Placeholder box the admin preview shows instead of a live script embed (docs/sources.md section 6) */
.embed-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 1rem 0;
  padding: 2rem 1rem;
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
