/* Judge's Logbook — mobile-first, built to be readable outdoors.
 *
 * Two constraints drove the palette and sizing (FR-053, FR-054, SC-011):
 *   1. Every text/background pair is >= 4.5:1. Phones get used in direct
 *      sunlight on a landing area, where low-contrast greys vanish entirely.
 *   2. Every interactive control is >= 44px on its shortest side, operable
 *      one-handed while holding a clipboard.
 * Disabled states darken rather than fade, because a faded control is
 * unreadable outdoors — the usual accessibility failure in a design like this.
 */

:root {
  --navy-900: #0b1a2b;
  --navy-800: #0e2033;
  --navy-700: #16324f;
  --navy-600: #1e4772;

  --ink: #0e2033;          /* 14.6:1 on white */
  --ink-soft: #3f5468;     /* 7.4:1 on white  */
  --ink-faint: #55697c;    /* 5.4:1 on white — the lightest text allowed */

  --paper: #ffffff;
  --paper-2: #f4f7fa;
  --paper-3: #e6edf4;
  --rule: #c3d0dd;

  --amber-bg: #fff4d6;
  --amber-line: #b07400;
  --amber-ink: #6b4600;    /* 7.6:1 on --amber-bg */

  --green-bg: #e3f6e8;
  --green-line: #1c7a3c;
  --green-ink: #14532d;

  --red-bg: #fdeaea;
  --red-line: #b3261e;
  --red-ink: #7f1d1d;

  --blue-bg: #e4eefb;
  --blue-line: #1e4772;

  --touch: 44px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(14, 32, 51, 0.09), 0 2px 8px rgba(14, 32, 51, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper-2);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------------------------------------------------------------- layout */

.wrap { max-width: 900px; margin: 0 auto; padding: 0 16px; }

.appbar {
  background: var(--navy-800);
  color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.appbar .wrap { display: flex; align-items: center; gap: 12px; }

.appbar a { color: #fff; text-decoration: none; }

.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand svg { flex: none; }

.appbar nav {
  margin-left: auto;
  display: flex;
  gap: 2px;
  align-items: center;
}

.appbar nav a,
.appbar nav button {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  background: none;
  border: 0;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
}

.appbar nav a[aria-current="page"] { background: rgba(255, 255, 255, 0.18); }
.appbar nav a:hover,
.appbar nav button:hover { background: rgba(255, 255, 255, 0.12); }

main { padding: 18px 0 56px; }

h1 { font-size: 24px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 24px 0 10px; }
h3 { font-size: 15px; margin: 18px 0 8px; text-transform: none; }

.lede { color: var(--ink-soft); margin: 0 0 20px; }

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head > div:first-child { flex: 1 1 240px; }

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

.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.card.tight { padding: 12px 14px; }

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

.btn {
  min-height: var(--touch);
  min-width: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1.5px solid var(--navy-700);
  background: var(--navy-700);
  color: #fff;
  font: inherit;
  font-weight: 650;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: var(--navy-600); border-color: var(--navy-600); }
.btn:active { transform: translateY(1px); }

.btn.secondary {
  background: var(--paper);
  color: var(--navy-700);
  border-color: var(--rule);
}
.btn.secondary:hover { background: var(--paper-2); border-color: var(--navy-600); }

.btn.danger { background: var(--red-line); border-color: var(--red-line); }
.btn.danger:hover { background: #8f1e17; border-color: #8f1e17; }

.btn.ghost {
  background: none;
  border-color: transparent;
  color: var(--navy-700);
  text-decoration: underline;
}

.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 18px; }

/* Disabled controls darken and keep a visible border rather than fading out —
 * a 40%-opacity button is invisible in sunlight. */
.btn:disabled,
.btn[aria-disabled="true"] {
  background: var(--paper-3);
  color: var(--ink-faint);
  border-color: var(--rule);
  cursor: not-allowed;
  transform: none;
}

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

:focus-visible {
  outline: 3px solid #1f6feb;
  outline-offset: 2px;
}

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

.field { margin-bottom: 16px; }

label {
  display: block;
  font-weight: 650;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--ink);
}

.hint { font-weight: 400; color: var(--ink-faint); font-size: 13px; }

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="number"], input[type="search"],
select, textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;               /* 16px stops iOS zooming the page on focus */
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  appearance: none;
}

textarea { min-height: 90px; resize: vertical; }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%230e2033' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--navy-600);
  outline: 3px solid rgba(30, 71, 114, 0.25);
  outline-offset: 0;
}

.field.error input, .field.error select, .field.error textarea {
  border-color: var(--red-line);
}

.field-error {
  color: var(--red-ink);
  font-size: 14px;
  font-weight: 600;
  margin-top: 5px;
}

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 160px; margin-bottom: 16px; }

