/* Clearinghouse — 3D Politics design system
   Tokens ported from 3dpolitics-theme/style.css v2.9.3 (Swiss institutional
   brutalism), identical to the Cost of Democracy app chrome: warm cream paper,
   dark ink, solid hairline rules, hard offset shadows, uppercase mono labels. */

:root {
  /* Core brand tokens (identical to the 3dpolitics theme) */
  --bg:        #F5F1E8; /* warm cream newsprint */
  --surface:   #FFFCF5; /* lighter paper */
  --fg:        #1A1A1A; /* dark ink */
  --muted:     #6B6B6B; /* warm gray */
  --border:    #1A1A1A;
  --accent:    #C0392B; /* hazard rust */
  --accent-contrast: #FFFCF5;

  --pillar-decision-making:  #C0392B; /* red */
  --pillar-decentralization: #2E86AB; /* blue */
  --pillar-distribution:     #5D9B4B; /* green */
  --pillar-synthesis:        #7B4F8F; /* lila / purple */
  --gold:                    #D4A017; /* Solar Gold */

  --font-display: 'Helvetica Neue', 'Helvetica Now', 'Neue Haas Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-body:    'IBM Plex Mono', ui-monospace, 'JetBrains Mono', Menlo, Consolas, monospace;
  --font-prose:   'IBM Plex Serif', Georgia, 'Times New Roman', serif;

  --space-3xs: 0.25rem;
  --space-2xs: 0.5rem;
  --space-xs:  0.75rem;
  --space-s:   1rem;
  --space-m:   1.5rem;
  --space-l:   2rem;
  --space-xl:  3rem;

  --text-xs:  0.75rem;
  --text-s:   0.75rem;
  --text-m:   0.875rem;
  --text-base:1rem;
  --text-l:   1.25rem;
  --text-xl:  1.75rem;

  --rule: 1px solid var(--border);
  --rule-thick: 2px solid var(--fg);
  --max-width: 1200px;

  /* Hard offset shadow for brutalist panels */
  --panel-shadow: 4px 4px 0 var(--fg);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.55;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Masthead — paper surface, thick ink rule (shell pattern) */
header {
  background: var(--surface);
  color: var(--fg);
  border-bottom: var(--rule-thick);
  padding: var(--space-s) var(--space-m);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2xs);
}

header h1 {
  font-family: var(--font-display);
  font-size: var(--text-l);
  font-weight: 900;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

header p {
  font-size: var(--text-s);
  color: var(--muted);
  margin-top: var(--space-3xs);
}

header .home-link {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: var(--rule);
  padding: 0.35em 0.9em;
  white-space: nowrap;
}

header .home-link:hover { background: var(--fg); color: var(--bg); }

/* Nav — bordered mode switcher, invert on hover/active */
nav {
  background: var(--surface);
  border-bottom: var(--rule);
  padding: var(--space-2xs) var(--space-m);
  display: flex;
  gap: 0;
}

nav a {
  color: var(--fg);
  font-size: var(--text-s);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.35em 0.9em;
  border: var(--rule);
  border-right: none;
}

nav a:last-child { border-right: var(--rule); }

nav a:hover,
nav a.active {
  background: var(--fg);
  color: var(--bg);
}

/* Layout */
main {
  max-width: 680px;
  margin: var(--space-l) auto;
  padding: 0 var(--space-s);
}

main.two-col {
  max-width: 980px;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--space-m);
  align-items: start;
}

/* Brutalist panel: paper fill, ink border, hard offset shadow */
.card {
  background: var(--surface);
  border: var(--rule-thick);
  box-shadow: var(--panel-shadow);
  padding: var(--space-m);
}

.card h2 {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-s);
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.card h2::before {
  content: '';
  width: 0.6em;
  height: 0.6em;
  background: var(--accent);
  flex-shrink: 0;
}

/* Forms */
.form-row { margin-bottom: var(--space-s); }

label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: var(--space-3xs);
}

input[type=text],
input[type=file],
select,
textarea {
  width: 100%;
  padding: var(--space-2xs) var(--space-xs);
  border: var(--rule);
  border-radius: 0;
  font-size: var(--text-m);
  background: var(--surface);
  color: var(--fg);
  font-family: inherit;
}

input[type=text]:focus,
input[type=file]:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--fg);
}

input[type=file] {
  border-style: dashed;
  padding: var(--space-xs);
  cursor: pointer;
  color: var(--muted);
}

input[type=file]:hover { border-color: var(--accent); color: var(--fg); }

textarea { resize: vertical; min-height: 80px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-xs);
}

