/* ==========================================================================
   legal.css · long-form documents, cookie tables, consent banner, reports.
   Loaded after style.css; reuses its tokens (--bg, --panel, --border, --text,
   --muted, --accent, --gold, --danger, --r, --gap, --font, --font-display).
   Mobile-first. Dark by default, light under html[data-theme="light"].
   ========================================================================== */

/* Legal-specific tints only · the palette itself lives in style.css. */
:root {
  --legal-measure: 72ch;
  --legal-rule: color-mix(in srgb, var(--border) 100%, transparent);
  --legal-mark: color-mix(in srgb, var(--accent) 14%, transparent);
  --legal-toc-bg: color-mix(in srgb, var(--panel) 100%, transparent);
  --legal-banner-bg: color-mix(in srgb, var(--bg-elev, var(--panel)) 82%, transparent);
}

html[data-theme="light"] {
  --legal-mark: color-mix(in srgb, var(--accent) 10%, transparent);
  --legal-banner-bg: color-mix(in srgb, #fff 86%, transparent);
}

/* ------------------------------------------------------------ page shell */
.legal {
  padding: 20px 0 48px;
  font-size: 1rem;
  line-height: 1.7;
}

.legal-head {
  border-bottom: 1px solid var(--border);
  padding-bottom: 18px;
  margin-bottom: 22px;
  max-width: var(--legal-measure);
}

.legal-head h1 { margin-bottom: 10px; }

.legal-updated {
  display: inline-block;
  font: 600 .78rem/1 var(--font);
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--gold);
  background: color-mix(in srgb, var(--gold) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
  border-radius: 999px;
  padding: 6px 11px;
  margin: 0 0 12px;
}

.legal-lede {
  font-size: 1.08rem;
  color: var(--text);
  margin: 0 0 10px;
}

.legal-disclaimer {
  font-size: .9rem;
  margin: 0;
  border-left: 3px solid var(--border);
  padding-left: 12px;
}

/* --------------------------------------------------------------- layout */
.legal-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.legal-body {
  max-width: var(--legal-measure);
  min-width: 0;
}

.legal-narrow { max-width: 780px; }

/* -------------------------------------------------- table of contents --
   <details open>: a real disclosure widget on phones, a plain sticky list
   on desktop (the summary is hidden and the content forced visible). */
.legal-toc {
  background: var(--legal-toc-bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 4px 14px;
  font-size: .92rem;
}

.legal-toc > summary {
  cursor: pointer;
  list-style: none;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: .3px;
  padding: 10px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.legal-toc > summary::-webkit-details-marker { display: none; }
.legal-toc > summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--muted);
  transition: transform .15s ease;
}
.legal-toc[open] > summary::after { transform: rotate(180deg); }
.legal-toc > summary:hover { color: var(--accent); }

.legal-toc-inner { padding-bottom: 10px; }

.legal-toc ol {
  list-style: none;
  counter-reset: toc;
  margin: 0;
  padding: 0;
}
.legal-toc li { counter-increment: toc; }
.legal-toc a {
  display: block;
  padding: 6px 0 6px 26px;
  position: relative;
  color: var(--muted);
  border-left: 2px solid transparent;
  line-height: 1.4;
}
.legal-toc a::before {
  content: counter(toc) ".";
  position: absolute;
  left: 6px;
  color: var(--border);
  font-variant-numeric: tabular-nums;
}
.legal-toc a:hover,
.legal-toc a:focus-visible { color: var(--text); text-decoration: none; }

/* ------------------------------------------------------------- sections */
.legal-section {
  padding-top: 8px;
  margin-bottom: 30px;
  scroll-margin-top: 80px;
}

.legal-section h2 {
  font-size: 1.2rem;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft, var(--border));
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.legal-section p { margin: 0 0 14px; }
.legal-section p:last-child { margin-bottom: 0; }
.legal-section strong { color: var(--text); }
.legal-section code {
  background: var(--panel-2, var(--panel));
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.legal-section :target,
.legal-section:target { scroll-margin-top: 80px; }
.legal-section:target h2 { background: var(--legal-mark); border-radius: var(--r-sm, 5px); }

/* anchored headings with permalinks */
.permalink {
  font: 600 .85em/1 var(--font-mono, monospace);
  color: var(--border);
  opacity: 0;
  transition: opacity .15s ease, color .15s ease;
  text-decoration: none;
}
.legal-section h2:hover .permalink,
.permalink:focus-visible { opacity: 1; color: var(--accent); }
@media (hover: none) {
  .permalink { opacity: 1; color: var(--border); }
}

.legal-list {
  margin: 0 0 14px;
  padding-left: 20px;
}
.legal-list li { margin-bottom: 8px; }
.legal-list li:last-child { margin-bottom: 0; }
ol.legal-list li::marker { color: var(--muted); font-variant-numeric: tabular-nums; }

.legal-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: .92rem;
}

/* -------------------------------------------------------- cookie tables */
.cookie-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: .92rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

.cookie-table th {
  text-align: left;
  font: 700 .74rem/1.3 var(--font);
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel-2, var(--panel));
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.cookie-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-soft, var(--border));
  vertical-align: top;
}
.cookie-table tbody tr:last-child td { border-bottom: 0; }
.cookie-table tbody tr:hover { background: var(--panel-2, var(--panel)); }
.cookie-table code { white-space: nowrap; }

