/* ExtremismLedger public site -- restrained news/research aesthetic.
   Light/dark via CSS custom properties; [data-theme] attribute on <html>
   overrides the OS default, set by static/public/theme.js. */

:root {
  --bg: #fafaf9;
  --bg-raised: #ffffff;
  --border: #e2e0dc;
  --text: #1c1b19;
  --text-muted: #5f5c56;
  --accent: #1d4e8f;
  --accent-muted: #e8eef7;
  --link: #1d4e8f;
  --badge-fact-bg: #e7f3ea;
  --badge-fact-text: #1f5c33;
  --badge-allegation-bg: #fbf0d9;
  --badge-allegation-text: #7a5a10;
  --badge-classification-bg: #eee9f7;
  --badge-classification-text: #4a3a7a;
  --badge-confirmed-bg: #e8eef7;
  --badge-confirmed-text: #1d4e8f;
  --badge-inferred-bg: #f1f0ee;
  --badge-inferred-text: #5f5c56;
  --status-alleged: #7a5a10;
  --status-charged: #9a4b12;
  --status-convicted: #8f1d1d;
  --status-adjudicated: #4a3a7a;
  --status-documented: #1f5c33;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #161513;
  --bg-raised: #201f1c;
  --border: #37352f;
  --text: #ece9e2;
  --text-muted: #a8a49a;
  --accent: #7aa7e0;
  --accent-muted: #22314a;
  --link: #7aa7e0;
  --badge-fact-bg: #16301f;
  --badge-fact-text: #8fd6a4;
  --badge-allegation-bg: #3a2e0c;
  --badge-allegation-text: #e3c374;
  --badge-classification-bg: #251c3a;
  --badge-classification-text: #c1aeee;
  --badge-confirmed-bg: #1c2c46;
  --badge-confirmed-text: #9cc0ec;
  --badge-inferred-bg: #2a2924;
  --badge-inferred-text: #a8a49a;
  --status-alleged: #e3c374;
  --status-charged: #e0a06a;
  --status-convicted: #e08a8a;
  --status-adjudicated: #c1aeee;
  --status-documented: #8fd6a4;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513;
    --bg-raised: #201f1c;
    --border: #37352f;
    --text: #ece9e2;
    --text-muted: #a8a49a;
    --accent: #7aa7e0;
    --accent-muted: #22314a;
    --link: #7aa7e0;
    --badge-fact-bg: #16301f;
    --badge-fact-text: #8fd6a4;
    --badge-allegation-bg: #3a2e0c;
    --badge-allegation-text: #e3c374;
    --badge-classification-bg: #251c3a;
    --badge-classification-text: #c1aeee;
    --badge-confirmed-bg: #1c2c46;
    --badge-confirmed-text: #9cc0ec;
    --badge-inferred-bg: #2a2924;
    --badge-inferred-text: #a8a49a;
    --status-alleged: #e3c374;
    --status-charged: #e0a06a;
    --status-convicted: #e08a8a;
    --status-adjudicated: #c1aeee;
    --status-documented: #8fd6a4;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; line-height: 1.25; }
a { color: var(--link); }

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}
.site-header .inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.site-title { font-family: Georgia, serif; font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); }
.site-header nav { display: flex; gap: 1rem; margin-left: auto; align-items: center; }
.site-header nav a { text-decoration: none; color: var(--text-muted); font-size: 0.95rem; }
.site-header nav a:hover { color: var(--text); }

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
}

.desktop-ad-rail { display: none; }

@media (min-width: 1360px) {
  .public-page-layout {
    display: grid;
    grid-template-columns: minmax(0, 1010px) 160px;
    gap: 2rem;
    max-width: 1280px;
    margin: 0 auto;
  }
  .public-page-layout main {
    max-width: none;
    margin: 0;
  }
  .public-page-layout.no-ad-rail {
    display: block;
    max-width: 960px;
  }
  .public-page-layout.no-ad-rail main {
    max-width: none;
    margin: 0;
  }
  .desktop-ad-rail {
    display: block;
    align-self: start;
    position: sticky;
    top: 1rem;
    min-width: 0;
  }
  .advertisement {
    min-height: 600px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
  }
  .advertisement-label {
    margin: 0.45rem 0 0.75rem;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-align: center;
    text-transform: uppercase;
  }
  .advertisement-slot { min-height: 600px; }
}

