:root {
  --crimson: #8b1528;
  --crimson-deep: #5c0c1a;
  --crimson-ink: #3a0811;
  --silver: #c5ccd4;
  --silver-bright: #e8eef4;
  --silver-metal: linear-gradient(145deg, #f4f7fa 0%, #c7ced6 42%, #9aa3ad 78%, #dde3ea 100%);
  --primary: #8b1528;
  --accent: #c5ccd4;
  --bg: #f3f1f2;
  --bg-2: #ebe6e8;
  --surface: #fffcfd;
  --text: #1a1214;
  --muted: #5c5054;
  --line: #d9d0d3;
  --danger: #8b1528;
  --ok: #1f6b3a;
  --shadow: 0 12px 28px rgba(58, 8, 17, 0.12);
  --sans: "Manrope", "Segoe UI", sans-serif;
  --serif: "Libre Baskerville", Georgia, serif;
  --id-bg: #fffcfd;
  --id-text: #1a1214;
  --radius: 18px;
}

html[data-theme="dark"] {
  --bg: #2a0c12;
  --bg-2: #3a0811;
  --surface: #4a1018;
  --text: #f7f4f5;
  --muted: #c5ccd4;
  --line: #6e3040;
  --danger: #f0b4be;
  --ok: #9ddeb4;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  --id-bg: #3a0811;
  --id-text: #f7f4f5;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(900px 420px at 8% -8%, rgba(165, 42, 61, 0.12), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(197, 204, 212, 0.35), transparent 50%),
    linear-gradient(180deg, #f7f4f5 0%, var(--bg) 45%, var(--bg-2) 100%);
  line-height: 1.55;
}
html[data-theme="dark"] body {
  background:
    radial-gradient(900px 420px at 8% -8%, rgba(139, 21, 40, 0.45), transparent 55%),
    linear-gradient(180deg, #3a0811 0%, var(--bg) 100%);
}
img { max-width: 100%; }
a { color: var(--primary); }
html[data-theme="dark"] a { color: var(--accent); }
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.02em; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
}
label { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.92rem; }
.lede, .muted { color: var(--muted); }
.lede { margin-top: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
}
.btn.primary {
  background: var(--silver-metal);
  color: var(--crimson-ink);
  border-color: transparent;
  box-shadow: 0 4px 0 rgba(90, 98, 108, 0.35);
}
html[data-theme="dark"] .btn.primary {
  background: var(--silver-metal);
  color: var(--crimson-ink);
}
.btn.danger { color: var(--danger); border-color: var(--danger); }
.link-btn {
  border: 0;
  background: none;
  color: var(--danger);
  cursor: pointer;
  padding: 0;
  font-weight: 600;
}

.stack { display: grid; gap: 1rem; }
.btn-row, .toolbar, .filter-bar, .inline-form, .assign-row, .copy-row, .create-tag, .color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: end;
}
.toolbar { justify-content: space-between; margin-bottom: 1rem; }
.filter-bar { flex: 1; }
.filter-bar input, .filter-bar select, .inline-form input, .assign-row select, .create-tag input, .create-tag select {
  width: auto;
  min-width: 10rem;
  flex: 1;
}
.grow { flex: 1; }

.flash {
  border-radius: 12px;
  padding: 0.8rem 1rem;
  margin: 0 0 1rem;
}
.flash-error { background: #f4d6d2; color: #6d1f1f; }
.flash-success { background: #d7eadc; color: #215336; }
html[data-theme="dark"] .flash-error { background: #3a2224; color: #f0c7c7; }
html[data-theme="dark"] .flash-success { background: #1d3328; color: #c6ebcf; }

.guest-body {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 10% 0%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 42%),
    var(--bg);
}
.guest-card {
  width: min(28rem, 100%);
  background: var(--surface);
  border-radius: 22px;
  padding: 1.6rem;
  box-shadow: var(--shadow);
}
.guest-brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}
.guest-brand img { width: 3rem; height: 3rem; object-fit: contain; }
.guest-brand p { margin: 0; font-family: var(--serif); font-size: 1.4rem; }

.app-shell { display: grid; min-height: 100svh; }
.sidenav {
  display: none;
  background: linear-gradient(180deg, var(--crimson-deep) 0%, var(--crimson) 100%);
  color: var(--silver-bright);
  padding: 1.2rem;
}
.sidenav a, .sidenav button { color: inherit; text-decoration: none; }
.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
}
.brand img { width: 2.6rem; height: 2.6rem; object-fit: contain; }
.brand small { display: block; opacity: 0.75; font-size: 0.8rem; }
.sidenav nav { display: grid; gap: 0.2rem; }
.sidenav nav a {
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  opacity: 0.86;
}
.sidenav nav a.is-active, .sidenav nav a:hover { background: color-mix(in srgb, #fff 14%, transparent); opacity: 1; }
.signout { margin-top: auto; }
.signout button {
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 0.6rem 0.7rem;
  opacity: 0.8;
}
.app-main { padding: 1rem 1rem 5.5rem; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}
.topbar h1 { margin: 0; font-size: 1.7rem; }
.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.68rem;
  color: var(--muted);
}
.who {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: inherit;
  font-weight: 600;
}
.who img, .avatar-fallback, .photo-preview {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  object-fit: cover;
}
.avatar-fallback, .photo-preview.fallback, .id-photo-fallback {
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #f7f1e3;
  font-weight: 700;
}
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-auto-flow: column;
  gap: 0.2rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 0.45rem 0.4rem calc(0.45rem + env(safe-area-inset-bottom));
}
.tabbar a {
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.45rem 0.2rem;
}
.tabbar a.is-active { color: var(--primary); }
html[data-theme="dark"] .tabbar a.is-active { color: var(--accent); }

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.panel h2 { margin: 0 0 0.6rem; font-size: 1.2rem; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-bottom: 1rem;
}
.stats article {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.stats p, .stats span { margin: 0; color: var(--muted); }
.stats strong {
  display: block;
  font-family: var(--serif);
  font-size: 2rem;
  line-height: 1.1;
  margin: 0.2rem 0;
}
.action-grid, .split, .check-grid {
  display: grid;
  gap: 0.7rem;
}
.action-grid { grid-template-columns: 1fr 1fr; }
.action {
  display: grid;
  place-items: center;
  min-height: 4rem;
  padding: 0.8rem;
  text-align: center;
  text-decoration: none;
  color: inherit;
  background: var(--bg);
  border-radius: 12px;
  font-weight: 700;
}
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
}
.swatch {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 999px;
  vertical-align: middle;
  margin-right: 0.35rem;
}
.swatch.lg { width: 1.4rem; height: 1.4rem; }
.pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-2);
  font-size: 0.78rem;
  font-weight: 700;
}
.pill.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); }
table.data th, table.data td {
  text-align: left;
  padding: 0.75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.row-actions { display: flex; gap: 0.7rem; white-space: nowrap; }
.photo-row { display: flex; gap: 1rem; align-items: center; }
.photo-preview { width: 4.8rem; height: 4.8rem; }
.check { font-weight: 500; display: flex; gap: 0.5rem; align-items: center; }
.check input { width: auto; }
.logo-preview img { max-height: 4rem; }
.danger-panel { border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line)); }

