/* ==========================================================================
   Certificate Portal — design system

   Midnight black, hairline borders, no gradients or glass. Depth comes from
   layered near-black surfaces and 1px rules, not shadows.

   Mobile first: every rule below is the small-screen rule. Breakpoints only
   add width (640px = wide phone/tablet, 900px = desktop).
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Surfaces, darkest to lightest. --bg is true black. */
  --bg: #000000;
  --bg-accent: #000000;
  --card: #0a0a0a;
  --card-strong: #101010;
  --surface: #0e0e0e;
  --surface-alt: #161616;

  /* Solid hairlines rather than alpha: an alpha border shifts tone with whatever
     is behind it, so the same rule looked different on a card and on the page. */
  --border: #1f1f1f;
  --border-strong: #2e2e2e;

  /* Three text tones, all of which must survive a contrast check on --surface.
     The old tertiary tone measured 2.7:1 and was being used for real text. */
  --text: #ededed;
  --muted: #a1a1a1;
  --faint: #86868e;

  /* The accent is white. On black it needs no hue to read as emphasis. */
  --accent: #fafafa;
  --accent-hover: #ffffff;
  --accent-soft: rgba(255, 255, 255, 0.09);
  --on-accent: #000000;

  --success-text: #3fb950;
  --success-bg: rgba(63, 185, 80, 0.12);
  --warning-text: #d29922;
  --warning-bg: rgba(210, 153, 34, 0.12);
  --error-text: #f85149;
  --error-bg: rgba(248, 81, 73, 0.11);

  --radius: 8px;
  --radius-sm: 6px;
  --radius-pill: 999px;
  --shadow: none;

  /* 4px rhythm. */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  /* One duration and one curve, so everything moves with the same rhythm. */
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur: 140ms;

  /* Two control heights, nothing in between. Touch sizes on small screens,
     tighter desktop sizes at the 640px breakpoint (see below). */
  --control-h: 44px;
  --control-h-sm: 40px;

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

  --gutter: 1.25rem;
  --header-h: 56px;
}

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

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  /* Slight optical tightening; grotesques read looser than they measure. */
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Desktop tightens to a 14px UI scale. Touch keeps 16px, both for readability
   and because anything smaller makes iOS Safari zoom the viewport on focus. */
@media (min-width: 640px) {
  body {
    font-size: 14px;
  }
  :root {
    --control-h: 36px;
    --control-h-sm: 32px;
  }
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.021em;
  line-height: 1.2;
}

h1 {
  font-size: clamp(1.5rem, 1.2rem + 1.4vw, 1.75rem);
  letter-spacing: -0.028em;
}
h2 {
  font-size: 1.125rem;
  letter-spacing: -0.024em;
}
h3 {
  font-size: 0.9375rem;
}

p {
  margin: 0;
}

a {
  color: var(--text);
  text-decoration: none;
}

::selection {
  background: rgba(255, 255, 255, 0.16);
}

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

/* Inputs draw their own ring so it hugs the field instead of the text box. */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline-offset: 1px;
}

/* Motion is decorative here - every transition is a state hint, never content.
   Honour the system setting rather than assuming everyone wants it. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Thin dark scrollbars, so panels do not sprout bright grey bars. */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.24);
  background-clip: content-box;
}

/* --- public page shell ---------------------------------------------------- */

.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 3rem var(--gutter) 2rem;
}

/* Participant/error pages: a full-height column so .page and the footer together
   fill the viewport exactly. Without this, .page is 100vh AND the footer sits after
   it, so every page was 100vh + footer tall - a scrollbar over mostly-empty space. */
.sheet { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.sheet .page { flex: 1 0 auto; min-height: 0; }

.card {
  width: 100%;
  max-width: 27rem;
  margin: auto;
}

.listing-card {
  max-width: 32rem;
}

.preview-card {
  max-width: 54rem;
}

.card-subtitle,
.listing-intro {
  margin-top: 0.375rem;
  color: var(--muted);
  font-size: 13px;
}

.site-footer {
  padding: 1.5rem var(--gutter) 2rem;
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-align: center;
  text-transform: uppercase;
}

/* --- event list ----------------------------------------------------------- */

.event-list {
  margin: 1.75rem 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border);
}

