/* ===========================================================================
   PEARL Radix — design system
   Paper-white brand surface, near-black ink, hairline rules, wide-tracked
   micro labels. Everything derives from the tokens below.
   ========================================================================= */

:root {
  --paper:      #f4f1ea;
  --paper-2:    #ece8de;
  --paper-3:    #e2ddd1;
  --card:       #fbf9f5;
  --ink:        #232320;
  --ink-2:      #56534c;
  --ink-3:      #8b857a;
  --line:       rgba(35, 35, 32, 0.14);
  --line-2:     rgba(35, 35, 32, 0.08);
  --ok:         #3d6b52;
  --warn:       #94661f;
  --err:        #97382c;
  --shadow:     0 1px 2px rgba(35,35,32,.05), 0 8px 24px -12px rgba(35,35,32,.18);

  --r-sm: 4px;
  --r:    8px;
  --r-lg: 16px;

  --step: 0.25rem;
  --measure: 68ch;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:   #1a1917;
    --paper-2: #22211e;
    --paper-3: #2b2a26;
    --card:    #201f1c;
    --ink:     #f2eee5;
    --ink-2:   #b3ada1;
    --ink-3:   #8b857a;
    --line:    rgba(242, 238, 229, 0.15);
    --line-2:  rgba(242, 238, 229, 0.08);
    --ok:      #7fb894;
    --warn:    #d2a45c;
    --err:     #e08a7c;
    --shadow:  0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
  }
}

/* --------------------------------------------------------------- reset -- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg { max-width: 100%; }
a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 600; letter-spacing: -0.015em; line-height: 1.18; }
h1 { font-size: clamp(2rem, 1.3rem + 2.6vw, 3.1rem); }
h2 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.85rem); }
h3 { font-size: 1.12rem; }
p  { margin: 0 0 1em; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: var(--r-sm); }

/* ---------------------------------------------------------- primitives -- */

.wrap { width: min(1180px, 100% - 3rem); margin-inline: auto; }
.wrap--narrow { width: min(760px, 100% - 3rem); }
@media (max-width: 640px) { .wrap, .wrap--narrow { width: calc(100% - 2rem); } }

.eyebrow {
  font-size: .69rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  margin: 0 0 .75rem;
}
.eyebrow--ink { color: var(--ink); }

.lede { font-size: 1.08rem; color: var(--ink-2); max-width: var(--measure); }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.mono  { font-family: var(--mono); font-size: .86em; }
.nowrap { white-space: nowrap; }

.rule { height: 1px; background: var(--line); border: 0; margin: 3rem 0; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.spacer { flex: 1 1 auto; }

/* -------------------------------------------------------------- header -- */

.masthead {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.masthead__inner { display: flex; align-items: center; gap: 1.5rem; height: 68px; }

.brand { display: inline-flex; align-items: center; gap: .7rem; text-decoration: none; }
.brand__mark { width: 30px; height: 30px; color: var(--ink); flex: none; }
.brand__word { font-size: 1.05rem; letter-spacing: .01em; }
.brand__word b { font-weight: 700; letter-spacing: .02em; }
.brand__word span { font-weight: 400; }

.nav { display: flex; gap: 1.5rem; align-items: center; margin-left: auto; }
.nav a {
  font-size: .82rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-2); text-decoration: none; padding: .3rem 0;
  border-bottom: 1px solid transparent;
}
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }
@media (max-width: 720px) {
  .nav { gap: 1rem; }
  .nav a { font-size: .72rem; letter-spacing: .06em; }
  .brand__word { display: none; }
}

/* --------------------------------------------------------------- hero -- */

.hero { padding: clamp(3rem, 8vw, 6.5rem) 0 clamp(2rem, 5vw, 4rem); }
.hero__grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 3rem; align-items: center; }
.hero__mark { width: min(320px, 100%); color: var(--ink); justify-self: center; }
@media (max-width: 860px) {
  .hero__grid { grid-template-columns: 1fr; }
  .hero__mark { width: 190px; order: -1; justify-self: start; }
}

.tagline {
  font-size: .72rem; letter-spacing: .24em; text-transform: uppercase; color: var(--ink-3);
}

/* ------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  font: inherit; font-size: .9rem; font-weight: 500;
  padding: .55rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent; color: var(--ink);
  cursor: pointer; text-decoration: none;
  transition: background .14s ease, border-color .14s ease, color .14s ease, transform .14s ease;
}
.btn:hover { border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn--primary:hover { background: color-mix(in srgb, var(--ink) 84%, var(--paper)); }
.btn--sm { font-size: .8rem; padding: .34rem .8rem; }
.btn--ghost { border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { color: var(--ink); border-color: var(--line); }
.btn--danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.btn--danger:hover { background: color-mix(in srgb, var(--err) 10%, transparent); border-color: var(--err); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }

/* --------------------------------------------------------------- chips -- */

