/* Church Planter Support. Palette borrowed from the MNA match demo (PCA Deep Blue / Scottish Blue, warm
   terracotta accent). System fonts only; no external CSS. */
:root {
  --deep: #042356;
  --blue: #0065A4;
  --blue-soft: #e6f0f8;
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #bcc5d1;
  --border-soft: #d9dee6;
  --ink: #042356;
  --ink-soft: #264560;
  --muted: #4b5a68;
  --accent: #b96740;
  --accent-deep: #7c350d;
  --accent-soft: #fbefe8;
  --plum: #833d65;
  --plum-soft: #f6eaf1;
  --ok: #1d6b3a;
  --ok-soft: #e5f3ea;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --bad: #a3222b;
  --bad-soft: #fcebec;
  --focus: #0065A4;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(4,35,86,.08), 0 1px 1px rgba(4,35,86,.06);
  --shadow-raised: 0 6px 24px rgba(4,35,86,.16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.5; color: var(--ink); background: var(--bg); overflow-wrap: anywhere; }
a { color: var(--blue); }
a:hover { color: var(--plum); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.skip-link { position: absolute; left: -999px; top: 8px; background: #fff; padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar { background: var(--deep); color: #fff; border-bottom: 3px solid var(--accent); }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .01em; }
.brand:hover { color: #fff; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--blue); display: grid; place-items: center; font-size: 15px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.topbar nav a, .topbar nav button { color: #dfe9f5; text-decoration: none; background: none; border: 0; font: inherit; font-size: .92rem; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.topbar nav a:hover, .topbar nav button:hover { background: rgba(255,255,255,.1); color: #fff; }
.who { font-size: .85rem; color: #c8d6e8; display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.who b { color: #fff; font-weight: 600; }

/* ---------- layout ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 64px; }
.narrow { max-width: 560px; }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; }
.auth-wrap main { width: 100%; max-width: 460px; padding-top: 32px; }
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand .brand-mark { margin: 0 auto 8px; width: 44px; height: 44px; font-size: 22px; color: #fff; }
.auth-brand h1 { font-size: 1.4rem; margin: 0; }
.auth-brand p { color: var(--muted); margin: 4px 0 0; }
.card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.spacer { flex: 1; }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .85rem; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=date], input[type=url], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 9px 10px; min-height: 42px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.check input { width: 18px; height: 18px; margin-top: 3px; flex: none; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 70px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--blue); font: inherit; font-size: .85rem; font-weight: 600; padding: 6px 8px; cursor: pointer; border-radius: 4px; }
fieldset { border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 10px 14px 4px; margin: 0 0 14px; }
legend { font-weight: 600; font-size: .92rem; padding: 0 4px; }
.choice { display: flex; gap: 10px; flex-wrap: wrap; }
.choice label { display: flex; gap: 8px; align-items: center; border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; font-weight: 500; cursor: pointer; background: #fff; }
.choice label:has(input:checked) { border-color: var(--blue); background: var(--blue-soft); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .95rem; border-radius: 6px; padding: 9px 16px; min-height: 42px; border: 1px solid var(--blue); background: var(--blue); color: #fff; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { background: var(--deep); border-color: var(--deep); color: #fff; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--blue); }
.btn.secondary:hover { background: var(--blue-soft); color: var(--deep); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--blue); }
.btn.ghost:hover { background: var(--blue-soft); }
.btn.danger { background: #fff; color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.accent { background: var(--accent); border-color: var(--accent); }
.btn.accent:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn.big { padding: 12px 22px; font-size: 1.05rem; min-height: 50px; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn.block { width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--blue); text-decoration: underline; cursor: pointer; }
kbd { font-family: var(--mono); font-size: .8em; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: #fff; color: var(--ink-soft); }

/* ---------- notices ---------- */
.notice { border-radius: 6px; padding: 10px 12px; margin: 0 0 14px; border: 1px solid; font-size: .95rem; }
.notice.error { background: var(--bad-soft); border-color: #e6b3b7; color: var(--bad); }
.notice.ok { background: var(--ok-soft); border-color: #b5dcc2; color: var(--ok); }
.notice.info { background: var(--blue-soft); border-color: #b8d3ea; color: var(--deep); }
.notice.warn { background: var(--warn-soft); border-color: #ebd193; color: var(--warn); }
.dev-note { border: 2px dashed #9c6a00; background: #fff8e1; color: #5c4100; border-radius: 6px; padding: 8px 10px; margin: 0 0 14px; font-size: .9rem; }
.dev-note b { background: #9c6a00; color: #fff; border-radius: 3px; padding: 0 5px; margin-right: 6px; font-size: .78rem; letter-spacing: .05em; }
.dev-note code { font-family: var(--mono); font-size: 1rem; font-weight: 700; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-soft); margin-bottom: 18px; overflow-x: auto; scrollbar-width: thin; }
.tabs a, .tabs button { flex: none; padding: 10px 14px; border: 0; border-bottom: 3px solid transparent; background: none; color: var(--ink-soft); font: inherit; font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer; }
.tabs a:hover, .tabs button:hover { color: var(--blue); }
.tabs [aria-selected=true], .tabs [aria-current=page] { color: var(--deep); border-bottom-color: var(--accent); }
.tabs .export { margin-left: auto; color: var(--blue); }

/* ---------- tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border-soft); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfd; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: #f3f7fb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.chip.stage { background: var(--blue-soft); color: var(--deep); }
.chip.stage-committed, .chip.stage-thanked { background: var(--ok-soft); color: var(--ok); }
.chip.stage-ask, .chip.stage-follow_up { background: var(--accent-soft); color: var(--accent-deep); }
.chip.st-new { background: var(--ok-soft); color: var(--ok); }
.chip.st-duplicate { background: var(--warn-soft); color: var(--warn); }
.chip.st-repeat { background: var(--plum-soft); color: var(--plum); }
.chip.st-invalid { background: var(--bad-soft); color: var(--bad); }
.chip.role { background: #eef1f5; color: var(--ink-soft); }
.chip.owner { background: var(--accent-soft); color: var(--accent-deep); }
.chip.override { background: var(--plum-soft); color: var(--plum); }
.chip.off { background: #eee; color: #555; }
.merge-chip { border: 1px dashed var(--blue); background: var(--blue-soft); color: var(--deep); border-radius: 999px; padding: 3px 10px; font: inherit; font-size: .8rem; font-family: var(--mono); cursor: pointer; }
.merge-chip:hover { background: #d4e6f5; }

/* ---------- stats ---------- */
.stat { padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: .85rem; font-weight: 600; }
.stat .value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.meter { height: 14px; background: #e9eef4; border-radius: 999px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--deep)); border-radius: 999px; transition: width .4s ease; }
.goal-line { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.stage-bars { display: grid; gap: 6px; }
.stage-bar { display: grid; grid-template-columns: 92px 1fr 34px; gap: 8px; align-items: center; font-size: .88rem; }
.stage-bar .track { height: 10px; background: #edf1f6; border-radius: 999px; overflow: hidden; }
.stage-bar .track span { display: block; height: 100%; background: var(--blue); }
.stage-bar .n { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- drawer & dialog ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(4,35,86,.35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: #fff; z-index: 41; box-shadow: var(--shadow-raised); display: flex; flex-direction: column; }
.drawer header { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border-soft); }
.drawer header h2 { margin: 0; font-size: 1.1rem; flex: 1; }
.drawer .body { padding: 16px; overflow-y: auto; flex: 1; }
dialog { border: 0; border-radius: 10px; box-shadow: var(--shadow-raised); padding: 0; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); color: var(--ink); }
dialog::backdrop { background: rgba(4,35,86,.4); }
dialog .dlg-head { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); position: sticky; top: 0; background: #fff; }
dialog .dlg-head h2 { flex: 1; margin: 0; font-size: 1.1rem; }
dialog .dlg-body { padding: 16px; }
.close-x { border: 0; background: none; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 4px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--deep); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-raised); z-index: 60; max-width: calc(100vw - 32px); font-size: .95rem; }

/* ---------- markdown ---------- */
.md h1 { font-size: 1.35rem; }
.md h2 { font-size: 1.1rem; margin-top: 1.1em; }
.md ul { padding-left: 1.3em; }
.md li { margin-bottom: .3em; }
.doc-box { max-height: 52vh; overflow-y: auto; border: 1px solid var(--border-soft); border-radius: 6px; padding: 14px 16px; background: #fcfdfe; }

/* ---------- history / thread ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-left: 3px solid var(--border-soft); padding: 4px 0 10px 12px; font-size: .9rem; }
.timeline time { color: var(--muted); font-size: .8rem; display: block; }
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 88%; border-radius: 10px; padding: 9px 12px; background: #fff; border: 1px solid var(--border-soft); }
.msg.mine { align-self: flex-end; background: var(--blue-soft); border-color: #c4dbee; }
.msg.feedback { border-left: 5px solid var(--accent); background: var(--accent-soft); }
.msg .meta { font-size: .78rem; color: var(--muted); margin-bottom: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.msg .text { white-space: pre-wrap; }
.tag-feedback { background: var(--accent); color: #fff; border-radius: 4px; padding: 0 6px; font-weight: 700; font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; }

/* ---------- workflow mode ---------- */
.wf { max-width: 860px; margin: 0 auto; }
.wf-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.wf-progress { flex: 1; min-width: 180px; }
.wf-progress .count { font-weight: 700; font-size: 1.05rem; }
.wf-progress .meter { height: 8px; margin-top: 4px; }
.wf-card { background: #fff; border: 1px solid var(--border-soft); border-radius: 12px; box-shadow: var(--shadow-raised); overflow: hidden; }
.wf-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--border-soft); background: linear-gradient(180deg, #fbfcfe, #fff); }
.wf-step { display: inline-block; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--accent-deep); margin-bottom: 4px; }
.wf-name { font-size: 1.6rem; font-weight: 700; margin: 0; }
.wf-rel { color: var(--ink-soft); margin: 2px 0 8px; }
.wf-contact { display: flex; gap: 14px; flex-wrap: wrap; font-size: .95rem; color: var(--ink-soft); }
.wf-contact span { display: inline-flex; gap: 4px; }
.wf-body { padding: 16px 20px 20px; }
.channels { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 14px; flex-wrap: wrap; }
.channels button { border: 0; background: #fff; font: inherit; font-weight: 600; font-size: .92rem; padding: 8px 14px; cursor: pointer; color: var(--ink-soft); border-right: 1px solid var(--border-soft); }
.channels button:last-child { border-right: 0; }
.channels button[aria-pressed=true] { background: var(--deep); color: #fff; }
.script-box { background: #f8fafc; border: 1px solid var(--border-soft); border-left: 5px solid var(--blue); border-radius: 8px; padding: 16px 18px; }
.script-box.override { border-left-color: var(--plum); }
.script-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.script-subject { font-weight: 700; margin-bottom: 8px; }
.script-text { font-size: 1.22rem; line-height: 1.65; white-space: pre-wrap; color: var(--ink); }
.wf-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 4px; }
.wf-finish { border-top: 1px solid var(--border-soft); margin-top: 16px; padding-top: 16px; }
.wf-finish .grid { gap: 12px; }
.wf-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.wf-empty { text-align: center; padding: 40px 20px; }
.wf-empty .big-mark { font-size: 2.6rem; }
.wf-celebrate { animation: rise .6s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .wf-celebrate { animation: none; } .meter > span { transition: none; } }
.help-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; align-items: center; }

/* ---------- hub ---------- */
.planter-card { display: block; text-decoration: none; color: inherit; }
.planter-card:hover { border-color: var(--blue); color: inherit; }
.planter-card h3 { margin-bottom: 2px; color: var(--deep); }
.planter-card .nums { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: .9rem; }
.planter-card .nums b { display: block; font-size: 1.2rem; }
.script-edit { border-top: 1px solid var(--border-soft); padding-top: 12px; margin-top: 12px; }
.compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.compare pre { white-space: pre-wrap; font-family: var(--font); margin: 0; background: #f8fafc; border: 1px solid var(--border-soft); border-radius: 6px; padding: 10px; font-size: .92rem; }

/* ---------- admin ---------- */
.admin { display: grid; grid-template-columns: 210px 1fr; gap: 20px; }
.side { position: sticky; top: 12px; align-self: start; }
.side a { display: block; padding: 8px 12px; border-radius: 6px; text-decoration: none; color: var(--ink-soft); font-weight: 600; }
.side a:hover { background: var(--blue-soft); }
.side a[aria-current=page] { background: var(--deep); color: #fff; }
.matrix th.coach { writing-mode: initial; white-space: normal; min-width: 110px; text-transform: none; font-size: .85rem; letter-spacing: 0; color: var(--ink); }
.matrix td.cell { text-align: center; min-width: 110px; }
.matrix td.cell.dirty { background: var(--warn-soft); }
.cell-inner { display: inline-flex; align-items: center; gap: 6px; }
.cell-inner input { width: 20px; height: 20px; }
.kind-toggle { font: inherit; font-size: .75rem; border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 2px 8px; cursor: pointer; }
.kind-toggle[data-kind=sponsor] { background: var(--plum-soft); color: var(--plum); border-color: var(--plum); }
.assign-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--blue-soft); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: .85rem; margin: 2px; }
.assign-chip button { border: 0; background: none; cursor: pointer; font-size: 1rem; line-height: 1; padding: 2px 6px; border-radius: 999px; color: var(--ink-soft); }
.assign-chip button:hover { background: #fff; }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(200px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.board-col { background: #eef2f7; border-radius: 8px; padding: 8px; min-height: 120px; }
.board-col h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.board-item { background: #fff; border-radius: 6px; padding: 8px; margin-bottom: 6px; box-shadow: var(--shadow); font-size: .88rem; }

@media (max-width: 760px) {
  .admin { grid-template-columns: 1fr; }
  .side { position: static; display: flex; overflow-x: auto; gap: 4px; border-bottom: 1px solid var(--border-soft); padding-bottom: 6px; }
  .side a { flex: none; }
  .who { display: none; }
  .wf-name { font-size: 1.35rem; }
  .script-text { font-size: 1.1rem; }
  .wf-head, .wf-body { padding-left: 14px; padding-right: 14px; }
  h1 { font-size: 1.35rem; }
}
/* grid children may shrink below their content (tables scroll inside .table-wrap, never the page) */
.grid > *, .admin > *, .compare > * { min-width: 0; }
.grid > .card + .card { margin-top: 0; }
.big-number { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.remember-row { margin-top: 14px; }
