:root {
  color-scheme: light;
  --ink: #1b2430;
  --muted: #5c6b7a;
  --line: #d7dee6;
  --card: #ffffff;
  --bg: #f3f5f8;
  --navy: #0c3d6e;
  --navy-2: #164e86;
  --red: #9e1b2e;
  --gold: #b0893e;
  --ok: #1c7a4a;
  --warn: #8a5a12;
  --bad: #8d1d18;
  --shadow: 0 8px 24px rgba(18, 38, 63, 0.08);
  --input: #ffffff;
  --track: #c5ced8;
  --focus: #b0893e;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e7edf4;
  --muted: #b7c3d0;
  --line: #314155;
  --card: #1c2633;
  --bg: #12181f;
  --navy: #8eb4db;
  --navy-2: #d5e4f5;
  --red: #ff8b8b;
  --gold: #e3c27a;
  --ok: #7dcea0;
  --warn: #e3c27a;
  --bad: #ff8b8b;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  --input: #0f141b;
  --track: #3d4c5f;
  --focus: #e3c27a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

.top {
  background: #0c3d6e;
  color: white;
  padding: 0.7rem 1rem 0.75rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 0.7rem;
  align-items: start;
}

html[data-theme="dark"] .top { background: #0a223c; }

.header-bar {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  min-width: 0;
}

.header-tools {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
}

.brand-logo {
  display: block;
  line-height: 0;
  color: white;
  text-decoration: none;
}

.brand-logo img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  background: transparent;
}

.header-main {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 0.65rem;
  row-gap: 0.55rem;
  align-items: center;
}

.brand-copy {
  color: white;
  text-decoration: none;
  min-width: 0;
}

.brand-copy strong { display: block; font-size: 1.15rem; }
.brand-copy small { color: #d5e2f0; }

.operator { text-align: right; }
.operator p, .who { margin: 0; }
.who { font-weight: 700; }
.role-line { color: #d5e2f0; font-size: 0.88rem; }

nav, .header-nav {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-start;
  width: 100%;
  min-width: 0;
}
.header-nav .nav-logout { margin-left: auto; }
nav a, nav a:hover, nav a:focus, nav a:active, nav a:visited, .linkish {
  color: white;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  min-height: 2.2rem;
  display: inline-flex;
  align-items: center;
}
nav a:hover, .linkish:hover { background: rgba(255, 255, 255, 0.12); }
.linkish {
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.debug-flag {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: #3d2a08;
  background: #f6e3b8;
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
}

main, footer {
  width: min(1100px, calc(100% - 1.5rem));
  margin-left: auto;
  margin-right: auto;
}

main { padding-bottom: 2rem; }

.theme-toggle, .status-pill {
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.theme-toggle {
  background: transparent;
  color: #0c3d6e;
  border: 1px solid currentColor;
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 2.5rem;
}
.theme-toggle svg { width: 1.25rem; height: 1.25rem; }
.theme-toggle svg * { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.top .theme-toggle, .login-tools .theme-toggle { color: white; border-color: rgba(255, 255, 255, 0.55); }

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.6rem;
  padding: 0.1rem 0.55rem;
  font-size: 0.78rem;
}

.status-on { background: #1f7a45; color: #fff; }
.status-off { background: #ff5c5c; color: #111; }

.switch {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-align: left;
  background: var(--card);
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  margin-top: 0.7rem;
}

.switch-track {
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: var(--track);
  position: relative;
  flex: 0 0 auto;
}

.switch-knob {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  position: absolute;
  top: 3px;
  left: 3px;
}

.switch[aria-checked="true"] .switch-track { background: #1f7a45; }
.switch[aria-checked="true"] .switch-knob { left: 21px; }
.switch-copy { flex: 1; font-weight: 700; }

.checkin-panel, .compact { max-width: 34rem; }
.section-head { display: flex; justify-content: space-between; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.inline-form, .stack-form { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: end; }
.inline-form input, .stack-form input[name="donation"], .stack-form input[name="reason"] { width: min(100%, 16rem); }
.login-tools { display: flex; justify-content: flex-end; align-items: center; gap: 0.5rem; }
.login-tools .theme-toggle { color: var(--navy); border-color: var(--line); }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, .switch:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  margin-top: 1rem;
}

h1 { margin: 0.2rem 0 0.75rem; font-size: 1.7rem; }
h2 { margin: 0 0 0.55rem; font-size: 1.15rem; }
h3 { margin: 0.2rem 0; font-size: 1rem; }

label { display: block; font-weight: 700; margin-bottom: 0.35rem; }

input[type="text"], input[type="email"], input[name="capid"], input[name="code"], input[name="donation"], input:not([type]), input[type="date"], input[type="datetime-local"], select {
  font-family: inherit;
  font-size: 1.15rem;
  padding: 0.7rem 0.75rem;
  width: min(100%, 22rem);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  color: var(--ink);
  height: 3.2rem;
  min-height: 3.2rem;
  box-sizing: border-box;
}

input[type="date"], input[type="datetime-local"] {
  color-scheme: inherit;
}

.member-field {
  position: relative;
  width: min(100%, 22rem);
}

.member-field input {
  width: 100%;
}

.member-suggestions {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 0.25rem);
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 16rem;
  overflow-x: hidden;
  overflow-y: auto;
}

.member-suggestions [role="option"] {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  width: 100%;
  margin: 0;
  padding: 0.45rem 0.55rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  min-height: 2.5rem;
}

.member-suggestions [role="option"][aria-selected="true"],
.member-suggestions [role="option"]:hover {
  background: color-mix(in srgb, var(--navy) 18%, var(--card));
}

.member-capid {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.member-rank {
  color: var(--muted);
  flex: 0 0 auto;
}

.member-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.member-empty {
  cursor: default;
  color: var(--muted);
}

.member-suggestions [role="option"]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -2px;
}

.app-dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem;
  width: min(28rem, calc(100vw - 1.5rem));
  max-width: calc(100vw - 1.5rem);
}

.app-dialog::backdrop {
  background: rgba(12, 24, 40, 0.55);
}

.app-dialog h2 {
  margin-top: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

button, .button {
  font-size: 1rem;
  padding: 0.75rem 1.1rem;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  min-height: 3rem;
}

.primary { background: #0c3d6e; color: #fff; }
.primary:hover, .primary:focus { background: #164e86; color: #fff; }
.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.secondary:hover, .secondary:focus { background: var(--bg); color: var(--ink); }
a.button:any-link,
a.button:hover,
a.button:focus,
a.button:focus-visible,
a.button:active,
a.button:visited {
  text-decoration: none;
}
a.button.primary:any-link,
a.button.primary:hover,
a.button.primary:focus,
a.button.primary:active,
a.button.primary:visited {
  color: #fff;
}
.danger, a.button.danger, a.button.danger:visited, button.danger { background: #9e1b2e; color: #fff; }
.danger:hover, a.button.danger:hover, button.danger:hover { background: #7d1524; color: #fff; }
button:disabled, button[disabled] { opacity: 0.62; cursor: not-allowed; color: #fff; }
html[data-theme="dark"] .primary { background: #2c6ca3; color: #fff; }
html[data-theme="dark"] .primary:hover, html[data-theme="dark"] .primary:focus { background: #3d82be; color: #fff; }
html[data-theme="dark"] .checkin:hover, html[data-theme="dark"] .checkout:hover,
html[data-theme="dark"] .danger:hover { color: #fff; filter: brightness(1.12); }
html[data-theme="dark"] button:disabled { color: #d5deea; background: #314155; }
.action-row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.page-title { padding: 0.75rem 1.1rem; }
.page-title h1 { margin: 0; font-size: 1.35rem; }
.current-event-kicker {
  margin: 0 0 0.3rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.current-event-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
.current-event-row h2 { margin: 0; font-size: 1.3rem; }
.current-event-dates { margin: 0.35rem 0 0; color: var(--muted); }
.event-status {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  white-space: nowrap;
}
.event-status-active { color: #1c7a45; }
html[data-theme="dark"] .event-status-active { color: #7dcea0; }
.event-status-created, .event-status-closed { color: var(--muted); }
.event-status-pending_closure { color: var(--warn); }
.status-check { width: 1.05rem; height: 1.05rem; flex: 0 0 auto; }
.status-check circle { fill: currentColor; }
.status-check path { fill: none; stroke: #fff; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.event-card, .admin-event { display: grid; gap: 0.75rem; }
.event-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
  margin-top: 0.75rem;
}
.event-card.is-selected { box-shadow: inset 3px 0 0 #0c3d6e; }
html[data-theme="dark"] .event-card.is-selected { box-shadow: inset 3px 0 0 var(--gold); }
.event-summary { display: flex; flex-wrap: wrap; gap: 0.35rem 0.75rem; align-items: center; }
.event-summary h2, .event-summary h3, .event-summary p { margin: 0; }
.event-summary h3 { flex: 1 1 12rem; }
.status-quiet { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.selected-flag {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.5rem;
  border: 1px solid var(--gold);
  border-radius: 999px;
  background: color-mix(in srgb, var(--gold) 18%, var(--card));
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 650;
  line-height: 1.35;
  vertical-align: middle;
}
.header-nav a.nav-super,
.header-nav a.nav-super:hover,
.header-nav a.nav-super:focus,
.header-nav a.nav-super:visited {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-color: var(--gold);
  color: var(--gold);
}
.nav-shield { display: block; flex: 0 0 auto; }
.lookup > button { margin-top: 0.45rem; }
.routine-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.consequential-actions { display: grid; gap: 0.55rem; border-top: 1px solid var(--line); padding-top: 0.7rem; }
.confirm-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 11.5rem;
  gap: 0.75rem;
  align-items: center;
}
.confirm-line .check-label { margin: 0; }
.confirm-line button {
  width: 100%;
  min-height: 3rem;
  margin: 0;
}
.reopen-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.reopen-form input { width: min(100%, 16rem); }
.count-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.5rem; margin: 0; }
.count-grid div { background: var(--bg); border-radius: 8px; padding: 0.55rem 0.7rem; }
.count-grid dt { color: var(--muted); font-size: 0.78rem; }
.count-grid dd { margin: 0; font-weight: 700; font-size: 1.05rem; }
.purge-panel { border-top: 1px solid var(--line); padding-top: 0.75rem; }
.purge-panel h3 { margin: 0 0 0.35rem; }
.purge-form { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; }
.purge-form input { width: min(100%, 12rem); }
details.create-event > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  font-size: 1.15rem;
  font-weight: 700;
  list-style: none;
}
details.create-event > summary::-webkit-details-marker { display: none; }
details.create-event > summary::marker { content: ""; }
details.create-event > summary::after {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  flex: 0 0 auto;
  margin-top: -0.2rem;
}
details.create-event[open] > summary::after {
  transform: rotate(225deg);
  margin-top: 0.25rem;
}
.checkin { background: #1c7a4a; color: white; }
.checkout { background: #9e1b2e; color: white; }

.lookup, .donation-form, .stack-form {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.55rem;
}

.stack-form { margin-top: 1rem; padding-top: 0.8rem; border-top: 1px solid var(--line); }
.check-label {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin: 0.85rem 0;
  font-weight: 400;
  cursor: pointer;
}
.check-label input {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  flex: 0 0 auto;
}

.field-error {
  margin: 0;
  color: var(--bad);
  font-size: 0.92rem;
  font-weight: 700;
}
.login-note {
  margin: 0 0 0.8rem;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: left;
}
.login-resend-label {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.login-start .primary { margin-top: 0.45rem; }
.login-resend {
  margin-top: 0.85rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.warning-card { border-top: 4px solid var(--gold); }
.status-in { border-top: 4px solid var(--ok); }
.status-out { border-top: 4px solid var(--navy); }
.note { background: color-mix(in srgb, var(--gold) 18%, var(--card)); color: var(--ink); padding: 0.7rem 0.8rem; border-radius: 8px; }
.hint, .eyebrow { color: var(--muted); }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.78rem; }

body:has(.login-panel) main {
  width: min(460px, calc(100% - 1.5rem));
  min-height: calc(100vh - 5rem);
  display: flex;
  align-items: center;
}

.login-panel { text-align: center; }
.login-column {
  width: min(100%, 380px);
  margin: 0 auto;
}
.login-panel form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
  text-align: left;
  width: 100%;
  margin: 0 auto 0.8rem;
}
.login-panel form input,
.login-panel form button {
  width: 100%;
  box-sizing: border-box;
}
.login-panel form input[type="text"],
.login-panel form input[type="email"],
.login-panel form input:not([type]) {
  height: 3.2rem;
  min-height: 3.2rem;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  color: var(--ink);
  font-family: inherit;
  font-size: 1.15rem;
}
.login-panel .debug-flag { margin-left: auto; margin-right: auto; }
.login-panel h1 { margin-top: 0.2rem; }
.brand-mark { margin: 0; }
.brand-mark img {
  width: min(220px, 68vw);
  height: auto;
  background: transparent;
}
.login-panel .debug-flag { display: inline-block; margin-top: 0.8rem; }

.capid { font-size: 1.35rem; font-weight: 700; letter-spacing: 0.04em; margin-top: 0; }

.identity { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.75rem; margin: 0; }
.identity div { margin: 0; }
.identity dt { font-size: 0.78rem; color: var(--muted); }
.identity dd { margin: 0; font-weight: 700; }

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin: 0.5rem 0 0;
}
.summary div {
  background: var(--bg);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}
.summary span { display: block; color: var(--muted); font-size: 0.78rem; }
.summary strong { font-size: 1.05rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); padding: 0.55rem 0.45rem; }
th { background: color-mix(in srgb, var(--card) 70%, var(--bg)); font-size: 0.82rem; }

.badge { display: inline-block; padding: 0.12rem 0.45rem; border-radius: 999px; font-size: 0.8rem; background: var(--bg); color: var(--ink); }
.badge-open { background: #e5f6ea; color: #143322; }
.badge-voided { background: #fde8e6; color: #4a1210; }
.badge-corrected { background: #fff4d6; color: #3d2a08; }
.badge-completed { background: #e7eef5; color: #10233c; }
.row-void { background: #fff6f5; }
.row-open { background: #f4fbf6; }
.row-corrected { background: #fffaf0; }

details.unit { border-top: 1px solid var(--line); padding: 0.15rem 0; }
details.unit > summary {
  cursor: pointer;
  display: grid;
  grid-template-columns: 2fr 1.1fr 0.8fr 0.9fr 0.9fr;
  gap: 0.5rem;
  align-items: center;
  font-weight: 700;
  padding: 0.7rem 0.2rem;
  min-height: 3rem;
}
.unit-body { padding: 0.2rem 0 0.9rem 0.4rem; }
.money-note { color: var(--muted); font-weight: 400; }

@media (max-width: 800px) {
  .member-field { width: 100%; }
  .header-main { display: flex; flex-direction: column; align-items: stretch; }
  .header-bar, .header-tools, .operator, nav { align-items: flex-start; text-align: left; justify-content: flex-start; }
  .header-tools { align-self: flex-end; }
  .header-nav .nav-logout { margin-left: 0; }
  .current-event-row { flex-wrap: wrap; align-items: flex-start; }
  details.unit > summary { grid-template-columns: 1fr 1fr; }
  .count-grid { grid-template-columns: 1fr 1fr; }
  .confirm-line { grid-template-columns: minmax(0, 1fr); }
  .confirm-line button { width: 100%; }
  table { display: block; overflow-x: auto; }
  input[type="text"], input[type="email"], input[name="capid"], input[name="code"], input[name="donation"], input[type="date"], input[type="datetime-local"], select, button:not(.theme-toggle):not(.linkish), .button {
    width: 100%;
  }
  .action-row > button, .action-row > a.button { width: auto; flex: 1 1 11rem; }
}

@media print {
  body { background: #fff; color: #10233c; }
  .top, nav, .event-select, .theme-toggle, .no-print, .debug-pill { display: none !important; }
  .card, .report-sheet { box-shadow: none; border: 0; color: #10233c; background: #fff; }
  a { color: #10233c; text-decoration: none; }
}
