:root {
  --canvas: #f5f5f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666666;
  --text-weak: #737373;
  --border: #d8d8d5;
  --border-strong: #b8b9b5;
  --hover: #eeeeeb;
  --accent: #41534b;
  --accent-hover: #33423b;
  --accent-soft: #e7ece9;
  --success: #26734d;
  --success-soft: #e8f3ec;
  --danger: #a43128;
  --danger-soft: #faecea;
  --warning: #7a5a17;
  --warning-soft: #f7f0df;
  --radius: 6px;
  --focus: #61786d;
  --content-width: 1280px;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  line-height: 1.5;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
summary,
select,
input[type="file"] {
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
}

h1,
h2,
h3,
p,
dl,
dd {
  margin: 0;
}

h1 {
  font-size: 20px;
  font-weight: 650;
  line-height: 28px;
}

h2 {
  font-size: 16px;
  font-weight: 650;
  line-height: 24px;
}

h3 {
  font-size: 14px;
  font-weight: 650;
  line-height: 20px;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 12px;
  left: 12px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--text);
  color: #ffffff;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-weight: 600;
  line-height: 20px;
  text-decoration: none;
  white-space: nowrap;
}

.button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.button-primary:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.button-secondary {
  border-color: var(--border-strong);
  background: var(--surface);
}

.button-secondary:hover:not(:disabled) {
  background: var(--hover);
}

.button-danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #ffffff;
}

.button-danger:hover:not(:disabled) {
  border-color: #84271f;
  background: #84271f;
}

.button-danger-secondary {
  border-color: #d7a39e;
  background: var(--surface);
  color: var(--danger);
}

.button-danger-secondary:hover:not(:disabled) {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.button-policy[aria-pressed="true"] {
  border-color: #a9c8b5;
  background: var(--success-soft);
  color: #194e34;
}

.button-policy[aria-pressed="true"]:hover:not(:disabled) {
  border-color: var(--success);
}

.button-quiet {
  color: var(--text-muted);
}

.button-quiet:hover:not(:disabled) {
  background: var(--hover);
  color: var(--text);
}

.button:disabled {
  border-color: #c9cbc8;
  background: #e6e7e5;
  color: #888b88;
}

.button-block {
  width: 100%;
}

.spinner {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.field {
  display: grid;
  gap: 8px;
}

.field label {
  color: var(--text);
  font-weight: 600;
}

input,
select,
textarea {
  min-height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

input {
  width: 100%;
  padding: 8px 11px;
}

select {
  padding: 7px 30px 7px 10px;
}

textarea {
  width: 100%;
  padding: 10px 11px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-weak);
}

input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: #969994;
}

input[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-help,
.field-error {
  font-size: 12px;
  line-height: 18px;
}

.field-help {
  color: var(--text-muted);
}

.field-error {
  color: var(--danger);
}

.input-action-wrap {
  position: relative;
}

.input-action-wrap input {
  padding-right: 64px;
}

.input-action {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 56px;
  height: 38px;
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface);
  color: var(--text-muted);
}

.input-action:hover {
  background: var(--hover);
  color: var(--text);
}

.notice {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas);
  color: var(--text);
  line-height: 20px;
}

.notice-success {
  border-color: #a9c8b5;
  background: var(--success-soft);
  color: #194e34;
}

.notice-error {
  border-color: #e0b3ad;
  background: var(--danger-soft);
  color: #76251f;
}

.product-label,
.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
}

/* Login */
.auth-page,
.exchange-page {
  background: var(--canvas);
}

.auth-shell,
.exchange-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 48px 20px 80px;
}

.auth-panel {
  width: min(100%, 400px);
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.auth-heading,
.exchange-heading {
  display: grid;
  gap: 8px;
  margin-bottom: 28px;
}

.auth-heading > p:last-child,
.exchange-heading > p:last-child {
  color: var(--text-muted);
}

.auth-panel form,
.exchange-panel form {
  display: grid;
  gap: 20px;
}

.auth-panel .notice {
  margin-bottom: 20px;
}

/* Admin shell */
.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  height: 64px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.97);
}

.topbar-inner {
  display: flex;
  width: min(100%, var(--content-width));
  height: 100%;
  align-items: center;
  justify-content: space-between;
  margin: 0 auto;
  padding: 0 32px;
}

.brand {
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  line-height: 22px;
  text-decoration: none;
}