.dev-notice {
  background: var(--accent-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 1.5rem;
}

.card {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
}
.card h3 { margin: 0 0 0.35rem; font-size: 1.05rem; }
.card a.card-link { text-decoration: none; color: var(--text); }
.card a.card-link:hover { color: var(--accent); }
.muted { color: var(--text-muted); font-size: 0.9rem; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.12rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.badge-fact { background: var(--badge-fact-bg); color: var(--badge-fact-text); }
.badge-allegation { background: var(--badge-allegation-bg); color: var(--badge-allegation-text); }
.badge-classification { background: var(--badge-classification-bg); color: var(--badge-classification-text); }
.badge-confirmed { background: var(--badge-confirmed-bg); color: var(--badge-confirmed-text); }
.badge-inferred { background: var(--badge-inferred-bg); color: var(--badge-inferred-text); border: 1px dashed var(--badge-inferred-text); }

.incident-status { font-weight: 600; }
.incident-status-alleged { color: var(--status-alleged); }
.incident-status-charged { color: var(--status-charged); }
.incident-status-convicted { color: var(--status-convicted); }
.incident-status-adjudicated { color: var(--status-adjudicated); }
.incident-status-documented { color: var(--status-documented); }

.fact-row {
  border-top: 1px solid var(--border);
  padding: 0.9rem 0;
}
.fact-row:first-child { border-top: none; }
.fact-statement { margin: 0.3rem 0 0.5rem; }
.sources { list-style: none; margin: 0.4rem 0 0; padding: 0; font-size: 0.85rem; }
.sources li { color: var(--text-muted); margin-bottom: 0.2rem; }
.sources a { color: var(--text-muted); }

.search-box { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.search-box input[type="text"] {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-raised);
  color: var(--text);
  font-size: 1rem;
}
.search-box select {
  padding: 0.55rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-raised);
  color: var(--text);
}
.search-box button {
  padding: 0.55rem 1rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
}

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 3rem;
  padding: 1.25rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.site-footer p { margin: 0 0 0.6rem; }
.footer-links { display: flex; justify-content: center; gap: 1.25rem; flex-wrap: wrap; }
.footer-links a { color: var(--text-muted); text-decoration: none; }
.footer-links a:hover { color: var(--text); }
.footer-version { margin-top: 0.6rem; font-size: 0.75rem; opacity: 0.7; }

.legal-page h2 { margin-top: 2rem; font-size: 1.15rem; }
.legal-page h2:first-of-type { margin-top: 1.5rem; }
.legal-page ul, .legal-page ol { padding-left: 1.4rem; }
.legal-page li { margin-bottom: 0.4rem; }
.legal-page .legal-updated { color: var(--text-muted); font-size: 0.85rem; margin-top: -0.5rem; margin-bottom: 1.5rem; }

.donate-page { max-width: 560px; }
.donate-button-area {
  margin-top: 1.75rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent-muted);
  max-width: 320px;
}

.error-page { text-align: center; padding: 4rem 1rem; }
.error-page h1 { font-size: 3rem; margin-bottom: 0.5rem; }

.record-photo {
  /* Shared by WikiPage's own detail page and every other public detail
     page that reuses a WikiPage's image (see includes/_wiki_image.html)
     -- one class, one rule, no per-record-type duplication. Always lives
     inside .detail-sidebar (~340px), so width:100% never expands past
     that column; height:auto keeps portrait and landscape images both
     scaling proportionally, uncropped. */
  width: 100%;
  max-width: 340px;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: block;
  /* Revealed by lightbox.js once the image has actually finished loading
     (or failed) -- opacity only, never display/visibility, so the box
     (once its intrinsic aspect ratio is known) never collapses and
     nothing jumps when it fades in. See .record-photo.is-loading below;
     if JS never runs at all, the image is simply visible immediately
     (this class is only ever added by script, never present in the
     server-rendered HTML), so this is a pure enhancement, never a
     way to hide the image permanently. */
  opacity: 1;
  transition: opacity 120ms ease-in;
}
.record-photo.is-loading {
  opacity: 0;
}
@media (prefers-reduced-motion: reduce) {
  .record-photo { transition: none; }
}

