/* FamilyLife Admin – self-contained stylesheet (no web fonts, no external assets). */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --border: #e3e6ec;
  --primary: #3d6fa8;
  --primary-text: #ffffff;
  --ok-bg: #e7f6ec; --ok-text: #1e6b3a;
  --err-bg: #fdecec; --err-text: #9b1c1c;
  --warn: #b45309;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1b1f27;
    --text: #e6e8ec;
    --muted: #98a2b3;
    --border: #2c323d;
    --primary: #6d9ad3;
    --primary-text: #0e1116;
    --ok-bg: #173323; --ok-text: #8fdcaa;
    --err-bg: #3a1a1a; --err-text: #f4a3a3;
    --warn: #f0a04b;
    --danger: #ef6b5b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .6rem; }
.card h2 { margin-top: 0; }

.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .6rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .45rem; font-weight: 700; color: var(--text); }
.brand span { font-weight: 400; color: var(--muted); }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { padding: .35rem .7rem; border-radius: 8px; color: var(--text); }
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a[aria-current="page"] { background: var(--primary); color: var(--primary-text); }
.logout { margin-left: auto; display: flex; align-items: center; gap: .6rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.4rem 16px 3rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; margin: 1rem 0; box-shadow: var(--shadow);
}
details.card summary { cursor: pointer; }
details.card[open] summary { margin-bottom: .8rem; }

.head-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.head-row h1 { margin-bottom: .6rem; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 1rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; }
.tile {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; color: var(--text); box-shadow: var(--shadow);
}
a.tile:hover { border-color: var(--primary); text-decoration: none; }
.tile .num { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.tile .lbl { font-weight: 600; }
.tile .sub { color: var(--muted); font-size: .85em; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card .table-wrap { border: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
td.payload code { color: var(--muted); word-break: break-all; }

.badge {
  display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
}
.badge.ok { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.badge.err { background: var(--err-bg); color: var(--err-text); border-color: transparent; }

.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok-text); }
.alert.err { background: var(--err-bg); color: var(--err-text); }

input[type=text], input[type=email], input[type=password], input[type=search] {
  font: inherit; color: inherit; background: var(--surface);
  padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 8px; width: 100%;
}
input[type=search] { max-width: 320px; }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: .5rem; }

.btn {
  font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: .3rem;
  padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.warn { color: var(--warn); border-color: var(--warn); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: .2rem .6rem; font-size: .85em; }

.stack { display: flex; flex-direction: column; gap: .9rem; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .9rem; align-items: end; }
.inline-form { display: flex; gap: .7rem; align-items: end; flex-wrap: wrap; margin-bottom: 1rem; }
.inline-form label { flex: 1 1 220px; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1.2rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-all; }
ul.plain { list-style: none; padding: 0; margin: 0 0 .8rem; }
ul.plain li { padding: .3rem 0; border-bottom: 1px solid var(--border); }
ul.plain li:last-child { border-bottom: 0; }

.pager { display: flex; gap: .8rem; align-items: center; justify-content: center; margin: 1rem 0; }

.login { max-width: 380px; margin: 8vh auto; }
.login h1 { margin-bottom: .2rem; }

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

@media (max-width: 640px) {
  .topbar { gap: .6rem; }
  .logout { margin-left: 0; width: 100%; justify-content: space-between; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { margin-top: .4rem; }
}
