/* PIWC-Essen Local Church Registration System
   Base stylesheet. Mobile-first: attendance marking is used on a phone under
   time pressure (spec 60, 95), so touch targets are generous and the layout
   works at 320px before it works at 1400px. */

:root {
  --navy: #12305c;
  --navy-dark: #0b1f3d;
  --gold: #c9a227;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1d2430;
  --text-muted: #5b6676;
  --border: #dfe3e9;
  --ok: #1b7f4b;
  --ok-bg: #e7f4ed;
  --warn: #9a6b00;
  --warn-bg: #fdf3dd;
  --danger: #a32020;
  --danger-bg: #fbeaea;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(18, 48, 92, .08), 0 4px 16px rgba(18, 48, 92, .06);
  --focus: 0 0 0 3px rgba(18, 48, 92, .28);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Accessibility: visible focus everywhere, never removed (spec 61) */
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

.skip-link {
  position: absolute;
  left: -9999px;
  background: var(--navy);
  color: #fff;
  padding: .75rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1rem;
  background: var(--navy);
  color: #fff;
}

.brand { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.brand-mark { flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 650; letter-spacing: .01em; }
.brand-sub { font-size: .8rem; color: #c3cee0; }

/* --------------------------------------------------------------- content */
.content {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

h1 { margin: 0 0 .25rem; font-size: 1.5rem; letter-spacing: -.01em; }
.lead { margin: 0 0 1.25rem; color: var(--text-muted); }
.muted { color: var(--text-muted); font-size: .9rem; }

/* Status messages never rely on colour alone (spec 61) */
.status-ok, .status-warn, .status-error {
  padding: .7rem .9rem;
  border-radius: 8px;
  border-left: 4px solid;
  margin: 0 0 1.25rem;
  font-size: .95rem;
}
.status-ok    { background: var(--ok-bg);     border-color: var(--ok);     color: #14603a; }
.status-warn  { background: var(--warn-bg);   border-color: var(--warn);   color: #7a5500; }
.status-error { background: var(--danger-bg); border-color: var(--danger); color: #8a1b1b; }
.status-ok::before    { content: "\2713  "; font-weight: 700; }
.status-warn::before  { content: "!  ";    font-weight: 700; }
.status-error::before { content: "\00d7  "; font-weight: 700; }

/* Timezone banner - attendance and member registration screens */
.tz-banner {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem 1rem;
  align-items: baseline;
  padding: .7rem .9rem;
  background: #eef2f8;
  border: 1px solid #d3dcea;
  border-radius: 8px;
  font-size: .92rem;
}
.tz-banner strong { color: var(--navy-dark); }

.kv { display: grid; grid-template-columns: 1fr; gap: .15rem .75rem; margin: 0 0 1.25rem; }
.kv dt { font-weight: 600; color: var(--text-muted); font-size: .85rem; }
.kv dd { margin: 0 0 .6rem; }

a { color: var(--navy); }
a:hover { color: var(--navy-dark); }

/* ---------------------------------------------------------------- footer */
.footer {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1rem;
  justify-content: space-between;
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: .85rem;
}

/* ------------------------------------------------------------- viewports */
@media (min-width: 640px) {
  .kv { grid-template-columns: 200px 1fr; }
  .kv dt { font-size: .95rem; }
  .content { padding: 2rem 1.5rem 3rem; }
  h1 { font-size: 1.75rem; }
}

/* ---------------------------------------------------------------- print */
/* Report printing (spec 128): drop chrome, keep the report itself. */
@media print {
  .topbar, .footer, .skip-link,
  nav, .sidebar, .no-print, button, .btn { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .content { max-width: none; padding: 0; }
  .card { border: none; box-shadow: none; padding: 0; }
  a[href]::after { content: ""; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; page-break-after: auto; }
  thead { display: table-header-group; }
}

/* ------------------------------------------------------------ auth pages */
.auth-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 1rem;
}

.auth-card { width: 100%; max-width: 420px; }

.auth-head { text-align: center; margin-bottom: 1.5rem; }
.auth-head h1 { font-size: 1.3rem; margin: .6rem 0 .1rem; }
.auth-head .lead { margin: 0; font-size: .92rem; }

.auth-note { margin: 1.25rem 0 0; text-align: center; }

/* ---------------------------------------------------------------- forms */
.field { margin-bottom: 1.1rem; }

.field label {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: .35rem;
}

.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="submit"]),
.toolbar input[type="search"],
.field select,
.field textarea {
  width: 100%;
  /* 16px minimum stops iOS Safari zooming in when the field is focused */
  font-size: 16px;
  font-family: inherit;
  padding: .7rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.field input:focus-visible,
.toolbar input[type="search"]:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
  border-color: var(--navy);
  box-shadow: var(--focus);
}

/* Invalid state is marked by more than colour (spec 61) */
.field input[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  /* 44px tall: a comfortable touch target for attendance on a phone */
  min-height: 44px;
  padding: .65rem 1.25rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); color: #fff; }
.btn-secondary { background: #fff; color: var(--navy); border-color: var(--border); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ------------------------------------------------------- shell + sidebar */
.shell { flex: 1; display: flex; width: 100%; max-width: 1400px; margin: 0 auto; }

.topbar-user { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.inline-form { margin: 0; }

/* ------------------------------------------------------------- user menu */
.user-menu { position: relative; }

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: #fff;
  cursor: pointer;
  list-style: none;
  padding: .3rem .5rem;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
.user-menu-trigger::-webkit-details-marker { display: none; }
/* A small chevron rather than the browser's default marker, so it reads as
   "opens a menu" rather than "expands text". */
.user-menu-trigger::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 2px solid rgba(255,255,255,.75);
  border-bottom: 2px solid rgba(255,255,255,.75);
  transform: rotate(45deg);
  margin-left: .1rem;
  transition: transform .15s ease;
}
.user-menu[open] .user-menu-trigger::after { transform: rotate(-135deg); }
.user-menu-trigger:hover { background: rgba(255,255,255,.12); }

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + .4rem);
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(11,31,61,.18);
  padding: .4rem;
  z-index: 50;
}

.user-menu-item,
.user-menu-item-button {
  display: block;
  width: 100%;
  text-align: left;
  padding: .55rem .7rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font: inherit;
  font-size: .9rem;
  background: none;
  border: none;
  cursor: pointer;
  min-height: 40px;
}
.user-menu-item:hover,
.user-menu-item-button:hover { background: #eef2f8; }
.user-menu-item-form { margin: 0; }

/* Sits directly in the dark topbar, to the left of the user menu - so it
   needs its own light-on-dark styling rather than the dropdown panel's. */
.lang-switch { margin: 0; }
.lang-switch-label {
  display: flex;
  align-items: center;
  gap: .3rem;
}
.lang-switch-btn {
  padding: .25rem .55rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,.3);
  background: transparent;
  color: rgba(255,255,255,.75);
  font: inherit;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 30px;
}
.lang-switch-btn.is-active {
  background: #fff;
  border-color: #fff;
  color: var(--navy);
}
.lang-switch-btn:hover:not(.is-active) { background: rgba(255,255,255,.12); color: #fff; }

.role-badge {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .15rem .45rem;
  border-radius: 4px;
  font-weight: 700;
}
.role-admin   { background: var(--gold); color: #3a2f00; }
.role-regular { background: #3f5c8a; color: #fff; }

.btn-ghost {
  background: transparent;
  color: #fff;
  border-color: rgba(255,255,255,.35);
  min-height: 36px;
  padding: .35rem .8rem;
  font-size: .85rem;
}
.btn-ghost:hover { background: rgba(255,255,255,.12); color: #fff; }

.sidebar {
  display: none;
  flex: none;
  width: 220px;
  padding: 1.25rem .75rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.nav-link {
  display: block;
  padding: .6rem .75rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: .95rem;
  margin-bottom: .15rem;
}
.nav-link:hover { background: #eef2f8; }
/* Active state uses a bar as well as colour (spec 61) */
.nav-link.is-active {
  background: #eef2f8;
  font-weight: 650;
  box-shadow: inset 3px 0 0 var(--navy);
}

.nav-section {
  display: block;
  margin: .75rem .75rem .4rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--navy-dark);
  font-weight: 700;
}

/* Administration section reads as its own distinct block: a pale tint of
   the logo's navy, dark navy text for contrast, white on hover. Same blue
   family as the brand mark, light enough that the labels stay easy to read. */
.admin-nav-group {
  margin-top: 1rem;
  padding: .5rem;
  border-radius: 10px;
  background: rgba(18, 48, 92, .08);
  border-left: 3px solid var(--navy);
}
.admin-nav-group .nav-link {
  color: var(--navy-dark);
}
.admin-nav-group .nav-link:hover {
  background: #fff;
}
.admin-nav-group .nav-link.is-active {
  background: #fff;
}

@media (min-width: 900px) { .sidebar { display: block; } }

/* On phones the sidebar collapses to a scrolling strip under the header,
   because attendance is used one-handed on a small screen (spec 60). */
@media (max-width: 899px) {
  .shell { flex-direction: column; }
  .sidebar {
    display: flex;
    width: 100%;
    gap: .4rem;
    overflow-x: auto;
    padding: .6rem .75rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
  }
  .nav-link { white-space: nowrap; margin: 0; padding: .5rem .7rem; }
  .nav-link.is-active { box-shadow: inset 0 -3px 0 var(--navy); }
  .nav-section { display: none; }
  /* The wrapper disappears from layout so its links rejoin the horizontal
     scroll strip as direct items, exactly as before it existed - the blue
     tint styling is a desktop-sidebar affordance, not useful in a one-row
     strip where every link is already equally visible. */
  .admin-nav-group {
    display: contents;
  }
  .admin-nav-group .nav-link {
    color: var(--text);
  }
  .admin-nav-group .nav-link:hover,
  .admin-nav-group .nav-link.is-active {
    background: transparent;
  }
}

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.data th, table.data td { padding: .6rem .7rem; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
table.data tbody tr:hover { background: #f7f9fc; }

.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: #e6ebf3; }
.avatar-placeholder {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: #e6ebf3; color: var(--navy); font-weight: 650; font-size: .8rem;
}

.pill { display: inline-block; padding: .15rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.pill-active   { background: var(--ok-bg);     color: #14603a; }
.pill-visitor  { background: #e3eefc;          color: #1d4f91; }
.pill-first-timer { background: #fdf0d5;       color: #7a5500; }
.pill-inactive { background: #eceff3;          color: #4a5462; }
.pill-present  { background: var(--ok-bg);     color: #14603a; }
.pill-removed  { background: var(--danger-bg); color: #8a1b1b; }
.pill-warn     { background: var(--warn-bg);   color: #7a5500; }
.pill-danger   { background: var(--danger-bg); color: #8a1b1b; }

.page-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: baseline; justify-content: space-between; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.toolbar input[type="search"] { flex: 1 1 240px; min-width: 0; width: auto; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover, .sort-link:focus-visible { text-decoration: underline; }
.sort-link .sort-arrow { font-size: .8em; margin-left: .2rem; }

.empty-state { padding: 2.5rem 1rem; text-align: center; color: var(--text-muted); }
.empty-state h2 { font-size: 1.05rem; color: var(--text); margin: 0 0 .4rem; }
.empty-state ul { list-style: none; padding: 0; margin: .6rem 0 0; font-size: .9rem; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 1.25rem; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.form-section { margin: 0 0 1.5rem; padding: 0; border: 0; }
.form-section legend { font-weight: 700; font-size: .95rem; padding: 0 0 .6rem; color: var(--navy-dark); }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.25rem; }
.form-actions .field { margin-bottom: 0; }
details.collapsible > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: .5rem; }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::before { content: "▸"; font-size: 1.1rem; color: var(--navy); }
details.collapsible[open] > summary::before { content: "▾"; }
details.collapsible > summary h2 { margin: 0; }
.results-footer { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; }
.results-footer .pager { display: flex; align-items: center; gap: .6rem; }
.form-actions form { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.required-mark { color: var(--danger); font-weight: 700; }
.hint { font-size: .82rem; color: var(--text-muted); margin-top: .25rem; }

/* --------------------------------------------------------- misc helpers */
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.row-actions { display: flex; gap: .75rem; font-size: .88rem; }
.pager { margin-top: 1rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; }

.btn-ghost-dark { background: transparent; color: var(--navy); border-color: var(--border); }
.btn-ghost-dark:hover { background: #eef2f8; }

/* --------------------------------------------------------------- profile */
.profile-head { display: flex; gap: 1.25rem; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; }
.profile-head h2 { margin: 0 0 .25rem; font-size: 1.25rem; }
.profile-photo { width: 120px; height: 120px; border-radius: 12px; object-fit: cover; background: #e6ebf3; }
.profile-photo-placeholder {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 650; color: var(--navy);
}
.profile h3 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 1rem 0 .5rem; }

/* ------------------------------------------------------------ attendance */
/* Used on a phone, standing up, under time pressure (spec 60, 95):
   large targets, obvious state, submit button always reachable. */

.field-inline { display: flex; align-items: center; gap: .6rem; margin-bottom: 0; }
.field-inline label { margin-bottom: 0; white-space: nowrap; }

.attendance-summary {
  padding: .6rem .8rem;
  background: #eef2f8;
  border-radius: 8px;
  margin: 1rem 0;
  font-size: .95rem;
}

.attendance-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }

.attendance-row { border-bottom: 1px solid var(--border); }
/* Present rows are distinguished by a bar and a tick, not colour alone. */
.attendance-row.is-present { background: var(--ok-bg); box-shadow: inset 3px 0 0 var(--ok); }

.attendance-label {
  display: flex;
  align-items: flex-start;
  gap: .85rem;
  /* Generous hit area - the whole row is tappable */
  padding: .85rem .7rem;
  cursor: pointer;
  min-height: 56px;
}
.attendance-row.is-present .attendance-label { cursor: default; }

.attendance-label input[type="checkbox"] {
  width: 24px; height: 24px;
  margin-top: .15rem;
  flex: none;
  accent-color: var(--navy);
}
.attendance-label input:focus-visible { box-shadow: var(--focus); }

.attendance-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.attendance-name { font-weight: 600; }
.attendance-meta { font-size: .82rem; color: var(--text-muted); }
.attendance-state { font-size: .82rem; color: #14603a; font-weight: 600; }
.attendance-state-removed { color: #8a1b1b; }

.attendance-actions {
  position: sticky;
  bottom: 0;
  padding: .85rem 0;
  background: linear-gradient(to top, var(--surface) 70%, rgba(255,255,255,0));
}
.btn-large { min-height: 52px; font-size: 1.05rem; }

/* ---------------------------------------------------------------- result */
.result-panel {
  border: 1px solid #cfe3d6;
  background: var(--ok-bg);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 1rem 0;
}
.result-panel h2 { margin: 0 0 .5rem; font-size: 1.05rem; color: #14603a; }
.result-counts { list-style: none; margin: 0 0 .5rem; padding: 0; display: flex; flex-wrap: wrap; gap: .3rem 1.25rem; }
.result-counts strong { font-size: 1.1rem; }
.result-failed { color: var(--danger); }
.result-details { margin-top: .5rem; font-size: .9rem; }
.result-details summary { cursor: pointer; font-weight: 600; }
.result-details ul { margin: .5rem 0 0; padding-left: 1.2rem; }

/* ------------------------------------------------------------ stat cards */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .85rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 650; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; color: var(--navy-dark); }

.card + .card { margin-top: 1.25rem; }
.card h2 { font-size: 1.05rem; margin: 0 0 .9rem; }

/* ----------------------------------------------------------------- admin */
.admin-actions { display: flex; flex-wrap: wrap; gap: .5rem 1rem; }
.btn-link {
  background: none; border: none; padding: 0;
  color: var(--navy); font: inherit; font-size: .88rem;
  cursor: pointer; text-decoration: underline;
}
.btn-link:hover { color: var(--navy-dark); }
.reset-link { display: inline-block; margin-top: .4rem; word-break: break-all; background: #fff; padding: .3rem .5rem; border-radius: 4px; }
.audit-meta { display: flex; flex-direction: column; gap: .1rem; font-size: .8rem; color: var(--text-muted); }
.pager { display: flex; align-items: center; gap: 1rem; }

/* ------------------------------------------------------------ dashboard */
.section-title { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 1.5rem 0 .6rem; font-weight: 700; }
.chart-box { position: relative; height: 280px; }
.chart-table { margin-top: .75rem; font-size: .9rem; }
.chart-table summary { cursor: pointer; color: var(--navy); }
.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-list li { display: flex; gap: .9rem; padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.activity-time { color: var(--text-muted); font-variant-numeric: tabular-nums; flex: none; }
@media print { .chart-box { display: none; } .chart-table { display: block; } .chart-table summary { display: none; } }

/* --------------------------------------------------------------- filters */
.filter-row { display: grid; grid-template-columns: 1fr; gap: 0 .75rem; padding: .75rem 0; border-bottom: 1px solid var(--border); }
@media (min-width: 860px) { .filter-row { grid-template-columns: 1.2fr 1fr 1.2fr 1fr; } }
.filter-chips { list-style: none; display: flex; flex-wrap: wrap; gap: .5rem; padding: 0; margin: 0 0 1rem; }
.chip { background: #eef2f8; border: 1px solid #d3dcea; border-radius: 999px; padding: .25rem .75rem; font-size: .85rem; }
.filter-active { border-left: 4px solid var(--navy); }
.hint-box { margin-top: 1rem; font-size: .9rem; }
.hint-box summary { cursor: pointer; color: var(--navy); font-weight: 600; }

/* ---------------------------------------------------------------- report */
.report-head { text-align: center; border-bottom: 2px solid var(--navy); padding-bottom: 1rem; margin-bottom: 1.25rem; }
.report-head h1 { font-size: 1.3rem; margin: .5rem 0 .1rem; }
.report-head h2 { font-size: 1.05rem; margin: .75rem 0 .1rem; }
.report-sheet h3 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 1.5rem 0 .6rem; }
.report-sheet h4 { font-size: .95rem; margin: 1.2rem 0 .4rem; color: var(--navy-dark); }
.report-foot { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); text-align: center; color: var(--text-muted); font-size: .85rem; }
.report-foot p { margin: .15rem 0; }

/* -------------------------------------------------------------- comments */
.comment-form { margin-bottom: 1.25rem; }
.comment-form textarea { resize: vertical; }

.comment-list { list-style: none; margin: 0; padding: 0; }
.comment {
  padding: .75rem 0;
  border-top: 1px solid var(--border);
}
.comment-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .75rem;
  margin: 0 0 .25rem;
  font-size: .82rem;
  color: var(--text-muted);
}
.comment-body { margin: 0; white-space: pre-wrap; }

/* --------------------------------------------- attendance row extras */
/* A shared name is flagged with a badge and a bar, not colour alone. */
.attendance-row.shares-name { box-shadow: inset 3px 0 0 var(--warn); }
.attendance-row.is-present.shares-name { box-shadow: inset 3px 0 0 var(--ok); }

.dup-badge {
  display: inline-block;
  margin-left: .4rem;
  padding: .1rem .4rem;
  border-radius: 4px;
  background: var(--warn-bg);
  color: #7a5500;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.attendance-label .avatar,
.attendance-label .avatar-placeholder { flex: none; margin-top: .1rem; }

.row-detail {
  margin: 0 0 .6rem 3.4rem;
  font-size: .82rem;
}
/* The <summary> replaces the old .btn-link button: same look, native
   click-to-open/click-to-close behaviour, no JS. */
.row-detail summary {
  display: list-item;
  cursor: pointer;
  color: var(--navy);
  text-decoration: underline;
  -webkit-tap-highlight-color: transparent;
}
.row-detail summary:hover { color: var(--navy-dark); }
.row-detail summary::marker { color: var(--text-muted); font-size: .8em; }
.row-detail[open] summary { margin-bottom: .5rem; }
.member-card-slot:empty { display: none; }

/* Unmark / Restore: same disclosure idiom as .row-detail, its own colour so
   a correction control never reads as the identical "Who is this?" link. */
.row-undo {
  margin: 0 0 .6rem 3.4rem;
  font-size: .82rem;
}
.row-undo summary {
  display: list-item;
  cursor: pointer;
  color: #8a1b1b;
  text-decoration: underline;
  -webkit-tap-highlight-color: transparent;
}
.row-undo summary:hover { color: #5e1010; }
.row-undo summary::marker { color: var(--text-muted); font-size: .8em; }
.row-undo[open] summary { margin-bottom: .5rem; }
.row-undo form {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  max-width: 32rem;
}
.row-undo input[type="text"] {
  flex: 1 1 14rem;
  min-height: 38px;
  padding: .4rem .6rem;
  font-size: .85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.btn-small { min-height: 34px; padding: .35rem .75rem; font-size: .82rem; }

.member-card {
  /* No left margin here - the parent .row-detail <details> already carries
     the 3.4rem offset that aligns this under the row's avatar; adding it
     again here would double-indent it. */
  margin: 0 .7rem .8rem 0;
  padding: .8rem .9rem;
  background: #f7f9fc;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .88rem;
}
.member-card-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .6rem; }
.member-card-photo { border-radius: 8px; object-fit: cover; }
.member-card-facts { display: grid; grid-template-columns: auto 1fr; gap: .1rem .75rem; margin: 0 0 .5rem; }
.member-card-facts dt { color: var(--text-muted); font-weight: 600; }
.member-card-facts dd { margin: 0; }
.member-card-recent { margin: 0 0 .4rem; }

/* Records table: a tall list stays usable by scrolling within the card
   rather than pushing the filters off the top of the screen. */
.records-scroll { max-height: 70vh; overflow-y: auto; }
.records-scroll thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  box-shadow: inset 0 -1px 0 var(--border);
  z-index: 1;
}

/* --------------------------------------------------------- checkbox group */
/* Used for multi-department selection on the member form: touch-friendly
   checkboxes, same target size as the attendance page, no JS required. */
.field-legend {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: .1rem;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem .75rem;
  padding: .4rem 0;
}

.checkbox-option {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: .92rem;
  min-height: 40px;
}
.checkbox-option:has(input:checked) {
  border-color: var(--navy);
  background: #eef2f8;
  font-weight: 600;
}
.checkbox-option input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--navy);
}

/* ------------------------------------------------------ username status */
.username-status-slot { display: inline-block; margin-left: .5rem; }
.username-status {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .82rem;
  font-weight: 600;
  padding: .1rem .5rem;
  border-radius: 999px;
}
.username-status-ok    { background: var(--ok-bg); color: #14603a; }
.username-status-taken { background: var(--danger-bg); color: var(--danger); }

/* ------------------------------------------------- portal: launcher tiles */
/* One tile per church system (core/modules.py). Large targets: the launcher
   is used on phones as much as on the office computer. */
.brand { color: inherit; text-decoration: none; }
.brand:hover .brand-name { text-decoration: underline; }

.launcher {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0 1.5rem;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  padding: 1.1rem 1.1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
a.tile:hover {
  transform: translateY(-2px);
  border-color: var(--navy);
  box-shadow: 0 2px 6px rgba(18, 48, 92, .12), 0 8px 24px rgba(18, 48, 92, .10);
}
.tile-icon { font-size: 1.9rem; line-height: 1; }
.tile-name { font-weight: 700; font-size: 1.05rem; color: var(--navy-dark); }
.tile-desc { font-size: .88rem; color: var(--text-muted); }
.tile-soon { opacity: .6; box-shadow: none; border-style: dashed; }
.tile-soon .pill { align-self: flex-start; margin-top: .3rem; }

.nav-home { font-weight: 650; }
.nav-group + .nav-group { margin-top: .35rem; }
.sidebar .admin-nav-group { margin-top: 1rem; }

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  a.tile:hover { transform: none; }
}

/* ------------------------------------------------- public front page (/) */
.shell-public .content { max-width: 880px; }
.public-home { position: relative; }
.public-lang { display: flex; justify-content: flex-end; gap: .35rem; }
.public-lang a {
  padding: .25rem .6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--navy);
  text-decoration: none;
  font-weight: 600;
  font-size: .85rem;
}
.public-lang a.is-active { background: var(--navy); border-color: var(--navy); color: #fff; }
.public-hero { text-align: center; padding: 1.5rem 0 1rem; }
.public-hero h1 { margin: .75rem 0 .5rem; color: var(--navy-dark); }
.public-lead { margin: .25rem auto; max-width: 60ch; color: var(--text-muted); font-size: 1.05rem; }
.public-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1rem 0 1.5rem;
}
.tile-public { padding: 1.4rem; }
.tile-public.tile-soon { cursor: default; }
.eyebrow {
  margin: 0 0 .2rem; font-size: .78rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted);
}
.public-info h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.public-info h2 + * + h2, .public-info ul + h2 { margin-top: 1.25rem; }
.public-services { margin: 0; padding-left: 1.1rem; }
.public-services li { margin: .2rem 0; }

/* ------------------------------------- admin users: systems per user */
.module-grants summary { cursor: pointer; color: var(--navy); font-size: .9rem; }
.module-grants-form {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  margin-top: .5rem;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.module-grants-form .check { display: flex; align-items: center; gap: .45rem; font-size: .9rem; }
.module-grants-form .btn { align-self: flex-start; margin-top: .25rem; }

/* Sign-in page: the way back to the public front page */
.auth-back { margin: .75rem 0 0; text-align: center; font-size: .9rem; }
.auth-back a { color: var(--navy); font-weight: 600; text-decoration: none; }
.auth-back a:hover { text-decoration: underline; }

/* ------------------------------------------- sidebar accordion (base.html) */
/* Only the system holding the current page is expanded; the rest collapse to
   a clickable heading that opens that system's start page. */
.nav-section-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin: .2rem 0;
  padding: .55rem .75rem;
  border-radius: 8px;
  text-decoration: none;
}
.nav-section-link:hover { background: #eef2f8; }
.nav-group[open] > .nav-section-link { color: var(--navy); }
.nav-group[open] { padding-bottom: .35rem; }
.nav-chevron { font-size: .8rem; color: var(--text-muted); }
.nav-group + .nav-group { margin-top: .15rem; }
/* Collapsed, the admin block keeps its tint but shrinks to its heading. */
.sidebar .admin-nav-group:not([open]) { padding: .25rem .5rem; }
.admin-nav-group .nav-section-link:hover { background: #fff; }

@media (max-width: 899px) {
  /* Phone strip: headings become chips; the open system's links follow its
     chip in the same scrolling row. */
  .nav-group { display: contents; }
  .sidebar .nav-section-link {
    display: inline-flex;
    flex: none;
    white-space: nowrap;
    margin: 0;
    padding: .45rem .7rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: .75rem;
  }
  .nav-group[open] > .nav-section-link { background: var(--navy); border-color: var(--navy); color: #fff; }
  .nav-group[open] > .nav-section-link .nav-chevron { color: #c3cee0; }
  .nav-group[open] > .nav-link { padding-left: .7rem; }
}

/* A field that takes the full row in a two-column form (e.g. street). */
@media (min-width: 720px) { .grid-2 > .field-wide { grid-column: 1 / -1; } }

/* ------------------------------------------------ sidebar: department */
.nav-department {
  margin: 0 0 .35rem; padding: .2rem .75rem; font-size: .78rem; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em;
}
.nav-switch { font-size: .88rem; color: var(--text-muted); }

/* --------------------------------------------------------------- finance */
.btn-danger { background: var(--danger-bg); color: #8a1b1b; border-color: #e7b4b4; }
.btn-danger:hover { background: #f6d2d2; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.finance-table tfoot th, .finance-table tfoot td { border-top: 2px solid var(--border); border-bottom: 0; }
.finance-table tr.is-void td { color: var(--text-muted); text-decoration: line-through; }
.finance-table tr.is-void td .pill { text-decoration: none; }
.finance-table .pill { margin-left: .35rem; }
.summary-table { font-size: .85rem; }
.summary-table th[scope="row"] { font-weight: 600; white-space: nowrap; }
.summary-table td a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--text-muted); }
.finance-filters select { width: auto; }
.field .label { display: block; font-weight: 600; margin-bottom: .35rem; }
.check { display: flex; align-items: flex-start; gap: .5rem; font-weight: 400; }
.check input { width: auto; margin-top: .2rem; }
.duplicate-confirm { margin-top: 1rem; padding: .75rem; background: var(--warn-bg); border-radius: var(--radius); }
.inline-rename { margin: 0; flex-wrap: nowrap; }
.inline-rename input { min-width: 0; }
.receipt-form { margin-top: .75rem; }
.amount-input { max-width: 9rem; text-align: right; font-variant-numeric: tabular-nums; }
.summary-table thead th a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--text-muted); }

/* ------------------------------------------------- finance: counting */
.count-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.count-column { min-width: 0; }
.count-column h3 { font-size: .95rem; margin: 0 0 .4rem; }
.count-table { font-size: .9rem; }
.count-table th, .count-table td { padding: .35rem .5rem; }
.qty-input { width: 5.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.count-running { margin: .75rem 0 0; font-size: 1.05rem; }
.count-history { margin: 0 0 .75rem; padding-left: 1.1rem; font-size: .9rem; color: var(--text-muted); }
.row-strong th, .row-strong td { border-top: 2px solid var(--border); }
tr.muted td, tr.muted th { color: var(--text-muted); }

/* ------------------------------------------------- finance: weekly offering */
.is-off, .is-off strong { color: var(--danger); }
.weekly-grid td, .weekly-grid th { padding: .3rem .5rem; }
.weekly-grid .amount-input { max-width: 7.5rem; }
.weekly-grid tr.is-inactive th { color: var(--text-muted); font-style: italic; }
.quick-add { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; }
.quick-add .field { margin: 0; }
/* Comment takes half the row; the proof upload goes on its own line under it. */
.quick-add .field-half { flex: 0 1 calc(50% - .25rem); min-width: 16rem; }
.quick-add .field-half input { width: 100%; }
.quick-add-break { flex-basis: 100%; height: 0; }
@media (max-width: 719px) { .quick-add .field-half { flex-basis: 100%; } }
.three-dates { font-size: .85rem; color: var(--text-muted); white-space: nowrap; }
.locked-note { border-left: 4px solid var(--danger); }
.chip-list { list-style: none; display: flex; flex-wrap: wrap; gap: .5rem; padding: 0; margin: .75rem 0 0; }
.chip-list li { border: 1px solid var(--border); border-radius: 999px; padding: .2rem .7rem; font-size: .9rem; }

/* Sidebar sections and sub-groups are <details>: the heading (summary)
   opens and closes them. Every page link of an open section shares one left
   margin; a sub-group's own pages are indented one step further. */
.nav-group > summary, .nav-subgroup > summary { list-style: none; cursor: pointer; }
.nav-group > summary::-webkit-details-marker,
.nav-subgroup > summary::-webkit-details-marker { display: none; }
.nav-chevron { display: inline-block; transition: transform .15s ease; }
details[open] > summary .nav-chevron { transform: rotate(90deg); }
.nav-group[open] { padding-bottom: .35rem; }
.nav-group[open] > .nav-link,
.nav-group[open] > .nav-subgroup > .nav-sublink-head { padding-left: 1.4rem; }
.nav-sublink-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.nav-subgroup[open] > .nav-sublink-head { color: var(--navy); font-weight: 650; }
.nav-sublink {
  margin-left: 1.4rem;
  padding-left: 1rem;
  border-left: 1px solid var(--border);
  border-radius: 0 8px 8px 0;
  font-size: .9rem;
}
@media (max-width: 899px) {
  .nav-group[open] > .nav-link,
  .nav-group[open] > .nav-subgroup > .nav-sublink-head { padding-left: .7rem; }
  .nav-sublink { margin-left: 0; border-left: 0; padding-left: .7rem; }
}
.share-pct { font-size: .8rem; margin-left: .25rem; }
.share-input { max-width: 4.5rem; text-align: right; }

/* Finance book 6: statements and Income & Expenditure */
.amount-negative { color: var(--danger); font-weight: 600; }
.ie-columns { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); }

/* An amount typed in the wrong format (static/js/amount-input.js). */
.amount-input.is-invalid { border-color: var(--danger, #b42318); box-shadow: 0 0 0 1px var(--danger, #b42318); }

/* Page links under long finance tables (templates/finance/_pager.html). */
.finance-pager { flex-wrap: wrap; gap: .75rem; margin-top: 1rem; }
.finance-pager .per-page { margin-left: auto; }

/* Local Assembly Report: attendance typed per week and group. */
.attendance-grid input { width: 5.5rem; text-align: right; }

/* Member form: the category worked out from the date of birth. */
.category-readout { display: block; padding: .5rem .75rem; border: 1px dashed var(--border, #ccd); border-radius: 6px; font-weight: 600; min-height: 2.5rem; }

/* Sunday Service Report: typed numbers and comments inside the table. */
.service-report .count-input { width: 6rem; text-align: right; }
.service-report .comment-input { width: 100%; min-width: 12rem; }
.service-report th[scope="rowgroup"] { vertical-align: top; }

/* ------------------------------------------------- member portal (/me) */
.me-nav {
  display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .5rem;
  margin: 0 0 1.25rem; padding: .6rem .75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.me-nav-name { font-weight: 600; margin-right: auto; color: var(--navy-dark); }
.me-nav-name code { font-weight: 400; color: var(--text-muted); }
.me-nav a {
  padding: .35rem .65rem; border-radius: 6px; color: var(--navy);
  text-decoration: none; font-weight: 600; font-size: .92rem;
}
.me-nav a:hover { background: #eef2f8; }
.me-nav a.is-active { background: var(--navy); color: #fff; }
.me-nav-out { margin: 0; }
.me-years { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 1rem; }
.me-years a {
  padding: .25rem .6rem; border: 1px solid var(--border); border-radius: 6px;
  color: var(--navy); text-decoration: none; font-weight: 600; font-size: .9rem;
}
.me-years a.is-active { background: var(--navy); border-color: var(--navy); color: #fff; }
.me-month { font-size: 1rem; margin: 1rem 0 .35rem; }
.me-list { margin: 0; padding-left: 1.1rem; }
.me-list li { margin: .15rem 0; }
.stat-value-small { font-size: 1.1rem; }
.portal-qr svg { width: 200px; height: 200px; background: #fff; }
.portal-link { word-break: break-all; }
@media (max-width: 600px) {
  .me-nav-name { flex-basis: 100%; }
}
a.me-child { color: inherit; text-decoration: none; }
a.me-child:hover { border-color: var(--navy); }
.change-old { color: var(--text-muted); text-decoration: line-through; }
.recovery-codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: .4rem; padding: 0; list-style: none; }
.recovery-codes code { font-size: 1.05rem; }