.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .7rem; letter-spacing: .09em; text-transform: uppercase; font-weight: 500;
  padding: .22rem .6rem; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink-2); background: var(--paper-2);
  text-decoration: none; white-space: nowrap;
}
a.chip:hover { border-color: var(--ink); color: var(--ink); }
.chip--solid { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip--ok    { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.chip--warn  { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.chip--err   { color: var(--err);  border-color: color-mix(in srgb, var(--err) 35%, transparent); }

/* --------------------------------------------------------------- cards -- */

.grid { display: grid; gap: 1.25rem; }
.grid--cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.card {
  display: flex; flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 1.35rem;
  text-decoration: none;
  transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}
a.card:hover { border-color: var(--ink); transform: translateY(-2px); box-shadow: var(--shadow); }
.card__head { display: flex; align-items: flex-start; gap: .75rem; }
.card__title { font-size: 1.06rem; font-weight: 600; margin: 0; }
.card__pub { font-size: .78rem; color: var(--ink-3); letter-spacing: .06em; text-transform: uppercase; }
.card__summary { color: var(--ink-2); font-size: .9rem; margin: .75rem 0 1rem; }
.card__meta {
  display: flex; flex-wrap: wrap; gap: .4rem; margin-top: auto;
  padding-top: .9rem; border-top: 1px solid var(--line-2);
}
.card__mark { width: 26px; height: 26px; color: var(--ink-3); flex: none; margin-left: auto; }

/* --------------------------------------------------------------- stats -- */

.stat { border-left: 2px solid var(--ink); padding-left: .9rem; }
.stat__n { font-size: 1.7rem; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.stat__k { font-size: .68rem; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-3); }

/* -------------------------------------------------------------- fields -- */

.field { display: block; margin-bottom: 1.1rem; }
.field__label {
  display: block; font-size: .7rem; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: .4rem; font-weight: 500;
}
.field__hint { font-size: .8rem; color: var(--ink-3); margin-top: .35rem; }
.field__error { font-size: .8rem; color: var(--err); margin-top: .35rem; }

.input, .select, .textarea {
  width: 100%; font: inherit; font-size: .92rem; color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: .58rem .75rem;
  transition: border-color .14s ease, box-shadow .14s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 10%, transparent);
}
.textarea { min-height: 9rem; resize: vertical; font-family: var(--mono); font-size: .85rem; line-height: 1.6; }
.input--invalid { border-color: var(--err); }
.select { appearance: none; padding-right: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}

.search {
  position: relative; display: flex; align-items: center; gap: .6rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); padding: .1rem .3rem .1rem 1rem;
}
.search:focus-within { border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 8%, transparent); }
.search input { flex: 1; border: 0; background: none; font: inherit; padding: .7rem 0; color: var(--ink); }
.search input:focus { outline: none; }

.grid--form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 1.25rem; }

/* --------------------------------------------------------------- table -- */

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  text-align: left; font-size: .66rem; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 500; padding: .6rem .75rem; border-bottom: 1px solid var(--line);
}
.table td { padding: .7rem .75rem; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:hover td { background: var(--paper-2); }
.table__scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--card); }
.table--flush { margin: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- filters -- */

.layout--catalog { display: grid; grid-template-columns: 232px 1fr; gap: 2.5rem; align-items: start; }
@media (max-width: 900px) { .layout--catalog { grid-template-columns: 1fr; gap: 1.5rem; } }

.facets { position: sticky; top: 92px; }
.facet + .facet { margin-top: 1.6rem; }
.facet__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .1rem; }
.facet__list a {
  display: flex; justify-content: space-between; gap: .5rem;
  font-size: .88rem; color: var(--ink-2); text-decoration: none;
  padding: .28rem .5rem; border-radius: var(--r-sm);
}
.facet__list a:hover { background: var(--paper-2); color: var(--ink); }
.facet__list a[aria-current="true"] { background: var(--ink); color: var(--paper); }
.facet__list .n { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: .8rem; }
.facet__list a[aria-current="true"] .n { color: var(--paper); opacity: .7; }

/* ---------------------------------------------------------- model page -- */

.layout--model { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 3rem; align-items: start; }
@media (max-width: 900px) { .layout--model { grid-template-columns: 1fr; gap: 2rem; } }

