/* ---------------------------------------------------------------------------
   Family Registration UI

   Two audiences, one stylesheet:
   - Families, on a phone, once, possibly in a hurry. Big targets, few words,
     nothing to type.
   - Panitia, on a laptop, for an hour. Dense tables, small controls.

   Mobile-first. No horizontal scroll at 360px; wide tables scroll inside their
   own container rather than pushing the page sideways.
--------------------------------------------------------------------------- */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #d9dfe7;
  --text: #17212e;
  --muted: #5b6a7d;
  --brand: #12603f;
  --brand-dark: #0d472f;
  --brand-soft: #e6f2ec;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4e0;
  --ok: #1c6b3f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  --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.55;
  color: var(--text);
  background: var(--bg);
  overflow-wrap: break-word;
}

.page {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

body.admin .page,
body.public .page { max-width: 1180px; }

body.admin,
body.public {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "banner"
    "side"
    "main";
  grid-template-rows: auto auto 1fr;
  min-height: 100vh;
  align-items: stretch;
  align-content: start;
}
body.admin .dev-banner,
body.public .dev-banner { grid-area: banner; }
body.admin .sidebar,
body.public .sidebar { grid-area: side; }
body.admin .page,
body.public .page { grid-area: main; }

@media (min-width: 800px) {
  body.admin,
  body.public {
    grid-template-columns: 240px minmax(0, 1fr);
    grid-template-areas:
      "banner banner"
      "side main";
    grid-template-rows: auto 1fr;
  }
  body.admin .sidebar,
  body.public .sidebar {
    display: block;
    position: sticky;
    top: 0;
    min-height: 100vh;
    padding: 16px 12px 24px;
  }
  .sidebar-brand {
    display: block;
    padding: 8px 10px 16px;
    font-size: 1rem;
  }
  .sidebar .nav-label {
    display: block;
    margin: 12px 10px 4px;
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #9cb5a8;
  }
  .sidebar a:not(.sidebar-brand) {
    display: block;
    flex: none;
    min-height: 0;
    justify-content: flex-start;
    text-align: left;
    font-size: .9375rem;
    padding: 8px 10px;
  }
  .sidebar-foot {
    margin-top: 20px;
    padding: 12px 10px 0;
  }
  body.admin .page,
  body.public .page {
    max-width: none;
    padding: 28px 28px 64px;
  }
}

h1 { font-size: 1.4rem; line-height: 1.3; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 0 0 8px; }
p  { margin: 0 0 12px; }

a { color: var(--brand); }

.muted { color: var(--muted); font-size: .875rem; }
.center { text-align: center; }
.stack > * + * { margin-top: 16px; }

/* --- cards ---------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card + .card { margin-top: 16px; }
.card-tight { padding: 14px 16px; }

/* --- verified banner ------------------------------------------------------ */

.verified {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  border: 1px solid #bcdcc9;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 600;
}

.verified .tick {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 14px;
}

.identity { margin-top: 16px; }
.identity .name { font-size: 1.35rem; font-weight: 700; line-height: 1.25; }
.identity .code {
  display: inline-block;
  margin-top: 4px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .875rem;
  color: var(--muted);
  background: #eef1f5;
  border-radius: 6px;
  padding: 2px 8px;
}

/* --- member picker -------------------------------------------------------- */

.member-list { list-style: none; margin: 0; padding: 0; }

.member {
  display: flex;
  align-items: center;
  gap: 14px;
  /* 60px keeps every row comfortably above the 44px touch-target minimum. */
  min-height: 60px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}

.member + .member { margin-top: 10px; }
.member:hover { border-color: #b6c1cf; }

.member input[type="checkbox"] {
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  accent-color: var(--brand);
  margin: 0;
  cursor: pointer;
}

.member .who { min-width: 0; }
.member .who strong { display: block; font-weight: 600; }
.member .who span { display: block; font-size: .8125rem; color: var(--muted); }

.member:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.member input:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* --- live counter --------------------------------------------------------- */

.counter {
  position: sticky;
  bottom: 0;
  margin-top: 20px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 16px rgba(16, 24, 40, .07);
}

.counter .line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.counter .value { font-size: 1.5rem; font-weight: 700; color: var(--brand); }

/* --- buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

.btn:hover { background: var(--brand-dark); }
.btn:disabled { background: #b9c3cd; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid var(--brand-dark); outline-offset: 2px; }

.btn-block { width: 100%; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: #eef1f5; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8f1e17; }

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .8125rem; }

.btn-row { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
@media (min-width: 560px) {
  .btn-row { flex-direction: row-reverse; }
  .btn-row .btn { flex: 1; }
}

/* --- alerts --------------------------------------------------------------- */

.alert {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  border: 1px solid;
  font-size: .9375rem;
}

.alert-error { background: var(--danger-soft); border-color: #f3c4c0; color: #7d1a15; }
.alert-warn  { background: var(--warn-soft);  border-color: #f0d9a8; color: var(--warn); }
.alert-ok    { background: var(--brand-soft); border-color: #bcdcc9; color: var(--brand-dark); }
.alert-info  { background: #e8f0fb; border-color: #c3d7f2; color: #1d4272; }

/* --- dev banner ----------------------------------------------------------- */

.dev-banner {
  background: #2b3240;
  color: #e8edf5;
  font-size: .8125rem;
  padding: 8px 16px;
  text-align: center;
}
.dev-banner code { color: #ffd479; }

/* --- summary / receipt ---------------------------------------------------- */

.summary { list-style: none; margin: 0 0 4px; padding: 0; }
.summary li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px solid #eef1f5;
}
.summary li:last-child { border-bottom: 0; }
.summary .tick { color: var(--ok); font-weight: 700; }

.receipt {
  text-align: center;
  padding: 28px 20px;
  border: 2px solid var(--brand);
  border-radius: var(--radius);
  background: var(--brand-soft);
}
.receipt .big { font-size: 2.5rem; font-weight: 700; color: var(--brand); line-height: 1; }
.receipt .reg-code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: .04em;
}
.qr { max-width: 180px; margin: 16px auto 0; display: block; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .9375rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

/* --- forms ---------------------------------------------------------------- */

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: .875rem; font-weight: 600; margin-bottom: 5px; }

input[type="text"], input[type="password"], input[type="search"],
input[type="email"], input[type="tel"], input[type="file"],
select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
}

input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

textarea { min-height: 90px; resize: vertical; }

.form-row { display: grid; gap: 0 14px; }
@media (min-width: 720px) { .form-row.cols-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 720px) { .form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }

/* --- chrome: compact bar on a phone, left rail from 800px ---------------- */

.sidebar {
  background: var(--brand-dark);
  color: #e4f0ea;
  padding: 10px max(12px, env(safe-area-inset-right, 0px)) 12px max(12px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.sidebar-brand {
  flex: 1 1 100%;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  padding: 2px 6px 4px;
  font-size: .9rem;
}
.sidebar .nav-label {
  display: none;
}
.sidebar a:not(.sidebar-brand) {
  flex: 1 1 30%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  color: #cfe0d7;
  text-decoration: none;
  font-size: .875rem;
  padding: 10px 8px;
  border-radius: 8px;
  text-align: center;
}
.sidebar a:not(.sidebar-brand):hover,
.sidebar a.active {
  background: var(--brand);
  color: #fff;
}
.sidebar-foot {
  flex: 1 1 100%;
  margin-top: 4px;
  padding: 8px 6px 0;
  border-top: 1px solid rgba(255,255,255,.12);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
}
.sidebar-foot .muted { color: #cfe0d7; }
.sidebar form { margin: 0; }
.sidebar .linkbtn {
  background: none; border: 0; color: #e4f0ea; font: inherit; cursor: pointer; padding: 0;
}

.topbar {
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
}
.topbar .brand { font-weight: 700; margin-right: auto; }
.topbar a { color: #e4f0ea; text-decoration: none; font-size: .9375rem; padding: 4px 0; }
.topbar a:hover, .topbar a.active { color: #fff; text-decoration: underline; }
.topbar form { margin: 0; }
.topbar .linkbtn {
  background: none; border: 0; color: #e4f0ea; font: inherit; cursor: pointer; padding: 4px 0;
}

/* --- stats ---------------------------------------------------------------- */

.stats { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 860px) { .stats { grid-template-columns: repeat(4, 1fr); } }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat .n { font-size: 1.75rem; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: .8125rem; color: var(--muted); }

/* --- tables --------------------------------------------------------------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
tbody tr:hover { background: #fafbfc; }
td.nowrap, th.nowrap { white-space: nowrap; }

.mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .8125rem;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
  background: #eef1f5;
  color: var(--muted);
}
.badge-ok      { background: var(--brand-soft); color: var(--brand-dark); }
.badge-warn    { background: var(--warn-soft);  color: var(--warn); }
.badge-danger  { background: var(--danger-soft); color: #7d1a15; }

.linkbox {
  display: block;
  width: 100%;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .8125rem;
  padding: 10px 12px;
  background: #f7f9fb;
  border: 1px dashed var(--border);
  border-radius: 8px;
  word-break: break-all;
}

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.toolbar > * { margin: 0; }
.toolbar .grow { flex: 1 1 220px; }

details.panel { margin-bottom: 16px; }
details.panel > summary {
  cursor: pointer;
  font-weight: 600;
  padding: 10px 0;
  list-style: revert;
}

.pager { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; margin-top: 18px; }

.errors { margin: 0; padding-left: 20px; font-size: .875rem; }
.errors li { margin-bottom: 4px; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}

/* --- public family picker -------------------------------------------------
   One form per row so a single tap chooses a family unambiguously. Laid out
   like .member so the two public lists feel like the same control.          */

.picker {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 60px;
  padding: 10px 14px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .12s, background .12s;
}

.picker:hover { border-color: var(--brand); background: var(--brand-soft); }

.picker .who { flex: 1 1 auto; min-width: 0; }
.picker .who strong { display: block; font-weight: 600; }
.picker .who span {
  display: block;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .8125rem;
  color: var(--muted);
}
.picker .btn { flex: 0 0 auto; min-height: 44px; padding: 8px 14px; }

.member-list li + li .picker { margin-top: 0; }