/* stacked cards on phones · each cell keeps its header via data-label */
@media (max-width: 700px) {
  .cookie-table, .cookie-table tbody, .cookie-table tr, .cookie-table td { display: block; width: 100%; }
  .cookie-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); }
  .cookie-table tr {
    border-bottom: 1px solid var(--border);
    padding: 6px 0;
  }
  .cookie-table tr:last-child { border-bottom: 0; }
  .cookie-table td { border-bottom: 0; padding: 5px 12px; }
  .cookie-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font: 700 .68rem/1.3 var(--font);
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 2px;
  }
}

/* ------------------------------------------------------- consent banner */
.cookie-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  background: var(--legal-banner-bg);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .35);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  animation: cookie-rise .25s ease-out;
}

/* Keep the last paragraph of a page reachable above the banner. */
body:has(.cookie-banner) { padding-bottom: 240px; }
@media (min-width: 900px) {
  body:has(.cookie-banner) { padding-bottom: 160px; }
}

@keyframes cookie-rise {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.cookie-banner-inner {
  width: 100%;
  max-width: var(--maxw, 1180px);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cookie-banner-text { max-width: 70ch; }
.cookie-banner-text h2 {
  font-size: 1rem;
  margin: 0 0 4px;
}
.cookie-banner-text p {
  margin: 0;
  font-size: .88rem;
  line-height: 1.55;
  color: var(--muted);
}
.cookie-banner-text strong { color: var(--text); }

.cookie-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cookie-banner-actions .btn { flex: 1 1 auto; text-align: center; }

/* consent manager radios */
.consent-option {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px;
  margin-bottom: 12px;
  cursor: pointer;
  background: var(--panel-2, var(--panel));
  transition: border-color .15s ease;
}
.consent-option:hover { border-color: var(--muted); }
.consent-option:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
}
.consent-option input { margin-top: 4px; flex: 0 0 auto; }

/* --------------------------------------------------------- report forms */
.report-card { max-width: 720px; }

/* honeypot · hidden from people, reachable for bots */
.report-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.report-detail {
  margin: 0;
  max-width: 52ch;
  font-size: .9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.report-table td { vertical-align: top; }
.report-table .admin-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ------------------------------------------------------------- desktop */
@media (min-width: 900px) {
  .legal { padding-top: 28px; }

  .legal-layout {
    grid-template-columns: 250px minmax(0, 1fr);
    gap: 34px;
  }

  .legal-toc {
    order: -1;
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    scrollbar-width: thin;
  }
  /* Always expanded on desktop, whatever the phone state left behind. */
  .legal-toc > summary { display: none; }
  .legal-toc > .legal-toc-inner { display: block; padding: 10px 0; }
  .legal-toc::details-content { content-visibility: visible; block-size: auto; }

  .legal-toc a:hover,
  .legal-toc a:focus-visible { border-left-color: var(--accent); }

  .cookie-banner-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
  }
  .cookie-banner-actions { flex-wrap: nowrap; }
  .cookie-banner-actions .btn { flex: 0 0 auto; }
}

/* ----------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  .cookie-banner { animation: none; }
  .legal-toc > summary::after,
  .permalink { transition: none; }
}

/* ---------------------------------------------------------------- print */
@media print {
  .cookie-banner, .legal-toc, .legal-foot, .report-hp { display: none !important; }

  .legal, .legal-body, .legal-head { max-width: none; color: #000; }
  .legal { font-size: 11pt; line-height: 1.45; }
  .legal-layout { display: block; }

  .legal-updated {
    border: 1px solid #999;
    color: #000;
    background: none;
  }

  .legal-section { page-break-inside: avoid; margin-bottom: 18pt; }
  .legal-section h2 { page-break-after: avoid; border-bottom: 1px solid #999; }
  .permalink { display: none; }

  /* Show link targets so a printed policy stays actionable. */
  .legal-body a[href^="http"]::after,
  .legal-body a[href^="mailto:"]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #444;
    word-break: break-all;
  }

  .cookie-table { border: 1px solid #999; background: none; }
  .cookie-table th, .cookie-table td { border-bottom: 1px solid #ccc; }
  .cookie-table thead { display: table-header-group; }
}

/* ==========================================================================
   Importer surfaces: /admin/import and the public /suggest box
   --------------------------------------------------------------------------
   Added with src/views/importer.js. Appended as one block so a concurrent edit
   elsewhere in this file cannot collide with it.
   ========================================================================== */

/* Honeypot. Defined here as well as in reviews.css because these two pages load
   legal.css and not that one · a honeypot the visitor can see is just a field
   people fill in, which turns the spam trap into a bug report. */
.pr-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.imp-tally { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-wrap: wrap; gap: 20px; }
.imp-tally li { color: var(--muted); }
.imp-tally strong { display: block; font-size: 1.5rem; color: var(--text); line-height: 1.1; }

.imp-sources { margin: 0; }
.imp-sources dt { font-weight: 600; margin-top: 12px; }
.imp-sources dd { margin: 2px 0 0; color: var(--muted); line-height: 1.5; }

/* The boundary this whole module exists to hold. It is a rule, not a footnote. */
.imp-forbidden {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid var(--danger);
  border-left-width: 4px;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  line-height: 1.55;
}

.imp-bad { list-style: none; margin: 0; padding: 0; }
.imp-bad li { padding: 4px 0; border-top: 1px solid var(--border-soft); }
.imp-bad code { font-family: var(--font-mono); font-size: .85rem; }

.imp-candidates { list-style: none; margin: 12px 0 0; padding: 0; }
.imp-candidates li { padding: 8px 0; border-top: 1px solid var(--border-soft); }
.imp-candidates form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.imp-candidates code { font-family: var(--font-mono); }

.imp-result { border-left: 3px solid var(--accent); }