.event-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 60px;
  padding: 0.9rem 0.25rem;
  border-bottom: 1px solid var(--border);
  transition: padding-left 0.16s ease, color 0.16s ease;
}

.event-link:hover,
.event-link:focus-visible {
  padding-left: 0.7rem;
}

.event-link-name {
  font-size: 1rem;
  font-weight: 500;
}

.event-arrow {
  color: var(--faint);
  transition: color 0.16s ease, transform 0.16s ease;
}

.event-link:hover .event-arrow {
  color: var(--text);
  transform: translateX(2px);
}

/* --- forms ---------------------------------------------------------------- */

.form {
  display: flex;
  flex-direction: column;
  margin-top: 1.75rem;
}

.form label,
.coord-editor-control label {
  margin-bottom: 0.375rem;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.form label:not(:first-of-type) {
  margin-top: 1.15rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  /* 16px keeps iOS Safari from zooming the viewport on focus. */
  font-size: 16px;
  font-family: inherit;
  letter-spacing: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  min-height: var(--control-h);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}

@media (min-width: 640px) {
  input[type="text"],
  input[type="password"],
  input[type="email"],
  input[type="number"],
  input[type="file"],
  select,
  textarea {
    font-size: 14px;
    min-height: var(--control-h);
    padding: 0.4375rem 0.6875rem;
  }
}

textarea {
  line-height: 1.5;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--border-strong);
}

input:disabled,
select:disabled,
textarea:disabled,
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-alt);
}

/* Datalist inputs get a validity hint from JS via these classes. */
input.is-match {
  border-color: rgba(63, 185, 80, 0.55);
}
input.is-nomatch {
  border-color: rgba(248, 81, 73, 0.45);
}

/* A file input is taller than a text field because the UA draws a button inside
   it. Trim both paddings so it lands one step above the standard control height
   rather than five pixels off it. */
input[type="file"] {
  padding: 0.5rem 0.625rem;
  color: var(--muted);
  cursor: pointer;
}

@media (min-width: 640px) {
  input[type="file"] {
    padding: 0.3125rem 0.5rem;
  }
}
input[type="file"]::file-selector-button {
  margin-right: 0.75rem;
  padding: 0.25rem 0.5rem;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover {
  border-color: var(--border-strong);
}

input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  /* Colour inputs are not in the width rule above and would otherwise size to
     their intrinsic swatch width, which looks broken next to full-width fields. */
  width: 100%;
  padding: 4px;
  min-height: var(--control-h);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
input[type="color"]:hover {
  border-color: var(--border-strong);
}
input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}
input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 4px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.2rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.coord-input {
  font-variant-numeric: tabular-nums;
}

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

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--control-h);
  padding: 0 0.9375rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.011em;
  white-space: nowrap;
  color: var(--on-accent);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}

@media (min-width: 640px) {
  button,
  .button-link {
    padding: 0 0.8125rem;
    font-size: 0.875rem;
  }
}

button:hover,
.button-link:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button:active,
.button-link:active {
  /* transform, not margin: a press must never move the elements around it. */
  transform: translateY(0.5px);
  opacity: 0.9;
}

.form button[type="submit"] {
  margin-top: 1.75rem;
  width: 100%;
}

