/* The Church — finance and membership system
   A single stylesheet, no build step. Colours are defined once as custom
   properties so the whole system can be retinted from one block. */

:root {
    --ink:            #1a1d23;
    --ink-soft:       #4a515e;
    --ink-faint:      #7b8395;
    --line:           #e2e5ea;
    --line-strong:    #cbd1da;
    --surface:        #ffffff;
    --surface-sunk:   #f6f7f9;
    --surface-raised: #ffffff;

    --brand:          #3d5a80;
    --brand-dark:     #2c4363;
    --brand-tint:     #eef2f7;

    /* Money semantics: money in, money out, and a problem that needs attention. */
    --credit:         #1b7f5a;
    --credit-tint:    #e8f5ef;
    --debit:          #a8383f;
    --debit-tint:     #fbecec;
    --warn:           #8a6100;
    --warn-tint:      #fdf4e0;

    --radius:         8px;
    --radius-sm:      5px;
    --shadow:         0 1px 2px rgba(26, 29, 35, .06), 0 4px 12px rgba(26, 29, 35, .04);

    --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--surface-sunk);
    -webkit-font-smoothing: antialiased;
}

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---------- Top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    height: 58px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 650;
    font-size: 15px;
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
}

.brand-mark { font-size: 18px; color: var(--brand); }

.nav {
    display: flex;
    gap: 2px;
    flex: 1;
    overflow-x: auto;
}

.nav-link {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

.nav-link:hover { background: var(--surface-sunk); color: var(--ink); }
.nav-link.is-active { background: var(--brand-tint); color: var(--brand-dark); font-weight: 600; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--ink-soft);
    white-space: nowrap;
}

.user-name { font-weight: 550; color: var(--ink); }
.inline-form { display: inline; margin: 0; }

/* ---------- Layout ---------- */

.content {
    flex: 1;
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.page-title { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.page-subtitle { color: var(--ink-faint); font-size: 14px; margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.footer {
    padding: 20px 24px;
    color: var(--ink-faint);
    font-size: 12px;
    text-align: center;
    border-top: 1px solid var(--line);
    background: var(--surface);
}

/* ---------- Cards ---------- */

.card {
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.card-title { font-size: 15px; font-weight: 620; margin: 0; }
.card-body { padding: 18px; }
.card-body.is-flush { padding: 0; }

/* ---------- Stat tiles ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.stat {
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 15px 17px;
    box-shadow: var(--shadow);
}

.stat-label {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--ink-faint);
    font-weight: 620;
    margin-bottom: 7px;
}

.stat-value {
    font-size: 23px;
    font-weight: 660;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.02em;
    line-height: 1.15;
}

.stat-note { font-size: 12.5px; color: var(--ink-faint); margin-top: 5px; }

.stat.is-credit .stat-value { color: var(--credit); }
.stat.is-debit  .stat-value { color: var(--debit); }
.stat.is-warn   .stat-value { color: var(--warn); }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table.data th {
    text-align: left;
    padding: 9px 14px;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .045em;
    color: var(--ink-faint);
    font-weight: 640;
    background: var(--surface-sunk);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

table.data td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-sunk); }

table.data tfoot td {
    padding: 11px 14px;
    font-weight: 640;
    background: var(--surface-sunk);
    border-top: 2px solid var(--line-strong);
}

/* Money and any other figure that should line up vertically. */
.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: var(--mono);
    font-size: 13.5px;
    white-space: nowrap;
}

.num.is-credit { color: var(--credit); }
.num.is-debit  { color: var(--debit); }
.num.is-strong { font-weight: 650; }
.muted { color: var(--ink-faint); }
.nowrap { white-space: nowrap; }

.empty {
    padding: 42px 20px;
    text-align: center;
    color: var(--ink-faint);
}

.empty-title { font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 11.5px;
    font-weight: 620;
    letter-spacing: .01em;
    white-space: nowrap;
    background: var(--surface-sunk);
    color: var(--ink-soft);
    border: 1px solid var(--line);
}

.badge-role { text-transform: capitalize; }
.badge-open      { background: var(--warn-tint);   color: var(--warn);   border-color: transparent; }
.badge-deposited { background: var(--credit-tint); color: var(--credit); border-color: transparent; }
.badge-restricted{ background: var(--brand-tint);  color: var(--brand-dark); border-color: transparent; }
.badge-cleared   { background: var(--credit-tint); color: var(--credit); border-color: transparent; }
.badge-void      { background: var(--debit-tint);  color: var(--debit);  border-color: transparent; }
.badge-locked    { background: var(--surface-sunk); color: var(--ink-faint); }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
    font-weight: 550;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { background: var(--surface-sunk); }

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.btn-danger { color: var(--debit); border-color: var(--line-strong); }
.btn-danger:hover { background: var(--debit-tint); border-color: var(--debit); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-sunk); color: var(--ink); }

.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Forms ---------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px 16px;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field.is-wide { grid-column: 1 / -1; }

.field label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-soft);
}

.field input,
.field select,
.field textarea {
    padding: 8px 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    color: var(--ink);
    background: var(--surface);
    width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: 2px solid var(--brand);
    outline-offset: -1px;
    border-color: var(--brand);
}