.account-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-name {
  max-width: 240px;
  overflow: hidden;
  color: var(--text-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-main {
  width: min(100%, var(--content-width));
  margin: 0 auto;
  padding: 32px 32px 56px;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 32px;
}

.page-heading > div:first-child {
  display: grid;
  gap: 4px;
}

.count-summary {
  display: flex;
  align-items: center;
}

.count-summary > div {
  display: grid;
  min-width: 90px;
  gap: 2px;
  padding: 0 20px;
  border-left: 1px solid var(--border);
}

.count-summary dt {
  color: var(--text-muted);
  font-size: 12px;
}

.count-summary dd {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.workspace-section {
  padding: 32px 0;
  border-top: 1px solid var(--border);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.section-heading > div {
  display: grid;
  gap: 4px;
}

.section-heading p {
  color: var(--text-muted);
  font-size: 13px;
}

/* Upload */
#upload-form {
  display: grid;
  gap: 14px;
}

.drop-zone {
  display: grid;
  min-height: 144px;
  align-content: center;
  justify-items: center;
  gap: 5px;
  padding: 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: #fafafa;
  text-align: center;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-zone:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.drop-title {
  font-weight: 650;
}

.drop-help {
  color: var(--text-muted);
  font-size: 12px;
}

.upload-mode {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0;
  border: 0;
  margin: 0;
}

.upload-mode legend {
  float: left;
  padding: 0;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
}

.upload-mode-options {
  display: inline-flex;
  min-height: 40px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas);
}

.upload-mode-options label {
  position: relative;
  display: block;
  cursor: pointer;
}

.upload-mode-options input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload-mode-options span {
  display: flex;
  min-height: 32px;
  align-items: center;
  padding: 5px 12px;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 13px;
}

.upload-mode-options input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border);
  font-weight: 650;
}

.upload-mode-options input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.upload-mode-options input:disabled + span {
  cursor: not-allowed;
  color: var(--text-weak);
}

.upload-actions {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
}

.selected-file {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--text-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-section .notice {
  margin-top: 16px;
}

/* Filtering and export */
.toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 230px) minmax(260px, 1fr) minmax(160px, 190px) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.batch-filter-field {
  min-width: 0;
}

.health-filter-field {
  min-width: 0;
}

.health-filter-field select {
  width: 100%;
}

.batch-filter-field select {
  width: 100%;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
  grid-column: 1 / -1;
}

.status-filter {
  display: inline-flex;
  width: max-content;
  min-height: 40px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas);
}

.status-filter button {
  min-height: 32px;
  padding: 5px 12px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
}

.status-filter button:hover {
  color: var(--text);
}

.status-filter button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border);
  font-weight: 650;
}

.export-menu {
  position: relative;
}

.export-menu summary {
  min-width: 88px;
  list-style: none;
}

.export-menu summary::-webkit-details-marker {
  display: none;
}

.export-menu summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin: -3px 1px 2px 4px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
}

.export-menu[open] summary::after {
  margin: 3px 1px -2px 4px;
  transform: rotate(225deg);
}

.export-popover {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  right: 0;
  width: 210px;
  max-height: min(520px, calc(100vh - 120px));
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 10px 24px rgba(26, 26, 26, 0.12);
}

.export-popover p {
  padding: 6px 8px 3px;
  color: var(--text-weak);
  font-size: 11px;
  font-weight: 700;
}

.export-popover button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 7px 8px;
  border: 0;
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.export-popover button:hover:not(:disabled),
.export-popover button:focus-visible {
  background: var(--hover);
}

.export-popover button:disabled {
  color: var(--text-weak);
}

.menu-separator {
  height: 1px;
  margin: 5px 0;
  background: var(--border);
}