/* Discipline / role pickers — real tap targets, not tiny checkboxes */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  padding: 8px 14px;
  border: 1.5px solid var(--rule);
  border-radius: 22px;
  background: var(--paper);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.chip:has(input:checked) {
  background: var(--navy-700);
  border-color: var(--navy-700);
  color: #fff;
}

.chip:has(input:focus-visible) { outline: 3px solid #1f6feb; outline-offset: 2px; }

/* Events Judged / Number of Jumps — the paper logbook's left-hand grid.
 * Each row is a tick plus, once ticked, its jumps and detail fields. */

.event-row {
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  margin-bottom: 7px;
  overflow: hidden;
}

.event-row.on { border-color: var(--navy-700); }

.event-tick {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--touch);
  padding: 8px 12px;
  margin: 0;
  cursor: pointer;
  font-weight: 600;
}

.event-tick input[type="checkbox"] {
  flex: none;
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--navy-700);
}

.event-code {
  flex: none;
  min-width: 42px;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--paper-3);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-align: center;
}

.event-row.on .event-code { background: var(--navy-700); color: #fff; }
.event-label { font-size: 15px; font-weight: 600; }

/* Hidden until the event is ticked — keeps a 12-row form from being a wall
 * of empty inputs. */
.event-extra { display: none; gap: 10px; padding: 0 12px 10px 12px; }
.event-row.on .event-extra { display: flex; }
.event-extra label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  margin-bottom: 4px;
}
.event-jumps { flex: 0 0 88px; }
.event-detail { flex: 1 1 140px; }

.chip-group { margin-bottom: 14px; }
.chip-group > .chip-group-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin-bottom: 7px;
}

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid;
  white-space: nowrap;
}

.badge.draft   { background: var(--paper-3); color: var(--ink); border-color: var(--rule); }
.badge.pending { background: var(--amber-bg); color: var(--amber-ink); border-color: var(--amber-line); }
.badge.signed  { background: var(--green-bg); color: var(--green-ink); border-color: var(--green-line); }
.badge.voided  { background: var(--red-bg); color: var(--red-ink); border-color: var(--red-line); }
.badge.unsynced { background: var(--amber-bg); color: var(--amber-ink); border-color: var(--amber-line); }

/* ---------------------------------------------------------------- notices */

.notice {
  border: 1.5px solid;
  border-left-width: 5px;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 15px;
}

.notice strong { display: block; margin-bottom: 2px; }
.notice.info   { background: var(--blue-bg); border-color: var(--blue-line); color: var(--ink); }
.notice.warn   { background: var(--amber-bg); border-color: var(--amber-line); color: var(--amber-ink); }
.notice.good   { background: var(--green-bg); border-color: var(--green-line); color: var(--green-ink); }
.notice.bad    { background: var(--red-bg); border-color: var(--red-line); color: var(--red-ink); }

/* Sync banner — pinned, because an unsynced signature is unrepeatable data */

#sync-banner {
  position: sticky;
  top: 0;
  z-index: 15;
  display: none;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  background: var(--amber-bg);
  color: var(--amber-ink);
  border-bottom: 2px solid var(--amber-line);
}

#sync-banner.show { display: block; }
#sync-banner.critical {
  background: var(--red-bg);
  color: var(--red-ink);
  border-bottom-color: var(--red-line);
}
#sync-banner .wrap { display: flex; align-items: center; gap: 10px; }
#sync-banner button {
  margin-left: auto;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1.5px solid currentColor;
  background: rgba(255, 255, 255, 0.65);
  color: inherit;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

/* ---------------------------------------------------------------- entries */

.entry-list { list-style: none; margin: 0; padding: 0; }

.entry {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-left: 5px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 15px;
  margin-bottom: 10px;
}

.entry:hover { border-color: var(--navy-600); }
.entry.status-signed  { border-left-color: var(--green-line); }
.entry.status-pending { border-left-color: var(--amber-line); }
.entry.status-voided  { border-left-color: var(--red-line); opacity: 0.85; }

.entry-top {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 3px;
}

