:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  --ink: #17191c;
  --muted: #60666d;
  --line: #cfd4d9;
  --soft: #f3f5f6;
  --panel: #ffffff;
  --green: #19743c;
  --green-dark: #10592d;
  --blue: #1769aa;
  --red: #b3261e;
  --yellow: #f4c542;
  background: #e9ecef;
  color: var(--ink);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #e9ecef;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 74px;
  padding: 10px clamp(14px, 3vw, 34px);
  border-bottom: 1px solid #000;
  background: #17191c;
  color: #fff;
}

.brand-logo { display: block; width: 128px; height: 48px; object-fit: contain; }
.brand-copy { display: grid; min-width: 0; gap: 3px; }
.brand-copy strong { font-size: 1.05rem; }
.brand-copy span { overflow: hidden; color: #c8cdd2; font-size: 0.85rem; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.brand-copy[hidden], .header-actions[hidden] { display: none; }
body.production-public .app-header { grid-template-columns: 128px; }

.account-button {
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid #aeb4ba;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 750;
}

.environment-badge { display: inline-flex; align-items: center; min-height: 30px; padding: 5px 9px; border: 1px solid #ffd166; border-radius: 4px; background: #fff4cf; color: #5f4300; font-size: 0.72rem; font-weight: 850; text-transform: uppercase; white-space: nowrap; }
.environment-badge[hidden] { display: none; }

.view-tabs {
  position: sticky;
  top: 74px;
  z-index: 19;
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.tab-button {
  flex: 1 0 128px;
  min-height: 48px;
  padding: 7px 10px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 4px solid transparent;
  background: #fff;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}
.tab-button:last-child { border-right: 0; }
.tab-button.active { border-bottom-color: var(--green); color: var(--ink); }
.mobile-view-nav { display: none; }
.count-badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 3px; border-radius: 999px; background: var(--red); color: #fff; font-size: 0.7rem; }

.app-main { width: min(1240px, 100%); margin: 0 auto; padding: clamp(14px, 3vw, 28px); }
.app-view { display: none; }
.app-view.active { display: block; }
.section-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 3px; font-size: clamp(1.4rem, 3vw, 2rem); }
h2 { margin-bottom: 0; font-size: 1.25rem; }
h3 { margin-bottom: 0; }
.section-status, .form-message { margin-bottom: 0; color: var(--muted); font-size: 0.9rem; }
.form-message.error { color: var(--red); font-weight: 700; }

.event-list, .entry-list, .dependent-list { display: grid; gap: 10px; }
.event-period-grid { display: grid; gap: 18px; }
.event-period-panel { display: grid; gap: 9px; }
.event-period-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 6px; border-bottom: 2px solid var(--line); }
.event-period-heading span { display: inline-grid; min-width: 30px; min-height: 28px; place-items: center; padding: 2px 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--soft); font-weight: 850; }
.event-card, .entry-card, .dependent-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 6px;
  background: var(--panel);
}
.event-card.live { border-left-color: var(--red); }
.event-card.closed, .entry-card.locked { border-left-color: #777d83; }
.card-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.card-title strong { font-size: 1.05rem; }
.card-badge { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 7px; border: 1px solid var(--line); border-radius: 999px; background: var(--soft); color: #454a50; font-size: 0.72rem; font-weight: 800; text-transform: uppercase; }
.card-badge.live { border-color: #e1a09b; background: #fbe9e7; color: #8b1b15; }
.card-badge.paid { border-color: #72b98b; background: #e8f5ec; color: #10592d; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 0.88rem; }
.card-actions { display: flex; align-items: center; gap: 8px; }

.button { min-height: 38px; padding: 7px 13px; border: 1px solid transparent; border-radius: 5px; font-weight: 750; }
.button.primary { border-color: var(--green-dark); background: var(--green); color: #fff; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { border-color: #9ea4aa; background: #fff; color: var(--ink); }
.button.secondary:hover { background: var(--soft); }
.button.danger { border-color: #8d1c16; background: var(--red); color: #fff; }
.full-button { width: 100%; margin-top: 10px; }

.empty-state, .account-callout { padding: 30px 18px; border: 1px dashed #aeb4ba; border-radius: 6px; background: #f7f8f9; color: var(--muted); text-align: center; }
.account-callout strong { display: block; margin-bottom: 6px; color: var(--ink); font-size: 1.05rem; }
.account-callout p { margin-bottom: 16px; }

select, input, textarea { width: 100%; min-height: 40px; padding: 7px 9px; border: 1px solid #9da4aa; border-radius: 4px; background: #fff; color: var(--ink); }
select:focus, input:focus, textarea:focus { border-color: var(--blue); outline: 2px solid rgba(23, 105, 170, 0.18); }

.data-toolbar select { width: min(410px, 42vw); }
.toolbar-selects { display: flex; gap: 8px; }
.results-toolbar-selects { flex-wrap: wrap; justify-content: flex-end; }
.results-toolbar-selects #resultsSeriesSelect { width: min(320px, 26vw); }
.results-toolbar-selects #resultsYearSelect { width: min(130px, 12vw); }
.results-toolbar-selects #resultsEventSelect { width: min(360px, 29vw); }
.results-toolbar-selects #resultsModeSelect { width: min(240px, 21vw); }
.events-series-select { display: block; width: min(360px, 40vw); min-width: 0; max-width: 100%; }
.events-year-select { display: block; width: 118px; min-width: 0; }
.number-lookup-controls { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(220px, 0.75fr); gap: 5px 12px; margin-bottom: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.number-lookup-controls .stacked-label { align-self: end; }
.number-lookup-controls #numberLookupWarning { grid-column: 1 / -1; }
.number-lookup-warning { min-height: 20px; color: #7b5a00; font-size: 0.86rem; font-weight: 750; }
.number-lookup-warning.error { color: var(--red); }
.number-lookup-events { max-width: 560px; overflow-wrap: anywhere; white-space: normal; }
.field-guidance { min-height: 17px; color: #7b5a00; font-size: 0.75rem; font-weight: 700; }
.field-guidance.error { color: var(--red); }
.data-table-wrap { overflow: auto; border: 1px solid #8d949b; border-radius: 5px; background: #fff; }
.data-table { width: 100%; min-width: 720px; border-collapse: collapse; table-layout: auto; }
.data-table th, .data-table td { padding: 8px 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
.data-table th { position: sticky; top: 0; z-index: 1; background: #e2e6ea; font-size: 0.8rem; text-transform: uppercase; }
.data-table th:last-child, .data-table td:last-child { border-right: 0; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .name-cell { text-align: left; }
.data-table .clickable-row { cursor: pointer; }
.data-table .clickable-row:hover,
.data-table .clickable-row:focus { outline: 0; background: #edf6f0; }
.class-separator td { height: 10px; padding: 0; border: 0; background: #e9ecef; }

.checkout-summary { position: sticky; bottom: 0; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; margin-top: 14px; padding: 14px; border: 1px solid #8d949b; border-radius: 6px; background: #fff; box-shadow: 0 -5px 18px rgba(0,0,0,0.08); }
.checkout-summary > strong { justify-self: end; font-size: 1.2rem; }

.account-panel { margin-bottom: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.panel-heading p { margin: 3px 0 0; color: var(--muted); font-size: 0.85rem; }
.verified-label { color: var(--green-dark); font-size: 0.85rem; font-weight: 800; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 14px; }

.app-dialog { width: min(800px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; overflow: auto; border: 1px solid #34383c; border-radius: 7px; background: #fff; color: var(--ink); }
.app-dialog::backdrop { background: rgba(18, 20, 22, 0.72); }
.app-dialog form, .compact-dialog { padding: 18px; }
.compact-dialog { width: min(560px, calc(100vw - 24px)); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.dialog-kicker { display: block; margin-bottom: 3px; color: var(--muted); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; }
.dialog-note { color: var(--muted); font-size: 0.9rem; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 1px solid #9ea4aa; border-radius: 4px; background: #fff; color: var(--ink); font-size: 1.55rem; line-height: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid label, .stacked-label { display: grid; gap: 5px; color: #41464b; font-size: 0.82rem; font-weight: 700; }
.participant-select { margin-bottom: 12px; }
.registration-summary { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 16px; padding: 11px 12px; border: 1px solid var(--line); background: var(--soft); }
.dialog-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); background: #fff; }

.waiver-section { margin-top: 16px; padding: 13px; border: 2px solid #b78c21; border-radius: 5px; background: #fffdf4; }
.waiver-heading { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 8px; }
.waiver-heading div { display: grid; gap: 2px; }
.waiver-heading span { color: #705a1a; font-size: 0.75rem; font-weight: 800; text-transform: uppercase; }
.waiver-list { display: grid; gap: 12px; }
.waiver-document-card { padding: 11px; border: 1px solid #c8b578; border-radius: 4px; background: #fff; }
.waiver-document-card .waiver-heading { align-items: center; }
.waiver-document-card .waiver-heading strong { font-size: 0.94rem; }
.waiver-document-card .waiver-heading span { white-space: nowrap; }
.waiver-document-link { display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 7px 12px; border: 1px solid #3669a8; border-radius: 4px; background: #eef6ff; color: #174a84; font-size: 0.86rem; font-weight: 800; text-align: center; }
.waiver-text { max-height: 190px; overflow: auto; padding: 10px; border: 1px solid #c8b578; background: #fff; font-size: 0.85rem; line-height: 1.45; white-space: pre-wrap; }
.waiver-document-link + .waiver-text { margin-top: 8px; }
.waiver-signature-fields { margin-top: 10px; }
.waiver-accept { display: grid; grid-template-columns: 20px 1fr; align-items: start; gap: 8px; margin-top: 12px; font-size: 0.85rem; font-weight: 700; }
.waiver-accept input { width: 18px; min-height: 18px; margin: 0; }

.detail-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; margin: 0; }
.detail-list dt { color: var(--muted); font-weight: 700; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.live-rider-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.live-summary-metric { display: grid; min-height: 88px; place-content: center; gap: 4px; padding: 12px; border: 1px solid var(--line); border-radius: 5px; background: var(--soft); text-align: center; }
.live-summary-metric span { color: var(--muted); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; }
.live-summary-metric strong { font-size: 1.45rem; }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 50; max-width: min(440px, calc(100vw - 36px)); padding: 11px 14px; border: 1px solid #0f4224; border-radius: 5px; background: #155e32; color: #fff; font-weight: 700; box-shadow: 0 8px 24px rgba(0,0,0,0.24); }

@media (max-width: 760px) {
  .app-header { grid-template-columns: 94px minmax(0, 1fr); gap: 9px; min-height: 66px; padding: 8px 10px; }
  body.production-public .app-header { grid-template-columns: 94px; gap: 0; }
  .brand-logo { width: 94px; height: 40px; }
  .brand-copy strong { font-size: 0.88rem; }
  .brand-copy span { font-size: 0.7rem; }
  .header-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .view-tabs { display: none; }
  .mobile-view-nav {
    position: sticky;
    top: 103px;
    z-index: 19;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    background: #fff;
  }
  body.production-public .mobile-view-nav { top: 66px; padding-top: 5px; }
  .mobile-view-nav select { min-height: 44px; font-size: 16px; font-weight: 750; }
  body.production-public .mobile-view-nav select { font-size: 18px; font-weight: 800; }
  body.production-public .app-view > .section-header h1 {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .app-main { padding: 12px; }
  .event-card, .entry-card, .dependent-card { grid-template-columns: 1fr; gap: 12px; }
  .card-actions .button { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .section-header, .panel-heading, .data-toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-selects { flex-direction: column; }
  .data-toolbar select { width: 100%; }
  .results-toolbar-selects #resultsSeriesSelect,
  .results-toolbar-selects #resultsYearSelect,
  .results-toolbar-selects #resultsEventSelect,
  .results-toolbar-selects #resultsModeSelect { width: 100%; }
  .events-series-select, .events-year-select { width: 100%; min-height: 44px; font-size: 16px; }
  .number-lookup-controls { grid-template-columns: 1fr; }
  .number-lookup-controls #numberLookupWarning { grid-column: 1; }
  .live-rider-summary { grid-template-columns: 1fr; }
  .checkout-summary { grid-template-columns: auto 1fr; }
  .checkout-summary .button { grid-column: 1 / -1; }
}
