/* Confluence Church — shared styles. Phone first; a side rail appears at ≥ 900px. */
:root {
  --bg: #EFE9DC;        /* parchment */
  --bg-2: #E4DCCB;
  --card: #F8F4EB;
  --ink: #1F2A30;       /* river slate */
  --ink-2: #4A565D;
  --stone: #7A8790;
  --line: #D5CDBB;
  --moss: #6F9A74;
  --moss-ink: #35563A;
  --moss-soft: #DCE7DD;
  --ember: #C9973F;
  --ember-ink: #7A5714;
  --ember-soft: #F3E6CC;
  --red: #B5493C;
  --red-soft: #F4DBD7;
  --radius: 10px;
  --nav-h: 60px;
  --font: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1F2A30;
    --bg-2: #18232A;
    --card: #28353C;
    --ink: #EFE9DC;
    --ink-2: #C9C2B3;
    --stone: #8E9AA2;
    --line: #3A474F;
    --moss: #7FAE85;
    --moss-ink: #BFDDC2;
    --moss-soft: #2C4131;
    --ember: #D6A75A;
    --ember-ink: #F1D8A8;
    --ember-soft: #4A3A1E;
    --red: #E07A6C;
    --red-soft: #4A2622;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 16px; line-height: 1.45;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}
h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.85rem; line-height: 1.15; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
a { color: var(--moss-ink); }
p { margin: 0 0 .75rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, label, .chip, .night-chip { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }

/* ----- shell ----- */
.shell { max-width: 760px; margin: 0 auto; padding: 16px 16px 24px; }
.topbar { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.topbar .brand { font-family: var(--serif); font-size: 1rem; color: var(--stone); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head .sub { color: var(--stone); font-size: .95rem; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px); height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--stone); font-size: .72rem; padding: 6px 2px 4px; min-width: 0;
}
.tabbar a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--moss-ink); }
.tabbar a.on svg { stroke-width: 2.2; }

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabbar {
    top: 0; bottom: auto; left: 0; right: auto; height: 100vh; width: 200px; flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--line); padding: 24px 12px;
  }
  .tabbar::before { content: 'Confluence Church'; font-family: var(--serif); color: var(--stone); padding: 0 12px 20px; font-size: 1rem; }
  .tabbar a { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 10px; font-size: .95rem; padding: 10px 12px; border-radius: 8px; }
  .tabbar a.on { background: var(--moss-soft); }
  .shell { margin-left: 200px; max-width: 900px; padding: 28px 32px; }
  .topbar .brand { display: none; }
}

