/* ════════════════════════════════════════════════════════════════════════
   APEX FI — certification register

   Type   Title 22/32 and 18/24 at -1%; body 14/20 and 12/16 at 0%.
          Uppercase micro-labels are the one exception, at +4%.
   Space  Everything on a 4px grid.
   Colour Primary #1C1C1C, secondary #8A8A8A, tertiary #B3B3B3, fixed across
          all themes. Themes re-tint the stock and the accent only.
   Rules  No left keylines anywhere — separation comes from the full border,
          the fill, and the method colour in the label itself.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  /* stock — cool grey, deliberately not white (theme: steel) */
  --paper:       #dde2e6;
  --card:        #f4f6f7;
  --card-sunk:   #e9edf0;
  --line:        #c9d1d8;
  --line-soft:   #dbe1e6;

  /* text */
  --ink:         #1c1c1c;   /* primary   */
  --ink-2:       #8a8a8a;   /* secondary */
  --ink-3:       #b3b3b3;   /* tertiary  */

  /* accent */
  --steel:       #1c4f72;
  --steel-tint:  #dde8ef;

  /* outcome */
  --pass:        #1c6440;
  --pass-tint:   #dcebe1;
  --fail:        #9c3126;
  --fail-tint:   #f2ddd9;

  /* method hues, drawn from each technique's own world */
  --m-vt:   #2c6382;   /* visual        */
  --m-pt:   #a8394e;   /* dye penetrant */
  --m-mt:   #766610;   /* fluorescent   */
  --m-rt:   #6a4794;   /* radiographic  */
  --m-ut:   #10635f;   /* ultrasonic    */
  --m-paut: #3a4a99;   /* phased array  */
  --m-none: #8a8a8a;

  --radius:  8px;
  --shadow:  0 1px 1px rgb(28 28 28 / .04), 0 8px 24px -20px rgb(28 28 28 / .45);

  --display: "IBM Plex Sans Condensed", "Arial Narrow", sans-serif;
  --sans:    "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono:    "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ── light theme variants ───────────────────────────────────────────────
   Stock and accent only. Text tiers and the method hues never move, so a
   record reads the same whichever variant is chosen. */

:root[data-theme="paper"] {   /* warm manila */
  --paper: #e3ddd2;  --card: #f7f4ee;  --card-sunk: #efeae0;
  --line:  #d2c9b9;  --line-soft: #e2dbcd;
  --steel: #6a4a1f;  --steel-tint: #eee3d2;
}

:root[data-theme="mist"] {    /* pale eucalyptus */
  --paper: #dae4e0;  --card: #f2f7f5;  --card-sunk: #e6eeeb;
  --line:  #c2d2cc;  --line-soft: #d8e3df;
  --steel: #1a5c4c;  --steel-tint: #d9ebe4;
}

:root[data-theme="slate"] {   /* deeper grey, lowest glare */
  --paper: #cdd2d7;  --card: #e8ecef;  --card-sunk: #dde2e6;
  --line:  #b6bec6;  --line-soft: #cdd4da;
  --steel: #29455c;  --steel-tint: #d4dee5;
}

:root[data-theme="apex"] {    /* APEX-FI brand blue, #0576BA */
  --paper: #d8e4ed;  --card: #f2f7fa;  --card-sunk: #e6eff5;
  --line:  #bcd3e3;  --line-soft: #d6e4ee;
  --steel: #0576ba;  --steel-tint: #d7e9f5;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 20px;
  letter-spacing: 0;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

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

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

/* Body copy sits at 0% tracking. Uppercase micro-labels are the one
   exception — caps need the extra room to stay legible at 12px. */
.section-title,
.field__label,
.trail__label,
.badge { letter-spacing: 0.04em; }

/* ── top bar ────────────────────────────────────────────────────────────── */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.topbar__logo {
  height: 40px;
  width: auto;
  display: block;
}

.topbar__title {
  display: flex;
  flex-direction: column;
  margin: 0;
  font-family: var(--display);
  font-size: 18px;
  line-height: 24px;
  letter-spacing: -0.01em;
  font-weight: 600;
}

.topbar__title span {
  font-family: var(--sans);
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--ink-2);
}

/* ── theme swatches ─────────────────────────────────────────────────────── */
.themer {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
}

.themer__toggle {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.themer__toggle:hover { border-color: var(--ink-2); }

.themer__dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--steel) 50%, var(--paper) 50%);
  border: 1px solid var(--line);
}

.themer__list {
  display: flex;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.themer__list[hidden] { display: none; }

.themer__swatch {
  width: 24px; height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}
.themer__swatch:hover { border-color: var(--ink-2); }

/* selected outranks hover and is not demoted while hovered */
.themer__swatch[aria-pressed="true"],
.themer__swatch[aria-pressed="true"]:hover {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink);
}

/* ── layout ─────────────────────────────────────────────────────────────── */
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  gap: 16px;
  padding: 16px;
}

