:root {
  --ink: #10201c;
  --muted: #60736b;
  --line: #d8e4de;
  --panel: #ffffff;
  --bg: #f4f7f5;
  --brand: #0b7f68;
  --brand-2: #12342d;
  --mint: #e5f7ef;
  --gold: #f5c75b;
  --danger: #b73535;
  --blue: #315d9f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.login-page, .scanner-login, .ticket-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg, #0f2b26 0%, #f4f7f5 62%);
}
.login-card, .ticket-card {
  width: min(460px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  box-shadow: 0 24px 70px rgba(16, 32, 28, .22);
}
.login-card.scanner { width: min(520px, 100%); }
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 800;
  color: #fff;
}
.brand.compact { color: var(--ink); margin-bottom: 22px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 900;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: var(--brand-2);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.side-nav { display: grid; gap: 8px; }
.side-nav a {
  padding: 11px 12px;
  border-radius: 8px;
  color: #cfe4dd;
}
.side-nav a.active, .side-nav a:hover {
  background: rgba(255,255,255,.12);
  color: #fff;
}
.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 4px;
  color: #cfe4dd;
  font-size: 13px;
}
.main-panel {
  padding: 28px;
  min-width: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 22px;
}
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 28px; margin-bottom: 0; }
h2 { font-size: 20px; margin-bottom: 0; }
.eyeline {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 12px;
  color: var(--brand);
  font-weight: 800;
}
.panel, .event-hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 18px;
}
.panel-head, .event-hero, .hero-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.hero-actions { flex-wrap: wrap; justify-content: flex-end; }
.layout-grid {
  display: grid;
  gap: 18px;
  align-items: start;
}
.layout-grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.layout-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-grid.compact { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.stat-tile {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.stat-tile span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.stat-tile strong { font-size: 28px; }
.stat-tile.accent { border-color: #edd180; background: #fff8de; }

.form-stack { display: grid; gap: 14px; }
.field-row, .filter-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}
.filter-bar {
  grid-template-columns: minmax(220px, 1fr) repeat(3, auto);
  margin-bottom: 14px;
}
label { display: grid; gap: 6px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }
.hint, .cell-sub, small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: #f7faf8; }
.btn.danger { background: #fff0f0; border-color: #efb0b0; color: var(--danger); }
.btn.icon { width: 38px; padding: 0; }
.inline-form { display: inline; }
.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
th, td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  background: var(--mint);
  font-size: 13px;
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  background: #eef3f0;
}
.badge.success { background: #daf5e6; color: #11613b; }
.badge.warning { background: #fff0c2; color: #735000; }
.badge.info { background: #dfeeff; color: #184a84; }
.badge.purple { background: #eadfff; color: #56349a; }
.badge.danger { background: #ffe0df; color: #922b2b; }
.badge.accent { background: #e0f5f0; color: var(--brand); }
.flash {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  background: #eef3f0;
  border: 1px solid var(--line);
}
.flash.success { background: #e1f7eb; border-color: #a9dfc1; }
.flash.warning { background: #fff5d7; border-color: #efd98e; }
.flash.danger { background: #ffe2e2; border-color: #efb0b0; }
.empty {
  color: var(--muted);
  padding: 16px;
  text-align: center;
}
.steps { margin-bottom: 0; line-height: 1.9; }
.inline-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.list-stack {
  display: grid;
  gap: 10px;
}
.rank-row {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}
.rank-row span {
  color: var(--muted);
  font-size: 13px;
}
.pick-list, .recipient-grid {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
}
.pick-row, .recipient-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  font-weight: 500;
}
.pick-row:last-child, .recipient-row:last-child { border-bottom: 0; }
.row-detail { position: relative; }
.row-detail summary { list-style: none; }
.mini-form {
  position: absolute;
  right: 0;
  z-index: 20;
  width: min(360px, 90vw);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(16, 32, 28, .18);
  padding: 12px;
  display: grid;
  gap: 8px;
}

.scanner-shell {
  min-height: 100vh;
  background: #071d19;
  color: #fff;
}
.scanner-top {
  padding: 18px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}
.scanner-top h1 { font-size: 22px; }
.segmented {
  display: inline-flex;
  padding: 4px;
  border-radius: 8px;
  background: rgba(255,255,255,.12);
}
.segmented button {
  border: 0;
  background: transparent;
  color: #dcebe6;
  border-radius: 6px;
  padding: 9px 12px;
  font-weight: 800;
}
.segmented button.active { background: #fff; color: var(--ink); }
.scanner-main { padding: 0 18px 20px; }
.scan-view { display: none; }
.scan-view.active { display: block; }
.camera-shell {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #000;
  aspect-ratio: 4 / 5;
  max-height: 68vh;
}
.camera-shell video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scan-frame {
  position: absolute;
  inset: 18%;
  border: 3px solid var(--gold);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.28);
}
.camera-state {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(0,0,0,.62);
  text-align: center;
}
.manual-scan {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}
.scan-result {
  margin-top: 12px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255,255,255,.1);
  min-height: 52px;
}
.scan-result.success { background: #dff8eb; color: #0f5234; }
.scan-result.danger { background: #ffe2e2; color: #842222; }
.scan-dialog {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  padding: 22px;
  background: rgba(0, 0, 0, .55);
}
.scan-dialog.active {
  display: grid;
}
.scan-dialog-card {
  width: min(420px, 100%);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 24px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}
.scan-dialog-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 36px;
  font-weight: 900;
}
.scan-dialog.danger .scan-dialog-icon {
  background: var(--danger);
}
.scan-dialog-card h2 {
  font-size: 26px;
  margin-bottom: 8px;
}
.scan-dialog-card p {
  color: var(--muted);
  margin-bottom: 14px;
}
.scan-dialog-card dl {
  display: grid;
  gap: 8px;
  margin: 0 0 18px;
  text-align: left;
}
.scan-dialog-card dl div {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #f4f7f5;
}
.scan-dialog-card dt {
  color: var(--muted);
  font-weight: 800;
}
.scan-dialog-card dd {
  margin: 0;
  font-weight: 900;
}
.mobile-list { display: grid; gap: 10px; }
.summary-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.summary-card {
  display: grid;
  gap: 6px;
  min-height: 92px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 8px;
  background: rgba(255,255,255,.1);
  color: #fff;
  text-align: left;
  cursor: pointer;
}
.summary-card.active {
  background: #fff;
  color: var(--ink);
}
.summary-card span {
  font-weight: 800;
  color: inherit;
}
.summary-card strong {
  font-size: 30px;
}
.summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 14px 0 10px;
}
.summary-head h2 {
  color: #fff;
}
.person-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.person-card span, .person-card small { color: var(--muted); }
.person-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
  min-width: 130px;
}
.ticket-card { text-align: center; }
.ticket-qr {
  width: 260px;
  height: 260px;
  margin: 16px auto;
  border: 1px solid var(--line);
  padding: 10px;
}

@media (max-width: 920px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow: auto;
  }
  .side-nav { grid-auto-flow: column; grid-auto-columns: max-content; }
  .sidebar-footer { display: none; }
  .main-panel { padding: 18px; }
  .layout-grid.two, .layout-grid.three, .stat-grid, .stat-grid.compact { grid-template-columns: 1fr; }
  .panel-head, .event-hero, .scanner-top { align-items: flex-start; flex-direction: column; }
  .field-row, .filter-bar, .manual-scan { grid-template-columns: 1fr; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .summary-head { align-items: stretch; flex-direction: column; }
  .person-card { flex-direction: column; }
  .person-actions { justify-items: stretch; }
}
