/* Tago legal pages — tokens mirror design.md (§2 color, §3 type, §4 spacing).
   Static HTML served from /public, so tokens are redeclared here rather than
   imported from the app's globals.css. Keep the values in lockstep. */
:root {
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-primary: #1e3a5f;
  --color-accent: #2563eb;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-warning: #d97706;
  --color-warning-text: #b45309;
  --font-display: "IBM Plex Sans Thai", "IBM Plex Sans", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", "IBM Plex Sans Thai", system-ui, sans-serif;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-6: 48px;
  --space-8: 64px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgb(17 24 39 / 0.04), 0 1px 3px rgb(17 24 39 / 0.06);
  --measure: 68ch;
  --toc-width: 240px;
}

* {
  box-sizing: border-box;
}
html {
  color-scheme: light;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:lang(th) {
  font-family: var(--font-display);
  line-height: 1.85;
}

a {
  color: var(--color-accent);
  text-underline-offset: 0.15em;
}
a:hover {
  color: var(--color-primary);
}
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------- shell */
main {
  max-width: 1120px;
  margin: 0 auto;
  /* No top padding: the sticky header must sit flush with the viewport edge
     or scrolled content shows through the strip above it. */
  padding: 0 var(--space-2) var(--space-8);
}

header.brand {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin: 0 calc(-1 * var(--space-2)) var(--space-6);
  padding: 14px var(--space-2);
  background: color-mix(in srgb, var(--color-bg) 96%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
}
header.brand a.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  color: var(--color-primary);
  text-decoration: none;
  letter-spacing: -0.01em;
}
/* Two stones — a quiet nod to the board without shipping an image. */
header.brand a.logo::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-primary);
  box-shadow:
    10px 6px 0 -1px var(--color-surface),
    10px 6px 0 0 var(--color-primary);
  margin-right: 10px;
}

nav.lang {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
}
nav.lang a {
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  color: var(--color-text-muted);
  text-decoration: none;
  padding: 8px 14px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  transition:
    background-color 150ms ease-out,
    color 150ms ease-out;
}
nav.lang a:hover {
  color: var(--color-primary);
  background: var(--color-bg);
}

/* ------------------------------------------------- language switching
   Pure CSS: with no hash both languages stack (crawlers, print, old
   browsers without :has). Targeting a language — or any heading inside
   it, e.g. from its own table of contents — shows only that language and
   lights up its pill. */
main:has(#th:target, #th :target) section#en {
  display: none;
}
main:has(#en:target, #en :target) section#th {
  display: none;
}
/* Solo language view: drop the divider that only makes sense when stacked. */
main:has(#th:target, #th :target) section#th {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
main:has(#th:target, #th :target) nav.lang a[hreflang="th"],
main:has(#en:target, #en :target) nav.lang a[hreflang="en"] {
  color: var(--color-surface);
  background: var(--color-primary);
}

/* ---------------------------------------------------------------- doc */
section.doc {
  scroll-margin-top: 72px;
}
section.doc + section.doc {
  margin-top: var(--space-8);
  padding-top: var(--space-8);
  border-top: 1px solid var(--color-border);
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(30px, 4vw, 40px);
  line-height: 1.15;
  font-weight: 600;
  color: var(--color-primary);
  margin: 0 0 var(--space-1);
  letter-spacing: -0.02em;
  max-width: var(--measure);
}
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-2);
  color: var(--color-text-muted);
  font-size: 14px;
  margin: 0 0 var(--space-4);
}

h2 {
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.3;
  font-weight: 600;
  color: var(--color-primary);
  margin: var(--space-6) 0 var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
  scroll-margin-top: 80px;
}
h2:first-of-type {
  border-top: 0;
  padding-top: 0;
  margin-top: var(--space-4);
}
h3 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  margin: var(--space-3) 0 var(--space-1);
  scroll-margin-top: 80px;
}
p,
li {
  margin: 0 0 var(--space-2);
  max-width: var(--measure);
}
li {
  margin-bottom: var(--space-1);
}
ul,
ol {
  padding-left: var(--space-3);
  margin: 0 0 var(--space-2);
}
li::marker {
  color: var(--color-text-muted);
}
strong {
  font-weight: 600;
  color: var(--color-text);
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3);
  margin: var(--space-3) 0;
  max-width: var(--measure);
}
.card p:last-child {
  margin-bottom: 0;
}

