/*
 * GeoCover data model documentation — HTML theme.
 *
 * Applied to the single-file HTML pandoc generates from datamodel.md
 * (`--to html5 --toc --include-in-header=headers.html`). Every selector
 * below targets pandoc's default markup verbatim (header#title-block-header,
 * nav#TOC, plain <table>/<thead>) since the build does not use a custom
 * pandoc template. Palette and layout are adapted from
 * https://download.swissgeol.ch/dm_boreholes/boreholes-data-specification.html
 */

:root {
  --paper: #f2f3f1;
  --surface: #fff;
  --ink: #1d1d1b;
  --ink-soft: #5c6570;
  --ink-faint: #8a9198;
  --rule: #d8dbd7;
  --rule-soft: #e8ebe7;

  --accent: #1f6b80;
  --accent-ink: #14505f;
  --accent-soft: #e4eff2;

  --brand: #a65462;
  --brand-ink: #7e3b47;
  --brand-soft: #f6eaec;

  /* Cyclical rail colors for top-level "Theme" sections (h1) and their
     matching TOC entries — purely decorative, cycle every 9 sections. */
  --rail-1: #2e859d;
  --rail-2: #91581d;
  --rail-3: #b4aa61;
  --rail-4: #706f6f;
  --rail-5: #759964;
  --rail-6: #8072b2;
  --rail-7: #ef7c57;
  --rail-8: #a65462;
  --rail-9: #4a5560;

  --nav-w: 300px;

  --f-disp: "Frutiger", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --f-body: "Frutiger", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --f-mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 1rem;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Reference site wraps content in a `.wrap` (sidebar offset) + `<main>`
   (max-width: 80rem, margin: 0 auto) pair. Pandoc's default HTML5 output has
   no such wrapper — body carries both jobs, so the centering that `margin:
   0 auto` gives `<main>` there has to be reproduced by hand here: offset past
   the fixed sidebar, then add half of whatever's left over past 80rem so the
   column centers in the remaining space instead of hugging the sidebar. */
body {
  margin: 0;
  margin-left: calc(var(--nav-w) + max(0px, (100vw - var(--nav-w) - 80rem) / 2));
  max-width: 80rem;
  padding: 0 clamp(1.25rem, 4vw, 3.4rem) 8rem;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.65 var(--f-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--accent-ink);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

p,
li,
dd {
  max-width: 75ch;
}

code {
  font: 0.875em/1.4 var(--f-mono);
  background: rgba(31, 107, 128, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 2px;
  overflow-wrap: anywhere;
}

pre {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
}

blockquote {
  margin: 1.2rem 0;
  padding: 0.2rem 1.1rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--ink-soft);
}

hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2.5rem 0;
}

/* ---------- headings ---------- */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--f-disp);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--ink);
  scroll-margin-top: 1.25rem;
}

.header-section-number {
  font: 600 0.62em/1 var(--f-mono);
  color: var(--ink-faint);
  margin-right: 0.5em;
  letter-spacing: 0;
  vertical-align: 2%;
}

/* Theme sections: body's direct h1 children, cycling the 9-color rail. */
body > h1 {
  font-size: clamp(1.7rem, 3.2vw, 2.35rem);
  margin: 3.4rem 0 1.1rem;
  padding: 0.7rem 0 0.9rem;
  border-bottom: 3px solid var(--rail-1);
}
body > h1:nth-of-type(9n + 1) { border-color: var(--rail-1); }
body > h1:nth-of-type(9n + 2) { border-color: var(--rail-2); }
body > h1:nth-of-type(9n + 3) { border-color: var(--rail-3); }
body > h1:nth-of-type(9n + 4) { border-color: var(--rail-4); }
body > h1:nth-of-type(9n + 5) { border-color: var(--rail-5); }
body > h1:nth-of-type(9n + 6) { border-color: var(--rail-6); }
body > h1:nth-of-type(9n + 7) { border-color: var(--rail-7); }
body > h1:nth-of-type(9n + 8) { border-color: var(--rail-8); }
body > h1:nth-of-type(9n + 9) { border-color: var(--rail-9); }
body > h1:first-of-type { margin-top: 1.6rem; }

h2 {
  font-size: 1.4rem;
  margin: 2.4rem 0 0.7rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--rule);
}

h3 {
  font-size: 1.1rem;
  margin: 1.7rem 0 0.5rem;
  color: var(--accent-ink);
}

h4,
h5,
h6 {
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 1.3rem 0 0.4rem;
}

/* ---------- title block (cover) ---------- */

header#title-block-header {
  padding: clamp(2.2rem, 7vh, 4rem) 0 2rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
}

header#title-block-header h1.title {
  font-family: var(--f-disp);
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  letter-spacing: -0.02em;
  margin: 0 0 0.4rem;
  border: none;
  padding: 0;
  color: var(--ink);
}

header#title-block-header p.subtitle {
  font-family: var(--f-disp);
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  font-weight: 400;
  color: var(--ink-soft);
  margin: 0 0 1.2rem;
  max-width: 44ch;
}

header#title-block-header p.author,
header#title-block-header p.date {
  display: inline-block;
  font: 600 11px/1.6 var(--f-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 1.4rem 0 0;
}

