:root {
    --teal: #123d47;
    --teal-dark: #0b2d35;
    --teal-hover: #1b5664;
    --green: #79b68d;
    --green-soft: #d9ecdf;
    --bg-tint: #eef5f2;
    --ink: #16323a;
    --ink-soft: #5b7079;
    --danger: #c0463e;
}
* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background:
        radial-gradient(1100px 550px at 12% -12%, rgba(121, 182, 141, 0.14), transparent 60%),
        radial-gradient(900px 520px at 105% 0%, rgba(18, 61, 71, 0.08), transparent 55%),
        repeating-linear-gradient(135deg, rgba(18, 61, 71, 0.035) 0px, rgba(18, 61, 71, 0.035) 1px, transparent 1px, transparent 34px),
        linear-gradient(180deg, #f5faf8 0%, #eef5f2 45%, #e7f0eb 100%);
    background-attachment: fixed;
    color: var(--ink);
}

/* Topbar */
.topbar { background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%); box-shadow: 0 2px 14px rgba(11, 45, 53, 0.2); }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.brand-logo { height: 26px; width: auto; display: block; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--green) 0%, #4f9c74 100%); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 0.85rem; }
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.02rem; color: #fff; text-decoration: none; }
.topbar .brand .divider { width: 1px; height: 20px; background: rgba(255,255,255,0.25); }
.topbar nav { display: flex; align-items: center; gap: 26px; }
.topbar nav a { position: relative; color: rgba(255,255,255,0.72); text-decoration: none; padding: 8px 2px; font-size: 0.88rem; font-weight: 500; transition: color 0.15s; }
.topbar nav a:hover { color: #fff; }
.topbar nav a.active { color: #fff; font-weight: 700; }
.topbar nav a.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px; border-radius: 2px; background: var(--green); }
.topbar .user-info { display: flex; align-items: center; gap: 12px; font-size: 0.85rem; color: rgba(255,255,255,0.85); }
.topbar .user-avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.75rem; color: #fff; background: linear-gradient(135deg, var(--green) 0%, #4f9c74 100%); }
.topbar .portal-link { color: rgba(255,255,255,0.9); text-decoration: none; border: 1px solid rgba(255,255,255,0.3); padding: 6px 12px; border-radius: 8px; font-size: 0.82rem; }
.topbar .portal-link:hover { background: rgba(255,255,255,0.15); }
.topbar form.logout button { background: transparent; border: 1px solid rgba(255,255,255,0.3); color: #fff; padding: 6px 12px; font-size: 0.82rem; border-radius: 8px; }
.topbar form.logout button:hover { background: rgba(255,255,255,0.15); }

.page { max-width: 1100px; margin: 0 auto; padding: 32px 24px 60px; }
.page-narrow { max-width: 520px; }
h1 { color: var(--teal); font-size: 1.5rem; letter-spacing: -0.01em; margin: 0; }
h2 { color: var(--teal); font-size: 1.05rem; margin: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.sub { color: var(--ink-soft); font-size: 0.88rem; margin: 4px 0 0; }

.card { background: #fff; border-radius: 16px; padding: 22px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(18,61,71,0.05), 0 10px 26px -16px rgba(18,61,71,0.22); }
.card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.card-header .icon { width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; background: var(--green-soft); color: var(--teal); display: flex; align-items: center; justify-content: center; }

.msg { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 0.9rem; }
.msg.success { background: var(--green-soft); color: var(--teal-dark); }
.msg.error { background: #fde8e8; color: #7f1d1d; }
.msg.warn { background: #fdf3d8; color: #6b4e0a; }
.msg code { background: rgba(0,0,0,0.07); padding: 2px 6px; border-radius: 5px; font-size: 1rem; user-select: all; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid #eef2f1; font-size: 0.9rem; vertical-align: top; }
thead th { color: var(--ink-soft); font-weight: 600; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:hover { background: var(--bg-tint); }
tbody tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

label { display: block; font-weight: 600; margin: 14px 0 6px; font-size: 0.86rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], input[type=file], textarea, select {
    width: 100%; padding: 10px 12px; border: 1.5px solid #dbe6e3; border-radius: 8px; font-size: 14px; font-family: inherit; background: #fbfdfc; transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); background: #fff; }
textarea { min-height: 96px; resize: vertical; }
input[type=checkbox] { accent-color: var(--teal); width: 17px; height: 17px; cursor: pointer; flex-shrink: 0; }
.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; margin: 12px 0; cursor: pointer; }
.hint { color: var(--ink-soft); font-size: 0.8rem; margin: 4px 0 0; font-weight: 400; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

button, .btn { background: var(--teal); color: #fff; border: none; padding: 9px 16px; border-radius: 8px; font-size: 0.9rem; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; font-family: inherit; transition: background 0.15s; }
button:hover, .btn:hover { background: var(--teal-hover); }
.btn.secondary { background: var(--green-soft); color: var(--teal-dark); }
.btn.secondary:hover { background: #c7e2d0; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #a83c35; }
.btn.small { padding: 6px 12px; font-size: 0.82rem; border-radius: 7px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.03em; background: var(--green-soft); color: var(--teal-dark); margin-right: 4px; }
.badge.muted { background: #e6ecea; color: var(--ink-soft); }
.badge.dark { background: var(--teal); color: #fff; }
.badge.warn { background: #f5e8cf; color: #6b4e0a; }

/* Repeating rows */
.row-item { display: grid; gap: 10px; align-items: end; padding: 12px; margin-bottom: 10px; background: var(--bg-tint); border-radius: 10px; }
.row-item label { margin-top: 0; }
.row-participant { grid-template-columns: 130px 1fr 1fr 40px; }
.row-contact { grid-template-columns: 1fr 1fr 1fr 40px; }
@media (max-width: 720px) { .row-participant, .row-contact { grid-template-columns: 1fr; } }
.row-item .remove-row { background: transparent; color: var(--danger); font-size: 1.3rem; padding: 4px 10px; }
.row-item .remove-row:hover { background: #fde8e8; }
.org-field.is-hidden { visibility: hidden; }

/* Photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 12px 0; }
.photo-grid figure { margin: 0; position: relative; }
.photo-grid img { width: 100%; height: 130px; object-fit: cover; border-radius: 10px; display: block; background: #e6ecea; }
.photo-grid .remove { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 500; margin: 6px 0 0; }

/* Detail view */
dl.detail { margin: 0; }
dl.detail dt { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); font-weight: 600; margin-top: 16px; }
dl.detail dd { margin: 4px 0 0; white-space: pre-line; line-height: 1.5; }
dl.detail dd.plain { white-space: normal; }
.empty { color: var(--ink-soft); font-style: italic; }

/* Auth pages */
body.auth { display: flex; align-items: center; justify-content: center; padding: 24px;
    background:
        radial-gradient(900px circle at 12% 15%, rgba(121, 182, 141, 0.28), transparent 45%),
        radial-gradient(800px circle at 88% 85%, rgba(18, 61, 71, 0.22), transparent 45%),
        repeating-linear-gradient(135deg, rgba(18, 61, 71, 0.035) 0px, rgba(18, 61, 71, 0.035) 1px, transparent 1px, transparent 34px),
        linear-gradient(160deg, #eef5f2 0%, #e3ede8 100%);
    background-attachment: fixed;
}
.auth-card { background: #fff; border-radius: 20px; padding: 40px 36px 36px; width: 430px; max-width: 100%; box-shadow: 0 30px 60px -12px rgba(18, 61, 71, 0.28), 0 8px 20px rgba(18, 61, 71, 0.1); }
.auth-card .brand-logo { height: 52px; margin: 0 auto 22px; }
.auth-card h1 { text-align: center; margin-bottom: 6px; }
.auth-card .lead { text-align: center; color: var(--ink-soft); font-size: 0.88rem; margin: 0 0 22px; line-height: 1.45; }
.auth-card button[type=submit] { width: 100%; margin-top: 22px; padding: 13px; font-size: 1rem; border-radius: 10px; background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%); box-shadow: 0 4px 14px rgba(18, 61, 71, 0.25); }
.auth-card input { padding: 12px; font-size: 15px; border-radius: 10px; }
.auth-card .code-input { text-align: center; font-size: 1.6rem; letter-spacing: 0.35em; font-variant-numeric: tabular-nums; }
.qr { display: flex; justify-content: center; margin: 8px 0 14px; }
.qr svg { width: 220px; height: 220px; }
.secret { text-align: center; font-family: Consolas, monospace; letter-spacing: 0.08em; background: var(--bg-tint); border-radius: 8px; padding: 8px; word-break: break-all; user-select: all; font-size: 0.85rem; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 60px; }
.pw-wrap .toggle-password { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; color: var(--ink-soft); padding: 4px 8px; font-size: 0.75rem; font-weight: 600; }
.pw-wrap .toggle-password:hover { background: var(--green-soft); color: var(--teal); }
.auth-foot { text-align: center; margin-top: 18px; font-size: 0.82rem; color: var(--ink-soft); }
.auth-foot a { color: var(--teal); }
.hidden { display: none; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.center { text-align: center; }
.link-code { display: block; margin-top: 8px; word-break: break-all; }
.link-form-actions { margin-top: 12px; }

/* ---------- Visit form: modes ---------- */
[hidden] { display: none !important; }
.form-toolbar { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.mode-switch { display: inline-flex; background: #fff; border: 1.5px solid #dbe6e3; border-radius: 999px; padding: 3px; }
.mode-switch button { background: transparent; color: var(--ink-soft); padding: 7px 14px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.mode-switch button:hover { background: var(--green-soft); color: var(--teal-dark); }
.mode-switch button[aria-pressed=true], .mode-switch button[aria-pressed=true]:hover { background: var(--teal); color: #fff; }

.date-row { display: flex; gap: 8px; align-items: center; }
.date-row input[type=date] { flex: 1; min-width: 0; }
.has-error { border-color: var(--danger) !important; box-shadow: 0 0 0 3px #fde8e8 !important; }

.check.option { padding: 12px 14px; border: 1.5px solid #dbe6e3; border-radius: 10px; background: #fbfdfc; align-items: center; }
.check.option:has(input:checked) { border-color: var(--green); background: var(--green-soft); }

.photo-add { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; padding: 22px; margin-top: 4px; background: var(--bg-tint); color: var(--teal); border: 2px dashed #b9d3c6; border-radius: 14px; font-size: 1rem; }
.photo-add:hover { background: var(--green-soft); }
.photo-add:disabled { opacity: 0.6; cursor: progress; }
.photo-previews figure .remove-photo { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; padding: 0; border-radius: 50%; background: rgba(11,45,53,0.8); font-size: 1.1rem; line-height: 1; }
.draft-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.wizard-head, .wizard-nav { display: none; }
.wizard-bar { height: 6px; background: #dbe6e3; border-radius: 999px; overflow: hidden; }
.wizard-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--green), #4f9c74); border-radius: 999px; transition: width 0.25s; }
.wizard-label { font-size: 0.85rem; font-weight: 600; color: var(--teal); margin-bottom: 8px; }

form.mode-phone { max-width: 520px; margin: 0 auto; padding-bottom: 96px; }
form.mode-phone .wizard-head { display: block; margin-bottom: 14px; }
form.mode-phone .step { display: none; padding: 18px; }
form.mode-phone .step.is-active { display: block; }
form.mode-phone .form-actions { display: none; }
form.mode-phone input[type=text], form.mode-phone input[type=email], form.mode-phone input[type=date], form.mode-phone textarea, form.mode-phone select { font-size: 16px; padding: 13px 12px; }
form.mode-phone textarea { min-height: 120px; }
form.mode-phone .grid-2 { grid-template-columns: 1fr; }
form.mode-phone .row-participant, form.mode-phone .row-contact { grid-template-columns: 1fr; position: relative; padding-right: 44px; }
form.mode-phone .row-item .remove-row { position: absolute; top: 6px; right: 6px; }
form.mode-phone .btn.small { padding: 10px 14px; font-size: 0.9rem; }
form.mode-phone .wizard-nav { display: flex; justify-content: center; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #fff; box-shadow: 0 -6px 20px rgba(18,61,71,0.14); }
form.mode-phone .wizard-nav .inner { display: flex; gap: 10px; width: 100%; max-width: 520px; }
form.mode-phone .wizard-nav button { flex: 1; padding: 15px; font-size: 1rem; border-radius: 12px; }
form.mode-phone .wizard-nav .wizard-prev { flex: 0 0 34%; }
body.phone-mode .topbar-inner nav { display: none; }
form.mode-phone .org-field.is-hidden { display: none; }
@media (max-width: 640px) {
    .topbar-inner { padding: 12px 16px; }
    .topbar nav { order: 3; width: 100%; gap: 18px; overflow-x: auto; white-space: nowrap; padding-bottom: 2px; }
    .topbar .user-info { flex-wrap: wrap; }
    .page { padding: 20px 16px 60px; }
}
.who { margin: 0 0 4px; font-size: 1rem; }

/* Submission status */
.badge.new { background: var(--danger); color: #fff; }
.badge.done { background: var(--green); color: var(--teal-dark); }
.count-badge { display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 4px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 0.7rem; font-weight: 700; text-align: center; }
.link-thumbs { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.link-thumbs a { display: block; }
.link-thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; display: block; background: #e6ecea; }
.link-thumbs .more { display: flex; align-items: center; justify-content: center; width: 56px; height: 56px; border-radius: 8px; background: var(--bg-tint); color: var(--ink-soft); font-size: 0.8rem; font-weight: 600; text-decoration: none; }
tr.submitted td { background: #f4faf6; }

/* E-mail approval login */
.or-divider { display: flex; align-items: center; gap: 12px; margin: 22px 0 4px; color: var(--ink-soft); font-size: 0.8rem; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: #dbe6e3; }
.auth-card button.btn-alt, .auth-card button[type=submit].btn-alt { background: #fff; color: var(--teal); border: 1.5px solid var(--teal); box-shadow: none; }
.auth-card button.btn-alt:hover { background: var(--green-soft); }
.deny-form { margin-top: 0; }
.match-number { text-align: center; font-size: 4.5rem; font-weight: 800; color: var(--teal); letter-spacing: 0.06em; padding: 18px 0 6px; font-variant-numeric: tabular-nums; }
.hint.center { text-align: center; }

/* Report numbers and photo downloads */
.ref { font-family: Consolas, monospace; font-size: 0.82rem; color: var(--teal); font-weight: 700; white-space: nowrap; }
.ref-line { margin: 0 0 2px; font-family: Consolas, monospace; font-size: 0.85rem; color: var(--ink-soft); font-weight: 700; letter-spacing: 0.04em; }
.photo-grid-large { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.photo-grid-large img { height: 160px; }
.photo-grid figure .dl { display: block; margin-top: 6px; font-size: 0.8rem; font-weight: 600; }