/* =============================================================================
   doc.css — the document reader.

   Legal text is the one thing on this site people actually READ, start to
   finish, and may need to quote or archive. So it gets a reading layout
   rather than a page layout: a measured column, a sticky table of contents
   that tracks where you are, a progress bar, and a real paginated PDF.
   ============================================================================= */

.doc-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: var(--space-7);
  max-width: 1100px;
  margin-inline: auto;
  padding: var(--space-6) var(--space-5) var(--space-9);
  align-items: start;
}

/* -----------------------------------------------------------------------------
   Reading progress — a thin bar, because in a document the question is always
   "how much is left".
   ----------------------------------------------------------------------------- */
.doc-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--accent-fill);
  transform-origin: 0 50%;
  transform: scaleX(0);
  z-index: 60;
  transition: transform 90ms linear;
}

/* -----------------------------------------------------------------------------
   Table of contents. Sticky, with scroll-spy -- in a 17-section contract,
   knowing which clause you are in matters more than knowing the list exists.
   ----------------------------------------------------------------------------- */
.doc-toc {
  position: sticky;
  top: var(--space-5);
  max-height: calc(100dvh - var(--space-7));
  overflow-y: auto;
  padding-right: var(--space-2);
}

.doc-toc h2 {
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: var(--space-3);
}

.doc-toc ol { list-style: none; margin: 0; padding: 0; counter-reset: toc; }

.doc-toc a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-left: 2px solid var(--line);
  color: var(--ink-2);
  text-decoration: none;
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  transition: border-color var(--transition), color var(--transition),
    background var(--transition);
}

.doc-toc a:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }

.doc-toc a[aria-current='true'] {
  border-left-color: var(--accent);
  color: var(--ink);
  font-weight: var(--weight-semi);
  background: var(--accent-soft);
}

.doc-toc-actions { display: grid; gap: var(--space-2); margin-top: var(--space-5); }

/* -----------------------------------------------------------------------------
   The document column
   ----------------------------------------------------------------------------- */
.doc {
  max-width: 72ch;
  /* Slightly larger and looser than UI text: this is read in paragraphs, not
     scanned in rows. */
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--ink-2);
}

.doc-header { border-bottom: 1px solid var(--line); padding-bottom: var(--space-5); margin-bottom: var(--space-6); }
.doc-header h1 { font-size: clamp(1.9rem, 4vw, 2.5rem); margin-bottom: var(--space-3); }

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  color: var(--ink-3);
}

.doc-meta span { display: inline-flex; align-items: center; gap: var(--space-1); }

.doc section { scroll-margin-top: var(--space-6); }

.doc h2 {
  font-size: var(--text-lg);
  margin: var(--space-7) 0 var(--space-3);
  padding-top: var(--space-2);
  scroll-margin-top: var(--space-6);
  position: relative;
}

.doc h3 {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  margin: var(--space-5) 0 var(--space-2);
  color: var(--ink);
}

.doc p { margin-bottom: var(--space-4); }
.doc ul, .doc ol { margin: 0 0 var(--space-4) var(--space-5); }
.doc li { margin-bottom: var(--space-2); }
.doc strong { color: var(--ink); font-weight: var(--weight-semi); }
.doc dfn { font-style: normal; font-weight: var(--weight-semi); color: var(--ink); }

/* A permalink per clause: legal text gets cited, and "section 7" is a worse
   reference than a URL that scrolls there. */
.doc .anchor {
  opacity: 0;
  margin-left: var(--space-2);
  font-size: var(--text-sm);
  color: var(--ink-3);
  text-decoration: none;
  transition: opacity var(--transition);
}

.doc h2:hover .anchor,
.doc .anchor:focus-visible { opacity: 1; }

/* The statute a clause rests on. */
.doc .law {
  display: block;
  font-size: var(--text-sm);
  color: var(--ink-3);
  border-left: 3px solid var(--accent);
  padding: var(--space-2) 0 var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
  line-height: var(--leading-normal);
}

.doc .callout {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  margin: var(--space-5) 0;
}

.doc .callout p:last-child { margin-bottom: 0; }

.doc .review-banner {
  border: 1px solid var(--warn);
  background: var(--warn-soft);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-6);
  font-size: var(--text-sm);
  color: var(--ink);
}

.doc .fill {
  background: var(--warn-soft);
  border-bottom: 1px dashed var(--warn);
  padding: 0 4px;
  color: var(--ink);
  font-weight: var(--weight-semi);
}

.doc-footer {
  margin-top: var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line);
  font-size: var(--text-sm);
  color: var(--ink-3);
}

@media (max-width: 900px) {
  .doc-shell { grid-template-columns: 1fr; gap: var(--space-5); }
  .doc-toc {
    position: static;
    max-height: none;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-4);
    background: var(--surface);
  }
  .doc-toc ol { columns: 2; column-gap: var(--space-5); }
  .doc-toc a { border-left: 0; padding: var(--space-2) 0; }
  .doc-toc-actions { grid-auto-flow: column; }
}

@media (max-width: 560px) {
  .doc-toc ol { columns: 1; }
  .doc-toc-actions { grid-auto-flow: row; }
}

