:root {
  --ink: #2A2F26;
  --sage-900: #3E4438;
  --sage-600: #6B7261;
  --sage-400: #8B9379;
  --sage-300: #A9B29A;
  --sage-100: #E4E7DD;
  --cream: #F7F3F0;
  --paper: #FFFFFF;
  --amber: #B98A3E;
  --amber-tint: #F3E6D0;
  --border: #EAE4D9;
  --dim: #8A8A7C;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--cream);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }
a { color: inherit; }

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--cream);
}

.topbar {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; z-index: 10;
  background: var(--cream);
  padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.wordmark { display: flex; align-items: center; gap: 7px; font-family: Georgia, "Iowan Old Style", ui-serif, serif; font-size: 18px; color: var(--sage-900); }
.wordmark-icon { width: 24px; height: 24px; border-radius: 50%; flex: none; }
.topbar .sub { font-size: 11.5px; color: var(--sage-600); font-weight: 600; }
.topbar .back {
  font-size: 13px; font-weight: 700; color: var(--sage-600); background: none; border: none;
  padding: 4px 0; cursor: pointer;
}

.content {
  flex: 1;
  padding: calc(var(--topbar-h, 60px) + 2px) 18px calc(var(--tabbar-h, 70px) + 24px);
}

.section-label {
  font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--sage-600); font-weight: 700; margin: 18px 0 8px;
}
.section-label:first-child { margin-top: 4px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-card { background: var(--paper); border-radius: 14px; padding: 12px 13px; border: 1px solid var(--border); }
.stat-num { font-size: 22px; font-weight: 700; color: var(--sage-900); font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat-lbl { font-size: 10.5px; color: var(--dim); margin-top: 2px; }

.event-card { background: var(--sage-900); color: var(--cream); border-radius: 16px; padding: 14px 16px; }
.event-card .tag { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; color: #C9CFB8; margin-bottom: 5px; }
.event-card .name { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.event-card .meta { font-size: 12px; color: #D8DBC9; margin-bottom: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 999px; font-weight: 700; font-size: 13.5px;
  padding: 11px 18px; cursor: pointer; font-family: inherit;
}
.btn-cream { background: var(--cream); color: var(--sage-900); width: 100%; }
.btn-sage { background: var(--sage-600); color: #fff; width: 100%; }
.btn-sage:disabled { opacity: .5; }
.btn-ghost { width: 100%; background: transparent; border: 1.5px dashed var(--sage-400); color: var(--sage-900); }
.btn-outline { background: var(--paper); border: 1px solid var(--border); color: var(--sage-900); }
.btn-block { width: 100%; }
.btn-danger { background: transparent; color: #A6543C; }

.card { background: var(--paper); border-radius: 14px; padding: 12px 13px; border: 1px solid var(--border); }

.person-row, .list-row {
  display: flex; align-items: center; gap: 10px; padding: 11px 2px;
  border-bottom: 1px solid var(--border);
}
.person-row:last-child, .list-row:last-child { border-bottom: none; }
.person-row { cursor: pointer; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 700; color: #fff; background: var(--sage-400);
}
.p-info { flex: 1; min-width: 0; }
.p-name { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.p-sub { font-size: 11.5px; color: var(--dim); margin-top: 1px; }

.pill {
  font-size: 9.5px; letter-spacing: .04em; text-transform: uppercase; font-weight: 700;
  padding: 2.5px 7px; border-radius: 999px; background: var(--sage-100); color: var(--sage-900);
  white-space: nowrap;
}
.pill.pending { background: var(--amber-tint); color: var(--amber); }
.pill.member { background: var(--sage-600); color: #fff; }
.pill.regular { background: var(--sage-100); color: var(--sage-900); }
.pill.once { background: var(--cream); color: var(--ink); border: 1px solid var(--border); }
.pill.new { background: transparent; color: var(--dim); font-style: italic; }
.pill.warn { background: #F3DED8; color: #A6543C; }

.checkmark {
  width: 27px; height: 27px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #D6D0C2; background: none; cursor: pointer; padding: 0;
}
.checkmark.done { background: var(--sage-600); border-color: var(--sage-600); }
.checkmark svg { width: 14px; height: 14px; }

.remove-btn {
  width: 27px; height: 27px; border-radius: 50%; flex: none; margin-left: 6px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: none; cursor: pointer; padding: 0; color: #A6543C;
}
.remove-btn svg { width: 14px; height: 14px; }

.progress-wrap { margin: 2px 0 12px; }
.progress-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.progress-head b { color: var(--sage-900); }
.progress-track { height: 7px; border-radius: 99px; background: #E7E1D4; overflow: hidden; }
.progress-fill { height: 100%; background: var(--sage-600); border-radius: 99px; transition: width .25s ease; }

.search {
  display: flex; align-items: center; gap: 8px; background: var(--paper);
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px;
  color: var(--dim); font-size: 13px;
}
.search input { border: none; outline: none; background: none; flex: 1; font-size: 13.5px; color: var(--ink); font-family: inherit; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11.5px; font-weight: 700; color: var(--sage-900); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.field input, .field select, .field textarea {
  width: 100%; min-width: 0; max-width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font-size: 15px; font-family: inherit; color: var(--ink); background: var(--paper);
}
/* iOS Safari's native date/time controls size themselves off their OS
   chrome rendering and largely ignore width/min-width on the box - turning
   that native appearance off is the fix that actually sticks. */
.field input[type="date"], .field input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
}
.field textarea { resize: vertical; min-height: 64px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }

.empty { text-align: center; color: var(--dim); font-size: 13px; padding: 40px 20px; }

.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; z-index: 10;
  display: flex; border-top: 1px solid var(--border); background: var(--paper);
  padding: 8px 4px max(10px, env(safe-area-inset-bottom));
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 9.5px; font-weight: 700; color: var(--sage-900); background: none; border: none; cursor: pointer;
  padding: 4px 0;
}
.tab.active { color: var(--sage-400); font-weight: 500; }
.tab svg { width: 20px; height: 20px; }

.spark-card .spark-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.spark-card .t { font-size: 12px; font-weight: 700; color: var(--sage-900); }
.spark-card .v { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(10px);
  background: var(--sage-900); color: var(--cream); font-size: 13px; font-weight: 600;
  padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 50; max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.table-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }

.login-wrap {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; background: var(--sage-900);
}
.login-card { background: var(--cream); border-radius: 20px; padding: 32px 26px; width: 100%; max-width: 340px; }
.login-mark { display: block; width: 84px; height: 84px; margin: 0 auto 18px; }
.login-card h1 { font-family: Georgia, "Iowan Old Style", ui-serif, serif; font-weight: 400; font-size: 22px; text-align: center; margin: 0 0 4px; }
.login-card p { text-align: center; color: var(--dim); font-size: 13px; margin: 0 0 22px; }
.login-error { color: #A6543C; font-size: 12.5px; text-align: center; margin-top: 10px; min-height: 16px; }

.fab-row { margin: 16px 0 4px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(62, 68, 56, .55);
  display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 100;
}
.modal-card { background: var(--cream); border-radius: 18px; padding: 22px; width: 100%; max-width: 340px; }
.modal-message { font-size: 14.5px; color: var(--sage-900); line-height: 1.5; margin: 0 0 20px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; width: auto; }
.btn-modal-danger { background: #A6543C; color: #fff; }

.scan-overlay { position: fixed; inset: 0; background: #000; z-index: 200; overflow: hidden; }
.scan-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.scan-frame {
  position: absolute; top: 42%; left: 50%; transform: translate(-50%, -50%);
  width: 68vw; max-width: 260px; aspect-ratio: 1;
  border: 3px solid rgba(255,255,255,.9); border-radius: 18px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,.4); pointer-events: none;
}
.scan-header {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
}
.scan-title { color: #fff; font-weight: 700; font-size: 14px; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.scan-close-btn {
  background: rgba(0,0,0,.5); color: #fff; border: none; border-radius: 20px;
  width: 40px; height: 40px; font-size: 22px; line-height: 1; cursor: pointer;
}
.scan-result {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 2;
  padding: 26px 16px calc(26px + env(safe-area-inset-bottom));
  text-align: center; font-weight: 700; font-size: 21px; line-height: 1.3; color: #fff;
}
.scan-result.ok { background: rgba(139, 147, 121, .95); }
.scan-result.already { background: rgba(184, 148, 76, .95); }
.scan-result.error { background: rgba(166, 84, 60, .95); }

.text-right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }

/* Desktop: the mobile bottom tab bar becomes a full-height left sidebar,
   the topbar spans the remaining width instead of a centered 480px strip,
   and content gets real breathing room instead of a narrow phone-width
   column floating in the middle of the browser window. */
@media (min-width: 860px) {
  body { background: var(--sage-100); }

  .app-shell { max-width: none; margin: 0; }

  .tabbar {
    top: 0; bottom: 0; left: 0; right: auto; transform: none;
    width: 224px; max-width: none; height: 100vh;
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    gap: 2px; padding: 22px 12px; border-top: none; border-right: 1px solid var(--border);
  }
  .tab {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 11px 14px; border-radius: 10px; font-size: 13.5px;
  }
  .tab:hover { background: var(--sage-100); }
  .tab.active { background: var(--sage-100); }
  .tab svg { width: 19px; height: 19px; flex: none; }

  .topbar {
    left: 224px; right: 0; transform: none; width: auto; max-width: none;
    padding: 20px 32px 16px;
  }

  .content {
    margin-left: 224px;
    max-width: 760px;
    padding: calc(var(--topbar-h, 76px) + 12px) 32px 40px;
  }

  .table-scroll { margin: 0 -32px; padding: 0 32px; }

  .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
}
