/* ============================================================
   Parish CRM — design system
   Typography: Inter (300/400/500). Deep violet + liturgical gold.
   Hairline borders, generous whitespace, calm surfaces.
   ============================================================ */

:root {
  --violet-900: #2e1065;
  --violet-800: #4c1d95;
  --violet-700: #5b21b6;
  --violet-600: #6d28d9;
  --violet-100: #ede9fe;
  --violet-50:  #f5f3ff;
  --gold:       #c89b3c;
  --gold-soft:  #f4ecd8;

  --ink:     #1c1a26;
  --body:    #3f3d4b;
  --muted:   #8b8a98;
  --line:    #ececf1;
  --line-2:  #e3e2ea;
  --bg:      #f7f7fb;
  --surface: #ffffff;
  --surface-2: #fbfbfd;

  --ok-bg:#e9f9ef; --ok-fg:#1b7a43;
  --warn-bg:#fdf4e3; --warn-fg:#9a6a12;
  --bad-bg:#fdecec; --bad-fg:#b42323;
  --info-bg:#eaf2fd; --info-fg:#1f5fb0;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20,18,38,.04), 0 8px 24px rgba(20,18,38,.05);
  --shadow-sm: 0 1px 2px rgba(20,18,38,.06);
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 400;
  font-size: 15px;
  line-height: 1.55;
  color: var(--body);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--violet-700); text-decoration: none; }