/* ----- primitives ----- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.tight { padding: 0; overflow: hidden; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list > li.link { cursor: pointer; }
.list > li.link:active { background: var(--bg-2); }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list .meta { color: var(--stone); font-size: .85rem; }
.trunc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--stone); flex: none; }
.empty { padding: 28px 16px; text-align: center; color: var(--stone); }
.empty strong { display: block; color: var(--ink); font-family: var(--serif); font-weight: 500; font-size: 1.1rem; margin-bottom: 4px; }

.pill { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--bg-2); color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: var(--moss-soft); color: var(--moss-ink); }
.pill.warn { background: var(--ember-soft); color: var(--ember-ink); }
.pill.bad { background: var(--red-soft); color: var(--red); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 8px 16px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--moss); border-color: var(--moss); color: #fff; }
.btn.danger { color: var(--red); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .9rem; font-weight: 500; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn-row .spacer { flex: 1; }
.iconbtn { border: 0; background: none; padding: 6px; color: var(--stone); cursor: pointer; border-radius: 6px; line-height: 0; }
.iconbtn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .85rem; color: var(--ink-2); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.field textarea { min-height: 80px; resize: vertical; }
.field input[type=checkbox], .field input[type=radio] { width: 20px; height: 20px; min-height: 0; margin: 0; flex: none; }
.field.check { display: flex; align-items: center; gap: 10px; }
.field.check > span { margin: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; }
.search { position: relative; margin-bottom: 12px; }
.search input { width: 100%; min-height: 44px; padding: 8px 12px 8px 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.search svg { position: absolute; left: 12px; top: 12px; width: 20px; height: 20px; stroke: var(--stone); fill: none; stroke-width: 1.8; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.seg button { border: 0; background: var(--card); padding: 7px 12px; cursor: pointer; font-size: .9rem; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: var(--bg); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .95rem; }
.kv dt { color: var(--stone); }
.kv dd { margin: 0; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; overflow: hidden; }
.stat .n { font-family: var(--serif); font-size: clamp(1.2rem, 5.5vw, 1.6rem); line-height: 1.1; white-space: nowrap; }
.stat .l { color: var(--stone); font-size: .82rem; margin-top: 2px; }
.money { font-variant-numeric: tabular-nums; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 0 8px; }
.section-title h2 { font-size: 1.15rem; }
.section-title .btn { min-height: 32px; }

table.plain { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.plain th, table.plain td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line); }
table.plain th { color: var(--stone); font-weight: 500; font-size: .82rem; border-top: 0; }
table.plain td.num, table.plain th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x, .card.tight.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ----- the dose grid (In Space): one card per person, three doses across, fits a phone ----- */
.doses { display: grid; gap: 10px; }
.person { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; }
.person.out { opacity: .55; }
.person-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.person-head .name { font-weight: 600; }
.person-head .meta { font-size: .8rem; color: var(--stone); }
.person-head .meta.bad { color: var(--red); }
.name-btn { font-weight: 600; display: inline-flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.name-btn .meta { font-weight: 400; }
.dose-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.dose-col { border: 1px dashed var(--line); border-radius: 8px; padding: 6px; min-height: 64px; display: flex; flex-direction: column; gap: 6px; }
.dose-col.has { border-style: solid; }
.dose-label { font-size: .72rem; color: var(--stone); font-weight: 500; }
/* Always a full-size touch target, and clear of the chips above it. */
.dose-col .add { margin-top: auto; min-height: 44px; border: 0; background: var(--bg-2); color: var(--ink-2); border-radius: 6px; cursor: pointer; font-size: 1.2rem; line-height: 1; touch-action: manipulation; }
.dose-col.has .add { background: transparent; color: var(--stone); border: 1px dashed var(--line); }
.dose-col .add:active { background: var(--moss-soft); }
.chip { touch-action: manipulation; }
.chip { display: grid; grid-template-columns: 1fr; width: 100%; min-height: 44px; text-align: left; border: 0; background: var(--moss-soft); color: var(--moss-ink); border-radius: 6px; padding: 6px; font: inherit; font-size: .8rem; cursor: pointer; }
.chip .nm { font-weight: 700; font-size: .95rem; line-height: 1.2; overflow-wrap: anywhere; }
.chip .q { font-size: .8rem; white-space: nowrap; margin-top: 2px; }
.chip .t { font-size: .72rem; font-style: italic; opacity: .75; margin-top: 2px; }
.daybar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.needs { display: grid; gap: 6px; margin-bottom: 10px; }
.need { font-size: .85rem; padding: 6px 10px; border-radius: 8px; background: var(--ember-soft); color: var(--ember-ink); }
.need.done { background: var(--moss-soft); color: var(--moss-ink); }
.need b { font-weight: 600; margin-right: 4px; }
.dose-line { align-items: center; }
.dose-line .meta { display: block; }
/* Fixed qty + unit columns so every row's input lines up whatever the unit is called. */
.qtybox { display: grid; grid-template-columns: 76px 56px; align-items: center; gap: 6px; flex: none; }
.qtybox input { width: 100%; min-height: 42px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); text-align: right; font-size: 1rem; }
.qtybox .unit { color: var(--stone); font-size: .85rem; line-height: 1.15; overflow-wrap: anywhere; }