.table-wrap {
  overflow-x: auto;
  margin: var(--space-3) 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.55;
  min-width: 520px;
}
th,
td {
  text-align: left;
  vertical-align: top;
  padding: 12px var(--space-2);
  border-bottom: 1px solid var(--color-border);
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--color-bg) 60%, var(--color-surface));
}
th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--color-bg);
}
th:lang(th) {
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
}
td:first-child {
  font-weight: 500;
}

mark.todo {
  background: color-mix(in srgb, var(--color-warning) 16%, transparent);
  color: var(--color-warning-text);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-style: italic;
}

/* ---------------------------------------------------------------- toc */
nav.toc {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-4);
}
nav.toc .toc-title {
  margin: 0 0 var(--space-1);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
nav.toc .toc-title:lang(th) {
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
}
nav.toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
  columns: 2;
  column-gap: var(--space-3);
}
nav.toc li {
  margin: 0;
  break-inside: avoid;
  max-width: none;
}
nav.toc a {
  display: block;
  padding: 6px 8px;
  margin: 0 -8px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--color-text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition:
    background-color 150ms ease-out,
    color 150ms ease-out;
}
nav.toc a:hover {
  background: var(--color-bg);
  color: var(--color-primary);
}
nav.toc a:active {
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
}

.back-to-top {
  margin: var(--space-6) 0 0;
  font-size: 14px;
}
.back-to-top a {
  color: var(--color-text-muted);
  text-decoration: none;
}
.back-to-top a:hover {
  color: var(--color-primary);
}

/* ---------------------------------------------------------- footer */
footer.legal-footer {
  margin-top: var(--space-8);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: space-between;
}
footer.legal-footer a {
  color: var(--color-text-muted);
}
footer.legal-footer a:hover {
  color: var(--color-primary);
}

/* ------------------------------------------------------- desktop ≥1024
   Sticky table of contents beside the document; the doc body keeps its
   reading measure. */
@media (min-width: 1024px) {
  section.doc {
    display: grid;
    grid-template-columns: var(--toc-width) minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    column-gap: var(--space-8);
    align-items: start;
  }
  section.doc > h1 {
    grid-column: 2;
    grid-row: 1;
  }
  section.doc > .meta {
    grid-column: 2;
    grid-row: 2;
    margin-bottom: var(--space-2);
  }
  section.doc > nav.toc {
    grid-column: 1;
    grid-row: 1 / span 3;
    position: sticky;
    top: 80px;
    max-height: calc(100dvh - 96px);
    overflow-y: auto;
    margin: 0;
  }
  section.doc > nav.toc ol {
    columns: 1;
  }
  section.doc > .doc-body {
    grid-column: 2;
    grid-row: 3;
    min-width: 0;
  }
  section.doc > .doc-body h2:first-of-type {
    margin-top: var(--space-2);
  }
}

@media (max-width: 480px) {
  header.brand {
    margin-bottom: var(--space-4);
  }
  nav.lang a {
    padding: 8px 12px;
  }
  nav.toc ol {
    columns: 1;
  }
  .card {
    padding: var(--space-2);
  }
}

/* ---------------------------------------------------------------- print */
@media print {
  html {
    scroll-behavior: auto;
  }
  body {
    background: #fff;
    font-size: 11pt;
  }
  main {
    max-width: none;
    padding: 0;
  }
  header.brand {
    position: static;
    border: 0;
    backdrop-filter: none;
  }
  nav.lang,
  nav.toc,
  .back-to-top,
  footer.legal-footer {
    display: none;
  }
  main:has(#th:target, #th :target) section#en,
  main:has(#en:target, #en :target) section#th {
    display: block;
  }
  section.doc {
    display: block;
  }
  section.doc + section.doc {
    page-break-before: always;
    border: 0;
    padding-top: 0;
    margin-top: 0;
  }
  h2 {
    break-after: avoid;
  }
  .table-wrap,
  .card {
    box-shadow: none;
    break-inside: avoid;
  }
  a {
    color: inherit;
    text-decoration: none;
  }
  mark.todo {
    background: none;
    border: 1px dashed var(--color-warning);
  }
}