a:hover { color: var(--violet-600); }
h1,h2,h3,h4 { color: var(--ink); font-weight: 500; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 24px; font-weight: 400; letter-spacing: -0.02em; }
p { margin: 0 0 1em; }
small { color: var(--muted); }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--violet-900), var(--violet-800));
  color: #d8d2ef;
  position: fixed;
  inset: 0 auto 0 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
  display: flex;
  flex-direction: column;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 22px 18px;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--gold-soft);
  display: grid; place-items: center;
  color: var(--violet-800); flex-shrink: 0;
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-name { font-size: 15px; font-weight: 500; color: #fff; letter-spacing: -0.01em; line-height: 1.2; }
.brand-sub  { font-size: 11px; color: #b6abe0; letter-spacing: .08em; text-transform: uppercase; }

.nav { padding: 6px 12px 24px; flex: 1; }
.nav-section { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: #9786cd; padding: 16px 12px 7px; font-weight: 500; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 9px;
  color: #cfc7ea; font-size: 14px; font-weight: 400;
  margin-bottom: 1px; transition: background .12s, color .12s;
}
.nav-link svg { width: 17px; height: 17px; opacity: .85; flex-shrink: 0; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.13); color: #fff; }
.nav-link.active svg { opacity: 1; }

.sidebar-foot { padding: 14px 18px 20px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user { font-size: 13px; color: #d8d2ef; }
.sidebar-user b { color: #fff; font-weight: 500; display: block; }
.sidebar-foot a { color: #b6abe0; font-size: 12.5px; }
.sidebar-foot a:hover { color: #fff; }

/* ---------- Main column ---------- */
.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 62px; background: rgba(255,255,255,.85); backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; position: sticky; top: 0; z-index: 30;
}
.topbar .page-title { font-size: 16px; font-weight: 500; color: var(--ink); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.menu-toggle { display: none; background: none; border: none; cursor: pointer; padding: 6px; color: var(--ink); }

.content { padding: 28px; max-width: 1200px; width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: inherit; font-size: 14px; font-weight: 400;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--body);
  cursor: pointer; transition: background .12s, border-color .12s, box-shadow .12s; text-decoration: none;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); border-color: #d3d2dc; color: var(--ink); }
.btn-primary { background: var(--violet-700); border-color: var(--violet-700); color: #fff; }
.btn-primary:hover { background: var(--violet-800); border-color: var(--violet-800); color: #fff; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #3a2c06; }
.btn-gold:hover { background: #b88c2f; border-color:#b88c2f; color:#3a2c06; }
.btn-danger { color: var(--bad-fg); border-color: #f3d3d3; background: #fff; }
.btn-danger:hover { background: var(--bad-bg); border-color: #efc2c2; color: var(--bad-fg); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Cards / panels ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 22px 24px; }
.card-head {
  padding: 16px 24px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-head h3 { font-size: 15px; font-weight: 500; }
.card-head .sub { font-size: 12.5px; color: var(--muted); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .lead { color: var(--muted); font-size: 14px; margin-top: 3px; }

/* ---------- Stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat::before { content:""; position:absolute; left:0; top:0; bottom:0; width:3px; background: var(--violet-600); opacity:.0; }
.stat .stat-label { font-size: 12px; color: var(--muted); letter-spacing: .02em; display: flex; align-items: center; gap: 7px; }
.stat .stat-label svg { width: 15px; height: 15px; color: var(--violet-600); }
.stat .stat-value { font-size: 28px; font-weight: 300; color: var(--ink); letter-spacing: -0.02em; margin-top: 8px; line-height: 1; }
.stat .stat-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.stat.gold .stat-value { color: var(--violet-800); }
.stat.danger .stat-label svg { color: var(--bad-fg); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; font-weight: 500; color: var(--muted);
  font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase;
  padding: 11px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td { padding: 13px 16px; border-bottom: 1px solid var(--line); color: var(--body); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .strong { color: var(--ink); font-weight: 500; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 44px 24px; text-align: center; color: var(--muted); }
.empty svg { width: 34px; height: 34px; opacity: .4; margin-bottom: 10px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 999px; background: #f1f0f5; color: var(--body); }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge.info { background: var(--info-bg); color: var(--info-fg); }
.badge.muted { background:#f1f0f5; color: var(--muted); }
.badge.gold { background: var(--gold-soft); color: var(--gold); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 500; color: var(--ink); }
.field .hint { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 14px; color: var(--ink);
  padding: 10px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface); width: 100%; transition: border-color .12s, box-shadow .12s;
}
.field input::placeholder, .field textarea::placeholder { color: #b6b5c0; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--violet-600); box-shadow: 0 0 0 3px var(--violet-100);
}
.field textarea { resize: vertical; min-height: 84px; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }

.input-prefix { display: flex; align-items: stretch; border: 1px solid var(--line-2); border-radius: var(--radius-sm); overflow: hidden; }
.input-prefix:focus-within { border-color: var(--violet-600); box-shadow: 0 0 0 3px var(--violet-100); }
.input-prefix span { display: grid; place-items: center; padding: 0 12px; background: var(--surface-2); color: var(--muted); border-right: 1px solid var(--line-2); font-size: 14px; }
.input-prefix input { border: none !important; box-shadow: none !important; border-radius: 0 !important; }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--body); cursor: pointer; }
.check input { width: auto; }
.channel-row { display: flex; gap: 18px; flex-wrap: wrap; padding: 4px 0; }

/* ---------- Flash ---------- */
.flash-stack { margin-bottom: 18px; display: flex; flex-direction: column; gap: 10px; }
.flash { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; border: 1px solid transparent; }
.flash svg { width: 18px; height: 18px; flex-shrink: 0; }
.flash.success { background: var(--ok-bg); color: var(--ok-fg); border-color: #c6ecd4; }
.flash.error { background: var(--bad-bg); color: var(--bad-fg); border-color: #f3cece; }
.flash.info { background: var(--info-bg); color: var(--info-fg); border-color: #cfe0f6; }

/* ---------- Detail / definition lists ---------- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px 26px; }
.detail .k { font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.detail .v { font-size: 14.5px; color: var(--ink); margin-top: 2px; }

.section-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.section-tabs a { padding: 10px 14px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.section-tabs a.active { color: var(--violet-700); border-bottom-color: var(--violet-700); font-weight: 500; }

/* ---------- Family tree (signature element) ---------- */
.tree-scroll { overflow-x: auto; padding: 10px 4px 30px; }
.tree { display: flex; justify-content: center; min-width: max-content; padding-top: 8px; }
.tree ul { display: flex; justify-content: center; padding-top: 26px; position: relative; margin: 0; list-style: none; }
.tree li {
  list-style: none; text-align: center; position: relative;
  padding: 26px 14px 0; display: flex; flex-direction: column; align-items: center;
}
/* connectors */
.tree li::before, .tree li::after {
  content: ''; position: absolute; top: 0; right: 50%;
  width: 50%; height: 26px; border-top: 1.5px solid var(--line-2);
}
.tree li::after { right: auto; left: 50%; border-left: 1.5px solid var(--line-2); }
.tree li:only-child::after, .tree li:only-child::before { display: none; }
.tree li:first-child::before, .tree li:last-child::after { border: 0 none; }
.tree li:last-child::before { border-right: 1.5px solid var(--line-2); border-radius: 0 6px 0 0; }
.tree li:first-child::after { border-radius: 6px 0 0 0; }
.tree ul ul::before {
  content: ''; position: absolute; top: 0; left: 50%;
  border-left: 1.5px solid var(--line-2); width: 0; height: 26px;
}
.tree-node {
  display: inline-flex; flex-direction: column; align-items: center; gap: 4px;
  border: 1px solid var(--line-2); background: var(--surface);
  border-radius: 12px; padding: 12px 16px; min-width: 132px;
  box-shadow: var(--shadow-sm); position: relative;
}
.tree-node .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 15px; font-weight: 500;
  background: var(--violet-100); color: var(--violet-800); margin-bottom: 2px;
}
.tree-node.f .avatar { background: #fde7f1; color: #9d2c63; }
.tree-node.deceased { opacity: .62; }
.tree-node.deceased .avatar { background: #eceaf0; color: #6b6878; }
.tree-node .nm { font-size: 13.5px; color: var(--ink); font-weight: 500; line-height: 1.2; }
.tree-node .rel { font-size: 11.5px; color: var(--muted); }
.tree-node .cross { position: absolute; top: 6px; right: 9px; color: var(--muted); font-size: 11px; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(109,40,217,.10), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(200,155,60,.10), transparent 55%),
    var(--bg);
}
.auth-card { width: 100%; max-width: 392px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 34px 32px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .brand-mark { width: 40px; height: 40px; background: var(--violet-800); color: var(--gold-soft); }
.auth-brand .brand-mark svg { width: 22px; height: 22px; }
.auth-title { font-size: 20px; font-weight: 400; color: var(--ink); letter-spacing: -0.01em; }
.auth-sub { font-size: 13.5px; color: var(--muted); margin-bottom: 22px; }

/* ---------- Payment ---------- */
.pay-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; align-items: start; }
.qr-box { display: grid; place-items: center; gap: 14px; padding: 26px; text-align: center; }
.qr-canvas { background:#fff; padding: 14px; border-radius: 14px; border: 1px solid var(--line); }
.pay-amount { font-size: 34px; font-weight: 300; color: var(--ink); letter-spacing: -0.02em; }
.vpa-pill { font-size: 13px; background: var(--violet-50); color: var(--violet-800); padding: 6px 12px; border-radius: 999px; display: inline-flex; gap: 7px; align-items: center; }
.or-split { display:flex; align-items:center; gap:12px; color:var(--muted); font-size:12px; margin: 4px 0; }
.or-split::before, .or-split::after { content:""; height:1px; flex:1; background: var(--line); }

/* ---------- Misc ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .search { flex: 1; min-width: 200px; max-width: 360px; }
.toolbar .search input { width: 100%; }
.count-pill { font-size: 12.5px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); padding: 5px 11px; border-radius: 999px; }
.inline-form { display: inline; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.stack > * + * { margin-top: 18px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .form-grid { grid-template-columns: 1fr; }
  .pay-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-grid; place-items: center; }
  .content { padding: 20px 16px; }
  .scrim { position: fixed; inset: 0; background: rgba(20,18,38,.4); z-index: 39; display: none; }
  .scrim.show { display: block; }

  /* tables → stacked cards */
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; padding: 6px 4px; }
  table.data td { border: none; display: flex; justify-content: space-between; gap: 14px; padding: 8px 14px; text-align: right; }
  table.data td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; text-align: left; }
  .row-actions { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
:focus-visible { outline: 2px solid var(--violet-600); outline-offset: 2px; }

/* ============================================================
   Enhancements: avatars, photo fields, grouped members,
   breadcrumbs, footer, settings switches
   ============================================================ */

/* ---- Avatars (photo or initials) ---- */
.avatar-photo, .avatar-initials {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; overflow: hidden; flex: none;
  font-size: 13px; font-weight: 600; letter-spacing: .01em;
  background: var(--violet-100); color: var(--violet-800);
  border: 1px solid var(--line-2);
}
.avatar-initials.f { background: #fde7f1; color: #9d2c63; }
.avatar-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cell-with-avatar { display: flex; align-items: center; gap: 10px; }

/* ---- Photo upload field ---- */
.photo-field { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.photo-field .avatar-photo, .photo-field .avatar-initials { box-shadow: var(--shadow-sm); }
.photo-field-controls { display: flex; flex-direction: column; gap: 8px; }
.photo-field-controls input[type=file] { font-size: 13px; }

/* ---- Members grouped by family ---- */
.fam-group {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 14px; overflow: hidden;
}
.fam-group > summary {
  list-style: none; cursor: pointer; padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--surface-2);
}
.fam-group > summary::-webkit-details-marker { display: none; }
.fam-group[open] > summary { border-bottom: 1px solid var(--line); }
.fam-group-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.fam-group-name { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); font-size: 15px; flex-wrap: wrap; }
.fam-group-name a { color: var(--ink); }
.fam-group-name a:hover { color: var(--violet-700); }
.fam-group-sub { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 3px; color: var(--muted); font-size: 12.5px; }
.fam-group-sub span { display: inline-flex; align-items: center; gap: 5px; }
.fam-group-sub svg { width: 13px; height: 13px; }
.fam-group-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.fam-group-caret { width: 22px; height: 22px; display: inline-grid; place-items: center; color: var(--muted); transition: transform .2s; }
.fam-group-caret::before { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin-top: -3px; }
.fam-group[open] .fam-group-caret { transform: rotate(180deg); }

/* ---- Breadcrumbs + back ---- */
.crumbbar { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.back-btn svg { width: 15px; height: 15px; }
.crumbs { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; font-size: 13px; }
.crumbs .crumb { color: var(--muted); }
.crumbs a.crumb:hover { color: var(--violet-700); }
.crumbs .crumb.cur { color: var(--ink); font-weight: 500; }
.crumbs .crumb-sep { color: var(--line-2); }

/* ---- App footer credit ---- */
.app-footer {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  margin: 36px 0 6px; padding-top: 20px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 13px;
}
.app-footer svg { width: 16px; height: 16px; color: var(--violet-700); }
.app-footer strong { color: var(--violet-800); font-weight: 600; }

/* ---- Settings graphical config ---- */
.settings-card { margin-bottom: 18px; }
.settings-card h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.settings-card h3 .badge { margin-left: 4px; }
.settings-card hr.sep { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.status-row { display: flex; gap: 24px; flex-wrap: wrap; }
.status-row > div { display: inline-flex; align-items: center; gap: 7px; }
.switch { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; color: var(--body); cursor: pointer; margin-bottom: 14px; }
.switch input { width: auto; }
.switch span { display: inline-flex; align-items: center; gap: 6px; }
.settings-save { position: sticky; bottom: 0; padding: 14px 0; }

/* ---- Tree avatars (photo support) ---- */
.tree-node .avatar-photo, .tree-node .avatar-initials { margin-bottom: 2px; }

/* ---- Icon sizing safety net (icons carry intrinsic 1em; pin the new contexts) ---- */
.content svg { flex: none; }
.settings-card h3 svg { width: 18px; height: 18px; color: var(--violet-700); }
.settings-card h3 .badge { font-size: 12px; }
.settings-card h3 .badge svg { width: 12px; height: 12px; }
.status-row svg { width: 16px; height: 16px; color: var(--violet-600); }
.switch span svg { width: 15px; height: 15px; color: var(--violet-600); }
.crumbs svg { width: 14px; height: 14px; }
.crumbbar .back-btn svg { width: 15px; height: 15px; }
.fam-group-actions svg { width: 15px; height: 15px; }
.fam-group-sub svg { width: 13px; height: 13px; }
/* Avatar guards (inline styles already enforce size; these are fallbacks) */
.avatar-photo, .avatar-initials { vertical-align: middle; }
.avatar-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ============================================================
   Feature pack: calendar, clergy tree, dashboard charts,
   AI assistant, users/roles
   ============================================================ */

/* ---- Sidebar role tag ---- */
.sidebar-role { display:block; font-size:11px; color:var(--muted); margin:2px 0 6px; text-transform:uppercase; letter-spacing:.04em; }

/* ---- Role grid (users page) ---- */
.role-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(200px,1fr)); gap:14px; }
.role-grid > div { background:var(--surface-2); border:1px solid var(--line); border-radius:12px; padding:12px 14px; }
.role-grid p { margin:8px 0 0; font-size:13px; color:var(--muted); line-height:1.5; }

/* ---- Dashboard charts ---- */
.chart-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:20px; margin-bottom:20px; }
.chart-card .card-head { margin-bottom:8px; }
.chart-card.chart-wide { grid-column:1 / -1; }
.chart-box { width:100%; min-height:120px; display:flex; flex-direction:column; align-items:center; justify-content:center; }
.chart-txt { font-family:inherit; }
.chart-axis { fill:var(--muted); font-size:11px; }
.chart-center { fill:var(--ink); font-size:22px; font-weight:600; }
.chart-grid-line, .chart-grid line, line.chart-grid { stroke:var(--line); stroke-width:1; }
.chart-track { fill:var(--surface-3, #eee); }
.chart-empty { color:var(--muted); font-size:13px; padding:26px 0; }
.chart-legend { display:flex; flex-wrap:wrap; gap:14px; justify-content:center; margin-top:12px; font-size:12.5px; color:var(--body); }
.chart-legend span { display:inline-flex; align-items:center; gap:6px; }
.chart-legend i { width:11px; height:11px; border-radius:3px; display:inline-block; }
@media(max-width:820px){ .chart-grid{ grid-template-columns:1fr; } }

/* ---- Calendar ---- */
.cal-toolbar { display:flex; align-items:center; gap:10px; margin-bottom:14px; flex-wrap:wrap; }
.cal-month { font-weight:600; font-size:15px; }
.cal-legend { display:flex; gap:14px; margin-left:auto; font-size:12px; color:var(--muted); flex-wrap:wrap; }
.cal-legend span { display:inline-flex; align-items:center; gap:6px; }
.cal-legend .dot { width:10px; height:10px; border-radius:3px; display:inline-block; }
.dot.ev-event, .cal-ev.ev-event { background:#ede9fe; }
.dot.ev-mass, .cal-ev.ev-mass { background:#dcfce7; }
.dot.ev-ann, .cal-ev.ev-ann { background:#fef3c7; }
.cal-grid { display:grid; grid-template-columns:repeat(7,1fr); gap:6px; }
.cal-dow { text-align:center; font-size:11px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); padding:4px 0; font-weight:600; }
.cal-cell { min-height:96px; border:1px solid var(--line); border-radius:10px; padding:6px; background:var(--surface); display:flex; flex-direction:column; gap:4px; }
.cal-cell.cal-empty { background:transparent; border:1px dashed var(--line); }
.cal-today { border-color:var(--violet-500,#7c3aed); box-shadow:0 0 0 1px var(--violet-500,#7c3aed) inset; }
.cal-daynum { font-size:12px; font-weight:600; color:var(--ink); }
.cal-today .cal-daynum { color:var(--violet-700); }
.cal-events { display:flex; flex-direction:column; gap:3px; overflow:hidden; }
.cal-ev { font-size:11px; line-height:1.3; padding:2px 6px; border-radius:6px; color:#3730a3; text-decoration:none; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.cal-ev.ev-mass { color:#166534; }
.cal-ev.ev-ann { color:#92400e; }
.cal-ev b { font-weight:600; }
@media(max-width:720px){ .cal-cell{ min-height:70px; } .cal-ev{ font-size:10px; } }

/* ---- AI assistant ---- */
.ai-quick { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:14px; }
.ai-thread { display:flex; flex-direction:column; gap:12px; max-height:460px; overflow-y:auto; padding:8px 2px; }
.ai-msg { display:flex; }
.ai-msg.ai-user { justify-content:flex-end; }
.ai-bubble { max-width:80%; padding:11px 14px; border-radius:14px; font-size:14px; line-height:1.55; white-space:pre-wrap; word-wrap:break-word; position:relative; }
.ai-bot .ai-bubble { background:var(--surface-2); border:1px solid var(--line); border-bottom-left-radius:4px; }
.ai-user .ai-bubble { background:var(--violet-600,#7c3aed); color:#fff; border-bottom-right-radius:4px; }
.ai-msg.ai-error .ai-bubble { background:#fef2f2; border-color:#fecaca; color:#991b1b; }
.ai-pending { color:var(--muted); font-style:italic; }
.ai-copy { display:block; margin-top:8px; font-size:11px; background:transparent; border:1px solid var(--line); border-radius:6px; padding:2px 8px; cursor:pointer; color:var(--muted); }
.ai-copy:hover { color:var(--ink); }
.ai-compose { margin-top:14px; display:flex; flex-direction:column; gap:8px; }
.ai-compose textarea { width:100%; resize:vertical; }
.ai-compose-row { display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; }

/* ---- Card head helper (reused) ---- */
.card-head { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:14px 18px; border-bottom:1px solid var(--line); }
.card-head h3 { display:flex; align-items:center; gap:8px; margin:0; }
.count-pill { font-size:12px; color:var(--muted); background:var(--surface-2); border:1px solid var(--line); border-radius:999px; padding:1px 9px; }
.form-actions { display:flex; gap:10px; margin-top:16px; }

/* ============================================================
   Documents: 80G receipts, giving statements, certificates
   (rendered in the minimal layout, print-optimised)
   ============================================================ */
.doc-actions { display:flex; gap:10px; justify-content:center; padding:22px 16px 0; }
.seg-tabs { display:inline-flex; gap:4px; background:var(--surface-2); border:1px solid var(--line); border-radius:10px; padding:4px; margin-bottom:16px; }
.seg-tabs .seg { padding:7px 14px; border-radius:7px; font-size:13.5px; color:var(--muted); text-decoration:none; }
.seg-tabs .seg.active { background:var(--surface); color:var(--ink); box-shadow:var(--shadow-sm); font-weight:500; }

.doc {
  max-width:820px; margin:22px auto 60px; background:#fff; color:#1f2430;
  border:1px solid var(--line); border-radius:12px; padding:38px 44px;
  box-shadow:var(--shadow-sm); font-size:14.5px; line-height:1.6;
}
.doc-head { text-align:center; border-bottom:2px solid #4c1d95; padding-bottom:16px; margin-bottom:18px; }
.doc-org h1 { font-size:23px; color:#4c1d95; margin:0 0 4px; letter-spacing:.01em; }
.doc-sub { font-size:14px; color:#555; }
.doc-addr { font-size:12.5px; color:#666; margin-top:4px; white-space:pre-line; }
.doc-reg { font-size:12px; color:#555; margin-top:6px; display:flex; gap:16px; justify-content:center; flex-wrap:wrap; }
.doc-title { text-align:center; font-size:17px; font-weight:600; margin:6px 0 18px; text-transform:uppercase; letter-spacing:.03em; }
.doc-title span { display:block; font-size:12px; font-weight:400; text-transform:none; color:#666; letter-spacing:0; margin-top:2px; }
.doc-meta { display:flex; gap:26px; flex-wrap:wrap; justify-content:space-between; background:#faf9fc; border:1px solid #eee; border-radius:8px; padding:10px 16px; margin-bottom:18px; }
.doc-meta .k { display:block; font-size:11px; text-transform:uppercase; letter-spacing:.04em; color:#888; }
.doc-meta .v { font-size:14px; font-weight:500; }
.doc-table { width:100%; border-collapse:collapse; margin:8px 0 18px; }
.doc-table td, .doc-table th { padding:9px 10px; vertical-align:top; }
.doc-table td.k { width:38%; color:#666; }
.doc-table td.v { font-weight:500; }
.doc-table td.amount { font-size:17px; font-weight:700; color:#4c1d95; }
.doc-table.striped th { background:#4c1d95; color:#fff; text-align:left; font-size:12.5px; }
.doc-table.striped tbody tr:nth-child(even) { background:#faf9fc; }
.doc-table.striped td, .doc-table.striped th { border:1px solid #eee; }
.doc-table.striped tfoot td { background:#f4f1fb; font-size:15px; }
.doc-table .right { text-align:right; }
.doc-table .center { text-align:center; }
.doc-note { font-size:12.5px; color:#555; background:#f4f1fb; border-left:3px solid #7c3aed; padding:10px 14px; border-radius:0 6px 6px 0; margin:6px 0 24px; }
.doc-sign { display:flex; justify-content:flex-end; margin-top:34px; }
.doc-sign-box { text-align:center; min-width:220px; font-size:13px; }
.doc-sign-box .line, .cert-sign .line { border-top:1px solid #333; margin-bottom:6px; height:1px; }
.doc-foot { text-align:center; font-size:11px; color:#999; margin-top:26px; border-top:1px dashed #ddd; padding-top:10px; }
.doc .muted { color:#888; }
.doc .strong { font-weight:600; }

/* Certificate — decorative */
.doc.certificate { padding:0; background:#fff; }
.cert-border { border:3px double #b9922e; margin:14px; border-radius:6px; }
.cert-inner { border:1px solid #d9c58c; margin:8px; border-radius:4px; padding:40px 46px; text-align:center; background:linear-gradient(#fffdf7,#fffdf7); }
.cert-church { font-size:24px; color:#4c1d95; font-weight:600; }
.cert-addr { font-size:12.5px; color:#777; margin-top:4px; white-space:pre-line; }
.cert-title { font-size:20px; letter-spacing:.06em; text-transform:uppercase; color:#b9922e; font-weight:600; margin:22px 0 6px; }
.cert-no { font-size:12px; color:#888; margin-bottom:22px; }
.cert-body { font-size:16px; line-height:2; max-width:620px; margin:0 auto; }
.cert-name { font-size:19px; font-weight:600; color:#4c1d95; border-bottom:1px dotted #b9922e; padding:0 6px; }
.cert-date { font-weight:600; }
.cert-foot { display:flex; justify-content:space-between; align-items:flex-end; margin-top:46px; text-align:left; }
.cert-place { font-size:12.5px; color:#555; }
.cert-sign { text-align:center; min-width:200px; font-size:13px; }

@media print {
  body { background:#fff !important; }
  .doc-actions, .seg-tabs { display:none !important; }
  .doc { box-shadow:none; border:none; margin:0 auto; max-width:100%; padding:16px 8px; }
  .cert-border { margin:0; }
  @page { margin:14mm; }
}

/* ============================================================
   Phase 2: account/2FA, audit, backup, import
   ============================================================ */
.acct-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:16px; }
@media(max-width:820px){ .acct-grid{ grid-template-columns:1fr; } }
.kv { display:flex; justify-content:space-between; gap:12px; padding:8px 0; border-bottom:1px solid var(--line); font-size:14px; }
.kv:last-child { border-bottom:0; }
.kv span:first-child { color:var(--muted); }

.totp-setup { display:flex; gap:22px; flex-wrap:wrap; align-items:flex-start; }
.totp-qr { background:#fff; padding:10px; border:1px solid var(--line); border-radius:10px; }
.totp-steps { flex:1; min-width:260px; }
.totp-steps ol { margin:0 0 12px; padding-left:18px; font-size:13.5px; line-height:1.9; color:var(--body); }
.totp-secret { background:var(--surface-2); border:1px solid var(--line); border-radius:6px; padding:2px 8px; letter-spacing:.12em; font-size:13px; }

.import-stats { display:flex; gap:26px; flex-wrap:wrap; }
.import-stats > div { display:flex; flex-direction:column; }
.import-stats .n { font-size:24px; font-weight:700; line-height:1.1; }
.import-stats .n.ok { color:#16a34a; } .import-stats .n.info { color:#4c1d95; } .import-stats .n.muted { color:var(--muted); }
.import-stats span:last-child { font-size:12px; color:var(--muted); text-transform:uppercase; letter-spacing:.04em; }
.import-errors { margin:8px 0 0; padding-left:18px; font-size:12.5px; color:#b91c1c; line-height:1.7; }

.pager { display:flex; align-items:center; gap:14px; justify-content:center; margin-top:16px; }

/* ============================================================
   Phase 3: wards, rota, celebrants, calendar rota chip, ID cards
   ============================================================ */
/* Calendar rota chip */
.dot.ev-rota, .cal-ev.ev-rota { background:#e0f2fe; }
.cal-ev.ev-rota { color:#075985; }

/* Ward cards */
.ward-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(280px,1fr)); gap:16px; }
.ward-card { display:flex; flex-direction:column; }
.ward-top { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.ward-name { font-weight:600; font-size:15.5px; color:var(--ink); text-decoration:none; }
.ward-name:hover { color:var(--violet-600,#7c3aed); }
.ward-animator { font-size:13px; color:var(--body); margin-top:8px; display:flex; align-items:center; gap:6px; }
.ward-desc { font-size:13px; color:var(--muted); margin:8px 0 0; line-height:1.5; }

/* Celebrants list */
.celebrants { display:grid; grid-template-columns:repeat(auto-fill,minmax(300px,1fr)); gap:10px; }
.celebrant { display:flex; align-items:center; gap:12px; padding:10px 12px; border:1px solid var(--line); border-radius:10px; background:var(--surface-2); }
.celebrant-ico { width:34px; height:34px; border-radius:9px; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.celebrant-ico.b { background:#fef3c7; color:#b45309; }
.celebrant-ico.x { background:#ede9fe; color:#6d28d9; }
.celebrant-main { flex:1; min-width:0; display:flex; flex-direction:column; }
.celebrant-main b { font-size:14px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.celebrant-main .muted { font-size:12px; }
.celebrant-meta { text-align:right; display:flex; flex-direction:column; gap:3px; align-items:flex-end; }
.celebrant-date { font-size:11.5px; color:var(--muted); }

/* QR ID cards */
.idcard {
  width:340px; margin:22px auto 40px; background:#fff; color:#1f2430;
  border:1px solid #e3e3ea; border-radius:14px; overflow:hidden;
  box-shadow:0 6px 24px rgba(0,0,0,.10); font-size:13px;
}
.idcard-head { background:linear-gradient(135deg,#4c1d95,#7c3aed); color:#fff; padding:12px 16px; display:flex; align-items:center; justify-content:space-between; }
.idcard-church { font-weight:600; font-size:14px; }
.idcard-kind { font-size:11px; text-transform:uppercase; letter-spacing:.06em; opacity:.9; }
.idcard-body { display:flex; gap:12px; padding:16px; align-items:center; }
.idcard-photo { flex-shrink:0; }
.idcard-info { flex:1; min-width:0; }
.idcard-info-wide { flex:1; }
.idcard-name { font-size:16px; font-weight:700; color:#4c1d95; margin-bottom:6px; }
.idcard-line { display:flex; gap:8px; font-size:12px; padding:1px 0; }
.idcard-line span { color:#8a8a99; min-width:52px; }
.idcard-qr { flex-shrink:0; background:#fff; padding:4px; border:1px solid #eee; border-radius:8px; }
.idcard-foot { background:#faf9fc; border-top:1px solid #eee; padding:8px 16px; font-size:10.5px; color:#8a8a99; text-align:center; }

@media print {
  .idcard { box-shadow:none; border:1px solid #ccc; margin:0 auto; }
}

/* ============================================================
   Phase 4: inline AI draft + weekly bulletin
   ============================================================ */
.ai-draft-btn { margin-bottom:8px; }
.ai-draft-panel { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-bottom:8px; padding:10px; background:var(--surface-2); border:1px solid var(--line); border-radius:10px; }
.ai-draft-brief { flex:1; min-width:220px; padding:7px 10px; border:1px solid var(--line); border-radius:8px; font-size:13.5px; }
.ai-draft-status { font-size:12.5px; color:var(--muted); }

.bulletin-opts { display:flex; gap:16px; flex-wrap:wrap; margin-bottom:12px; }
.bulletin-result .bulletin-text {
  white-space:pre-wrap; font-size:14px; line-height:1.65; color:var(--ink);
  background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:18px 20px;
}
@media print {
  .sidebar, .page-head .btn, .bulletin-form, .card-head .row-actions, .topbar { display:none !important; }
  .bulletin-result { border:none; box-shadow:none; padding:0; }
  .bulletin-result .bulletin-text { border:none; padding:0; }
}

/* ============================================================
   Cron reminders
   ============================================================ */
hr.soft { border:0; border-top:1px solid var(--line); margin:12px 0; }
.mini-label { display:block; font-size:11px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); margin:10px 0 4px; }
.cron-cmd { background:#0f172a; color:#e2e8f0; padding:10px 12px; border-radius:8px; font-size:12.5px; overflow-x:auto; white-space:pre; margin:0 0 4px; }

/* ============================================================
   Document watermark, inline editing, family-code builder
   ============================================================ */
.doc { position:relative; }
.doc-watermark {
  position:absolute; inset:0; z-index:0; pointer-events:none;
  background-repeat:no-repeat; background-position:center center; background-size:58%;
}
.doc > *:not(.doc-watermark) { position:relative; z-index:1; }
.certificate .cert-border { position:relative; z-index:1; }

.edit-hint { text-align:center; font-size:12.5px; color:#7c3aed; background:#f4f1fb; border:1px solid #e5dbf7; border-radius:8px; padding:6px 12px; max-width:820px; margin:8px auto 0; }
body.doc-editing [data-editable] { outline:1px dashed #a78bfa; outline-offset:2px; background:rgba(124,58,237,.05); cursor:text; border-radius:3px; }
[data-editable]:focus { outline:2px solid #7c3aed !important; background:#fff; }

.code-builder { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.code-builder .code-dash { color:var(--muted); font-weight:600; }
.code-builder input { min-width:0; }

@media print {
  .doc-watermark { -webkit-print-color-adjust:exact; print-color-adjust:exact; }
  [data-editable] { outline:none !important; background:none !important; }
  .edit-hint { display:none !important; }
}

/* ============================================================
   Role-based UI hiding (server-side RBAC still enforces).
   Viewers: no create/edit/delete affordances. Staff: no delete.
   ============================================================ */
body[data-role="viewer"] a[href*="/new"],
body[data-role="viewer"] a[href*="/edit"],
body[data-role="viewer"] a[href*="/create"],
body[data-role="viewer"] .row-actions form[action$="/delete"],
body[data-role="viewer"] form[action$="/delete"] button,
body[data-role="viewer"] .btn-danger {
  display: none !important;
}
body[data-role="staff"] .row-actions form[action$="/delete"],
body[data-role="staff"] form[action$="/delete"] button,
body[data-role="staff"] .btn-danger {
  display: none !important;
}

/* ============================================================
   Parishioner portal — login footer + login panes
   ============================================================ */
.auth-footer { margin:18px auto 0; display:flex; align-items:center; justify-content:center; gap:8px; color:var(--muted); font-size:12.5px; }
.auth-footer svg { width:15px; height:15px; color:var(--violet-600); }
.login-pane[hidden] { display:none; }
body[data-role="parishioner"] .btn-danger { display:none !important; }