.health-summary {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.health-summary-heading {
  min-width: 160px;
}

.health-summary-heading h3 {
  font-size: 13px;
}

.health-summary-heading p {
  max-width: 280px;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.health-summary-values {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.health-stat {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  gap: 7px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.health-stat strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.health-stat.is-alive { border-color: #a9c8b5; background: var(--success-soft); color: #194e34; }
.health-stat.is-dead,
.health-stat.is-failed { border-color: #e0b3ad; background: var(--danger-soft); color: #76251f; }
.health-stat.is-pending { border-color: #d8c28e; background: var(--warning-soft); color: #6d5015; }
.health-stat.is-unknown { background: var(--canvas); }

.confirmation-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 18px 48px rgba(26, 26, 26, 0.2);
}

.confirmation-dialog::backdrop {
  background: rgba(26, 26, 26, 0.48);
}

.dialog-content {
  padding: 24px;
}

.dialog-content h2 {
  margin-top: 4px;
  font-size: 20px;
  line-height: 28px;
}

.dialog-warning {
  margin-top: 10px;
  color: var(--text-muted);
  line-height: 22px;
}

.delete-batch-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 20px;
  margin-top: 20px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.delete-batch-summary div {
  min-width: 0;
}

.delete-batch-summary div:first-child {
  grid-column: 1 / -1;
}

.delete-batch-summary dt {
  margin-bottom: 3px;
  color: var(--text-weak);
  font-size: 11px;
  font-weight: 650;
}

.delete-batch-summary dd {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* Data table */
.list-loading {
  display: flex;
  min-height: 160px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

table {
  width: 100%;
  min-width: 1286px;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  height: 54px;
  padding: 10px 12px;
  border-bottom: 1px solid #e9e9e7;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  height: 42px;
  background: #fafafa;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
}

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

tbody tr:hover {
  background: #fafafa;
}

th:nth-child(1) { width: 158px; }
th:nth-child(2) { width: 92px; }
th:nth-child(3) { width: 168px; }
th:nth-child(4) { width: 150px; }
th:nth-child(5),
th:nth-child(6),
th:nth-child(7) { width: 150px; }
th:nth-child(8) { width: 150px; }
th:nth-child(9) { width: 124px; }

.card-code {
  color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.status-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #888b88;
}

.status-unused {
  color: var(--warning);
}

.status-unused::before {
  background: #a17a28;
}

.status-used {
  color: var(--success);
}

.status-used::before {
  background: var(--success);
}

.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.health-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #888b88;
}

.health-alive { color: var(--success); }
.health-alive::before { background: var(--success); }
.health-dead,
.health-failed { color: var(--danger); }
.health-dead::before,
.health-failed::before { background: var(--danger); }
.health-pending { color: var(--warning); }
.health-pending::before { background: #a17a28; }

.card-health-state {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-health-button {
  width: 58px;
  min-height: 34px;
  padding: 5px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.card-health-button:hover:not(:disabled) {
  border-color: var(--success);
  background: var(--success-soft);
  color: #194e34;
}

.card-state {
  display: grid;
  justify-items: start;
  gap: 4px;
}

.policy-badge {
  display: inline-flex;
  min-height: 20px;
  align-items: center;
  padding: 1px 6px;
  border: 1px solid #e0b3ad;
  border-radius: 4px;
  background: var(--danger-soft);
  color: #76251f;
  font-size: 11px;
  font-weight: 650;
  line-height: 16px;
}

.copy-button {
  min-width: 40px;
  min-height: 44px;
  padding: 6px 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
}

.copy-button:hover {
  background: var(--hover);
  color: var(--text);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-policy-button {
  width: 62px;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.card-policy-button:hover:not(:disabled) {
  border-color: var(--text-muted);
  background: var(--hover);
  color: var(--text);
}

.card-policy-button.is-welfare {
  border-color: #e0b3ad;
  background: var(--danger-soft);
  color: #76251f;
}

.mobile-card-list {
  display: none;
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  align-content: center;
  gap: 6px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.empty-state p {
  max-width: 420px;
  color: var(--text-muted);
}

.empty-state .button {
  margin-top: 10px;
}

.pagination {
  display: flex;
  min-height: 64px;
  align-items: center;
  gap: 10px;
  padding-top: 16px;
}

.pagination select {
  min-height: 36px;
}

.page-size-label,
.page-total {
  color: var(--text-muted);
  font-size: 12px;
}

.page-total {
  margin-right: auto;
}

.page-controls,
.page-numbers {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-controls .button,
.page-number {
  min-height: 36px;
}

.page-number {
  min-width: 36px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
}

.page-number:hover:not(:disabled) {
  background: var(--hover);
}

.page-number[aria-current="page"] {
  border-color: var(--border-strong);
  background: var(--surface);
  font-weight: 700;
}

.mobile-page-indicator {
  display: none;
  min-width: 76px;
  color: var(--text-muted);
  text-align: center;
}

/* Toasts */
.toast-region {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  display: grid;
  width: min(360px, calc(100vw - 40px));
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(26, 26, 26, 0.12);
  line-height: 20px;
  pointer-events: auto;
}

.toast-error {
  border-color: #d8a6a1;
}

.toast button {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
}

.toast button:hover {
  background: var(--hover);
}

/* Exchange */
.exchange-shell {
  align-items: start;
  padding-top: max(72px, 16vh);
}

.exchange-panel {
  width: min(100%, 480px);
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.exchange-panel:has(input[value="batch"]:checked) {
  width: min(100%, 600px);
}

.exchange-heading h1 {
  font-size: 24px;
  line-height: 32px;
}

#redeem-code {
  min-height: 48px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 16px;
  font-weight: 650;
  text-transform: uppercase;
}

.exchange-mode {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
  margin: 0 0 20px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas);
}

.exchange-mode label {
  position: relative;
  cursor: pointer;
}

.exchange-mode input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.exchange-mode span {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  font-weight: 600;
}

.exchange-mode input:checked + span {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.exchange-mode input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.exchange-mode input:disabled + span {
  color: var(--text-weak);
  cursor: wait;
}

.exchange-format-field select {
  width: 100%;
}

#batch-codes {
  min-height: 184px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 15px;
  line-height: 24px;
  text-transform: uppercase;
}

.batch-field-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

#batch-count {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

#batch-count.is-over-limit {
  color: var(--danger);
}

.exchange-submit {
  min-height: 48px;
}

.redeem-result {
  margin-top: 20px;
  padding: 12px;
  border: 1px solid #a9c8b5;
  border-radius: var(--radius);
  background: var(--success-soft);
  color: #194e34;
}

.redeem-result.is-error {
  border-color: #e0b3ad;
  background: var(--danger-soft);
  color: #76251f;
}

@media (max-width: 900px) {
  .toolbar {
    grid-template-columns: minmax(220px, 1fr) minmax(260px, 1fr);
  }

  .toolbar-actions {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .status-filter {
    grid-column: 2;
    grid-row: 2;
  }

  .health-filter-field {
    grid-column: 1;
    grid-row: 2;
  }
}

@media (max-width: 640px) {
  .button,
  input,
  select,
  textarea,
  .exchange-mode span {
    min-height: 44px;
  }

  .auth-shell,
  .exchange-shell {
    min-height: auto;
    place-items: start stretch;
    padding: 64px 20px 40px;
  }

  .auth-panel,
  .exchange-panel {
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .auth-page,
  .exchange-page {
    background: var(--surface);
  }

  .input-action {
    height: 42px;
  }

  .topbar {
    height: 56px;
  }

  .topbar-inner {
    padding: 0 16px;
  }

  .admin-name {
    display: none;
  }

  .account-actions .button {
    padding-inline: 10px;
  }

  .admin-main {
    padding: 24px 16px 40px;
  }

  .page-heading {
    display: grid;
    gap: 20px;
    padding-bottom: 24px;
  }

  .count-summary {
    width: 100%;
  }

  .count-summary > div {
    min-width: 0;
    flex: 1;
    padding: 0 12px;
  }

  .count-summary > div:first-child {
    padding-left: 0;
    border-left: 0;
  }

  .workspace-section {
    padding: 24px 0;
  }

  .drop-zone {
    min-height: 132px;
    padding: 20px 16px;
  }

  .upload-actions {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .upload-mode {
    display: grid;
    gap: 6px;
  }

  .upload-mode legend {
    float: none;
  }

  .upload-mode-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .upload-mode-options span {
    min-height: 38px;
    justify-content: center;
  }

  .selected-file {
    min-height: 24px;
    grid-column: 1;
  }

  #remove-file {
    grid-column: 2;
  }

  #upload-submit {
    grid-column: 1 / -1;
    width: 100%;
  }

  .toolbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .search-field,
  .batch-filter-field,
  .health-filter-field,
  .status-filter,
  .toolbar-actions {
    width: 100%;
    grid-column: 1;
    grid-row: auto;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .toolbar-actions > .export-menu {
    grid-column: 1 / -1;
    width: 100%;
  }

  #check-batch-health {
    grid-column: 1 / -1;
  }

  .status-filter {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .status-filter button {
    min-height: 44px;
    padding-inline: 6px;
  }

  .export-menu summary {
    width: 100%;
  }

  .dialog-content {
    padding: 20px;
  }

  .delete-batch-summary {
    grid-template-columns: 1fr;
  }

  .delete-batch-summary div:first-child {
    grid-column: auto;
  }

  .export-popover {
    right: 0;
    left: 0;
    width: 100%;
  }

  .health-summary {
    display: grid;
    gap: 10px;
  }

  .health-summary-heading p {
    max-width: calc(100vw - 32px);
  }

  .health-summary-values {
    justify-content: flex-start;
  }

  .table-wrap {
    display: none;
  }

  .mobile-card-list {
    display: block;
    border-top: 1px solid var(--border);
  }

  .mobile-card {
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
  }

  .mobile-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
  }

  .mobile-code-wrap {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 6px;
  }

  .mobile-code-wrap .card-code {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-card dl {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 16px;
  }

  .mobile-card dl > div {
    min-width: 0;
  }

  .mobile-card .wide-value {
    grid-column: 1 / -1;
  }

  .mobile-card dt {
    margin-bottom: 2px;
    color: var(--text-weak);
    font-size: 11px;
    line-height: 17px;
  }

  .mobile-card dd {
    overflow: hidden;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 19px;
    overflow-wrap: anywhere;
  }

  .mobile-card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
  }

  .mobile-card-actions .card-policy-button,
  .mobile-card-actions .card-health-button {
    width: auto;
    min-width: 88px;
    min-height: 40px;
  }

  .pagination {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 8px;
  }

  .page-total {
    justify-self: end;
    margin: 0;
  }

  .page-controls {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
  }

  .page-controls .button:last-child {
    grid-column: 3;
  }

  .page-numbers {
    display: none;
  }

  .mobile-page-indicator {
    display: inline;
  }

  .toast-region {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: calc(100vw - 32px);
  }

  .exchange-heading h1 {
    font-size: 22px;
    line-height: 30px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