.button-link.secondary,
button.secondary {
  color: var(--text);
  background: transparent;
  border-color: var(--border-strong);
}
.button-link.secondary:hover,
button.secondary:hover {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

.button-link.danger,
button.danger {
  color: var(--error-text);
  background: transparent;
  border-color: rgba(248, 81, 73, 0.35);
}
.button-link.danger:hover,
button.danger:hover {
  color: #fff;
  background: #da3633;
  border-color: #da3633;
}

.back-link-row {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.back-link {
  color: var(--muted);
  font-size: 13px;
  transition: color 0.15s ease;
}
.back-link:hover {
  color: var(--text);
}

/* --- messages ------------------------------------------------------------- */

.error,
.success-msg {
  margin-top: 1.25rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.error {
  color: var(--error-text);
  background: var(--error-bg);
  border-color: rgba(248, 81, 73, 0.3);
}

.success-msg {
  color: var(--success-text);
  background: var(--success-bg);
  border-color: rgba(63, 185, 80, 0.3);
}

.field-hint {
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.success-text {
  color: var(--success-text);
}
.warn-text {
  color: var(--warning-text);
}

.field-hint code,
code {
  padding: 0.0625rem 0.3125rem;
  font-family: var(--font-mono);
  /* Fixed, not em: nested in 12px hint text this used to render at 9.6px. */
  font-size: 12px;
  color: var(--text);
  background: var(--surface-alt);
  border-radius: 4px;
}

/* --- certificate preview -------------------------------------------------- */

.preview-frame {
  margin-top: 1.75rem;
  padding: 0.75rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.preview-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
}

.preview-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.preview-actions .button-link {
  width: 100%;
}

@media (min-width: 640px) {
  .preview-actions {
    flex-direction: row;
  }
  .preview-actions .button-link {
    width: auto;
    flex: 1;
  }
  /* The secondary action should not compete with the primary one for width. */
  .preview-actions .button-link.secondary {
    flex: 0 0 auto;
    min-width: 7rem;
  }
}

/* ==========================================================================
   Admin
   ========================================================================== */

.admin-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--header-h);
  padding: 0.5rem var(--gutter);
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.admin-header-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.admin-nav-link,
.admin-nav-btn {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-h-sm);
  padding: 0 0.625rem;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  font-weight: 500;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.admin-nav-link:hover,
.admin-nav-btn:hover {
  color: var(--text);
  background: var(--surface-alt);
  border-color: transparent;
}

.admin-main {
  flex: 1;
  width: 100%;
  max-width: 68rem;
  margin: 0 auto;
  padding: 1.75rem var(--gutter) 4rem;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.admin-subtitle {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 13px;
}

.admin-card {
  padding: 1.25rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* --- event list (replaces the old table on every width) ------------------- */

.admin-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.admin-table {
  display: flex;
  flex-direction: column;
}

.event-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 1rem;
  padding: 1rem 1.1rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.event-row:last-child {
  border-bottom: none;
}

.event-row-main {
  min-width: 0;
}

.event-row-name {
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.event-row-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 12px;
}

.event-row-meta .dot {
  color: var(--faint);
}

.admin-table-link {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  transition: color 0.15s ease;
}
.admin-table-link:hover {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.admin-actions-cell {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.admin-action-link,
.admin-action-btn {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-h-sm);
  padding: 0 0.625rem;
  line-height: 1;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.admin-action-link:hover,
.admin-action-btn:hover {
  color: var(--text);
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

/* Resting state stays quiet; the red only appears on hover. The generic
   button.danger rule would otherwise give every Delete a permanent red outline. */
.admin-action-btn.danger {
  color: var(--muted);
  border-color: var(--border);
}
.admin-action-btn.danger:hover {
  color: var(--error-text);
  background: var(--error-bg);
  border-color: rgba(248, 81, 73, 0.35);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0.5rem;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1px solid;
  border-radius: 99px;
  white-space: nowrap;
}

.status-badge::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.active {
  color: var(--success-text);
  background: var(--success-bg);
  border-color: rgba(63, 185, 80, 0.28);
}

.status-badge.inactive {
  color: var(--muted);
  background: var(--surface-alt);
  border-color: var(--border);
}

.delete-confirm-row {
  padding: 0.9rem 1.1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.delete-confirm-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.delete-confirm-label {
  color: var(--muted);
  font-size: 13px;
}

.delete-confirm-label strong {
  color: var(--text);
  font-family: var(--font-mono);
}

.delete-confirm-input {
  font-family: var(--font-mono);
  font-size: 13px;
}

.delete-confirm-actions {
  display: flex;
  gap: 0.5rem;
}

.delete-confirm-actions .button-link {
  flex: 1;
}

@media (min-width: 640px) {
  .event-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
  }
  .admin-actions-cell {
    grid-column: 1 / -1;
  }
  .delete-confirm-form {
    flex-direction: row;
    align-items: center;
  }
  .delete-confirm-input {
    flex: 1;
    max-width: 18rem;
  }
  .delete-confirm-actions .button-link {
    flex: none;
  }
}

@media (min-width: 900px) {
  .event-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }
  .admin-actions-cell {
    grid-column: 3;
    grid-row: 1;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    justify-content: flex-end;
  }
}

.empty-state {
  padding: 3rem 1.25rem;
  text-align: center;
  color: var(--muted);
}

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

.admin-form-section {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-form-section > h3 {
  margin-bottom: 0.25rem;
  font-size: 0.95rem;
}

.admin-form {
  margin-top: 1.25rem;
}

.admin-form label:not(:first-of-type) {
  margin-top: 1rem;
}

.admin-form button[type="submit"] {
  margin-top: 1.5rem;
  width: 100%;
}

@media (min-width: 640px) {
  .admin-form button[type="submit"] {
    width: auto;
    min-width: 11rem;
  }
}

/* --- validation type picker ----------------------------------------------- */

.validation-type-group {
  display: grid;
  gap: 0.5rem;
  margin: 1.25rem 0 0;
  padding: 0;
  border: none;
}

.validation-type-group legend {
  padding: 0;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.validation-option {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.7rem;
  padding: 0.85rem 0.95rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.validation-option:hover {
  border-color: var(--border-strong);
}

.validation-option input[type="radio"] {
  grid-row: 1 / span 3;
  align-self: start;
  width: 16px;
  height: 16px;
  margin: 3px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.validation-option strong {
  font-size: 14px;
  font-weight: 600;
}

.validation-desc,
.validation-csv {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
}

.validation-csv {
  color: var(--faint);
}

/* :has() lets the whole card light up; the input outline is the fallback. */
.validation-option:has(input:checked) {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

@supports not selector(:has(*)) {
  .validation-option input[type="radio"]:checked {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
}

@media (min-width: 640px) {
  .validation-type-group {
    grid-template-columns: 1fr 1fr;
  }
}

/* --- custom column picker ------------------------------------------------- */

.custom-columns-panel {
  display: none;
  margin-top: 1.25rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.custom-columns-panel.is-visible {
  display: block;
}

.custom-columns-panel h3 {
  margin-bottom: 0.25rem;
}

.custom-columns-grid {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.custom-column-option {
  padding: 0.7rem 0.85rem;
  background: var(--card-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.custom-column-main,
.custom-column-dropdown {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  cursor: pointer;
}

.custom-column-main input,
.custom-column-dropdown input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.custom-column-name {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
}

.custom-column-dropdown {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

@media (min-width: 640px) {
  .custom-columns-grid {
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  }
}

/* --- inline certificate preview ------------------------------------------- */

.cert-config-layout {
  margin-top: 1.25rem;
}

.cert-config-inputs {
  display: grid;
  gap: 1rem;
}

.input-pair {
  display: grid;
  gap: 1rem;
}

.input-pair > div {
  display: flex;
  flex-direction: column;
}

.input-pair label {
  margin-top: 0 !important;
}

@media (min-width: 480px) {
  .input-pair {
    grid-template-columns: 1fr 1fr;
  }
}

.cert-preview-area {
  margin-top: 1.25rem;
}

.cert-preview-media {
  position: relative;
  display: flex;
  justify-content: center;
  padding: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 120px;
}

.cert-preview-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.cert-preview-base {
  position: relative;
}

.cert-preview-overlay {
  position: absolute;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

.cert-preview-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface);
  border-radius: var(--radius-sm);
}

.cert-preview-loading.is-visible {
  display: flex;
}

.cert-preview-loading.has-error {
  color: var(--error-text);
}

.cert-preview-empty {
  margin-top: 1.25rem;
  padding: 2rem 1rem;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}

/* --- logs ----------------------------------------------------------------- */

.log-viewport {
  height: 60vh;
  min-height: 18rem;
  padding: 1rem;
  overflow: auto;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.log-output {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ==========================================================================
   Full-screen editors (coordinate editor, bulk email)
   ========================================================================== */

.coord-editor-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.coord-editor-canvas {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: #050505;
  border-bottom: 1px solid var(--border);
  /* On phones the canvas takes the top half and the panel scrolls under it. */
  min-height: 38vh;
  max-height: 45vh;
  overflow: auto;
}

#certEditorCanvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-sm);
  cursor: crosshair;
  touch-action: none;
}

.coord-editor-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1.25rem var(--gutter) 2rem;
  background: var(--bg);
  overflow-y: auto;
}

.coord-editor-panel h3 {
  margin: 1.5rem 0 0.9rem;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.coord-editor-panel h3:first-child {
  margin-top: 0;
}

.coord-editor-control {
  margin-bottom: 1rem;
}

.coord-editor-control label {
  display: block;
}

.coord-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.coord-info {
  padding: 0.75rem 0.85rem;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.coord-info strong {
  color: var(--text);
}

.coord-editor-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.coord-editor-btn {
  width: 100%;
}

.coord-editor-btn.secondary {
  color: var(--text);
  background: transparent;
  border-color: var(--border-strong);
}
.coord-editor-btn.secondary:hover {
  background: var(--surface-alt);
}

@media (min-width: 900px) {
  .coord-editor-layout {
    flex-direction: row;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  .coord-editor-canvas {
    flex: 1;
    min-height: 0;
    max-height: none;
    padding: 2rem;
    border-bottom: none;
    border-right: 1px solid var(--border);
  }
  .coord-editor-panel {
    flex: none;
    width: 23rem;
    padding: 1.75rem;
  }
  .coord-editor-actions {
    margin-top: auto;
  }
}

/* --- restored: roster-disclosure warning (Phase 0.5b) --------------------- */
.custom-column-option.is-person-level {
  border-color: var(--warning-text);
}
.roster-warning {
  margin: 0.5rem 0 0;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.45;
  color: var(--warning-text);
  background: var(--warning-bg);
  border: 1px solid transparent;
  opacity: 0.7;
}
.roster-warning.is-active {
  opacity: 1;
  border-color: var(--warning-text);
  font-weight: 500;
}
.roster-warning strong {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ==========================================================================
   Dashboard layer - the club/admin app shell and its components.
   Shares the midnight-black tokens above; adds the distinctive Archivo /
   IBM Plex Mono type used by the placement editor so the whole app reads as
   one product. Load the two Google fonts in the page <head>.
   ========================================================================== */

:root {
  --font-display: var(--font);
  --data: var(--font-mono);
}

.appbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: var(--space-4);
  height: var(--header-h); padding: 0 var(--gutter);
  background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.appbar__brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  font-family: var(--font-display); font-weight: 700; letter-spacing: -0.01em;
  color: var(--text); text-decoration: none; font-size: 0.95rem;
}
.appbar__brand .mark {
  display: grid; place-items: center; width: 26px; height: 26px;
  border: 1px solid var(--border-strong); border-radius: 7px; color: var(--accent);
}
.appbar__brand .mark svg { width: 15px; height: 15px; }
.appbar__spacer { flex: 1; }
.appbar__meta { font-size: 0.82rem; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.appbar__meta b { color: var(--text); font-weight: 600; }
.appbar__link { color: var(--muted); text-decoration: none; font-size: 0.85rem; }
.appbar__link:hover { color: var(--text); }

.wrap { max-width: 940px; margin: 0 auto; padding: var(--space-6) var(--gutter) var(--space-7); }
.wrap--wide { max-width: 1120px; }

.page-head { display: flex; align-items: flex-start; gap: var(--space-4);
  flex-wrap: wrap; margin-bottom: var(--space-6); }
.page-head__text { min-width: 0; flex: 1; }
.page-head h1 { font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.4rem, 3vw, 1.9rem); letter-spacing: -0.02em; margin: 0; text-wrap: balance; }
.page-head .sub { color: var(--muted); margin: 0.35rem 0 0; font-size: 0.9rem; }
.page-head .sub code, .addr { font-family: var(--data); font-size: 0.82em;
  color: var(--text); background: var(--surface-alt); border: 1px solid var(--border);
  padding: 0.1rem 0.4rem; border-radius: 5px; }
.page-head__actions { display: flex; gap: var(--space-2); align-items: center; flex-shrink: 0; }

.stats { display: grid; grid-template-columns: 1fr; gap: var(--space-3); margin-bottom: var(--space-5); }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(3, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-4) var(--space-5); }
.stat__label { font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--faint); font-weight: 600; }
.stat__value { font-family: var(--data); font-size: 1.6rem; font-variant-numeric: tabular-nums;
  color: var(--text); margin-top: 0.35rem; line-height: 1.1; }
.stat__value .unit { font-size: 0.85rem; color: var(--muted); }

.meter { height: 6px; border-radius: 999px; background: var(--surface-alt);
  overflow: hidden; margin-top: 0.7rem; }
.meter__fill { height: 100%; background: var(--accent); border-radius: 999px;
  transition: width var(--dur) var(--ease); }
.meter__fill.is-warn { background: var(--warning-text); }
.meter__fill.is-full { background: var(--error-text); }

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-5); margin-bottom: var(--space-4); }
.panel__head { display: flex; align-items: center; gap: 0.6rem; margin: 0 0 var(--space-2); }
.panel__head h2 { font-family: var(--font-display); font-size: 1rem; font-weight: 600; margin: 0; }
.panel__head .ico { color: var(--muted); display: grid; place-items: center; }
.panel__head .ico svg { width: 17px; height: 17px; }
.panel__hint { color: var(--faint); font-size: 0.82rem; margin: 0 0 var(--space-3); line-height: 1.5; }
.panel__row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: var(--space-4); }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; } }

.events { display: flex; flex-direction: column; gap: var(--space-2); }
a.event-row { display: flex; align-items: center; gap: var(--space-3);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-3) var(--space-4); text-decoration: none; color: inherit;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease); }
a.event-row:hover { border-color: var(--border-strong); background: var(--card-strong); }
.event-row__main { min-width: 0; flex: 1; }
.event-row__name { font-weight: 600; font-size: 0.95rem; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.event-row__sub { font-family: var(--data); font-size: 0.76rem; color: var(--faint); margin-top: 0.15rem; }
.event-row__chev { color: var(--faint); flex-shrink: 0; display: grid; place-items: center; }
.event-row__chev svg { width: 16px; height: 16px; }

.pill { display: inline-flex; align-items: center; gap: 0.4rem; flex-shrink: 0;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 0.24rem 0.6rem; border-radius: 999px; border: 1px solid var(--border-strong);
  color: var(--muted); background: var(--surface); white-space: nowrap; }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--live { color: var(--success-text); border-color: rgba(63,185,80,0.35); background: var(--success-bg); }
.pill--draft { color: var(--faint); }
.pill--pending { color: var(--warning-text); border-color: rgba(210,153,34,0.35); background: var(--warning-bg); }
.pill--suspended { color: var(--error-text); border-color: rgba(248,81,73,0.35); background: var(--error-bg); }

.banner { display: flex; gap: 0.7rem; padding: var(--space-3) var(--space-4);
  border-radius: var(--radius); font-size: 0.86rem; line-height: 1.5; margin-bottom: var(--space-4);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted); }
.banner svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.banner--warn { border-color: rgba(210,153,34,0.35); background: var(--warning-bg); color: #e6c674; }
.banner--warn svg { color: var(--warning-text); }
.banner--ok { border-color: rgba(63,185,80,0.35); background: var(--success-bg); color: #82d996; }
.banner--ok svg { color: var(--success-text); }
.banner b { color: var(--text); font-weight: 600; }
.banner code { font-family: var(--data); font-size: 0.85em; color: var(--text); }

.empty { text-align: center; padding: var(--space-7) var(--space-5);
  border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--faint); }
.empty svg { width: 30px; height: 30px; color: var(--border-strong); margin-bottom: var(--space-3); }
.empty p { margin: 0 0 var(--space-4); font-size: 0.9rem; line-height: 1.55; }

.danger { border-color: rgba(248,81,73,0.3); }
.danger .panel__head h2 { color: var(--error-text); }
.btn-danger { display: inline-flex; align-items: center; justify-content: center;
  background: var(--error-bg); color: var(--error-text);
  border: 1px solid rgba(248,81,73,0.4); border-radius: var(--radius-sm); height: var(--control-h-sm);
  padding: 0 var(--space-4); font-weight: 600; font-family: var(--font-display); cursor: pointer;
  transition: background var(--dur) var(--ease); }
.btn-danger:hover { background: rgba(248,81,73,0.2); }

.dtable { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.dtable thead th { text-align: left; font-size: 0.68rem; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--faint); font-weight: 600; padding: 0 var(--space-3) var(--space-3) 0;
  border-bottom: 1px solid var(--border); white-space: nowrap; }
.dtable td { padding: var(--space-3) var(--space-3) var(--space-3) 0; border-bottom: 1px solid var(--border);
  vertical-align: middle; }
.dtable tr:last-child td { border-bottom: none; }
.dtable .cell-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end; }
.dtable .inline-set { display: flex; gap: var(--space-1); align-items: center; }
.dtable .inline-set input { width: 8.5rem; }
.table-scroll { overflow-x: auto; }

.auth { min-height: 100dvh; display: grid; place-items: center; padding: var(--space-5); }
.auth__card { width: 100%; max-width: 400px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-6); }
.auth__brand { display: inline-flex; align-items: center; gap: 0.55rem; margin-bottom: var(--space-5);
  font-family: var(--font-display); font-weight: 700; color: var(--text); }
.auth__brand .mark { display: grid; place-items: center; width: 28px; height: 28px;
  border: 1px solid var(--border-strong); border-radius: 7px; color: var(--accent); }
.auth__brand .mark svg { width: 16px; height: 16px; }
.auth h1 { font-family: var(--font-display); font-size: 1.35rem; letter-spacing: -0.02em; margin: 0 0 0.3rem; }
.auth .lede { color: var(--muted); font-size: 0.9rem; margin: 0 0 var(--space-5); }
.auth .alt { margin-top: var(--space-5); text-align: center; font-size: 0.85rem; color: var(--faint); }
.auth .alt a { color: var(--muted); }
.auth .alt a:hover { color: var(--text); }

.field-label { display: block; font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--faint); font-weight: 600; margin-bottom: 0.4rem; }

/* ── Public landing ────────────────────────────────────────────────────────── */
.hero { padding: var(--space-7) 0 var(--space-6); max-width: 34rem; }
.hero h1 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.02em;
  font-size: clamp(1.7rem, 4.5vw, 2.5rem); line-height: 1.1; margin: 0 0 var(--space-4); }
.hero .lede { color: var(--muted); font-size: 1rem; line-height: 1.6; margin: 0 0 var(--space-5); }
.hero__cta { display: flex; gap: var(--space-3); flex-wrap: wrap; }
/* Full-height column so the footer sits at the bottom even on a short landing page. */
.landing { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.landing > main { flex: 1 0 auto; }
.landing > .site-foot { flex: 0 0 auto; margin-top: auto; }
.site-foot { text-align: center; color: var(--faint); font-size: 0.78rem;
  padding: var(--space-6) var(--space-5) var(--space-7); }
.site-foot a { color: var(--muted); }
.site-foot a:hover { color: var(--text); }

/* ── Club events manager (modeled on the legacy admin event table) ──────────── */
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-3);
  flex-wrap: wrap; margin: var(--space-6) 0 var(--space-3); }
.section-head h2 { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; margin: 0; }
.section-head .count { color: var(--faint); font-size: 0.8rem; margin-top: 0.2rem; }
.section-head .storage { display: flex; align-items: center; gap: 0.6rem; font-size: 0.76rem;
  color: var(--muted); font-family: var(--data); font-variant-numeric: tabular-nums; }
.section-head .storage .meter { width: 84px; margin: 0; }

.evmgr { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.evmgr__row { display: grid; grid-template-columns: minmax(0,1fr) auto auto; gap: 0.4rem 1rem;
  align-items: center; padding: var(--space-4); border-bottom: 1px solid var(--border); }
.evmgr__row:last-child { border-bottom: none; }
.evmgr__main { min-width: 0; }
.evmgr__name { font-weight: 600; font-size: 0.96rem; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.evmgr__meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.35rem; }
.evlink { font-family: var(--data); font-size: 0.76rem; color: var(--muted); text-decoration: none;
  transition: color var(--dur) var(--ease); }
.evlink:hover { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.evmgr__actions { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }

.evact { display: inline-flex; align-items: center; min-height: var(--control-h-sm); padding: 0 0.7rem;
  line-height: 1; color: var(--muted); font-family: var(--font-display); font-size: 0.82rem; font-weight: 500;
  background: transparent; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; text-decoration: none;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.evact:hover { color: var(--text); background: var(--surface-alt); border-color: var(--border-strong); }
.evact--primary { color: var(--text); border-color: var(--border-strong); }
.evact--danger:hover { color: var(--error-text); background: var(--error-bg); border-color: rgba(248,81,73,0.35); }

.copybtn { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.1rem 0.45rem; height: 24px;
  font-family: var(--font-display); font-size: 0.68rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--faint); background: transparent; border: 1px solid var(--border); border-radius: 5px; cursor: pointer;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.copybtn:hover { color: var(--text); border-color: var(--border-strong); }
.copybtn.is-ok { color: var(--success-text); border-color: rgba(63,185,80,0.35); }
.copybtn svg { width: 12px; height: 12px; }

.evdel { padding: var(--space-3) var(--space-4); background: var(--surface); border-bottom: 1px solid var(--border); }
.evdel:last-child { border-bottom: none; }
.evdel__form { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.evdel__label { color: var(--muted); font-size: 0.8rem; }
.evdel__label code { font-family: var(--data); color: var(--text); }
.evdel__form input { flex: 1; min-width: 10rem; max-width: 18rem; font-family: var(--data); font-size: 0.82rem; }

@media (max-width: 560px) {
  .evmgr__row { grid-template-columns: 1fr; }
  .evmgr__actions { justify-content: flex-start; }
}

/* Address chip with an inline copy control, used in page heads. */
.addr-copy { display: inline-flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }

/* Progressive-disclosure danger zone: the destructive form stays folded away. */
.disclosure { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); overflow: hidden; }
.disclosure > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 0.6rem;
  padding: var(--space-4); font-family: var(--font-display); font-weight: 600; font-size: 0.95rem; color: var(--muted); }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary .chev { margin-left: auto; color: var(--faint); transition: transform var(--dur) var(--ease); }
.disclosure[open] > summary .chev { transform: rotate(90deg); }
.disclosure > summary:hover { color: var(--text); }
.disclosure__body { padding: 0 var(--space-4) var(--space-4); }
.disclosure--danger { border-color: rgba(248,81,73,0.25); }
.disclosure--danger > summary { color: var(--error-text); }
.disclosure--danger > summary .ico { color: var(--error-text); display: inline-flex; }
.disclosure--danger > summary .ico svg { width: 16px; height: 16px; }
