:root {
  --navy: #1d2a4d;
  --navy-2: #26365f;
  --gold: #b8902b;
  --gold-text: #7a5f16;
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #dfe2e8;
  --text: #1f2430;
  --muted: #6a7180;
  --green: #2e7d4f;
  --red: #b3261e;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
header {
  background: var(--navy);
  color: #fff;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
header .brand { font-weight: 600; letter-spacing: .2px; }
header .brand small { display: block; font-weight: 400; opacity: .75; font-size: 12px; }
header .who { font-size: 13px; opacity: .9; }
header button { background: var(--gold); color: var(--navy); }

main { max-width: 1000px; margin: 24px auto; padding: 0 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 14px;
  background: #fff;
}
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 160px; }
.checkbox { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.checkbox input { width: auto; }

button {
  background: var(--navy);
  color: #fff;
  border: 0;
  padding: 9px 16px;
  border-radius: 7px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 12px;
}
button.small { padding: 5px 11px; font-size: 13px; margin: 0; }
button.ghost { background: #eef0f4; color: var(--navy); }
button.danger { background: var(--red); }
button:disabled { opacity: .5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; margin-top: 6px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill.submitted { background: #fff2d6; color: #8a6300; }
.pill.verified { background: #e2efff; color: #1d57a6; }
.pill.scheduled { background: #e3f4e9; color: var(--green); }
.pill.completed { background: #ececec; color: #555; }
.pill.forming { background: #fff2d6; color: #8a6300; }
.pill.ready { background: #e3f4e9; color: var(--green); }
.pill.confirmed { background: #d8ecff; color: #1d57a6; }

.note { font-size: 13px; color: var(--muted); }
.error { color: var(--red); font-size: 13px; margin-top: 8px; }
.ok { color: var(--green); font-size: 13px; margin-top: 8px; }
.center { max-width: 380px; margin: 60px auto; }
.hidden { display: none; }
.members { font-size: 13px; color: var(--muted); }
.members .chair { color: var(--gold-text); font-weight: 600; }

/* District admin: app-shell layout */
.adminLayout { display: flex; gap: 0; align-items: stretch; }
.adminNav {
  flex: 0 0 232px;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  overflow: auto;
}
.adminNav button { text-align: left; background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 10px 12px; cursor: pointer; font-size: 14px; color: var(--navy); }
.adminNav button:hover { background: rgba(0,0,0,.05); }
.adminNav button.active { background: var(--navy); color: #fff; }
.adminMain { flex: 1; min-width: 0; padding: 24px 28px 64px; }

/* Overview calendar */
table.cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.cal th { font-size: 12px; color: #666; padding: 4px; text-align: center; }
table.cal td { border: 1px solid var(--line); vertical-align: top; height: 84px; padding: 3px; font-size: 12px; }
table.cal td.calEmpty { background: #fafafa; }
.calNum { font-weight: 600; color: #888; font-size: 11px; }
.calEv { background: var(--navy); color: #fff; border-radius: 4px; padding: 1px 4px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 760px) {
  .adminMain { padding: 16px 16px 56px; }
}

/* People list as breathable rows */
.personRow { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.personMain { flex: 1 1 240px; min-width: 220px; }
.personMain > div { margin-bottom: 2px; }
.personActions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.roleTag { display: inline-block; background: #eef0f4; color: var(--navy); border-radius: 10px; padding: 1px 9px; font-size: 12px; margin-left: 4px; }
#peopleFilter { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }

/* ===================== Phase 1: design system ===================== */
:root {
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px;
  --radius: 10px; --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow: 0 6px 20px rgba(16,24,40,.08);
  --focus: 0 0 0 3px rgba(29,42,77,.28);
}

/* motion + visible focus for keyboard users */
button, input, select, textarea, .adminNav button, a {
  transition: background-color .15s ease, box-shadow .15s ease, border-color .15s ease, color .15s ease;
}
:focus-visible { outline: none; box-shadow: var(--focus); }

/* button hierarchy + hover states */
button:hover { background: var(--navy-2); }
button.ghost:hover { background: #e4e7ee; }
button.danger:hover { background: #9d211b; }
header button:hover { background: var(--gold); filter: brightness(1.08); }

/* subtle lift on cards */
.card { box-shadow: var(--shadow-sm); }

/* textarea matches inputs */
textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit; background: #fff;
}

/* panels: one consistent sub-surface, optional gold accent for action panels */
.panel { background: #f8f9fb; border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-4); margin-top: var(--space-4); }
.panel.accent { border-left: 3px solid var(--gold); }

/* repeating cards */
.itemCard { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3); }
.statCard { flex: 1; min-width: 120px; border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3); }

/* layout helpers */
.spread { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.cluster { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 14px; padding: 2px 10px; margin: 2px; font-size: 13px; }
.chip-x { border: none; background: none; cursor: pointer; color: var(--red); font-weight: 700; line-height: 1; padding: 0 2px; }
.chip-x:hover { background: none; color: #7d1a15; }

/* small utilities */
.danger-text { color: var(--red); }
.alignR { text-align: right; }
.bold { font-weight: 600; }
.m0 { margin: 0; }
.mt-2 { margin-top: 8px; }
.mb-3 { margin-bottom: 10px; }
.mb-4 { margin-bottom: 14px; }

/* links */
a { color: var(--navy); }
a:focus-visible { box-shadow: var(--focus); border-radius: 4px; }

/* ===================== Phase 2: toasts + modal ===================== */
#toastWrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.toast {
  pointer-events: auto; width: 100%; max-width: 440px;
  background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 14px; line-height: 1.4;
  opacity: 0; transform: translateY(10px); transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

.modalOverlay {
  position: fixed; inset: 0; z-index: 1100; background: rgba(16,20,30,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  opacity: 0; transition: opacity .18s ease;
}
.modalOverlay.show { opacity: 1; }
.modalBox {
  background: #fff; border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 420px; padding: 20px;
  transform: translateY(12px); transition: transform .18s ease;
}
.modalOverlay.show .modalBox { transform: none; }
.modalTitle { margin: 0 0 8px; font-size: 17px; color: var(--text); text-transform: none; letter-spacing: 0; }
.modalBody { font-size: 14px; color: var(--text); line-height: 1.5; }
.modalActions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modalActions button { margin-top: 0; }
.codebox {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px;
  background: #f4f5f7; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin-top: 10px; word-break: break-all;
}
@media (max-width: 480px) {
  .modalActions { flex-direction: column-reverse; }
  .modalActions button { width: 100%; }
}

/* ===================== Phase 4: app shell + mobile drawer ===================== */
:root { --header-h: 58px; }

/* admin view goes full-bleed so the sidebar sits at the far left */
body.admin-shell #appView { max-width: none; margin: 0; padding: 0; }

.headLeft { display: flex; align-items: center; gap: 12px; min-width: 0; }
.navToggle {
  display: none; background: rgba(255,255,255,.16); color: #fff; border: 0;
  font-size: 18px; line-height: 1; padding: 8px 12px; border-radius: 8px; margin: 0; cursor: pointer;
}
.navToggle:hover { background: rgba(255,255,255,.28); }
#navBackdrop { display: none; }

@media (max-width: 760px) {
  /* hamburger only where there is a sidebar to open */
  body.admin-shell .navToggle { display: inline-flex; align-items: center; }
  header .brand { font-size: 14px; }

  /* sidebar becomes an off-canvas drawer */
  body.admin-shell .adminNav {
    position: fixed; top: 0; left: 0; height: 100vh; width: 264px; max-width: 84vw;
    transform: translateX(-100%); transition: transform .22s ease;
    z-index: 200; border-right: 1px solid var(--line); border-radius: 0;
    box-shadow: var(--shadow); padding-top: 18px;
  }
  body.admin-shell.nav-open .adminNav { transform: translateX(0); }
  body.admin-shell.nav-open #navBackdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 150;
  }

  /* dense tables scroll sideways instead of crushing */
  table:not(.cal) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }

  /* calendar fits a phone */
  table.cal td { height: 56px; font-size: 11px; padding: 2px; }
  table.cal th { font-size: 11px; padding: 2px; }
  .calNum { font-size: 10px; }
  .calEv { font-size: 10px; padding: 1px 3px; }
}

@media (max-width: 760px) { header .who { display: none; } }

/* ===================== Phase 5: accessibility + polish ===================== */
/* troop number renders as a real button styled like a link */
.troopLink {
  background: none; border: 0; padding: 0; margin: 0;
  color: var(--navy); font: inherit; font-weight: 600;
  text-decoration: underline; cursor: pointer;
}
.troopLink:hover { color: var(--gold-text); }

/* honor reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *, .adminNav { transition: none !important; animation: none !important; }
}

/* comfortable tap targets on touch screens */
@media (max-width: 760px) {
  button.small { min-height: 38px; }
  .adminNav button { min-height: 44px; }
}
