:root {
  --bg: #f8faf4;
  --panel: #ffffff;
  --ink: #1f261f;
  --muted: #647064;
  --line: #dde5d4;
  --green: #168645;
  --leaf: #8cc918;
  --brown: #907b65;
  --gold: #b9985d;
  --danger: #b43c32;
  --warn: #b37b17;
  --blue: #33658a;
  --shadow: 0 18px 50px rgba(33, 45, 30, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.shell { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 22px; background: rgba(248, 250, 244, .9); backdrop-filter: blur(16px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 230px; color: inherit; text-decoration: none; }
.brand img { width: 42px; height: 42px; object-fit: contain; }
.brand-title { font-weight: 800; letter-spacing: .02em; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tab { border: 1px solid transparent; background: transparent; color: var(--muted); padding: 8px 12px; border-radius: 999px; font-size: 14px; text-decoration: none; }
.tab.active { background: #eaf3e4; color: #174c2a; border-color: #cfe1c5; }

.container { max-width: 1220px; margin: 0 auto; padding: 22px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(280px, .9fr) minmax(320px, 1.1fr); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; } .topbar { align-items: flex-start; flex-direction: column; } .tabs { justify-content: flex-start; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 18px; }
.section-title { margin: 0 0 4px; font-size: 22px; letter-spacing: .01em; }
.section-subtitle { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn { border: 1px solid var(--line); background: white; color: var(--ink); border-radius: 8px; padding: 9px 13px; font-weight: 700; font-size: 14px; }
.btn.primary { background: var(--green); border-color: var(--green); color: white; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: white; }
.btn.warn { background: #fff8e9; border-color: #eed7a8; color: #714c0d; }
.btn.danger { background: #fff1ef; border-color: #efc7c2; color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { color: var(--muted); font-size: 13px; font-weight: 700; }
.input, .select, .textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); padding: 10px 11px; outline: none; }
.input.compact, .select.compact { min-width: 128px; padding: 7px 9px; font-size: 13px; }
.textarea { min-height: 82px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 134, 69, .12); }

.stat { padding: 16px; border-radius: 8px; background: linear-gradient(180deg, #fff, #f7faf4); border: 1px solid var(--line); }
.stat-value { font-size: 28px; font-weight: 850; color: var(--green); }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 4px; }

.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge.active { background: #e6f5e9; color: #11612f; }
.badge.expiring { background: #fff4cf; color: #805500; }
.badge.expired { background: #ffe5df; color: #9b2d22; }
.badge.none { background: #edf0ed; color: #5d665d; }
.badge.role { background: #f1eadf; color: #70573a; }
.badge.web { background: #e5f0f7; color: #255875; }

.member-card { position: relative; overflow: hidden; aspect-ratio: 1.6 / 1; min-height: 210px; border-radius: 8px; padding: 22px; background: linear-gradient(135deg, #fbfff7 0%, #eff7ea 55%, #f8f3e9 100%); border: 1px solid #d7e7ce; box-shadow: var(--shadow); }
.member-card::before { content: ""; position: absolute; width: 330px; height: 330px; border-radius: 50%; border: 32px solid rgba(140, 201, 24, .28); right: -110px; top: -90px; }
.member-card::after { content: ""; position: absolute; width: 360px; height: 360px; border-radius: 50%; border: 26px solid rgba(22, 134, 69, .16); left: -160px; bottom: -210px; }
.card-logo { position: absolute; right: 30px; bottom: 28px; width: 110px; opacity: .86; }
.card-content { position: relative; z-index: 1; display: grid; height: 100%; }
.card-kicker { color: var(--green); font-size: 13px; font-weight: 800; letter-spacing: .04em; }
.card-name { align-self: end; font-size: clamp(28px, 5vw, 42px); font-weight: 900; color: #2c342c; }
.card-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.formal-card { background: #fbfff1; box-shadow: 0 18px 60px rgba(42, 50, 35, .16); min-height: 300px; max-width: 640px; padding: 24px 32px; }
.formal-card::before, .formal-card::after { display: none; }
.formal-card-top { position: relative; z-index: 2; display: flex; justify-content: space-between; gap: 20px; }
.formal-org { color: #806d5a; font-size: clamp(22px, 4vw, 37px); font-weight: 900; font-family: Georgia, "Noto Serif TC", serif; line-height: 1.15; }
.formal-sub { color: #466d55; font-weight: 800; margin-top: 4px; }
.formal-sub span { font-weight: 500; }
.formal-id { color: #466d55; text-align: right; font-weight: 800; line-height: 1.45; min-width: 120px; }
.formal-id strong { font-size: 18px; }
.formal-name { position: relative; z-index: 2; margin-top: 10px; color: #466d55; font-size: clamp(32px, 7vw, 48px); font-weight: 950; line-height: 1.1; }
.formal-tags { position: relative; z-index: 3; display: flex; gap: 7px; flex-wrap: wrap; max-width: 70%; margin-top: 12px; }
.formal-logo { position: absolute; z-index: 2; right: 60px; top: 108px; width: min(22vw, 150px); mix-blend-mode: multiply; }
.formal-expiry { position: absolute; z-index: 2; left: 38px; bottom: 30px; color: #14205a; font-size: 16px; line-height: 1.8; }
.formal-expiry span { color: #1f261f; font-size: 12px; font-weight: 700; }
.card-arcs { position: absolute; pointer-events: none; border-radius: 50%; }
.card-arcs-left { left: -210px; bottom: -220px; width: 460px; height: 460px; border: 2px solid rgba(69, 113, 116, .7); box-shadow: 35px -22px 0 -33px rgba(69, 113, 116, .7), 65px -48px 0 -63px rgba(69, 113, 116, .7), 92px -75px 0 -90px rgba(69, 113, 116, .7); }
.card-arcs-right { right: -125px; top: -205px; width: 430px; height: 430px; border: 58px solid rgba(174, 185, 167, .95); box-shadow: -70px 0 0 0 rgba(193, 152, 85, .95); }
.qr-row { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; margin-top: 14px; }
.qr-box { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: inline-grid; place-items: center; }
.qr-box canvas, .qr-box img { width: 150px !important; height: 150px !important; }
.small { font-size: 12px; color: var(--muted); line-height: 1.6; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: white; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #edf1e8; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 800; background: #f7faf4; }
tr:last-child td { border-bottom: 0; }

.signature-wrap { border: 1.5px dashed #cbd9c2; border-radius: 8px; background: #fff; padding: 8px; position: relative; }
.signature-pad { display: block; width: 100%; height: 210px; border-radius: 8px; background: #fff; touch-action: none; overscroll-behavior: contain; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.signature-hint { position: absolute; left: 18px; right: 18px; bottom: 38px; text-align: center; color: #b8c4b0; pointer-events: none; letter-spacing: .25em; font-size: 13px; }
.receipt-preview { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 22px; line-height: 1.8; }
.receipt-signature { height: 78px; object-fit: contain; object-position: left center; max-width: 220px; border-bottom: 1px solid #cfd8c8; }
.event-box { border: 1px solid var(--line); background: #fbfdf8; border-radius: 8px; padding: 14px; }
.event-box h3 { margin: 0 0 4px; }
.stamp-admin { display: grid; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fbfdf8; }
.stamp-preview { width: 92px; height: 92px; object-fit: contain; border: 1px solid #eadfcf; border-radius: 8px; background: white; padding: 6px; }
.manage-row td { background: #fbfdf8; }
.document-preview { margin-top: 16px; border-color: var(--gold); }
.print-surface { background: #fff; color: #111; padding: 24px; border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.print-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; border-bottom: 2px solid #d8d1c5; padding-bottom: 12px; }
.print-heading img { width: 58px; height: 58px; object-fit: contain; }
.print-heading h1 { margin: 0; color: #806d5a; font-size: 24px; font-family: Georgia, "Noto Serif TC", serif; }
.print-heading h2 { margin: 4px 0 0; color: #1f261f; font-size: 18px; }
.event-info { margin-bottom: 16px; border: 1px solid #ccc; }
.onsite-panel { position: sticky; bottom: 18px; z-index: 30; border-color: #b9985d; box-shadow: 0 24px 70px rgba(50, 42, 25, .24); }
.checkin-signature-slot { margin-top: 10px; }
.auth-panel, .receipt-public { max-width: 760px; margin: 0 auto; }
.scanner-video { width: 100%; aspect-ratio: 4 / 3; background: #1f261f; border-radius: 8px; object-fit: cover; }
.toggle-line { display: flex; align-items: center; gap: 8px; min-height: 42px; border: 1px solid var(--line); background: #fbfdf8; border-radius: 8px; padding: 10px 12px; font-size: 14px; font-weight: 700; color: var(--muted); }
.toggle-line input { width: 18px; height: 18px; accent-color: var(--green); }
.span-2 { grid-column: span 2; }
.receipt-print { background: #fff; color: #111; line-height: 1.8; }
.receipt-print table { margin-top: 16px; border: 1px solid #ccc; }
.receipt-print th { width: 120px; color: #333; background: #f5f5f5; border: 1px solid #ccc; }
.receipt-print td { border: 1px solid #ccc; }
.receipt-signature.large { height: 120px; max-width: 320px; }
.approval-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 36px; }
.approval-row > div { min-height: 100px; border-top: 1px solid #222; padding-top: 8px; text-align: center; position: relative; }
.stamp-text { display: inline-grid; place-items: center; width: 74px; height: 74px; border: 3px solid #b43c32; color: #b43c32; border-radius: 50%; margin-top: 8px; font-weight: 900; transform: rotate(-8deg); }
.stamp-image { display: block; width: 86px; height: 86px; object-fit: contain; margin: 8px auto 0; mix-blend-mode: multiply; }
code { color: #255875; background: #eef5f8; border: 1px solid #d9e8ef; border-radius: 6px; padding: 2px 5px; white-space: normal; overflow-wrap: anywhere; }
@media (max-width: 620px) { .formal-card { padding: 18px; min-height: 250px; } .formal-logo { right: 24px; top: 120px; width: 105px; } .formal-tags { max-width: 100%; } .span-2 { grid-column: span 1; } }

.notice { padding: 12px 14px; background: #fff8e8; border: 1px solid #ecd39e; color: #65450e; border-radius: 8px; font-size: 14px; line-height: 1.65; }
.success { padding: 12px 14px; background: #e7f6eb; border: 1px solid #c3e5cb; color: #0f5f2f; border-radius: 8px; font-size: 14px; line-height: 1.65; }
.danger-box { padding: 12px 14px; background: #fff1ef; border: 1px solid #efc7c2; color: #8c2b22; border-radius: 8px; font-size: 14px; line-height: 1.65; }

@media print {
  body { background: #fff; }
  body * { visibility: hidden; }
  .print-surface, .print-surface * { visibility: visible; }
  .print-surface { position: absolute; left: 0; top: 0; width: 100%; border: 0; border-radius: 0; padding: 0; overflow: visible; }
  .print-page { page-break-after: always; }
}
