:root {
  --bg: #f4f6fa; --card: #ffffff; --text: #1a2233; --muted: #6b7280; --line: #e3e7ee;
  --primary: #1f5eff; --primary-dark: #1848c7; --success: #15803d; --success-bg: #dcfce7;
  --warn: #b45309; --warn-bg: #fef3c7; --danger: #b91c1c; --danger-bg: #fee2e2;
  --radius: 12px; --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Helvetica Neue", Arial, sans-serif; font-size: 16px; -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.right { margin-left: auto; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; }
.center { text-align: center; }

/* ---------- 頂欄 */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); padding: .6rem 1rem; display: flex; align-items: center; gap: .8rem; position: sticky; top: 0; z-index: 20; }
.topbar .brand { font-weight: 800; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.topbar .brand .badge { font-size: .7rem; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a, .topbar nav button { white-space: nowrap; padding: .45rem .8rem; border-radius: 8px; border: 0; background: transparent; color: var(--text); font-weight: 600; }
.topbar nav a.active, .topbar nav button.active { background: #e8efff; color: var(--primary); }
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef1f6; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.primary { background: #e8efff; color: var(--primary); }

/* ---------- 版面 */
.page { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.page.narrow { max-width: 520px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

/* ---------- 表單 */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
.field label { font-weight: 600; font-size: .9rem; }
.field .hint { font-size: .8rem; color: var(--muted); }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=search], input[type=datetime-local], input[type=number], select, textarea {
  width: 100%; padding: .65rem .8rem; border: 1px solid #cfd6e2; border-radius: 10px; background: #fff; font-size: 1rem; min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b8caff; border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: 22px; height: 22px; }

/* ---------- 按鈕 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .65rem 1.1rem; border-radius: 10px; border: 1px solid #cfd6e2; background: #fff; font-weight: 600; min-height: 46px; transition: background .15s; white-space: nowrap; }
.btn:hover { background: #f5f7fb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { background: #fff; border-color: #f3b4b4; color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.sm { padding: .4rem .7rem; min-height: 36px; font-size: .9rem; border-radius: 8px; }
.btn.lg { padding: .9rem 1.4rem; font-size: 1.1rem; }
.btn.block { width: 100%; }
.btn.icon { padding: .5rem; min-width: 46px; }
.btn.active { background: #e8efff; border-color: var(--primary); color: var(--primary); }

/* ---------- 登入 */
.login-wrap { min-height: calc(100vh - 60px); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 420px; }
.captcha-row { display: flex; gap: .5rem; align-items: center; }
.captcha-row .img { border-radius: 8px; overflow: hidden; border: 1px solid var(--line); cursor: pointer; flex: 0 0 auto; line-height: 0; }
.captcha-row .img svg { display: block; width: 150px; height: 50px; }
.error { background: var(--danger-bg); color: var(--danger); padding: .6rem .8rem; border-radius: 8px; margin-bottom: .8rem; font-size: .92rem; }
.notice { background: var(--warn-bg); color: var(--warn); padding: .6rem .8rem; border-radius: 8px; margin-bottom: .8rem; font-size: .92rem; }

/* ---------- 活動標頭（前台） */
.event-head { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.event-head .logo { width: 84px; height: 84px; border-radius: 12px; object-fit: contain; background: #fff; border: 1px solid var(--line); flex: 0 0 auto; }
.event-head .logo.placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; }
.event-head .title { font-size: 1.45rem; font-weight: 800; line-height: 1.2; }
.event-head .meta { color: var(--muted); font-size: .92rem; margin-top: .25rem; display: flex; gap: .4rem 1rem; flex-wrap: wrap; }
.event-head .status { text-align: right; min-width: 160px; }
.event-head .status .count { font-size: 2rem; font-weight: 800; line-height: 1; }
.event-head .status .count small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.progress { height: 8px; background: #e8ecf3; border-radius: 999px; overflow: hidden; margin-top: .4rem; }
.progress > div { height: 100%; background: var(--success); border-radius: 999px; transition: width .3s; }

/* ---------- 標籤頁 */
.tabs { display: flex; gap: .3rem; background: #e8ecf3; padding: .3rem; border-radius: 12px; margin-bottom: 1rem; }
.tabs button { flex: 1; padding: .7rem .5rem; border: 0; border-radius: 9px; background: transparent; font-weight: 700; font-size: 1rem; color: var(--muted); }
.tabs button.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.subtabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.subtabs button { padding: .6rem .9rem; border: 0; background: transparent; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.subtabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- 搜尋列 */
.searchbar { display: flex; gap: .5rem; align-items: center; margin-bottom: .8rem; flex-wrap: wrap; }
.searchbar .search { flex: 1 1 240px; position: relative; }
.searchbar .search input { padding-left: 2.4rem; padding-right: 2.6rem; }
.searchbar .search .ico { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.searchbar .search .clear { position: absolute; right: .4rem; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; padding: .3rem .5rem; }
.mic.listening { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(185, 28, 28, .35); } 100% { box-shadow: 0 0 0 10px rgba(185, 28, 28, 0); } }
.view-toggle { display: inline-flex; border: 1px solid #cfd6e2; border-radius: 10px; overflow: hidden; }
.view-toggle button { border: 0; background: #fff; padding: .55rem .8rem; min-height: 46px; font-weight: 600; color: var(--muted); }
.view-toggle button.active { background: #e8efff; color: var(--primary); }

/* ---------- 組別 chips */
.chips { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip { border: 1px solid #cfd6e2; background: #fff; border-radius: 999px; padding: .5rem .9rem; font-weight: 600; display: inline-flex; gap: .4rem; align-items: center; min-height: 42px; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .n { font-size: .8rem; opacity: .8; }
.actionbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding: .7rem; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; margin-bottom: .8rem; position: sticky; top: 58px; z-index: 10; }

/* ---------- 參與者 方塊 / 列表 */
.people.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .7rem; }
.people.list { display: flex; flex-direction: column; gap: .4rem; }
.person { background: #fff; border: 1.5px solid var(--line); border-radius: 12px; padding: .8rem .9rem; cursor: pointer; display: flex; gap: .7rem; align-items: center; position: relative; -webkit-user-select: none; user-select: none; transition: border-color .15s, background .15s; }
.person:active { background: #f5f7fb; }
.person.checked { background: #f6fbf7; border-color: #bfe6cb; }
.person.checked .name { color: #35543c; }
.person.selected { border-color: var(--primary); box-shadow: 0 0 0 2px #c9d8ff inset; }
.people.cards .person { flex-direction: column; align-items: stretch; min-height: 108px; }
.person .name { font-weight: 700; font-size: 1.1rem; line-height: 1.25; word-break: break-word; }
.person .sub { color: var(--muted); font-size: .82rem; margin-top: .2rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.person .state { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.people.list .person .state { margin-top: 0; margin-left: auto; }
.person .tick { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #cfd6e2; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; flex: 0 0 auto; background: #fff; }
.person.checked .tick { background: var(--success); border-color: var(--success); color: #fff; }
.person .sel { width: 24px; height: 24px; flex: 0 0 auto; }
.people.cards .person .sel { position: absolute; top: .7rem; right: .7rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* ---------- Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; padding: 1.3rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 860px; }
.modal h2 { margin-bottom: 1rem; }
.modal .actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.2rem; }
.modal .actions .btn { flex: 1 1 auto; }
.detail { display: grid; grid-template-columns: 110px 1fr; gap: .45rem .8rem; font-size: 1rem; }
.detail dt { color: var(--muted); font-weight: 600; }
.detail dd { margin: 0; word-break: break-word; }

/* ---------- Toast */
.toast-wrap { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 100; pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: .7rem 1.1rem; border-radius: 10px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); animation: fadein .2s; max-width: 90vw; }
.toast.ok { background: var(--success); } .toast.err { background: var(--danger); }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } }

/* ---------- 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { background: #f8fafc; font-weight: 700; color: #374151; position: sticky; top: 0; }
tr:hover td { background: #fafbfd; }
td.actions { white-space: nowrap; }

/* ---------- Dashboard */
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.stat .label { color: var(--muted); font-size: .85rem; font-weight: 600; }
.stat .value { font-size: 2.2rem; font-weight: 800; line-height: 1.1; margin-top: .2rem; }
.stat.ok .value { color: var(--success); } .stat.warn .value { color: var(--warn); }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 90px; gap: .8rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.bar-row .bar { height: 14px; background: #e8ecf3; border-radius: 999px; overflow: hidden; }
.bar-row .bar > div { height: 100%; background: var(--primary); }
.event-item { display: flex; gap: 1rem; align-items: center; padding: .9rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.event-item .logo { width: 56px; height: 56px; border-radius: 10px; object-fit: contain; border: 1px solid var(--line); background: #fff; }
.event-item .title { font-weight: 700; font-size: 1.05rem; }
.logo-preview { width: 120px; height: 120px; object-fit: contain; border: 1px dashed #cfd6e2; border-radius: 12px; background: #fff; }

@media (max-width: 640px) {
  .page { padding: .7rem; }
  .event-head .title { font-size: 1.2rem; }
  .event-head .status { text-align: left; }
  .actionbar { top: 54px; }
  .detail { grid-template-columns: 90px 1fr; }
  .tabs button { font-size: .92rem; padding: .6rem .3rem; }
}
input[type=search]::-webkit-search-cancel-button, input[type=search]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
