:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #f0f4f8;
  --text: #172033;
  --muted: #667085;
  --line: #d7dde7;
  --primary: #1f6feb;
  --primary-strong: #1756ba;
  --success: #137333;
  --danger: #c5221f;
  --warning: #b06000;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
  line-height: 1.5;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 8px 14px;
}

button:hover {
  background: var(--primary-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

button.secondary:hover {
  background: var(--panel-soft);
}

button.danger {
  background: var(--danger);
}

button.success {
  background: var(--success);
}

button.secondary.danger-text {
  border-color: #e4a5a2;
  color: var(--danger);
}

button.secondary.danger-text:hover {
  background: #fceeee;
}

a {
  color: var(--primary);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  padding: 10px 12px;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.13);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.vote-shell {
  width: min(760px, 100%);
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.2;
}

.topbar p {
  color: var(--muted);
  margin: 6px 0 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.panel h2,
.panel h3 {
  margin: 0 0 12px;
  line-height: 1.25;
}

.panel h2 {
  font-size: 20px;
}

.panel h3 {
  font-size: 17px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field label,
.small-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status {
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  padding: 12px 14px;
  margin-bottom: 16px;
}

.status.ok {
  color: var(--success);
  background: #edf7ee;
  border-color: #b7dfbe;
}

.status.warn {
  color: var(--warning);
  background: #fff6e5;
  border-color: #f1c980;
}

.status.bad {
  color: var(--danger);
  background: #fceeee;
  border-color: #efb7b4;
}

.candidate-list {
  display: grid;
  gap: 10px;
}

.candidate-profiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.candidate-profile {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px;
  min-height: 150px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.candidate-profile-photo {
  width: 112px;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 32px;
  font-weight: 800;
}

.candidate-profile-photo img,
.candidate-choice-photo img,
.candidate-photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.candidate-profile-info {
  min-width: 0;
}

.candidate-profile-info small {
  color: var(--muted);
  font-weight: 700;
}

.candidate-profile-info h3 {
  margin: 4px 0 8px;
}

.candidate-profile-info p {
  margin: 0;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.candidate {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  cursor: pointer;
}

#candidateList .candidate {
  grid-template-columns: 28px 52px minmax(0, 1fr);
  align-items: center;
}

.candidate-choice-photo {
  width: 52px;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 800;
}

.candidate:hover {
  border-color: #9ab8eb;
}

.candidate.selected {
  border-color: var(--primary);
  background: #f0f6ff;
}

.candidate input {
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
}

.candidate strong {
  display: block;
  font-size: 17px;
}

.candidate span {
  display: block;
  color: var(--muted);
  margin-top: 3px;
  word-break: break-word;
}

.abstain-option {
  margin-top: 12px;
  border-style: dashed;
}

.abstain-option.selected {
  border-color: var(--warning);
  background: #fff8e8;
}

.counter {
  font-weight: 800;
  color: var(--primary);
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.stat b {
  display: block;
  font-size: 26px;
  line-height: 1.1;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  min-width: 520px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
}

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
}

tr:last-child td {
  border-bottom: 0;
}

.progress {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf5;
}

.progress > i {
  display: block;
  height: 100%;
  background: var(--primary);
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tab {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  min-height: 36px;
}

.tab.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

.hidden {
  display: none !important;
}

.scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.82);
}

.scanner-dialog {
  width: min(100%, 480px);
  overflow: hidden;
  border-radius: 8px;
  background: #fff;
}

.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.scanner-header h2 {
  margin: 0;
  font-size: 18px;
}

.scanner-header button {
  min-height: 36px;
}

.scanner-viewport {
  position: relative;
  height: min(68vh, 560px);
  min-height: 320px;
  overflow: hidden;
  background: #000;
}

.scanner-viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(72%, 320px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 3px solid #fff;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.scanner-hint {
  min-height: 22px;
  margin: 0;
  padding: 11px 14px 13px;
  color: var(--muted);
  text-align: center;
}

.notice {
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
}

.section-divider,
.candidate-photo-section {
  border-top: 1px solid var(--line);
  margin-top: 22px;
  padding-top: 18px;
}

.candidate-photo-editor {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.candidate-photo-item {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 14px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.candidate-photo-item:last-child {
  border-bottom: 0;
}

.candidate-photo-preview {
  width: 82px;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 24px;
  font-weight: 800;
}

.candidate-photo-controls {
  min-width: 0;
}

.candidate-photo-controls strong {
  display: block;
  margin-bottom: 8px;
}

.live-qr {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 204px;
  align-items: center;
  gap: 20px;
  border: 1px solid #b7dfbe;
  border-radius: 8px;
  background: #f4fbf5;
  padding: 16px;
  margin-bottom: 16px;
}

.live-qr-info {
  min-width: 0;
}

.live-qr-info code {
  display: block;
  overflow-wrap: anywhere;
  font-size: 16px;
  font-weight: 700;
}

.live-qr-code {
  width: 204px;
  height: 204px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 11px;
}

.live-qr-code img,
.live-qr-code canvas {
  display: block;
  width: 180px;
  height: 180px;
}

.direct-qr-test {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  background: #fff;
}

.direct-qr-test h3 {
  margin: 0;
}

.direct-qr-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.direct-qr-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
}

.direct-qr-image {
  min-height: 156px;
  display: grid;
  place-items: center;
}

.direct-qr-image img,
.direct-qr-image canvas {
  display: block;
  width: 156px;
  height: 156px;
  max-width: 100%;
}

.direct-qr-card code {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.token-delete {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
}

.print-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.ticket {
  break-inside: avoid;
  border: 1px solid #222;
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  display: grid;
  gap: 8px;
  min-height: 230px;
}

.ticket h3 {
  margin: 0;
  font-size: 16px;
}

.ticket-code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.ticket-scan-label {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.qr {
  width: 132px;
  height: 132px;
  margin: 0 auto;
}

.integrity-line code {
  overflow-wrap: anywhere;
}

@media (max-width: 820px) {
  .shell {
    padding: 16px;
  }

  .topbar {
    display: grid;
  }

  .grid.two,
  .grid.three,
  .live-qr,
  .candidate-profiles {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .live-qr-code {
    justify-self: center;
  }

  .direct-qr-grid {
    grid-template-columns: 1fr;
  }

  .candidate {
    grid-template-columns: 26px 1fr;
    padding: 12px;
  }

  #candidateList .candidate {
    grid-template-columns: 26px 48px minmax(0, 1fr);
  }

  .candidate-choice-photo {
    width: 48px;
  }

  .candidate-profile {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .candidate-profile-photo {
    width: 96px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .no-print {
    display: none !important;
  }

  .shell {
    width: 100%;
    padding: 0;
  }

  .panel {
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .print-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
}