.field input[type="number"], .field .money-input { font-family: var(--mono); text-align: right; }
.field textarea { resize: vertical; min-height: 62px; }
.field-hint { font-size: 12px; color: var(--ink-faint); }

.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: auto; }
.check-row label { font-size: 13.5px; font-weight: 500; color: var(--ink); }

.form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.filter-bar {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-bar .field { min-width: 140px; }

/* ---------- Alerts ---------- */

.alert {
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-error   { background: var(--debit-tint);  color: var(--debit);  border-color: #f0cdcd; }
.alert-success { background: var(--credit-tint); color: var(--credit); border-color: #c5e6d8; }
.alert-warn    { background: var(--warn-tint);   color: var(--warn);   border-color: #f0e0b8; }
.alert-info    { background: var(--brand-tint);  color: var(--brand-dark); border-color: #d3dfec; }

/* ---------- Login ---------- */

.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--surface-sunk);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 30px;
}

.login-head { text-align: center; margin-bottom: 22px; }
.login-mark { font-size: 32px; color: var(--brand); }
.login-title { font-size: 19px; font-weight: 650; margin: 8px 0 3px; }
.login-sub { color: var(--ink-faint); font-size: 13.5px; margin: 0; }
.login-card .field { margin-bottom: 13px; }
.login-card .btn { width: 100%; }

/* ---------- Reconciliation ---------- */

.recon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    margin-bottom: 20px;
}

.recon-cell {
    padding: 14px 16px;
    border-right: 1px solid var(--line);
}

.recon-cell:last-child { border-right: none; }
.recon-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .045em; color: var(--ink-faint); font-weight: 620; }
.recon-value { font-size: 19px; font-weight: 650; font-family: var(--mono); font-variant-numeric: tabular-nums; margin-top: 5px; }

.recon-cell.is-difference { background: var(--debit-tint); }
.recon-cell.is-difference .recon-value { color: var(--debit); }
.recon-cell.is-balanced { background: var(--credit-tint); }
.recon-cell.is-balanced .recon-value { color: var(--credit); }

.recon-formula {
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--ink-faint);
    padding: 11px 16px;
    background: var(--surface-sunk);
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    line-height: 1.7;
}

/* Rows that have been ticked off against the statement. */
tr.is-cleared { background: var(--credit-tint) !important; }
tr.is-cleared:hover { background: #ddefe6 !important; }
tr.is-void td { opacity: .55; text-decoration: line-through; }
tr.is-void .badge { text-decoration: none; opacity: 1; }

.clear-check { width: 17px; height: 17px; cursor: pointer; accent-color: var(--credit); }

/* ---------- Progress ---------- */

.progress {
    height: 7px;
    background: var(--line);
    border-radius: 100px;
    overflow: hidden;
    min-width: 90px;
}

.progress-bar { height: 100%; background: var(--brand); border-radius: 100px; }
.progress-bar.is-complete { background: var(--credit); }

/* ---------- Statement (print) ---------- */

.statement {
    background: #fff;
    padding: 44px;
    max-width: 800px;
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.statement-head { text-align: center; border-bottom: 2px solid var(--ink); padding-bottom: 18px; margin-bottom: 24px; }
.statement-church { font-size: 21px; font-weight: 680; }
.statement-doctype { font-size: 14px; color: var(--ink-soft); margin-top: 5px; letter-spacing: .02em; }
.statement-donor { margin-bottom: 24px; line-height: 1.65; }
.statement-donor-name { font-weight: 640; font-size: 15.5px; }
.statement-address { color: var(--ink-soft); white-space: pre-line; font-size: 14px; }

.statement-total {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 15px 18px;
    background: var(--surface-sunk);
    border-radius: var(--radius-sm);
    margin: 22px 0;
}

.statement-total-label { font-weight: 620; }
.statement-total-value { font-size: 24px; font-weight: 680; font-family: var(--mono); }

.statement-notice {
    border: 1px solid var(--line-strong);
    border-left: 3px solid var(--brand);
    padding: 13px 16px;
    font-size: 13.5px;
    color: var(--ink-soft);
    border-radius: var(--radius-sm);
    margin-top: 22px;
    line-height: 1.6;
}

.print-only { display: none; }

@media print {
    .topbar, .footer, .page-actions, .no-print { display: none !important; }
    .print-only { display: block; }
    body { background: #fff; font-size: 12pt; }
    .content { max-width: none; padding: 0; }
    .statement { border: none; padding: 0; max-width: none; }
    .card { border: none; box-shadow: none; }
    table.data th { background: #fff !important; }
    a { text-decoration: none; color: inherit; }
}

/* ---------- Misc ---------- */

.link { color: var(--brand); text-decoration: none; font-weight: 550; }
.link:hover { text-decoration: underline; }

.section-divider {
    margin: 26px 0 14px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--ink-faint);
    font-weight: 650;
}

.two-col {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    align-items: start;
}

.htmx-request { opacity: .6; transition: opacity .1s; }

@media (max-width: 780px) {
    .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
    .nav { order: 3; width: 100%; }
    .content { padding: 16px; }
}