/* =============================================================================
   PRINT

   Two ways to get a paginated document out of this page, on purpose:

     1. "Shkarko PDF"  -> doc-reader.js builds a real PDF with pdf-lib:
                          selectable text, page numbers, a cover page.
     2. Ctrl+P          -> this stylesheet. Perfect typographic fidelity,
                          because the browser is doing the layout.

   A legal document must be searchable and quotable, so neither path
   rasterises the text. A screenshot-to-PDF would be unusable for the one
   thing people actually do with terms: find the clause they need.
   ============================================================================= */
@media print {
  @page {
    size: A4;
    margin: 20mm 18mm;
  }

  /* Print is always light, whatever surface the screen was showing. */
  :root,
  [data-surface='public'],
  [data-surface='console'] {
    --page: #ffffff;
    --surface: #ffffff;
    --surface-2: #ffffff;
    --ink: #000000;
    --ink-2: #1a1a1a;
    --ink-3: #4a4a4a;
    --line: #cccccc;
    --accent: #000000;
    --accent-soft: #f2f2f2;
    --warn: #000000;
    --warn-soft: #f6f6f6;
  }

  body { background: #fff; font-size: 10.5pt; line-height: 1.5; }

  /* Chrome drops backgrounds by default, which would erase the callouts. */
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Navigation, controls and the progress bar are screen furniture. */
  .bar,
  .site-footer,
  .doc-toc,
  .doc-progress,
  .toast,
  .skip-link,
  .doc .anchor { display: none !important; }

  .doc-shell { display: block; max-width: none; padding: 0; }
  .doc { max-width: none; font-size: 10.5pt; }

  .doc-header { border-bottom: 1pt solid #000; }
  .doc-header h1 { font-size: 20pt; }

  /* A clause must not be split from its heading, and a heading must never be
     the last thing on a page. */
  .doc h2 {
    font-size: 13pt;
    break-after: avoid;
    break-inside: avoid;
    margin-top: 16pt;
  }

  .doc h3 { font-size: 11pt; break-after: avoid; }
  .doc p, .doc li { orphans: 3; widows: 3; }
  .doc .callout, .doc .law, .doc .review-banner, .doc ul, .doc ol { break-inside: avoid; }

  /* Expand links so a printed copy is still actionable. */
  .doc a[href^='http']::after {
    content: ' (' attr(href) ')';
    font-size: 9pt;
    color: #444;
    word-break: break-all;
  }

  .doc a[href^='#']::after,
  .doc a[href^='/']::after { content: ''; }
}

/* =============================================================================
   Document catalog (/dokumentet.html)

   Documents as objects you pick up, not links buried in a footer. The spine
   down the left is the tell: it reads as a shelf, which is the right metaphor
   for "everything that governs this platform, in one place".
   ============================================================================= */
.doc-hero {
  background: var(--bar-bg);
  color: var(--bar-ink);
  padding-block: var(--space-7) var(--space-8);
}

.doc-hero h1 {
  color: var(--bar-ink);
  font-size: clamp(1.9rem, 4.5vw, 2.6rem);
  max-width: 20ch;
  margin-block: var(--space-3);
}

.doc-hero p { color: var(--bar-ink-2); max-width: 56ch; }

.doc-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: var(--space-5);
  margin-top: calc(var(--space-7) * -1);
  position: relative;
  z-index: 2;
  padding-bottom: var(--space-6);
}

.doc-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition),
    border-color var(--transition);
}

a.doc-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
  text-decoration: none;
}

/* The spine: vertical lettering, like a book turned edge-on. */
.doc-card-spine {
  background: var(--brand-navy);
  color: var(--brand-gold);
  display: grid;
  place-items: center;
  font-weight: var(--weight-bold);
  letter-spacing: 0.16em;
  font-size: var(--text-xs);
  border-right: 2px solid var(--brand-gold);
  padding-block: var(--space-4);
}

.doc-card-spine span { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; }

.doc-card-body { padding: var(--space-5); display: grid; gap: var(--space-3); align-content: start; }
.doc-card-body h2 { font-size: var(--text-lg); }
.doc-card-body p { font-size: var(--text-sm); color: var(--ink-2); line-height: var(--leading-normal); }

.doc-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-1);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}

.doc-card-meta div { display: grid; gap: 1px; }
.doc-card-meta dt {
  font-size: var(--text-xs);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}
.doc-card-meta dd { margin: 0; font-size: var(--text-sm); font-weight: var(--weight-semi); }

.doc-card-go {
  display: grid;
  place-items: center;
  padding-inline: var(--space-5);
  color: var(--ink-3);
  font-size: var(--text-lg);
  transition: color var(--transition), transform var(--transition);
}

a.doc-card:hover .doc-card-go { color: var(--accent); transform: translateX(4px); }

.doc-card.is-upcoming { opacity: 0.6; box-shadow: none; }
.doc-card.is-upcoming .doc-card-spine {
  background: var(--surface-2);
  color: var(--ink-3);
  border-right-color: var(--line);
}

.doc-note {
  border-left: 3px solid var(--warn);
  background: var(--warn-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: var(--space-5);
  margin-bottom: var(--space-8);
}

.doc-note h3 { font-size: var(--text-base); margin-bottom: var(--space-2); }
.doc-note p { font-size: var(--text-sm); color: var(--ink-2); max-width: 70ch; }

@media (max-width: 560px) {
  .doc-catalog { grid-template-columns: 1fr; margin-top: calc(var(--space-6) * -1); }
  .doc-card { grid-template-columns: 44px minmax(0, 1fr); }
  .doc-card-go { display: none; }
}
