/* Mobile-first, single column. */
:root {
    --accent: #1a5e37;
    --accent-dark: #124428;
    --error: #b3261e;
    --text: #1d1d1f;
    --muted: #5f6368;
    --border: #c9ccd1;
    --bg: #f5f6f7;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

header {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    padding: 14px 16px;
}

main {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
}

h1 { font-size: 1.5rem; margin: 8px 0; }
.lead { color: var(--muted); margin-top: 0; }
.hint { color: var(--muted); font-size: 0.875rem; margin: 6px 0 0; }

.field { margin-bottom: 16px; }

label, .label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
}

input:not([type=hidden]) {
    width: 100%;
    padding: 12px;
    font-size: 16px; /* 16px stops iOS zooming into the field */
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input.input-validation-error { border-color: var(--error); }

.error, .field-validation-error { color: var(--error); font-size: 0.875rem; display: block; margin-top: 4px; }
.field-validation-valid { display: none; }

.alert {
    background: #fdecea;
    color: var(--error);
    border: 1px solid #f5c2bd;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}
.alert.validation-summary-valid { display: none; }
.alert ul { margin: 0; padding-left: 18px; }

.camera {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: #202124;
    border-radius: 12px;
    overflow: hidden;
}

/* Mirrored on screen only, as a mirror feels natural; the captured photo is not mirrored. */
.camera video, .camera img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.camera .placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #bdc1c6;
    padding: 16px;
    text-align: center;
}

.camera-buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

button {
    flex: 1;
    padding: 12px 16px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
}

button.primary {
    width: 100%;
    border: none;
    background: var(--accent);
    color: #fff;
    margin-top: 8px;
}
button.primary:hover { background: var(--accent-dark); }
button.primary:disabled { opacity: 0.6; cursor: wait; }

button.secondary {
    border: 1px solid var(--accent);
    background: #fff;
    color: var(--accent);
}
/* Take photo while the face check waits for the face (Registration:FaceCheck). */
button.secondary:disabled { opacity: 0.45; cursor: not-allowed; }

/* Face guide over the camera (and the photo): dimmed surround with an oval cut-out, as on the kiosk. */
.camera .face-guide {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.face-guide svg {
    display: block;
    width: 100%;
    height: 100%;
}
.face-guide-mask { fill: rgba(0, 0, 0, 0.45); }
.face-guide-ring {
    fill: none;
    stroke: #fff;
    stroke-width: 4;
    stroke-dasharray: 10 6;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
    opacity: 0.9;
}
.face-guide-hint {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 12px;
    text-align: center;
    color: #fff;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

[hidden] { display: none !important; }

/* Registration photo (AutoCapture / IcaoCrop / BackgroundRemoval / SpeedTest). */
.face-guide.aligned .face-guide-ring { stroke: #34c759; stroke-dasharray: none; opacity: 1; }
/* A cropped photo: the camera box takes the photo's shape (selfie.js), so it fills it exactly. */
.camera img.cropped { object-fit: cover; }
/* A transparent background (BackgroundColour "transparent") shown as a checkerboard. */
.camera img.transparent {
    object-fit: contain;
    background: repeating-conic-gradient(#d0d3d7 0 25%, #f1f3f4 0 50%) 0 0 / 24px 24px;
}
.speed-test {
    margin-top: 12px;
    padding: 10px 12px;
    background: #fff;
    border: 1px dashed var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
}
.speed-test h2 { font-size: 0.95rem; margin: 0 0 6px; }
.speed-test dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; }
.speed-test dt { color: var(--muted); }
.speed-test dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.success { text-align: center; padding-top: 32px; }
.success .tick {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 40px;
    line-height: 72px;
}

/* ---- Admin dashboard ---- */
main.wide { max-width: 1100px; }

h2 { font-size: 1.15rem; margin: 24px 0 8px; }
h2 .count { color: var(--muted); font-weight: 400; }

a.button {
    display: inline-block;
    padding: 12px 16px;
    font-weight: 600;
    border-radius: 8px;
    text-decoration: none;
    text-align: center;
}
a.button.secondary { border: 1px solid var(--accent); background: #fff; color: var(--accent); }

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 12px;
}
.tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 18px 20px;
    background: #fff;
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
}
.tile:hover { border-color: var(--accent); }
.tile.active { border-color: var(--accent); background: #eaf4ee; }
.tile-label { color: var(--muted); font-weight: 600; }
.tile-value { font-size: 2.25rem; font-weight: 700; color: var(--accent); }
.tile.mia .tile-value { color: var(--error); }
.tile.mia.active { border-color: var(--error); background: #fdeceb; }
.tile.mia:hover { border-color: var(--error); }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 16px 0; }

/* ---- Admin: navigation and events (mobile-first; widens on larger screens) ---- */
.admin-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: -4px 0 12px;
    border-bottom: 1px solid var(--border);
}
.admin-nav a, .admin-nav button.link {
    padding: 10px 12px;
    color: var(--muted);
    font-weight: 600;
    text-decoration: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
}
.admin-nav a.active { color: var(--accent); border-bottom-color: var(--accent); }
.admin-nav form { margin-left: auto; }
button.link {
    flex: none;
    background: none;
    border: none;
    border-radius: 0;
    font-size: 1rem;
    cursor: pointer;
}

.back { margin: 0 0 4px; }
.back a { color: var(--accent); text-decoration: none; font-weight: 600; }

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
}
.page-head h1 { margin-right: auto; overflow-wrap: anywhere; }

a.button.primary { background: var(--accent); color: #fff; border: 1px solid var(--accent); }
a.button.primary:hover { background: var(--accent-dark); }
button.danger, a.button.danger { border: 1px solid var(--error); background: #fff; color: var(--error); }
button.small { flex: none; padding: 6px 10px; font-size: 0.875rem; }

.notice {
    background: #eaf4ee;
    color: var(--accent-dark);
    border: 1px solid #b9dcc6;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}
.badge.draft { background: #eceef0; color: var(--muted); }
.badge.open { background: #e3eefc; color: #1a4f8a; }
.badge.live { background: #eaf4ee; color: var(--accent); }
.badge.closed { background: #f3e8e8; color: #7a3b3b; }

.event-list { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 10px; }
.event-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 16px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
}
.event-card:hover { border-color: var(--accent); }
.event-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.event-name { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.event-times { color: var(--muted); margin: 0; }
.event-counts { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 0.9rem; margin: 0; }
.event-counts strong { color: var(--text); }

.event-head .event-counts { margin-top: 4px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions > *, .actions form button { flex: none; }
.actions form { margin: 0; }
.actions button, .actions a.button { width: auto; margin-top: 0; padding: 10px 14px; font-size: 1rem; line-height: 1.25; }
button { font-family: inherit; }

.panel {
    margin-top: 20px;
    padding: 14px 16px 16px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
}
.panel h2 { margin-top: 0; }

.qr { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.qr-image { width: 100%; max-width: 260px; margin: 0 auto; }
.qr-image svg { display: block; width: 100%; height: auto; }
.qr-text { min-width: 0; }
.link-box { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.link-box code { overflow-wrap: anywhere; font-size: 0.9rem; }

.import { margin: 12px 0; }
.import input[type=file] { padding: 10px; }
.import button.primary { width: auto; }

.import-result { margin: 12px 0; padding: 12px; border-radius: 8px; background: #eaf4ee; border: 1px solid #b9dcc6; }
.import-result.has-errors { background: #fff8e6; border-color: #f0d9a0; }
.import-result p { margin: 0; }
.import-errors { margin: 8px 0 0; padding-left: 20px; max-height: 260px; overflow-y: auto; font-size: 0.9rem; }

.list-filter { margin: 16px 0 8px; }
.invitee-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid #eceef0; }
.invitee-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 12px;
    padding: 10px 0;
    border-bottom: 1px solid #eceef0;
}
.invitee-main { display: flex; flex-direction: column; min-width: 0; }
.invitee-name { font-weight: 600; overflow-wrap: anywhere; }
.invitee-meta { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.invitee-side { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.invitee-side form { margin: 0; }

@media (min-width: 720px) {
    .qr { flex-direction: row; align-items: flex-start; }
    .qr-image { width: 220px; margin: 0; flex: none; }
    .event-list { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
}

/* ---- Registration through a link ---- */
.event-banner {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 14px;
    margin: 4px 0 12px;
    background: #eaf4ee;
    border: 1px solid #b9dcc6;
    border-radius: 10px;
}
.event-banner strong { font-size: 1.05rem; overflow-wrap: anywhere; }
.event-banner span { color: var(--muted); font-size: 0.9rem; }
.readonly-value {
    padding: 12px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    background: #f0f1f3;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
}
.button.block, button.block { display: block; width: 100%; margin: 12px 0; }

/* ---- Admin dashboard: one event ---- */
.event-picker { margin: 8px 0 4px; }
.event-picker select {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}
.event-times .badge { margin-right: 4px; }
.event-times a { color: var(--accent); font-weight: 600; }

.export-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 12px 0; }
.export-bar a.button { padding: 8px 12px; font-size: 0.95rem; }
label.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 600; }
label.check input { width: auto; }

/* Four tiles: two by two on a phone, one row on a wider screen. */
.tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tiles.four .tile { padding: 12px 14px; }
.tiles.four .tile-value { font-size: 1.9rem; }

.people { list-style: none; margin: 8px 0; padding: 0; background: #fff; border: 1px solid var(--border); border-radius: 12px; }
.people li {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 4px 12px;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #eceef0;
}
.people li:last-child { border-bottom: none; }
.thumb {
    grid-row: span 2;
    width: 56px;
    height: 56px;
    padding: 0;
    border: none;
    border-radius: 10px;
    overflow: hidden;
    background: #eceef0;
    flex: none;
}
button.thumb { cursor: zoom-in; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb.none { display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 700; font-size: 1.3rem; }
.person { display: flex; flex-direction: column; min-width: 0; }
.person-name { font-weight: 700; overflow-wrap: anywhere; }
.person-meta { color: var(--muted); font-size: 0.875rem; }
.person-times { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.contact { grid-column: 2; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }

/* Contact numbers: tel: links; a row turns amber once an admin has tapped the number. */
a.contact-link { color: var(--accent); font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.contacted-note { font-size: 0.8rem; color: var(--muted); }
.contacted-note:empty { display: none; }
.people li.contacted { background: #fff3cd; }
.people li.contacted a.contact-link, .people li.contacted .contacted-note { color: #8a5300; }

.refresh-status { text-align: center; }

.photo-viewer {
    width: min(92vw, 520px);
    max-height: 92vh;
    padding: 12px;
    border: none;
    border-radius: 14px;
}
.photo-viewer::backdrop { background: rgba(0, 0, 0, 0.7); }
.photo-viewer img { display: block; width: 100%; height: auto; max-height: 70vh; object-fit: contain; border-radius: 8px; background: #202124; }
.photo-viewer form { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.photo-viewer .close { flex: none; padding: 6px 12px; }
.photo-viewer-name { font-weight: 700; margin: 0 0 8px; }

@media (min-width: 720px) {
    .tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
    .tiles.four .tile { padding: 18px 20px; }
    .tiles.four .tile-value { font-size: 2.25rem; }
    .people li { grid-template-columns: 56px minmax(0, 1fr) auto; }
    .thumb { grid-row: auto; }
    .contact { grid-column: auto; flex-direction: column; align-items: flex-end; text-align: right; }
}