/* Buttons — uppercase mono, invert to ink on hover */
button,
.btn,
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2xs);
  background: var(--accent);
  color: var(--accent-contrast);
  border: 1px solid var(--accent);
  border-radius: 0;
  padding: var(--space-xs) var(--space-s);
  font-family: var(--font-body);
  font-size: var(--text-m);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  width: 100%;
}

button:hover,
.btn:hover,
.action-btn:hover {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

button:disabled,
.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: var(--surface);
  border-color: var(--muted);
  color: var(--muted);
}

.btn--secondary {
  background: var(--surface);
  border: var(--rule);
  color: var(--fg);
  width: auto;
}

.btn--secondary:hover { background: var(--fg); color: var(--bg); }

small { font-size: var(--text-xs); color: var(--muted); }

.section-title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: var(--space-s) 0 var(--space-xs);
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.section-title::before {
  content: '';
  width: 0.6em;
  height: 0.6em;
  background: var(--accent);
  flex-shrink: 0;
}

#status {
  margin-top: var(--space-s);
  padding: var(--space-xs) var(--space-s);
  font-size: var(--text-m);
  display: none;
  border: var(--rule);
}

#status.ok  { border-left: 4px solid var(--pillar-distribution); background: var(--surface); }
#status.err { border-left: 4px solid var(--accent); background: var(--surface); color: var(--accent); }

/* Query results */
#results { min-height: 200px; }

.empty-state {
  text-align: center;
  padding: var(--space-xl) var(--space-s);
  color: var(--muted);
  font-size: var(--text-m);
  background: var(--surface);
  border: 1px dashed var(--border);
}

.rec-card {
  background: var(--surface);
  border: var(--rule);
  padding: var(--space-s);
  margin-bottom: var(--space-xs);
}

.rec-card:last-child { margin-bottom: 0; }

.rec-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-xs);
}

.rec-title {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  flex: 1;
  line-height: 1.25;
}

/* Relevance badges — text + shape, never color alone */
.priority {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.1em 0.5em;
  border: 1px solid var(--fg);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface);
  white-space: nowrap;
  border-radius: 0;
}

.priority::before { content: ''; width: 0.55em; height: 0.55em; flex-shrink: 0; }
.priority-1::before { background: var(--accent); }
.priority-2::before { background: var(--gold); border-radius: 50%; }
.priority-3::before { background: var(--muted); transform: rotate(45deg); }

.rec-meta {
  font-size: var(--text-xs);
  color: var(--muted);
  margin: var(--space-2xs) 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3xs);
}

.tag {
  background: var(--bg);
  border: 1px solid var(--muted);
  padding: 0.1em 0.5em;
}

/* Verbatim quotes read as documents: serif prose on paper */
.rec-summary {
  font-family: var(--font-prose);
  font-size: var(--text-m);
  color: var(--fg);
  margin: var(--space-2xs) 0;
  line-height: 1.6;
}

.rec-relevance {
  font-size: var(--text-s);
  color: var(--muted);
  background: var(--bg);
  border-left: 3px solid var(--accent);
  padding: var(--space-2xs) var(--space-xs);
  margin-top: var(--space-2xs);
}

.error-msg {
  border: var(--rule);
  border-left: 4px solid var(--accent);
  color: var(--accent);
  background: var(--surface);
  padding: var(--space-xs) var(--space-s);
  font-size: var(--text-m);
}

.spinner {
  text-align: center;
  padding: var(--space-l);
  color: var(--muted);
  font-size: var(--text-m);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Footer note */
.brand-note {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--muted);
  padding: var(--space-l) var(--space-s) var(--space-xl);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.brand-note a {
  color: var(--fg);
  border-bottom: 1px solid var(--accent);
}

.brand-note a:hover { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Masthead action buttons (Ask / Contribute / Methodology) ──────────────── */
.masthead-actions {
  display: flex;
  gap: var(--space-2xs);
  flex-shrink: 0;
  margin-top: var(--space-2xs);
}

.masthead-actions button {
  width: auto;
  background: var(--surface);
  border: var(--rule);
  color: var(--fg);
  padding: 0.35em 0.9em;
  font-size: var(--text-s);
}

.masthead-actions button:hover { background: var(--fg); color: var(--bg); }

/* ── Landing hero + CTAs ────────────────────────────────────────────────────── */
.hero { max-width: 760px; margin: var(--space-l) auto; }

.intro-text {
  font-family: var(--font-prose);
  font-size: var(--text-l);
  line-height: 1.6;
  margin-bottom: var(--space-l);
}

.intro-text a { border-bottom: 1px solid var(--accent); }
.intro-text a:hover { color: var(--accent); }

.cta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-s);
}

