/* ─── Design tokens ────────────────────────────────────────────────────────── */
:root {
  --primary:       #8B1A1A;
  --primary-dark:  #6B1313;
  --primary-light: #f9f0f0;
  --text:          #1a1a1a;
  --text-muted:    #666;
  --border:        #d8d8d8;
  --bg:            #f2f2f2;
  --white:         #ffffff;
  --error:         #c62828;
  --success:       #2e7d32;
  --radius:        8px;
  --shadow:        0 2px 10px rgba(0,0,0,0.09);
}

/* ─── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Base ──────────────────────────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

/* ─── Header ────────────────────────────────────────────────────────────────── */
header {
  background: var(--primary);
  color: #fff;
  padding: 14px 20px 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

header h1 {
  font-size: clamp(14px, 3vw, 18px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.ref {
  max-width: 720px;
  margin: 4px auto 0;
  font-size: 11px;
  opacity: 0.65;
}

#langToggle {
  flex-shrink: 0;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.45);
  color: #fff;
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.18s;
  white-space: nowrap;
}
#langToggle:hover { background: rgba(255,255,255,0.30); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-link {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  opacity: 0.85;
  white-space: nowrap;
}
.header-link:hover { opacity: 1; text-decoration: underline; }
.header-gear { font-size: 22px; line-height: 1; text-decoration: none !important; }

.session-banner {
  max-width: 720px;
  margin: 2px auto 0;
  font-size: 13px;
  font-weight: 600;
}

/* ─── Layout ────────────────────────────────────────────────────────────────── */
main {
  max-width: 720px;
  margin: 24px auto 60px;
  padding: 0 16px;
}

/* ─── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  padding-bottom: 8px;
  margin-bottom: 20px;
}

/* ─── Form fields ───────────────────────────────────────────────────────────── */
.field {
  margin-bottom: 14px;
  flex: 1;
}

.field-row {
  display: flex;
  gap: 14px;
  margin-bottom: 0;
}

.field-row .field { margin-bottom: 14px; }

.field--narrow { flex: 0 0 110px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
}

.optional {
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 2px;
}

.req {
  color: var(--primary);
  margin-left: 2px;
}

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.18s, box-shadow 0.18s;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' fill='none' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139,26,26,0.13);
}

.invalid,
.invalid:focus {
  border-color: var(--error) !important;
  box-shadow: 0 0 0 3px rgba(198,40,40,0.12) !important;
}

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

/* ─── Checklist ─────────────────────────────────────────────────────────────── */
.checklist {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.45;
}

.check-item input[type="checkbox"],
.check-item input[type="radio"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin-top: 1px;
  cursor: pointer;
  accent-color: var(--primary);
  border-radius: 3px;
}

/* ─── Error message ─────────────────────────────────────────────────────────── */
.error-msg {
  background: #fff0f0;
  border: 1px solid #ffcccc;
  border-left: 4px solid var(--error);
  color: var(--error);
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}

/* ─── Settings page ─────────────────────────────────────────────────────────── */
.hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.hint:last-child { margin-bottom: 0; }

.period-fields { margin-top: 18px; }

.upload-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--primary-light);
  border-radius: 6px;
  padding: 10px 12px;
  word-break: break-word;
}

.success-msg {
  background: #f0f8f0;
  border: 1px solid #c8e6c9;
  border-left: 4px solid var(--success);
  color: var(--success);
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}

/* Sessions editor */
.session-rows { display: flex; flex-direction: column; gap: 14px; margin: 6px 0 16px; }

.session-row {
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 14px 14px 10px;
}

.session-link-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.session-url {
  flex: 1 1 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--primary-light);
  border-radius: 6px;
  padding: 6px 10px;
  word-break: break-all;
}

.session-row-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.btn-small {
  flex-shrink: 0;
  background: var(--white);
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-small:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--error);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 8px;
}
.btn-remove:hover { text-decoration: underline; }

