:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe7d6;
  --ink: #2a2118;
  --muted: #74685a;
  --line: #ddd2bd;
  --brand: #6b1d1d;
  --brand-ink: #fff8ee;
  --brand-soft: #f3e2df;
  --gold: #b88a2e;
  --good: #2f6b3a;
  --good-soft: #e3efe0;
  --bad: #9b2c22;
  --bad-soft: #f6e0dc;
  --warn: #8a5a00;
  --warn-soft: #f7ecd2;
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17120e;
    --surface: #221b15;
    --surface-2: #2c231b;
    --ink: #efe6d6;
    --muted: #a99b88;
    --line: #3d3127;
    --brand: #c0584a;
    --brand-ink: #1a0f0c;
    --brand-soft: #3a211c;
    --gold: #d4ac55;
    --good: #7fbf86;
    --good-soft: #1f3322;
    --bad: #e58272;
    --bad-soft: #3d1f1a;
    --warn: #e2b459;
    --warn-soft: #3a2e15;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
a { color: var(--brand); }
p { margin: 0 0 .8em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.muted { color: var(--muted); }
.tiny { font-size: .82rem; }
.center { text-align: center; }
.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 520px; }
.loading { padding: 48px 0; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }

/* Top bar & navigation */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--brand); color: var(--brand-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
@media (prefers-color-scheme: dark) { .topbar { background: #3a1814; color: #f3e4d6; } }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 1.1rem; font-weight: 600; }
.brand img { width: 30px; height: 30px; border-radius: 7px; }
.topnav { display: none; gap: 4px; }
.topnav a, .tabbar a { text-decoration: none; color: inherit; }
.topnav a { padding: 6px 12px; border-radius: 999px; opacity: .85; font-size: .95rem; }
.topnav a.on { background: rgba(255,255,255,.16); opacity: 1; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 9px; font-size: .72rem; color: var(--muted); }
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.on { color: var(--brand); font-weight: 600; }
@media (min-width: 760px) {
  .topnav { display: flex; }
  .tabbar { display: none !important; }
  body { padding-bottom: 24px; }
}

.banner { background: var(--warn-soft); color: var(--warn); padding: 10px 16px; text-align: center; font-size: .92rem; }
.banner button { margin-left: 8px; }

/* Cards & lists */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

/* Forms */
label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 10px; }
label .hint { font-weight: 400; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: auto; min-height: 0; margin: 0; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
@media (max-width: 420px) { .checks { grid-template-columns: 1fr; } }
.form .btn { margin-top: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 16px; border-radius: 999px; min-height: 42px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.small { padding: 4px 12px; min-height: 32px; font-size: .85rem; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); text-decoration: underline; cursor: pointer; }

.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: .92rem; }
.notice.ok { background: var(--good-soft); color: var(--good); }
.notice.err { background: var(--bad-soft); color: var(--bad); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

.chip { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.lvl { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; }
.lvl-mit { background: var(--warn-soft); color: var(--warn); }
.lvl-mof { background: var(--good-soft); color: var(--good); }
.lvl-training { background: var(--brand-soft); color: var(--brand); }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; }
.bar span { display: block; height: 100%; background: var(--gold); border-radius: 99px; }

/* ID card */
.idcard {
  position: relative; overflow: hidden;
  background: linear-gradient(160deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--line); border-top: 6px solid var(--brand);
  border-radius: 16px; padding: 18px 18px 16px; margin-bottom: 14px;
  box-shadow: 0 1px 0 rgba(0,0,0,.03), 0 8px 24px -16px rgba(60,30,10,.35);
}
.idcard-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.kingdom { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.idcard .sca { font-size: 1.7rem; margin: 4px 0 2px; }
.idcard .office { margin-top: 6px; font-size: .88rem; font-weight: 600; color: var(--brand); }
.qrbox { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 14px; }
.qrbox .qr { background: #fff; padding: 12px; border-radius: 12px; line-height: 0; }
.qrbox .qr svg, .qrbox .qr img { width: 220px; height: 220px; display: block; }
.standing { list-style: none; padding: 0; margin: 0; }
.standing li { padding: 10px 0; border-top: 1px solid var(--line); }
.standing li:first-child { border-top: 0; }

/* Checklist */
.items { list-style: none; padding: 0; margin: 0; }
.items li { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.items li:first-child { border-top: 0; }
.num {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-size: .82rem; font-weight: 700; border: 2px solid var(--line); color: var(--muted);
}
.items li.done .num { background: var(--good); border-color: var(--good); color: #fff; }
.items .t { font-weight: 600; }
.items .meta { font-size: .84rem; color: var(--muted); margin-top: 2px; }
.items .meta strong { color: var(--ink); font-weight: 600; }
.items li.na { opacity: .55; }

/* Sign off */
.pick { display: grid; gap: 8px; }
.opt {
  display: flex; align-items: flex-start; gap: 10px; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  font: inherit; color: inherit; cursor: pointer;
}
.opt:hover:not(:disabled) { border-color: var(--brand); }
.opt.on { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); background: var(--brand-soft); }
.opt:disabled { cursor: default; opacity: .6; }
.opt .sub { font-size: .82rem; color: var(--muted); }
.step { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 18px 0 8px; }
.selected-person { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.scanner { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 1; max-width: 360px; margin: 0 auto; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 15%; border: 3px solid rgba(255,255,255,.85); border-radius: 14px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 9px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-top: 0; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--surface-2); }
.scrollx { overflow-x: auto; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { font: inherit; font-size: .88rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.tabs button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

details.item-edit { border-top: 1px solid var(--line); padding: 10px 0; }
details.item-edit summary { cursor: pointer; font-weight: 600; }
details.item-edit summary .chip { margin-left: 6px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 10px 18px;
  font-size: .92rem; width: max-content; max-width: min(440px, calc(100% - 32px)); border-radius: 14px; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
@media (min-width: 760px) { .toast { bottom: 24px; } }

.auth-hero { text-align: center; padding: 18px 0 8px; }
.auth-hero img { width: 72px; height: 72px; border-radius: 16px; }
.empty { text-align: center; padding: 24px 8px; color: var(--muted); }

body.setup { padding-bottom: 24px; }
.verify { padding-top: 24px; }
.card.confirm { border-left: 4px solid var(--brand); }

/* Sign-off requests */
.reqbox { margin-top: 6px; padding: 8px 10px; border-radius: 8px; font-size: .84rem; }
.reqbox.pending { background: var(--warn-soft); color: var(--warn); }
.reqbox.declined { background: var(--bad-soft); color: var(--bad); }
.reqform { margin-top: 10px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; }
.card.req { border-left: 4px solid var(--gold); }
.topnav a, .tabbar a { position: relative; }
.navbadge {
  position: absolute; top: 3px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--gold); color: #1a1208; font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center;
}
.topnav .navbadge { top: -4px; left: auto; right: -4px; }

/* Roster import */
.rgroup { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.rgroup:first-of-type { border-top: 0; }
.rchange { display: flex; align-items: flex-start; gap: 10px; font-weight: 400; padding: 7px 0; margin: 0; }
.rchange input { width: 18px; height: 18px; min-height: 0; margin: 3px 0 0; flex: none; }
.rchange .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin: 8px 5px 0; flex: none; }

/* System → Claude usage */
.statrow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 6px 0 4px; }
@media (max-width: 520px) { .statrow { grid-template-columns: repeat(2, 1fr); } }
.stat { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; line-height: 1.2; }
.conn { border-top: 1px solid var(--line); padding: 10px 0; }
.conn:first-of-type { border-top: 0; }
.conn.on { box-shadow: inset 3px 0 0 var(--good); padding-left: 10px; }
details.item-edit summary .chip { margin-left: 4px; vertical-align: 1px; }
details.additem summary { color: var(--brand); }
form.area { padding: 12px 0; border-top: 1px solid var(--line); }
form.area:first-child { border-top: 0; padding-top: 0; }
.areapick button { font-size: .82rem; padding: 5px 12px; }
.areaselect { display: none; }
@media (max-width: 759px) {
  .areapick { display: none; }
  .areaselect { display: block; }
}

/* Passkeys */
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .8rem; margin: 12px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
#pksign svg { width: 20px; height: 20px; }

/* Modal dialogs */
body.modal-open { overflow: hidden; }
.modal-back { position: fixed; inset: 0; z-index: 100; background: rgba(20, 12, 8, .55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); color: var(--ink); border-radius: 14px; width: min(520px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal-head { padding: 16px 18px 10px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 12px 18px; overflow-y: auto; }
.modal-foot { padding: 10px 18px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.pick-list .check { padding: 5px 0; }
.stack > .btn.block + .btn.block { margin-top: 8px; }

/* Accounts table + filters */
.filterbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.fchk { display: inline-flex; align-items: center; gap: 6px; }
.fchk label.check { margin: 0; font-weight: 600; font-size: .9rem; }
table.acct th, table.acct td { padding: 8px 6px; }
table.acct td .lvl { margin-left: 2px; font-size: .68rem; padding: 1px 6px; }
.nowrap { white-space: nowrap; }
.wrap.wide { max-width: 1240px; }
