:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2f7bff;
  --warn: #facc15;
  --danger: #dc2626;
  --success: #16a34a;
  --border: #e5e7eb;
  --radius: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.page { max-width: 980px; margin: 0 auto; padding: 20px 16px 48px; }

/* 发卡台：固定视口高度，仅短码列表区域滚动 */
body:has(.page-dashboard) {
  height: 100%;
  overflow: hidden;
}

.page-dashboard {
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

.page-dashboard .flash-stack {
  flex-shrink: 0;
  margin-bottom: 8px;
}

.page-dashboard .dashboard-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.page-dashboard .issue-card {
  flex-shrink: 0;
  margin-bottom: 0;
}

.page-dashboard .manage-card {
  flex: 1;
  min-height: 0;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-dashboard .manage-header {
  flex-shrink: 0;
  margin-bottom: 10px;
}

.page-dashboard .code-list-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.page-dashboard .manage-footer-hint {
  flex-shrink: 0;
  margin: 8px 0 0;
}

.page-dashboard .code-list-wrap .code-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  box-shadow: 0 1px 0 var(--border);
}

@media (max-height: 720px) {
  .page-dashboard {
    padding: 8px 12px 12px;
  }
  .page-dashboard .card {
    padding: 14px;
  }
  .page-dashboard .dashboard-layout {
    gap: 8px;
  }
}

@media (max-width: 640px) {
  .page {
    padding: 12px max(10px, env(safe-area-inset-right)) 32px max(10px, env(safe-area-inset-left));
  }

  .page-dashboard {
    padding: 8px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .page-dashboard .card {
    padding: 12px;
  }

  .card h2,
  .manage-header h2 {
    font-size: 1.05rem;
  }

  .manage-header {
    flex-wrap: wrap;
    gap: 6px;
  }

  .manage-header h2 {
    width: 100%;
    margin-bottom: 2px;
  }

  .manage-search-input,
  .manage-search-btn {
    flex: 1 1 auto;
    min-height: 40px;
  }

  .issue-row {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    margin-bottom: 8px;
  }

  .issue-row > .issue-row-label {
    width: 100%;
    font-size: 0.85rem;
  }

  .issue-row .ui-round-input {
    flex: 1 1 0;
    min-width: 0;
    min-height: 40px;
  }

  .issue-row .ui-round-btn.ui-action-btn {
    min-width: 72px;
    padding: 0 12px;
    min-height: 40px;
  }

  .issue-row-expiry .ui-round-display {
    flex: 1 1 100%;
    width: 100%;
    font-size: 0.82rem;
  }

  .issue-row-expiry .expiry-days-input {
    flex: 0 0 56px;
    width: 56px;
  }

  .issue-row-expiry .btn-preset {
    flex: 1 1 calc(33.333% - 6px);
    min-width: 0;
    padding: 0 6px;
    font-size: 0.82rem;
  }

  .btn-generate {
    min-height: 44px;
  }

  .code-list-wrap .code-table th,
  .code-list-wrap .code-table td {
    font-size: 0.78rem;
    padding: 8px 4px;
  }

  .code-list-wrap .code-table tbody td code {
    font-size: 0.78rem;
  }

  .badge {
    min-width: 4.2em;
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  .auth-card {
    margin: 20px auto;
    padding: 24px 18px;
    border-radius: 12px;
  }

  .auth-card h1 {
    font-size: 1.35rem;
  }

  .form input,
  .btn {
    min-height: 44px;
  }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.auth-card {
  max-width: 400px;
  margin: 48px auto;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: 0 8px 30px rgba(17, 24, 39, 0.08);
}
.auth-card h1 { margin: 0 0 8px; font-size: 1.5rem; }
.subtitle { color: var(--muted); margin: 0 0 24px; }

.auth-actions-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.auth-actions-row .btn {
  flex: 1;
  min-width: 0;
  height: 46px;
  margin: 0;
}

.modal-panel-auth {
  width: min(400px, calc(100vw - 32px));
  padding: 20px;
}

.modal-auth .modal-panel,
.modal-auth.is-open .modal-panel {
  left: 50%;
  top: 50%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: min(400px, calc(100vw - 32px));
  max-width: 400px;
  border-radius: 16px;
}

.modal-auth-title {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.modal-account-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-account-form .account-input {
  height: 46px;
  min-height: 46px;
  padding: 0 14px;
  font-size: 1rem;
  border-radius: 10px;
}

.modal-auth-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.modal-auth-actions .btn {
  flex: 1;
  height: 46px;
  margin: 0;
}

.employee-manage-hint {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.employee-modal-message {
  margin: 0 0 10px;
  font-size: 0.88rem;
  color: #b45309;
}

.employee-list-wrap {
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.employee-list-table {
  width: 100%;
  border-collapse: collapse;
}

.employee-list-table th,
.employee-list-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  text-align: left;
}

.employee-list-table th:last-child,
.employee-list-table td:last-child {
  text-align: right;
  white-space: nowrap;
}

.employee-list-table tbody tr:last-child td {
  border-bottom: none;
}

.employee-reset-btn {
  min-width: 72px;
  height: 32px;
  padding: 0 10px;
  font-size: 0.85rem;
}

.employee-toggle-generate-btn {
  min-width: 72px;
  height: 32px;
  padding: 0 10px;
  font-size: 0.85rem;
}

.employee-action-btns {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

.employee-delete-btn {
  min-width: 56px;
  height: 32px;
  padding: 0 10px;
  font-size: 0.85rem;
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.employee-delete-btn:hover {
  background: #fecaca;
}

.employee-add-row .ui-round-input {
  flex: 1;
  min-width: 0;
}

.employee-quota-cell {
  white-space: nowrap;
  font-size: 0.88rem;
}

.employee-quota-cell.is-full {
  color: #b91c1c;
  font-weight: 600;
}

.employee-release-btn {
  min-width: 56px;
  height: 32px;
  padding: 0 10px;
  font-size: 0.85rem;
  background: #eff6ff;
  border-color: #93c5fd;
  color: var(--primary);
}

.employee-release-limit-row .ui-round-input {
  flex: 1;
  min-width: 0;
}

.modal-employee-release {
  z-index: 10060;
}

.employee-quota-summary {
  font-size: 0.88rem;
  color: var(--muted);
  white-space: nowrap;
}

.page-auth-kefu .flash-stack {
  max-width: 400px;
  margin: 12px auto 0;
}

.auth-force-hint {
  margin: 0 0 14px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: #b45309;
  text-align: center;
}

.auth-modal-page {
  min-height: 100vh;
}

.auth-modal-page .modal.is-open {
  display: block !important;
}

.page-auth-admin .flash-stack {
  max-width: 400px;
  margin: 12px auto 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.link-muted { color: var(--muted); text-decoration: none; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 12px rgba(17, 24, 39, 0.06);
}
.highlight-card {
  background: #ecfdf5;
  border: 1px solid #86efac;
}
.manage-card {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
}
.card h2 { margin: 0 0 12px; font-size: 1.15rem; }

.issue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.issue-header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.issue-header-link {
  border: none;
  background: none;
  padding: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
}

.issue-header-link:hover {
  text-decoration: underline;
}

.issue-header h2 {
  margin: 0;
  flex-shrink: 0;
}

.issue-logout-link {
  flex-shrink: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}

.issue-logout-link:hover {
  text-decoration: underline;
}

.download-card h1 {
  margin-bottom: 16px;
  text-align: center;
}

.download-meta {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

.download-btn {
  display: block;
  width: 100%;
  height: 46px;
  line-height: 46px;
  text-align: center;
  text-decoration: none;
}

.download-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.download-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.page-download .flash-stack {
  max-width: 400px;
  margin: 16px auto 0;
}

.portal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 auto 12px;
  max-width: 960px;
  padding: 0 4px;
}

.portal-toolbar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.portal-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.portal-toolbar-link {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}

.portal-toolbar-link:hover {
  text-decoration: underline;
}

.issue-row-expiry-readonly .issue-row-fixed-hint {
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.account-card {
  max-width: 480px;
  margin: 0 auto;
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.account-label {
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 4px;
}

.account-input {
  width: 100%;
  height: 40px;
  box-sizing: border-box;
}

.account-submit {
  margin-top: 12px;
  width: 100%;
}

.manage-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.manage-header h2 {
  flex-shrink: 0;
  margin: 0;
  font-size: 1.15rem;
}

.manage-search-input {
  flex: 1;
  min-width: 0;
  height: 36px;
}

.manage-search-btn {
  flex-shrink: 0;
  min-width: 72px;
  height: 36px;
  background: #eff6ff;
  border-color: #93c5fd;
  color: var(--primary);
}

.manage-clear-form {
  flex-shrink: 0;
  margin: 0;
}

.manage-clear-btn {
  min-width: 88px;
  height: 36px;
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.manage-clear-btn:hover {
  background: #fecaca;
}
.hint { color: var(--muted); font-size: 0.92rem; line-height: 1.5; margin: 0 0 16px; }
.hint.mono { font-family: Consolas, monospace; font-size: 0.82rem; word-break: break-all; }
.warn-text { color: #b45309; }

.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 12px 0 8px;
}

/* 发卡四行：直角外框 + 行内小圆角控件，铺满 */
.issue-form { width: 100%; }

.issue-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 10px;
  padding: 10px;
  border: 2px solid #9ca3af;
  border-radius: 0;
  background: #f3f4f6;
}

.issue-row-label {
  flex-shrink: 0;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text);
}

.issue-row-unit {
  flex-shrink: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.ui-round-input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: #fff;
}

.ui-round-input:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 2px rgba(47, 123, 255, 0.12);
}

.ui-round-display {
  flex: 1.2;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.9rem;
  font-family: Consolas, "Courier New", monospace;
}

.ui-round-btn {
  flex-shrink: 0;
  height: 36px;
  padding: 0 14px;
  border: 1px solid #a5c5ff;
  border-radius: 6px;
  background: #fff;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.ui-round-btn:hover {
  background: #eff6ff;
}

.ui-round-btn.ui-action-btn {
  min-width: 96px;
  padding: 0 22px;
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
  font-weight: 600;
}

.ui-round-btn.ui-action-btn:hover {
  background: #bbf7d0;
  border-color: #4ade80;
  color: #14532d;
}

.issue-row-expiry .expiry-days-input {
  flex: 0 0 64px;
  width: 64px;
  text-align: center;
  font-weight: 600;
}

.issue-row-expiry .btn-preset,
#issueExpiryToolbar .btn-preset {
  flex: 1;
  min-width: 72px;
  padding: 0 16px;
  font-weight: 600;
}

.issue-row-expiry .btn-preset[data-months="1"],
#modalExpiryToolbar .btn-preset[data-months="1"] {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.issue-row-expiry .btn-preset[data-months="1"]:hover,
#modalExpiryToolbar .btn-preset[data-months="1"]:hover {
  background: #bbf7d0;
  border-color: #4ade80;
}

.issue-row-expiry .btn-preset[data-months="1"].active,
#modalExpiryToolbar .btn-preset[data-months="1"].active {
  background: #86efac;
  border-color: #22c55e;
  color: #14532d;
}

.issue-row-expiry .btn-preset[data-months="6"],
#modalExpiryToolbar .btn-preset[data-months="6"] {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e40af;
}

.issue-row-expiry .btn-preset[data-months="6"]:hover,
#modalExpiryToolbar .btn-preset[data-months="6"]:hover {
  background: #bfdbfe;
  border-color: #60a5fa;
}

.issue-row-expiry .btn-preset[data-months="6"].active,
#modalExpiryToolbar .btn-preset[data-months="6"].active {
  background: #93c5fd;
  border-color: #3b82f6;
  color: #1e3a8a;
}

.issue-row-expiry .btn-preset[data-months="12"],
#modalExpiryToolbar .btn-preset[data-months="12"] {
  background: #fef3c7;
  border-color: #fcd34d;
  color: #92400e;
}

.issue-row-expiry .btn-preset[data-months="12"]:hover,
#modalExpiryToolbar .btn-preset[data-months="12"]:hover {
  background: #fde68a;
  border-color: #fbbf24;
}

.issue-row-expiry .btn-preset[data-months="12"].active,
#modalExpiryToolbar .btn-preset[data-months="12"].active {
  background: #fcd34d;
  border-color: #f59e0b;
  color: #78350f;
}