.tag-list { display: grid; gap: 0.8rem; }
.tag-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.tag-card header { display: flex; gap: 0.7rem; align-items: center; margin-bottom: 0.7rem; }
.copy-url { margin: 0.4rem 0 0.8rem; }
.copy-row input { font-family: ui-monospace, monospace; font-size: 0.82rem; }
.sheet-body { padding: 1.5rem; background: #fff; color: #111; }
.sheet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 0.8rem; }
.sheet-item {
  border: 1px solid #d8d0bc;
  border-radius: 12px;
  padding: 0.8rem;
}
.sheet-item code { display: block; font-size: 0.78rem; margin: 0.4rem 0; word-break: break-all; }

/* Digital ID card: fill the phone, never scroll */
html:has(body.id-body) {
  height: 100%;
  overflow: hidden;
}
.id-body {
  position: fixed;
  inset: 0;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  background: var(--id-bg);
  color: var(--id-text);
}
.id-card {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding:
    max(0.9rem, env(safe-area-inset-top))
    1.15rem
    max(0.9rem, env(safe-area-inset-bottom));
  border-left: 0.72rem solid var(--tag, var(--primary));
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--tag) 12%, var(--id-bg)), var(--id-bg) 28%);
  container-type: size;
}
.id-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 0;
}
.id-logo {
  width: min(12cqh, 2.6rem);
  height: min(12cqh, 2.6rem);
  object-fit: contain;
}
.id-church {
  margin: 0;
  font-size: clamp(0.72rem, 3.6cqh, 1rem);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-weight: 700;
}
.id-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.85rem;
  text-align: center;
}
.id-photo-wrap {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.id-photo {
  width: min(38cqw, 22cqh);
  height: min(38cqw, 22cqh);
  border-radius: 50%;
  object-fit: cover;
  border: 0.18rem solid var(--accent);
  background: color-mix(in srgb, var(--tag) 18%, var(--id-bg));
}
.id-identity {
  text-align: center;
  min-height: 0;
  display: grid;
  gap: 0.28rem;
}
.id-name {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  line-height: 0.98;
  text-wrap: balance;
  font-size: clamp(2.1rem, 8.4cqh, 3.4rem);
}
.id-department {
  margin: 0.15rem 0 0;
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.1;
  font-size: clamp(1.35rem, 5.4cqh, 2.15rem);
}
.id-services,
.id-roles,
.id-expires {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.15rem, 4.4cqh, 1.7rem);
  line-height: 1.2;
}
.id-roles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.2rem 0.85rem;
}
.id-expires {
  margin-top: 0.15rem;
}
.id-watermark {
  position: absolute;
  left: -35%;
  top: -35%;
  width: 170%;
  height: 170%;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 0.2rem 1.4rem;
  margin: 0;
  transform: rotate(-28deg);
  pointer-events: none;
  background: none;
}
.id-watermark span {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(3.2rem, 14vw, 6.5rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 0.9;
  color: rgba(255, 255, 255, 0.72);
  -webkit-text-stroke: 3px #3a0811;
  paint-order: stroke fill;
  text-shadow: none;
}
html[data-theme="dark"] .id-watermark span {
  color: rgba(58, 8, 17, 0.72);
  -webkit-text-stroke: 3px #f4f7fa;
  text-shadow: none;
}
.id-empty {
  flex: 1;
  display: grid;
  align-content: center;
  text-align: center;
  gap: 0.4rem;
}
.id-empty h1 {
  margin: 0;
  font-size: clamp(1.6rem, 7cqh, 2.6rem);
}
.id-kicker {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--muted);
}
.id-back {
  position: absolute;
  left: 50%;
  bottom: max(0.7rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  color: inherit;
  font-size: 0.85rem;
  opacity: 0.8;
}

@media (min-width: 860px) {
  .app-shell { grid-template-columns: 16.5rem 1fr; }
  .sidenav { display: flex; flex-direction: column; }
  .tabbar { display: none; }
  .app-main { padding: 1.6rem 2rem; }
  .split { grid-template-columns: 1fr 1fr; }
  .check-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .table-wrap { overflow: visible; }
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td {
    display: block;
    width: 100%;
  }
  table.data tr {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 0.75rem;
    padding: 0.85rem 1rem;
  }
  table.data td {
    border: 0;
    padding: 0.2rem 0;
  }
  table.data td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .row-actions { margin-top: 0.4rem; }
}