/* Yearly rollover */
.new-year { margin-top: 18px; }
.new-year summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 10px;
}
.new-year .checklist { margin-bottom: 14px; }

.history { margin-top: 18px; }
.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

/* QR code dialog */
.qr-dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: min(420px, calc(100vw - 32px));
  text-align: center;
}
.qr-dialog::backdrop { background: rgba(0,0,0,0.52); }
.qr-dialog h2 { font-size: 18px; color: var(--primary); margin-bottom: 4px; }
.qr-image { width: 260px; height: 260px; margin: 8px auto 12px; }
.qr-image svg { width: 100%; height: 100%; }
#qrUnsaved { color: var(--error); margin-top: 10px; }
.qr-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }

/* Congregations editor */
.cong-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 480px;
  overflow-y: auto;
  margin-bottom: 14px;
}

.cong-row { display: flex; align-items: center; gap: 8px; }
.cong-row input  { flex: 3; }
.cong-row select { flex: 2; }
.cong-row .btn-remove { font-size: 20px; line-height: 1; }
.cong-row--untracked input,
.cong-row--untracked select { color: var(--text-muted); background-color: #fafafa; }

.add-congs summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 10px;
}

.upload-path-label { font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
.upload-path-label:first-child { margin-top: 0; }

/* ─── Submit button ─────────────────────────────────────────────────────────── */
#submitBtn,
.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  transition: background 0.18s, transform 0.1s;
  margin-top: 4px;
}
#submitBtn:hover:not(:disabled),
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
#submitBtn:active:not(:disabled),
.btn-primary:active:not(:disabled) { transform: scale(0.99); }
#submitBtn:disabled,
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

/* ─── Success panel ─────────────────────────────────────────────────────────── */
.success-panel { text-align: center; padding: 40px 24px; }

.success-icon {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}

.success-panel h2 {
  border-bottom: none !important;
  color: var(--success) !important;
  font-size: 22px !important;
  margin-bottom: 8px !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

.success-panel > p {
  color: var(--text-muted);
  margin-bottom: 20px;
}

.drive-link { margin-bottom: 24px; font-size: 14px; }

.drive-link a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.drive-link a:hover { text-decoration: underline; }

#newReportBtn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 28px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s;
}
#newReportBtn:hover { background: var(--primary-dark); }

.btn-secondary {
  background: var(--white);
  color: var(--primary);
  border: 1.5px solid var(--primary);
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s;
}
.btn-secondary:hover { background: var(--primary-light); }

.test-result { margin: 14px 0 0; }

/* ─── Loading overlay ───────────────────────────────────────────────────────── */
#loadingOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.52);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  color: #fff;
  gap: 18px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.spinner {
  width: 46px;
  height: 46px;
  border: 4px solid rgba(255,255,255,0.28);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Convention picker ─────────────────────────────────────────────────────── */
.session-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.session-link {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.18s, background 0.18s;
}
.session-link:hover { border-color: var(--primary); background: var(--primary-light); }
.session-link span { font-size: 13px; color: var(--text-muted); }

a.btn-secondary { display: inline-block; text-decoration: none; }

/* ─── Legal pages & footer ──────────────────────────────────────────────────── */
.legal { line-height: 1.65; }
.legal h2 { margin-top: 28px; }
.legal p, .legal ul { margin-bottom: 12px; }
.legal ul { padding-left: 22px; }
.legal li { margin-bottom: 4px; }
.legal a, .site-footer a { color: var(--primary); }
.legal code { font-size: 13px; background: var(--primary-light); padding: 1px 5px; border-radius: 4px; }
.legal-updated { font-size: 13px; color: var(--text-muted); }

.site-footer {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin: -36px auto 32px;
  padding: 0 16px;
}

/* ─── Utility ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .card { padding: 16px; }
  .cong-row { flex-wrap: wrap; }
  .cong-row input { flex: 1 1 100%; }
  .field-row { flex-direction: column; gap: 0; }
  .field--narrow { flex: 1; }
}