.entry-name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.entry-dates { font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.entry-meta { font-size: 14px; color: var(--ink-soft); }
.entry-badges { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: 8px 16px;
  font-size: 15px;
}
.detail-grid dt { font-weight: 650; color: var(--ink-soft); }
.detail-grid dd { margin: 0; }

.sig-preview {
  max-width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 6px;
}

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

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.stat .n { font-size: 30px; font-weight: 750; line-height: 1.1; letter-spacing: -0.02em; }
.stat .k { font-size: 13px; font-weight: 650; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }

table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th, table.data td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--rule);
}
table.data th { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------------------------------------------------------------- empty */

.empty { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.empty h2 { margin-top: 0; color: var(--ink); }

/* ---------------------------------------------------------------- auth */

.auth { max-width: 420px; margin: 32px auto; }

/* ---------------------------------------------------------------- audit */

.audit { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.audit li {
  padding: 8px 0 8px 14px;
  border-left: 2px solid var(--rule);
  color: var(--ink-soft);
}
.audit li strong { color: var(--ink); }

/* ================================================================
 * THE SIDEWAYS SIGNATURE STRIP
 *
 * Rotated in CSS, inside a normal portrait page. NOT via
 * screen.orientation.lock() — that needs a fullscreen context, and the
 * Fullscreen API does not exist in Safari on iPhone at all, so orientation
 * locking is simply impossible on the target device (research R2).
 *
 * Rotating in CSS is also the better behaviour: it is immune to the system
 * rotation lock most people leave switched on, and it is already correctly
 * oriented the moment the judge turns the phone toward the Chief Judge.
 * ================================================================ */

.sign-stage {
  position: relative;
  width: 100%;
  /* Tall in portrait so the rotated child has room to be wide. */
  height: min(70vh, 520px);
  background: var(--navy-900);
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: none;
}

.sign-rotor {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* Width/height are set from the stage's inverted dimensions by
   * signature.js, so the rotated box fills the stage. */
}

/* Step 2 of the in-person flow has the screen to itself, so the strip takes
 * nearly all of it. `svh` tracks the *small* viewport so iOS Safari's
 * collapsing toolbars cannot push the Confirm button off-screen. */
.sign-stage.tall { height: min(72svh, 620px); }

.sign-rotor .sign-label {
  color: #dce6f0;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sign-canvas-shell {
  position: relative;
  flex: 1;
  background: #fff;
  border-radius: 8px;
  border: 2px solid #dce6f0;
  overflow: hidden;
}

canvas.sign-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;               /* a stroke must never scroll the page */
  cursor: crosshair;
}

.sign-baseline {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 24%;
  border-bottom: 2px dashed #b7c6d6;
  pointer-events: none;
}

.sign-x {
  position: absolute;
  left: 5%;
  bottom: calc(24% + 4px);
  font-size: 22px;
  font-weight: 700;
  color: #b7c6d6;
  pointer-events: none;
}

.sign-rotor .sign-actions { display: flex; gap: 10px; align-items: center; }
.sign-rotor .sign-actions .btn { flex: 1; }
.sign-rotor .sign-actions .btn.secondary {
  background: rgba(255, 255, 255, 0.94);
  flex: 0 0 auto;
  min-width: 110px;
}

/* On a wide screen there is no need to rotate — a laptop signer gets a
 * normal wide strip. The rotation only helps a phone held out sideways. */
@media (min-width: 820px) and (min-aspect-ratio: 1/1) {
  .sign-stage { height: 380px; background: var(--navy-900); }
  .sign-rotor {
    transform: translate(-50%, -50%);
    width: calc(100% - 28px) !important;
    height: calc(100% - 28px) !important;
  }
}

.handoff {
  background: var(--navy-800);
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.handoff h1 { font-size: 18px; margin-bottom: 3px; }
.handoff p { margin: 0; color: #d5e0eb; font-size: 14px; line-height: 1.35; }
.handoff .review {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
  font-size: 15px;
}
.handoff .review dt { color: #a9bccd; font-weight: 650; font-size: 13px; }
.handoff .review dd { margin: 0 0 8px; }

/* Two-column so five facts cost five lines, not ten. */
.handoff .review.compact {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 4px 10px;
  align-items: baseline;
  font-size: 14.5px;
  line-height: 1.35;
}
.handoff .review.compact dt { margin: 0; }
.handoff .review.compact dd { margin: 0; }

/* ---------------------------------------------------------------- misc */

.muted { color: var(--ink-soft); }
.small { font-size: 14px; }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; }
.mb0 { margin-bottom: 0; }
.spacer { height: 12px; }
hr.rule { border: 0; border-top: 1px solid var(--rule); margin: 18px 0; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin-bottom: 0; flex: 1 1 120px; }

.consent {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  background: var(--paper-2);
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}
.consent input[type="checkbox"] {
  flex: none;
  width: 26px;
  height: 26px;
  margin: 0;
  accent-color: var(--navy-700);
}

@media (max-width: 560px) {
  h1 { font-size: 21px; }
  .appbar nav a, .appbar nav button { padding: 0 8px; font-size: 14px; }
  .card { padding: 14px; }
  /* The wordmark is the first thing to go — the nav must never clip. */
  .brand-text { display: none; }
}

@media print {
  .appbar, #sync-banner, .btn, .filters { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #999; }
}