.prose { max-width: var(--measure); }
.prose h2 { margin-top: 2rem; font-size: 1.25rem; }
.prose h3 { margin-top: 1.5rem; }
.prose code { font-family: var(--mono); font-size: .88em; background: var(--paper-2); padding: .12em .38em; border-radius: var(--r-sm); }
.prose pre {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--r);
  padding: 1rem; overflow-x: auto; font-family: var(--mono); font-size: .84rem; line-height: 1.6;
}
.prose pre code { background: none; padding: 0; }
.prose ul { padding-left: 1.2rem; }

.specs { list-style: none; margin: 0; padding: 0; }
.specs li { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--line-2); font-size: .89rem; }
.specs dt, .specs .k { color: var(--ink-3); font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; }
.specs .v { text-align: right; }

.filerow { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: center; padding: .95rem 1.1rem; border-bottom: 1px solid var(--line-2); }
.filerow:last-child { border-bottom: 0; }
.filerow__name { font-family: var(--mono); font-size: .86rem; word-break: break-all; }
.filerow__meta { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .35rem; }

.copyline {
  display: flex; align-items: center; gap: .5rem;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--paper-2); padding: .55rem .75rem;
  font-family: var(--mono); font-size: .8rem; overflow: hidden;
}
.copyline code { flex: 1; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
.copyline code::-webkit-scrollbar { display: none; }

/* ------------------------------------------------------------- alerts -- */

.alert { border: 1px solid var(--line); border-left-width: 3px; border-radius: var(--r); padding: .8rem 1rem; font-size: .9rem; background: var(--card); }
.alert--ok   { border-left-color: var(--ok); }
.alert--warn { border-left-color: var(--warn); }
.alert--error{ border-left-color: var(--err); }

.empty { text-align: center; padding: 4rem 1rem; color: var(--ink-3); border: 1px dashed var(--line); border-radius: var(--r-lg); }
.empty svg { width: 56px; height: 56px; opacity: .35; margin-bottom: 1rem; }

/* ------------------------------------------------------------- toasts -- */

#toasts { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 90; display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, calc(100vw - 2.5rem)); }
.toast {
  background: var(--ink); color: var(--paper);
  border-radius: var(--r); padding: .7rem 1rem; font-size: .87rem;
  box-shadow: var(--shadow); animation: toast-in .18s ease-out;
}
.toast--warn  { background: var(--warn); color: #fff; }
.toast--error { background: var(--err);  color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------- htmx states -- */

.htmx-indicator { opacity: 0; transition: opacity .15s ease; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.htmx-swapping { opacity: .4; transition: opacity .1s ease; }
.htmx-settling { opacity: 1; }
#results.htmx-request { opacity: .5; transition: opacity .12s ease; }

.spinner { width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress { height: 3px; background: var(--paper-3); border-radius: 999px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--ink); width: 0; transition: width .2s ease; }

/* -------------------------------------------------------------- admin -- */

.admin-shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
@media (max-width: 820px) { .admin-shell { grid-template-columns: 1fr; } }

.sidebar { border-right: 1px solid var(--line); padding: 1.5rem 1.25rem; background: var(--paper-2); }
.sidebar__nav { list-style: none; margin: 1.5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .15rem; }
.sidebar__nav a { display: block; padding: .45rem .7rem; border-radius: var(--r-sm); font-size: .9rem; color: var(--ink-2); text-decoration: none; }
.sidebar__nav a:hover { background: var(--paper-3); color: var(--ink); }
.sidebar__nav a[aria-current="page"] { background: var(--ink); color: var(--paper); }
@media (max-width: 820px) {
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar__nav { flex-direction: row; flex-wrap: wrap; }
}
.admin-main { padding: 2rem clamp(1rem, 3vw, 2.5rem) 5rem; min-width: 0; }
.page-head { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.page-head h1 { font-size: 1.7rem; margin: 0; }

.panel { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--card); padding: 1.4rem; }
.panel + .panel { margin-top: 1.25rem; }
.panel__head { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.panel__head h2 { margin: 0; font-size: 1.05rem; }

.sparkline { display: flex; align-items: flex-end; gap: 2px; height: 56px; }
.sparkline span { flex: 1; background: var(--ink); border-radius: 1px 1px 0 0; min-height: 2px; opacity: .8; }
.sparkline span:hover { opacity: 1; }

/* -------------------------------------------------------------- footer -- */

.footer { border-top: 1px solid var(--line); margin-top: 5rem; padding: 2.5rem 0 3rem; font-size: .84rem; color: var(--ink-3); }
.footer__inner { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: center; }
.footer a { color: var(--ink-2); text-decoration: none; }
.footer a:hover { color: var(--ink); }

/* ------------------------------------------------------------ utility -- */

/* Class selectors like .field { display: block } outrank the UA rule for
   [hidden], so restate it with force. */
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

@media print {
  .masthead, .footer, .facets, .btn { display: none !important; }
  body { background: #fff; color: #000; }
}