.record-photo-trigger {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}
.record-photo-trigger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.lightbox {
  /* Reset the <dialog> UA stylesheet (border/background/padding) --
     centering itself is left entirely to the browser's own modal-dialog
     positioning (position: fixed; inset: 0; margin: auto) triggered by
     showModal() in lightbox.js, so nothing here needs to re-implement it. */
  border: none;
  background: transparent;
  padding: 0;
  max-width: none;
  max-height: none;
}
.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.75);
}
.lightbox-inner {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}
.lightbox-image {
  /* Only max-width/max-height are set (never width/height) so a smaller
     image is never upscaled -- it renders at its natural size unless
     that exceeds the viewport-relative cap, in which case it scales down
     proportionally, uncropped. */
  display: block;
  max-width: 90vw;
  max-height: 90vh;
  width: auto;
  height: auto;
  border-radius: 6px;
}
.lightbox-close {
  position: absolute;
  top: -0.9rem;
  right: -0.9rem;
  width: 2rem;
  height: 2rem;
  line-height: 1;
  font-size: 1.15rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-raised);
  color: var(--text);
  cursor: pointer;
}
.lightbox-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
body.lightbox-open {
  overflow: hidden;
}

@media (max-width: 480px) {
  .lightbox-close { top: 0.5rem; right: 0.5rem; }
}

.detail-layout {
  /* Two-column desktop layout for Person/Organization/WikiPage detail
     pages: a flexible evidentiary/content column plus a fixed-width
     sidebar (image + Quick Info) aligned near the top of the record.
     align-items: start keeps the sidebar from stretching to match the
     (usually much taller) main column. */
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 2rem;
  align-items: start;
}
.detail-sidebar { display: flex; flex-direction: column; gap: 1rem; }