/* ---------- sidebar table of contents ---------- */

nav#TOC {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--nav-w);
  background: var(--surface);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  z-index: 40;
}

nav#TOC::before {
  content: "Contents";
  flex: none;
  font: 600 11px/1 var(--f-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 1.15rem 1.1rem 0.85rem;
  border-bottom: 1px solid var(--rule-soft);
}

nav#TOC > ul {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 0.5rem 0 3rem;
  list-style: none;
}

nav#TOC ul {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

nav#TOC li {
  margin: 0;
}

nav#TOC a {
  display: block;
  padding: 0.32rem 1.1rem;
  font-size: 0.86rem;
  color: var(--ink-soft);
  text-decoration: none;
  border-left: 3px solid transparent;
}

nav#TOC a:hover,
nav#TOC a:focus-visible {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

nav#TOC .toc-section-number {
  font: 500 0.75em/1 var(--f-mono);
  color: var(--ink-faint);
  margin-right: 0.45em;
}

/* Top level = Theme entries: bold, rail-colored left border. */
nav#TOC > ul > li > a {
  font-family: var(--f-disp);
  font-weight: 600;
  color: var(--ink);
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}
nav#TOC > ul > li:nth-child(9n + 1) > a { border-left-color: var(--rail-1); }
nav#TOC > ul > li:nth-child(9n + 2) > a { border-left-color: var(--rail-2); }
nav#TOC > ul > li:nth-child(9n + 3) > a { border-left-color: var(--rail-3); }
nav#TOC > ul > li:nth-child(9n + 4) > a { border-left-color: var(--rail-4); }
nav#TOC > ul > li:nth-child(9n + 5) > a { border-left-color: var(--rail-5); }
nav#TOC > ul > li:nth-child(9n + 6) > a { border-left-color: var(--rail-6); }
nav#TOC > ul > li:nth-child(9n + 7) > a { border-left-color: var(--rail-7); }
nav#TOC > ul > li:nth-child(9n + 8) > a { border-left-color: var(--rail-8); }
nav#TOC > ul > li:nth-child(9n + 9) > a { border-left-color: var(--rail-9); }

/* Nested (Class) entries: indented, lighter. */
nav#TOC ul ul a {
  padding-left: 1.7rem;
  font-size: 0.82rem;
  border-left-color: var(--rule-soft);
}

nav#TOC ul ul a:hover {
  border-left-color: var(--accent);
}

.navbtn {
  display: none;
}

/* ---------- figures ---------- */

figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin: 1.6rem 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 3px;
}

figure img {
  max-width: 100%;
  height: auto;
}

figcaption {
  margin-top: 0.7rem;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------- tables ---------- */

table {
  width: 100%;
  margin: 1rem 0 1.8rem;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--rule-soft);
  font-size: 0.88rem;
}

caption {
  caption-side: top;
  text-align: left;
  font: 600 0.78rem/1.4 var(--f-mono);
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}

th,
td {
  padding: 0.5rem 0.7rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--rule-soft);
}

table thead tr,
h2 + p + table thead tr {
  background: var(--accent-ink);
  color: #fff;
}

thead th {
  font: 600 0.72rem/1.4 var(--f-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

tbody tr:nth-of-type(even) {
  background: var(--paper);
}

tbody tr:hover {
  background: var(--accent-soft);
}

tbody tr:last-of-type {
  border-bottom: 2px solid var(--accent-ink);
}

/* Sortable-table affordance (see sortable.html) */
th[data-sortable] {
  cursor: grab;
  user-select: none;
  position: relative;
  transition: background-color 0.15s ease;
}

th[data-sortable]:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

th[data-sortable]:active {
  cursor: grabbing;
}

th.sort-asc::after,
th.sort-desc::after {
  opacity: 0.85;
  font-size: 0.9em;
  margin-left: 0.35em;
}

th.sort-asc::after {
  content: "▲";
}

th.sort-desc::after {
  content: "▼";
}

/* ---------- back-to-top ---------- */

.totop {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--rule);
  padding: 0.5rem 0.75rem;
  font: 600 11px/1 var(--f-mono);
  text-decoration: none;
  color: var(--ink);
  border-radius: 2px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.totop.on {
  opacity: 1;
  pointer-events: auto;
}

.totop:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ---------- narrow screens ---------- */

@media (max-width: 960px) {
  :root {
    --nav-w: 0px;
  }

  body {
    padding-top: 3.6rem;
  }

  .navbtn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    position: fixed;
    top: 0.7rem;
    left: 0.7rem;
    z-index: 50;
    background: var(--surface);
    border: 1px solid var(--rule);
    padding: 0.55rem 0.8rem;
    font: 600 12px/1 var(--f-mono);
    border-radius: 2px;
    cursor: pointer;
    color: var(--ink);
  }

  nav#TOC {
    width: min(21rem, 88vw);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
  }

  nav#TOC.open {
    transform: none;
  }
}

/* ---------- print ---------- */

@media print {
  nav#TOC,
  .navbtn,
  .totop {
    display: none !important;
  }

  body {
    margin-left: 0;
    background: #fff;
    padding: 0;
  }

  a {
    color: #000;
  }

  table {
    break-inside: avoid;
  }
}