.cta-card {
  width: auto;
  background: var(--surface);
  border: var(--rule-thick);
  box-shadow: var(--panel-shadow);
  color: var(--fg);
  padding: var(--space-m) var(--space-s);
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  text-transform: none;
  letter-spacing: normal;
  line-height: 1.3;
  min-height: 6.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.cta-card:hover {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

main:not(.two-col) { max-width: 760px; }

/* ── Topic cards (Ask flow, step 1) ────────────────────────────────────────── */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-2xs);
  margin: var(--space-s) 0;
}

.topic-card {
  width: auto;
  background: var(--surface);
  border: var(--rule);
  color: var(--fg);
  padding: var(--space-xs);
  font-family: var(--font-body);
  font-size: var(--text-m);
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3em;
}

.topic-card:hover { border-color: var(--accent); }

.topic-card.selected {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.topic-card-count {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.topic-card.selected .topic-card-count { color: var(--bg); opacity: 0.7; }

.button-row {
  display: flex;
  gap: var(--space-xs);
  margin-top: var(--space-s);
}

.button-row button { width: auto; flex: 1; }

.section-note {
  font-size: var(--text-s);
  color: var(--muted);
  margin-bottom: var(--space-s);
}

/* ── Results banners (Ask flow, step 3) ────────────────────────────────────── */
.rec-banner {
  background: var(--surface);
  border: var(--rule);
  border-left: 4px solid var(--accent);
  padding: var(--space-s);
  margin-bottom: var(--space-xs);
}

.rec-banner:last-child { margin-bottom: 0; }

.rec-source {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: var(--space-2xs);
  padding-top: var(--space-2xs);
  border-top: 1px dashed var(--border);
}

/* ── Contribute review step ────────────────────────────────────────────────── */
.optional-details {
  border: var(--rule);
  padding: var(--space-xs) var(--space-s);
  margin: var(--space-s) 0;
}

.optional-details summary {
  cursor: pointer;
  font-size: var(--text-s);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.optional-details[open] summary { margin-bottom: var(--space-s); }

.preview-item {
  border-top: 1px dashed var(--border);
  padding: var(--space-xs) 0;
}

.preview-item-head {
  font-weight: 700;
  font-size: var(--text-s);
}

.preview-item-quote {
  font-family: var(--font-prose);
  font-size: var(--text-m);
  margin: var(--space-3xs) 0;
}

.preview-item-page {
  font-size: var(--text-xs);
  color: var(--muted);
}

#reviewNoteBox textarea { min-height: 100px; margin-bottom: var(--space-xs); }

#reviewDone {
  padding: var(--space-s);
  border: var(--rule);
  border-left: 4px solid var(--pillar-distribution);
  background: var(--bg);
}

/* ── Methodology modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-l) var(--space-s);
  z-index: 1000;
  overflow-y: auto;
}

/* [hidden] and .modal-overlay{display:flex} have equal CSS specificity, so
   without this the later rule wins and the modal never hides. */
.modal-overlay[hidden] { display: none; }

.modal-box {
  max-width: 640px;
  width: 100%;
  position: relative;
  margin: var(--space-l) 0;
}

.modal-box h2 {
  font-family: var(--font-display);
  font-size: var(--text-l);
  font-weight: 900;
  text-transform: uppercase;
  margin-bottom: var(--space-s);
}

.modal-prose {
  font-family: var(--font-prose);
  font-size: var(--text-m);
  line-height: 1.65;
}

.modal-prose p { margin-bottom: var(--space-s); }
.modal-prose p:last-child { margin-bottom: 0; }

.modal-close {
  position: absolute;
  top: var(--space-s);
  right: var(--space-s);
  width: 2em;
  height: 2em;
  padding: 0;
  font-size: var(--text-l);
  line-height: 1;
  background: var(--surface);
  border: var(--rule);
  color: var(--fg);
}

.modal-close:hover { background: var(--fg); color: var(--bg); }

/* ── Print stylesheet (Download report as PDF via browser print) ──────────── */
.print-only { display: none; }

@media print {
  .no-print, dp-header, nav { display: none !important; }
  body { padding-top: 0; background: #fff; color: #000; }
  .print-only { display: block; margin-bottom: var(--space-m); }
  .print-only h2 {
    font-family: var(--font-display);
    font-weight: 900;
    text-transform: uppercase;
    border-bottom: 2px solid #000;
    padding-bottom: var(--space-xs);
    margin-bottom: var(--space-xs);
  }
  .card { box-shadow: none; border: 1px solid #000; }
  .rec-banner { break-inside: avoid; border-left: 3px solid #000; }
}

/* Responsive */
@media (max-width: 760px) {
  main.two-col { grid-template-columns: 1fr; }
  header { flex-direction: column; gap: var(--space-xs); }
  .form-grid { grid-template-columns: 1fr; }
  .cta-grid { grid-template-columns: 1fr; }
  .masthead-actions { flex-wrap: wrap; }
}