.issue-row-submit {
  padding: 10px;
  gap: 8px;
}

.btn-generate,
.btn-offline-issue {
  flex: 1;
  min-width: 0;
  height: 42px;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-generate {
  background: var(--warn);
  color: #111;
}

.btn-generate:hover {
  filter: brightness(0.97);
}

.btn-offline-issue {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
}

.btn-offline-issue:hover {
  background: #bbf7d0;
}

.issue-row-output {
  align-items: flex-start;
}

.issue-row-output .ui-action-btn {
  margin-top: 0;
}

.ui-round-textarea {
  flex: 1;
  min-width: 0;
  min-height: 72px;
  max-height: 140px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.35;
  background: #fff;
  resize: vertical;
}

.ui-round-textarea:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 2px rgba(47, 123, 255, 0.12);
}

.shortcode-display,
.issue-output-display:not(textarea) {
  font-family: Consolas, "Courier New", monospace;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.issue-output-display.ui-round-textarea {
  font-family: Consolas, "Courier New", monospace;
  letter-spacing: 0;
  font-weight: 400;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0 20px;
  height: 46px;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}
.btn-block { width: 100%; margin-top: 8px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-warn { background: var(--warn); color: #111; }
.btn-outline {
  background: #fff;
  border: 1px solid #a5c5ff;
  color: var(--primary);
  height: 46px;
  border-radius: 10px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 600;
}
.btn-mini {
  font-size: 0.75rem;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f9fafb;
  cursor: pointer;
  margin-left: 4px;
}
.btn-action {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  margin-right: 4px;
}
.btn-action.confirm {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}
.btn-action.danger {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}
.inline-form { display: inline; }
.actions-cell { white-space: nowrap; }

code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; font-size: 0.88em; }

/* 短码列表：无外框，表内白底行 */
.code-list-wrap {
  overflow-x: auto;
}

.code-list-wrap .code-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  table-layout: fixed;
  margin: 0;
}

.code-list-wrap .code-table th,
.code-list-wrap .code-table td {
  width: 25%;
  vertical-align: middle;
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.4;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.code-list-wrap .code-table th:last-child,
.code-list-wrap .code-table td:last-child {
  border-right: 1px solid var(--border);
}

.code-list-wrap .code-table-row[data-code] {
  cursor: pointer;
}

.code-list-wrap .code-table-row[data-code]:hover td {
  background: #f0f7ff;
}

.manage-click-hint {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.badge-device-ban {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.72rem;
  vertical-align: middle;
}

.row-device-blacklisted td {
  background: #f9fafb;
}

.code-list-wrap .code-table thead th {
  background: #fff;
  padding: 10px 8px;
  font-weight: 700;
}

.code-list-wrap .code-table tbody td {
  background: #fff;
  padding: 12px 8px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}

.code-list-wrap .code-table-row[data-code] {
  cursor: pointer;
}

.code-list-wrap .code-table-row[data-code]:hover td {
  background: #f8fafc;
}

.code-list-wrap .code-table thead tr th:first-child {
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}

.code-list-wrap .code-table thead tr th:last-child {
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

.code-list-wrap .code-table tbody tr td:first-child {
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}

.code-list-wrap .code-table tbody tr td:last-child {
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

.code-list-wrap .code-table tbody td code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: normal;
}

.code-list-wrap .code-table tbody td.col-remain {
  color: var(--primary);
}

.code-list-wrap .row-blacklisted.code-table-row td.col-remain {
  color: var(--muted);
}

.code-list-wrap .code-table tbody td .badge {
  vertical-align: middle;
}

.code-list-wrap .row-blacklisted.code-table-row {
  opacity: 0.75;
}

.code-list-wrap .code-table-empty {
  text-align: center;
  color: var(--muted);
  padding: 20px;
  background: #fff !important;
  font-size: 0.9rem;
}

/* 改期浮窗 */
body.modal-open { overflow: hidden; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}
.modal[hidden],
.modal:not(.is-open) { display: none !important; }
.modal.is-open { display: block !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.modal-title {
  margin: 0 0 14px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
}

.modal-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.modal-info-item {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.modal-info-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.modal-info-value {
  font-size: 0.95rem;
  font-weight: 600;
  word-break: break-all;
}

.modal-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.modal-section-title {
  margin: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.modal-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-bottom: 8px;
}

.modal-actions-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 4px;
}

.modal-panel {
  position: fixed;
  z-index: 1001;
  width: calc(100% - 32px);
  max-width: 520px;
  max-height: min(90vh, calc(100dvh - 32px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--surface);
  border-radius: 16px;
  padding: 22px 20px;
  padding-bottom: max(22px, env(safe-area-inset-bottom));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}
.modal-drag-handle {
  cursor: move;
  user-select: none;
}
.modal-toolbar-wrap > .issue-row {
  margin-bottom: 10px;
}

/* 弹窗第一行：外框内 2 列均分 */
.issue-row.modal-summary-row {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.modal-summary-row .modal-pair {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.modal-summary-row .modal-pair .issue-row-label {
  flex-shrink: 0;
}

.modal-summary-row .modal-pair .modal-summary-display {
  flex: 1;
  min-width: 0;
  justify-content: center;
  text-align: center;
  font-family: Consolas, "Courier New", monospace;
}

/* 弹窗第二行：外框内 4 列均分 */
.issue-row.modal-edit-row {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.modal-edit-row .expiry-days-input,
.modal-edit-row .btn-preset {
  width: 100%;
  min-width: 0 !important;
  max-width: 100%;
  flex: none !important;
  box-sizing: border-box;
}

.modal-edit-row .expiry-days-input {
  text-align: center;
  font-weight: 600;
}

.modal-edit-row .btn-preset {
  padding: 0 6px;
  font-weight: 600;
}
.modal-actions-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f9fafb;
  box-sizing: border-box;
}

.modal-actions-bar .inline-form {
  margin: 0;
  display: block;
}

.modal-actions-bar .btn-action {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 10px 6px;
  font-size: 0.88rem;
  font-weight: 600;
  box-sizing: border-box;
}

.modal-actions-bar .btn-action-modify {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1d4ed8;
}

.modal-actions-bar .btn-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.modal-actions-bar .btn-action.danger {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.modal-actions-bar .btn-action.danger:disabled {
  background: #fee2e2;
  border-color: #fecaca;
  color: #b91c1c;
}

.modal-actions-cancel {
  margin-top: 10px;
}

.modal-actions-cancel .btn-block {
  width: 100%;
}

.badge {
  display: inline-block;
  min-width: 5.5em;
  padding: 6px 20px;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  box-sizing: border-box;
  line-height: 1.3;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-confirmed { background: #dcfce7; color: #166534; }
.badge-redeemed { background: #e5e7eb; color: #374151; }
.badge-blacklisted { background: #1f2937; color: #f9fafb; }
.badge-unused { background: #fef3c7; color: #92400e; }
.badge-revoked { background: #fee2e2; color: #991b1b; }

.row-blacklisted { opacity: 0.75; }

.flash-stack { margin-bottom: 12px; }
.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.92rem;
}
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

.form label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.form input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 1rem;
  margin-bottom: 14px;
}

@media (max-width: 640px) {
  .issue-row-expiry {
    flex-wrap: wrap;
  }

  .issue-row-expiry .issue-row-unit {
    flex-shrink: 0;
  }

  /* 改期弹窗：手机端全宽贴底，高度随内容，不撑满视口 */
  .modal-panel {
    width: 100%;
    max-width: none;
    height: auto;
    max-height: calc(100dvh - env(safe-area-inset-top));
    overflow-y: auto;
    box-sizing: border-box;
    padding: 16px max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    border-radius: 12px 12px 0 0;
  }

  .modal-panel.is-positioned {
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    bottom: 0 !important;
    width: 100% !important;
    transform: none !important;
  }

  .modal-auth .modal-panel,
  .modal-auth.is-open .modal-panel {
    left: 50% !important;
    top: 50% !important;
    right: auto !important;
    bottom: auto !important;
    width: min(400px, calc(100vw - 32px)) !important;
    max-width: 400px !important;
    transform: translate(-50%, -50%) !important;
    border-radius: 16px !important;
  }

  .modal-drag-handle {
    cursor: default;
    touch-action: manipulation;
  }

  .issue-row.modal-summary-row {
    grid-template-columns: 1fr !important;
    gap: 6px;
  }

  .modal-summary-row .modal-pair {
    width: 100%;
  }

  .modal-summary-row .modal-pair .modal-summary-display {
    font-size: 0.82rem;
  }

  .issue-row.modal-edit-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 6px;
  }

  .modal-edit-row .expiry-days-input {
    grid-column: 1 / -1;
  }

  .modal-edit-row .btn-preset {
    font-size: 0.8rem;
    padding: 0 4px;
    min-height: 40px;
  }

  .modal-actions-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .modal-actions-bar .btn-action {
    min-height: 44px;
    padding: 10px 4px;
    font-size: 0.85rem;
  }

  .modal-actions-cancel .btn-outline {
    min-height: 44px;
  }

  .modal-backdrop {
    background: rgba(15, 23, 42, 0.55);
  }
}

@media (max-width: 380px) {
  .issue-row-expiry .btn-preset {
    font-size: 0.75rem;
    padding: 0 2px;
  }

  .modal-edit-row .btn-preset {
    font-size: 0.72rem;
  }
}

.copy-toast {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 10000;
  padding: 14px 28px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 1rem;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.copy-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.app-confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: none;
}

.app-confirm-modal.is-open {
  display: block;
}

.app-confirm-modal[hidden] {
  display: none !important;
}

.app-confirm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.app-confirm-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100vw - 32px));
  padding: 20px 18px 16px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.2);
}

.app-confirm-message {
  margin: 0 0 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #111827;
  text-align: center;
  word-break: break-word;
}

.app-confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.app-confirm-btn {
  min-width: 88px;
  height: 36px;
}

.app-confirm-btn-cancel {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #374151;
}