.pane {
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.pane--list   { display: flex; flex-direction: column; overflow: hidden; }
.pane--detail { overflow-y: auto; outline: none; }

/* ── finder ─────────────────────────────────────────────────────────────── */
.finder {
  flex: none;
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--card);
}

.search { position: relative; }

.search__icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1.8;
  stroke-linecap: round;
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 4px 12px 4px 36px;
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}
#search::placeholder { color: var(--ink-3); }
#search:focus {
  border-color: var(--steel);
  box-shadow: 0 0 0 4px var(--steel-tint);
}

/* ── results ────────────────────────────────────────────────────────────── */
.results {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 8px;
  list-style: none;
}

.result {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 8px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.result:hover { background: var(--card-sunk); }

.result[aria-selected="true"],
.result[aria-selected="true"]:hover { background: var(--steel-tint); }

.result:focus-visible { outline-offset: -2px; }

.result__name {
  min-width: 0;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result[aria-selected="true"] .result__name { color: var(--steel); font-weight: 600; }

.result__id {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 20px;
  color: var(--ink-2);
}

.result__methods {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.tick {
  --chip: var(--m-none);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  padding: 0 4px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--chip) 12%, transparent);
  color: color-mix(in srgb, var(--chip) 85%, var(--ink));
}

mark {
  background: color-mix(in srgb, var(--steel) 20%, transparent);
  color: inherit;
  border-radius: 2px;
}

.empty {
  padding: 24px 16px;
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-2);
  text-align: center;
}

/* ── record ─────────────────────────────────────────────────────────────── */
.placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 40px;
  text-align: center;
  color: var(--ink-2);
}

.placeholder strong {
  font-family: var(--display);
  font-size: 18px;
  line-height: 24px;
  letter-spacing: -0.01em;
  font-weight: 600;
  color: var(--ink);
}

.placeholder p { margin: 0; font-size: 14px; line-height: 20px; max-width: 32ch; }

.placeholder .placeholder__meta {
  margin-top: 8px;
  max-width: none;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-3);
}

.person {
  max-width: 940px;
  padding: 24px 32px 40px;
}

.person__back {
  display: none;
  margin-bottom: 16px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--card);
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  color: var(--ink-2);
  cursor: pointer;
}
.person__back:hover { background: var(--card-sunk); color: var(--ink); }

.person__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--ink);
}

.person__name {
  margin: 0;
  font-family: var(--display);
  font-size: 22px;
  line-height: 32px;
  letter-spacing: -0.01em;
  font-weight: 600;
}

.person__aside {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  text-align: right;
  padding-top: 4px;
}

.person__id {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-2);
}
.person__id b {
  font-weight: 600;
  font-size: 14px;
  line-height: 20px;
  color: var(--ink);
}

.person__methods { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }

.section-title {
  margin: 24px 0 8px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* ── certificate cards ──────────────────────────────────────────────────── */
.cert {
  --chip: var(--m-none);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-sunk);
  overflow: hidden;
}
.cert + .cert { margin-top: 8px; }

.cert__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line-soft);
}

.cert__scope {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  color: var(--chip);
}

.badge {
  flex: none;
  padding: 0 8px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 20px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge--pass    { background: var(--pass-tint); color: var(--pass); border-color: color-mix(in srgb, var(--pass) 28%, transparent); }
.badge--fail    { background: var(--fail-tint); color: var(--fail); border-color: color-mix(in srgb, var(--fail) 28%, transparent); }
.badge--pending { background: var(--card-sunk); color: var(--ink-2); border-color: var(--line); }
.badge--sm      { line-height: 16px; }

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(172px, 1fr));
  gap: 1px;
  background: var(--line-soft);
}

.field {
  padding: 12px 16px;
  background: var(--card-sunk);
}

.field__label {
  display: block;
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--ink-2);
}

.field__value { font-size: 14px; line-height: 20px; }
.field__value--mono  { font-family: var(--mono); }
.field__value--empty { color: var(--ink-3); }

/* attempt trail — only rendered when a re-test actually happened, so the
   sequence itself is information rather than decoration */
.trail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 12px 16px;
  background: var(--card-sunk);
  border-top: 1px solid var(--line-soft);
}

.trail__label {
  flex: 0 0 100%;
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--ink-2);
}

.attempt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 16px;
  margin-right: 16px;
  border-right: 1px solid var(--line);
}
.attempt:last-child { border-right: 0; margin-right: 0; padding-right: 0; }

.attempt__n {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-2);
}

.attempt__date { font-size: 14px; line-height: 20px; }

/* ── responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }
  .pane--list   { max-height: calc(100dvh - 96px); }
  .pane--detail { display: none; }

  body[data-view="detail"] .pane--list   { display: none; }
  body[data-view="detail"] .pane--detail { display: block; }
  body[data-view="detail"] .person__back { display: inline-block; }

  .person { padding: 16px 16px 32px; }
  .person__head { flex-direction: column; gap: 12px; }
  .person__aside { align-items: flex-start; text-align: left; padding-top: 0; }
  .person__methods { justify-content: flex-start; }

  .themer { right: 12px; bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