/* ----- accounting rows: heading line + a wrapping grid of figures ----- */
.list > li.acct-row { display: block; }
.acct-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.figs > div { background: var(--bg); border-radius: 8px; padding: 6px 10px; min-width: 0; }
.figs .n { display: block; font-family: var(--serif); font-size: 1.15rem; line-height: 1.2; white-space: nowrap; }
.figs .n small { font-family: var(--font); font-size: .8rem; color: var(--stone); }
.figs .n.due { color: var(--ember-ink); }
.figs .l { display: block; font-size: .75rem; color: var(--stone); }

/* ----- In Space: one scenic card per retreat ----- */
.scenes { display: grid; gap: 12px; }
.scene { position: relative; display: block; min-height: 124px; border-radius: 14px; overflow: hidden; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.scene svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.scene-text { position: relative; padding: 16px 16px 14px; max-width: 72%; }
.scene-text::before { content: ''; position: absolute; inset: 0; right: -40px; background: linear-gradient(90deg, var(--card) 0%, var(--card) 55%, transparent 100%); opacity: .85; z-index: -1; }
.scene-text { z-index: 1; }
.scene svg { z-index: 0; }
.scene-title { font-family: var(--serif); font-size: 1.35rem; line-height: 1.15; margin-bottom: 4px; }
.scene-meta { font-size: .85rem; color: var(--ink-2); }
.scene-pill { position: absolute; top: 12px; right: 12px; }
.scene:active { filter: brightness(.97); }

/* ----- retreat summary ----- */
.lede { font-family: var(--serif); font-size: 1.12rem; line-height: 1.45; margin: 10px 0 14px; }
.insights { display: grid; gap: 8px; margin-bottom: 16px; }
.ins { display: grid; grid-template-columns: 26px 1fr; gap: 8px; align-items: start; background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--moss); border-radius: 10px; padding: 10px 12px; font-size: .92rem; line-height: 1.45; }
.ins .ico { font-size: 1.05rem; line-height: 1.3; }
.bar { height: 6px; border-radius: 3px; background: var(--bg-2); overflow: hidden; margin: 6px 0 4px; }
.bar span { display: block; height: 100%; background: var(--moss); border-radius: 3px; }
.bar.big { height: 10px; border-radius: 5px; }
.nightmix { display: grid; gap: 6px; margin-top: 10px; }
.nm { font-size: .85rem; color: var(--ink-2); background: var(--bg-2); border-radius: 8px; padding: 8px 10px; }
.nm b { color: var(--ink); margin-right: 4px; }
#debriefForm .field > span { font-size: .95rem; color: var(--ink); margin-bottom: 6px; }
#debriefForm .field { margin-bottom: 16px; }
/* Grown to fit by JS — no inner scrollbar, so nothing is clipped mid-sentence. */
textarea.grow-fit { min-height: 88px; overflow: hidden; resize: none; line-height: 1.5; }
.note { white-space: pre-wrap; }

/* ----- retreat page tabs ----- */
.tabs { display: flex; gap: 4px; background: var(--bg-2); border-radius: 12px; padding: 4px; margin: 4px 0 8px; position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; }
.tabs button { flex: 1; min-height: 40px; padding: 4px 2px; border: 0; border-radius: 9px; background: transparent; color: var(--ink-2); font-weight: 600; font-size: .92rem; cursor: pointer; white-space: nowrap; }
@media (max-width: 430px) { .tabs .count { display: none; } }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.tabs .count { font-weight: 400; color: var(--stone); font-size: .85rem; }
.tabs button.on .count { color: var(--moss-ink); }

