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

* { 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);
}
.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;
}

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.actions form { display: inline-flex; margin: 0; }

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

button {
  font: inherit;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}
button.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
}
button:disabled, .btn-sm:disabled {
  border-color: var(--line);
  background: var(--line);
  color: var(--muted);
  cursor: not-allowed;
}

/* 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; }

.btn-sm {
  display: inline-block;
  font: inherit;
  padding: 0.2rem 0.55rem;
  font-size: 0.8rem;
  line-height: 1.4;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  text-decoration: none;
}
.btn-sm:hover { text-decoration: none; }

.flash {
  max-width: 1100px;
  margin: 1rem auto 0;
  padding: 0.6rem 1rem;
  border: 1px solid #b7e0c0;
  background: #eaf7ee;
  border-radius: 6px;
}
.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: 8px;
  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;
}

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: 8px;
  padding: 1.5rem;
}
.login-box label { display: block; margin-bottom: 0.75rem; }
.login-box input { display: block; width: 100%; padding: 0.45rem 0.6rem; margin-top: 0.25rem; border: 1px solid var(--line); border-radius: 6px; font: inherit; }

.roles-table select, .roles-table input[type="text"] {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 100%;
  min-width: 10rem;
}
.roles-table td { vertical-align: middle; }

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

.filters { display: flex; gap: 0.5rem; margin: 0.5rem 0 1rem; }
.filters .tag { cursor: pointer; }
.filters .tag.active { background: var(--accent); color: var(--accent-fg); }

.submit-forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.5rem; margin-top: 0.75rem; }
.submit-forms form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}
.submit-forms .note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}
.submit-forms label { display: block; margin-bottom: 0.75rem; font-size: 0.9rem; color: var(--muted); }
.submit-forms input, .submit-forms textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--fg);
  background: var(--card);
}

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

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

.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: 8px; 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: 8px; 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: 46rem;
  margin: 0.75rem 0 1.25rem;
  padding: 1rem 1.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.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: 6px; }
.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 > figure:first-child img,
main > section figure img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  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: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

details {
  margin: 0.75rem 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}
details summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.15rem 0;
}
details[open] summary { margin-bottom: 0.5rem; }
details label { display: block; margin-bottom: 0.75rem; font-size: 0.9rem; color: var(--muted); }
details input, details textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--fg);
  background: var(--card);
}
details textarea[name="html"] { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.85rem; }