.quick-info { padding: 1rem 1.25rem; }
.quick-info h3 {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.quick-info-list { margin: 0; }
.quick-info-row { border-top: 1px solid var(--border); padding: 0.6rem 0; }
.quick-info-row:first-child { border-top: none; padding-top: 0; }
.quick-info-row dt { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.15rem; }
.quick-info-row dd { margin: 0; font-size: 0.92rem; }

@media (max-width: 860px) {
  .detail-layout { grid-template-columns: 1fr; gap: 1.5rem; }
  /* Sidebar (image + Quick Info) stacks above the main content column at
     tablet/mobile widths, regardless of source order in the template. */
  .detail-sidebar { order: -1; }
  .record-photo { max-width: 360px; }
}

.wiki-body > h1:first-child {
  /* The page's own <h1>{{ page.title }}</h1> (wiki_page_detail.html)
     already renders the title -- a WikiPage.body that also opens with a
     top-level Markdown heading (the common case) would otherwise show it
     twice. Only ever hides a body's own *first* element when it's an h1;
     never touches a later heading, or a body that doesn't open with one.
     CSS-only on purpose -- no change to apps/core/markdown.py, which is
     the one piece of this feature with real XSS-safety review behind it. */
  display: none;
}

.wiki-body blockquote {
  margin: 0 0 1rem;
  padding: 0.1rem 1rem;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}
.wiki-body code {
  background: var(--accent-muted);
  border-radius: 3px;
  padding: 0.1em 0.35em;
  font-size: 0.9em;
}
.wiki-body ul,
.wiki-body ol {
  padding-left: 1.4rem;
}

/* Report form
   One flowing editorial column -- deliberately NOT a stack of bordered
   cards. Sections are separated by type weight and spacing, not boxes;
   only the final action area gets a rule, to mark the form's end. Field
   styling is scoped to .report-form and keyed off tag/type rather than
   added classes, since ReportForm (apps/reporting/forms.py) intentionally
   carries no widget attrs -- this keeps the form's Python untouched by a
   visual pass. Width utility classes (.field-lg/-md/-compact) express
   intentional field widths without touching forms.py. */
.report-form { max-width: 640px; }

.report-form fieldset {
  border: none;
  margin: 0 0 2.5rem;
  padding: 0;
}
.report-form fieldset:last-of-type { margin-bottom: 0; }
.report-form legend {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  padding: 0;
  margin: 0 0 1.1rem;
}

.field { margin-bottom: 1.1rem; max-width: 100%; }
.field:last-child { margin-bottom: 0; }
.field-lg { max-width: 480px; }
.field-md { max-width: 320px; }
.field-compact { max-width: 150px; }

.report-form label {
  display: block;
  font-size: 0.87rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.report-form .field-optional {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.83rem;
}
.report-form .required-mark {
  color: var(--status-convicted);
  margin-left: 0.15rem;
}

.report-form input[type="text"],
.report-form input[type="url"],
.report-form input[type="email"],
.report-form input[type="date"],
.report-form textarea,
.report-form select {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.45rem 0.6rem;
}
.report-form textarea { height: 3rem; resize: vertical; line-height: 1.45; }
.report-form textarea#id_description,
.report-form textarea#id_inclusion_relevance { height: 6rem; }

.report-form input:focus,
.report-form textarea:focus,
.report-form select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.report-form .checkbox-field { display: flex; align-items: baseline; gap: 0.5rem; margin: 0.6rem 0 1.1rem; }
.report-form .checkbox-field input[type="checkbox"] { margin: 0; flex: none; }
.report-form .checkbox-field label { margin: 0; font-weight: 400; }

.report-form .field-hint {
  color: var(--text-muted);
  font-size: 0.81rem;
  margin: 0.35rem 0 0;
  line-height: 1.45;
  max-width: 56ch;
}

.report-form .form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem 1.25rem;
}
.report-form .form-row .field { margin-bottom: 0; flex: none; }

/* Reporter contact: name/email columns must stay equal width and align on
   the same baseline even though the email label is much longer and wraps
   -- a grid (not the general .form-row flex) gives both columns the same
   width, and reserving two lines of label height (with the label's own
   text bottom-aligned) keeps both inputs level regardless of wrap. */
.report-form .form-row.form-row-contact {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.report-form .form-row.form-row-contact .field { max-width: none; }
.report-form .form-row.form-row-contact label {
  display: flex;
  align-items: flex-end;
  line-height: 1.3;
  min-height: 2.6em;
}

.report-form .field-error {
  color: var(--status-convicted);
  font-size: 0.82rem;
  margin: 0.35rem 0 0;
}
.report-form .field.has-error input,
.report-form .field.has-error textarea,
.report-form .field.has-error select {
  border-color: var(--status-convicted);
}
.report-form .form-error-banner {
  background: var(--badge-allegation-bg);
  color: var(--badge-allegation-text);
  border: 1px solid var(--status-charged);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
}

.report-form .privacy-note {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0.6rem 0 0;
}

.report-form .field.is-deemphasized { opacity: 0.5; }
.report-form .field.is-emphasized label { color: var(--accent); }

/* Optional-details disclosure -- native <details>, keyboard/AT operable
   without JS, so it stays correct with JS disabled per the brief. */
.report-form details.optional-section {
  margin: 0 0 2.5rem;
  padding: 0.9rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.report-form details.optional-section summary {
  cursor: pointer;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-muted);
  padding: 0;
  list-style: none;
}
.report-form details.optional-section summary::-webkit-details-marker { display: none; }
.report-form details.optional-section summary::before {
  content: "+";
  display: inline-block;
  width: 1em;
  color: var(--text-muted);
}
.report-form details.optional-section[open] summary::before { content: "\2212"; }
.report-form details.optional-section summary:hover { color: var(--text); }
.report-form details.optional-section[open] summary { margin-bottom: 1.4rem; }
.report-form details.optional-section .form-row { margin-top: 1.1rem; }

.report-form .final-section {
  margin-top: 2.75rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--border);
}
.report-form .submit-section { margin-top: 0.25rem; }
.report-form .submit-section button {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.6rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 1rem;
}
.report-form .submit-section button:hover { opacity: 0.92; }
.report-form .submit-section button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 640px) {
  .site-header .inner { flex-wrap: wrap; }
  .site-header nav { flex-wrap: wrap; width: 100%; margin-left: 0; row-gap: 0.5rem; }
  main { padding: 1.25rem 1rem 3rem; }
  .report-form .field-lg,
  .report-form .field-md,
  .report-form .field-compact { max-width: 100%; }
  .report-form .form-row .field { flex: 1 1 140px; }
  .report-form .form-row.form-row-contact { grid-template-columns: 1fr; gap: 1.1rem; }
  .report-form .form-row.form-row-contact label {
    display: block;
    line-height: 1.55;
    min-height: 0;
  }
}