/* ----- bare tappable text, payment ledger rows ----- */
button.tap { border: 0; background: none; padding: 0; cursor: pointer; font: inherit; text-align: left; color: inherit; }
button.pill.tap { padding: 2px 8px; }
button.link-ish { color: var(--moss-ink); font-size: inherit; }
.list.sub { margin-top: 8px; border-top: 1px solid var(--line); }
.list.sub > li { padding: 8px 0; }
.list > li.pay-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
.pay-row .remove { margin: -6px -8px -6px 0; padding: 10px; }
.pay-row .title { min-width: 0; }
.pay-row .meta, .pay-row .list.sub { grid-column: 1 / -1; }
.pay-row .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 6px; padding-right: 44px; }
.night-pills { display: inline-flex; gap: 4px; flex-wrap: wrap; }
a.quiet { color: inherit; text-decoration: none; }
button.tap.small.muted { color: var(--stone); text-decoration: underline; }
.night-pill { cursor: pointer; font-weight: 600; }
.pay-pill { cursor: pointer; font-weight: 600; }
.night-pill.bad { opacity: .85; }
.night-pill:disabled { opacity: .5; }
.stat-row.compact { grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; }
.stat-row.compact .stat { padding: 8px 10px; }
.stat-row.compact .n { font-size: clamp(1.05rem, 4.6vw, 1.3rem); }
.stat .n.due { color: var(--ember-ink); }
td.due { color: var(--ember-ink); }

.night-chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 4px 0 10px; }
.night-chip { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; min-height: 58px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); color: var(--stone); cursor: pointer; text-align: left; }
.night-chip .n { font-weight: 600; }
.night-chip .d { font-size: .8rem; }
.night-chip.on { border-color: var(--moss); background: var(--moss-soft); color: var(--moss-ink); }
.night-chip.on .n::before { content: '✓ '; }
.pad { position: relative; border: 1px solid var(--line); border-radius: 10px; background: #fff; touch-action: none; height: 160px; }
.pad canvas { width: 100%; height: 100%; display: block; border-radius: 10px; }
.pad .hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #9aa; pointer-events: none; font-family: var(--serif); font-size: 1.1rem; }
.pad .line { position: absolute; left: 20px; right: 20px; bottom: 34px; border-top: 1px solid #ccc; pointer-events: none; }
.pad .clear { position: absolute; right: 8px; top: 8px; }
details.danger-zone { margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--line); }
details.danger-zone summary { color: var(--stone); font-size: .85rem; cursor: pointer; list-style: none; }
details.danger-zone summary::-webkit-details-marker { display: none; }
details.danger-zone[open] summary { color: var(--red); }
details.danger-zone p { margin: 8px 0; }

/* ----- sheet (bottom modal) ----- */
.sheet-back { position: fixed; inset: 0; background: rgba(20, 26, 30, .45); z-index: 40; display: none; }
.sheet-back.open { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--card); border-radius: 16px 16px 0 0;
  max-height: 92vh; overflow-y: auto; padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%); transition: transform .22s ease-out; box-shadow: 0 -8px 30px rgba(0,0,0,.2);
}
.sheet.open { transform: translateY(0); }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin-bottom: 12px; }
@media (min-width: 900px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 520px; border-radius: 14px; transform: translate(-50%, -46%); opacity: 0; transition: opacity .15s, transform .15s; }
  .sheet.open { transform: translate(-50%, -50%); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .sheet { transition: none; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; }
.toast.err { background: var(--red); color: #fff; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

.note { border-left: 3px solid var(--line); padding: 4px 12px; margin-bottom: 10px; }
.note .when { color: var(--stone); font-size: .8rem; }
.linkbox { display: flex; gap: 8px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: .85rem; }
.linkbox code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--stone); }
.small { font-size: .85rem; }
.mt { margin-top: 12px; }
.hide { display: none !important; }

/* Comp controls in a person's payment sheet */
details.comp-zone { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }
details.comp-zone summary { color: var(--stone); font-size: .85rem; cursor: pointer; }
details.comp-zone p { margin: 8px 0; }
.comp-custom { display: flex; gap: 8px; align-items: flex-end; }
.comp-custom .field { flex: 1; margin-bottom: 0; }
